mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8198526: getAnnotatedOwnerType does not handle static nested classes correctly
Reviewed-by: jfranck, vromero
This commit is contained in:
parent
996968d480
commit
7a046a24ea
4 changed files with 182 additions and 18 deletions
|
@ -100,12 +100,15 @@ public final class AnnotatedTypeFactory {
|
|||
if (clz.getEnclosingClass() == null)
|
||||
return addTo;
|
||||
if (Modifier.isStatic(clz.getModifiers()))
|
||||
return nestingForType(clz.getEnclosingClass(), addTo);
|
||||
return addTo;
|
||||
return nestingForType(clz.getEnclosingClass(), addTo.pushInner());
|
||||
} else if (type instanceof ParameterizedType) {
|
||||
ParameterizedType t = (ParameterizedType)type;
|
||||
if (t.getOwnerType() == null)
|
||||
return addTo;
|
||||
if (t.getRawType() instanceof Class
|
||||
&& Modifier.isStatic(((Class) t.getRawType()).getModifiers()))
|
||||
return addTo;
|
||||
return nestingForType(t.getOwnerType(), addTo.pushInner());
|
||||
}
|
||||
return addTo;
|
||||
|
@ -193,14 +196,18 @@ public final class AnnotatedTypeFactory {
|
|||
if (!(type instanceof Class<?>))
|
||||
throw new IllegalStateException("Can't compute owner");
|
||||
|
||||
Class<?> inner = (Class<?>)type;
|
||||
Class<?> owner = inner.getDeclaringClass();
|
||||
Class<?> nested = (Class<?>)type;
|
||||
Class<?> owner = nested.getDeclaringClass();
|
||||
if (owner == null) // top-level, local or anonymous
|
||||
return null;
|
||||
if (inner.isPrimitive() || inner == Void.TYPE)
|
||||
if (nested.isPrimitive() || nested == Void.TYPE)
|
||||
return null;
|
||||
|
||||
LocationInfo outerLoc = nestingForType(owner, getLocation().popAllLocations((byte)1));
|
||||
LocationInfo outerLoc = getLocation().popLocation((byte)1);
|
||||
if (outerLoc == null) {
|
||||
return buildAnnotatedType(owner, LocationInfo.BASE_LOCATION,
|
||||
EMPTY_TYPE_ANNOTATION_ARRAY, EMPTY_TYPE_ANNOTATION_ARRAY, getDecl());
|
||||
}
|
||||
TypeAnnotation[]all = getTypeAnnotations();
|
||||
List<TypeAnnotation> l = new ArrayList<>(all.length);
|
||||
|
||||
|
@ -445,7 +452,12 @@ public final class AnnotatedTypeFactory {
|
|||
Type owner = getParameterizedType().getOwnerType();
|
||||
if (owner == null)
|
||||
return null;
|
||||
LocationInfo outerLoc = nestingForType(owner, getLocation().popAllLocations((byte)1));
|
||||
|
||||
LocationInfo outerLoc = getLocation().popLocation((byte)1);
|
||||
if (outerLoc == null) {
|
||||
return buildAnnotatedType(owner, LocationInfo.BASE_LOCATION,
|
||||
EMPTY_TYPE_ANNOTATION_ARRAY, EMPTY_TYPE_ANNOTATION_ARRAY, getDecl());
|
||||
}
|
||||
TypeAnnotation[]all = getTypeAnnotations();
|
||||
List<TypeAnnotation> l = new ArrayList<>(all.length);
|
||||
|
||||
|
|
|
@ -187,19 +187,17 @@ public final class TypeAnnotation {
|
|||
return new LocationInfo(newDepth, res);
|
||||
}
|
||||
|
||||
/** Pop a series of locations matching {@code tag}. Stop poping as soon as a non-matching tag is found. */
|
||||
public LocationInfo popAllLocations(byte tag) {
|
||||
LocationInfo l = this;
|
||||
int newDepth = l.depth;
|
||||
while(newDepth > 0 && l.locations[newDepth - 1].tag == tag) {
|
||||
newDepth--;
|
||||
/**
|
||||
* Pops a location matching {@code tag}, or returns {@code null}
|
||||
* if no matching location was found.
|
||||
*/
|
||||
public LocationInfo popLocation(byte tag) {
|
||||
if (depth == 0 || locations[depth - 1].tag != tag) {
|
||||
return null;
|
||||
}
|
||||
if (newDepth != l.depth) {
|
||||
Location[] res = new Location[newDepth];
|
||||
System.arraycopy(this.locations, 0, res, 0, newDepth);
|
||||
return new LocationInfo(newDepth, res);
|
||||
} else
|
||||
return l;
|
||||
Location[] res = new Location[depth - 1];
|
||||
System.arraycopy(locations, 0, res, 0, depth - 1);
|
||||
return new LocationInfo(depth - 1, res);
|
||||
}
|
||||
|
||||
public TypeAnnotation[] filter(TypeAnnotation[] ta) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue