Example usage for org.eclipse.jdt.internal.compiler.ast ASTNode HasSyntaxErrors

List of usage examples for org.eclipse.jdt.internal.compiler.ast ASTNode HasSyntaxErrors

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast ASTNode HasSyntaxErrors.

Prototype

int HasSyntaxErrors

To view the source code for org.eclipse.jdt.internal.compiler.ast ASTNode HasSyntaxErrors.

Click Source Link

Usage

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

public void parse(ConstructorDeclaration cd, CompilationUnitDeclaration unit, boolean recordLineSeparator) {
    //only parse the method body of cd
    //fill out its statements

    //convert bugs into parse error

    boolean oldMethodRecoveryActivated = this.methodRecoveryActivated;
    if (this.options.performMethodsFullRecovery) {
        this.methodRecoveryActivated = true;
    }/*from  w  w w.  j a  va  2 s  .  c  o m*/

    initialize();
    goForBlockStatementsopt();
    if (recordLineSeparator) {
        this.scanner.recordLineSeparator = true;
    }
    this.nestedMethod[this.nestedType]++;
    pushOnRealBlockStack(0);

    this.referenceContext = cd;
    this.compilationUnit = unit;

    this.scanner.resetTo(cd.bodyStart, cd.bodyEnd);
    try {
        parse();
    } catch (AbortCompilation ex) {
        this.lastAct = ERROR_ACTION;
    } finally {
        this.nestedMethod[this.nestedType]--;
        if (this.options.performStatementsRecovery) {
            this.methodRecoveryActivated = oldMethodRecoveryActivated;
        }
    }

    checkNonNLSAfterBodyEnd(cd.declarationSourceEnd);

    if (this.lastAct == ERROR_ACTION) {
        cd.bits |= ASTNode.HasSyntaxErrors;
        initialize();
        return;
    }

    //statements
    cd.explicitDeclarations = this.realBlockStack[this.realBlockPtr--];
    int length;
    if (this.astLengthPtr > -1 && (length = this.astLengthStack[this.astLengthPtr--]) != 0) {
        this.astPtr -= length;
        if (!this.options.ignoreMethodBodies) {
            if (this.astStack[this.astPtr + 1] instanceof ExplicitConstructorCall)
            //avoid a isSomeThing that would only be used here BUT what is faster between two alternatives ?
            {
                System.arraycopy(this.astStack, this.astPtr + 2, cd.statements = new Statement[length - 1], 0,
                        length - 1);
                cd.constructorCall = (ExplicitConstructorCall) this.astStack[this.astPtr + 1];
            } else { //need to add explicitly the super();
                System.arraycopy(this.astStack, this.astPtr + 1, cd.statements = new Statement[length], 0,
                        length);
                cd.constructorCall = SuperReference.implicitSuperConstructorCall();
            }
        }
    } else {
        if (!this.options.ignoreMethodBodies) {
            cd.constructorCall = SuperReference.implicitSuperConstructorCall();
        }
        if (!containsComment(cd.bodyStart, cd.bodyEnd)) {
            cd.bits |= ASTNode.UndocumentedEmptyBlock;
        }
    }

    ExplicitConstructorCall explicitConstructorCall = cd.constructorCall;
    if (explicitConstructorCall != null && explicitConstructorCall.sourceEnd == 0) {
        explicitConstructorCall.sourceEnd = cd.sourceEnd;
        explicitConstructorCall.sourceStart = cd.sourceStart;
    }
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

public void parse(FieldDeclaration field, TypeDeclaration type, CompilationUnitDeclaration unit,
        char[] initializationSource) {
    //only parse the initializationSource of the given field

    //convert bugs into parse error

    initialize();//from ww  w .ja  v a  2  s.c  o  m
    goForExpression();
    this.nestedMethod[this.nestedType]++;

    this.referenceContext = type;
    this.compilationUnit = unit;

    this.scanner.setSource(initializationSource);
    this.scanner.resetTo(0, initializationSource.length - 1);
    try {
        parse();
    } catch (AbortCompilation ex) {
        this.lastAct = ERROR_ACTION;
    } finally {
        this.nestedMethod[this.nestedType]--;
    }

    if (this.lastAct == ERROR_ACTION) {
        field.bits |= ASTNode.HasSyntaxErrors;
        return;
    }

    field.initialization = this.expressionStack[this.expressionPtr];

    // mark field with local type if one was found during parsing
    if ((type.bits & ASTNode.HasLocalType) != 0) {
        field.bits |= ASTNode.HasLocalType;
    }
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

public void parse(Initializer initializer, TypeDeclaration type, CompilationUnitDeclaration unit) {
    //only parse the method body of md
    //fill out method statements

    //convert bugs into parse error

    boolean oldMethodRecoveryActivated = this.methodRecoveryActivated;
    if (this.options.performMethodsFullRecovery) {
        this.methodRecoveryActivated = true;
    }/* w  w  w  . jav  a 2  s.  co m*/

    initialize();
    goForBlockStatementsopt();
    this.nestedMethod[this.nestedType]++;
    pushOnRealBlockStack(0);

    this.referenceContext = type;
    this.compilationUnit = unit;

    this.scanner.resetTo(initializer.bodyStart, initializer.bodyEnd); // just on the beginning {
    try {
        parse();
    } catch (AbortCompilation ex) {
        this.lastAct = ERROR_ACTION;
    } finally {
        this.nestedMethod[this.nestedType]--;
        if (this.options.performStatementsRecovery) {
            this.methodRecoveryActivated = oldMethodRecoveryActivated;
        }
    }

    checkNonNLSAfterBodyEnd(initializer.declarationSourceEnd);

    if (this.lastAct == ERROR_ACTION) {
        initializer.bits |= ASTNode.HasSyntaxErrors;
        return;
    }

    //refill statements
    initializer.block.explicitDeclarations = this.realBlockStack[this.realBlockPtr--];
    int length;
    if (this.astLengthPtr > -1 && (length = this.astLengthStack[this.astLengthPtr--]) > 0) {
        System.arraycopy(this.astStack, (this.astPtr -= length) + 1,
                initializer.block.statements = new Statement[length], 0, length);
    } else {
        // check whether this block at least contains some comment in it
        if (!containsComment(initializer.block.sourceStart, initializer.block.sourceEnd)) {
            initializer.block.bits |= ASTNode.UndocumentedEmptyBlock;
        }
    }

    // mark initializer with local type if one was found during parsing
    if ((type.bits & ASTNode.HasLocalType) != 0) {
        initializer.bits |= ASTNode.HasLocalType;
    }
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

public void parse(MethodDeclaration md, CompilationUnitDeclaration unit) {
    //only parse the method body of md
    //fill out method statements

    //convert bugs into parse error

    if (md.isAbstract())
        return;//from  w  w  w . j  a v  a 2  s.  com
    if (md.isNative())
        return;
    if ((md.modifiers & ExtraCompilerModifiers.AccSemicolonBody) != 0)
        return;

    boolean oldMethodRecoveryActivated = this.methodRecoveryActivated;
    if (this.options.performMethodsFullRecovery) {
        this.methodRecoveryActivated = true;
        this.rParenPos = md.sourceEnd;
    }
    initialize();
    goForBlockStatementsopt();
    this.nestedMethod[this.nestedType]++;
    pushOnRealBlockStack(0);

    this.referenceContext = md;
    this.compilationUnit = unit;

    this.scanner.resetTo(md.bodyStart, md.bodyEnd);
    // reset the scanner to parser from { down to }
    try {
        parse();
    } catch (AbortCompilation ex) {
        this.lastAct = ERROR_ACTION;
    } finally {
        this.nestedMethod[this.nestedType]--;
        if (this.options.performStatementsRecovery) {
            this.methodRecoveryActivated = oldMethodRecoveryActivated;
        }
    }

    checkNonNLSAfterBodyEnd(md.declarationSourceEnd);

    if (this.lastAct == ERROR_ACTION) {
        md.bits |= ASTNode.HasSyntaxErrors;
        return;
    }

    //refill statements
    md.explicitDeclarations = this.realBlockStack[this.realBlockPtr--];
    int length;
    if (this.astLengthPtr > -1 && (length = this.astLengthStack[this.astLengthPtr--]) != 0) {
        if (this.options.ignoreMethodBodies) {
            // ignore statements
            this.astPtr -= length;
        } else {
            System.arraycopy(this.astStack, (this.astPtr -= length) + 1, md.statements = new Statement[length],
                    0, length);
        }
    } else {
        if (!containsComment(md.bodyStart, md.bodyEnd)) {
            md.bits |= ASTNode.UndocumentedEmptyBlock;
        }
    }
}

From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java

License:Open Source License

public ASTNode[] parseClassBodyDeclarations(char[] source, int offset, int length,
        CompilationUnitDeclaration unit) {
    boolean oldDiet = this.diet;
    /* automaton initialization */
    initialize();/*from  w  w  w  .  ja v  a2s.c o m*/
    goForClassBodyDeclarations();
    /* scanner initialization */
    this.scanner.setSource(source);
    this.scanner.resetTo(offset, offset + length - 1);
    if (this.javadocParser != null && this.javadocParser.checkDocComment) {
        this.javadocParser.scanner.setSource(source);
        this.javadocParser.scanner.resetTo(offset, offset + length - 1);
    }

    /* type declaration should be parsed as member type declaration */
    this.nestedType = 1;

    /* unit creation */
    TypeDeclaration referenceContextTypeDeclaration = new TypeDeclaration(unit.compilationResult);
    referenceContextTypeDeclaration.name = Util.EMPTY_STRING.toCharArray();
    referenceContextTypeDeclaration.fields = new FieldDeclaration[0];
    this.compilationUnit = unit;
    unit.types = new TypeDeclaration[1];
    unit.types[0] = referenceContextTypeDeclaration;
    this.referenceContext = unit;

    /* run automaton */
    try {
        this.diet = true;
        parse();
    } catch (AbortCompilation ex) {
        this.lastAct = ERROR_ACTION;
    } finally {
        this.diet = oldDiet;
    }

    ASTNode[] result = null;
    if (this.lastAct == ERROR_ACTION) {
        if (!this.options.performMethodsFullRecovery && !this.options.performStatementsRecovery) {
            return null;
        }
        // collect all body declaration inside the compilation unit except the default constructor
        final List bodyDeclarations = new ArrayList();
        ASTVisitor visitor = new ASTVisitor() {
            public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
                if (!methodDeclaration.isDefaultConstructor()) {
                    bodyDeclarations.add(methodDeclaration);
                }
                return false;
            }

            public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) {
                bodyDeclarations.add(fieldDeclaration);
                return false;
            }

            public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) {
                bodyDeclarations.add(memberTypeDeclaration);
                return false;
            }
        };
        unit.ignoreFurtherInvestigation = false;
        unit.traverse(visitor, unit.scope);
        unit.ignoreFurtherInvestigation = true;
        result = (ASTNode[]) bodyDeclarations.toArray(new ASTNode[bodyDeclarations.size()]);
    } else {
        int astLength;
        if (this.astLengthPtr > -1 && (astLength = this.astLengthStack[this.astLengthPtr--]) != 0) {
            result = new ASTNode[astLength];
            this.astPtr -= astLength;
            System.arraycopy(this.astStack, this.astPtr + 1, result, 0, astLength);
        } else {
            // empty class body declaration (like ';' see https://bugs.eclipse.org/bugs/show_bug.cgi?id=280079).
            result = new ASTNode[0];
        }
    }
    boolean containsInitializers = false;
    TypeDeclaration typeDeclaration = null;
    for (int i = 0, max = result.length; i < max; i++) {
        // parse each class body declaration
        ASTNode node = result[i];
        if (node instanceof TypeDeclaration) {
            ((TypeDeclaration) node).parseMethods(this, unit);
        } else if (node instanceof AbstractMethodDeclaration) {
            ((AbstractMethodDeclaration) node).parseStatements(this, unit);
        } else if (node instanceof FieldDeclaration) {
            FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
            switch (fieldDeclaration.getKind()) {
            case AbstractVariableDeclaration.INITIALIZER:
                containsInitializers = true;
                if (typeDeclaration == null) {
                    typeDeclaration = referenceContextTypeDeclaration;
                }
                if (typeDeclaration.fields == null) {
                    typeDeclaration.fields = new FieldDeclaration[1];
                    typeDeclaration.fields[0] = fieldDeclaration;
                } else {
                    int length2 = typeDeclaration.fields.length;
                    FieldDeclaration[] temp = new FieldDeclaration[length2 + 1];
                    System.arraycopy(typeDeclaration.fields, 0, temp, 0, length2);
                    temp[length2] = fieldDeclaration;
                    typeDeclaration.fields = temp;
                }
                break;
            }
        }
        if (((node.bits & ASTNode.HasSyntaxErrors) != 0)
                && (!this.options.performMethodsFullRecovery && !this.options.performStatementsRecovery)) {
            return null;
        }
    }
    if (containsInitializers) {
        FieldDeclaration[] fieldDeclarations = typeDeclaration.fields;
        for (int i = 0, max = fieldDeclarations.length; i < max; i++) {
            Initializer initializer = (Initializer) fieldDeclarations[i];
            initializer.parseStatements(this, typeDeclaration, unit);
            if (((initializer.bits & ASTNode.HasSyntaxErrors) != 0)
                    && (!this.options.performMethodsFullRecovery && !this.options.performStatementsRecovery)) {
                return null;
            }
        }
    }
    return result;
}