當前位置: 首頁>>代碼示例>>Java>>正文


Java ParserRuleContext.inspect方法代碼示例

本文整理匯總了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));
}
 
開發者ID:twosigma,項目名稱:beaker-notebook-archive,代碼行數:68,代碼來源:GroovyAutocomplete.java


注:本文中的org.antlr.v4.runtime.ParserRuleContext.inspect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。