diff options
author | acolyer <acolyer> | 2005-07-22 15:36:32 +0000 |
---|---|---|
committer | acolyer <acolyer> | 2005-07-22 15:36:32 +0000 |
commit | 61b56c3484d0b9f282dad4b3da494a65bee987f1 (patch) | |
tree | bc04c162b0af1a227f5c777309d0251c7dfb4c8e | |
parent | dfba82dc0af71d904aad95c371736183e6877896 (diff) | |
download | aspectj-61b56c3484d0b9f282dad4b3da494a65bee987f1.tar.gz aspectj-61b56c3484d0b9f282dad4b3da494a65bee987f1.zip |
improved matching in canBeBoundTo to consider equality of all bounds when testing against a type variable reference
-rw-r--r-- | weaver/src/org/aspectj/weaver/TypeVariable.java | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/weaver/src/org/aspectj/weaver/TypeVariable.java b/weaver/src/org/aspectj/weaver/TypeVariable.java index b4b4d0261..9f04f55f9 100644 --- a/weaver/src/org/aspectj/weaver/TypeVariable.java +++ b/weaver/src/org/aspectj/weaver/TypeVariable.java @@ -11,6 +11,9 @@ * ******************************************************************/ package org.aspectj.weaver; +import java.util.HashSet; +import java.util.Set; + /** * Represents a type variable with bounds */ @@ -130,10 +133,31 @@ public class TypeVariable { // can match any type in the range of the type variable... // XXX what about interfaces? private boolean matchingBounds(TypeVariableReferenceType tvrt) { - boolean upperMatch = canBeBoundTo(tvrt.getUpperBound()); - boolean lowerMatch = true; - if (tvrt.hasLowerBound()) lowerMatch = canBeBoundTo(tvrt.getLowerBound()); - return upperMatch && lowerMatch; + if (tvrt.getUpperBound() != upperBound) return false; + if (tvrt.hasLowerBound() != (lowerBound != null)) return false; + if (tvrt.hasLowerBound() && tvrt.lowerBound != lowerBound) return false; + // either we both have bounds, or neither of us have bounds + if ((tvrt.additionalInterfaceBounds != null) != (additionalInterfaceBounds != null)) return false; + if (additionalInterfaceBounds != null) { + // we both have bounds, compare + if (tvrt.additionalInterfaceBounds.length != additionalInterfaceBounds.length) return false; + Set aAndNotB = new HashSet(); + Set bAndNotA = new HashSet(); + for (int i = 0; i < additionalInterfaceBounds.length; i++) { + aAndNotB.add(additionalInterfaceBounds[i]); + } + for (int i = 0; i < tvrt.additionalInterfaceBounds.length; i++) { + bAndNotA.add(tvrt.additionalInterfaceBounds[i]); + } + for (int i = 0; i < additionalInterfaceBounds.length; i++) { + bAndNotA.remove(additionalInterfaceBounds[i]); + } + for (int i = 0; i < tvrt.additionalInterfaceBounds.length; i++) { + aAndNotB.remove(tvrt.additionalInterfaceBounds[i]); + } + if (! (aAndNotB.isEmpty() && bAndNotA.isEmpty()) ) return false; + } + return true; } private boolean isASubtypeOf(UnresolvedType candidateSuperType, UnresolvedType candidateSubType) { |