8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 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 sun.reflect.generics.reflectiveObjects; 27 28 import java.lang.reflect.GenericDeclaration; 29 import java.lang.reflect.Type; 30 import java.lang.reflect.TypeVariable; 31 32 import sun.reflect.generics.factory.GenericsFactory; 33 import sun.reflect.generics.tree.FieldTypeSignature; 34 import sun.reflect.generics.visitor.Reifier; 35 36 /** 37 * Implementation of <tt>java.lang.reflect.TypeVariable</tt> interface 38 * for core reflection. 39 */ 40 public class TypeVariableImpl<D extends GenericDeclaration> 41 extends LazyReflectiveObjectGenerator implements TypeVariable<D> { 42 D genericDeclaration; 43 private String name; 44 // upper bounds - evaluated lazily 45 private Type[] bounds; 46 47 // The ASTs for the bounds. We are required to evaluate the bounds 48 // lazily, so we store these at least until we are first asked 49 // for the bounds. This also neatly solves the 50 // problem with F-bounds - you can't reify them before the formal 161 162 GenericDeclaration thatDecl = that.getGenericDeclaration(); 163 String thatName = that.getName(); 164 165 return 166 (genericDeclaration == null ? 167 thatDecl == null : 168 genericDeclaration.equals(thatDecl)) && 169 (name == null ? 170 thatName == null : 171 name.equals(thatName)); 172 173 } else 174 return false; 175 } 176 177 @Override 178 public int hashCode() { 179 return genericDeclaration.hashCode() ^ name.hashCode(); 180 } 181 } | 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 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 sun.reflect.generics.reflectiveObjects; 27 28 import java.lang.annotation.Annotation; 29 import java.lang.reflect.GenericDeclaration; 30 import java.lang.reflect.Type; 31 import java.lang.reflect.TypeVariable; 32 import java.util.Objects; 33 34 import sun.reflect.generics.factory.GenericsFactory; 35 import sun.reflect.generics.tree.FieldTypeSignature; 36 import sun.reflect.generics.visitor.Reifier; 37 38 /** 39 * Implementation of <tt>java.lang.reflect.TypeVariable</tt> interface 40 * for core reflection. 41 */ 42 public class TypeVariableImpl<D extends GenericDeclaration> 43 extends LazyReflectiveObjectGenerator implements TypeVariable<D> { 44 D genericDeclaration; 45 private String name; 46 // upper bounds - evaluated lazily 47 private Type[] bounds; 48 49 // The ASTs for the bounds. We are required to evaluate the bounds 50 // lazily, so we store these at least until we are first asked 51 // for the bounds. This also neatly solves the 52 // problem with F-bounds - you can't reify them before the formal 163 164 GenericDeclaration thatDecl = that.getGenericDeclaration(); 165 String thatName = that.getName(); 166 167 return 168 (genericDeclaration == null ? 169 thatDecl == null : 170 genericDeclaration.equals(thatDecl)) && 171 (name == null ? 172 thatName == null : 173 name.equals(thatName)); 174 175 } else 176 return false; 177 } 178 179 @Override 180 public int hashCode() { 181 return genericDeclaration.hashCode() ^ name.hashCode(); 182 } 183 184 // Currently vacuous implementations of AnnotatedElement methods. 185 public boolean isAnnotationPresent(Class<? extends Annotation> annotationClass) { 186 Objects.requireNonNull(annotationClass); 187 return false; 188 } 189 190 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { 191 Objects.requireNonNull(annotationClass); 192 return null; 193 } 194 195 public Annotation[] getAnnotations() { 196 // Since zero-length, don't need defensive clone 197 return EMPTY_ANNOTATION_ARRAY; 198 } 199 200 public Annotation[] getDeclaredAnnotations() { 201 // Since zero-length, don't need defensive clone 202 return EMPTY_ANNOTATION_ARRAY; 203 } 204 205 private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0]; 206 } |