< prev index next >

src/java.base/share/classes/java/lang/reflect/Method.java

Print this page




  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 jdk.internal.HotSpotIntrinsicCandidate;
  29 import jdk.internal.misc.SharedSecrets;
  30 import jdk.internal.reflect.CallerSensitive;
  31 import jdk.internal.reflect.MethodAccessor;
  32 import jdk.internal.reflect.Reflection;


  33 import sun.reflect.generics.repository.MethodRepository;
  34 import sun.reflect.generics.factory.CoreReflectionFactory;
  35 import sun.reflect.generics.factory.GenericsFactory;
  36 import sun.reflect.generics.scope.MethodScope;
  37 import sun.reflect.annotation.AnnotationType;
  38 import sun.reflect.annotation.AnnotationParser;
  39 import java.lang.annotation.Annotation;
  40 import java.lang.annotation.AnnotationFormatError;
  41 import java.nio.ByteBuffer;
  42 
  43 /**
  44  * A {@code Method} provides information about, and access to, a single method
  45  * on a class or interface.  The reflected method may be a class method
  46  * or an instance method (including an abstract method).
  47  *
  48  * <p>A {@code Method} permits widening conversions to occur when matching the
  49  * actual parameters to invoke with the underlying method's formal
  50  * parameters, but it throws an {@code IllegalArgumentException} if a
  51  * narrowing conversion would occur.
  52  *


 624      * null if no default is associated with the member, or if the method
 625      * instance does not represent a declared member of an annotation type.
 626      *
 627      * @return the default value for the annotation member represented
 628      *     by this {@code Method} instance.
 629      * @throws TypeNotPresentException if the annotation is of type
 630      *     {@link Class} and no definition can be found for the
 631      *     default class value.
 632      * @since  1.5
 633      */
 634     public Object getDefaultValue() {
 635         if  (annotationDefault == null)
 636             return null;
 637         Class<?> memberType = AnnotationType.invocationHandlerReturnType(
 638             getReturnType());
 639         Object result = AnnotationParser.parseMemberValue(
 640             memberType, ByteBuffer.wrap(annotationDefault),
 641             SharedSecrets.getJavaLangAccess().
 642                 getConstantPool(getDeclaringClass()),
 643             getDeclaringClass());
 644         if (result instanceof sun.reflect.annotation.ExceptionProxy)




 645             throw new AnnotationFormatError("Invalid default: " + this);

 646         return result;
 647     }
 648 
 649     /**
 650      * {@inheritDoc}
 651      * @throws NullPointerException  {@inheritDoc}
 652      * @since 1.5
 653      */
 654     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 655         return super.getAnnotation(annotationClass);
 656     }
 657 
 658     /**
 659      * {@inheritDoc}
 660      * @since 1.5
 661      */
 662     public Annotation[] getDeclaredAnnotations()  {
 663         return super.getDeclaredAnnotations();
 664     }
 665 




  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 jdk.internal.HotSpotIntrinsicCandidate;
  29 import jdk.internal.misc.SharedSecrets;
  30 import jdk.internal.reflect.CallerSensitive;
  31 import jdk.internal.reflect.MethodAccessor;
  32 import jdk.internal.reflect.Reflection;
  33 import sun.reflect.annotation.ExceptionProxy;
  34 import sun.reflect.annotation.TypeNotPresentExceptionProxy;
  35 import sun.reflect.generics.repository.MethodRepository;
  36 import sun.reflect.generics.factory.CoreReflectionFactory;
  37 import sun.reflect.generics.factory.GenericsFactory;
  38 import sun.reflect.generics.scope.MethodScope;
  39 import sun.reflect.annotation.AnnotationType;
  40 import sun.reflect.annotation.AnnotationParser;
  41 import java.lang.annotation.Annotation;
  42 import java.lang.annotation.AnnotationFormatError;
  43 import java.nio.ByteBuffer;
  44 
  45 /**
  46  * A {@code Method} provides information about, and access to, a single method
  47  * on a class or interface.  The reflected method may be a class method
  48  * or an instance method (including an abstract method).
  49  *
  50  * <p>A {@code Method} permits widening conversions to occur when matching the
  51  * actual parameters to invoke with the underlying method's formal
  52  * parameters, but it throws an {@code IllegalArgumentException} if a
  53  * narrowing conversion would occur.
  54  *


 626      * null if no default is associated with the member, or if the method
 627      * instance does not represent a declared member of an annotation type.
 628      *
 629      * @return the default value for the annotation member represented
 630      *     by this {@code Method} instance.
 631      * @throws TypeNotPresentException if the annotation is of type
 632      *     {@link Class} and no definition can be found for the
 633      *     default class value.
 634      * @since  1.5
 635      */
 636     public Object getDefaultValue() {
 637         if  (annotationDefault == null)
 638             return null;
 639         Class<?> memberType = AnnotationType.invocationHandlerReturnType(
 640             getReturnType());
 641         Object result = AnnotationParser.parseMemberValue(
 642             memberType, ByteBuffer.wrap(annotationDefault),
 643             SharedSecrets.getJavaLangAccess().
 644                 getConstantPool(getDeclaringClass()),
 645             getDeclaringClass());
 646         if (result instanceof ExceptionProxy) {
 647             if (result instanceof TypeNotPresentExceptionProxy) {
 648                 TypeNotPresentExceptionProxy proxy = (TypeNotPresentExceptionProxy)result;
 649                 throw new TypeNotPresentException(proxy.typeName(), proxy.getCause());
 650             }
 651             throw new AnnotationFormatError("Invalid default: " + this);
 652         }
 653         return result;
 654     }
 655 
 656     /**
 657      * {@inheritDoc}
 658      * @throws NullPointerException  {@inheritDoc}
 659      * @since 1.5
 660      */
 661     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 662         return super.getAnnotation(annotationClass);
 663     }
 664 
 665     /**
 666      * {@inheritDoc}
 667      * @since 1.5
 668      */
 669     public Annotation[] getDeclaredAnnotations()  {
 670         return super.getDeclaredAnnotations();
 671     }
 672 


< prev index next >