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

Print this page

        

*** 23,32 **** --- 23,34 ---- * questions. */ package sun.reflect.annotation; + import sun.misc.JavaLangAccess; + import java.lang.annotation.*; import java.lang.reflect.*; import java.util.*; import java.security.AccessController; import java.security.PrivilegedAction;
*** 59,88 **** private final Map<String, Method> members; /** * The retention policy for this annotation type. */ ! private RetentionPolicy retention = RetentionPolicy.RUNTIME;; /** * Whether this annotation type is inherited. */ ! private boolean inherited = false; /** * Returns an AnnotationType instance for the specified annotation type. * * @throw IllegalArgumentException if the specified class object for * does not represent a valid annotation type */ ! public static synchronized AnnotationType getInstance( Class<? extends Annotation> annotationClass) { ! AnnotationType result = sun.misc.SharedSecrets.getJavaLangAccess(). ! getAnnotationType(annotationClass); ! if (result == null) ! result = new AnnotationType((Class<? extends Annotation>) annotationClass); return result; } /** --- 61,97 ---- private final Map<String, Method> members; /** * The retention policy for this annotation type. */ ! private final RetentionPolicy retention; /** * Whether this annotation type is inherited. */ ! private final boolean inherited; /** * Returns an AnnotationType instance for the specified annotation type. * * @throw IllegalArgumentException if the specified class object for * does not represent a valid annotation type */ ! public static AnnotationType getInstance( Class<? extends Annotation> annotationClass) { ! JavaLangAccess jla = sun.misc.SharedSecrets.getJavaLangAccess(); ! AnnotationType result = jla.getAnnotationType(annotationClass); // volatile read ! if (result == null) { ! result = new AnnotationType(annotationClass); ! // try to CAS the AnnotationType: null -> result ! if (!jla.casAnnotationType(annotationClass, null, result)) { ! // somebody was quicker -> read it's result ! result = jla.getAnnotationType(annotationClass); ! assert result != null; ! } ! } return result; } /**
*** 119,138 **** Object defaultValue = method.getDefaultValue(); if (defaultValue != null) memberDefaults.put(name, defaultValue); } - sun.misc.SharedSecrets.getJavaLangAccess(). - setAnnotationType(annotationClass, this); - // Initialize retention, & inherited fields. Special treatment // of the corresponding annotation types breaks infinite recursion. if (annotationClass != Retention.class && annotationClass != Inherited.class) { ! Retention ret = annotationClass.getAnnotation(Retention.class); retention = (ret == null ? RetentionPolicy.CLASS : ret.value()); ! inherited = annotationClass.isAnnotationPresent(Inherited.class); } } /** * Returns the type that must be returned by the invocation handler --- 128,156 ---- Object defaultValue = method.getDefaultValue(); if (defaultValue != null) memberDefaults.put(name, defaultValue); } // Initialize retention, & inherited fields. Special treatment // of the corresponding annotation types breaks infinite recursion. if (annotationClass != Retention.class && annotationClass != Inherited.class) { ! JavaLangAccess jla = sun.misc.SharedSecrets.getJavaLangAccess(); ! Map<Class<? extends Annotation>, Annotation> metaAnnotations = ! AnnotationParser.parseSelectAnnotations( ! jla.getRawClassAnnotations(annotationClass), ! jla.getConstantPool(annotationClass), ! annotationClass, ! Retention.class, Inherited.class ! ); ! Retention ret = (Retention) metaAnnotations.get(Retention.class); retention = (ret == null ? RetentionPolicy.CLASS : ret.value()); ! inherited = metaAnnotations.containsKey(Inherited.class); ! } ! else { ! retention = RetentionPolicy.RUNTIME; ! inherited = false; } } /** * Returns the type that must be returned by the invocation handler
*** 203,215 **** /** * For debugging. */ public String toString() { ! StringBuffer s = new StringBuffer("Annotation Type:" + "\n"); ! s.append(" Member types: " + memberTypes + "\n"); ! s.append(" Member defaults: " + memberDefaults + "\n"); ! s.append(" Retention policy: " + retention + "\n"); ! s.append(" Inherited: " + inherited); ! return s.toString(); } } --- 221,232 ---- /** * For debugging. */ public String toString() { ! return "Annotation Type:\n" + ! " Member types: " + memberTypes + "\n" + ! " Member defaults: " + memberDefaults + "\n" + ! " Retention policy: " + retention + "\n" + ! " Inherited: " + inherited; } }