Search in sources :

Example 1 with ListConstructorContext

use of com.twosigma.beakerx.groovy.autocomplete.GroovyParser.ListConstructorContext in project beakerx by twosigma.

the class GroovyNameBuilder method exitDeclarationRule.

@Override
public void exitDeclarationRule(DeclarationRuleContext ctx) {
    if (ctx.getChildCount() == 4 && ctx.getChild(0) instanceof TypeDeclarationContext && ctx.getChild(3) instanceof ExpressionContext && ctx.getChild(3).getChildCount() > 0) {
        if (!ctx.getChild(1).getText().contains(".")) {
            if (ctx.getChild(3).getChild(0) instanceof PathExpressionContext) {
                String typpen = ctx.getChild(3).getChild(0).getText().trim();
                AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, ctx.getChild(1).getText());
                registry.addCandidate(c);
                if (GroovyCompletionTypes.debug)
                    logger.info("define variable of type " + ctx.getChild(1).getText() + " " + typpen);
                if (classUtils.getVariableType(typpen) != null) {
                    classUtils.defineVariable(ctx.getChild(1).getText(), classUtils.getVariableType(typpen));
                }
            } else if (ctx.getChild(3).getChild(0) instanceof NewInstanceRuleContext) {
                nameDeclaration(ctx);
            } else {
                if (GroovyCompletionTypes.debug)
                    System.out.println(((ExpressionContext) ctx.getChild(3)).getStart().getType());
                String typpen = null;
                if (ctx.getChild(3) instanceof ListConstructorContext)
                    typpen = "Array";
                else if (ctx.getChild(3) instanceof MapConstructorContext)
                    typpen = "Map";
                else {
                    switch(((ExpressionContext) ctx.getChild(3)).getStart().getType()) {
                        case GroovyLexer.STRING:
                            typpen = "String";
                            break;
                        case GroovyLexer.INTEGER:
                            typpen = "Integer";
                            break;
                        case GroovyLexer.DECIMAL:
                            typpen = "Double";
                            break;
                    }
                }
                AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, ctx.getChild(1).getText());
                registry.addCandidate(c);
                if (GroovyCompletionTypes.debug)
                    logger.info("define variable of type " + ctx.getChild(1).getText() + " " + typpen);
                if (typpen != null)
                    classUtils.defineVariable(ctx.getChild(1).getText(), typpen);
            }
        }
    }
}
Also used : MapConstructorContext(com.twosigma.beakerx.groovy.autocomplete.GroovyParser.MapConstructorContext) AssignmentExpressionContext(com.twosigma.beakerx.groovy.autocomplete.GroovyParser.AssignmentExpressionContext) PathExpressionContext(com.twosigma.beakerx.groovy.autocomplete.GroovyParser.PathExpressionContext) ClassNameExpressionContext(com.twosigma.beakerx.groovy.autocomplete.GroovyParser.ClassNameExpressionContext) ExpressionContext(com.twosigma.beakerx.groovy.autocomplete.GroovyParser.ExpressionContext) AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate) NewInstanceRuleContext(com.twosigma.beakerx.groovy.autocomplete.GroovyParser.NewInstanceRuleContext) PathExpressionContext(com.twosigma.beakerx.groovy.autocomplete.GroovyParser.PathExpressionContext) ListConstructorContext(com.twosigma.beakerx.groovy.autocomplete.GroovyParser.ListConstructorContext) TypeDeclarationContext(com.twosigma.beakerx.groovy.autocomplete.GroovyParser.TypeDeclarationContext)

Aggregations

AutocompleteCandidate (com.twosigma.beakerx.autocomplete.AutocompleteCandidate)1 AssignmentExpressionContext (com.twosigma.beakerx.groovy.autocomplete.GroovyParser.AssignmentExpressionContext)1 ClassNameExpressionContext (com.twosigma.beakerx.groovy.autocomplete.GroovyParser.ClassNameExpressionContext)1 ExpressionContext (com.twosigma.beakerx.groovy.autocomplete.GroovyParser.ExpressionContext)1 ListConstructorContext (com.twosigma.beakerx.groovy.autocomplete.GroovyParser.ListConstructorContext)1 MapConstructorContext (com.twosigma.beakerx.groovy.autocomplete.GroovyParser.MapConstructorContext)1 NewInstanceRuleContext (com.twosigma.beakerx.groovy.autocomplete.GroovyParser.NewInstanceRuleContext)1 PathExpressionContext (com.twosigma.beakerx.groovy.autocomplete.GroovyParser.PathExpressionContext)1 TypeDeclarationContext (com.twosigma.beakerx.groovy.autocomplete.GroovyParser.TypeDeclarationContext)1