Example usage for org.eclipse.jdt.internal.compiler.lookup ProblemMethodBinding ProblemMethodBinding

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

Introduction

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

Prototype

public ProblemMethodBinding(char[] selector, TypeBinding[] args, int problemReason) 

Source Link

Usage

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

License:Open Source License

private MethodBinding getMethodBinding0(MethodPattern methodPattern) {
    if (this.unitScope == null)
        return null;
    // Try to get binding from cache
    Binding binding = (Binding) this.bindings.get(methodPattern);
    if (binding != null) {
        if (binding instanceof MethodBinding && binding.isValidBinding())
            return (MethodBinding) binding;
        return null;
    }//from   w  w  w.  j  av a  2  s .  co  m
    //   Get binding from unit scope
    char[] typeName = PatternLocator.qualifiedPattern(methodPattern.declaringSimpleName,
            methodPattern.declaringQualification);
    if (typeName == null) {
        if (methodPattern.declaringType == null)
            return null;
        typeName = methodPattern.declaringType.getFullyQualifiedName().toCharArray();
    }
    TypeBinding declaringTypeBinding = getType(typeName, typeName);
    if (declaringTypeBinding != null) {
        if (declaringTypeBinding.isArrayType()) {
            declaringTypeBinding = declaringTypeBinding.leafComponentType();
        }
        if (!declaringTypeBinding.isBaseType()) {
            char[][] parameterTypes = methodPattern.parameterSimpleNames;
            if (parameterTypes == null)
                return null;
            int paramTypeslength = parameterTypes.length;
            ReferenceBinding referenceBinding = (ReferenceBinding) declaringTypeBinding;
            MethodBinding[] methods = referenceBinding.getMethods(methodPattern.selector);
            int methodsLength = methods.length;
            TypeVariableBinding[] refTypeVariables = referenceBinding.typeVariables();
            int typeVarLength = refTypeVariables == null ? 0 : refTypeVariables.length;
            for (int i = 0; i < methodsLength; i++) {
                TypeBinding[] methodParameters = methods[i].parameters;
                int paramLength = methodParameters == null ? 0 : methodParameters.length;
                TypeVariableBinding[] methodTypeVariables = methods[i].typeVariables;
                int methTypeVarLength = methodTypeVariables == null ? 0 : methodTypeVariables.length;
                boolean found = false;
                if (methodParameters != null && paramLength == paramTypeslength) {
                    for (int p = 0; p < paramLength; p++) {
                        if (CharOperation.equals(methodParameters[p].sourceName(), parameterTypes[p])) {
                            // param erasure match
                            found = true;
                        } else {
                            // type variable
                            found = false;
                            if (refTypeVariables != null) {
                                for (int v = 0; v < typeVarLength; v++) {
                                    if (!CharOperation.equals(refTypeVariables[v].sourceName,
                                            parameterTypes[p])) {
                                        found = false;
                                        break;
                                    }
                                    found = true;
                                }
                            }
                            if (!found && methodTypeVariables != null) {
                                for (int v = 0; v < methTypeVarLength; v++) {
                                    if (!CharOperation.equals(methodTypeVariables[v].sourceName,
                                            parameterTypes[p])) {
                                        found = false;
                                        break;
                                    }
                                    found = true;
                                }
                            }
                            if (!found)
                                break;
                        }
                    }
                }
                if (found) {
                    this.bindings.put(methodPattern, methods[i]);
                    return methods[i];
                }
            }
        }
    }
    this.bindings.put(methodPattern,
            new ProblemMethodBinding(methodPattern.selector, null, ProblemReasons.NotFound));
    return null;
}

From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java

License:Open Source License

public MethodBinding getConstructor(ReferenceBinding receiverType, TypeBinding[] argumentTypes,
        InvocationSite invocationSite) {
    CompilationUnitScope unitScope = compilationUnitScope();
    LookupEnvironment env = unitScope.environment;
    try {/*from  www  . ja v a  2  s.  c o m*/
        env.missingClassFileLocation = invocationSite;
        unitScope.recordTypeReference(receiverType);
        unitScope.recordTypeReferences(argumentTypes);
        MethodBinding methodBinding = receiverType.getExactConstructor(argumentTypes);
        if (methodBinding != null && methodBinding.canBeSeenBy(invocationSite, this)) {
            // targeting a non generic constructor with type arguments ?
            if (invocationSite.genericTypeArguments() != null)
                methodBinding = computeCompatibleMethod(methodBinding, argumentTypes, invocationSite);
            return methodBinding;
        }
        MethodBinding[] methods = receiverType.getMethods(TypeConstants.INIT, argumentTypes.length);
        if (methods == Binding.NO_METHODS)
            return new ProblemMethodBinding(TypeConstants.INIT, argumentTypes, ProblemReasons.NotFound);

        MethodBinding[] compatible = new MethodBinding[methods.length];
        int compatibleIndex = 0;
        MethodBinding problemMethod = null;
        for (int i = 0, length = methods.length; i < length; i++) {
            MethodBinding compatibleMethod = computeCompatibleMethod(methods[i], argumentTypes, invocationSite);
            if (compatibleMethod != null) {
                if (compatibleMethod.isValidBinding())
                    compatible[compatibleIndex++] = compatibleMethod;
                else if (problemMethod == null)
                    problemMethod = compatibleMethod;
            }
        }
        if (compatibleIndex == 0) {
            if (problemMethod == null)
                return new ProblemMethodBinding(methods[0], TypeConstants.INIT, argumentTypes,
                        ProblemReasons.NotFound);
            return problemMethod;
        }
        // need a more descriptive error... cannot convert from X to Y

        MethodBinding[] visible = new MethodBinding[compatibleIndex];
        int visibleIndex = 0;
        for (int i = 0; i < compatibleIndex; i++) {
            MethodBinding method = compatible[i];
            if (method.canBeSeenBy(invocationSite, this))
                visible[visibleIndex++] = method;
        }
        if (visibleIndex == 1)
            return visible[0];
        if (visibleIndex == 0)
            return new ProblemMethodBinding(compatible[0], TypeConstants.INIT, compatible[0].parameters,
                    ProblemReasons.NotVisible);
        // all of visible are from the same declaringClass, even before 1.4 we can call this method instead of mostSpecificClassMethodBinding
        return mostSpecificMethodBinding(visible, visibleIndex, argumentTypes, invocationSite, receiverType);
    } catch (AbortCompilation e) {
        e.updateContext(invocationSite, referenceCompilationUnit().compilationResult);
        throw e;
    } finally {
        env.missingClassFileLocation = null;
    }
}

From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java

License:Open Source License

public MethodBinding getMethod(TypeBinding receiverType, char[] selector, TypeBinding[] argumentTypes,
        InvocationSite invocationSite) {
    CompilationUnitScope unitScope = compilationUnitScope();
    LookupEnvironment env = unitScope.environment;
    try {/*  ww  w  . j av  a  2 s.  c o  m*/
        env.missingClassFileLocation = invocationSite;
        switch (receiverType.kind()) {
        case Binding.BASE_TYPE:
            return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.NotFound);
        case Binding.ARRAY_TYPE:
            unitScope.recordTypeReference(receiverType);
            return findMethodForArray((ArrayBinding) receiverType, selector, argumentTypes, invocationSite);
        }
        unitScope.recordTypeReference(receiverType);

        ReferenceBinding currentType = (ReferenceBinding) receiverType;
        if (!currentType.canBeSeenBy(this))
            return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.ReceiverTypeNotVisible);

        // retrieve an exact visible match (if possible)
        MethodBinding methodBinding = findExactMethod(currentType, selector, argumentTypes, invocationSite);
        if (methodBinding != null)
            return methodBinding;

        methodBinding = findMethod(currentType, selector, argumentTypes, invocationSite);
        // GROOVY start: give it one more chance as the ast transform may have introduced it
        // is this the right approach?  Requires ast transforms running before this is done
        if (methodBinding == null) {
            methodBinding = oneLastLook(currentType, selector, argumentTypes, invocationSite);
        }
        // GROOVY end
        if (methodBinding == null)
            return new ProblemMethodBinding(selector, argumentTypes, ProblemReasons.NotFound);
        if (!methodBinding.isValidBinding())
            return methodBinding;

        // special treatment for Object.getClass() in 1.5 mode (substitute parameterized return type)
        if (argumentTypes == Binding.NO_PARAMETERS && CharOperation.equals(selector, TypeConstants.GETCLASS)
                && methodBinding.returnType.isParameterizedType()/*1.5*/) {
            return environment().createGetClassMethod(receiverType, methodBinding, this);
        }
        return methodBinding;
    } catch (AbortCompilation e) {
        e.updateContext(invocationSite, referenceCompilationUnit().compilationResult);
        throw e;
    } finally {
        env.missingClassFileLocation = null;
    }
}

From source file:org.eclipse.jdt.internal.core.search.matching.MatchLocator.java

License:Open Source License

public MethodBinding getMethodBinding(MethodPattern methodPattern) {
    if (this.unitScope == null)
        return null;
    // Try to get binding from cache
    Binding binding = (Binding) this.bindings.get(methodPattern);
    if (binding != null) {
        if (binding instanceof MethodBinding && binding.isValidBinding())
            return (MethodBinding) binding;
        return null;
    }/*from   w w  w.  j a v a 2s .c o  m*/
    //   Get binding from unit scope
    char[] typeName = PatternLocator.qualifiedPattern(methodPattern.declaringSimpleName,
            methodPattern.declaringQualification);
    if (typeName == null) {
        if (methodPattern.declaringType == null)
            return null;
        typeName = methodPattern.declaringType.getFullyQualifiedName().toCharArray();
    }
    TypeBinding declaringTypeBinding = getType(typeName, typeName);
    if (declaringTypeBinding != null) {
        if (declaringTypeBinding.isArrayType()) {
            declaringTypeBinding = declaringTypeBinding.leafComponentType();
        }
        if (!declaringTypeBinding.isBaseType()) {
            char[][] parameterTypes = methodPattern.parameterSimpleNames;
            if (parameterTypes == null)
                return null;
            int paramTypeslength = parameterTypes.length;
            ReferenceBinding referenceBinding = (ReferenceBinding) declaringTypeBinding;
            MethodBinding[] methods = referenceBinding.getMethods(methodPattern.selector);
            int methodsLength = methods.length;
            TypeVariableBinding[] refTypeVariables = referenceBinding.typeVariables();
            int typeVarLength = refTypeVariables == null ? 0 : refTypeVariables.length;
            for (int i = 0; i < methodsLength; i++) {
                TypeBinding[] methodParameters = methods[i].parameters;
                int paramLength = methodParameters == null ? 0 : methodParameters.length;
                TypeVariableBinding[] methodTypeVariables = methods[i].typeVariables;
                int methTypeVarLength = methodTypeVariables == null ? 0 : methodTypeVariables.length;
                boolean found = false;
                if (methodParameters != null && paramLength == paramTypeslength) {
                    for (int p = 0; p < paramLength; p++) {
                        if (CharOperation.equals(methodParameters[p].sourceName(), parameterTypes[p])) {
                            // param erasure match
                            found = true;
                        } else {
                            // type variable
                            found = false;
                            if (refTypeVariables != null) {
                                for (int v = 0; v < typeVarLength; v++) {
                                    if (!CharOperation.equals(refTypeVariables[v].sourceName,
                                            parameterTypes[p])) {
                                        found = false;
                                        break;
                                    }
                                    found = true;
                                }
                            }
                            if (!found && methodTypeVariables != null) {
                                for (int v = 0; v < methTypeVarLength; v++) {
                                    if (!CharOperation.equals(methodTypeVariables[v].sourceName,
                                            parameterTypes[p])) {
                                        found = false;
                                        break;
                                    }
                                    found = true;
                                }
                            }
                            if (!found)
                                break;
                        }
                    }
                }
                if (found) {
                    this.bindings.put(methodPattern, methods[i]);
                    return methods[i];
                }
            }
        }
    }
    this.bindings.put(methodPattern,
            new ProblemMethodBinding(methodPattern.selector, null, ProblemReasons.NotFound));
    return null;
}

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  ww.  j a  v  a2s.c  o 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;
}