Example usage for org.eclipse.jdt.internal.compiler.ast AbstractMethodDeclaration isDefaultMethod

List of usage examples for org.eclipse.jdt.internal.compiler.ast AbstractMethodDeclaration isDefaultMethod

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast AbstractMethodDeclaration isDefaultMethod.

Prototype

public boolean isDefaultMethod() 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance.java

License:Open Source License

/**
 * This method should ensure, that an interface does not provide the same
 * method as an implicitly inherited method but with a more specific signature
 * Since role interfaces are created by the RoleSplitter, at that time nothing
 * was known about method signatures of tsuper roles.
 * Also check whether all methods of roleType are compatible with implicitly
 * inherited versions from tsuperRole (visibility, exceptions etc.).
 * Perform these checks on the interface parts only, since class versions have
 * their visibilities twisted.//  w w w.  j av  a  2s. c  o  m
 * @param superRoleIfc   lookup methods here, to match ours against.
 * @param subTeam
 * @param subRoleIfcDecl this type declaration is edited.
 */
public static void weakenInterfaceSignatures(ReferenceBinding superRoleIfc, ReferenceBinding subTeam,
        TypeDeclaration subRoleIfcDecl) {
    ReferenceBinding superTeam = superRoleIfc.enclosingType();
    MethodBinding[] superMethods = superRoleIfc.methods();

    checkPrivateMethods(superTeam, superMethods, subTeam, subRoleIfcDecl);

    AbstractMethodDeclaration[] oldMethods = subRoleIfcDecl.methods;
    if (oldMethods == null)
        return;

    MethodVerifier verifier = subRoleIfcDecl.scope.environment().methodVerifier();

    // collect methods that match an implicitly inherited method
    HashSet<AbstractMethodDeclaration> foundMethodDecls = new HashSet<AbstractMethodDeclaration>();
    HashSet<MethodBinding> foundMethodBinds = new HashSet<MethodBinding>();
    for (int i = 0; i < superMethods.length; i++) {
        MethodBinding inheritedMethod = superMethods[i];
        AbstractMethodDeclaration methodFound = findMethod(superTeam, superMethods[i], subTeam, subRoleIfcDecl);
        if ((methodFound != null) && (methodFound.binding != null)) // do not touch broken methods
        {
            // check compatibility before removing:
            if (inheritedMethod.isValidBinding()) {
                verifier.checkAgainstImplicitlyInherited(subRoleIfcDecl.binding, subTeam, methodFound.binding,
                        superTeam, inheritedMethod);
            }
            if ((!methodFound.isGenerated // don't remove generated methods
                    || methodFound.hasErrors()) // unless erroneous
                    && !methodFound.isDefaultMethod()) {
                foundMethodDecls.add(methodFound);
                foundMethodBinds.add(methodFound.binding);
            }
        }
    }
    int declarationLen = oldMethods.length - foundMethodDecls.size();

    // remove matching declarations:
    subRoleIfcDecl.methods = new AbstractMethodDeclaration[declarationLen];
    reduceArray(oldMethods, subRoleIfcDecl.methods, foundMethodDecls);

    //invalid method-bindings has been removed from methods-binding-array in faultInTypes
    int bindingLen = subRoleIfcDecl.binding.methods().length - foundMethodBinds.size();

    // remove matching bindings
    SourceTypeBinding subRoleBind = subRoleIfcDecl.binding;
    subRoleBind.reduceMethods(foundMethodBinds, bindingLen);

    // recurse to interfaces (including tsuper):
    ReferenceBinding[] superInterfaces = superRoleIfc.superInterfaces();
    for (int i = 0; i < superInterfaces.length; i++) {
        ReferenceBinding superIfc = superInterfaces[i];
        if (superIfc.isSynthInterface())
            weakenInterfaceSignatures(superIfc, subTeam, subRoleIfcDecl);
    }
}