< prev index next >

src/java.base/share/classes/sun/reflect/annotation/AnnotatedTypeFactory.java

Print this page




 185 
 186             Class<?> inner = (Class<?>)type;
 187             Class<?> owner = inner.getDeclaringClass();
 188             if (owner == null) // top-level, local or anonymous
 189                 return null;
 190             if (inner.isPrimitive() || inner == Void.TYPE)
 191                 return null;
 192 
 193             LocationInfo outerLoc = nestingForType(owner, getLocation().popAllLocations((byte)1));
 194             TypeAnnotation[]all = getTypeAnnotations();
 195             List<TypeAnnotation> l = new ArrayList<>(all.length);
 196 
 197             for (TypeAnnotation t : all)
 198                 if (t.getLocationInfo().isSameLocationInfo(outerLoc))
 199                     l.add(t);
 200 
 201             return buildAnnotatedType(owner, outerLoc, l.toArray(EMPTY_TYPE_ANNOTATION_ARRAY), all, getDecl());
 202 
 203         }
 204 








 205         // Implementation details
 206         final LocationInfo getLocation() {
 207             return location;
 208         }
 209         final TypeAnnotation[] getTypeAnnotations() {
 210             return allOnSameTargetTypeAnnotations;
 211         }
 212         final AnnotatedElement getDecl() {
 213             return decl;
 214         }
 215     }
 216 
 217     private static final class AnnotatedArrayTypeImpl extends AnnotatedTypeBaseImpl implements AnnotatedArrayType {
 218         AnnotatedArrayTypeImpl(Type type, LocationInfo location,
 219                 TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
 220                 AnnotatedElement decl) {
 221             super(type, location, actualTypeAnnotations, allOnSameTargetTypeAnnotations, decl);
 222         }
 223 
 224         @Override


 227             return AnnotatedTypeFactory.buildAnnotatedType(t,
 228                     nestingForType(t, getLocation().pushArray()),
 229                     getTypeAnnotations(),
 230                     getTypeAnnotations(),
 231                     getDecl());
 232         }
 233 
 234         @Override
 235         public AnnotatedType getAnnotatedOwnerType() {
 236             return null;
 237         }
 238 
 239         private Type getComponentType() {
 240             Type t = getType();
 241             if (t instanceof Class) {
 242                 Class<?> c = (Class)t;
 243                 return c.getComponentType();
 244             }
 245             return ((GenericArrayType)t).getGenericComponentType();
 246         }







 247     }
 248 
 249     private static final class AnnotatedTypeVariableImpl extends AnnotatedTypeBaseImpl implements AnnotatedTypeVariable {
 250         AnnotatedTypeVariableImpl(TypeVariable<?> type, LocationInfo location,
 251                 TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
 252                 AnnotatedElement decl) {
 253             super(type, location, actualTypeAnnotations, allOnSameTargetTypeAnnotations, decl);
 254         }
 255 
 256         @Override
 257         public AnnotatedType[] getAnnotatedBounds() {
 258             return getTypeVariable().getAnnotatedBounds();
 259         }
 260 
 261         @Override
 262         public AnnotatedType getAnnotatedOwnerType() {
 263             return null;
 264         }
 265 
 266         private TypeVariable<?> getTypeVariable() {
 267             return (TypeVariable)getType();







 268         }
 269     }
 270 
 271     private static final class AnnotatedParameterizedTypeImpl extends AnnotatedTypeBaseImpl
 272             implements AnnotatedParameterizedType {
 273         AnnotatedParameterizedTypeImpl(ParameterizedType type, LocationInfo location,
 274                 TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
 275                 AnnotatedElement decl) {
 276             super(type, location, actualTypeAnnotations, allOnSameTargetTypeAnnotations, decl);
 277         }
 278 
 279         @Override
 280         public AnnotatedType[] getAnnotatedActualTypeArguments() {
 281             Type[] arguments = getParameterizedType().getActualTypeArguments();
 282             AnnotatedType[] res = new AnnotatedType[arguments.length];
 283             Arrays.fill(res, EMPTY_ANNOTATED_TYPE);
 284             int initialCapacity = getTypeAnnotations().length;
 285             for (int i = 0; i < res.length; i++) {
 286                 List<TypeAnnotation> l = new ArrayList<>(initialCapacity);
 287                 LocationInfo newLoc = nestingForType(arguments[i], getLocation().pushTypeArg((byte)i));




 185 
 186             Class<?> inner = (Class<?>)type;
 187             Class<?> owner = inner.getDeclaringClass();
 188             if (owner == null) // top-level, local or anonymous
 189                 return null;
 190             if (inner.isPrimitive() || inner == Void.TYPE)
 191                 return null;
 192 
 193             LocationInfo outerLoc = nestingForType(owner, getLocation().popAllLocations((byte)1));
 194             TypeAnnotation[]all = getTypeAnnotations();
 195             List<TypeAnnotation> l = new ArrayList<>(all.length);
 196 
 197             for (TypeAnnotation t : all)
 198                 if (t.getLocationInfo().isSameLocationInfo(outerLoc))
 199                     l.add(t);
 200 
 201             return buildAnnotatedType(owner, outerLoc, l.toArray(EMPTY_TYPE_ANNOTATION_ARRAY), all, getDecl());
 202 
 203         }
 204 
 205         String inlineAnnotationsAsString() {
 206             StringJoiner sj = new StringJoiner(" " );
 207             for (Annotation annotation : getDeclaredAnnotations() ) {
 208                 sj.add(annotation.toString());
 209             }
 210             return sj.toString();
 211         }
 212 
 213         // Implementation details
 214         final LocationInfo getLocation() {
 215             return location;
 216         }
 217         final TypeAnnotation[] getTypeAnnotations() {
 218             return allOnSameTargetTypeAnnotations;
 219         }
 220         final AnnotatedElement getDecl() {
 221             return decl;
 222         }
 223     }
 224 
 225     private static final class AnnotatedArrayTypeImpl extends AnnotatedTypeBaseImpl implements AnnotatedArrayType {
 226         AnnotatedArrayTypeImpl(Type type, LocationInfo location,
 227                 TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
 228                 AnnotatedElement decl) {
 229             super(type, location, actualTypeAnnotations, allOnSameTargetTypeAnnotations, decl);
 230         }
 231 
 232         @Override


 235             return AnnotatedTypeFactory.buildAnnotatedType(t,
 236                     nestingForType(t, getLocation().pushArray()),
 237                     getTypeAnnotations(),
 238                     getTypeAnnotations(),
 239                     getDecl());
 240         }
 241 
 242         @Override
 243         public AnnotatedType getAnnotatedOwnerType() {
 244             return null;
 245         }
 246 
 247         private Type getComponentType() {
 248             Type t = getType();
 249             if (t instanceof Class) {
 250                 Class<?> c = (Class)t;
 251                 return c.getComponentType();
 252             }
 253             return ((GenericArrayType)t).getGenericComponentType();
 254         }
 255 
 256         @Override
 257         public String toString() {
 258             // do the annotations go the right way round?
 259             AnnotatedType at = getAnnotatedGenericComponentType();
 260             return  inlineAnnotationsAsString + at.toString() + "[]"
 261         }
 262     }
 263 
 264     private static final class AnnotatedTypeVariableImpl extends AnnotatedTypeBaseImpl implements AnnotatedTypeVariable {
 265         AnnotatedTypeVariableImpl(TypeVariable<?> type, LocationInfo location,
 266                 TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
 267                 AnnotatedElement decl) {
 268             super(type, location, actualTypeAnnotations, allOnSameTargetTypeAnnotations, decl);
 269         }
 270 
 271         @Override
 272         public AnnotatedType[] getAnnotatedBounds() {
 273             return getTypeVariable().getAnnotatedBounds();
 274         }
 275 
 276         @Override
 277         public AnnotatedType getAnnotatedOwnerType() {
 278             return null;
 279         }
 280 
 281         private TypeVariable<?> getTypeVariable() {
 282             return (TypeVariable)getType();
 283         }
 284 
 285         @Override
 286         public String toString() {
 287             // do the annotations go the right way round?
 288             AnnotatedType at = getAnnotatedGenericComponentType();
 289             return  inlineAnnotationsAsString + getType().getTypeName();
 290         }
 291     }
 292 
 293     private static final class AnnotatedParameterizedTypeImpl extends AnnotatedTypeBaseImpl
 294             implements AnnotatedParameterizedType {
 295         AnnotatedParameterizedTypeImpl(ParameterizedType type, LocationInfo location,
 296                 TypeAnnotation[] actualTypeAnnotations, TypeAnnotation[] allOnSameTargetTypeAnnotations,
 297                 AnnotatedElement decl) {
 298             super(type, location, actualTypeAnnotations, allOnSameTargetTypeAnnotations, decl);
 299         }
 300 
 301         @Override
 302         public AnnotatedType[] getAnnotatedActualTypeArguments() {
 303             Type[] arguments = getParameterizedType().getActualTypeArguments();
 304             AnnotatedType[] res = new AnnotatedType[arguments.length];
 305             Arrays.fill(res, EMPTY_ANNOTATED_TYPE);
 306             int initialCapacity = getTypeAnnotations().length;
 307             for (int i = 0; i < res.length; i++) {
 308                 List<TypeAnnotation> l = new ArrayList<>(initialCapacity);
 309                 LocationInfo newLoc = nestingForType(arguments[i], getLocation().pushTypeArg((byte)i));


< prev index next >