src/share/classes/com/sun/tools/javac/model/JavacElements.java

Print this page




 249         } else if (directIndex >= 0) {
 250             arr[0] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
 251             return arr;
 252         } else {
 253             // Only container
 254             insert = 0;
 255         }
 256 
 257         for (int i = 0; i + insert < length; i++)
 258             arr[insert + i] = AnnotationProxyMaker.generateAnnotation(contained[i], annoType);
 259 
 260         return arr;
 261     }
 262 
 263     // Needed to unpack the runtime view of containing annotations
 264     private static final Class<? extends Annotation> REPEATABLE_CLASS = initRepeatable();
 265     private static final Method VALUE_ELEMENT_METHOD = initValueElementMethod();
 266 
 267     private static Class<? extends Annotation> initRepeatable() {
 268         try {
 269             @SuppressWarnings("unchecked") // java.lang.annotation.Repeatable extends Annotation by being an annotation type
 270             Class<? extends Annotation> c = (Class)Class.forName("java.lang.annotation.Repeatable");
 271             return c;

 272         } catch (ClassNotFoundException e) {
 273             return null;
 274         } catch (SecurityException e) {
 275             return null;
 276         }
 277     }
 278     private static Method initValueElementMethod() {
 279         if (REPEATABLE_CLASS == null)
 280             return null;
 281 
 282         Method m = null;
 283         try {
 284             m = REPEATABLE_CLASS.getMethod("value");
 285             if (m != null)
 286                 m.setAccessible(true);
 287             return m;
 288         } catch (NoSuchMethodException e) {
 289             return null;
 290         }
 291     }




 249         } else if (directIndex >= 0) {
 250             arr[0] = AnnotationProxyMaker.generateAnnotation(direct, annoType);
 251             return arr;
 252         } else {
 253             // Only container
 254             insert = 0;
 255         }
 256 
 257         for (int i = 0; i + insert < length; i++)
 258             arr[insert + i] = AnnotationProxyMaker.generateAnnotation(contained[i], annoType);
 259 
 260         return arr;
 261     }
 262 
 263     // Needed to unpack the runtime view of containing annotations
 264     private static final Class<? extends Annotation> REPEATABLE_CLASS = initRepeatable();
 265     private static final Method VALUE_ELEMENT_METHOD = initValueElementMethod();
 266 
 267     private static Class<? extends Annotation> initRepeatable() {
 268         try {
 269             // Repeatable will not be available when bootstrapping on
 270             // JDK 7 so use a reflective lookup instead of a class
 271             // literal for Repeatable.class.
 272             return Class.forName("java.lang.annotation.Repeatable").asSubclass(Annotation.class);
 273         } catch (ClassNotFoundException e) {
 274             return null;
 275         } catch (SecurityException e) {
 276             return null;
 277         }
 278     }
 279     private static Method initValueElementMethod() {
 280         if (REPEATABLE_CLASS == null)
 281             return null;
 282 
 283         Method m = null;
 284         try {
 285             m = REPEATABLE_CLASS.getMethod("value");
 286             if (m != null)
 287                 m.setAccessible(true);
 288             return m;
 289         } catch (NoSuchMethodException e) {
 290             return null;
 291         }
 292     }