< prev index next >

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

Print this page




  56 
  57     /**
  58      * Member name -> Method object mapping. This (and its associated
  59      * accessor) are used only to generate AnnotationTypeMismatchExceptions.
  60      */
  61     private final Map<String, Method> members;
  62 
  63     /**
  64      * The retention policy for this annotation type.
  65      */
  66     private final RetentionPolicy retention;
  67 
  68     /**
  69      * Whether this annotation type is inherited.
  70      */
  71     private final boolean inherited;
  72 
  73     /**
  74      * Returns an AnnotationType instance for the specified annotation type.
  75      *
  76      * @throw IllegalArgumentException if the specified class object for
  77      *     does not represent a valid annotation type
  78      */
  79     public static AnnotationType getInstance(
  80         Class<? extends Annotation> annotationClass)
  81     {
  82         JavaLangAccess jla = sun.misc.SharedSecrets.getJavaLangAccess();
  83         AnnotationType result = jla.getAnnotationType(annotationClass); // volatile read
  84         if (result == null) {
  85             result = new AnnotationType(annotationClass);
  86             // try to CAS the AnnotationType: null -> result
  87             if (!jla.casAnnotationType(annotationClass, null, result)) {
  88                 // somebody was quicker -> read it's result
  89                 result = jla.getAnnotationType(annotationClass);
  90                 assert result != null;
  91             }
  92         }
  93 
  94         return result;
  95     }
  96 


 166             return Character.class;
 167         if (type == double.class)
 168             return Double.class;
 169         if (type == float.class)
 170             return Float.class;
 171         if (type == int.class)
 172             return Integer.class;
 173         if (type == long.class)
 174             return Long.class;
 175         if (type == short.class)
 176             return Short.class;
 177         if (type == boolean.class)
 178             return Boolean.class;
 179 
 180         // Otherwise, just return declared type
 181         return type;
 182     }
 183 
 184     /**
 185      * Returns member types for this annotation type
 186      * (member name -> type mapping).
 187      */
 188     public Map<String, Class<?>> memberTypes() {
 189         return memberTypes;
 190     }
 191 
 192     /**
 193      * Returns members of this annotation type
 194      * (member name -> associated Method object mapping).
 195      */
 196     public Map<String, Method> members() {
 197         return members;
 198     }
 199 
 200     /**
 201      * Returns the default values for this annotation type
 202      * (Member name -> default value mapping).
 203      */
 204     public Map<String, Object> memberDefaults() {
 205         return memberDefaults;
 206     }
 207 
 208     /**
 209      * Returns the retention policy for this annotation type.
 210      */
 211     public RetentionPolicy retention() {
 212         return retention;
 213     }
 214 
 215     /**
 216      * Returns true if this annotation type is inherited.
 217      */
 218     public boolean isInherited() {
 219         return inherited;
 220     }
 221 
 222     /**


  56 
  57     /**
  58      * Member name -> Method object mapping. This (and its associated
  59      * accessor) are used only to generate AnnotationTypeMismatchExceptions.
  60      */
  61     private final Map<String, Method> members;
  62 
  63     /**
  64      * The retention policy for this annotation type.
  65      */
  66     private final RetentionPolicy retention;
  67 
  68     /**
  69      * Whether this annotation type is inherited.
  70      */
  71     private final boolean inherited;
  72 
  73     /**
  74      * Returns an AnnotationType instance for the specified annotation type.
  75      *
  76      * @throws IllegalArgumentException if the specified class object
  77      *         does not represent a valid annotation type
  78      */
  79     public static AnnotationType getInstance(
  80         Class<? extends Annotation> annotationClass)
  81     {
  82         JavaLangAccess jla = sun.misc.SharedSecrets.getJavaLangAccess();
  83         AnnotationType result = jla.getAnnotationType(annotationClass); // volatile read
  84         if (result == null) {
  85             result = new AnnotationType(annotationClass);
  86             // try to CAS the AnnotationType: null -> result
  87             if (!jla.casAnnotationType(annotationClass, null, result)) {
  88                 // somebody was quicker -> read it's result
  89                 result = jla.getAnnotationType(annotationClass);
  90                 assert result != null;
  91             }
  92         }
  93 
  94         return result;
  95     }
  96 


 166             return Character.class;
 167         if (type == double.class)
 168             return Double.class;
 169         if (type == float.class)
 170             return Float.class;
 171         if (type == int.class)
 172             return Integer.class;
 173         if (type == long.class)
 174             return Long.class;
 175         if (type == short.class)
 176             return Short.class;
 177         if (type == boolean.class)
 178             return Boolean.class;
 179 
 180         // Otherwise, just return declared type
 181         return type;
 182     }
 183 
 184     /**
 185      * Returns member types for this annotation type
 186      * (member name {@literal ->} type mapping).
 187      */
 188     public Map<String, Class<?>> memberTypes() {
 189         return memberTypes;
 190     }
 191 
 192     /**
 193      * Returns members of this annotation type
 194      * (member name {@literal ->} associated Method object mapping).
 195      */
 196     public Map<String, Method> members() {
 197         return members;
 198     }
 199 
 200     /**
 201      * Returns the default values for this annotation type
 202      * (Member name {@literal ->} default value mapping).
 203      */
 204     public Map<String, Object> memberDefaults() {
 205         return memberDefaults;
 206     }
 207 
 208     /**
 209      * Returns the retention policy for this annotation type.
 210      */
 211     public RetentionPolicy retention() {
 212         return retention;
 213     }
 214 
 215     /**
 216      * Returns true if this annotation type is inherited.
 217      */
 218     public boolean isInherited() {
 219         return inherited;
 220     }
 221 
 222     /**
< prev index next >