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

Print this page

        

@@ -57,14 +57,14 @@
      *   annotation annotations[num_annotations];
      *
      * @throws AnnotationFormatError if an annotation is found to be
      *         malformed.
      */
-    public static Map<Class, Annotation> parseAnnotations(
+    public static Map<Class<? extends Annotation>, Annotation> parseAnnotations(
                 byte[] rawAnnotations,
                 ConstantPool constPool,
-                Class container) {
+                Class<?> container) {
         if (rawAnnotations == null)
             return Collections.emptyMap();
 
         try {
             return parseAnnotations2(rawAnnotations, constPool, container);

@@ -74,21 +74,22 @@
             // Type mismatch in constant pool
             throw new AnnotationFormatError(e);
         }
     }
 
-    private static Map<Class, Annotation> parseAnnotations2(
+    private static Map<Class<? extends Annotation>, Annotation> parseAnnotations2(
                 byte[] rawAnnotations,
                 ConstantPool constPool,
-                Class container) {
-        Map<Class, Annotation> result = new LinkedHashMap<Class, Annotation>();
+                Class<?> container) {
+        Map<Class<? extends Annotation>, Annotation> result = 
+            new LinkedHashMap<Class<? extends Annotation>, Annotation>();
         ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
         int numAnnotations = buf.getShort() & 0xFFFF;
         for (int i = 0; i < numAnnotations; i++) {
             Annotation a = parseAnnotation(buf, constPool, container, false);
             if (a != null) {
-                Class klass = a.annotationType();
+                Class<? extends Annotation> klass = a.annotationType();
                 AnnotationType type = AnnotationType.getInstance(klass);
                 if (type.retention() == RetentionPolicy.RUNTIME)
                     if (result.put(klass, a) != null)
                         throw new AnnotationFormatError(
                             "Duplicate annotation for class: "+klass+": " + a);

@@ -121,11 +122,11 @@
      *         malformed.
      */
     public static Annotation[][] parseParameterAnnotations(
                     byte[] rawAnnotations,
                     ConstantPool constPool,
-                    Class container) {
+                    Class<?> container) {
         try {
             return parseParameterAnnotations2(rawAnnotations, constPool, container);
         } catch(BufferUnderflowException e) {
             throw new AnnotationFormatError(
                 "Unexpected end of parameter annotations.");

@@ -136,11 +137,11 @@
     }
 
     private static Annotation[][] parseParameterAnnotations2(
                     byte[] rawAnnotations,
                     ConstantPool constPool,
-                    Class container) {
+                    Class<?> container) {
         ByteBuffer buf = ByteBuffer.wrap(rawAnnotations);
         int numParameters = buf.get() & 0xFF;
         Annotation[][] result = new Annotation[numParameters][];
 
         for (int i = 0; i < numParameters; i++) {

@@ -186,19 +187,19 @@
      * TypeNotPresentException if a referenced annotation type is not
      * available at runtime
      */
     private static Annotation parseAnnotation(ByteBuffer buf,
                                               ConstantPool constPool,
-                                              Class container,
+                                              Class<?> container,
                                               boolean exceptionOnMissingAnnotationClass) {
         int typeIndex = buf.getShort() & 0xFFFF;
-        Class annotationClass = null;
+        Class<? extends Annotation> annotationClass = null;
         String sig = "[unknown]";
         try {
             try {
                 sig = constPool.getUTF8At(typeIndex);
-                annotationClass = parseSig(sig, container);
+                annotationClass = (Class<? extends Annotation>)parseSig(sig, container);
             } catch (IllegalArgumentException ex) {
                 // support obsolete early jsr175 format class files
                 annotationClass = constPool.getClassAt(typeIndex);
             }
         } catch (NoClassDefFoundError e) {

@@ -221,19 +222,19 @@
         } catch (IllegalArgumentException e) {
             skipAnnotation(buf, false);
             return null;
         }
 
-        Map<String, Class> memberTypes = type.memberTypes();
+        Map<String, Class<?>> memberTypes = type.memberTypes();
         Map<String, Object> memberValues =
             new LinkedHashMap<String, Object>(type.memberDefaults());
 
         int numMembers = buf.getShort() & 0xFFFF;
         for (int i = 0; i < numMembers; i++) {
             int memberNameIndex = buf.getShort() & 0xFFFF;
             String memberName = constPool.getUTF8At(memberNameIndex);
-            Class memberType = memberTypes.get(memberName);
+            Class<?> memberType = memberTypes.get(memberName);
 
             if (memberType == null) {
                 // Member is no longer present in annotation type; ignore it
                 skipMemberValue(buf);
             } else {

@@ -250,11 +251,11 @@
     /**
      * Returns an annotation of the given type backed by the given
      * member -> value map.
      */
     public static Annotation annotationForMap(
-        Class type, Map<String, Object> memberValues)
+        Class<? extends Annotation> type, Map<String, Object> memberValues)
     {
         return (Annotation) Proxy.newProxyInstance(
             type.getClassLoader(), new Class[] { type },
             new AnnotationInvocationHandler(type, memberValues));
     }

@@ -284,18 +285,19 @@
      * }
      *
      * The member must be of the indicated type. If it is not, this
      * method returns an AnnotationTypeMismatchExceptionProxy.
      */
-    public static Object parseMemberValue(Class memberType, ByteBuffer buf,
+    public static Object parseMemberValue(Class<?> memberType,
+                                          ByteBuffer buf,
                                           ConstantPool constPool,
-                                          Class container) {
+                                          Class<?> container) {
         Object result = null;
         int tag = buf.get();
         switch(tag) {
           case 'e':
-              return parseEnumValue(memberType, buf, constPool, container);
+              return parseEnumValue((Class<? extends Enum<?>>)memberType, buf, constPool, container);
           case 'c':
               result = parseClassValue(buf, constPool, container);
               break;
           case '@':
               result = parseAnnotation(buf, constPool, container, true);

@@ -359,11 +361,11 @@
      *
      *       u2   class_info_index;
      */
     private static Object parseClassValue(ByteBuffer buf,
                                           ConstantPool constPool,
-                                          Class container) {
+                                          Class<?> container) {
         int classIndex = buf.getShort() & 0xFFFF;
         try {
             try {
                 String sig = constPool.getUTF8At(classIndex);
                 return parseSig(sig, container);

@@ -377,21 +379,21 @@
         catch (TypeNotPresentException e) {
             return new TypeNotPresentExceptionProxy(e.typeName(), e.getCause());
         }
     }
 
-    private static Class<?> parseSig(String sig, Class container) {
+    private static Class<?> parseSig(String sig, Class<?> container) {
         if (sig.equals("V")) return void.class;
         SignatureParser parser = SignatureParser.make();
         TypeSignature typeSig = parser.parseTypeSig(sig);
         GenericsFactory factory = CoreReflectionFactory.make(container, ClassScope.make(container));
         Reifier reify = Reifier.make(factory);
         typeSig.accept(reify);
         Type result = reify.getResult();
         return toClass(result);
     }
-    static Class toClass(Type o) {
+    static Class<?> toClass(Type o) {
         if (o instanceof GenericArrayType)
             return Array.newInstance(toClass(((GenericArrayType)o).getGenericComponentType()),
                                      0)
                 .getClass();
         return (Class)o;

@@ -407,13 +409,13 @@
      *       {
      *           u2   type_name_index;
      *           u2   const_name_index;
      *       } enum_const_value;
      */
-    private static Object parseEnumValue(Class enumType, ByteBuffer buf,
+    private static Object parseEnumValue(Class<? extends Enum> enumType, ByteBuffer buf,
                                          ConstantPool constPool,
-                                         Class container) {
+                                         Class<?> container) {
         int typeNameIndex = buf.getShort() & 0xFFFF;
         String typeName  = constPool.getUTF8At(typeNameIndex);
         int constNameIndex = buf.getShort() & 0xFFFF;
         String constName = constPool.getUTF8At(constNameIndex);
 

@@ -447,16 +449,16 @@
      *       } array_value;
      *
      * If the array values do not match arrayType, an
      * AnnotationTypeMismatchExceptionProxy will be returned.
      */
-    private static Object parseArray(Class arrayType,
+    private static Object parseArray(Class<?> arrayType,
                                      ByteBuffer buf,
                                      ConstantPool constPool,
-                                     Class container) {
+                                     Class<?> container) {
         int length = buf.getShort() & 0xFFFF;  // Number of array components
-        Class componentType = arrayType.getComponentType();
+        Class<?> componentType = arrayType.getComponentType();
 
         if (componentType == byte.class) {
             return parseByteArray(length, buf, constPool);
         } else if (componentType == char.class) {
             return parseCharArray(length, buf, constPool);

@@ -475,15 +477,15 @@
         } else if (componentType == String.class) {
             return parseStringArray(length, buf, constPool);
         } else if (componentType == Class.class) {
             return parseClassArray(length, buf, constPool, container);
         } else if (componentType.isEnum()) {
-            return parseEnumArray(length, componentType, buf,
+            return parseEnumArray(length, (Class<? extends Enum>)componentType, buf,
                                   constPool, container);
         } else {
             assert componentType.isAnnotation();
-            return parseAnnotationArray(length, componentType, buf,
+            return parseAnnotationArray(length, (Class <? extends Annotation>)componentType, buf,
                                         constPool, container);
         }
     }
 
     private static Object parseByteArray(int length,

@@ -658,12 +660,12 @@
     }
 
     private static Object parseClassArray(int length,
                                           ByteBuffer buf,
                                           ConstantPool constPool,
-                                          Class container) {
-        Object[] result = new Class[length];
+                                          Class<?> container) {
+        Object[] result = new Class<?>[length];
         boolean typeMismatch = false;
         int tag = 0;
 
         for (int i = 0; i < length; i++) {
             tag = buf.get();

@@ -675,14 +677,14 @@
             }
         }
         return typeMismatch ? exceptionProxy(tag) : result;
     }
 
-    private static Object parseEnumArray(int length, Class enumType,
+    private static Object parseEnumArray(int length, Class<? extends Enum> enumType,
                                          ByteBuffer buf,
                                          ConstantPool constPool,
-                                         Class container) {
+                                         Class<?> container) {
         Object[] result = (Object[]) Array.newInstance(enumType, length);
         boolean typeMismatch = false;
         int tag = 0;
 
         for (int i = 0; i < length; i++) {

@@ -696,14 +698,14 @@
         }
         return typeMismatch ? exceptionProxy(tag) : result;
     }
 
     private static Object parseAnnotationArray(int length,
-                                               Class annotationType,
+                                               Class<? extends Annotation> annotationType,
                                                ByteBuffer buf,
                                                ConstantPool constPool,
-                                               Class container) {
+                                               Class<?> container) {
         Object[] result = (Object[]) Array.newInstance(annotationType, length);
         boolean typeMismatch = false;
         int tag = 0;
 
         for (int i = 0; i < length; i++) {

@@ -795,9 +797,9 @@
      * Method.getDeclaredAnnotations(), and Constructor.getDeclaredAnnotations().
      * This avoids the reflection classes to load the Annotation class until
      * it is needed.
      */
     private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
-    public static Annotation[] toArray(Map<Class, Annotation> annotations) {
+    public static Annotation[] toArray(Map<Class<? extends Annotation>, Annotation> annotations) {
         return annotations.values().toArray(EMPTY_ANNOTATION_ARRAY);
     }
 }