Example usage for org.eclipse.jdt.internal.compiler.ast MessageSend isSuperAccess

List of usage examples for org.eclipse.jdt.internal.compiler.ast MessageSend isSuperAccess

Introduction

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

Prototype

@Override
    public boolean isSuperAccess() 

Source Link

Usage

From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MethodLocator.java

License:Open Source License

/**
 * Returns whether the code gen will use an invoke virtual for
 * this message send or not.//from  w ww  .j  a  v a 2 s . c  om
 */
protected boolean isVirtualInvoke(MethodBinding method, MessageSend messageSend) {
    return !method.isStatic() && !method.isPrivate() && !messageSend.isSuperAccess()
            && !(method.isDefault() && this.pattern.focus != null && !CharOperation
                    .equals(this.pattern.declaringPackageName, method.declaringClass.qualifiedPackageName()));
}

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 v a2s. co  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;
}