1 /* 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 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 java.lang.reflect; 27 28 import java.lang.annotation.Annotation; 29 30 /** 31 * {@code AnnotatedType} represents the potentially annotated use of a type in 32 * the program currently running in this VM. The use may be of any type in the 33 * Java programming language, including an array type, a parameterized type, a 34 * type variable, or a wildcard type. 35 * 36 * Note that any annotations returned by methods on this 37 * interface are <em>type annotations</em> (JLS {@jls 9.7.4}) as the 38 * entity being potentially annotated is a type. 39 * 40 * @since 1.8 41 */ 42 public interface AnnotatedType extends AnnotatedElement { 43 44 /** 45 * Returns the potentially annotated type that this type is a member of, if 46 * this type represents a nested type. For example, if this type is 47 * {@code @TA O<T>.I<S>}, return a representation of {@code @TA O<T>}. 48 * 49 * <p>Returns {@code null} if this {@code AnnotatedType} represents a 50 * top-level type, or a local or anonymous class, or a primitive type, or 51 * void. 52 * 53 * <p>Returns {@code null} if this {@code AnnotatedType} is an instance of 54 * {@code AnnotatedArrayType}, {@code AnnotatedTypeVariable}, or 55 * {@code AnnotatedWildcardType}. 56 * 57 * @implSpec 58 * This default implementation returns {@code null} and performs no other 59 * action. 60 * 61 * @return an {@code AnnotatedType} object representing the potentially 62 * annotated type that this type is a member of, or {@code null} 63 * @throws TypeNotPresentException if the owner type 64 * refers to a non-existent type declaration 65 * @throws MalformedParameterizedTypeException if the owner type 66 * refers to a parameterized type that cannot be instantiated 67 * for any reason 68 * 69 * @since 9 70 */ 71 default AnnotatedType getAnnotatedOwnerType() { 72 return null; 73 } 74 75 /** 76 * Returns the underlying type that this annotated type represents. 77 * 78 * @return the type this annotated type represents 79 */ 80 public Type getType(); 81 82 /** 83 * {@inheritDoc} 84 * <p>Note that any annotation returned by this method is a type 85 * annotation. 86 * 87 * @throws NullPointerException {@inheritDoc} 88 */ 89 @Override 90 <T extends Annotation> T getAnnotation(Class<T> annotationClass); 91 92 /** 93 * {@inheritDoc} 94 * <p>Note that any annotations returned by this method are type 95 * annotations. 96 */ 97 @Override 98 Annotation[] getAnnotations(); 99 100 /** 101 * {@inheritDoc} 102 * <p>Note that any annotations returned by this method are type 103 * annotations. 104 */ 105 @Override 106 Annotation[] getDeclaredAnnotations(); 107 }