本文整理匯總了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));
}