本文整理了Java中org.netbeans.modules.parsing.api.Source.create()
方法的一些代码示例,展示了Source.create()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Source.create()
方法的具体详情如下:
包路径:org.netbeans.modules.parsing.api.Source
类名称:Source
方法名:create
暂无
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
private void parsePresenter(FileObject presenterFile) throws ParseException {
ParserManager.parse(Collections.singleton(Source.create(presenterFile)), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
PHPParseResult parseResult = (PHPParseResult) resultIterator.getParserResult();
if (parseResult != null) {
findControls(parseResult);
}
}
});
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
@Override
@NonNull
protected final CharSequence createContent() throws IOException {
final FileObject file = getHandle().resolveFileObject(false);
if (file == null) {
throw new FileNotFoundException("Cannot open file: " + toString());
}
final Source source = Source.create(file);
if (source == null) {
throw new IOException("No source for: " + FileUtil.getFileDisplayName(file)); //NOI18N
}
CharSequence content = source.createSnapshot().getText();
if (hasFilter && source.getDocument(false) == null) {
content = filter(content);
}
return content;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
@Override
public void run() {
try {
ParserManager.parse(Collections.singleton(Source.create(target.getDocument())), task);
} catch (ParseException ex) {
Exceptions.printStackTrace(ex);
}
}
}, Bundle.LongName(), cancel, false);
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-parsing-nb
@Override
public void caretUpdate(final CaretEvent event) {
final JTextComponent lastEditor = lastEditorRef == null ? null : lastEditorRef.get();
if (lastEditor != null) {
Document doc = lastEditor.getDocument ();
String mimeType = DocumentUtilities.getMimeType (doc);
if (doc != null && mimeType != null) {
Source source = Source.create(doc);
if (source != null) {
((EventSupport)SourceEnvironment.forSource(source)).resetState(false, false, -1, -1, false);
}
}
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
private void parsePresenter(FileObject presenterFile) throws ParseException {
ParserManager.parse(Collections.singleton(Source.create(presenterFile)), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
PHPParseResult parseResult = (PHPParseResult) resultIterator.getParserResult();
PresenterVisitor presenterVisitor = new PresenterVisitor(templateFile);
presenterVisitor.scan(parseResult.getProgram());
for (MethodDeclaration methodToScan : presenterVisitor.getMethodsToScan()) {
VariableVisitor variableVisitor = new VariableVisitor(parseResult.getModel(), variablePrefix);
methodToScan.accept(variableVisitor);
result.addAll(variableVisitor.getVariables());
}
}
});
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
private FileScope getFileScope(final FileObject fileObject) {
final FileScope[] fileScope = new FileScope[1];
try {
ParserManager.parse(Collections.singletonList(Source.create(fileObject)), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
Result parserResult = resultIterator.getParserResult();
PHPParseResult phpResult = (PHPParseResult) parserResult;
fileScope[0] = phpResult.getModel().getFileScope();
}
});
} catch (ParseException ex) {
LOGGER.log(Level.WARNING, null, ex);
}
return fileScope[0];
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
@Override
public void run() {
try {
ParserManager.parse(Collections.singleton(Source.create(doc)), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
PHPParseResult parserResult = (PHPParseResult) resultIterator.getParserResult();
if (parserResult != null) {
PHPCodeTemplateProcessor.this.info = parserResult;
}
}
});
} catch (ParseException ex) {
Exceptions.printStackTrace(ex);
info = null;
}
}
});
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
private void resolveNodesUnderCarret() {
try {
ParserManager.parse(Collections.singleton(Source.create(component.getDocument())), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
ParserResult info = (ParserResult) resultIterator.getParserResult();
if (info != null) {
int caretOffset = component.getCaretPosition();
nodes = NavUtils.underCaret(info, caretOffset);
}
}
});
} catch (ParseException ex) {
LOGGER.log(Level.WARNING, "Error during resolving nodes under carret (codegens): {0}", ex.getMessage());
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-parsing-nb
protected void setEditor (JTextComponent editor) {
if (editor != null) {
Document document = editor.getDocument ();
if (currentDocument == document) return;
currentDocument = document;
final Source source = Source.create (currentDocument);
schedule (source, new SchedulerEvent (this) {});
}
else {
currentDocument = null;
schedule(null, null);
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-parsing-nb
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (DataObject.PROP_PRIMARY_FILE.equals(evt.getPropertyName())) {
final DataObject dobj = (DataObject) evt.getSource();
final Source newSource = Source.create(dobj.getPrimaryFile());
if (newSource != null) {
LOGGER.log(
Level.FINE,
"Rescheduling {0} due to change of primary file.", //NOI18N
dobj.getPrimaryFile());
control.sourceChanged(newSource);
}
}
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
public ReformatTask createTask(Context context) {
Source source = Source.create(context.document());
return source != null ? new Reformatter(source, context) : null;
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-css-prep
@Override
public final void run() {
try {
Source source = Source.create(document);
ParserManager.parse(Collections.singleton(source), this);
} catch (ParseException e) {
LOG.log(Level.WARNING, null, e);
return;
}
TopComponent activetc = TopComponent.getRegistry().getActivated();
if (ui != null) {
UI.openRefactoringUI(ui, activetc);
} else {
JOptionPane.showMessageDialog(null, NbBundle.getMessage(CPActionsImplementationProvider.class, "ERR_CannotRefactorLoc"));//NOI18N
}
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
@Override
public StyledDocument getDocument() {
final FileObject file = getHandle().resolveFileObject(false);
if (file == null) {
return null;
}
final Source src = Source.create(file);
if (src == null) {
return null;
}
final Document doc = src.getDocument(false);
return (doc instanceof StyledDocument) ? ((StyledDocument)doc) : null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-editor
@Override
public void actionPerformed(ActionEvent evt, final JTextComponent target) {
final FileObject fo = NbEditorUtilities.getDataObject(target.getDocument()).getPrimaryFile();
final Source source = Source.create(fo);
CollectMissingImportsTask task = new CollectMissingImportsTask();
try {
ParserManager.parse(Collections.singleton(source), task);
} catch (ParseException ex) {
Exceptions.printStackTrace(ex);
}
ImportHelper.resolveImports(fo, task.getPackageName(), task.getMissingNames());
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javascript-refactoring
public void run() {
FileObject[] fobs = new FileObject[nodes.size()];
int i = 0;
for(Node node : nodes) {
DataObject dob = node.getCookie(DataObject.class);
if (dob != null) {
fobs[i] = dob.getPrimaryFile();
Source source = Source.create(fobs[i]);
try {
ParserManager.parse(Collections.singleton(source), this);
} catch (ParseException ex) {
LOG.log(Level.WARNING, null, ex);
}
pkg[i++] = node.getLookup().lookup(NonRecursiveFolder.class);
}
}
UI.openRefactoringUI(createRefactoringUI(fobs, handles));
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
private static PhpDocumentation getPhpDocumentation(final PhpElement indexedElement, final CCDocHtmlFormatter header) {
PhpDocumentation result = PhpDocumentation.NONE;
if (canBeProcessed(indexedElement)) {
FileObject nextFo = indexedElement.getFileObject();
try {
Source source = Source.create(nextFo);
if (source != null) {
PHPDocExtractor phpDocExtractor = new PHPDocExtractor(header, indexedElement);
ParserManager.parse(Collections.singleton(source), phpDocExtractor);
result = phpDocExtractor.getPhpDocumentation();
}
} catch (ParseException ex) {
Exceptions.printStackTrace(ex);
}
}
return result;
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
@Override
protected final Long isDirty() {
final FileObject file = getHandle().resolveFileObject(false);
if (file == null) {
return null;
}
final Source source = Source.create(file);
if (source != null) {
Document doc = source.getDocument(false);
if (doc != null) {
return DocumentUtilities.getDocumentTimestamp(doc);
}
}
return null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
public TypeNameResolver createTypeNameResolver(MethodElement method) {
TypeNameResolver result;
if (method.getParameters().isEmpty()) {
result = TypeNameResolverImpl.forNull();
} else {
Model model = ModelUtils.getModel(Source.create(getComponent().getDocument()), 300);
if (model == null) {
result = TypeNameResolverImpl.forNull();
} else {
result = CodegenUtils.createSmarterTypeNameResolver(method, model, getComponent().getCaretPosition());
}
}
return result;
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
public final void update (CharSequence content) throws IOException {
if (content == null) {
update();
} else {
if (filter != null) {
final FileObject file = handle.resolveFileObject(false);
if (file != null) {
final Source source = Source.create(file);
if (source != null && source.getDocument(false) == null) {
content = filter.filterCharSequence(content);
}
}
}
this.text = toString(content);
}
this.tokens = null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-parsing-nb
public void run () {
final Node[] nodes = TopComponent.getRegistry ().getActivatedNodes ();
if (nodes.length == 1) {
final DataObject dataObject = nodes [0].getLookup ().lookup (DataObject.class);
if (dataObject != null && dataObject.isValid()) {
final FileObject fileObject = dataObject.getPrimaryFile ();
if (fileObject.isValid() && ParserManager.canBeParsed(fileObject.getMIMEType())) {
final Source source = Source.create (fileObject);
if (source != null) {
schedule (source, new SchedulerEvent (SelectedNodesScheduler.this) {});
return;
}
}
}
}
schedule(null, null);
}
});
内容来源于网络,如有侵权,请联系作者删除!