mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8256693: getAnnotatedReceiverType parameterizes types too eagerly
Reviewed-by: vromero
This commit is contained in:
parent
1ce2e94f5f
commit
1cc98bde67
4 changed files with 112 additions and 27 deletions
|
@ -699,10 +699,29 @@ public abstract class Executable extends AccessibleObject
|
|||
getConstantPool(getDeclaringClass()),
|
||||
this,
|
||||
getDeclaringClass(),
|
||||
resolveToOwnerType(getDeclaringClass()),
|
||||
parameterize(getDeclaringClass()),
|
||||
TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER);
|
||||
}
|
||||
|
||||
Type parameterize(Class<?> c) {
|
||||
Class<?> ownerClass = c.getDeclaringClass();
|
||||
TypeVariable<?>[] typeVars = c.getTypeParameters();
|
||||
|
||||
if (ownerClass == null) { // base case
|
||||
if (typeVars.length == 0)
|
||||
return c;
|
||||
else
|
||||
return ParameterizedTypeImpl.make(c, typeVars, null);
|
||||
}
|
||||
|
||||
// Resolve owner
|
||||
Type ownerType = parameterize(ownerClass);
|
||||
if (ownerType instanceof Class<?> && typeVars.length == 0) // We have yet to encounter type parameters
|
||||
return c;
|
||||
else
|
||||
return ParameterizedTypeImpl.make(c, typeVars, ownerType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of {@code AnnotatedType} objects that represent the use
|
||||
* of types to specify formal parameter types of the method/constructor
|
||||
|
@ -753,24 +772,4 @@ public abstract class Executable extends AccessibleObject
|
|||
getGenericExceptionTypes(),
|
||||
TypeAnnotation.TypeAnnotationTarget.THROWS);
|
||||
}
|
||||
|
||||
static Type resolveToOwnerType(Class<?> c) {
|
||||
TypeVariable<?>[] v = c.getTypeParameters();
|
||||
Type o = resolveOwner(c);
|
||||
Type t;
|
||||
if (o != null || v.length > 0) {
|
||||
t = ParameterizedTypeImpl.make(c, v, o);
|
||||
} else {
|
||||
t = c;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
private static Type resolveOwner(Class<?> t) {
|
||||
if (Modifier.isStatic(t.getModifiers()) || !(t.isLocalClass() || t.isMemberClass() || t.isAnonymousClass())) {
|
||||
return null;
|
||||
}
|
||||
Class<?> d = t.getDeclaringClass();
|
||||
return ParameterizedTypeImpl.make(d, d.getTypeParameters(), resolveOwner(d));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue