< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -28,10 +28,11 @@
 import java.io.ObjectInputStream;
 import java.lang.annotation.*;
 import java.lang.reflect.*;
 import java.io.Serializable;
 import java.util.*;
+import java.util.stream.Collectors;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 
 /**
  * InvocationHandler for dynamic proxy implementation of Annotation.

@@ -156,17 +157,21 @@
         result.append(')');
         return result.toString();
     }
 
     /**
-     * Translates a member value (in "dynamic proxy return form") into a string
+     * Translates a member value (in "dynamic proxy return form") into a string.
      */
     private static String memberValueToString(Object value) {
         Class<?> type = value.getClass();
-        if (!type.isArray())    // primitive, string, class, enum const,
+        if (!type.isArray()) {   // primitive, string, class, enum const,
                                 // or annotation
+            if (type == Class.class)
+                return classValueToString((Class<?>) value);
+            else
             return value.toString();
+        }
 
         if (type == byte[].class)
             return Arrays.toString((byte[]) value);
         if (type == char[].class)
             return Arrays.toString((char[]) value);

@@ -180,14 +185,30 @@
             return Arrays.toString((long[]) value);
         if (type == short[].class)
             return Arrays.toString((short[]) value);
         if (type == boolean[].class)
             return Arrays.toString((boolean[]) value);
+        if (type == Class[].class)
+            return classArrayValueToString((Class<?>[])value);
         return Arrays.toString((Object[]) value);
     }
 
     /**
+     * Translates a Class value to a form suitable for use in the
+     * string representation of an annotation.
+     */
+    private static String classValueToString(Class<?> clazz) {
+        return clazz.getName() + ".class" ;
+    }
+
+    private static String classArrayValueToString(Class<?>[] classes) {
+        return Arrays.stream(classes)
+            .map(AnnotationInvocationHandler::classValueToString)
+            .collect(Collectors.joining(", ", "{", "}"));
+    }
+
+    /**
      * Implementation of dynamicProxy.equals(Object o)
      */
     private Boolean equalsImpl(Object o) {
         if (o == this)
             return true;
< prev index next >