Example usage for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding binarySearch

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

Introduction

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

Prototype

static int binarySearch(char[] sourceName, ReferenceBinding[] sortedMemberTypes) 

Source Link

Document

Search the given sourceName in the list of sorted member types.

Usage

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

License:Open Source License

boolean implementsMethod(MethodBinding method) {
    char[] selector = method.selector;
    ReferenceBinding type = this;
    while (type != null) {
        MethodBinding[] methods = type.methods();
        long range;
        if ((range = ReferenceBinding.binarySearch(selector, methods)) >= 0) {
            int start = (int) range, end = (int) (range >> 32);
            for (int i = start; i <= end; i++) {
                if (methods[i].areParametersEqual(method))
                    return true;
            }/*from   w  w w  .  j a v a 2  s . c o m*/
        }
        type = type.superclass();
    }
    return false;
}

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

License:Open Source License

public MethodBinding getExactConstructor(TypeBinding[] argumentTypes) {
    int argCount = argumentTypes.length;
    if ((this.tagBits & TagBits.AreMethodsComplete) != 0) { // have resolved all arg types & return type of the methods
        long range;
        if ((range = ReferenceBinding.binarySearch(TypeConstants.INIT, this.methods)) >= 0) {
            nextMethod: for (int imethod = (int) range, end = (int) (range >> 32); imethod <= end; imethod++) {
                MethodBinding method = this.methods[imethod];
                if (method.parameters.length == argCount) {
                    TypeBinding[] toMatch = method.parameters;
                    for (int iarg = 0; iarg < argCount; iarg++)
                        if (toMatch[iarg] != argumentTypes[iarg])
                            continue nextMethod;
                    return method;
                }/*from w ww.j a  v a 2s.  c  o  m*/
            }
        }
    } else {
        // lazily sort methods
        if ((this.tagBits & TagBits.AreMethodsSorted) == 0) {
            int length = this.methods.length;
            if (length > 1)
                ReferenceBinding.sortMethods(this.methods, 0, length);
            this.tagBits |= TagBits.AreMethodsSorted;
        }
        long range;
        if ((range = ReferenceBinding.binarySearch(TypeConstants.INIT, this.methods)) >= 0) {
            nextMethod: for (int imethod = (int) range, end = (int) (range >> 32); imethod <= end; imethod++) {
                MethodBinding method = this.methods[imethod];
                if (resolveTypesFor(method) == null || method.returnType == null) {
                    methods();
                    return getExactConstructor(argumentTypes); // try again since the problem methods have been removed
                }
                if (method.parameters.length == argCount) {
                    TypeBinding[] toMatch = method.parameters;
                    for (int iarg = 0; iarg < argCount; iarg++)
                        if (toMatch[iarg] != argumentTypes[iarg])
                            continue nextMethod;
                    return method;
                }
            }
        }
    }
    return null;
}

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

License:Open Source License

public MethodBinding getExactMethod(char[] selector, TypeBinding[] argumentTypes,
        CompilationUnitScope refScope) {
    // sender from refScope calls recordTypeReference(this)
    int argCount = argumentTypes.length;
    boolean foundNothing = true;

    if ((this.tagBits & TagBits.AreMethodsComplete) != 0) { // have resolved all arg types & return type of the methods
        long range;
        if ((range = ReferenceBinding.binarySearch(selector, this.methods)) >= 0) {
            nextMethod: for (int imethod = (int) range, end = (int) (range >> 32); imethod <= end; imethod++) {
                MethodBinding method = this.methods[imethod];
                foundNothing = false; // inner type lookups must know that a method with this name exists
                if (method.parameters.length == argCount) {
                    TypeBinding[] toMatch = method.parameters;
                    for (int iarg = 0; iarg < argCount; iarg++)
                        if (toMatch[iarg] != argumentTypes[iarg])
                            continue nextMethod;
                    return method;
                }/* w  ww.ja va 2 s  . c om*/
            }
        }
    } else {
        // lazily sort methods
        if ((this.tagBits & TagBits.AreMethodsSorted) == 0) {
            int length = this.methods.length;
            if (length > 1)
                ReferenceBinding.sortMethods(this.methods, 0, length);
            this.tagBits |= TagBits.AreMethodsSorted;
        }

        long range;
        if ((range = ReferenceBinding.binarySearch(selector, this.methods)) >= 0) {
            // check unresolved method
            int start = (int) range, end = (int) (range >> 32);
            for (int imethod = start; imethod <= end; imethod++) {
                MethodBinding method = this.methods[imethod];
                if (resolveTypesFor(method) == null || method.returnType == null) {
                    methods();
                    return getExactMethod(selector, argumentTypes, refScope); // try again since the problem methods have been removed
                }
            }
            // check dup collisions
            boolean isSource15 = this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5;
            for (int i = start; i <= end; i++) {
                MethodBinding method1 = this.methods[i];
                for (int j = end; j > i; j--) {
                    MethodBinding method2 = this.methods[j];
                    boolean paramsMatch = isSource15 ? method1.areParameterErasuresEqual(method2)
                            : method1.areParametersEqual(method2);
                    if (paramsMatch) {
                        methods();
                        return getExactMethod(selector, argumentTypes, refScope); // try again since the problem methods have been removed
                    }
                }
            }
            nextMethod: for (int imethod = start; imethod <= end; imethod++) {
                MethodBinding method = this.methods[imethod];
                TypeBinding[] toMatch = method.parameters;
                if (toMatch.length == argCount) {
                    for (int iarg = 0; iarg < argCount; iarg++)
                        if (toMatch[iarg] != argumentTypes[iarg])
                            continue nextMethod;
                    return method;
                }
            }
        }
    }

    if (foundNothing) {
        if (isInterface()) {
            if (this.superInterfaces.length == 1) {
                if (refScope != null)
                    refScope.recordTypeReference(this.superInterfaces[0]);
                return this.superInterfaces[0].getExactMethod(selector, argumentTypes, refScope);
            }
        } else if (this.superclass != null) {
            if (refScope != null)
                refScope.recordTypeReference(this.superclass);
            return this.superclass.getExactMethod(selector, argumentTypes, refScope);
        }
    }
    return null;
}

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

License:Open Source License

public FieldBinding getField(char[] fieldName, boolean needResolve) {

    if ((this.tagBits & TagBits.AreFieldsComplete) != 0)
        return ReferenceBinding.binarySearch(fieldName, this.fields);

    // lazily sort fields
    if ((this.tagBits & TagBits.AreFieldsSorted) == 0) {
        int length = this.fields.length;
        if (length > 1)
            ReferenceBinding.sortFields(this.fields, 0, length);
        this.tagBits |= TagBits.AreFieldsSorted;
    }/* w  w w.j  av  a  2s .  c o  m*/
    // always resolve anyway on source types
    FieldBinding field = ReferenceBinding.binarySearch(fieldName, this.fields);
    if (field != null) {
        FieldBinding result = null;
        try {
            result = resolveTypeFor(field);
            return result;
        } finally {
            if (result == null) {
                // ensure fields are consistent reqardless of the error
                int newSize = this.fields.length - 1;
                if (newSize == 0) {
                    this.fields = Binding.NO_FIELDS;
                } else {
                    FieldBinding[] newFields = new FieldBinding[newSize];
                    int index = 0;
                    for (int i = 0, length = this.fields.length; i < length; i++) {
                        FieldBinding f = this.fields[i];
                        if (f == field)
                            continue;
                        newFields[index++] = f;
                    }
                    this.fields = newFields;
                }
            }
        }
    }
    return null;
}

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

License:Open Source License

public MethodBinding[] getMethods(char[] selector) {
    if ((this.tagBits & TagBits.AreMethodsComplete) != 0) {
        long range;
        if ((range = ReferenceBinding.binarySearch(selector, this.methods)) >= 0) {
            int start = (int) range, end = (int) (range >> 32);
            int length = end - start + 1;
            MethodBinding[] result;/*from   w  w  w . j  a  v  a  2  s.  c  o  m*/
            System.arraycopy(this.methods, start, result = new MethodBinding[length], 0, length);
            return result;
        } else {
            return Binding.NO_METHODS;
        }
    }
    // lazily sort methods
    if ((this.tagBits & TagBits.AreMethodsSorted) == 0) {
        int length = this.methods.length;
        if (length > 1)
            ReferenceBinding.sortMethods(this.methods, 0, length);
        this.tagBits |= TagBits.AreMethodsSorted;
    }
    MethodBinding[] result;
    long range;
    if ((range = ReferenceBinding.binarySearch(selector, this.methods)) >= 0) {
        int start = (int) range, end = (int) (range >> 32);
        for (int i = start; i <= end; i++) {
            MethodBinding method = this.methods[i];
            if (resolveTypesFor(method) == null || method.returnType == null) {
                methods();
                return getMethods(selector); // try again since the problem methods have been removed
            }
        }
        int length = end - start + 1;
        System.arraycopy(this.methods, start, result = new MethodBinding[length], 0, length);
    } else {
        return Binding.NO_METHODS;
    }
    boolean isSource15 = this.scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5;
    for (int i = 0, length = result.length - 1; i < length; i++) {
        MethodBinding method = result[i];
        for (int j = length; j > i; j--) {
            boolean paramsMatch = isSource15 ? method.areParameterErasuresEqual(result[j])
                    : method.areParametersEqual(result[j]);
            if (paramsMatch) {
                methods();
                return getMethods(selector); // try again since the duplicate methods have been removed
            }
        }
    }
    return result;
}