Search in sources :

Example 36 with AutocompleteCandidate

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

the class AutocompleteRegistryFactory method createImportAutocompleteCandidate.

public static void createImportAutocompleteCandidate(ClassUtils cu, AutocompleteRegistry registry, String imp) {
    String[] txtv = imp.split("\\.");
    AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.PACKAGE_NAME, txtv, txtv.length - 1);
    registry.addCandidate(c);
    c = new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, txtv);
    registry.addCandidate(c);
    c = new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, txtv[txtv.length - 1]);
    registry.addCandidate(c);
    cu.defineClassShortName(txtv[txtv.length - 1], imp);
}
Also used : AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate)

Example 37 with AutocompleteCandidate

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

the class GroovyNodeCompletion method exitPathExpression.

@Override
public void exitPathExpression(PathExpressionContext ctx) {
    if (ctx.getStart().getStartIndex() < cursor && ctx.getStop().getStopIndex() + 1 >= cursor) {
        // it might be import
        if (ctx.getParent().getChild(0).equals(ctx) && ctx.getParent().getParent() != null && ctx.getParent().getParent() instanceof StatementContext && ctx.getParent().getParent().getChild(0).equals(ctx.getParent())) {
            AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.TOPLEVEL, ctx.getText());
            addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
        }
        // // try to expand this as a path expression
        if (ctx.getText().contains(".")) {
            addQuery(classUtils.expandExpression(ctx.getText(), registry, classUtils.DO_NON_STATIC), AutocompleteGroovyResult.getStartIndex(ctx));
            // complete with standard groovy extension functions
            AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.STDFUNCS, ctx.getText().substring(ctx.getText().lastIndexOf(".") + 1));
            addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
            addQuery(classUtils.expandExpression(ctx.getText(), registry, classUtils.DO_ALL), AutocompleteGroovyResult.getStartIndex(ctx));
        } else {
            AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, ctx.getText());
            addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
            c = new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, ctx.getText());
            addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
        }
    }
}
Also used : AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate) StatementContext(com.twosigma.beakerx.groovy.autocomplete.GroovyParser.StatementContext)

Example 38 with AutocompleteCandidate

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

the class GroovyNodeCompletion method exitCompilationUnit.

// @Override
// public void visitErrorNode(ErrorNode arg0) {
// if (arg0.getSymbol().getStartIndex() < cursor && arg0.getSymbol().getStopIndex() + 1 >= cursor) {
// //System.out.println("ERR: "+arg0.getSymbol().getStartIndex()+" "+arg0.getSymbol().getStopIndex()+" "+arg0.getSymbol().getText());
// ParseTree cuc = arg0.getParent();
// if (cuc.getChild(0).equals(arg0)) {
// AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.INITIAL, arg0.getText());
// addQuery(c, 0);
// } else {
// AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.TOPLEVEL, arg0.getText());
// addQuery(c, 0);
// }
// if (cuc instanceof GroovyParser.StatementContext && ((GroovyParser.StatementContext) cuc).getStop().getStopIndex() + 1 == cursor) {
// if (cuc.getText().contains(".")) {
// addQuery(classUtils.expandExpression(cuc.getText(), registry, classUtils.DO_ALL), cursor);
// // complete with standard groovy extension functions
// AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.STDFUNCS, cuc.getText().substring(cuc.getText().lastIndexOf(".") + 1));
// addQuery(c, cursor);
// } else {
// AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, cuc.getText());
// addQuery(c, 0);
// c = new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, cuc.getText());
// addQuery(c, 0);
// }
// }
// }
// }
// 
// 
// private RuleContext findParentNode(RuleContext ctx, Class<?> classtype) {
// RuleContext p = ctx.getParent();
// while (p != null) {
// if (p.getClass().equals(classtype)) {
// return p;
// }
// p = p.getParent();
// }
// return null;
// }
// 
// private ParseTree findLeftSibling(RuleContext ctx) {
// RuleContext p = ctx.getParent();
// if (p != null) {
// for (int i = 0; i < p.getChildCount(); i++) {
// if (p.getChild(i).equals(ctx)) {
// if (i > 0)
// return p.getChild(i - 1);
// break;
// }
// }
// }
// return null;
// }
@Override
public void exitCompilationUnit(CompilationUnitContext ctx) {
    if (ctx.getStop() != null && ctx.getStop().getStopIndex() + 1 == cursor) {
        // if (ctx.getChildCount() > 0) {
        // String t = ctx.getChild(ctx.getChildCount() - 2).getText();
        // if (t.endsWith("\n")) {
        // String txt = ctx.getChild(ctx.getChildCount() - 1).getText();
        // if (txt.contains(".")) {
        // addQuery(classUtils.expandExpression(txt, registry, classUtils.DO_ALL), AutocompleteGroovyResult.getStartIndex(ctx));
        // } else {
        // AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.TOPLEVEL, txt);
        // addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
        // c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, txt);
        // addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
        // }
        // } else {
        // for (int i = ctx.getChildCount() - 1; i >= 0; i--) {
        // if (!ctx.getChild(i).getText().isEmpty() && !ctx.getChild(i).getText().equals("<EOF>")) {
        // String txt = ctx.getChild(i).getText();
        // if (txt.contains(".")) {
        // addQuery(classUtils.expandExpression(txt, registry, classUtils.DO_ALL), AutocompleteGroovyResult.getStartIndex(ctx));
        // } else {
        // AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, txt);
        // addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
        // }
        // break;
        // }
        // }
        // }
        // }
        String t = removeEOF(ctx.getText());
        addQuery(classUtils.expandExpression(t, registry, classUtils.DO_ALL), calculateStartIndex(t, ctx));
        String[] txtv = splitByDot(t);
        AutocompleteCandidate c2 = new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, txtv);
        addQuery(c2, calculateStartIndex(t, ctx));
    }
}
Also used : AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate)

Example 39 with AutocompleteCandidate

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

the class GroovyNodeCompletion method exitClassNameExpression.

@Override
public void exitClassNameExpression(ClassNameExpressionContext ctx) {
    if (ctx.getStart().getStartIndex() < cursor && ctx.getStop().getStopIndex() + 1 >= cursor) {
        if (ctx.getText().contains(".")) {
            addQuery(classUtils.expandExpression(ctx.getText(), registry, classUtils.DO_STATIC), AutocompleteGroovyResult.getStartIndex(ctx));
            // complete with standard groovy extension functions
            AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.STDFUNCS, ctx.getText().substring(ctx.getText().lastIndexOf(".") + 1));
            addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
            completeClassFromPath(ctx);
        } else {
            AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, ctx.getText());
            addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
            c = new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, ctx.getText());
            addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
        }
    }
}
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