Example usage for org.eclipse.jdt.core.dom SimpleName SimpleName

List of usage examples for org.eclipse.jdt.core.dom SimpleName SimpleName

Introduction

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

Prototype

SimpleName(AST ast) 

Source Link

Document

Creates a new AST node for a simple name owned by the given AST.

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   www.  j  a va 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

private AnnotationTypeDeclaration convertToAnnotationDeclaration(
        org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration) {
    checkCanceled();/*  w  w  w  .j av a  2  s .co m*/
    if (this.scanner.sourceLevel < ClassFileConstants.JDK1_5)
        return null;
    AnnotationTypeDeclaration typeDecl = this.ast.newAnnotationTypeDeclaration();
    setModifiers(typeDecl, typeDeclaration);
    final SimpleName typeName = new SimpleName(this.ast);
    typeName.internalSetIdentifier(new String(typeDeclaration.name));
    typeName.setSourceRange(typeDeclaration.sourceStart,
            typeDeclaration.sourceEnd - typeDeclaration.sourceStart + 1);
    typeDecl.setName(typeName);
    typeDecl.setSourceRange(typeDeclaration.declarationSourceStart,
            typeDeclaration.bodyEnd - typeDeclaration.declarationSourceStart + 1);

    buildBodyDeclarations(typeDeclaration, typeDecl, false);
    // The javadoc comment is now got from list store in compilation unit declaration
    if (this.resolveBindings) {
        recordNodes(typeDecl, typeDeclaration);
        recordNodes(typeName, typeDeclaration);
        typeDecl.resolveBinding();
    }
    return typeDecl;
}

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  w  w w. j  ava2  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);// w  w w.j a va 2 s .c om
    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 BreakStatement convert(org.eclipse.jdt.internal.compiler.ast.BreakStatement statement) {
    BreakStatement breakStatement = new BreakStatement(this.ast);
    breakStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
    if (statement.label != null) {
        final SimpleName name = new SimpleName(this.ast);
        name.internalSetIdentifier(new String(statement.label));
        retrieveIdentifierAndSetPositions(statement.sourceStart, statement.sourceEnd, name);
        breakStatement.setLabel(name);//from w  w  w  . jav  a 2  s.c om
    }
    return breakStatement;
}

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

License:Open Source License

public ContinueStatement convert(org.eclipse.jdt.internal.compiler.ast.ContinueStatement statement) {
    ContinueStatement continueStatement = new ContinueStatement(this.ast);
    continueStatement.setSourceRange(statement.sourceStart, statement.sourceEnd - statement.sourceStart + 1);
    if (statement.label != null) {
        final SimpleName name = new SimpleName(this.ast);
        name.internalSetIdentifier(new String(statement.label));
        retrieveIdentifierAndSetPositions(statement.sourceStart, statement.sourceEnd, name);
        continueStatement.setLabel(name);
    }/*w  ww .  j a v a 2  s.  c o  m*/
    return continueStatement;
}

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

License:Open Source License

public EnumConstantDeclaration convert(org.eclipse.jdt.internal.compiler.ast.FieldDeclaration enumConstant) {
    checkCanceled();//from   w w  w.j a  v  a 2 s . com
    EnumConstantDeclaration enumConstantDeclaration = new EnumConstantDeclaration(this.ast);
    final SimpleName typeName = new SimpleName(this.ast);
    typeName.internalSetIdentifier(new String(enumConstant.name));
    typeName.setSourceRange(enumConstant.sourceStart, enumConstant.sourceEnd - enumConstant.sourceStart + 1);
    enumConstantDeclaration.setName(typeName);
    int declarationSourceStart = enumConstant.declarationSourceStart;
    int declarationSourceEnd = enumConstant.declarationSourceEnd;
    final org.eclipse.jdt.internal.compiler.ast.Expression initialization = enumConstant.initialization;
    if (initialization != null) {
        if (initialization instanceof QualifiedAllocationExpression) {
            org.eclipse.jdt.internal.compiler.ast.TypeDeclaration anonymousType = ((QualifiedAllocationExpression) initialization).anonymousType;
            if (anonymousType != null) {
                AnonymousClassDeclaration anonymousClassDeclaration = new AnonymousClassDeclaration(this.ast);
                int start = retrieveStartBlockPosition(anonymousType.sourceEnd, anonymousType.bodyEnd);
                int end = retrieveRightBrace(anonymousType.bodyEnd, declarationSourceEnd);
                if (end == -1)
                    end = anonymousType.bodyEnd;
                anonymousClassDeclaration.setSourceRange(start, end - start + 1);
                enumConstantDeclaration.setAnonymousClassDeclaration(anonymousClassDeclaration);
                buildBodyDeclarations(anonymousType, anonymousClassDeclaration);
                if (this.resolveBindings) {
                    recordNodes(anonymousClassDeclaration, anonymousType);
                    anonymousClassDeclaration.resolveBinding();
                }
                enumConstantDeclaration.setSourceRange(declarationSourceStart,
                        end - declarationSourceStart + 1);
            }
        } else {
            enumConstantDeclaration.setSourceRange(declarationSourceStart,
                    declarationSourceEnd - declarationSourceStart + 1);
        }
        final org.eclipse.jdt.internal.compiler.ast.Expression[] arguments = ((org.eclipse.jdt.internal.compiler.ast.AllocationExpression) initialization).arguments;
        if (arguments != null) {
            for (int i = 0, max = arguments.length; i < max; i++) {
                enumConstantDeclaration.arguments().add(convert(arguments[i]));
            }
        }
    } else {
        enumConstantDeclaration.setSourceRange(declarationSourceStart,
                declarationSourceEnd - declarationSourceStart + 1);
    }
    setModifiers(enumConstantDeclaration, enumConstant);
    if (this.resolveBindings) {
        recordNodes(enumConstantDeclaration, enumConstant);
        recordNodes(typeName, enumConstant);
        enumConstantDeclaration.resolveVariable();
    }
    convert(enumConstant.javadoc, enumConstantDeclaration);
    return enumConstantDeclaration;
}

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

License:Open Source License

public Expression convert(org.eclipse.jdt.internal.compiler.ast.FieldReference reference) {
    if (reference.receiver.isSuper()) {
        final SuperFieldAccess superFieldAccess = new SuperFieldAccess(this.ast);
        if (this.resolveBindings) {
            recordNodes(superFieldAccess, reference);
        }/*ww  w  .j av  a 2s .c om*/
        if (reference.receiver instanceof org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) {
            Name qualifier = convert(
                    (org.eclipse.jdt.internal.compiler.ast.QualifiedSuperReference) reference.receiver);
            superFieldAccess.setQualifier(qualifier);
            if (this.resolveBindings) {
                recordNodes(qualifier, reference.receiver);
            }
        }
        final SimpleName simpleName = new SimpleName(this.ast);
        simpleName.internalSetIdentifier(new String(reference.token));
        int sourceStart = (int) (reference.nameSourcePosition >>> 32);
        int length = (int) (reference.nameSourcePosition & 0xFFFFFFFF) - sourceStart + 1;
        simpleName.setSourceRange(sourceStart, length);
        superFieldAccess.setName(simpleName);
        if (this.resolveBindings) {
            recordNodes(simpleName, reference);
        }
        superFieldAccess.setSourceRange(reference.receiver.sourceStart,
                reference.sourceEnd - reference.receiver.sourceStart + 1);
        return superFieldAccess;
    } else {
        final FieldAccess fieldAccess = new FieldAccess(this.ast);
        if (this.resolveBindings) {
            recordNodes(fieldAccess, reference);
        }
        Expression receiver = convert(reference.receiver);
        fieldAccess.setExpression(receiver);
        final SimpleName simpleName = new SimpleName(this.ast);
        simpleName.internalSetIdentifier(new String(reference.token));
        int sourceStart = (int) (reference.nameSourcePosition >>> 32);
        int length = (int) (reference.nameSourcePosition & 0xFFFFFFFF) - sourceStart + 1;
        simpleName.setSourceRange(sourceStart, length);
        fieldAccess.setName(simpleName);
        if (this.resolveBindings) {
            recordNodes(simpleName, reference);
        }
        fieldAccess.setSourceRange(receiver.getStartPosition(),
                reference.sourceEnd - receiver.getStartPosition() + 1);
        return fieldAccess;
    }
}

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

License:Open Source License

public LabeledStatement convert(org.eclipse.jdt.internal.compiler.ast.LabeledStatement statement) {
    LabeledStatement labeledStatement = new LabeledStatement(this.ast);
    final int sourceStart = statement.sourceStart;
    labeledStatement.setSourceRange(sourceStart, statement.sourceEnd - sourceStart + 1);
    Statement body = convert(statement.statement);
    if (body == null)
        return null;
    labeledStatement.setBody(body);/*  w  ww.j av a  2  s . c  om*/
    final SimpleName name = new SimpleName(this.ast);
    name.internalSetIdentifier(new String(statement.label));
    name.setSourceRange(sourceStart, statement.labelEnd - sourceStart + 1);
    labeledStatement.setLabel(name);
    return labeledStatement;
}

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;//from w  ww  .j  a  va2s .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;
}