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

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

Introduction

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

Prototype

MethodInvocation(AST ast) 

Source Link

Document

Creates a new AST node for a method invocation expression owned by the given AST.

Usage

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 .j  a  va 2s  .  c o m*/
    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;
}