提交 a82f5510 编写于 作者: J jfranck

8027796: Refactor Core Reflection for Type Annotations

Reviewed-by: psandoz
上级 fc73eb55
...@@ -34,7 +34,7 @@ import java.util.Map; ...@@ -34,7 +34,7 @@ import java.util.Map;
import static sun.reflect.annotation.TypeAnnotation.*; import static sun.reflect.annotation.TypeAnnotation.*;
public class AnnotatedTypeFactory { public final class AnnotatedTypeFactory {
/** /**
* Create an AnnotatedType. * Create an AnnotatedType.
* *
...@@ -47,10 +47,10 @@ public class AnnotatedTypeFactory { ...@@ -47,10 +47,10 @@ public class AnnotatedTypeFactory {
* corresponds to * corresponds to
*/ */
public static AnnotatedType buildAnnotatedType(Type type, public static AnnotatedType buildAnnotatedType(Type type,
LocationInfo currentLoc, LocationInfo currentLoc,
TypeAnnotation[] actualTypeAnnos, TypeAnnotation[] actualTypeAnnos,
TypeAnnotation[] allOnSameTarget, TypeAnnotation[] allOnSameTarget,
AnnotatedElement decl) { AnnotatedElement decl) {
if (type == null) { if (type == null) {
return EMPTY_ANNOTATED_TYPE; return EMPTY_ANNOTATED_TYPE;
} }
...@@ -156,40 +156,40 @@ public class AnnotatedTypeFactory { ...@@ -156,40 +156,40 @@ public class AnnotatedTypeFactory {
} }
@Override @Override
public Annotation[] getDeclaredAnnotations() { public final Annotation[] getDeclaredAnnotations() {
return annotations.values().toArray(new Annotation[0]); return annotations.values().toArray(new Annotation[0]);
} }
@Override @Override
@SuppressWarnings("unchecked") @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); return (T)annotations.get(annotation);
} }
@Override @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); return AnnotationSupport.getDirectlyAndIndirectlyPresent(annotations, annotation);
} }
// AnnotatedType // AnnotatedType
@Override @Override
public Type getType() { public final Type getType() {
return type; return type;
} }
// Implementation details // Implementation details
LocationInfo getLocation() { final LocationInfo getLocation() {
return location; return location;
} }
TypeAnnotation[] getTypeAnnotations() { final TypeAnnotation[] getTypeAnnotations() {
return allOnSameTargetTypeAnnotations; return allOnSameTargetTypeAnnotations;
} }
AnnotatedElement getDecl() { final AnnotatedElement getDecl() {
return decl; return decl;
} }
} }
private static class AnnotatedArrayTypeImpl extends AnnotatedTypeBaseImpl implements AnnotatedArrayType { private static final class AnnotatedArrayTypeImpl extends AnnotatedTypeBaseImpl implements AnnotatedArrayType {
AnnotatedArrayTypeImpl(Type type, LocationInfo location, AnnotatedArrayTypeImpl(Type type, LocationInfo location,
TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations, TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
AnnotatedElement decl) { AnnotatedElement decl) {
...@@ -215,7 +215,7 @@ public class AnnotatedTypeFactory { ...@@ -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, AnnotatedTypeVariableImpl(TypeVariable<?> type, LocationInfo location,
TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations, TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
AnnotatedElement decl) { AnnotatedElement decl) {
...@@ -232,7 +232,8 @@ public class AnnotatedTypeFactory { ...@@ -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, AnnotatedParameterizedTypeImpl(ParameterizedType type, LocationInfo location,
TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations, TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
AnnotatedElement decl) { AnnotatedElement decl) {
...@@ -265,7 +266,7 @@ public class AnnotatedTypeFactory { ...@@ -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; private final boolean hasUpperBounds;
AnnotatedWildcardTypeImpl(WildcardType type, LocationInfo location, AnnotatedWildcardTypeImpl(WildcardType type, LocationInfo location,
TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations, TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
......
...@@ -40,7 +40,7 @@ import java.util.List; ...@@ -40,7 +40,7 @@ import java.util.List;
* distinguish between '@A Inner.@B Outer' in for example nested types), * distinguish between '@A Inner.@B Outer' in for example nested types),
* target info and the declaration the TypeAnnotaiton was parsed from. * target info and the declaration the TypeAnnotaiton was parsed from.
*/ */
public class TypeAnnotation { public final class TypeAnnotation {
private final TypeAnnotationTargetInfo targetInfo; private final TypeAnnotationTargetInfo targetInfo;
private final LocationInfo loc; private final LocationInfo loc;
private final Annotation annotation; private final Annotation annotation;
...@@ -92,7 +92,8 @@ public class TypeAnnotation { ...@@ -92,7 +92,8 @@ public class TypeAnnotation {
METHOD_FORMAL_PARAMETER, METHOD_FORMAL_PARAMETER,
THROWS; THROWS;
} }
public static class TypeAnnotationTargetInfo {
public static final class TypeAnnotationTargetInfo {
private final TypeAnnotationTarget target; private final TypeAnnotationTarget target;
private final int count; private final int count;
private final int secondaryIndex; private final int secondaryIndex;
...@@ -131,7 +132,7 @@ public class TypeAnnotation { ...@@ -131,7 +132,7 @@ public class TypeAnnotation {
} }
} }
public static class LocationInfo { public static final class LocationInfo {
private final int depth; private final int depth;
private final Location[] locations; private final Location[] locations;
...@@ -204,7 +205,7 @@ public class TypeAnnotation { ...@@ -204,7 +205,7 @@ public class TypeAnnotation {
return true; return true;
} }
public static class Location { public static final class Location {
public final byte tag; public final byte tag;
public final byte index; public final byte index;
......
...@@ -43,7 +43,7 @@ import static sun.reflect.annotation.TypeAnnotation.*; ...@@ -43,7 +43,7 @@ import static sun.reflect.annotation.TypeAnnotation.*;
* TypeAnnotationParser implements the logic needed to parse * TypeAnnotationParser implements the logic needed to parse
* TypeAnnotations from an array of bytes. * TypeAnnotations from an array of bytes.
*/ */
public class TypeAnnotationParser { public final class TypeAnnotationParser {
private static final TypeAnnotation[] EMPTY_TYPE_ANNOTATION_ARRAY = new TypeAnnotation[0]; private static final TypeAnnotation[] EMPTY_TYPE_ANNOTATION_ARRAY = new TypeAnnotation[0];
/** /**
...@@ -237,7 +237,7 @@ public class TypeAnnotationParser { ...@@ -237,7 +237,7 @@ public class TypeAnnotationParser {
return parseAnnotatedBounds(bounds, decl, typeVarIndex, LocationInfo.BASE_LOCATION); return parseAnnotatedBounds(bounds, decl, typeVarIndex, LocationInfo.BASE_LOCATION);
} }
//helper for above //helper for above
static <D extends GenericDeclaration> AnnotatedType[] parseAnnotatedBounds(Type[] bounds, private static <D extends GenericDeclaration> AnnotatedType[] parseAnnotatedBounds(Type[] bounds,
D decl, D decl,
int typeVarIndex, int typeVarIndex,
LocationInfo loc) { LocationInfo loc) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册