Example usage for org.antlr.v4.runtime.tree ErrorNode getSymbol

List of usage examples for org.antlr.v4.runtime.tree ErrorNode getSymbol

Introduction

In this page you can find the example usage for org.antlr.v4.runtime.tree ErrorNode getSymbol.

Prototype

Token getSymbol();

Source Link

Usage

From source file:com.twosigma.beaker.groovy.autocomplete.GroovyNodeCompletion.java

License:Apache License

@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);/*from ww w  .j  a  v  a2 s.co m*/
        } else {
            AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.TOPLEVEL, arg0.getText());
            addQuery(c);
        }
        if (cuc instanceof StatementContext
                && ((StatementContext) cuc).getStop().getStopIndex() + 1 == cursor) {
            if (cuc.getText().contains(".")) {
                addQuery(classUtils.expandExpression(cuc.getText(), registry, classUtils.DO_ALL));
                // complete with standard groovy extension functions
                AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.STDFUNCS,
                        cuc.getText().substring(cuc.getText().lastIndexOf(".") + 1));
                addQuery(c);
            } else {
                AutocompleteCandidate c = new AutocompleteCandidate(GroovyCompletionTypes.NAME, cuc.getText());
                addQuery(c);
                c = new AutocompleteCandidate(GroovyCompletionTypes.CUSTOM_TYPE, cuc.getText());
                addQuery(c);
            }
        }
    }
}

From source file:com.twosigma.beaker.javash.autocomplete.JavaNodeCompletion.java

License:Apache License

@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());
        if (arg0.getParent() instanceof CompilationUnitContext) {
            CompilationUnitContext cuc = (CompilationUnitContext) arg0.getParent();
            if (cuc.getChild(0).equals(arg0)) {
                AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.INITIAL,
                        arg0.getText());
                addQuery(c);//from   w ww  .ja  v  a2  s. c  o m
            } else {
                AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TOPLEVEL,
                        arg0.getText());
                addQuery(c);
            }
            return;
        } else if (arg0.getParent() instanceof BlockStatementContext) {
            if (!arg0.getSymbol().getText().equals(".")) {
                AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.BLOCKLEVEL,
                        arg0.getText());
                addQuery(c);
                c = new AutocompleteCandidate(JavaCompletionTypes.TYPE, arg0.getText());
                addQuery(c);
                c = new AutocompleteCandidate(JavaCompletionTypes.CUSTOM_TYPE, arg0.getText());
                addQuery(c);
                c = new AutocompleteCandidate(JavaCompletionTypes.NAME, arg0.getText());
                addQuery(c);
            } else {
                BlockStatementContext bs = (BlockStatementContext) arg0.getParent();
                if (bs.getChildCount() > 1) {
                    addQuery(classUtils.expandExpression(bs.getText(), registry, classUtils.DO_ALL));
                }
            }
        } else if (arg0.getParent() instanceof ExpressionContext) {
            // we are the rightmost child of the expression
            ParseTree chld = arg0.getParent().getChild(arg0.getParent().getChildCount() - 1);
            if (!chld.equals(arg0))
                return;
            addQuery(classUtils.expandExpression(arg0.getParent().getText(), registry,
                    classUtils.DO_NON_STATIC));
        } else if (arg0.getParent() instanceof TypeDeclarationContext && arg0.getParent().getParent() != null
                && arg0.getParent().getParent() instanceof CompilationUnitContext) {
            AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TOPLEVEL, arg0.getText());
            addQuery(c);
        } else if (arg0.getParent() instanceof MemberDeclarationContext && arg0.getParent().getParent() != null
                && arg0.getParent().getParent() instanceof ClassBodyDeclarationContext
                && arg0.getParent().getParent().getParent() != null
                && arg0.getParent().getParent().getParent() instanceof ClassBodyContext
                && arg0.getParent().getParent().getParent().getText().trim().startsWith("<missing '{'>")) {
            AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.CLASSLEVEL, arg0.getText());
            addQuery(c);
        } else if (arg0.getParent() instanceof MemberDeclarationContext && arg0.getParent().getParent() != null
                && arg0.getParent().getParent() instanceof ClassBodyDeclarationContext
                && arg0.getParent().getParent().getParent() != null
                && arg0.getParent().getParent().getParent() instanceof ClassBodyContext) {
            AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TYPE, arg0.getText());
            addQuery(c);
            c = new AutocompleteCandidate(JavaCompletionTypes.CUSTOM_TYPE, arg0.getText());
            addQuery(c);
        }
    }
}

From source file:com.twosigma.beakerx.javash.autocomplete.JavaNodeCompletion.java

License:Apache License

@Override
public void visitErrorNode(ErrorNode arg0) {

    if (arg0.getText().equals("new")) {
        CompilationUnitContext cuc = (CompilationUnitContext) arg0.getParent();
        List<ParseTree> children = cuc.children;
        int tokenIndex = arg0.getSymbol().getTokenIndex();
        if (tokenIndex - 2 >= 0 && tokenIndex + 1 <= children.size()) {
            ParseTree variablePT = children.get(tokenIndex - 2);
            ParseTree typePT = children.get(tokenIndex + 1);
            String type = typePT.getText();
            String variable = variablePT.getText();
            AutocompleteCandidate c1 = new AutocompleteCandidate(JavaCompletionTypes.NAME, variable);
            registry.addCandidate(c1);/*from  w w  w  .  j  a va  2  s  . c  o m*/
            if (type != null)
                classUtils.defineVariable(variable, type);
            return;
        }
    }

    if (arg0.getSymbol().getStartIndex() < cursor && arg0.getSymbol().getStopIndex() + 1 >= cursor) {
        //System.out.println("ERR: "+arg0.getSymbol().getStartIndex()+" "+arg0.getSymbol().getStopIndex()+" "+arg0.getSymbol().getText());
        if (arg0.getParent() instanceof CompilationUnitContext) {
            CompilationUnitContext cuc = (CompilationUnitContext) arg0.getParent();
            AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.INITIAL, arg0.getText());
            addQuery(c, cursor);
            AutocompleteCandidate c2 = new AutocompleteCandidate(JavaCompletionTypes.TOPLEVEL, arg0.getText());
            addQuery(c2, cursor);
            completeClassFromPath(cuc, arg0.getText());
            return;
        } else if (arg0.getParent() instanceof BlockStatementContext) {
            if (!arg0.getSymbol().getText().equals(".")) {
                AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.BLOCKLEVEL,
                        arg0.getText());
                addQuery(c, cursor);
                c = new AutocompleteCandidate(JavaCompletionTypes.TYPE, arg0.getText());
                addQuery(c, cursor);
                c = new AutocompleteCandidate(JavaCompletionTypes.CUSTOM_TYPE, arg0.getText());
                addQuery(c, cursor);
                c = new AutocompleteCandidate(JavaCompletionTypes.NAME, arg0.getText());
                addQuery(c, cursor);
            } else {
                BlockStatementContext bs = (BlockStatementContext) arg0.getParent();
                if (bs.getChildCount() > 1) {
                    addQuery(classUtils.expandExpression(bs.getText(), registry, classUtils.DO_ALL), cursor);
                }
            }
        } else if (arg0.getParent() instanceof ExpressionContext) {
            // we are the rightmost child of the expression
            ParseTree chld = arg0.getParent().getChild(arg0.getParent().getChildCount() - 1);
            if (!chld.equals(arg0))
                return;
            addQuery(
                    classUtils.expandExpression(arg0.getParent().getText(), registry, classUtils.DO_NON_STATIC),
                    cursor);
        } else if (arg0.getParent() instanceof TypeDeclarationContext && arg0.getParent().getParent() != null
                && arg0.getParent().getParent() instanceof CompilationUnitContext) {
            AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TOPLEVEL, arg0.getText());
            addQuery(c, cursor);
        } else if (arg0.getParent() instanceof MemberDeclarationContext && arg0.getParent().getParent() != null
                && arg0.getParent().getParent() instanceof ClassBodyDeclarationContext
                && arg0.getParent().getParent().getParent() != null
                && arg0.getParent().getParent().getParent() instanceof ClassBodyContext
                && arg0.getParent().getParent().getParent().getText().trim().startsWith("<missing '{'>")) {
            AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.CLASSLEVEL, arg0.getText());
            addQuery(c, cursor);
        } else if (arg0.getParent() instanceof MemberDeclarationContext && arg0.getParent().getParent() != null
                && arg0.getParent().getParent() instanceof ClassBodyDeclarationContext
                && arg0.getParent().getParent().getParent() != null
                && arg0.getParent().getParent().getParent() instanceof ClassBodyContext) {
            AutocompleteCandidate c = new AutocompleteCandidate(JavaCompletionTypes.TYPE, arg0.getText());
            addQuery(c, cursor);
            c = new AutocompleteCandidate(JavaCompletionTypes.CUSTOM_TYPE, arg0.getText());
            addQuery(c, cursor);
        }
    }
}

From source file:illarion.easynpc.parser.ParsedNpcVisitor.java

License:Open Source License

@Override
public ParsedNpcVisitor visitErrorNode(@NotNull ErrorNode node) {
    npc.addError(node.getSymbol().getLine(), node.getSymbol().getCharPositionInLine(), node.getText());
    return defaultResult();
}