Search in sources :

Example 1 with PrimitiveTypeContext

use of com.twosigma.beakerx.javash.autocomplete.JavaParser.PrimitiveTypeContext 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 2 with PrimitiveTypeContext

use of com.twosigma.beakerx.javash.autocomplete.JavaParser.PrimitiveTypeContext 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 3 with PrimitiveTypeContext

use of com.twosigma.beakerx.javash.autocomplete.JavaParser.PrimitiveTypeContext 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)

Aggregations

AutocompleteCandidate (com.twosigma.beakerx.autocomplete.AutocompleteCandidate)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 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 TerminalNodeImpl (org.antlr.v4.runtime.tree.TerminalNodeImpl)1