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

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

Introduction

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

Prototype

public static boolean equalsEquals(TypeBinding that, TypeBinding other) 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.PrecedenceBinding.java

License:Open Source License

/**
 * Does this precedence declaration regulate the precedence of the given two callins?
 *///from  w  ww .  j  a  v  a2 s  .com
private boolean containsBoth(CallinCalloutBinding callin1, CallinCalloutBinding callin2) {
    int numFound = 0;
    for (int i = 0; i < this.elements.length; i++) {
        Binding element = this.elements[i];
        if (element == null) // failed to resolve
            continue;
        if (element.kind() == BINDING) {
            if (sameOrOverridingBinding((CallinCalloutBinding) element, callin1))
                numFound++;
            if (sameOrOverridingBinding((CallinCalloutBinding) element, callin2))
                numFound++;
        } else {
            ReferenceBinding roleType = (ReferenceBinding) element;
            roleType = roleType.roleModel.getClassPartBinding();
            if (TypeBinding.equalsEquals(roleType, callin1._declaringRoleClass))
                numFound++;
            if (TypeBinding.equalsEquals(roleType, callin2._declaringRoleClass))
                numFound++;
        }

        if (numFound == 2)
            return true;
    }
    return false;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding.java

License:Open Source License

private void initialize(ReferenceBinding roleType, ITeamAnchor teamAnchor) {
    // FIXME(SH): is it OK to strip ParameterizedFields?
    if (teamAnchor instanceof ParameterizedFieldBinding)
        teamAnchor = ((ParameterizedFieldBinding) teamAnchor).original();

    initializeDependentType(teamAnchor, -1); // role type bindings have no explicit value parameters

    // infer argument position.
    ITeamAnchor firstAnchorSegment = teamAnchor.getBestNamePath()[0];
    if (firstAnchorSegment instanceof LocalVariableBinding
            && (((LocalVariableBinding) firstAnchorSegment).tagBits & TagBits.IsArgument) != 0) {
        LocalVariableBinding argumentBinding = (LocalVariableBinding) firstAnchorSegment;
        this._argumentPosition = argumentBinding.resolvedPosition;
        final MethodScope methodScope = argumentBinding.declaringScope.methodScope();
        if (methodScope != null)
            // if scope is a callout, role method may not yet be resolved, defer:
            this._declaringMethod = new IMethodProvider() {
                private MethodBinding binding;

                public MethodBinding getMethod() {
                    if (this.binding == null)
                        this.binding = methodScope.referenceMethodBinding();
                    return this.binding;
                }//from ww w.  j  a  v  a  2s  .c o  m
            };
    }

    // compute the team:
    if (CharOperation.equals(roleType.compoundName, IOTConstants.ORG_OBJECTTEAMS_TEAM_OTCONFINED))
        // the following is needed in order to break the circularity
        // of roles extending the predefined Team.__OT__Confined (see class comment)
        this._staticallyKnownTeam = roleType.enclosingType();
    else if (teamAnchor == NoAnchor)
        this._staticallyKnownTeam = roleType.enclosingType();
    else
        teamAnchor.setStaticallyKnownTeam(this);

    assert (this._staticallyKnownTeam.isTeam());

    // compute role class and role interface (by name manipulation):
    if (RoleSplitter.isClassPartName(roleType.sourceName)) {
        this._staticallyKnownRoleClass = roleType.getRealClass();
        char[] typeName = RoleSplitter.getInterfacePartName(roleType.sourceName);
        this._staticallyKnownRoleType = this._staticallyKnownTeam.getMemberType(typeName);
    } else {
        this._staticallyKnownRoleType = roleType.getRealType();
        char[] className = CharOperation.concat(OT_DELIM_NAME, this._staticallyKnownRoleType.sourceName);
        this._staticallyKnownRoleClass = this._staticallyKnownTeam.getMemberType(className);
        this._staticallyKnownRoleClass = transferTypeArguments(this._staticallyKnownRoleClass);
    }
    this._staticallyKnownRoleType = transferTypeArguments(this._staticallyKnownRoleType);

    this._declaredRoleType = this._staticallyKnownRoleType;
    // keep these consistent with _declaredRoleType:
    this.roleModel = this._declaredRoleType.roleModel;
    this._teamModel = this._declaredRoleType.getTeamModel();

    assert TypeBinding.equalsEquals(this._staticallyKnownTeam.getRealClass(),
            roleType.enclosingType()) : "weakening not using WeakenedTypeBinding"; //$NON-NLS-1$
    // some adjustments after all fields are known:
    if (TypeBinding.notEquals(this._staticallyKnownTeam, roleType.enclosingType()))
        this._staticallyKnownRoleType = this._staticallyKnownTeam.getMemberType(roleType.sourceName);
    if (this._staticallyKnownRoleClass != null)
        this.modifiers = this._staticallyKnownRoleClass.modifiers;
    // after we might have overwritten the modifiers restore some bits in the vein of ParameterizedTypeBinding:
    if (this.arguments != null) {
        this.modifiers |= ExtraCompilerModifiers.AccGenericSignature;
    } else if (this.enclosingType() != null) {
        this.modifiers |= (this.enclosingType().modifiers & ExtraCompilerModifiers.AccGenericSignature);
        this.tagBits |= this.enclosingType().tagBits & (TagBits.HasTypeVariable | TagBits.HasMissingType);
    }

    // record as known role type at teamAnchor and in our own cache
    registerAnchor();
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding.java

License:Open Source License

public static boolean type_eq(ReferenceBinding left, ReferenceBinding right) {
    // null-checks allways first:
    if (left == null) {
        if (right == null)
            return true;
        else/*from ww  w.  j a  va2s.c  o  m*/
            return false;
    }
    if (right == null)
        return false;

    if (TypeBinding.equalsEquals(left.erasure(), right.erasure()))
        return true;

    if (left instanceof RoleTypeBinding) {
        RoleTypeBinding leftRole = (RoleTypeBinding) left;
        if (right instanceof RoleTypeBinding)
            return TypeBinding.equalsEquals(left.getRealType(), ((RoleTypeBinding) right).getRealType());
        if (TypeBinding.equalsEquals(leftRole.getRealType(), right))
            return true;
        if (TypeBinding.equalsEquals(leftRole.getRealClass(), right))
            return true;
    } else if (right instanceof RoleTypeBinding) {
        RoleTypeBinding rightRole = (RoleTypeBinding) right;
        if (TypeBinding.equalsEquals(rightRole.getRealType(), left))
            return true;
        if (TypeBinding.equalsEquals(rightRole.getRealClass(), left))
            return true;
    }
    return false;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding.java

License:Open Source License

/**
 * Stricter comparison: almost as "==", allow different but equivalent type anchors.
 * Similar to isEquivalentTo, but symmetric.
 *
 * @param left/* w w  w.  j a  v  a2  s.  c o m*/
 * @param right
 * @return whether or not left and right are regarded as equal as defined above.
 */
public static boolean eq(TypeBinding left, TypeBinding right) {
    if (TypeBinding.equalsEquals(left, right))
        return true;
    DependentTypeBinding leftDep = null;
    DependentTypeBinding rightDep = null;
    // nesting occurs for WeakenedTypeBinding(RoleTypeBinding), e.g.
    while (left instanceof DependentTypeBinding) {
        leftDep = (DependentTypeBinding) left;
        left = leftDep.type;
    }
    while (right instanceof DependentTypeBinding) {
        rightDep = (DependentTypeBinding) right;
        right = rightDep.type;
    }
    return leftDep != null && rightDep != null && leftDep._teamAnchor.hasSameBestNameAs(rightDep._teamAnchor)
            && CharOperation.equals(left.internalName(), right.internalName());
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding.java

License:Open Source License

/**
 * Answer whether the method has a parameter of a type of a role such that
 * <ul>/*from w w  w.j av a2 s .c o m*/
 *   <li>the role is a role of the type declaring the method, and</li>
 *   <li>the parameter type is used by a simple reference, i.e., not explicitly anchored.</li>
 * </ul>
 * @param method
 * @return the answer
 */
public static boolean hasNonExternalizedRoleParameter(MethodBinding method) {
    ReferenceBinding declaringClass = method.declaringClass;
    TypeBinding[] parameters = method.parameters;
    for (int j = 0; j < parameters.length; j++) {
        TypeBinding leafType = parameters[j].leafComponentType();
        if (isRoleWithoutExplicitAnchor(leafType)
                && TypeBinding.equalsEquals(((ReferenceBinding) leafType).enclosingType(), declaringClass))
            return true;
    }
    return false;
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding.java

License:Open Source License

/**
* Is type `other' a sibling role of current?
*///from   w  w w.j a  v  a  2s  .  co  m
public boolean isSiblingRole(SourceTypeBinding other) {
    return TypeBinding.equalsEquals(enclosingType(), other.enclosingType());
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding.java

License:Open Source License

/**
 * Would 'role' be the same type as 'this' if it had 'anchor'?
 *
 * @param role/*from   w ww.  j  a  va2 s  .  c  o m*/
 * @param anchor
 */
public boolean isSameType(RoleTypeBinding role, ITeamAnchor anchor) {
    return TypeBinding.equalsEquals(role._staticallyKnownRoleType, this._staticallyKnownRoleType)
            && TypeBinding.equalsEquals(role._staticallyKnownTeam, this._staticallyKnownTeam)
            && this._teamAnchor.hasSameBestNameAs(anchor);
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding.java

License:Open Source License

/**
 * MAIN ENTRY FOR TYPE CHECKING.//from  w  w  w. j  ava  2s  .c o m
 *
 * Answer true if the receiver type can be assigned to the argument type (right).
 * Compare team-anchor and role-type.
 * Note, that the type of _teamAnchor and _staticallyKnownTeam may differ.
 * The former is relevant for type-checking. the latter serves mainly for code generation
 * and for determining overriding.
 */
public boolean isCompatibleWith(TypeBinding right, /*@Nullable*/ Scope captureScope) {
    if (TypeBinding.equalsEquals(right, this))
        return true;
    if (!(right instanceof ReferenceBinding))
        return false;
    if (right.isRawType() && this.erasure().isCompatibleWith(right, captureScope))
        return true;

    ReferenceBinding referenceBinding = (ReferenceBinding) right;
    if (referenceBinding.isRoleType()) {
        RoleTypeBinding rightRole = getRoleTypeBinding(referenceBinding);
        ReferenceBinding rightTeam = referenceBinding.enclosingType();

        // compare teams:
        if (!this._teamAnchor.hasSameBestNameAs(rightRole._teamAnchor)) { // different anchors, not both tthis: not compatible!
            return isCompatibleViaLowering(rightRole);
        }

        // compensate weakened signature:
        if (TypeBinding.notEquals(rightRole._staticallyKnownTeam, this._staticallyKnownTeam)) {
            try {
                if (TeamModel.areTypesCompatible(rightTeam, this._staticallyKnownTeam)) {
                    ReferenceBinding leftStrengthened = this._teamAnchor.getMemberTypeOfType(internalName());
                    if (TypeBinding.notEquals(leftStrengthened, this))
                        return leftStrengthened.isCompatibleWith(right, captureScope);
                } else if (TeamModel.areTypesCompatible(this._staticallyKnownTeam, rightTeam)) {
                    rightRole = (RoleTypeBinding) this._teamAnchor
                            .getMemberTypeOfType(rightRole.internalName());

                } else {
                    return false;
                }
            } finally {
                Config.setCastRequired(null); // reset
            }
        }

        // check the role types:
        if (this._staticallyKnownRoleType.isCompatibleWith(rightRole._staticallyKnownRoleType, captureScope))
            return true;
    }
    if (referenceBinding.isInterface() && implementsInterface(referenceBinding, true))
        return true;

    if (this._staticallyKnownRoleClass == null
            && this._staticallyKnownRoleType.isCompatibleWith(referenceBinding, false, captureScope)) {
        checkAmbiguousObjectLower(referenceBinding);
        return true; // this case is wittnessed by: "this=RoleIfc", right="Object"; other examples?
    }

    // do we need the class part instead of the interface part?
    if ((this._staticallyKnownRoleClass != null)
            && this._staticallyKnownRoleClass.isStrictlyCompatibleWith(referenceBinding, captureScope)
            && !TeamModel.isTeamContainingRole(this._staticallyKnownTeam, referenceBinding)) {
        // Cast from a role to its non-role superclass
        // (Interfaces do not reflect this compatibility, thus we need to help here).
        Config.setCastRequired(referenceBinding);
        checkAmbiguousObjectLower(referenceBinding);
        return true;
    }

    // after everything else has failed try lowering:
    return isCompatibleViaLowering(referenceBinding);
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticBaseCallSurrogate.java

License:Open Source License

/** For role types ignore weakening and anchors. */
static boolean areTypesEqual(TypeBinding one, TypeBinding two) {
    if (TypeBinding.equalsEquals(one, two))
        return true;
    ReferenceBinding enclosingOne = one.enclosingType();
    if (enclosingOne == null)
        return false;
    ReferenceBinding enclosingTwo = two.enclosingType();
    if (enclosingTwo == null)
        return false;
    if (!areTypesEqual(enclosingOne, enclosingTwo))
        return false;
    return CharOperation.equals(one.sourceName(), two.sourceName());
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.TeamAnchor.java

License:Open Source License

private boolean isSameVariable(ITeamAnchor one, ITeamAnchor two) {
    if (one == two)
        return true;
    if (one instanceof TThisBinding && two instanceof TThisBinding)
        return true;
    // thanks to 1.4(c) tthis bindings from the same context
    // can never refer to different roles of the same name.

    // check if one is a fake replica of the other:
    if (one instanceof FieldBinding && two instanceof FieldBinding) {
        FieldBinding f1 = (FieldBinding) one;
        FieldBinding f2 = (FieldBinding) two;
        if (!CharOperation.equals(f1.name, f2.name))
            return false;

        return TypeBinding.equalsEquals(FieldModel.getActualDeclaringClass(f1),
                FieldModel.getActualDeclaringClass(f2));
    }/* w  w  w .ja v a 2  s .  c o  m*/
    return false;
}