jdk/src/share/classes/java/lang/Class.java
changeset 7803 56bc97d69d93
parent 5506 202f599c92aa
child 9035 1255eb81cc2f
child 9266 121fb370f179
equal deleted inserted replaced
7802:74f2ee2b62ba 7803:56bc97d69d93
  1304         // has already been ok'd by the SecurityManager.
  1304         // has already been ok'd by the SecurityManager.
  1305 
  1305 
  1306         return java.security.AccessController.doPrivileged(
  1306         return java.security.AccessController.doPrivileged(
  1307             new java.security.PrivilegedAction<Class<?>[]>() {
  1307             new java.security.PrivilegedAction<Class<?>[]>() {
  1308                 public Class[] run() {
  1308                 public Class[] run() {
  1309                     List<Class<?>> list = new ArrayList<Class<?>>();
  1309                     List<Class<?>> list = new ArrayList<>();
  1310                     Class<?> currentClass = Class.this;
  1310                     Class<?> currentClass = Class.this;
  1311                     while (currentClass != null) {
  1311                     while (currentClass != null) {
  1312                         Class<?>[] members = currentClass.getDeclaredClasses();
  1312                         Class<?>[] members = currentClass.getDeclaredClasses();
  1313                         for (int i = 0; i < members.length; i++) {
  1313                         for (int i = 0; i < members.length; i++) {
  1314                             if (Modifier.isPublic(members[i].getModifiers())) {
  1314                             if (Modifier.isPublic(members[i].getModifiers())) {
  2304         }
  2304         }
  2305         // No cached value available; request value from VM
  2305         // No cached value available; request value from VM
  2306         res = Reflection.filterFields(this, getDeclaredFields0(publicOnly));
  2306         res = Reflection.filterFields(this, getDeclaredFields0(publicOnly));
  2307         if (useCaches) {
  2307         if (useCaches) {
  2308             if (publicOnly) {
  2308             if (publicOnly) {
  2309                 declaredPublicFields = new SoftReference<Field[]>(res);
  2309                 declaredPublicFields = new SoftReference<>(res);
  2310             } else {
  2310             } else {
  2311                 declaredFields = new SoftReference<Field[]>(res);
  2311                 declaredFields = new SoftReference<>(res);
  2312             }
  2312             }
  2313         }
  2313         }
  2314         return res;
  2314         return res;
  2315     }
  2315     }
  2316 
  2316 
  2328             if (res != null) return res;
  2328             if (res != null) return res;
  2329         }
  2329         }
  2330 
  2330 
  2331         // No cached value available; compute value recursively.
  2331         // No cached value available; compute value recursively.
  2332         // Traverse in correct order for getField().
  2332         // Traverse in correct order for getField().
  2333         List<Field> fields = new ArrayList<Field>();
  2333         List<Field> fields = new ArrayList<>();
  2334         if (traversedInterfaces == null) {
  2334         if (traversedInterfaces == null) {
  2335             traversedInterfaces = new HashSet<Class<?>>();
  2335             traversedInterfaces = new HashSet<>();
  2336         }
  2336         }
  2337 
  2337 
  2338         // Local fields
  2338         // Local fields
  2339         Field[] tmp = privateGetDeclaredFields(true);
  2339         Field[] tmp = privateGetDeclaredFields(true);
  2340         addAll(fields, tmp);
  2340         addAll(fields, tmp);
  2356         }
  2356         }
  2357 
  2357 
  2358         res = new Field[fields.size()];
  2358         res = new Field[fields.size()];
  2359         fields.toArray(res);
  2359         fields.toArray(res);
  2360         if (useCaches) {
  2360         if (useCaches) {
  2361             publicFields = new SoftReference<Field[]>(res);
  2361             publicFields = new SoftReference<>(res);
  2362         }
  2362         }
  2363         return res;
  2363         return res;
  2364     }
  2364     }
  2365 
  2365 
  2366     private static void addAll(Collection<Field> c, Field[] o) {
  2366     private static void addAll(Collection<Field> c, Field[] o) {
  2401         } else {
  2401         } else {
  2402             res = getDeclaredConstructors0(publicOnly);
  2402             res = getDeclaredConstructors0(publicOnly);
  2403         }
  2403         }
  2404         if (useCaches) {
  2404         if (useCaches) {
  2405             if (publicOnly) {
  2405             if (publicOnly) {
  2406                 publicConstructors = new SoftReference<Constructor<T>[]>(res);
  2406                 publicConstructors = new SoftReference<>(res);
  2407             } else {
  2407             } else {
  2408                 declaredConstructors = new SoftReference<Constructor<T>[]>(res);
  2408                 declaredConstructors = new SoftReference<>(res);
  2409             }
  2409             }
  2410         }
  2410         }
  2411         return res;
  2411         return res;
  2412     }
  2412     }
  2413 
  2413 
  2438         }
  2438         }
  2439         // No cached value available; request value from VM
  2439         // No cached value available; request value from VM
  2440         res = Reflection.filterMethods(this, getDeclaredMethods0(publicOnly));
  2440         res = Reflection.filterMethods(this, getDeclaredMethods0(publicOnly));
  2441         if (useCaches) {
  2441         if (useCaches) {
  2442             if (publicOnly) {
  2442             if (publicOnly) {
  2443                 declaredPublicMethods = new SoftReference<Method[]>(res);
  2443                 declaredPublicMethods = new SoftReference<>(res);
  2444             } else {
  2444             } else {
  2445                 declaredMethods = new SoftReference<Method[]>(res);
  2445                 declaredMethods = new SoftReference<>(res);
  2446             }
  2446             }
  2447         }
  2447         }
  2448         return res;
  2448         return res;
  2449     }
  2449     }
  2450 
  2450 
  2596         }
  2596         }
  2597         methods.addAllIfNotPresent(inheritedMethods);
  2597         methods.addAllIfNotPresent(inheritedMethods);
  2598         methods.compactAndTrim();
  2598         methods.compactAndTrim();
  2599         res = methods.getArray();
  2599         res = methods.getArray();
  2600         if (useCaches) {
  2600         if (useCaches) {
  2601             publicMethods = new SoftReference<Method[]>(res);
  2601             publicMethods = new SoftReference<>(res);
  2602         }
  2602         }
  2603         return res;
  2603         return res;
  2604     }
  2604     }
  2605 
  2605 
  2606 
  2606 
  2975         if (enumConstantDirectory == null) {
  2975         if (enumConstantDirectory == null) {
  2976             T[] universe = getEnumConstantsShared();
  2976             T[] universe = getEnumConstantsShared();
  2977             if (universe == null)
  2977             if (universe == null)
  2978                 throw new IllegalArgumentException(
  2978                 throw new IllegalArgumentException(
  2979                     getName() + " is not an enum type");
  2979                     getName() + " is not an enum type");
  2980             Map<String, T> m = new HashMap<String, T>(2 * universe.length);
  2980             Map<String, T> m = new HashMap<>(2 * universe.length);
  2981             for (T constant : universe)
  2981             for (T constant : universe)
  2982                 m.put(((Enum<?>)constant).name(), constant);
  2982                 m.put(((Enum<?>)constant).name(), constant);
  2983             enumConstantDirectory = m;
  2983             enumConstantDirectory = m;
  2984         }
  2984         }
  2985         return enumConstantDirectory;
  2985         return enumConstantDirectory;
  3088             getRawAnnotations(), getConstantPool(), this);
  3088             getRawAnnotations(), getConstantPool(), this);
  3089         Class<?> superClass = getSuperclass();
  3089         Class<?> superClass = getSuperclass();
  3090         if (superClass == null) {
  3090         if (superClass == null) {
  3091             annotations = declaredAnnotations;
  3091             annotations = declaredAnnotations;
  3092         } else {
  3092         } else {
  3093             annotations = new HashMap<Class<? extends Annotation>, Annotation>();
  3093             annotations = new HashMap<>();
  3094             superClass.initAnnotationsIfNecessary();
  3094             superClass.initAnnotationsIfNecessary();
  3095             for (Map.Entry<Class<? extends Annotation>, Annotation> e : superClass.annotations.entrySet()) {
  3095             for (Map.Entry<Class<? extends Annotation>, Annotation> e : superClass.annotations.entrySet()) {
  3096                 Class<? extends Annotation> annotationClass = e.getKey();
  3096                 Class<? extends Annotation> annotationClass = e.getKey();
  3097                 if (AnnotationType.getInstance(annotationClass).isInherited())
  3097                 if (AnnotationType.getInstance(annotationClass).isInherited())
  3098                     annotations.put(annotationClass, e.getValue());
  3098                     annotations.put(annotationClass, e.getValue());