use of com.twosigma.beakerx.groovy.autocomplete.GroovyParser.PathExpressionContext 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);
}
}
}
}
Aggregations