8027796: Refactor Core Reflection for Type Annotations

Reviewed-by: psandoz
This commit is contained in:
Joel Borggrén-Franck 2013-11-07 13:33:03 +01:00
parent bffc06393b
commit 7950bec46c
3 changed files with 24 additions and 22 deletions

View File

@ -34,7 +34,7 @@ import java.util.Map;
import static sun.reflect.annotation.TypeAnnotation.*;
public class AnnotatedTypeFactory {
public final class AnnotatedTypeFactory {
/**
* Create an AnnotatedType.
*
@ -156,40 +156,40 @@ public class AnnotatedTypeFactory {
}
@Override
public Annotation[] getDeclaredAnnotations() {
public final Annotation[] getDeclaredAnnotations() {
return annotations.values().toArray(new Annotation[0]);
}
@Override
@SuppressWarnings("unchecked")
public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotation) {
public final <T extends Annotation> T getDeclaredAnnotation(Class<T> annotation) {
return (T)annotations.get(annotation);
}
@Override
public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotation) {
public final <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotation) {
return AnnotationSupport.getDirectlyAndIndirectlyPresent(annotations, annotation);
}
// AnnotatedType
@Override
public Type getType() {
public final Type getType() {
return type;
}
// Implementation details
LocationInfo getLocation() {
final LocationInfo getLocation() {
return location;
}
TypeAnnotation[] getTypeAnnotations() {
final TypeAnnotation[] getTypeAnnotations() {
return allOnSameTargetTypeAnnotations;
}
AnnotatedElement getDecl() {
final AnnotatedElement getDecl() {
return decl;
}
}
private static class AnnotatedArrayTypeImpl extends AnnotatedTypeBaseImpl implements AnnotatedArrayType {
private static final class AnnotatedArrayTypeImpl extends AnnotatedTypeBaseImpl implements AnnotatedArrayType {
AnnotatedArrayTypeImpl(Type type, LocationInfo location,
TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
AnnotatedElement decl) {
@ -215,7 +215,7 @@ public class AnnotatedTypeFactory {
}
}
private static class AnnotatedTypeVariableImpl extends AnnotatedTypeBaseImpl implements AnnotatedTypeVariable {
private static final class AnnotatedTypeVariableImpl extends AnnotatedTypeBaseImpl implements AnnotatedTypeVariable {
AnnotatedTypeVariableImpl(TypeVariable<?> type, LocationInfo location,
TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
AnnotatedElement decl) {
@ -232,7 +232,8 @@ public class AnnotatedTypeFactory {
}
}
private static class AnnotatedParameterizedTypeImpl extends AnnotatedTypeBaseImpl implements AnnotatedParameterizedType {
private static final class AnnotatedParameterizedTypeImpl extends AnnotatedTypeBaseImpl
implements AnnotatedParameterizedType {
AnnotatedParameterizedTypeImpl(ParameterizedType type, LocationInfo location,
TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
AnnotatedElement decl) {
@ -265,7 +266,7 @@ public class AnnotatedTypeFactory {
}
}
private static class AnnotatedWildcardTypeImpl extends AnnotatedTypeBaseImpl implements AnnotatedWildcardType {
private static final class AnnotatedWildcardTypeImpl extends AnnotatedTypeBaseImpl implements AnnotatedWildcardType {
private final boolean hasUpperBounds;
AnnotatedWildcardTypeImpl(WildcardType type, LocationInfo location,
TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,

View File

@ -40,7 +40,7 @@ import java.util.List;
* distinguish between '@A Inner.@B Outer' in for example nested types),
* target info and the declaration the TypeAnnotaiton was parsed from.
*/
public class TypeAnnotation {
public final class TypeAnnotation {
private final TypeAnnotationTargetInfo targetInfo;
private final LocationInfo loc;
private final Annotation annotation;
@ -92,7 +92,8 @@ public class TypeAnnotation {
METHOD_FORMAL_PARAMETER,
THROWS;
}
public static class TypeAnnotationTargetInfo {
public static final class TypeAnnotationTargetInfo {
private final TypeAnnotationTarget target;
private final int count;
private final int secondaryIndex;
@ -131,7 +132,7 @@ public class TypeAnnotation {
}
}
public static class LocationInfo {
public static final class LocationInfo {
private final int depth;
private final Location[] locations;
@ -204,7 +205,7 @@ public class TypeAnnotation {
return true;
}
public static class Location {
public static final class Location {
public final byte tag;
public final byte index;

View File

@ -43,7 +43,7 @@ import static sun.reflect.annotation.TypeAnnotation.*;
* TypeAnnotationParser implements the logic needed to parse
* TypeAnnotations from an array of bytes.
*/
public class TypeAnnotationParser {
public final class TypeAnnotationParser {
private static final TypeAnnotation[] EMPTY_TYPE_ANNOTATION_ARRAY = new TypeAnnotation[0];
/**
@ -237,7 +237,7 @@ public class TypeAnnotationParser {
return parseAnnotatedBounds(bounds, decl, typeVarIndex, LocationInfo.BASE_LOCATION);
}
//helper for above
static <D extends GenericDeclaration> AnnotatedType[] parseAnnotatedBounds(Type[] bounds,
private static <D extends GenericDeclaration> AnnotatedType[] parseAnnotatedBounds(Type[] bounds,
D decl,
int typeVarIndex,
LocationInfo loc) {