Example usage for org.eclipse.jdt.internal.compiler.lookup TypeBinding isProvablyDistinct

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

Introduction

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

Prototype

public boolean isProvablyDistinct(TypeBinding otherType) 

Source Link

Document

Returns true if a type is provably distinct from another one,

Usage

From source file:lombok.eclipse.agent.PatchExtensionMethod.java

License:Open Source License

private static List<MethodBinding> getApplicableExtensionMethodsDefinedInProvider(EclipseNode typeNode,
        ReferenceBinding extensionMethodProviderBinding, TypeBinding receiverType) {

    List<MethodBinding> extensionMethods = new ArrayList<MethodBinding>();
    CompilationUnitScope cuScope = ((CompilationUnitDeclaration) typeNode.top().get()).scope;
    for (MethodBinding method : extensionMethodProviderBinding.methods()) {
        if (!method.isStatic())
            continue;
        if (!method.isPublic())
            continue;
        if (method.parameters == null || method.parameters.length == 0)
            continue;
        TypeBinding firstArgType = method.parameters[0];
        if (receiverType.isProvablyDistinct(firstArgType)
                && !receiverType.isCompatibleWith(firstArgType.erasure()))
            continue;
        TypeBinding[] argumentTypes = Arrays.copyOfRange(method.parameters, 1, method.parameters.length);
        if ((receiverType instanceof ReferenceBinding) && ((ReferenceBinding) receiverType)
                .getExactMethod(method.selector, argumentTypes, cuScope) != null)
            continue;
        extensionMethods.add(method);//w w w  . jav  a 2s  .  c  o m
    }
    return extensionMethods;
}

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

License:Open Source License

/**
 * Returns true if the two types have an incompatible common supertype,
 * e.g. List<String> and List<Integer>
 *//*w w w  . j a v  a2 s .c o  m*/
public boolean hasIncompatibleSuperType(ReferenceBinding otherType) {

    if (this == otherType)
        return false;

    ReferenceBinding[] interfacesToVisit = null;
    int nextPosition = 0;
    ReferenceBinding currentType = this;
    TypeBinding match;
    do {
        match = otherType.findSuperTypeOriginatingFrom(currentType);
        if (match != null && match.isProvablyDistinct(currentType))
            return true;

        ReferenceBinding[] itsInterfaces = currentType.superInterfaces();
        if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) {
            if (interfacesToVisit == null) {
                interfacesToVisit = itsInterfaces;
                nextPosition = interfacesToVisit.length;
            } else {
                int itsLength = itsInterfaces.length;
                if (nextPosition + itsLength >= interfacesToVisit.length)
                    System.arraycopy(interfacesToVisit, 0,
                            interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0,
                            nextPosition);
                nextInterface: for (int a = 0; a < itsLength; a++) {
                    ReferenceBinding next = itsInterfaces[a];
                    for (int b = 0; b < nextPosition; b++)
                        if (next == interfacesToVisit[b])
                            continue nextInterface;
                    interfacesToVisit[nextPosition++] = next;
                }
            }
        }
    } while ((currentType = currentType.superclass()) != null);

    for (int i = 0; i < nextPosition; i++) {
        currentType = interfacesToVisit[i];
        if (currentType == otherType)
            return false;
        match = otherType.findSuperTypeOriginatingFrom(currentType);
        if (match != null && match.isProvablyDistinct(currentType))
            return true;

        ReferenceBinding[] itsInterfaces = currentType.superInterfaces();
        if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) {
            int itsLength = itsInterfaces.length;
            if (nextPosition + itsLength >= interfacesToVisit.length)
                System.arraycopy(interfacesToVisit, 0,
                        interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0,
                        nextPosition);
            nextInterface: for (int a = 0; a < itsLength; a++) {
                ReferenceBinding next = itsInterfaces[a];
                for (int b = 0; b < nextPosition; b++)
                    if (next == interfacesToVisit[b])
                        continue nextInterface;
                interfacesToVisit[nextPosition++] = next;
            }
        }
    }
    return false;
}