From 61b56c3484d0b9f282dad4b3da494a65bee987f1 Mon Sep 17 00:00:00 2001 From: acolyer Date: Fri, 22 Jul 2005 15:36:32 +0000 Subject: improved matching in canBeBoundTo to consider equality of all bounds when testing against a type variable reference --- weaver/src/org/aspectj/weaver/TypeVariable.java | 32 +++++++++++++++++++++---- 1 file 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) { -- cgit v1.2.3