当前位置: 首页>>代码示例>>Java>>正文


Java Parser类代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ParserManager.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:Language.java

示例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");
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:CslTestBase.java

示例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());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:CslTestBase.java

示例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");
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:CslTestBase.java

示例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");
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:CslTestBase.java

示例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);
            }
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:FxmlParserTest.java

示例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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:CssFileModel.java

示例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();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:SchedulerEventTest.java

示例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();
        }
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ResourceStringFoldProvider.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:DataObjectEnvFactory.java

示例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);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:EmbeddedIndexerTest.java

示例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);
    }

    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:QuerySupportLifeLock230220Test.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:TestEnvironmentFactory.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:WorkingCopy.java


注:本文中的org.netbeans.modules.parsing.spi.Parser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。