Example usage for org.eclipse.jdt.internal.compiler.lookup TagBits KnowsDefaultAbstractMethods

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

Introduction

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

Prototype

long KnowsDefaultAbstractMethods

To view the source code for org.eclipse.jdt.internal.compiler.lookup TagBits KnowsDefaultAbstractMethods.

Click Source Link

Usage

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

License:Open Source License

private void addDefaultAbstractMethods() {
    if ((this.tagBits & TagBits.KnowsDefaultAbstractMethods) != 0)
        return;/*from w  w w. j  a  v  a 2 s .  c om*/

    this.tagBits |= TagBits.KnowsDefaultAbstractMethods;
    if (isClass() && isAbstract()) {
        if (this.scope.compilerOptions().targetJDK >= ClassFileConstants.JDK1_2)
            return; // no longer added for post 1.2 targets

        ReferenceBinding[] itsInterfaces = superInterfaces();
        if (itsInterfaces != Binding.NO_SUPERINTERFACES) {
            MethodBinding[] defaultAbstracts = null;
            int defaultAbstractsCount = 0;
            ReferenceBinding[] interfacesToVisit = itsInterfaces;
            int nextPosition = interfacesToVisit.length;
            for (int i = 0; i < nextPosition; i++) {
                ReferenceBinding superType = interfacesToVisit[i];
                if (superType.isValidBinding()) {
                    MethodBinding[] superMethods = superType.methods();
                    nextAbstractMethod: for (int m = superMethods.length; --m >= 0;) {
                        MethodBinding method = superMethods[m];
                        // explicitly implemented ?
                        if (implementsMethod(method))
                            continue nextAbstractMethod;
                        if (defaultAbstractsCount == 0) {
                            defaultAbstracts = new MethodBinding[5];
                        } else {
                            // already added as default abstract ?
                            for (int k = 0; k < defaultAbstractsCount; k++) {
                                MethodBinding alreadyAdded = defaultAbstracts[k];
                                if (CharOperation.equals(alreadyAdded.selector, method.selector)
                                        && alreadyAdded.areParametersEqual(method))
                                    continue nextAbstractMethod;
                            }
                        }
                        MethodBinding defaultAbstract = new MethodBinding(
                                method.modifiers | ExtraCompilerModifiers.AccDefaultAbstract
                                        | ClassFileConstants.AccSynthetic,
                                method.selector, method.returnType, method.parameters, method.thrownExceptions,
                                this);
                        if (defaultAbstractsCount == defaultAbstracts.length)
                            System.arraycopy(defaultAbstracts, 0,
                                    defaultAbstracts = new MethodBinding[2 * defaultAbstractsCount], 0,
                                    defaultAbstractsCount);
                        defaultAbstracts[defaultAbstractsCount++] = defaultAbstract;
                    }

                    if ((itsInterfaces = superType.superInterfaces()) != 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;
                        }
                    }
                }
            }
            if (defaultAbstractsCount > 0) {
                int length = this.methods.length;
                System.arraycopy(this.methods, 0,
                        this.methods = new MethodBinding[length + defaultAbstractsCount], 0, length);
                System.arraycopy(defaultAbstracts, 0, this.methods, length, defaultAbstractsCount);
                // re-sort methods
                length = length + defaultAbstractsCount;
                if (length > 1)
                    ReferenceBinding.sortMethods(this.methods, 0, length);
                // this.tagBits |= TagBits.AreMethodsSorted; -- already set in #methods()
            }
        }
    }
}