Search in sources :

Example 31 with AutocompleteCandidate

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

the class JavaNameBuilder method exitFieldDeclaration.

@Override
public void exitFieldDeclaration(FieldDeclarationContext ctx) {
    String type = null;
    TypeContext ty = ctx.getRuleContext(TypeContext.class, 0);
    if (ty != null) {
        ClassOrInterfaceTypeContext t = ty.getRuleContext(ClassOrInterfaceTypeContext.class, 0);
        if (t != null) {
            type = t.getText();
        } else {
            PrimitiveTypeContext pt = ty.getRuleContext(PrimitiveTypeContext.class, 0);
            if (pt != null)
                type = pt.getText();
        }
    }
    List<VariableDeclaratorsContext> vars = ctx.getRuleContexts(VariableDeclaratorsContext.class);
    VariableDeclaratorContext v;
    for (VariableDeclaratorsContext vc : vars) {
        v = vc.getRuleContext(VariableDeclaratorContext.class, 0);
        if (v != null) {
            VariableDeclaratorIdContext vi = v.getRuleContext(VariableDeclaratorIdContext.class, 0);
            if (vi.getChildCount() > 0) {
                // System.out.println("VAR "+vi.getChild(0).getText()+" of type "+type);
                AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.NAME, vi.getChild(0).getText());
                registry.addCandidate(c);
                if (type != null) {
                    classUtils.defineVariable(vi.getChild(0).getText(), type);
                }
            }
        }
    }
}
Also used : VariableDeclaratorsContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.VariableDeclaratorsContext) VariableDeclaratorContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.VariableDeclaratorContext) VariableDeclaratorIdContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.VariableDeclaratorIdContext) ClassOrInterfaceTypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.ClassOrInterfaceTypeContext) PrimitiveTypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.PrimitiveTypeContext) AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate) TypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.TypeContext) ClassOrInterfaceTypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.ClassOrInterfaceTypeContext) PrimitiveTypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.PrimitiveTypeContext)

Example 32 with AutocompleteCandidate

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

the class JavaNameBuilder method exitLocalVariableDeclaration.

@Override
public void exitLocalVariableDeclaration(LocalVariableDeclarationContext ctx) {
    String type = null;
    TypeContext ty = ctx.getRuleContext(TypeContext.class, 0);
    if (ty != null) {
        ClassOrInterfaceTypeContext t = ty.getRuleContext(ClassOrInterfaceTypeContext.class, 0);
        if (t != null) {
            type = t.getText();
        } else {
            PrimitiveTypeContext pt = ty.getRuleContext(PrimitiveTypeContext.class, 0);
            if (pt != null)
                type = pt.getText();
        }
    }
    List<VariableDeclaratorsContext> vars = ctx.getRuleContexts(VariableDeclaratorsContext.class);
    for (VariableDeclaratorsContext vc : vars) {
        List<VariableDeclaratorContext> v = vc.getRuleContexts(VariableDeclaratorContext.class);
        if (v != null) {
            for (VariableDeclaratorContext v2 : v) {
                VariableDeclaratorIdContext vi = v2.getRuleContext(VariableDeclaratorIdContext.class, 0);
                if (vi.getChildCount() > 0) {
                    // System.out.println("VAR "+vi.getChild(0).getText()+" of type "+type);
                    AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.NAME, vi.getChild(0).getText());
                    registry.addCandidate(c);
                    if (type != null) {
                        classUtils.defineVariable(vi.getChild(0).getText(), type);
                    }
                }
            }
        }
    }
}
Also used : VariableDeclaratorsContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.VariableDeclaratorsContext) VariableDeclaratorContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.VariableDeclaratorContext) VariableDeclaratorIdContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.VariableDeclaratorIdContext) ClassOrInterfaceTypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.ClassOrInterfaceTypeContext) PrimitiveTypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.PrimitiveTypeContext) AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate) TypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.TypeContext) ClassOrInterfaceTypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.ClassOrInterfaceTypeContext) PrimitiveTypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.PrimitiveTypeContext)

Example 33 with AutocompleteCandidate

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

the class JavaNameBuilder method exitMethodDeclaration.

@Override
public void exitMethodDeclaration(MethodDeclarationContext ctx) {
    if (ctx.getChildCount() >= 3 && ctx.getChild(1) instanceof TerminalNodeImpl) {
        String type = null;
        TypeContext ty = ctx.getRuleContext(TypeContext.class, 0);
        if (ty != null) {
            ClassOrInterfaceTypeContext t = ty.getRuleContext(ClassOrInterfaceTypeContext.class, 0);
            if (t != null) {
                type = t.getText();
            } else {
                PrimitiveTypeContext pt = ty.getRuleContext(PrimitiveTypeContext.class, 0);
                if (pt != null)
                    type = pt.getText();
            }
        }
        AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.NAME, ctx.getChild(1).getText());
        registry.addCandidate(c);
        if (type != null) {
            classUtils.defineVariable(ctx.getChild(1).getText(), type);
        }
    }
}
Also used : ClassOrInterfaceTypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.ClassOrInterfaceTypeContext) PrimitiveTypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.PrimitiveTypeContext) AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate) TerminalNodeImpl(org.antlr.v4.runtime.tree.TerminalNodeImpl) TypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.TypeContext) ClassOrInterfaceTypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.ClassOrInterfaceTypeContext) PrimitiveTypeContext(com.twosigma.beakerx.javash.autocomplete.JavaParser.PrimitiveTypeContext)

Example 34 with AutocompleteCandidate

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

the class AutocompleteRegistryFactory method createRegistry.

public static AutocompleteRegistry createRegistry(GroovyClasspathScanner cps) {
    AutocompleteRegistry registry = AutocompleteRegistryFactory.create(GroovyCompletionTypes.NUM_TYPES);
    for (String pkg : cps.getPackages()) {
        String[] pkgv = pkg.split("\\.");
        AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.PACKAGE_NAME, pkgv);
        registry.addCandidate(c);
        List<String> cls = cps.getClasses(pkg);
        if (cls != null && !cls.isEmpty()) {
            c = new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, pkgv);
            AutocompleteCandidate l = c;
            while (l.hasChildren()) {
                l = l.getChildrens().get(0);
            }
            for (String cl : cls) {
                l.addChildren(new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, cl));
            }
            registry.addCandidate(c);
        }
    }
    return registry;
}
Also used : AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate) AutocompleteRegistry(com.twosigma.beakerx.autocomplete.AutocompleteRegistry)

Example 35 with AutocompleteCandidate

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

the class AutocompleteRegistryFactory method addDefaultImports.

public static void addDefaultImports(ClassUtils cu, AutocompleteRegistry registry, List<String> imports, GroovyClasspathScanner cps) {
    for (String imp : imports) {
        // this imports using '*'
        if (imp.endsWith(".*")) {
            String st = imp.substring(0, imp.length() - 2);
            String[] txtv = st.split("\\.");
            AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.PACKAGE_NAME, txtv);
            registry.addCandidate(c);
            List<String> cls = cps.getClasses(st);
            if (cls != null) {
                c = new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, txtv);
                AutocompleteCandidate l = c.findLeaf();
                for (String s : cls) {
                    l.addChildren(new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, s));
                    registry.addCandidate(new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, s));
                    cu.defineClassShortName(s, st + "." + s);
                }
                registry.addCandidate(c);
            }
        } else {
            createImportAutocompleteCandidate(cu, registry, imp);
        }
    }
}
Also used : AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate)

Aggregations

AutocompleteCandidate (com.twosigma.beakerx.autocomplete.AutocompleteCandidate)39 AutocompleteResult (com.twosigma.beakerx.autocomplete.AutocompleteResult)4 ArrayList (java.util.ArrayList)4 AutocompleteRegistryFactory.createImportAutocompleteCandidate (com.twosigma.beakerx.groovy.autocomplete.AutocompleteRegistryFactory.createImportAutocompleteCandidate)3 AutocompleteRegistryFactory.createImportAutocompleteCandidate (com.twosigma.beakerx.javash.autocomplete.AutocompleteRegistryFactory.createImportAutocompleteCandidate)3 ClassOrInterfaceTypeContext (com.twosigma.beakerx.javash.autocomplete.JavaParser.ClassOrInterfaceTypeContext)3 PrimitiveTypeContext (com.twosigma.beakerx.javash.autocomplete.JavaParser.PrimitiveTypeContext)3 TypeContext (com.twosigma.beakerx.javash.autocomplete.JavaParser.TypeContext)3 ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 AutocompleteRegistry (com.twosigma.beakerx.autocomplete.AutocompleteRegistry)2 VariableDeclaratorContext (com.twosigma.beakerx.javash.autocomplete.JavaParser.VariableDeclaratorContext)2 VariableDeclaratorIdContext (com.twosigma.beakerx.javash.autocomplete.JavaParser.VariableDeclaratorIdContext)2 VariableDeclaratorsContext (com.twosigma.beakerx.javash.autocomplete.JavaParser.VariableDeclaratorsContext)2 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)2 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)2 Lexer (org.antlr.v4.runtime.Lexer)2 ParserRuleContext (org.antlr.v4.runtime.ParserRuleContext)2 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)2 ClassUtils (com.twosigma.beakerx.autocomplete.ClassUtils)1 AssignmentExpressionContext (com.twosigma.beakerx.groovy.autocomplete.GroovyParser.AssignmentExpressionContext)1