本文整理了Java中org.netbeans.modules.parsing.api.Source
类的一些代码示例,展示了Source
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Source
类的具体详情如下:
包路径:org.netbeans.modules.parsing.api.Source
类名称:Source
暂无
代码示例来源: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-javascript2-model
String getUnigueNameForAnonymObject(ParserResult parserResult) {
FileObject fo = parserResult.getSnapshot().getSource().getFileObject();
if (fo != null) {
return fo.getName() + ANONYMOUS_OBJECT_NAME_START + anonymObjectCount++;
}
return ANONYMOUS_OBJECT_NAME_START + anonymObjectCount++;
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
/**
* Returns {@link Document} of this {@link CompilationInfoImpl}
* @return Document or null when the {@link DataObject} doesn't
* exist or has no {@link EditorCookie}.
* @throws java.io.IOException
*/
public Document getDocument() {
if (this.file == null) {
return null;
}
if (!this.file.isValid()) {
return null;
}
Source source = this.snapshot != null ? this.snapshot.getSource() : null;
if (source != null) {
return source.getDocument(false);
}
return null;
}
代码示例来源: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
FileObject fo = FileUtil.toFileObject(file);
if (fo != null) {
Source source = Source.create(fo);
if (GroovyLanguage.GROOVY_MIME_TYPE.equals(source.getMimeType())) {
try {
ParserManager.parse(Collections.singleton(source), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
Exceptions.printStackTrace(ex);
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
try {
final Rectangle caretRectangle = target.modelToView(target.getCaretPosition());
final Font font = target.getFont();
final Point where = new Point(caretRectangle.x, caretRectangle.y + caretRectangle.height);
SwingUtilities.convertPointToScreen(where, target);
final int position = target.getCaretPosition();
try {
ParserManager.parse(Collections.singleton(Source.create(target.getDocument())), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
ParserResult info = (ParserResult) resultIterator.getParserResult();
if (info != null) {
importItem(info, where, caretRectangle, font, position);
}
}
});
} catch (ParseException ex) {
Exceptions.printStackTrace(ex);
}
} catch (BadLocationException ex) {
ErrorManager.getDefault().notify(ex);
}
}
代码示例来源: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
@CheckForNull
public Collection<Occurence> occurences(FileObject fileObject) {
final Set<Occurence> retval = new TreeSet<>(new Comparator<Occurence>() {
@Override
public int compare(Occurence o1, Occurence o2) {
return o1.getOccurenceRange().compareTo(o2.getOccurenceRange());
}
});
if (fileObject != null && fileObject.isValid()) {
try {
ParserManager.parse(Collections.singleton(Source.create(fileObject)), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
Result parameter = resultIterator.getParserResult();
if (parameter != null && parameter instanceof PHPParseResult) {
Model model = ModelFactory.getModel((PHPParseResult) parameter);
ModelVisitor modelVisitor = model.getModelVisitor();
retval.addAll(modelVisitor.getOccurence(element));
}
}
});
} catch (org.netbeans.modules.parsing.spi.ParseException ex) {
Exceptions.printStackTrace(ex);
}
}
return retval;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-parsing-nb
) {
JTextComponent editor = EditorRegistry.focusedComponent ();
if (editor == currentEditor || (editor != null && editor.getClientProperty("AsTextField") != null)) { //NOI18N
return;
currentEditor.removePropertyChangeListener(this);
Document document = currentEditor.getDocument ();
FileObject fileObject = DataObjectEnvFactory.getFileObject (document);
if (fileObject == null) {
final Document document = currentEditor.getDocument();
final FileObject fileObject = DataObjectEnvFactory.getFileObject(document);
if (fileObject != null && fileObject.isValid()) {
final Source src = Source.create(document);
schedule(src, new SchedulerEvent(this){});
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-parsing-nb
private void editorRegistryChanged() {
final JTextComponent editor = EditorRegistry.lastFocusedComponent();
final JTextComponent lastEditor = lastEditorRef == null ? null : lastEditorRef.get();
if (lastEditor != editor && (editor == null || editor.getClientProperty("AsTextField") == null)) {
if (lastEditor != null) {
lastEditor.removeCaretListener(this);
lastEditor.removePropertyChangeListener(this);
k24.set(false);
}
lastEditorRef = new WeakReference<JTextComponent>(editor);
if (editor != null) {
editor.addCaretListener(this);
editor.addPropertyChangeListener(this);
}
final JTextComponent focused = EditorRegistry.focusedComponent();
if (focused != null) {
final Document doc = editor.getDocument();
final String mimeType = DocumentUtilities.getMimeType (doc);
if (doc != null && mimeType != null) {
final Source source = Source.create (doc);
if (source != null) {
((EventSupport)SourceEnvironment.forSource(source)).resetState(true, false, -1, -1, true);
}
}
}
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javascript-refactoring
public static CloneableEditorSupport findCloneableEditorSupport(JsParseResult info) {
DataObject dob = null;
try {
dob = DataObject.find(info.getSnapshot().getSource().getFileObject());
} catch (DataObjectNotFoundException ex) {
Exceptions.printStackTrace(ex);
}
return RetoucheUtils.findCloneableEditorSupport(dob);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-parsing-nb
protected void setEditor (JTextComponent editor) {
if (currentEditor != null)
currentEditor.removeCaretListener (caretListener);
currentEditor = editor;
if (editor != null) {
if (caretListener == null)
caretListener = new ACaretListener ();
editor.addCaretListener (caretListener);
Document document = editor.getDocument ();
if (currentDocument == document) return;
currentDocument = document;
final Source source = Source.create (currentDocument);
schedule (source, new CursorMovedSchedulerEvent (this, editor.getCaret ().getDot (), editor.getCaret ().getMark ()) {});
}
else {
currentDocument = null;
schedule(null, null);
}
}
代码示例来源: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
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.modules/org-netbeans-modules-javascript-hints
if (/*node.getType() == Token.EMPTY && */!JsTokenId.JAVASCRIPT_MIME_TYPE.equals(info.getSnapshot().getSource().getMimeType())) {
setContextRemove(context);
return;
Exceptions.printStackTrace(ex);
range = OffsetRange.NONE;
Hint desc = new Hint(this, message, info.getSnapshot().getSource().getFileObject(), range, fixList, 500);
result.add(desc);
代码示例来源: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-css-prep
return false;
Source source = Source.create(context.document);
Snapshot snapshot = source.createSnapshot();
Exceptions.printStackTrace(ex);
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
BaseDocument document = (BaseDocument) info.getSnapshot().getSource().getDocument(false);
if (!importInPreviousLine) {
TokenSequence<PHPTokenId> ts = LexUtilities.getPHPTokenSequence(document, position);
Exceptions.printStackTrace(ex);
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javascript2-model
public ModelVisitor(ParserResult parserResult, OccurrenceBuilder occurrenceBuilder) {
super();
FileObject fileObject = parserResult.getSnapshot().getSource().getFileObject();
this.modelBuilder = new ModelBuilder(JsFunctionImpl.createGlobal(
fileObject, Integer.MAX_VALUE, parserResult.getSnapshot().getMimeType()));
this.occurrenceBuilder = occurrenceBuilder;
this.parserResult = parserResult;
this.scriptName = fileObject != null ? fileObject.getName().replace('.', '_') : "";
lc = getLexicalContext();
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-source-base
@Override
public JavacParser createParser(final Collection<Snapshot> snapshots) {
assert snapshots != null;
if (snapshots.size() == 1) {
final FileObject fo = snapshots.iterator().next().getSource().getFileObject();
try {
if (fo == null) {
return null;
}
if (fo.getFileSystem().isDefault() && fo.getAttribute("javax.script.ScriptEngine") != null //NOI18N
&& fo.getAttribute("template") == Boolean.TRUE) { //NOI18N
// Do not create javac parser for templates
return null;
}
} catch (FileStateInvalidException fsie) {}
}
JavacParser parser = new JavacParser(snapshots, false);
if (TIMER.isLoggable(Level.FINE)) {
LogRecord rec = new LogRecord(Level.FINE, "JavacParser");
rec.setParameters(new Object[] { parser });
TIMER.log(rec);
}
return parser;
}
内容来源于网络,如有侵权,请联系作者删除!