Search in sources :

Example 26 with AutocompleteCandidate

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

the class JavaImportDeclarationCompletion method importPackageName.

private void importPackageName(ImportDeclarationContext ctx) {
    String st = ctx.getText();
    st = removeImportWord(st);
    String[] txtv = st.split("\\.");
    AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.PACKAGE_NAME, txtv);
    addQuery(c, AutocompleteJavaResult.getStartIndex(ctx));
    c = new AutocompleteCandidate(JavaCompletionTypes.FQ_TYPE, txtv);
    addQuery(c, AutocompleteJavaResult.getStartIndex(ctx));
}
Also used : AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate) AutocompleteRegistryFactory.createImportAutocompleteCandidate(com.twosigma.beakerx.javash.autocomplete.AutocompleteRegistryFactory.createImportAutocompleteCandidate)

Example 27 with AutocompleteCandidate

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

the class GroovyImportDeclarationCompletion method importPackageNameAfterDot.

private void importPackageNameAfterDot(ImportStatementContext ctx) {
    String st = ctx.getText();
    st = removeImportWord(st);
    if (GroovyCompletionTypes.debug)
        logger.info("wants next package name for {}", st);
    String[] txtv = (st + "X").split("\\.");
    txtv[txtv.length - 1] = EMPTY_NODE;
    AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.PACKAGE_NAME, txtv);
    addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx) + 1);
    c = new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, txtv);
    addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx) + 1);
}
Also used : AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate) AutocompleteRegistryFactory.createImportAutocompleteCandidate(com.twosigma.beakerx.groovy.autocomplete.AutocompleteRegistryFactory.createImportAutocompleteCandidate)

Example 28 with AutocompleteCandidate

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

the class GroovyImportDeclarationCompletion method importPackageName.

private void importPackageName(ImportStatementContext ctx) {
    String st = ctx.getText();
    st = removeImportWord(st);
    if (GroovyCompletionTypes.debug)
        logger.info("wants to finish package name for {}", st);
    String[] txtv = st.split("\\.");
    AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.PACKAGE_NAME, txtv);
    addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
    c = new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, txtv);
    addQuery(c, AutocompleteGroovyResult.getStartIndex(ctx));
}
Also used : AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate) AutocompleteRegistryFactory.createImportAutocompleteCandidate(com.twosigma.beakerx.groovy.autocomplete.AutocompleteRegistryFactory.createImportAutocompleteCandidate)

Example 29 with AutocompleteCandidate

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

the class GroovyImportDeclarationCompletion method importWithWildcard.

private void importWithWildcard(String st) {
    String[] txtv = st.split("\\.");
    AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.PACKAGE_NAME, txtv);
    registry.addCandidate(c);
    st = st.substring(0, st.length() - 2);
    List<String> cls = cps.getClasses(st);
    if (cls != null) {
        c = new AutocompleteCandidate(GroovyCompletionTypes.FQ_TYPE, txtv);
        AutocompleteCandidate l = c.findLeaf();
        for (String s : cls) {
            l.addChildren(new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, s));
            registry.addCandidate(new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, s));
            classUtils.defineClassShortName(s, st + "." + s);
            if (GroovyCompletionTypes.debug)
                logger.info("define {} {}.{}", s, st, s);
        }
        registry.addCandidate(c);
    }
}
Also used : AutocompleteCandidate(com.twosigma.beakerx.autocomplete.AutocompleteCandidate) AutocompleteRegistryFactory.createImportAutocompleteCandidate(com.twosigma.beakerx.groovy.autocomplete.AutocompleteRegistryFactory.createImportAutocompleteCandidate)

Example 30 with AutocompleteCandidate

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