Skip to content

Commit

Permalink
WildTypePattern: match generic type params correctly for array types
Browse files Browse the repository at this point in the history
For array reference types, match type parameters on component type, not
on array type itself.

Signed-off-by: Alexander Kriegisch <Alexander@Kriegisch.name>
  • Loading branch information
kriegaex committed Apr 12, 2024
1 parent 397796d commit 2a1ec08
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
Expand All @@ -25,6 +26,7 @@
import org.aspectj.util.FileUtil;
import org.aspectj.util.FuzzyBoolean;
import org.aspectj.weaver.AjAttribute;
import org.aspectj.weaver.ArrayReferenceType;
import org.aspectj.weaver.BCException;
import org.aspectj.weaver.BoundedReferenceType;
import org.aspectj.weaver.CompressingDataOutputStream;
Expand All @@ -39,6 +41,7 @@
import org.aspectj.weaver.UnresolvedTypeVariableReferenceType;
import org.aspectj.weaver.VersionedDataInputStream;
import org.aspectj.weaver.WeaverMessages;
import org.aspectj.weaver.WildcardedUnresolvedType;
import org.aspectj.weaver.World;

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

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

0 comments on commit 2a1ec08

Please sign in to comment.