jdk/src/share/classes/sun/reflect/generics/reflectiveObjects/TypeVariableImpl.java
equal
deleted
inserted
replaced
26 package sun.reflect.generics.reflectiveObjects; |
26 package sun.reflect.generics.reflectiveObjects; |
27 |
27 |
28 import java.lang.annotation.*; |
28 import java.lang.annotation.*; |
29 import java.lang.reflect.AnnotatedType; |
29 import java.lang.reflect.AnnotatedType; |
30 import java.lang.reflect.Array; |
30 import java.lang.reflect.Array; |
|
31 import java.lang.reflect.Constructor; |
31 import java.lang.reflect.GenericDeclaration; |
32 import java.lang.reflect.GenericDeclaration; |
|
33 import java.lang.reflect.Member; |
|
34 import java.lang.reflect.Method; |
32 import java.lang.reflect.Type; |
35 import java.lang.reflect.Type; |
33 import java.lang.reflect.TypeVariable; |
36 import java.lang.reflect.TypeVariable; |
34 import java.util.LinkedHashMap; |
37 import java.util.LinkedHashMap; |
35 import java.util.Map; |
38 import java.util.Map; |
36 import java.util.Objects; |
39 import java.util.Objects; |
38 import sun.reflect.annotation.TypeAnnotationParser; |
41 import sun.reflect.annotation.TypeAnnotationParser; |
39 import sun.reflect.annotation.AnnotationType; |
42 import sun.reflect.annotation.AnnotationType; |
40 import sun.reflect.generics.factory.GenericsFactory; |
43 import sun.reflect.generics.factory.GenericsFactory; |
41 import sun.reflect.generics.tree.FieldTypeSignature; |
44 import sun.reflect.generics.tree.FieldTypeSignature; |
42 import sun.reflect.generics.visitor.Reifier; |
45 import sun.reflect.generics.visitor.Reifier; |
|
46 import sun.reflect.misc.ReflectUtil; |
43 |
47 |
44 /** |
48 /** |
45 * Implementation of <tt>java.lang.reflect.TypeVariable</tt> interface |
49 * Implementation of <tt>java.lang.reflect.TypeVariable</tt> interface |
46 * for core reflection. |
50 * for core reflection. |
47 */ |
51 */ |
93 */ |
97 */ |
94 public static <T extends GenericDeclaration> |
98 public static <T extends GenericDeclaration> |
95 TypeVariableImpl<T> make(T decl, String name, |
99 TypeVariableImpl<T> make(T decl, String name, |
96 FieldTypeSignature[] bs, |
100 FieldTypeSignature[] bs, |
97 GenericsFactory f) { |
101 GenericsFactory f) { |
|
102 |
|
103 if (!((decl instanceof Class) || |
|
104 (decl instanceof Method) || |
|
105 (decl instanceof Constructor))) { |
|
106 throw new AssertionError("Unexpected kind of GenericDeclaration" + |
|
107 decl.getClass().toString()); |
|
108 } |
98 return new TypeVariableImpl<T>(decl, name, bs, f); |
109 return new TypeVariableImpl<T>(decl, name, bs, f); |
99 } |
110 } |
100 |
111 |
101 |
112 |
102 /** |
113 /** |
147 * @return the generic declaration that declared this type variable. |
158 * @return the generic declaration that declared this type variable. |
148 * |
159 * |
149 * @since 1.5 |
160 * @since 1.5 |
150 */ |
161 */ |
151 public D getGenericDeclaration(){ |
162 public D getGenericDeclaration(){ |
|
163 if (genericDeclaration instanceof Class) |
|
164 ReflectUtil.checkPackageAccess((Class)genericDeclaration); |
|
165 else if ((genericDeclaration instanceof Method) || |
|
166 (genericDeclaration instanceof Constructor)) |
|
167 ReflectUtil.conservativeCheckMemberAccess((Member)genericDeclaration); |
|
168 else |
|
169 throw new AssertionError("Unexpected kind of GenericDeclaration"); |
152 return genericDeclaration; |
170 return genericDeclaration; |
153 } |
171 } |
154 |
172 |
155 |
173 |
156 /** |
174 /** |
162 |
180 |
163 public String toString() {return getName();} |
181 public String toString() {return getName();} |
164 |
182 |
165 @Override |
183 @Override |
166 public boolean equals(Object o) { |
184 public boolean equals(Object o) { |
167 if (o instanceof TypeVariable) { |
185 if (o instanceof TypeVariable && |
|
186 o.getClass() == TypeVariableImpl.class) { |
168 TypeVariable<?> that = (TypeVariable<?>) o; |
187 TypeVariable<?> that = (TypeVariable<?>) o; |
169 |
188 |
170 GenericDeclaration thatDecl = that.getGenericDeclaration(); |
189 GenericDeclaration thatDecl = that.getGenericDeclaration(); |
171 String thatName = that.getName(); |
190 String thatName = that.getName(); |
172 |
191 |