Skip to content

Commit 2a1ec08

Browse files
committed
WildTypePattern: match generic type params correctly for array types
For array reference types, match type parameters on component type, not on array type itself. Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
1 parent 397796d commit 2a1ec08

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

org.aspectj.matcher/src/main/java/org/aspectj/weaver/patterns/WildTypePattern.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.io.IOException;
1616
import java.util.ArrayList;
17+
import java.util.Arrays;
1718
import java.util.List;
1819
import java.util.Map;
1920
import java.util.StringTokenizer;
@@ -25,6 +26,7 @@
2526
import org.aspectj.util.FileUtil;
2627
import org.aspectj.util.FuzzyBoolean;
2728
import org.aspectj.weaver.AjAttribute;
29+
import org.aspectj.weaver.ArrayReferenceType;
2830
import org.aspectj.weaver.BCException;
2931
import org.aspectj.weaver.BoundedReferenceType;
3032
import org.aspectj.weaver.CompressingDataOutputStream;
@@ -39,6 +41,7 @@
3941
import org.aspectj.weaver.UnresolvedTypeVariableReferenceType;
4042
import org.aspectj.weaver.VersionedDataInputStream;
4143
import org.aspectj.weaver.WeaverMessages;
44+
import org.aspectj.weaver.WildcardedUnresolvedType;
4245
import org.aspectj.weaver.World;
4346

4447
/**
@@ -233,7 +236,8 @@ protected boolean matchesExactly(ResolvedType type, ResolvedType annotatedType)
233236
// Ensure the annotation pattern is resolved
234237
annotationPattern.resolve(type.getWorld());
235238

236-
return matchesExactlyByName(targetTypeName.replaceFirst("(\\[\\])+$", ""), type.isAnonymous(), type.isNested()) && matchesParameters(type, STATIC)
239+
return matchesExactlyByName(targetTypeName.replaceFirst("(\\[\\])+$", ""), type.isAnonymous(), type.isNested())
240+
&& matchesParameters(type, STATIC)
237241
&& matchesArray(type)
238242
&& matchesBounds(type, STATIC)
239243
&& annotationPattern.matches(annotatedType, type.temporaryAnnotationTypes).alwaysTrue();
@@ -242,6 +246,9 @@ && matchesBounds(type, STATIC)
242246
// we've matched against the base (or raw) type, but if this type pattern specifies parameters or
243247
// type variables we need to make sure we match against them too
244248
private boolean matchesParameters(ResolvedType aType, MatchKind staticOrDynamic) {
249+
// For array reference types, match type parameters on component type, not on array type itself
250+
if (aType instanceof ArrayReferenceType)
251+
aType = aType.getResolvedComponentType();
245252
if (!isGeneric && typeParameters.size() > 0) {
246253
if (!aType.isParameterizedType()) {
247254
return false;

0 commit comments

Comments
 (0)