Example usage for org.eclipse.jdt.internal.compiler.lookup Scope COMPATIBLE

List of usage examples for org.eclipse.jdt.internal.compiler.lookup Scope COMPATIBLE

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.lookup Scope COMPATIBLE.

Prototype

int COMPATIBLE

To view the source code for org.eclipse.jdt.internal.compiler.lookup Scope COMPATIBLE.

Click Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.TSuperMessageSend.java

License:Open Source License

@Override
protected TypeBinding findMethodBinding(BlockScope scope) {

    // check: is a tsuper call legal in the current context?

    AbstractMethodDeclaration context = scope.methodScope().referenceMethod();
    if (context == null || !CharOperation.equals(this.selector, context.selector)
            || context.binding.parameters.length != this.argumentTypes.length) {
        scope.problemReporter().tsuperCallsWrongMethod(this);
        return null;
    }/*w  w  w . ja  v  a2s .co  m*/

    ReferenceBinding receiverRole;
    if (!(this.actualReceiverType instanceof ReferenceBinding)
            || !(receiverRole = (ReferenceBinding) this.actualReceiverType).isSourceRole()) {
        scope.problemReporter().tsuperOutsideRole(context, this, this.actualReceiverType);
        return null;
    }

    ReferenceBinding[] tsuperRoleBindings = receiverRole.roleModel.getTSuperRoleBindings();
    if (tsuperRoleBindings.length == 0) {
        scope.problemReporter().tsuperCallWithoutTsuperRole(receiverRole, this);
        return null;
    }

    // context is OK, start searching:

    this.tsuperReference.resolveType(scope);
    // qualified tsuper? => directly search within the designated tsuper role:
    if (this.tsuperReference.qualification != null) {
        TypeBinding tsuperRole = this.tsuperReference.resolvedType;
        if (tsuperRole == null || !tsuperRole.isRole())
            return null;
        this.binding = scope.getMethod(tsuperRole, this.selector, this.argumentTypes, this);
        if (!this.binding.isValidBinding() && ((ProblemMethodBinding) this.binding).declaringClass == null)
            this.binding.declaringClass = (ReferenceBinding) tsuperRole;
        resolvePolyExpressionArguments(this, this.binding, this.argumentTypes, scope);
        return this.binding.returnType;
    }
    // no qualification => search all tsupers by priority:
    MethodBinding bestMatch = null;
    for (int i = tsuperRoleBindings.length - 1; i >= 0; i--) {
        ReferenceBinding tsuperRole = tsuperRoleBindings[i];
        MethodBinding candidate = scope.getMethod(tsuperRole, this.selector, this.argumentTypes, this);
        if (candidate.isValidBinding()) {
            if (scope.parameterCompatibilityLevel(candidate, this.argumentTypes) != Scope.COMPATIBLE) {
                scope.problemReporter().tsuperCallsWrongMethod(this);
                return candidate.returnType;
            }
            this.binding = candidate;
            resolvePolyExpressionArguments(this, this.binding, this.argumentTypes, scope);
            return this.binding.returnType;
        }
        if (bestMatch == null || (bestMatch.problemId() == ProblemReasons.NotFound
                && candidate.problemId() != ProblemReasons.NotFound))
            bestMatch = candidate;
    }
    if (bestMatch == null)
        bestMatch = new ProblemMethodBinding(this.selector, this.argumentTypes, ProblemReasons.NotFound);
    if (bestMatch.declaringClass == null)
        bestMatch.declaringClass = (ReferenceBinding) this.tsuperReference.resolvedType;
    this.binding = bestMatch;
    return this.binding.returnType;
}