@@ -102,7 +102,7 @@ public AnnotatedType[] getAnnotatedActualTypeArguments() {
102
102
private TypeResolution resolveVariable (TypeResolution typeVariableResolution ) {
103
103
TypeResolution localResolution = resolveVariableLocally (typeVariableResolution );
104
104
if (localResolution .isVariable ()) {
105
- TypeResolution supertypeResolution = resolveVariableInSupertypes (localResolution );
105
+ TypeResolution supertypeResolution = resolveVariableInSupertypesOf (localResolution , contextType );
106
106
if (supertypeResolution .typeHasChanged ()) {
107
107
return resolveType (supertypeResolution );
108
108
}
@@ -119,29 +119,25 @@ private TypeResolution resolveVariableLocally(TypeResolution typeResolution) {
119
119
return resolutions .getOrDefault (variable , typeResolution .unchanged ());
120
120
}
121
121
122
- private TypeResolution resolveVariableInSupertypes (TypeResolution typeResolution ) {
123
- // TODO: Optimize so that only get supertypes of supertypes if necessary
124
- // i.e. it cannot be resolved in direct supertypes
125
- Set <TypeUsage > superTypes = getAllSupertypes (contextType );
126
- List <TypeResolution > typeResolutionList =
127
- superTypes .stream ()
128
- .map (GenericsSupport ::contextFor )
129
- .map (context -> context .resolveVariableLocally (typeResolution ))
130
- .filter (TypeResolution ::typeHasChanged )
131
- .collect (Collectors .toList ());
132
-
133
- return typeResolutionList .stream ()
134
- .findFirst ()
135
- .orElse (typeResolution .unchanged ());
122
+ private static TypeResolution resolveVariableInSupertypesOf (TypeResolution variableResolution , TypeUsage type ) {
123
+ return resolveVariableInTypes (variableResolution , type .getSuperTypes ());
136
124
}
137
125
138
- private Set <TypeUsage > getAllSupertypes (TypeUsage contextType ) {
139
- List <TypeUsage > directSupertypes = contextType .getSuperTypes ();
140
- Set <TypeUsage > allSupertypes = new LinkedHashSet <>(directSupertypes );
141
- for (TypeUsage directSupertype : directSupertypes ) {
142
- allSupertypes .addAll (getAllSupertypes (directSupertype ));
126
+ private static TypeResolution resolveVariableInTypes (TypeResolution variableResolution , Collection <TypeUsage > superTypes ) {
127
+ for (TypeUsage superType : superTypes ) {
128
+ GenericsClassContext context = GenericsSupport .contextFor (superType );
129
+ TypeResolution resolved = context .resolveVariableLocally (variableResolution );
130
+ if (resolved .typeHasChanged ()) {
131
+ return resolved ;
132
+ }
133
+ }
134
+ for (TypeUsage superType : superTypes ) {
135
+ TypeResolution typeResolution = resolveVariableInSupertypesOf (variableResolution , superType );
136
+ if (typeResolution .typeHasChanged ()) {
137
+ return typeResolution ;
138
+ }
143
139
}
144
- return allSupertypes ;
140
+ return variableResolution . unchanged () ;
145
141
}
146
142
147
143
private static class LookupTypeVariable {
@@ -243,6 +239,7 @@ public Annotation[] getDeclaredAnnotations() {
243
239
244
240
// For compatibility with JDK >= 9. A breaking change in the JDK :-(
245
241
// @Override
242
+ @ SuppressWarnings ("Since15" )
246
243
public AnnotatedType getAnnotatedOwnerType () {
247
244
// TODO: Return annotatedType.getAnnotatedOwnerType() as soon as Java >= 9 is being used
248
245
return null ;
0 commit comments