本文整理汇总了Java中org.antlr.v4.runtime.ParserRuleContext.inspect方法的典型用法代码示例。如果您正苦于以下问题:Java ParserRuleContext.inspect方法的具体用法?Java ParserRuleContext.inspect怎么用?Java ParserRuleContext.inspect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.ParserRuleContext
的用法示例。
在下文中一共展示了ParserRuleContext.inspect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doAutocomplete
import org.antlr.v4.runtime.ParserRuleContext; //导入方法依赖的package包/类
public AutocompleteResult doAutocomplete(String txt, int cur, ClassLoader l) {
ClassUtils cu = createClassUtils(l);
setup(cu, registry);
registry.clearForType(GroovyCompletionTypes.CUSTOM_TYPE);
registry.clearForType(GroovyCompletionTypes.FIELD);
registry.clearForType(GroovyCompletionTypes.NAME);
addDefaultImports(cu);
moreSetup(cu);
moreSetup(registry);
Lexer lexer = new GroovyLexer(new ANTLRInputStream(txt));
lexer.removeErrorListeners();
CommonTokenStream tokens = new CommonTokenStream(lexer);
// Create a parser that reads from the scanner
GroovyParser parser = new GroovyParser(tokens);
parser.removeErrorListeners();
// start parsing at the compilationUnit rule
ParserRuleContext t = parser.compilationUnit();
ParseTreeWalker walker = new ParseTreeWalker();
List<AutocompleteCandidate> q = new ArrayList<AutocompleteCandidate>();
GroovyImportDeclarationCompletion extractor = new GroovyImportDeclarationCompletion(txt,cur,registry,cps,cu);
GroovyNameBuilder extractor2 = new GroovyNameBuilder(registry,cu );
GroovyNodeCompletion extractor3 = new GroovyNodeCompletion(txt,cur, registry, cu);
walker.walk(extractor, t);
if(extractor.getQuery()!=null)
q.addAll(extractor.getQuery());
walker.walk(extractor2, t);
walker.walk(extractor3, t);
if(extractor3.getQuery()!=null)
q.addAll(extractor3.getQuery());
List<String> ret = registry.searchCandidates(q);
if(ret.isEmpty()) {
q.clear();
for (int i=cur-1; i>=0; i--) {
if(i<txt.length() && Character.isWhitespace(txt.charAt(i))) {
String tx = txt.substring(i+1, cur).trim();
if(!txt.isEmpty()) {
if(tx.contains(".")) {
q.add(cu.expandExpression(tx, registry, cu.DO_ALL));
} else {
q.add(new AutocompleteCandidate(GroovyCompletionTypes.NAME, tx));
}
ret = registry.searchCandidates(q);
}
break;
}
}
}
if(txt.charAt(cur-1)=='.') {
for(int i=0; i<ret.size(); i++) {
String s = ret.get(i);
if(s.startsWith("."))
ret.set(i, s.substring(1));
}
}
// this shows the GUI
if(GroovyCompletionTypes.debug)
t.inspect(parser);
return new AutocompleteResult(ret, getStartIndex(extractor,extractor2,extractor3));
}