Search in sources :

Example 1 with VariableDeclaratorsContext

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

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

Aggregations

AutocompleteCandidate (com.twosigma.beakerx.autocomplete.AutocompleteCandidate)2 ClassOrInterfaceTypeContext (com.twosigma.beakerx.javash.autocomplete.JavaParser.ClassOrInterfaceTypeContext)2 PrimitiveTypeContext (com.twosigma.beakerx.javash.autocomplete.JavaParser.PrimitiveTypeContext)2 TypeContext (com.twosigma.beakerx.javash.autocomplete.JavaParser.TypeContext)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