Example usage for org.eclipse.jdt.core.dom AST JLS2_INTERNAL

List of usage examples for org.eclipse.jdt.core.dom AST JLS2_INTERNAL

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom AST JLS2_INTERNAL.

Prototype

int JLS2_INTERNAL

To view the source code for org.eclipse.jdt.core.dom AST JLS2_INTERNAL.

Click Source Link

Document

Internal synonym for #JLS2 .

Usage

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public ASTNode convert(boolean isInterface,
        org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration methodDeclaration) {
    checkCanceled();//from ww w . jav a 2s.c o  m
    if (methodDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) {
        return convert((org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration) methodDeclaration);
    }
    MethodDeclaration methodDecl = new MethodDeclaration(this.ast);
    setModifiers(methodDecl, methodDeclaration);
    boolean isConstructor = methodDeclaration.isConstructor();
    methodDecl.setConstructor(isConstructor);
    final SimpleName methodName = new SimpleName(this.ast);
    methodName.internalSetIdentifier(new String(methodDeclaration.selector));
    int start = methodDeclaration.sourceStart;
    // GROOVY start
    // why does this do what it does?
    /* old {
    int end = retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd);
    } new */
    int end = (scannerAvailable(methodDeclaration.scope)
            ? retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd)
            : methodDeclaration.sourceEnd);
    // GROOVY end
    methodName.setSourceRange(start, end - start + 1);
    methodDecl.setName(methodName);
    org.eclipse.jdt.internal.compiler.ast.TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
    int methodHeaderEnd = methodDeclaration.sourceEnd;
    int thrownExceptionsLength = thrownExceptions == null ? 0 : thrownExceptions.length;
    if (thrownExceptionsLength > 0) {
        Name thrownException;
        int i = 0;
        do {
            thrownException = convert(thrownExceptions[i++]);
            methodDecl.thrownExceptions().add(thrownException);
        } while (i < thrownExceptionsLength);
        methodHeaderEnd = thrownException.getStartPosition() + thrownException.getLength();
    }
    org.eclipse.jdt.internal.compiler.ast.Argument[] parameters = methodDeclaration.arguments;
    int parametersLength = parameters == null ? 0 : parameters.length;
    if (parametersLength > 0) {
        SingleVariableDeclaration parameter;
        int i = 0;
        do {
            // GROOVY start
            // make sure the scope is available just in case it is necessary for varargs
            // new code
            BlockScope origScope = null;
            if (parameters[i].binding != null) {
                origScope = parameters[i].binding.declaringScope;
                parameters[i].binding.declaringScope = methodDeclaration.scope;
            }
            // GROOVY end

            parameter = convert(parameters[i++]);

            // GROOVY start
            // unset the scope
            // new code
            if (parameters[i - 1].binding != null) {
                parameters[i - 1].binding.declaringScope = origScope;
            }
            // GROOVY end
            methodDecl.parameters().add(parameter);
        } while (i < parametersLength);
        if (thrownExceptionsLength == 0) {
            methodHeaderEnd = parameter.getStartPosition() + parameter.getLength();
        }
    }
    org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall explicitConstructorCall = null;
    if (isConstructor) {
        if (isInterface) {
            // interface cannot have a constructor
            methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
        }
        org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration constructorDeclaration = (org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration) methodDeclaration;
        explicitConstructorCall = constructorDeclaration.constructorCall;
        switch (this.ast.apiLevel) {
        case AST.JLS2_INTERNAL:
            // set the return type to VOID
            PrimitiveType returnType = new PrimitiveType(this.ast);
            returnType.setPrimitiveTypeCode(PrimitiveType.VOID);
            returnType.setSourceRange(methodDeclaration.sourceStart, 0);
            methodDecl.internalSetReturnType(returnType);
            break;
        default:
            methodDecl.setReturnType2(null);
        }
    } else if (methodDeclaration instanceof org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) {
        org.eclipse.jdt.internal.compiler.ast.MethodDeclaration method = (org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) methodDeclaration;
        org.eclipse.jdt.internal.compiler.ast.TypeReference typeReference = method.returnType;
        if (typeReference != null) {
            Type returnType = convertType(typeReference);
            // get the positions of the right parenthesis
            int rightParenthesisPosition = retrieveEndOfRightParenthesisPosition(end, method.bodyEnd);
            int extraDimensions = retrieveExtraDimension(rightParenthesisPosition, method.bodyEnd);
            methodDecl.setExtraDimensions(extraDimensions);
            setTypeForMethodDeclaration(methodDecl, returnType, extraDimensions);
        } else {
            // no return type for a method that is not a constructor
            methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
            switch (this.ast.apiLevel) {
            case AST.JLS2_INTERNAL:
                break;
            default:
                methodDecl.setReturnType2(null);
            }
        }
    }
    int declarationSourceStart = methodDeclaration.declarationSourceStart;
    int bodyEnd = methodDeclaration.bodyEnd;
    methodDecl.setSourceRange(declarationSourceStart, bodyEnd - declarationSourceStart + 1);
    int declarationSourceEnd = methodDeclaration.declarationSourceEnd;
    int rightBraceOrSemiColonPositionStart = bodyEnd == declarationSourceEnd ? bodyEnd : bodyEnd + 1;
    int closingPosition = retrieveRightBraceOrSemiColonPosition(rightBraceOrSemiColonPositionStart,
            declarationSourceEnd);
    if (closingPosition != -1) {
        int startPosition = methodDecl.getStartPosition();
        methodDecl.setSourceRange(startPosition, closingPosition - startPosition + 1);

        org.eclipse.jdt.internal.compiler.ast.Statement[] statements = methodDeclaration.statements;

        start = retrieveStartBlockPosition(methodHeaderEnd, methodDeclaration.bodyStart);
        if (start == -1)
            start = methodDeclaration.bodyStart; // use recovery position for body start
        end = retrieveRightBrace(methodDeclaration.bodyEnd, declarationSourceEnd);
        Block block = null;
        if (start != -1 && end != -1) {
            /*
             * start or end can be equal to -1 if we have an interface's method.
             */
            block = new Block(this.ast);
            block.setSourceRange(start, closingPosition - start + 1);
            methodDecl.setBody(block);
        }
        if (block != null && (statements != null || explicitConstructorCall != null)) {
            if (explicitConstructorCall != null
                    && explicitConstructorCall.accessMode != org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall.ImplicitSuper) {
                block.statements().add(convert(explicitConstructorCall));
            }
            int statementsLength = statements == null ? 0 : statements.length;
            for (int i = 0; i < statementsLength; i++) {
                if (statements[i] instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
                    checkAndAddMultipleLocalDeclaration(statements, i, block.statements());
                } else {
                    final Statement statement = convert(statements[i]);
                    if (statement != null) {
                        block.statements().add(statement);
                    }
                }
            }
        }
        if (block != null && (Modifier.isAbstract(methodDecl.getModifiers())
                || Modifier.isNative(methodDecl.getModifiers()) || isInterface)) {
            methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
        }
    } else {
        // syntax error in this method declaration
        methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
        if (!methodDeclaration.isNative() && !methodDeclaration.isAbstract()) {
            start = retrieveStartBlockPosition(methodHeaderEnd, bodyEnd);
            if (start == -1)
                start = methodDeclaration.bodyStart; // use recovery position for body start
            end = methodDeclaration.bodyEnd;
            // try to get the best end position
            CategorizedProblem[] problems = methodDeclaration.compilationResult().problems;
            if (problems != null) {
                for (int i = 0, max = methodDeclaration.compilationResult().problemCount; i < max; i++) {
                    CategorizedProblem currentProblem = problems[i];
                    if (currentProblem.getSourceStart() == start
                            && currentProblem.getID() == IProblem.ParsingErrorInsertToComplete) {
                        end = currentProblem.getSourceEnd();
                        break;
                    }
                }
            }
            int startPosition = methodDecl.getStartPosition();
            methodDecl.setSourceRange(startPosition, end - startPosition + 1);
            if (start != -1 && end != -1) {
                /*
                 * start or end can be equal to -1 if we have an interface's method.
                 */
                Block block = new Block(this.ast);
                block.setSourceRange(start, end - start + 1);
                methodDecl.setBody(block);
            }
        }
    }

    org.eclipse.jdt.internal.compiler.ast.TypeParameter[] typeParameters = methodDeclaration.typeParameters();
    if (typeParameters != null) {
        switch (this.ast.apiLevel) {
        case AST.JLS2_INTERNAL:
            methodDecl.setFlags(methodDecl.getFlags() | ASTNode.MALFORMED);
            break;
        default:
            for (int i = 0, max = typeParameters.length; i < max; i++) {
                methodDecl.typeParameters().add(convert(typeParameters[i]));
            }
        }
    }

    // The javadoc comment is now got from list store in compilation unit declaration
    convert(methodDeclaration.javadoc, methodDecl);
    if (this.resolveBindings) {
        recordNodes(methodDecl, methodDeclaration);
        recordNodes(methodName, methodDeclaration);
        methodDecl.resolveBinding();
    }
    return methodDecl;
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public ClassInstanceCreation convert(org.eclipse.jdt.internal.compiler.ast.AllocationExpression expression) {
    ClassInstanceCreation classInstanceCreation = new ClassInstanceCreation(this.ast);
    if (this.resolveBindings) {
        recordNodes(classInstanceCreation, expression);
    }/*from   w  ww  .j a va  2 s .  c o  m*/
    if (expression.typeArguments != null) {
        switch (this.ast.apiLevel) {
        case AST.JLS2_INTERNAL:
            classInstanceCreation.setFlags(classInstanceCreation.getFlags() | ASTNode.MALFORMED);
            break;
        default:
            for (int i = 0, max = expression.typeArguments.length; i < max; i++) {
                classInstanceCreation.typeArguments().add(convertType(expression.typeArguments[i]));
            }
        }
    }
    switch (this.ast.apiLevel) {
    case AST.JLS2_INTERNAL:
        classInstanceCreation.internalSetName(convert(expression.type));
        break;
    default:
        classInstanceCreation.setType(convertType(expression.type));
    }
    classInstanceCreation.setSourceRange(expression.sourceStart,
            expression.sourceEnd - expression.sourceStart + 1);
    org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = expression.arguments;
    if (arguments != null) {
        int length = arguments.length;
        for (int i = 0; i < length; i++) {
            classInstanceCreation.arguments().add(convert(arguments[i]));
        }
    }
    removeTrailingCommentFromExpressionEndingWithAParen(classInstanceCreation);
    return classInstanceCreation;
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public ASTNode convert(
        org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration annotationTypeMemberDeclaration) {
    checkCanceled();/*from   ww  w.j a  va  2  s . co m*/
    if (this.ast.apiLevel == AST.JLS2_INTERNAL) {
        return null;
    }
    AnnotationTypeMemberDeclaration annotationTypeMemberDeclaration2 = new AnnotationTypeMemberDeclaration(
            this.ast);
    setModifiers(annotationTypeMemberDeclaration2, annotationTypeMemberDeclaration);
    final SimpleName methodName = new SimpleName(this.ast);
    methodName.internalSetIdentifier(new String(annotationTypeMemberDeclaration.selector));
    int start = annotationTypeMemberDeclaration.sourceStart;
    int end = retrieveIdentifierEndPosition(start, annotationTypeMemberDeclaration.sourceEnd);
    methodName.setSourceRange(start, end - start + 1);
    annotationTypeMemberDeclaration2.setName(methodName);
    org.eclipse.jdt.internal.compiler.ast.TypeReference typeReference = annotationTypeMemberDeclaration.returnType;
    if (typeReference != null) {
        Type returnType = convertType(typeReference);
        setTypeForMethodDeclaration(annotationTypeMemberDeclaration2, returnType, 0);
    }
    int declarationSourceStart = annotationTypeMemberDeclaration.declarationSourceStart;
    int declarationSourceEnd = annotationTypeMemberDeclaration.bodyEnd;
    annotationTypeMemberDeclaration2.setSourceRange(declarationSourceStart,
            declarationSourceEnd - declarationSourceStart + 1);
    // The javadoc comment is now got from list store in compilation unit declaration
    convert(annotationTypeMemberDeclaration.javadoc, annotationTypeMemberDeclaration2);
    org.eclipse.jdt.internal.compiler.ast.Expression memberValue = annotationTypeMemberDeclaration.defaultValue;
    if (memberValue != null) {
        annotationTypeMemberDeclaration2.setDefault(convert(memberValue));
    }
    if (this.resolveBindings) {
        recordNodes(annotationTypeMemberDeclaration2, annotationTypeMemberDeclaration);
        recordNodes(methodName, annotationTypeMemberDeclaration);
        annotationTypeMemberDeclaration2.resolveBinding();
    }
    return annotationTypeMemberDeclaration2;
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public SingleVariableDeclaration convert(org.eclipse.jdt.internal.compiler.ast.Argument argument) {
    SingleVariableDeclaration variableDecl = new SingleVariableDeclaration(this.ast);
    setModifiers(variableDecl, argument);
    final SimpleName name = new SimpleName(this.ast);
    name.internalSetIdentifier(new String(argument.name));
    int start = argument.sourceStart;
    int nameEnd = argument.sourceEnd;
    name.setSourceRange(start, nameEnd - start + 1);
    variableDecl.setName(name);//  ww  w .  j a  v a 2s. co m
    final int typeSourceEnd = argument.type.sourceEnd;
    final int extraDimensions = retrieveExtraDimension(nameEnd + 1, typeSourceEnd);
    variableDecl.setExtraDimensions(extraDimensions);
    final boolean isVarArgs = argument.isVarArgs();
    // GROOVY start
    // Do not try to change source ends for var args.  Groovy assumes that
    // all methods that have an array as the last param are varargs
    /* old {
    if (isVarArgs && extraDimensions == 0) {
    } new */
    if (argument.binding != null && scannerAvailable(argument.binding.declaringScope) && isVarArgs
            && extraDimensions == 0) {
        // GROOVY end
        // remove the ellipsis from the type source end
        argument.type.sourceEnd = retrieveEllipsisStartPosition(argument.type.sourceStart, typeSourceEnd);
    }
    Type type = convertType(argument.type);
    int typeEnd = type.getStartPosition() + type.getLength() - 1;
    int rightEnd = Math.max(typeEnd, argument.declarationSourceEnd);
    /*
     * There is extra work to do to set the proper type positions
     * See PR http://bugs.eclipse.org/bugs/show_bug.cgi?id=23284
     */
    if (isVarArgs) {
        setTypeForSingleVariableDeclaration(variableDecl, type, extraDimensions + 1);
        if (extraDimensions != 0) {
            variableDecl.setFlags(variableDecl.getFlags() | ASTNode.MALFORMED);
        }
    } else {
        setTypeForSingleVariableDeclaration(variableDecl, type, extraDimensions);
    }
    variableDecl.setSourceRange(argument.declarationSourceStart,
            rightEnd - argument.declarationSourceStart + 1);

    if (isVarArgs) {
        switch (this.ast.apiLevel) {
        case AST.JLS2_INTERNAL:
            variableDecl.setFlags(variableDecl.getFlags() | ASTNode.MALFORMED);
            break;
        default:
            variableDecl.setVarargs(true);
        }
    }
    if (this.resolveBindings) {
        recordNodes(name, argument);
        recordNodes(variableDecl, argument);
        variableDecl.resolveBinding();
    }
    return variableDecl;
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public Statement convert(org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall statement) {
    Statement newStatement;/*from ww w  .j  a  v a 2s .  co m*/
    int sourceStart = statement.sourceStart;
    if (statement.isSuperAccess() || statement.isSuper()) {
        SuperConstructorInvocation superConstructorInvocation = new SuperConstructorInvocation(this.ast);
        if (statement.qualification != null) {
            superConstructorInvocation.setExpression(convert(statement.qualification));
        }
        org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = statement.arguments;
        if (arguments != null) {
            int length = arguments.length;
            for (int i = 0; i < length; i++) {
                superConstructorInvocation.arguments().add(convert(arguments[i]));
            }
        }
        if (statement.typeArguments != null) {
            if (sourceStart > statement.typeArgumentsSourceStart) {
                sourceStart = statement.typeArgumentsSourceStart;
            }
            switch (this.ast.apiLevel) {
            case AST.JLS2_INTERNAL:
                superConstructorInvocation.setFlags(superConstructorInvocation.getFlags() | ASTNode.MALFORMED);
                break;
            default:
                for (int i = 0, max = statement.typeArguments.length; i < max; i++) {
                    superConstructorInvocation.typeArguments().add(convertType(statement.typeArguments[i]));
                }
                break;
            }
        }
        newStatement = superConstructorInvocation;
    } else {
        ConstructorInvocation constructorInvocation = new ConstructorInvocation(this.ast);
        org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = statement.arguments;
        if (arguments != null) {
            int length = arguments.length;
            for (int i = 0; i < length; i++) {
                constructorInvocation.arguments().add(convert(arguments[i]));
            }
        }
        if (statement.typeArguments != null) {
            if (sourceStart > statement.typeArgumentsSourceStart) {
                sourceStart = statement.typeArgumentsSourceStart;
            }
            switch (this.ast.apiLevel) {
            case AST.JLS2_INTERNAL:
                constructorInvocation.setFlags(constructorInvocation.getFlags() | ASTNode.MALFORMED);
                break;
            default:
                for (int i = 0, max = statement.typeArguments.length; i < max; i++) {
                    constructorInvocation.typeArguments().add(convertType(statement.typeArguments[i]));
                }
                break;
            }
        }
        if (statement.qualification != null) {
            // this is an error
            constructorInvocation.setFlags(constructorInvocation.getFlags() | ASTNode.MALFORMED);
        }
        newStatement = constructorInvocation;
    }
    newStatement.setSourceRange(sourceStart, statement.sourceEnd - sourceStart + 1);
    if (this.resolveBindings) {
        recordNodes(newStatement, statement);
    }
    return newStatement;
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public Statement convert(ForeachStatement statement) {
    switch (this.ast.apiLevel) {
    case AST.JLS2_INTERNAL:
        return createFakeEmptyStatement(statement);
    default://from  ww w.  j  a v  a 2  s .  c om
        EnhancedForStatement enhancedForStatement = new EnhancedForStatement(this.ast);
        enhancedForStatement.setParameter(convertToSingleVariableDeclaration(statement.elementVariable));
        org.eclipse.jdt.internal.compiler.ast.Expression collection = statement.collection;
        if (collection == null)
            return null;
        enhancedForStatement.setExpression(convert(collection));
        final Statement action = convert(statement.action);
        if (action == null)
            return null;
        enhancedForStatement.setBody(action);
        int start = statement.sourceStart;
        int end = statement.sourceEnd;
        enhancedForStatement.setSourceRange(start, end - start + 1);
        return enhancedForStatement;
    }
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public void convert(org.eclipse.jdt.internal.compiler.ast.Javadoc javadoc,
        PackageDeclaration packageDeclaration) {
    switch (this.ast.apiLevel) {
    case AST.JLS2_INTERNAL:
        return;//from   w w w.j  av a2s  .  co m
    }
    if (packageDeclaration.getJavadoc() == null) {
        if (javadoc != null) {
            if (this.commentMapper == null || !this.commentMapper.hasSameTable(this.commentsTable)) {
                this.commentMapper = new DefaultCommentMapper(this.commentsTable);
            }
            Comment comment = this.commentMapper.getComment(javadoc.sourceStart);
            if (comment != null && comment.isDocComment() && comment.getParent() == null) {
                Javadoc docComment = (Javadoc) comment;
                if (this.resolveBindings) {
                    recordNodes(docComment, javadoc);
                    // resolve member and method references binding
                    Iterator tags = docComment.tags().listIterator();
                    while (tags.hasNext()) {
                        recordNodes(javadoc, (TagElement) tags.next());
                    }
                }
                packageDeclaration.setJavadoc(docComment);
            }
        }
    }
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public Expression convert(MessageSend expression) {
    // will return a MethodInvocation or a SuperMethodInvocation or
    Expression expr;/*  w w w  .ja  va  2  s  . c  om*/
    int sourceStart = expression.sourceStart;
    if (expression.isSuperAccess()) {
        // returns a SuperMethodInvocation
        final SuperMethodInvocation superMethodInvocation = new SuperMethodInvocation(this.ast);
        if (this.resolveBindings) {
            recordNodes(superMethodInvocation, expression);
        }
        final SimpleName name = new SimpleName(this.ast);
        name.internalSetIdentifier(new String(expression.selector));
        int nameSourceStart = (int) (expression.nameSourcePosition >>> 32);
        int nameSourceLength = ((int) expression.nameSourcePosition) - nameSourceStart + 1;
        name.setSourceRange(nameSourceStart, nameSourceLength);
        if (this.resolveBindings) {
            recordNodes(name, expression);
        }
        superMethodInvocation.setName(name);
        // expression.receiver is either a QualifiedSuperReference or a SuperReference
        // so the casting cannot fail
        if (expression.receiver instanceof org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) {
            Name qualifier = convert(
                    (org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) expression.receiver);
            superMethodInvocation.setQualifier(qualifier);
            if (this.resolveBindings) {
                recordNodes(qualifier, expression.receiver);
            }
            if (qualifier != null) {
                sourceStart = qualifier.getStartPosition();
            }
        }
        org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = expression.arguments;
        if (arguments != null) {
            int argumentsLength = arguments.length;
            for (int i = 0; i < argumentsLength; i++) {
                Expression expri = convert(arguments[i]);
                if (this.resolveBindings) {
                    recordNodes(expri, arguments[i]);
                }
                superMethodInvocation.arguments().add(expri);
            }
        }
        final TypeReference[] typeArguments = expression.typeArguments;
        if (typeArguments != null) {
            switch (this.ast.apiLevel) {
            case AST.JLS2_INTERNAL:
                superMethodInvocation.setFlags(superMethodInvocation.getFlags() | ASTNode.MALFORMED);
                break;
            default:
                for (int i = 0, max = typeArguments.length; i < max; i++) {
                    superMethodInvocation.typeArguments().add(convertType(typeArguments[i]));
                }
                break;
            }
        }
        expr = superMethodInvocation;
    } else {
        // returns a MethodInvocation
        final MethodInvocation methodInvocation = new MethodInvocation(this.ast);
        if (this.resolveBindings) {
            recordNodes(methodInvocation, expression);
        }
        final SimpleName name = new SimpleName(this.ast);
        name.internalSetIdentifier(new String(expression.selector));
        int nameSourceStart = (int) (expression.nameSourcePosition >>> 32);
        int nameSourceLength = ((int) expression.nameSourcePosition) - nameSourceStart + 1;
        name.setSourceRange(nameSourceStart, nameSourceLength);
        methodInvocation.setName(name);
        if (this.resolveBindings) {
            recordNodes(name, expression);
        }
        org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = expression.arguments;
        if (arguments != null) {
            int argumentsLength = arguments.length;
            for (int i = 0; i < argumentsLength; i++) {
                Expression expri = convert(arguments[i]);
                if (this.resolveBindings) {
                    recordNodes(expri, arguments[i]);
                }
                methodInvocation.arguments().add(expri);
            }
        }
        Expression qualifier = null;
        org.eclipse.jdt.internal.compiler.ast.Expression receiver = expression.receiver;
        if (receiver instanceof MessageSend) {
            if ((receiver.bits & org.eclipse.jdt.internal.compiler.ast.ASTNode.ParenthesizedMASK) != 0) {
                qualifier = convertToParenthesizedExpression(receiver);
            } else {
                qualifier = convert((MessageSend) receiver);
            }
        } else {
            qualifier = convert(receiver);
        }
        if (qualifier instanceof Name && this.resolveBindings) {
            recordNodes(qualifier, receiver);
        }
        methodInvocation.setExpression(qualifier);
        if (qualifier != null) {
            sourceStart = qualifier.getStartPosition();
        }
        final TypeReference[] typeArguments = expression.typeArguments;
        if (typeArguments != null) {
            switch (this.ast.apiLevel) {
            case AST.JLS2_INTERNAL:
                methodInvocation.setFlags(methodInvocation.getFlags() | ASTNode.MALFORMED);
                break;
            default:
                for (int i = 0, max = typeArguments.length; i < max; i++) {
                    methodInvocation.typeArguments().add(convertType(typeArguments[i]));
                }
                break;
            }
        }
        expr = methodInvocation;
    }
    expr.setSourceRange(sourceStart, expression.sourceEnd - sourceStart + 1);
    removeTrailingCommentFromExpressionEndingWithAParen(expr);
    return expr;
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public Expression convert(org.eclipse.jdt.internal.compiler.ast.QualifiedAllocationExpression allocation) {
    final ClassInstanceCreation classInstanceCreation = new ClassInstanceCreation(this.ast);
    if (allocation.enclosingInstance != null) {
        classInstanceCreation.setExpression(convert(allocation.enclosingInstance));
    }//  w ww. ja  v a 2  s.  c  o  m
    switch (this.ast.apiLevel) {
    case AST.JLS2_INTERNAL:
        classInstanceCreation.internalSetName(convert(allocation.type));
        break;
    default:
        classInstanceCreation.setType(convertType(allocation.type));
    }
    org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = allocation.arguments;
    if (arguments != null) {
        int length = arguments.length;
        for (int i = 0; i < length; i++) {
            Expression argument = convert(arguments[i]);
            if (this.resolveBindings) {
                recordNodes(argument, arguments[i]);
            }
            classInstanceCreation.arguments().add(argument);
        }
    }
    if (allocation.typeArguments != null) {
        switch (this.ast.apiLevel) {
        case AST.JLS2_INTERNAL:
            classInstanceCreation.setFlags(classInstanceCreation.getFlags() | ASTNode.MALFORMED);
            break;
        default:
            for (int i = 0, max = allocation.typeArguments.length; i < max; i++) {
                classInstanceCreation.typeArguments().add(convertType(allocation.typeArguments[i]));
            }
        }
    }
    if (allocation.anonymousType != null) {
        int declarationSourceStart = allocation.sourceStart;
        classInstanceCreation.setSourceRange(declarationSourceStart,
                allocation.anonymousType.bodyEnd - declarationSourceStart + 1);
        final AnonymousClassDeclaration anonymousClassDeclaration = new AnonymousClassDeclaration(this.ast);
        int start = retrieveStartBlockPosition(allocation.anonymousType.sourceEnd,
                allocation.anonymousType.bodyEnd);
        anonymousClassDeclaration.setSourceRange(start, allocation.anonymousType.bodyEnd - start + 1);
        classInstanceCreation.setAnonymousClassDeclaration(anonymousClassDeclaration);
        buildBodyDeclarations(allocation.anonymousType, anonymousClassDeclaration);
        if (this.resolveBindings) {
            recordNodes(classInstanceCreation, allocation.anonymousType);
            recordNodes(anonymousClassDeclaration, allocation.anonymousType);
            anonymousClassDeclaration.resolveBinding();
        }
        return classInstanceCreation;
    } else {
        final int start = allocation.sourceStart;
        classInstanceCreation.setSourceRange(start, allocation.sourceEnd - start + 1);
        if (this.resolveBindings) {
            recordNodes(classInstanceCreation, allocation);
        }
        removeTrailingCommentFromExpressionEndingWithAParen(classInstanceCreation);
        return classInstanceCreation;
    }
}

From source file:org.eclipse.jdt.core.dom.ASTConverter.java

License:Open Source License

public Statement convert(org.eclipse.jdt.internal.compiler.ast.Statement statement) {
    if (statement instanceof ForeachStatement) {
        return convert((ForeachStatement) statement);
    }//ww w  . j a va  2  s.  c o  m
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) {
        org.eclipse.jdt.internal.compiler.ast.LocalDeclaration localDeclaration = (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) statement;
        return convertToVariableDeclarationStatement(localDeclaration);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.AssertStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.AssertStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.Block) {
        return convert((org.eclipse.jdt.internal.compiler.ast.Block) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.BreakStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.BreakStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.ContinueStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.ContinueStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.CaseStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.CaseStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.DoStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.DoStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.EmptyStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.EmptyStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall) {
        return convert((org.eclipse.jdt.internal.compiler.ast.ExplicitConstructorCall) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.ForStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.ForStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.IfStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.IfStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.LabeledStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.LabeledStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.ReturnStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.ReturnStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.SwitchStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.SwitchStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.SynchronizedStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.SynchronizedStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.ThrowStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.ThrowStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.TryStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.TryStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
        ASTNode result = convert((org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) statement);
        if (result == null) {
            return createFakeEmptyStatement(statement);
        }
        // annotation and enum type declarations are not returned by the parser inside method bodies
        TypeDeclaration typeDeclaration = (TypeDeclaration) result;
        TypeDeclarationStatement typeDeclarationStatement = new TypeDeclarationStatement(this.ast);
        typeDeclarationStatement.setDeclaration(typeDeclaration);
        switch (this.ast.apiLevel) {
        case AST.JLS2_INTERNAL:
            TypeDeclaration typeDecl = typeDeclarationStatement.internalGetTypeDeclaration();
            typeDeclarationStatement.setSourceRange(typeDecl.getStartPosition(), typeDecl.getLength());
            break;
        default:
            AbstractTypeDeclaration typeDeclAST3 = typeDeclarationStatement.getDeclaration();
            typeDeclarationStatement.setSourceRange(typeDeclAST3.getStartPosition(), typeDeclAST3.getLength());
            break;
        }
        return typeDeclarationStatement;
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.WhileStatement) {
        return convert((org.eclipse.jdt.internal.compiler.ast.WhileStatement) statement);
    }
    if (statement instanceof org.eclipse.jdt.internal.compiler.ast.Expression) {
        org.eclipse.jdt.internal.compiler.ast.Expression statement2 = (org.eclipse.jdt.internal.compiler.ast.Expression) statement;
        final Expression expr = convert(statement2);
        final ExpressionStatement stmt = new ExpressionStatement(this.ast);
        stmt.setExpression(expr);
        int sourceStart = expr.getStartPosition();
        int sourceEnd = statement2.statementEnd;
        stmt.setSourceRange(sourceStart, sourceEnd - sourceStart + 1);
        return stmt;
    }
    return createFakeEmptyStatement(statement);
}