Example usage for org.eclipse.jdt.internal.compiler.lookup MethodBinding isConstructor

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

Introduction

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

Prototype

public final boolean isConstructor() 

Source Link

Usage

From source file:com.android.build.gradle.tasks.annotations.Extractor.java

License:Apache License

@Nullable
private static String getReturnType(MethodBinding binding) {
    if (binding.returnType != null) {
        return new String(binding.returnType.readableName());
    } else if (binding.declaringClass != null) {
        assert binding.isConstructor();
        return new String(binding.declaringClass.readableName());
    }/* www.ja v  a2 s  . c  o  m*/

    return null;
}

From source file:com.android.build.gradle.tasks.annotations.Extractor.java

License:Apache License

@Nullable
private static String getMethodName(@NonNull MethodBinding binding) {
    if (binding.isConstructor()) {
        if (binding.declaringClass != null) {
            String classFqn = new String(binding.declaringClass.readableName());
            return classFqn.substring(classFqn.lastIndexOf('.') + 1);
        }/*w  w  w .ja  v  a  2 s. com*/

    }
    if (binding.selector != null) {
        return new String(binding.selector);
    }

    assert binding.isConstructor();

    return null;
}

From source file:com.android.tools.lint.psi.EcjPsiBinaryClass.java

License:Apache License

@NonNull
@Override//from  www.j ava 2 s  . c  o  m
public PsiMethod[] getConstructors() {
    if (mBinding instanceof ReferenceBinding) {
        ReferenceBinding cls = (ReferenceBinding) mBinding;
        MethodBinding[] methods = cls.getMethods(TypeConstants.INIT);
        if (methods != null) {
            int count = methods.length;
            List<EcjPsiBinaryMethod> result = Lists.newArrayListWithExpectedSize(count);
            for (MethodBinding method : methods) {
                if (method.isConstructor()) {
                    result.add(new EcjPsiBinaryMethod(mManager, method));
                }
            }
            return result.toArray(PsiMethod.EMPTY_ARRAY);
        }
    }

    return PsiMethod.EMPTY_ARRAY;
}

From source file:com.android.tools.lint.psi.EcjPsiBinaryClass.java

License:Apache License

@NonNull
private PsiMethod[] findMethods(@Nullable String name, boolean includeInherited, boolean includeConstructors) {
    if (mBinding instanceof ReferenceBinding) {
        ReferenceBinding cls = (ReferenceBinding) mBinding;
        if (includeInherited) {
            List<EcjPsiBinaryMethod> result = null;
            while (cls != null) {
                MethodBinding[] methods = name != null ? cls.getMethods(name.toCharArray()) : cls.methods();
                if (methods != null) {
                    int count = methods.length;
                    if (count > 0) {
                        if (result == null) {
                            result = Lists.newArrayListWithExpectedSize(count);
                        }/*ww w.j  ava 2s . c  om*/
                        for (MethodBinding method : methods) {
                            if ((method.modifiers & Modifier.PRIVATE) != 0 && cls != mBinding) {
                                // Ignore parent methods that are private
                                continue;
                            }

                            if (includeConstructors || !method.isConstructor()) {
                                // See if this method looks like it's masked
                                boolean masked = false;
                                for (PsiMethod m : result) {
                                    MethodBinding mb = ((EcjPsiBinaryMethod) m).getBinding();
                                    if (mb.areParameterErasuresEqual(method)) {
                                        masked = true;
                                        break;
                                    }
                                }
                                if (masked) {
                                    continue;
                                }
                                result.add(new EcjPsiBinaryMethod(mManager, method));
                            }
                        }
                    }
                }
                cls = cls.superclass();
            }

            return result != null ? result.toArray(PsiMethod.EMPTY_ARRAY) : PsiMethod.EMPTY_ARRAY;
        } else {
            MethodBinding[] methods = name != null ? cls.getMethods(name.toCharArray()) : cls.methods();
            if (methods != null) {
                int count = methods.length;
                List<EcjPsiBinaryMethod> result = Lists.newArrayListWithExpectedSize(count);
                for (MethodBinding method : methods) {
                    if (includeConstructors || !method.isConstructor()) {
                        result.add(new EcjPsiBinaryMethod(mManager, method));
                    }
                }
                return result.toArray(PsiMethod.EMPTY_ARRAY);
            }
        }
    }

    return PsiMethod.EMPTY_ARRAY;
}

From source file:com.android.tools.lint.psi.EcjPsiManager.java

License:Apache License

/** Computes the super method, if any, given a method binding */
@SuppressWarnings("SameParameterValue")
@Nullable//from  w ww  . ja  v a2  s  . com
static MethodBinding findSuperMethodBinding(@NonNull MethodBinding binding, boolean allowStatic,
        boolean allowPrivate) {
    if (binding.isConstructor()) {
        return null;
    }
    if (!allowPrivate && binding.isPrivate()) {
        return null;
    }
    if (!allowStatic && binding.isStatic()) {
        return null;
    }
    try {
        ReferenceBinding superclass = binding.declaringClass.superclass();
        while (superclass != null) {
            MethodBinding[] methods = superclass.getMethods(binding.selector, binding.parameters.length);
            for (MethodBinding method : methods) {
                if (method.isStatic() != binding.isStatic()) {
                    continue;
                }
                if (method.areParameterErasuresEqual(binding)) {
                    if (method.isPrivate()) {
                        if (method.declaringClass.outermostEnclosingType() == binding.declaringClass
                                .outermostEnclosingType()) {
                            return method;
                        } else {
                            return null;
                        }
                    } else {
                        return method;
                    }
                }
            }

            // TODO: Check interfaces too!

            superclass = superclass.superclass();
        }
    } catch (Exception ignore) {
        // Work around ECJ bugs; see https://code.google.com/p/android/issues/detail?id=172268
    }

    return null;
}

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java

License:Open Source License

private void selectStaticMethodFromStaticImport(CompilationUnitDeclaration parsedUnit, char[] lastToken,
        ReferenceBinding ref) {/*w w w . j  a  v a  2  s.  com*/
    int methodLength = lastToken.length;
    MethodBinding[] methods = ref.availableMethods();
    next: for (int j = 0; j < methods.length; j++) {
        MethodBinding method = methods[j];

        if (method.isSynthetic())
            continue next;

        if (method.isDefaultAbstract())
            continue next;

        if (method.isConstructor())
            continue next;

        if (!method.isStatic())
            continue next;

        if (methodLength > method.selector.length)
            continue next;

        if (!CharOperation.equals(lastToken, method.selector, true))
            continue next;

        selectFrom(method, parsedUnit, false);
    }
}

From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java

License:Open Source License

private void selectFrom(Binding binding, CompilationUnitDeclaration parsedUnit, ICompilationUnit unit,
        boolean isDeclaration) {
    if (binding instanceof TypeVariableBinding) {
        TypeVariableBinding typeVariableBinding = (TypeVariableBinding) binding;
        Binding enclosingElement = typeVariableBinding.declaringElement;
        this.noProposal = false;

        if (enclosingElement instanceof SourceTypeBinding) {
            SourceTypeBinding enclosingType = (SourceTypeBinding) enclosingElement;
            if (isLocal(enclosingType) && this.requestor instanceof SelectionRequestor) {
                ((SelectionRequestor) this.requestor).acceptLocalTypeParameter(typeVariableBinding);
            } else {
                this.requestor.acceptTypeParameter(enclosingType.qualifiedPackageName(),
                        enclosingType.qualifiedSourceName(), typeVariableBinding.sourceName(), false,
                        this.actualSelectionStart, this.actualSelectionEnd);
            }/*from  w w w  . j a  v a  2 s  . c o  m*/
        } else if (enclosingElement instanceof MethodBinding) {
            MethodBinding enclosingMethod = (MethodBinding) enclosingElement;
            if (isLocal(enclosingMethod.declaringClass) && this.requestor instanceof SelectionRequestor) {
                ((SelectionRequestor) this.requestor).acceptLocalMethodTypeParameter(typeVariableBinding);
            } else {
                this.requestor.acceptMethodTypeParameter(enclosingMethod.declaringClass.qualifiedPackageName(),
                        enclosingMethod.declaringClass.qualifiedSourceName(),
                        enclosingMethod.isConstructor() ? enclosingMethod.declaringClass.sourceName()
                                : enclosingMethod.selector,
                        enclosingMethod.sourceStart(), enclosingMethod.sourceEnd(),
                        typeVariableBinding.sourceName(), false, this.actualSelectionStart,
                        this.actualSelectionEnd);
            }
        }
        this.acceptedAnswer = true;
    } else if (binding instanceof ReferenceBinding) {
        ReferenceBinding typeBinding = (ReferenceBinding) binding;
        if (typeBinding instanceof ProblemReferenceBinding) {
            TypeBinding closestMatch = typeBinding.closestMatch();
            if (closestMatch instanceof ReferenceBinding) {
                typeBinding = (ReferenceBinding) closestMatch;
            } else {
                typeBinding = null;
            }
        }
        if (typeBinding == null)
            return;
        if (isLocal(typeBinding) && this.requestor instanceof SelectionRequestor) {
            this.noProposal = false;
            ((SelectionRequestor) this.requestor).acceptLocalType(typeBinding);
        } else {
            this.noProposal = false;

            this.requestor.acceptType(typeBinding.qualifiedPackageName(), typeBinding.qualifiedSourceName(),
                    typeBinding.modifiers, false, typeBinding.computeUniqueKey(), this.actualSelectionStart,
                    this.actualSelectionEnd);
        }
        this.acceptedAnswer = true;
    } else if (binding instanceof MethodBinding) {
        MethodBinding methodBinding = getCorrectMethodBinding((MethodBinding) binding);
        this.noProposal = false;

        boolean isValuesOrValueOf = false;
        if (binding instanceof SyntheticMethodBinding) {
            SyntheticMethodBinding syntheticMethodBinding = (SyntheticMethodBinding) binding;
            if (syntheticMethodBinding.purpose == SyntheticMethodBinding.EnumValues
                    || syntheticMethodBinding.purpose == SyntheticMethodBinding.EnumValueOf) {
                isValuesOrValueOf = true;
            }
        }

        if (!isValuesOrValueOf && !methodBinding.isSynthetic()) {
            TypeBinding[] parameterTypes = methodBinding.original().parameters;
            int length = parameterTypes.length;
            char[][] parameterPackageNames = new char[length][];
            char[][] parameterTypeNames = new char[length][];
            String[] parameterSignatures = new String[length];
            for (int i = 0; i < length; i++) {
                parameterPackageNames[i] = parameterTypes[i].qualifiedPackageName();
                parameterTypeNames[i] = parameterTypes[i].qualifiedSourceName();
                parameterSignatures[i] = new String(getSignature(parameterTypes[i])).replace('/', '.');
            }

            TypeVariableBinding[] typeVariables = methodBinding.original().typeVariables;
            length = typeVariables == null ? 0 : typeVariables.length;
            char[][] typeParameterNames = new char[length][];
            char[][][] typeParameterBoundNames = new char[length][][];
            for (int i = 0; i < length; i++) {
                TypeVariableBinding typeVariable = typeVariables[i];
                typeParameterNames[i] = typeVariable.sourceName;
                if (typeVariable.firstBound == null) {
                    typeParameterBoundNames[i] = new char[0][];
                } else if (TypeBinding.equalsEquals(typeVariable.firstBound, typeVariable.superclass)) {
                    int boundCount = 1
                            + (typeVariable.superInterfaces == null ? 0 : typeVariable.superInterfaces.length);
                    typeParameterBoundNames[i] = new char[boundCount][];
                    typeParameterBoundNames[i][0] = typeVariable.superclass.sourceName;
                    for (int j = 1; j < boundCount; j++) {
                        typeParameterBoundNames[i][j] = typeVariables[i].superInterfaces[j - 1].sourceName;
                    }
                } else {
                    int boundCount = typeVariable.superInterfaces == null ? 0
                            : typeVariable.superInterfaces.length;
                    typeParameterBoundNames[i] = new char[boundCount][];
                    for (int j = 0; j < boundCount; j++) {
                        typeParameterBoundNames[i][j] = typeVariables[i].superInterfaces[j].sourceName;
                    }
                }
            }

            ReferenceBinding declaringClass = methodBinding.declaringClass;
            if (isLocal(declaringClass) && this.requestor instanceof SelectionRequestor) {
                ((SelectionRequestor) this.requestor).acceptLocalMethod(methodBinding);
            } else {
                this.requestor.acceptMethod(declaringClass.qualifiedPackageName(),
                        declaringClass.qualifiedSourceName(),
                        declaringClass.enclosingType() == null ? null
                                : new String(getSignature(declaringClass.enclosingType())),
                        methodBinding.isConstructor() ? declaringClass.sourceName() : methodBinding.selector,
                        parameterPackageNames, parameterTypeNames, parameterSignatures, typeParameterNames,
                        typeParameterBoundNames, methodBinding.isConstructor(), isDeclaration,
                        methodBinding.computeUniqueKey(), this.actualSelectionStart, this.actualSelectionEnd);
            }
        }
        this.acceptedAnswer = true;
    } else if (binding instanceof FieldBinding) {
        FieldBinding fieldBinding = (FieldBinding) binding;
        ReferenceBinding declaringClass = fieldBinding.declaringClass;
        if (declaringClass != null) { // arraylength
            this.noProposal = false;
            if (isLocal(declaringClass) && this.requestor instanceof SelectionRequestor) {
                ((SelectionRequestor) this.requestor).acceptLocalField(fieldBinding);
            } else {
                // if the binding is a problem field binding, we want to make sure
                // we can retrieve the closestMatch if the problem reason is NotVisible
                FieldBinding currentFieldBinding = fieldBinding;
                while (currentFieldBinding instanceof ProblemFieldBinding) {
                    ProblemFieldBinding problemFieldBinding = (ProblemFieldBinding) currentFieldBinding;
                    if (problemFieldBinding.problemId() == ProblemReasons.NotVisible) {
                        currentFieldBinding = problemFieldBinding.closestMatch;
                    } else {
                        currentFieldBinding = null;
                    }
                }
                char[] fieldName = null;
                char[] key = null;
                if (currentFieldBinding != null) {
                    fieldName = currentFieldBinding.name;
                    key = currentFieldBinding.computeUniqueKey();
                } else {
                    fieldName = fieldBinding.name;
                    key = fieldBinding.computeUniqueKey();
                }
                this.requestor.acceptField(declaringClass.qualifiedPackageName(),
                        declaringClass.qualifiedSourceName(), fieldName, false, key, this.actualSelectionStart,
                        this.actualSelectionEnd);
            }
            this.acceptedAnswer = true;
        }
    } else if (binding instanceof LocalVariableBinding) {
        if (this.requestor instanceof SelectionRequestor) {
            ((SelectionRequestor) this.requestor).acceptLocalVariable((LocalVariableBinding) binding, unit);
            this.acceptedAnswer = true;
        } else {
            // open on the type of the variable
            selectFrom(((LocalVariableBinding) binding).type, parsedUnit, false);
        }
    } else if (binding instanceof ArrayBinding) {
        selectFrom(((ArrayBinding) binding).leafComponentType, parsedUnit, false);
        // open on the type of the array
    } else if (binding instanceof PackageBinding) {
        PackageBinding packageBinding = (PackageBinding) binding;
        this.noProposal = false;
        this.requestor.acceptPackage(packageBinding.readableName());
        this.acceptedAnswer = true;
    } else if (binding instanceof BaseTypeBinding) {
        this.acceptedAnswer = true;
    }
}

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

License:Open Source License

/**
 * Locate declaration in the current class file. This class file is always in a jar.
 *//*ww  w.  j  a v  a 2  s.  c om*/
public void locateMatches(MatchLocator locator, ClassFile classFile, IBinaryType info) throws CoreException {
    SearchPattern pattern = locator.pattern;

    // check annotations references
    matchAnnotations(pattern, locator, classFile, info);

    // check class definition
    BinaryType binaryType = (BinaryType) classFile.getType();
    if (matchBinary(pattern, info, null)) {
        binaryType = new ResolvedBinaryType((JavaElement) binaryType.getParent(), binaryType.getElementName(),
                binaryType.getKey());
        locator.reportBinaryMemberDeclaration(null, binaryType, null, info, SearchMatch.A_ACCURATE);
        return;
    }

    // Define arrays to store methods/fields from binary type if necessary
    IBinaryMethod[] binaryMethods = info.getMethods();
    int bMethodsLength = binaryMethods == null ? 0 : binaryMethods.length;
    IBinaryMethod[] unresolvedMethods = null;
    char[][] binaryMethodSignatures = null;
    boolean hasUnresolvedMethods = false;

    // Get fields from binary type info
    IBinaryField[] binaryFields = info.getFields();
    int bFieldsLength = binaryFields == null ? 0 : binaryFields.length;
    IBinaryField[] unresolvedFields = null;
    boolean hasUnresolvedFields = false;

    // Report as many accurate matches as possible
    int accuracy = SearchMatch.A_ACCURATE;
    boolean mustResolve = pattern.mustResolve;
    if (mustResolve) {
        BinaryTypeBinding binding = locator.cacheBinaryType(binaryType, info);
        if (binding != null) {
            // filter out element not in hierarchy scope
            if (!locator.typeInHierarchy(binding))
                return;

            // Search matches on resolved methods
            MethodBinding[] availableMethods = binding.availableMethods();
            int aMethodsLength = availableMethods == null ? 0 : availableMethods.length;
            hasUnresolvedMethods = bMethodsLength != aMethodsLength;
            for (int i = 0; i < aMethodsLength; i++) {
                MethodBinding method = availableMethods[i];
                char[] methodSignature = method.genericSignature();
                if (methodSignature == null)
                    methodSignature = method.signature();

                // Report the match if possible
                int level = locator.patternLocator.resolveLevel(method);
                if (level != PatternLocator.IMPOSSIBLE_MATCH) {
                    IMethod methodHandle = binaryType.getMethod(
                            new String(method.isConstructor()
                                    ? binding.compoundName[binding.compoundName.length - 1]
                                    : method.selector),
                            CharOperation.toStrings(
                                    Signature.getParameterTypes(convertClassFileFormat(methodSignature))));
                    accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE
                            : SearchMatch.A_INACCURATE;
                    locator.reportBinaryMemberDeclaration(null, methodHandle, method, info, accuracy);
                }

                // Remove method from unresolved list
                if (hasUnresolvedMethods) {
                    if (binaryMethodSignatures == null) { // Store binary method signatures to avoid multiple computation
                        binaryMethodSignatures = new char[bMethodsLength][];
                        for (int j = 0; j < bMethodsLength; j++) {
                            IBinaryMethod binaryMethod = binaryMethods[j];
                            char[] signature = binaryMethod.getGenericSignature();
                            if (signature == null)
                                signature = binaryMethod.getMethodDescriptor();
                            binaryMethodSignatures[j] = signature;
                        }
                    }
                    for (int j = 0; j < bMethodsLength; j++) {
                        if (CharOperation.equals(binaryMethods[j].getSelector(), method.selector)
                                && CharOperation.equals(binaryMethodSignatures[j], methodSignature)) {
                            if (unresolvedMethods == null) {
                                System.arraycopy(binaryMethods, 0,
                                        unresolvedMethods = new IBinaryMethod[bMethodsLength], 0,
                                        bMethodsLength);
                            }
                            unresolvedMethods[j] = null;
                            break;
                        }
                    }
                }
            }

            // Search matches on resolved fields
            FieldBinding[] availableFields = binding.availableFields();
            int aFieldsLength = availableFields == null ? 0 : availableFields.length;
            hasUnresolvedFields = bFieldsLength != aFieldsLength;
            for (int i = 0; i < aFieldsLength; i++) {
                FieldBinding field = availableFields[i];

                // Report the match if possible
                int level = locator.patternLocator.resolveLevel(field);
                if (level != PatternLocator.IMPOSSIBLE_MATCH) {
                    IField fieldHandle = binaryType.getField(new String(field.name));
                    accuracy = level == PatternLocator.ACCURATE_MATCH ? SearchMatch.A_ACCURATE
                            : SearchMatch.A_INACCURATE;
                    locator.reportBinaryMemberDeclaration(null, fieldHandle, field, info, accuracy);
                }

                // Remove the field from unresolved list
                if (hasUnresolvedFields) {
                    for (int j = 0; j < bFieldsLength; j++) {
                        if (CharOperation.equals(binaryFields[j].getName(), field.name)) {
                            if (unresolvedFields == null) {
                                System.arraycopy(binaryFields, 0,
                                        unresolvedFields = new IBinaryField[bFieldsLength], 0, bFieldsLength);
                            }
                            unresolvedFields[j] = null;
                            break;
                        }
                    }
                }
            }

            // If all methods/fields were accurate then returns now
            if (!hasUnresolvedMethods && !hasUnresolvedFields) {
                return;
            }
        }
        accuracy = SearchMatch.A_INACCURATE;
    }

    // Report inaccurate methods
    if (mustResolve)
        binaryMethods = unresolvedMethods;
    bMethodsLength = binaryMethods == null ? 0 : binaryMethods.length;
    for (int i = 0; i < bMethodsLength; i++) {
        IBinaryMethod method = binaryMethods[i];
        if (method == null)
            continue; // impossible match or already reported as accurate
        if (matchBinary(pattern, method, info)) {
            char[] name;
            if (method.isConstructor()) {
                // https://bugs.eclipse.org/bugs/show_bug.cgi?id=329727
                // We don't need the enclosing type name for the constructor name
                name = info.getSourceName();
            } else {
                name = method.getSelector();
            }
            String selector = new String(name);
            char[] methodSignature = binaryMethodSignatures == null ? null : binaryMethodSignatures[i];
            if (methodSignature == null) {
                methodSignature = method.getGenericSignature();
                if (methodSignature == null)
                    methodSignature = method.getMethodDescriptor();
            }
            String[] parameterTypes = CharOperation
                    .toStrings(Signature.getParameterTypes(convertClassFileFormat(methodSignature)));
            IMethod methodHandle = binaryType.getMethod(selector, parameterTypes);
            methodHandle = new ResolvedBinaryMethod(binaryType, selector, parameterTypes,
                    methodHandle.getKey());
            locator.reportBinaryMemberDeclaration(null, methodHandle, null, info, accuracy);
        }
    }

    // Report inaccurate fields
    if (mustResolve)
        binaryFields = unresolvedFields;
    bFieldsLength = binaryFields == null ? 0 : binaryFields.length;
    for (int i = 0; i < bFieldsLength; i++) {
        IBinaryField field = binaryFields[i];
        if (field == null)
            continue; // impossible match or already reported as accurate
        if (matchBinary(pattern, field, info)) {
            String fieldName = new String(field.getName());
            IField fieldHandle = binaryType.getField(fieldName);
            fieldHandle = new ResolvedBinaryField(binaryType, fieldName, fieldHandle.getKey());
            locator.reportBinaryMemberDeclaration(null, fieldHandle, null, info, accuracy);
        }
    }
}

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

License:Open Source License

protected int matchConstructor(MethodBinding constructor) {
    if (!constructor.isConstructor())
        return IMPOSSIBLE_MATCH;

    // declaring type, simple name has already been matched by matchIndexEntry()
    int level = resolveLevelForType(this.pattern.declaringSimpleName, this.pattern.declaringQualification,
            constructor.declaringClass);
    if (level == IMPOSSIBLE_MATCH)
        return IMPOSSIBLE_MATCH;

    // parameter types
    int parameterCount = this.pattern.parameterCount;
    if (parameterCount > -1) {
        if (constructor.parameters == null)
            return INACCURATE_MATCH;
        if (parameterCount != constructor.parameters.length)
            return IMPOSSIBLE_MATCH;
        for (int i = 0; i < parameterCount; i++) {
            // TODO (frederic) use this call to refine accuracy on parameter types
            //         int newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i], this.pattern.parameterQualifications[i], this.pattern.parametersTypeArguments[i], 0, constructor.parameters[i]);
            int newLevel = resolveLevelForType(this.pattern.parameterSimpleNames[i],
                    this.pattern.parameterQualifications[i], constructor.parameters[i]);
            if (level > newLevel) {
                if (newLevel == IMPOSSIBLE_MATCH) {
                    //               if (isErasureMatch) {
                    //                  return ERASURE_MATCH;
                    //               }
                    return IMPOSSIBLE_MATCH;
                }/*from  ww w  .j  a  v  a  2  s.  c o  m*/
                level = newLevel; // can only be downgraded
            }
        }
    }
    return level;
}

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

License:Open Source License

protected int matchTypeParameter(TypeVariableBinding variable, boolean matchName) {
    if (variable == null || variable.declaringElement == null)
        return INACCURATE_MATCH;
    if (variable.declaringElement instanceof ReferenceBinding) {
        ReferenceBinding refBinding = (ReferenceBinding) variable.declaringElement;
        if (matchesName(refBinding.sourceName, this.pattern.declaringMemberName)) {
            return ACCURATE_MATCH;
        }/* ww  w.j a  v a2 s.  c om*/
    } else if (variable.declaringElement instanceof MethodBinding) {
        MethodBinding methBinding = (MethodBinding) variable.declaringElement;
        if (matchesName(methBinding.declaringClass.sourceName, this.pattern.methodDeclaringClassName)
                && (methBinding.isConstructor()
                        || matchesName(methBinding.selector, this.pattern.declaringMemberName))) {
            int length = this.pattern.methodArgumentTypes == null ? 0 : this.pattern.methodArgumentTypes.length;
            if (methBinding.parameters == null) {
                if (length == 0)
                    return ACCURATE_MATCH;
            } else if (methBinding.parameters.length == length) {
                for (int i = 0; i < length; i++) {
                    if (!matchesName(methBinding.parameters[i].shortReadableName(),
                            this.pattern.methodArgumentTypes[i])) {
                        return IMPOSSIBLE_MATCH;
                    }
                }
                return ACCURATE_MATCH;
            }
        }
    }
    return IMPOSSIBLE_MATCH;
}