本文整理汇总了Java中org.netbeans.modules.parsing.spi.Parser类的典型用法代码示例。如果您正苦于以下问题:Java Parser类的具体用法?Java Parser怎么用?Java Parser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Parser类属于org.netbeans.modules.parsing.spi包,在下文中一共展示了Parser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
public Void run () throws Exception {
final LowMemoryWatcher lMListener = LowMemoryWatcher.getInstance();
Parser parser = null;
final Collection<Snapshot> snapShots = new LazySnapshots(sources);
for (Source source : sources) {
if (parser == null) {
Lookup lookup = MimeLookup.getLookup (source.getMimeType ());
ParserFactory parserFactory = lookup.lookup (ParserFactory.class);
if (parserFactory != null) {
parser = parserFactory.createParser (snapShots);
}
}
final SourceCache uncachedSourceCache = new SourceCache(source, null, parser);
SourceCache origCache = SourceAccessor.getINSTANCE().getAndSetCache(source, uncachedSourceCache);
final ResultIterator resultIterator = new ResultIterator (uncachedSourceCache, parser, userTask);
try {
TaskProcessor.callUserTask(userTask, resultIterator);
} finally {
ResultIteratorAccessor.getINSTANCE().invalidate(resultIterator);
SourceAccessor.getINSTANCE().getAndSetCache(source, origCache);
}
if (lMListener.isLowMemory ())
parser = null;
}
return null;
}
示例2: getParser
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
/** Return a parser for use with this language. A parser is optional (in which
* case getParser() may return null) but in that case a lot of functionality
* will be disabled for this language.
* @todo Clarify whether clients should cache instances of this or if it will
* be called only once and management done by the IDE
*/
@CheckForNull
public Parser getParser(Collection<Snapshot> snapshots) {
Parser parser = null;
if (parserFile != null) {
// Lazily construct Parser
ParserFactory factory = (ParserFactory)createInstance(parserFile);
if (factory == null) {
// Don't keep trying
parserFile = null;
} else {
parser = factory.createParser(snapshots);
}
} else {
getGsfLanguage(); // Also initializes languageConfig
if (languageConfig != null) {
parser = languageConfig.getParser();
}
}
return parser;
}
示例3: checkErrors
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
protected void checkErrors(final String relFilePath) throws Exception {
Source testSource = getTestSource(getTestFile(relFilePath));
ParserManager.parse(Collections.singleton(testSource), new UserTask() {
public @Override void run(ResultIterator resultIterator) throws Exception {
Parser.Result r = resultIterator.getParserResult();
assertNotNull(r);
assertTrue(r instanceof ParserResult);
ParserResult pr = (ParserResult) r;
List<? extends Error> diagnostics = pr.getDiagnostics();
String annotatedSource = annotateErrors(diagnostics);
assertDescriptionMatches(relFilePath, annotatedSource, false, ".errors");
}
});
}
示例4: checkIsIndexable
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
protected void checkIsIndexable(String relFilePath, boolean isIndexable) throws Exception {
final EmbeddingIndexerFactory factory = getIndexerFactory();
assertNotNull("getIndexerFactory must be implemented", factory);
final FileObject fo = getTestFile(relFilePath);
assertNotNull(fo);
final Boolean result [] = new Boolean [] { null };
Source testSource = getTestSource(fo);
ParserManager.parse(Collections.singleton(testSource), new UserTask() {
public @Override void run(ResultIterator resultIterator) throws Exception {
Parser.Result r = resultIterator.getParserResult();
EmbeddingIndexer indexer = factory.createIndexer(
SPIAccessor.getInstance().create(new FileObjectIndexable(fo.getParent(), fo)),
r.getSnapshot());
result[0] = Boolean.valueOf(indexer != null);
}
});
assertNotNull(result[0]);
assertEquals(isIndexable, result[0].booleanValue());
}
示例5: checkOffsets
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
protected void checkOffsets(final String relFilePath, final String caretLine) throws Exception {
Source testSource = getTestSource(getTestFile(relFilePath));
if (caretLine != null) {
int caretOffset = getCaretOffset(testSource.createSnapshot().getText().toString(), caretLine);
enforceCaretOffset(testSource, caretOffset);
}
ParserManager.parse(Collections.singleton(testSource), new UserTask() {
public @Override void run(ResultIterator resultIterator) throws Exception {
Parser.Result r = resultIterator.getParserResult();
assertTrue(r instanceof ParserResult);
ParserResult pr = (ParserResult) r;
List<Object> validNodes = new ArrayList<Object>();
List<Object> invalidNodes = new ArrayList<Object>();
Map<Object,OffsetRange> positions = new HashMap<Object,OffsetRange>();
initializeNodes(pr, validNodes, positions, invalidNodes);
String annotatedSource = annotateOffsets(validNodes, positions, invalidNodes, pr);
assertDescriptionMatches(relFilePath, annotatedSource, false, ".offsets");
}
});
}
示例6: checkTypes
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
protected void checkTypes(final String relFilePath, final String caretLine) throws Exception {
Source testSource = getTestSource(getTestFile(relFilePath));
if (caretLine != null) {
int caretOffset = getCaretOffset(testSource.createSnapshot().getText().toString(), caretLine);
enforceCaretOffset(testSource, caretOffset);
}
ParserManager.parse(Collections.singleton(testSource), new UserTask() {
public @Override void run(ResultIterator resultIterator) throws Exception {
Parser.Result r = resultIterator.getParserResult();
assertTrue(r instanceof ParserResult);
ParserResult pr = (ParserResult) r;
List<Object> nodes = new ArrayList<Object>();
Map<Object,String> types = new HashMap<Object,String>();
Map<Object,OffsetRange> positions = new HashMap<Object,OffsetRange>();
initializeTypeNodes(pr, nodes, positions, types);
String annotatedSource = annotateTypes(nodes, positions, types, pr);
assertDescriptionMatches(relFilePath, annotatedSource, false, ".types");
}
});
}
示例7: testParserInvocation
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
public void testParserInvocation() throws Exception {
Source fxmlSource = Source.create(document);
ParserManager.parse(Collections.singleton(fxmlSource), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
Parser.Result result = resultIterator.getParserResult();
if (result instanceof FxmlParserResult) {
FxmlParserResult fxResult = (FxmlParserResult)result;
appendParsedTree(fxResult, report);
appendErrors(fxResult, report);
assertContents(report);
}
}
});
}
示例8: create
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
public static CssFileModel create(Source source) throws ParseException {
final AtomicReference<CssFileModel> model = new AtomicReference<>();
ParserManager.parse(Collections.singletonList(source), new UserTask() {
@Override
public void run(ResultIterator resultIterator) throws Exception {
ResultIterator cssRi = WebUtils.getResultIterator(resultIterator, CssLanguage.CSS_MIME_TYPE);
Snapshot topLevelSnapshot = resultIterator.getSnapshot();
if(cssRi != null) {
Parser.Result parserResult = cssRi.getParserResult();
if(parserResult != null) {
model.set(new CssFileModel((CssParserResult)parserResult, topLevelSnapshot));
return ;
}
}
model.set(new CssFileModel(topLevelSnapshot));
}
});
return model.get();
}
示例9: update
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
synchronized void update(
final Class<? extends ParserResultTask<? extends Parser.Result>> task,
final SchedulerEvent event) {
LOG.log(
Level.FINE,
"UPDATE: {0} {1}", //NOI18N
new Object[]{
task.getSimpleName(),
event
});
if (event instanceof BaseScheduler.Event) {
final Long expectedId = toExpect.get(task);
if (expectedId != null && expectedId == ((BaseScheduler.Event)event).getId()) {
toExpect.remove(task);
notify();
}
}
}
示例10: createParserTask
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
@Override
protected ParserResultTask createParserTask(FileObject file, FoldProcessor processor) {
final ParserResultTask wrapped = super.createParserTask(file, processor);
return new JavaParserResultTask(JavaSource.Phase.RESOLVED, TaskIndexingMode.ALLOWED_DURING_SCAN) {
@Override
public void run(Parser.Result result, SchedulerEvent event) {
wrapped.run(result, event);
}
@Override
public int getPriority() {
return wrapped.getPriority();
}
@Override
public Class<? extends Scheduler> getSchedulerClass() {
return wrapped.getSchedulerClass();
}
@Override
public void cancel() {
wrapped.cancel();
}
};
}
示例11: findMimeParser
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
public Parser findMimeParser(Lookup context, final String mimeType) {
Parser p = null;
final Reference<Parser> ref = cachedParsers.get (mimeType);
if (ref != null) {
p = ref.get();
}
if (p == null) {
final Lookup lookup = MimeLookup.getLookup (mimeType);
final ParserFactory parserFactory = lookup.lookup (ParserFactory.class);
if (parserFactory == null) {
throw new IllegalArgumentException("No parser for mime type: " + mimeType);
}
p = parserFactory.createParser(Collections.<Snapshot>emptyList());
cachedParsers.put(mimeType, new SoftReference<Parser>(p));
}
return p;
}
示例12: index
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
@Override
protected void index(Indexable indexable, Parser.Result parserResult, Context context) {
try {
final IndexingSupport support = IndexingSupport.getInstance(context);
support.removeDocuments(indexable);
final IndexDocument doc = support.createDocument(indexable);
doc.addPair(
"valid", //NOI18N
((TopParser.TopResult)parserResult).isValid() ? Boolean.TRUE.toString() : Boolean.FALSE.toString(),
false,
true);
support.addDocument(doc);
} catch (IOException ioe) {
Exceptions.printStackTrace(ioe);
}
}
示例13: index
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
@Override
protected void index(Indexable indexable, Parser.Result parserResult, Context context) {
try {
System.out.println("EMB: " + parserResult.getSnapshot().getText());
IndexingSupport is = IndexingSupport.getInstance(context);
if (!indexable.equals(f.lastIndexable)) {
is.removeDocuments(indexable);
f.lastIndexable = indexable;
}
final IndexDocument doc = is.createDocument(indexable);
doc.addPair(
"key", //NOI18N
parserResult.getSnapshot().getText().toString(),
true,
true);
is.addDocument(doc);
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
示例14: findMimeParser
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
@Override
public synchronized Parser findMimeParser(Lookup context, String mimeType) {
Reference<Parser> rp = cachedParsers.get(mimeType);
Parser p = null;
if (rp != null) {
p = rp.get();
}
if (p != null) {
return p;
}
ParserFactory f = MimeLookup.getLookup(mimeType).lookup(ParserFactory.class);
if (f != null) {
p = f.createParser(Collections.<Snapshot>emptyList());
} else {
p = MimeLookup.getDefault().lookup(ParserFactory.class).createParser(Collections.<Snapshot>emptyList());
}
cachedParsers.put(mimeType, new WeakReference<>(p));
return p;
}
示例15: get
import org.netbeans.modules.parsing.spi.Parser; //导入依赖的package包/类
/**
* Returns an instance of the {@link WorkingCopy} for
* given {@link Parser.Result} if it is a result
* of a java parser.
* @param result for which the {@link WorkingCopy} should be
* returned.
* @return a {@link WorkingCopy} or null when the given result
* is not a result of java parsing.
* @since 0.42
*/
public static @NullUnknown WorkingCopy get (final @NonNull Parser.Result result) {
Parameters.notNull("result", result); //NOI18N
WorkingCopy copy = instance != null ? instance.get() : null;
if (copy != null && result instanceof JavacParserResult) {
final JavacParserResult javacResult = (JavacParserResult)result;
CompilationController controller = javacResult.get(CompilationController.class);
if (controller != null && controller.impl == copy.impl)
return copy;
}
return null;
}