Search in sources :

Example 1 with ClassUtils

use of com.twosigma.beakerx.autocomplete.ClassUtils in project beakerx by twosigma.

the class JavaAutocomplete method find.

private AutocompleteResult find(String txt, int cur, ClassLoader l, Imports imports) {
    registry = AutocompleteRegistryFactory.createRegistry(cps);
    ClassUtils cu = createClassUtils(l);
    setup(cu, registry);
    AutocompleteRegistryFactory.addDefaultImports(cu, registry, imports.toListOfStrings(), cps);
    Lexer lexer = new JavaLexer(new ANTLRInputStream(txt));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    // Create a parser that reads from the scanner
    JavaParser parser = new JavaParser(tokens);
    parser.removeErrorListeners();
    // start parsing at the compilationUnit rule
    ParserRuleContext t = parser.compilationUnit();
    ParseTreeWalker walker = new ParseTreeWalker();
    List<AutocompleteCandidate> q = new ArrayList<AutocompleteCandidate>();
    JavaImportDeclarationCompletion extractor = new JavaImportDeclarationCompletion(txt, cur, registry, cps, cu);
    JavaNameBuilder extractor2 = new JavaNameBuilder(registry, cu);
    JavaNodeCompletion extractor3 = new JavaNodeCompletion(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()) {
        return new AutocompleteResult(ret, getStartIndex(extractor, extractor2, extractor3));
    }
    return findAutocompleteResult(txt, cur, cu);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) ParserRuleContext(org.antlr.v4.runtime.ParserRuleContext) ArrayList(java.util.ArrayList) ClassUtils(com.twosigma.beakerx.autocomplete.ClassUtils) Lexer(org.antlr.v4.runtime.Lexer) AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) AutocompleteResult(com.twosigma.beakerx.autocomplete.AutocompleteResult)

Aggregations

AutocompleteCandidate (com.twosigma.beakerx.autocomplete.AutocompleteCandidate)1 AutocompleteResult (com.twosigma.beakerx.autocomplete.AutocompleteResult)1 ClassUtils (com.twosigma.beakerx.autocomplete.ClassUtils)1 ArrayList (java.util.ArrayList)1 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 Lexer (org.antlr.v4.runtime.Lexer)1 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)1 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)1