< prev index next >

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

Print this page




 334         int annotationCount = buf.getShort() & 0xFFFF;
 335         List<TypeAnnotation> typeAnnotations = new ArrayList<>(annotationCount);
 336 
 337         // Parse each TypeAnnotation
 338         for (int i = 0; i < annotationCount; i++) {
 339              TypeAnnotation ta = parseTypeAnnotation(buf, cp, baseDecl, container);
 340              if (ta != null)
 341                  typeAnnotations.add(ta);
 342         }
 343 
 344         return typeAnnotations.toArray(EMPTY_TYPE_ANNOTATION_ARRAY);
 345     }
 346 
 347 
 348     // Helper
 349     static Map<Class<? extends Annotation>, Annotation> mapTypeAnnotations(TypeAnnotation[] typeAnnos) {
 350         Map<Class<? extends Annotation>, Annotation> result =
 351             new LinkedHashMap<>();
 352         for (TypeAnnotation t : typeAnnos) {
 353             Annotation a = t.getAnnotation();

 354             Class<? extends Annotation> klass = a.annotationType();
 355             AnnotationType type = AnnotationType.getInstance(klass);
 356             if (type.retention() == RetentionPolicy.RUNTIME)
 357                 if (result.put(klass, a) != null)
 358                     throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);


 359         }
 360         return result;
 361     }
 362 
 363     // Position codes
 364     // Regular type parameter annotations
 365     private static final byte CLASS_TYPE_PARAMETER = 0x00;
 366     private static final byte METHOD_TYPE_PARAMETER = 0x01;
 367     // Type Annotations outside method bodies
 368     private static final byte CLASS_EXTENDS = 0x10;
 369     private static final byte CLASS_TYPE_PARAMETER_BOUND = 0x11;
 370     private static final byte METHOD_TYPE_PARAMETER_BOUND = 0x12;
 371     private static final byte FIELD = 0x13;
 372     private static final byte METHOD_RETURN = 0x14;
 373     private static final byte METHOD_RECEIVER = 0x15;
 374     private static final byte METHOD_FORMAL_PARAMETER = 0x16;
 375     private static final byte THROWS = 0x17;
 376     // Type Annotations inside method bodies
 377     private static final byte LOCAL_VARIABLE = (byte)0x40;
 378     private static final byte RESOURCE_VARIABLE = (byte)0x41;




 334         int annotationCount = buf.getShort() & 0xFFFF;
 335         List<TypeAnnotation> typeAnnotations = new ArrayList<>(annotationCount);
 336 
 337         // Parse each TypeAnnotation
 338         for (int i = 0; i < annotationCount; i++) {
 339              TypeAnnotation ta = parseTypeAnnotation(buf, cp, baseDecl, container);
 340              if (ta != null)
 341                  typeAnnotations.add(ta);
 342         }
 343 
 344         return typeAnnotations.toArray(EMPTY_TYPE_ANNOTATION_ARRAY);
 345     }
 346 
 347 
 348     // Helper
 349     static Map<Class<? extends Annotation>, Annotation> mapTypeAnnotations(TypeAnnotation[] typeAnnos) {
 350         Map<Class<? extends Annotation>, Annotation> result =
 351             new LinkedHashMap<>();
 352         for (TypeAnnotation t : typeAnnos) {
 353             Annotation a = t.getAnnotation();
 354             if (a != null) {
 355                 Class<? extends Annotation> klass = a.annotationType();
 356                 AnnotationType type = AnnotationType.getInstance(klass);
 357                 if (type.retention() == RetentionPolicy.RUNTIME &&
 358                     result.put(klass, a) != null) {
 359                     throw new AnnotationFormatError("Duplicate annotation for class: "+klass+": " + a);
 360                 }
 361             }
 362         }
 363         return result;
 364     }
 365 
 366     // Position codes
 367     // Regular type parameter annotations
 368     private static final byte CLASS_TYPE_PARAMETER = 0x00;
 369     private static final byte METHOD_TYPE_PARAMETER = 0x01;
 370     // Type Annotations outside method bodies
 371     private static final byte CLASS_EXTENDS = 0x10;
 372     private static final byte CLASS_TYPE_PARAMETER_BOUND = 0x11;
 373     private static final byte METHOD_TYPE_PARAMETER_BOUND = 0x12;
 374     private static final byte FIELD = 0x13;
 375     private static final byte METHOD_RETURN = 0x14;
 376     private static final byte METHOD_RECEIVER = 0x15;
 377     private static final byte METHOD_FORMAL_PARAMETER = 0x16;
 378     private static final byte THROWS = 0x17;
 379     // Type Annotations inside method bodies
 380     private static final byte LOCAL_VARIABLE = (byte)0x40;
 381     private static final byte RESOURCE_VARIABLE = (byte)0x41;


< prev index next >