src/share/classes/java/lang/reflect/Executable.java

Print this page
rev 10097 : 8044629: (reflect) Constructor.getAnnotatedReceiverType() returns wrong value
Reviewed-by: duke


 568 
 569     /* Helper for subclasses of Executable.
 570      *
 571      * Returns an AnnotatedType object that represents the use of a type to
 572      * specify the return type of the method/constructor represented by this
 573      * Executable.
 574      */
 575     AnnotatedType getAnnotatedReturnType0(Type returnType) {
 576         return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(),
 577                 sun.misc.SharedSecrets.getJavaLangAccess().
 578                         getConstantPool(getDeclaringClass()),
 579                 this,
 580                 getDeclaringClass(),
 581                 returnType,
 582                 TypeAnnotation.TypeAnnotationTarget.METHOD_RETURN);
 583     }
 584 
 585     /**
 586      * Returns an {@code AnnotatedType} object that represents the use of a
 587      * type to specify the receiver type of the method/constructor represented
 588      * by this Executable object. The receiver type of a method/constructor is
 589      * available only if the method/constructor has a <em>receiver
 590      * parameter</em> (JLS 8.4.1).
 591      *
 592      * If this {@code Executable} object represents a constructor or instance
 593      * method that does not have a receiver parameter, or has a receiver
 594      * parameter with no annotations on its type, then the return value is an
 595      * {@code AnnotatedType} object representing an element with no



 596      * annotations.
 597      *
 598      * If this {@code Executable} object represents a static method, then the
 599      * return value is null.

 600      *
 601      * @return an object representing the receiver type of the method or
 602      * constructor represented by this {@code Executable}

 603      */
 604     public AnnotatedType getAnnotatedReceiverType() {
 605         if (Modifier.isStatic(this.getModifiers()))
 606             return null;
 607         return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(),
 608                 sun.misc.SharedSecrets.getJavaLangAccess().
 609                         getConstantPool(getDeclaringClass()),
 610                 this,
 611                 getDeclaringClass(),
 612                 getDeclaringClass(),
 613                 TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER);
 614     }
 615 
 616     /**
 617      * Returns an array of {@code AnnotatedType} objects that represent the use
 618      * of types to specify formal parameter types of the method/constructor
 619      * represented by this Executable. The order of the objects in the array
 620      * corresponds to the order of the formal parameter types in the
 621      * declaration of the method/constructor.
 622      *




 568 
 569     /* Helper for subclasses of Executable.
 570      *
 571      * Returns an AnnotatedType object that represents the use of a type to
 572      * specify the return type of the method/constructor represented by this
 573      * Executable.
 574      */
 575     AnnotatedType getAnnotatedReturnType0(Type returnType) {
 576         return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(),
 577                 sun.misc.SharedSecrets.getJavaLangAccess().
 578                         getConstantPool(getDeclaringClass()),
 579                 this,
 580                 getDeclaringClass(),
 581                 returnType,
 582                 TypeAnnotation.TypeAnnotationTarget.METHOD_RETURN);
 583     }
 584 
 585     /**
 586      * Returns an {@code AnnotatedType} object that represents the use of a
 587      * type to specify the receiver type of the method/constructor represented
 588      * by this {@code Executable} object.


 589      *
 590      * The receiver type of a method/constructor is available only if the
 591      * method/constructor has a receiver parameter (JLS 8.4.1). If this {@code
 592      * Executable} object <em>represents an instance method or represents a
 593      * constructor of an inner member class</em>, and the
 594      * method/constructor <em>either</em> has no receiver parameter or has a
 595      * receiver parameter with no annotations on its type, then the return
 596      * value is an {@code AnnotatedType} object representing an element with no
 597      * annotations.
 598      *
 599      * If this {@code Executable} object represents a static method or
 600      * represents a constructor of a top level, static member, local, or
 601      * anoymous class, then the return value is null.
 602      *
 603      * @return an object representing the receiver type of the method or
 604      * constructor represented by this {@code Executable} or {@code null} if
 605      * this {@code Executable} can not have a receiver parameter
 606      */
 607     public AnnotatedType getAnnotatedReceiverType() {
 608         if (Modifier.isStatic(this.getModifiers()))
 609             return null;
 610         return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(),
 611                 sun.misc.SharedSecrets.getJavaLangAccess().
 612                         getConstantPool(getDeclaringClass()),
 613                 this,
 614                 getDeclaringClass(),
 615                 getDeclaringClass(),
 616                 TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER);
 617     }
 618 
 619     /**
 620      * Returns an array of {@code AnnotatedType} objects that represent the use
 621      * of types to specify formal parameter types of the method/constructor
 622      * represented by this Executable. The order of the objects in the array
 623      * corresponds to the order of the formal parameter types in the
 624      * declaration of the method/constructor.
 625      *