12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.lang; 27 28 import java.lang.reflect.Array; 29 import java.lang.reflect.GenericArrayType; 30 import java.lang.reflect.Member; 31 import java.lang.reflect.Field; 32 import java.lang.reflect.Method; 33 import java.lang.reflect.Constructor; 34 import java.lang.reflect.Modifier; 35 import java.lang.reflect.Type; 36 import java.lang.reflect.TypeVariable; 37 import java.lang.reflect.InvocationTargetException; 38 import java.lang.ref.SoftReference; 39 import java.io.InputStream; 40 import java.io.ObjectStreamField; 41 import java.security.AccessController; 42 import java.security.PrivilegedAction; 43 import java.util.ArrayList; 44 import java.util.Arrays; 45 import java.util.Collection; 46 import java.util.HashSet; 47 import java.util.List; 48 import java.util.Set; 49 import java.util.Map; 50 import java.util.HashMap; 51 import java.util.Objects; 52 import sun.misc.Unsafe; 53 import sun.reflect.ConstantPool; 54 import sun.reflect.Reflection; 55 import sun.reflect.ReflectionFactory; 56 import sun.reflect.generics.factory.CoreReflectionFactory; 57 import sun.reflect.generics.factory.GenericsFactory; 2308 2309 // accessor for factory 2310 private GenericsFactory getFactory() { 2311 // create scope and factory 2312 return CoreReflectionFactory.make(this, ClassScope.make(this)); 2313 } 2314 2315 // accessor for generic info repository 2316 private ClassRepository getGenericInfo() { 2317 // lazily initialize repository if necessary 2318 if (genericInfo == null) { 2319 // create and cache generic info repository 2320 genericInfo = ClassRepository.make(getGenericSignature(), 2321 getFactory()); 2322 } 2323 return genericInfo; //return cached repository 2324 } 2325 2326 // Annotations handling 2327 private native byte[] getRawAnnotations(); 2328 2329 native ConstantPool getConstantPool(); 2330 2331 // 2332 // 2333 // java.lang.reflect.Field handling 2334 // 2335 // 2336 2337 // Returns an array of "root" fields. These Field objects must NOT 2338 // be propagated to the outside world, but must instead be copied 2339 // via ReflectionFactory.copyField. 2340 private Field[] privateGetDeclaredFields(boolean publicOnly) { 2341 checkInitted(); 2342 Field[] res; 2343 ReflectionData<T> rd = reflectionData(); 2344 if (rd != null) { 2345 res = publicOnly ? rd.declaredPublicFields : rd.declaredFields; 2346 if (res != null) return res; 2347 } 3179 annotations.putAll(declaredAnnotations); 3180 } 3181 } 3182 3183 // Annotation types cache their internal (AnnotationType) form 3184 3185 private AnnotationType annotationType; 3186 3187 void setAnnotationType(AnnotationType type) { 3188 annotationType = type; 3189 } 3190 3191 AnnotationType getAnnotationType() { 3192 return annotationType; 3193 } 3194 3195 /* Backing store of user-defined values pertaining to this class. 3196 * Maintained by the ClassValue class. 3197 */ 3198 transient ClassValue.ClassValueMap classValueMap; 3199 } | 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.lang; 27 28 import java.lang.reflect.Array; 29 import java.lang.reflect.GenericArrayType; 30 import java.lang.reflect.Member; 31 import java.lang.reflect.Field; 32 import java.lang.reflect.Executable; 33 import java.lang.reflect.Method; 34 import java.lang.reflect.Constructor; 35 import java.lang.reflect.Modifier; 36 import java.lang.reflect.Type; 37 import java.lang.reflect.TypeVariable; 38 import java.lang.reflect.InvocationTargetException; 39 import java.lang.reflect.AnnotatedType; 40 import java.lang.ref.SoftReference; 41 import java.io.InputStream; 42 import java.io.ObjectStreamField; 43 import java.security.AccessController; 44 import java.security.PrivilegedAction; 45 import java.util.ArrayList; 46 import java.util.Arrays; 47 import java.util.Collection; 48 import java.util.HashSet; 49 import java.util.List; 50 import java.util.Set; 51 import java.util.Map; 52 import java.util.HashMap; 53 import java.util.Objects; 54 import sun.misc.Unsafe; 55 import sun.reflect.ConstantPool; 56 import sun.reflect.Reflection; 57 import sun.reflect.ReflectionFactory; 58 import sun.reflect.generics.factory.CoreReflectionFactory; 59 import sun.reflect.generics.factory.GenericsFactory; 2310 2311 // accessor for factory 2312 private GenericsFactory getFactory() { 2313 // create scope and factory 2314 return CoreReflectionFactory.make(this, ClassScope.make(this)); 2315 } 2316 2317 // accessor for generic info repository 2318 private ClassRepository getGenericInfo() { 2319 // lazily initialize repository if necessary 2320 if (genericInfo == null) { 2321 // create and cache generic info repository 2322 genericInfo = ClassRepository.make(getGenericSignature(), 2323 getFactory()); 2324 } 2325 return genericInfo; //return cached repository 2326 } 2327 2328 // Annotations handling 2329 private native byte[] getRawAnnotations(); 2330 // Since 1.8 2331 native byte[] getRawTypeAnnotations(); 2332 static byte[] getExecutableTypeAnnotationBytes(Executable ex) { 2333 return getReflectionFactory().getExecutableTypeAnnotationBytes(ex); 2334 } 2335 2336 native ConstantPool getConstantPool(); 2337 2338 // 2339 // 2340 // java.lang.reflect.Field handling 2341 // 2342 // 2343 2344 // Returns an array of "root" fields. These Field objects must NOT 2345 // be propagated to the outside world, but must instead be copied 2346 // via ReflectionFactory.copyField. 2347 private Field[] privateGetDeclaredFields(boolean publicOnly) { 2348 checkInitted(); 2349 Field[] res; 2350 ReflectionData<T> rd = reflectionData(); 2351 if (rd != null) { 2352 res = publicOnly ? rd.declaredPublicFields : rd.declaredFields; 2353 if (res != null) return res; 2354 } 3186 annotations.putAll(declaredAnnotations); 3187 } 3188 } 3189 3190 // Annotation types cache their internal (AnnotationType) form 3191 3192 private AnnotationType annotationType; 3193 3194 void setAnnotationType(AnnotationType type) { 3195 annotationType = type; 3196 } 3197 3198 AnnotationType getAnnotationType() { 3199 return annotationType; 3200 } 3201 3202 /* Backing store of user-defined values pertaining to this class. 3203 * Maintained by the ClassValue class. 3204 */ 3205 transient ClassValue.ClassValueMap classValueMap; 3206 3207 // AnnotatedType since 1.8 3208 3209 /** 3210 * Returns an AnnotatedType object that represents the use of a type to denote 3211 * the superclass of the entity represented by this Class. (The _use_ of type 3212 * Foo to denote the superclass in '... extends Foo' is distinct from the 3213 * _declaration_ of type Foo.) 3214 * 3215 * If this Class represents a class type whose declaration does not explicitly 3216 * indicate an annotated superclass, the return value is null. 3217 * 3218 * If this Class represents either the Object class, an interface type, an 3219 * array type, a primitive type, or void, the return value is null. 3220 * 3221 * @since 1.8 3222 */ 3223 public AnnotatedType getAnnotatedSuperclass() { 3224 return TypeAnnotationParser.buildAnnotatedSuperclass(getRawTypeAnnotations(), getConstantPool(), this); 3225 } 3226 3227 /** 3228 * Returns an array of AnnotatedType objects that represent the use of types to 3229 * denote superinterfaces of the entity represented by this Class. (The _use_ 3230 * of type Foo to denote a superinterface in '... implements Foo' is 3231 * distinct from the _declaration_ of type Foo.) 3232 * 3233 * If this Class represents a class, the return value is an array 3234 * containing objects representing the uses of interface types to denote 3235 * interfaces implemented by the class. The order of the objects in the 3236 * array corresponds to the order of the interface types used in the 3237 * 'implements' clause of the declaration of this Class. 3238 * 3239 * If this Class represents an interface, the return value is an array 3240 * containing objects representing the uses of interface types to denote 3241 * interfaces directly extended by the interface. The order of the objects in 3242 * the array corresponds to the order of the interface types used in the 3243 * 'extends' clause of the declaration of this Class. 3244 * 3245 * If this Class represents a class or interface whose declaration does not 3246 * explicitly indicate any annotated superinterfaces, the return value is an 3247 * array of length 0. 3248 * 3249 * If this Class represents either the Object class, an array type, a 3250 * primitive type, or void, the return value is an array of length 0. 3251 * 3252 * @since 1.8 3253 */ 3254 public AnnotatedType[] getAnnotatedInterfaces() { 3255 return TypeAnnotationParser.buildAnnotatedInterfaces(getRawTypeAnnotations(), getConstantPool(), this); 3256 } 3257 } |