1 /*
   2  * Copyright (c) 2012, 2015, 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.*;
  29 import java.util.Map;
  30 import java.util.Objects;
  31 import java.util.StringJoiner;
  32 
  33 import jdk.internal.misc.SharedSecrets;
  34 import sun.reflect.annotation.AnnotationParser;
  35 import sun.reflect.annotation.AnnotationSupport;
  36 import sun.reflect.annotation.TypeAnnotationParser;
  37 import sun.reflect.annotation.TypeAnnotation;
  38 import sun.reflect.generics.repository.ConstructorRepository;
  39 
  40 /**
  41  * A shared superclass for the common functionality of {@link Method}
  42  * and {@link Constructor}.
  43  *
  44  * @since 1.8
  45  */
  46 public abstract class Executable extends AccessibleObject
  47     implements Member, GenericDeclaration {
  48     /*
  49      * Only grant package-visibility to the constructor.
  50      */
  51     Executable() {}
  52 
  53     /**
  54      * Accessor method to allow code sharing
  55      */
  56     abstract byte[] getAnnotationBytes();
  57 
  58     /**
  59      * Accessor method to allow code sharing
  60      */
  61     abstract Executable getRoot();
  62 
  63     /**
  64      * Does the Executable have generic information.
  65      */
  66     abstract boolean hasGenericInformation();
  67 
  68     abstract ConstructorRepository getGenericInfo();
  69 
  70     boolean equalParamTypes(Class<?>[] params1, Class<?>[] params2) {
  71         /* Avoid unnecessary cloning */
  72         if (params1.length == params2.length) {
  73             for (int i = 0; i < params1.length; i++) {
  74                 if (params1[i] != params2[i])
  75                     return false;
  76             }
  77             return true;
  78         }
  79         return false;
  80     }
  81 
  82     Annotation[][] parseParameterAnnotations(byte[] parameterAnnotations) {
  83         return AnnotationParser.parseParameterAnnotations(
  84                parameterAnnotations,
  85                SharedSecrets.getJavaLangAccess().
  86                getConstantPool(getDeclaringClass()),
  87                getDeclaringClass());
  88     }
  89 









  90     void printModifiersIfNonzero(StringBuilder sb, int mask, boolean isDefault) {
  91         int mod = getModifiers() & mask;
  92 
  93         if (mod != 0 && !isDefault) {
  94             sb.append(Modifier.toString(mod)).append(' ');
  95         } else {
  96             int access_mod = mod & Modifier.ACCESS_MODIFIERS;
  97             if (access_mod != 0)
  98                 sb.append(Modifier.toString(access_mod)).append(' ');
  99             if (isDefault)
 100                 sb.append("default ");
 101             mod = (mod & ~Modifier.ACCESS_MODIFIERS);
 102             if (mod != 0)
 103                 sb.append(Modifier.toString(mod)).append(' ');
 104         }
 105     }
 106 
 107     String sharedToString(int modifierMask,
 108                           boolean isDefault,
 109                           Class<?>[] parameterTypes,
 110                           Class<?>[] exceptionTypes) {
 111         try {
 112             StringBuilder sb = new StringBuilder();
 113 
 114             printModifiersIfNonzero(sb, modifierMask, isDefault);
 115             specificToStringHeader(sb);
 116             StringJoiner sj = new StringJoiner(",", "(", ")");
 117             sj.setEmptyValue("()");
 118             for (Class<?> parameterType : parameterTypes) {
 119                 sj.add(parameterType.getTypeName());
 120             }
 121             sb.append(sj.toString());
 122 



 123             if (exceptionTypes.length > 0) {
 124                 StringJoiner joiner = new StringJoiner(",", "throws ", "");
 125                 for (Class<?> exceptionType : exceptionTypes) {
 126                     joiner.add(exceptionType.getTypeName());
 127                 }
 128                 sb.append(joiner.toString());
 129             }
 130             return sb.toString();
 131         } catch (Exception e) {
 132             return "<" + e + ">";
 133         }
 134     }
 135 
 136     /**
 137      * Generate toString header information specific to a method or
 138      * constructor.
 139      */
 140     abstract void specificToStringHeader(StringBuilder sb);
 141 
 142     String sharedToGenericString(int modifierMask, boolean isDefault) {
 143         try {
 144             StringBuilder sb = new StringBuilder();
 145 
 146             printModifiersIfNonzero(sb, modifierMask, isDefault);
 147 
 148             TypeVariable<?>[] typeparms = getTypeParameters();
 149             if (typeparms.length > 0) {
 150                 StringJoiner sj = new StringJoiner(",", "<", "> ");

 151                 for(TypeVariable<?> typeparm: typeparms) { 
 152                     sj.add(typeparm.getTypeName());





 153                 }
 154                 sb.append(sj.toString());
 155             }
 156 
 157             specificToGenericStringHeader(sb);
 158 
 159             StringJoiner sj = new StringJoiner(",", "(", ")");
 160             sj.setEmptyValue("()");
 161 
 162             Type[] params = getGenericParameterTypes();
 163             for (int j = 0; j < params.length; j++) {
 164                 String param = params[j].getTypeName();
 165                 if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
 166                     param = param.replaceFirst("\\[\\]$", "...");
 167                 sj.add(param);
 168             }
 169             sb.append(sj.toString());
 170 
 171             Type[] exceptionTypes = getGenericExceptionTypes();
 172             if (exceptionTypes.length > 0) {
 173                 StringJoiner joiner = new StringJoiner(",", " throws ", "");
 174                 for (Type exceptionType : exceptionTypes) {
 175                     joiner.add(exceptionType.getTypeName());





 176                 }
 177                 sb.append(joiner.toString());
 178             }
 179             return sb.toString();
 180         } catch (Exception e) {
 181             return "<" + e + ">";
 182         }
 183     }
 184 
 185     /**
 186      * Generate toGenericString header information specific to a
 187      * method or constructor.
 188      */
 189     abstract void specificToGenericStringHeader(StringBuilder sb);
 190 
 191     /**
 192      * Returns the {@code Class} object representing the class or interface
 193      * that declares the executable represented by this object.
 194      */
 195     public abstract Class<?> getDeclaringClass();
 196 
 197     /**
 198      * Returns the name of the executable represented by this object.
 199      */
 200     public abstract String getName();
 201 
 202     /**
 203      * Returns the Java language {@linkplain Modifier modifiers} for
 204      * the executable represented by this object.
 205      */
 206     public abstract int getModifiers();
 207 
 208     /**
 209      * Returns an array of {@code TypeVariable} objects that represent the
 210      * type variables declared by the generic declaration represented by this
 211      * {@code GenericDeclaration} object, in declaration order.  Returns an
 212      * array of length 0 if the underlying generic declaration declares no type
 213      * variables.
 214      *
 215      * @return an array of {@code TypeVariable} objects that represent
 216      *     the type variables declared by this generic declaration
 217      * @throws GenericSignatureFormatError if the generic
 218      *     signature of this generic declaration does not conform to
 219      *     the format specified in
 220      *     <cite>The Java&trade; Virtual Machine Specification</cite>
 221      */
 222     public abstract TypeVariable<?>[] getTypeParameters();
 223 
 224     /**
 225      * Returns an array of {@code Class} objects that represent the formal
 226      * parameter types, in declaration order, of the executable
 227      * represented by this object.  Returns an array of length
 228      * 0 if the underlying executable takes no parameters.
 229      *
 230      * @return the parameter types for the executable this object
 231      * represents
 232      */
 233     public abstract Class<?>[] getParameterTypes();
 234 
 235     /**
 236      * Returns the number of formal parameters (whether explicitly
 237      * declared or implicitly declared or neither) for the executable
 238      * represented by this object.
 239      *
 240      * @return The number of formal parameters for the executable this
 241      * object represents
 242      */
 243     public int getParameterCount() {
 244         throw new AbstractMethodError();
 245     }
 246 
 247     /**
 248      * Returns an array of {@code Type} objects that represent the formal
 249      * parameter types, in declaration order, of the executable represented by
 250      * this object. Returns an array of length 0 if the
 251      * underlying executable takes no parameters.
 252      *
 253      * <p>If a formal parameter type is a parameterized type,
 254      * the {@code Type} object returned for it must accurately reflect
 255      * the actual type parameters used in the source code.
 256      *
 257      * <p>If a formal parameter type is a type variable or a parameterized
 258      * type, it is created. Otherwise, it is resolved.
 259      *
 260      * @return an array of {@code Type}s that represent the formal
 261      *     parameter types of the underlying executable, in declaration order
 262      * @throws GenericSignatureFormatError
 263      *     if the generic method signature does not conform to the format
 264      *     specified in
 265      *     <cite>The Java&trade; Virtual Machine Specification</cite>
 266      * @throws TypeNotPresentException if any of the parameter
 267      *     types of the underlying executable refers to a non-existent type
 268      *     declaration
 269      * @throws MalformedParameterizedTypeException if any of
 270      *     the underlying executable's parameter types refer to a parameterized
 271      *     type that cannot be instantiated for any reason
 272      */
 273     public Type[] getGenericParameterTypes() {
 274         if (hasGenericInformation())
 275             return getGenericInfo().getParameterTypes();
 276         else
 277             return getParameterTypes();
 278     }
 279 
 280     /**
 281      * Behaves like {@code getGenericParameterTypes}, but returns type
 282      * information for all parameters, including synthetic parameters.
 283      */
 284     Type[] getAllGenericParameterTypes() {
 285         final boolean genericInfo = hasGenericInformation();
 286 
 287         // Easy case: we don't have generic parameter information.  In
 288         // this case, we just return the result of
 289         // getParameterTypes().
 290         if (!genericInfo) {
 291             return getParameterTypes();
 292         } else {
 293             final boolean realParamData = hasRealParameterData();
 294             final Type[] genericParamTypes = getGenericParameterTypes();
 295             final Type[] nonGenericParamTypes = getParameterTypes();
 296             final Type[] out = new Type[nonGenericParamTypes.length];
 297             final Parameter[] params = getParameters();
 298             int fromidx = 0;
 299             // If we have real parameter data, then we use the
 300             // synthetic and mandate flags to our advantage.
 301             if (realParamData) {
 302                 for (int i = 0; i < out.length; i++) {
 303                     final Parameter param = params[i];
 304                     if (param.isSynthetic() || param.isImplicit()) {
 305                         // If we hit a synthetic or mandated parameter,
 306                         // use the non generic parameter info.
 307                         out[i] = nonGenericParamTypes[i];
 308                     } else {
 309                         // Otherwise, use the generic parameter info.
 310                         out[i] = genericParamTypes[fromidx];
 311                         fromidx++;
 312                     }
 313                 }
 314             } else {
 315                 // Otherwise, use the non-generic parameter data.
 316                 // Without method parameter reflection data, we have
 317                 // no way to figure out which parameters are
 318                 // synthetic/mandated, thus, no way to match up the
 319                 // indexes.
 320                 return genericParamTypes.length == nonGenericParamTypes.length ?
 321                     genericParamTypes : nonGenericParamTypes;
 322             }
 323             return out;
 324         }
 325     }
 326 
 327     /**
 328      * Returns an array of {@code Parameter} objects that represent
 329      * all the parameters to the underlying executable represented by
 330      * this object.  Returns an array of length 0 if the executable
 331      * has no parameters.
 332      *
 333      * <p>The parameters of the underlying executable do not necessarily
 334      * have unique names, or names that are legal identifiers in the
 335      * Java programming language (JLS 3.8).
 336      *
 337      * @throws MalformedParametersException if the class file contains
 338      * a MethodParameters attribute that is improperly formatted.
 339      * @return an array of {@code Parameter} objects representing all
 340      * the parameters to the executable this object represents.
 341      */
 342     public Parameter[] getParameters() {
 343         // TODO: This may eventually need to be guarded by security
 344         // mechanisms similar to those in Field, Method, etc.
 345         //
 346         // Need to copy the cached array to prevent users from messing
 347         // with it.  Since parameters are immutable, we can
 348         // shallow-copy.
 349         return privateGetParameters().clone();
 350     }
 351 
 352     private Parameter[] synthesizeAllParams() {
 353         final int realparams = getParameterCount();
 354         final Parameter[] out = new Parameter[realparams];
 355         for (int i = 0; i < realparams; i++)
 356             // TODO: is there a way to synthetically derive the
 357             // modifiers?  Probably not in the general case, since
 358             // we'd have no way of knowing about them, but there
 359             // may be specific cases.
 360             out[i] = new Parameter("arg" + i, 0, this, i);
 361         return out;
 362     }
 363 
 364     private void verifyParameters(final Parameter[] parameters) {
 365         final int mask = Modifier.FINAL | Modifier.SYNTHETIC | Modifier.MANDATED;
 366 
 367         if (getParameterTypes().length != parameters.length)
 368             throw new MalformedParametersException("Wrong number of parameters in MethodParameters attribute");
 369 
 370         for (Parameter parameter : parameters) {
 371             final String name = parameter.getRealName();
 372             final int mods = parameter.getModifiers();
 373 
 374             if (name != null) {
 375                 if (name.isEmpty() || name.indexOf('.') != -1 ||
 376                     name.indexOf(';') != -1 || name.indexOf('[') != -1 ||
 377                     name.indexOf('/') != -1) {
 378                     throw new MalformedParametersException("Invalid parameter name \"" + name + "\"");
 379                 }
 380             }
 381 
 382             if (mods != (mods & mask)) {
 383                 throw new MalformedParametersException("Invalid parameter modifiers");
 384             }
 385         }
 386     }
 387 
 388     private Parameter[] privateGetParameters() {
 389         // Use tmp to avoid multiple writes to a volatile.
 390         Parameter[] tmp = parameters;
 391 
 392         if (tmp == null) {
 393 
 394             // Otherwise, go to the JVM to get them
 395             try {
 396                 tmp = getParameters0();
 397             } catch(IllegalArgumentException e) {
 398                 // Rethrow ClassFormatErrors
 399                 throw new MalformedParametersException("Invalid constant pool index");
 400             }
 401 
 402             // If we get back nothing, then synthesize parameters
 403             if (tmp == null) {
 404                 hasRealParameterData = false;
 405                 tmp = synthesizeAllParams();
 406             } else {
 407                 hasRealParameterData = true;
 408                 verifyParameters(tmp);
 409             }
 410 
 411             parameters = tmp;
 412         }
 413 
 414         return tmp;
 415     }
 416 
 417     boolean hasRealParameterData() {
 418         // If this somehow gets called before parameters gets
 419         // initialized, force it into existence.
 420         if (parameters == null) {
 421             privateGetParameters();
 422         }
 423         return hasRealParameterData;
 424     }
 425 
 426     private transient volatile boolean hasRealParameterData;
 427     private transient volatile Parameter[] parameters;
 428 
 429     private native Parameter[] getParameters0();
 430     native byte[] getTypeAnnotationBytes0();
 431 
 432     // Needed by reflectaccess
 433     byte[] getTypeAnnotationBytes() {
 434         return getTypeAnnotationBytes0();
 435     }
 436 
 437     /**
 438      * Returns an array of {@code Class} objects that represent the
 439      * types of exceptions declared to be thrown by the underlying
 440      * executable represented by this object.  Returns an array of
 441      * length 0 if the executable declares no exceptions in its {@code
 442      * throws} clause.
 443      *
 444      * @return the exception types declared as being thrown by the
 445      * executable this object represents
 446      */
 447     public abstract Class<?>[] getExceptionTypes();
 448 
 449     /**
 450      * Returns an array of {@code Type} objects that represent the
 451      * exceptions declared to be thrown by this executable object.
 452      * Returns an array of length 0 if the underlying executable declares
 453      * no exceptions in its {@code throws} clause.
 454      *
 455      * <p>If an exception type is a type variable or a parameterized
 456      * type, it is created. Otherwise, it is resolved.
 457      *
 458      * @return an array of Types that represent the exception types
 459      *     thrown by the underlying executable
 460      * @throws GenericSignatureFormatError
 461      *     if the generic method signature does not conform to the format
 462      *     specified in
 463      *     <cite>The Java&trade; Virtual Machine Specification</cite>
 464      * @throws TypeNotPresentException if the underlying executable's
 465      *     {@code throws} clause refers to a non-existent type declaration
 466      * @throws MalformedParameterizedTypeException if
 467      *     the underlying executable's {@code throws} clause refers to a
 468      *     parameterized type that cannot be instantiated for any reason
 469      */
 470     public Type[] getGenericExceptionTypes() {
 471         Type[] result;
 472         if (hasGenericInformation() &&
 473             ((result = getGenericInfo().getExceptionTypes()).length > 0))
 474             return result;
 475         else
 476             return getExceptionTypes();
 477     }
 478 
 479     /**
 480      * Returns a string describing this {@code Executable}, including
 481      * any type parameters.
 482      * @return a string describing this {@code Executable}, including
 483      * any type parameters
 484      */
 485     public abstract String toGenericString();
 486 
 487     /**
 488      * Returns {@code true} if this executable was declared to take a
 489      * variable number of arguments; returns {@code false} otherwise.
 490      *
 491      * @return {@code true} if an only if this executable was declared
 492      * to take a variable number of arguments.
 493      */
 494     public boolean isVarArgs()  {
 495         return (getModifiers() & Modifier.VARARGS) != 0;
 496     }
 497 
 498     /**
 499      * Returns {@code true} if this executable is a synthetic
 500      * construct; returns {@code false} otherwise.
 501      *
 502      * @return true if and only if this executable is a synthetic
 503      * construct as defined by
 504      * <cite>The Java&trade; Language Specification</cite>.
 505      * @jls 13.1 The Form of a Binary
 506      */
 507     public boolean isSynthetic() {
 508         return Modifier.isSynthetic(getModifiers());
 509     }
 510 
 511     /**
 512      * Returns an array of arrays of {@code Annotation}s that
 513      * represent the annotations on the formal parameters, in
 514      * declaration order, of the {@code Executable} represented by
 515      * this object.  Synthetic and mandated parameters (see
 516      * explanation below), such as the outer "this" parameter to an
 517      * inner class constructor will be represented in the returned
 518      * array.  If the executable has no parameters (meaning no formal,
 519      * no synthetic, and no mandated parameters), a zero-length array
 520      * will be returned.  If the {@code Executable} has one or more
 521      * parameters, a nested array of length zero is returned for each
 522      * parameter with no annotations. The annotation objects contained
 523      * in the returned arrays are serializable.  The caller of this
 524      * method is free to modify the returned arrays; it will have no
 525      * effect on the arrays returned to other callers.
 526      *
 527      * A compiler may add extra parameters that are implicitly
 528      * declared in source ("mandated"), as well as parameters that
 529      * are neither implicitly nor explicitly declared in source
 530      * ("synthetic") to the parameter list for a method.  See {@link
 531      * java.lang.reflect.Parameter} for more information.
 532      *
 533      * @see java.lang.reflect.Parameter
 534      * @see java.lang.reflect.Parameter#getAnnotations
 535      * @return an array of arrays that represent the annotations on
 536      *    the formal and implicit parameters, in declaration order, of
 537      *    the executable represented by this object
 538      */
 539     public abstract Annotation[][] getParameterAnnotations();
 540 
 541     Annotation[][] sharedGetParameterAnnotations(Class<?>[] parameterTypes,
 542                                                  byte[] parameterAnnotations) {
 543         int numParameters = parameterTypes.length;
 544         if (parameterAnnotations == null)
 545             return new Annotation[numParameters][0];
 546 
 547         Annotation[][] result = parseParameterAnnotations(parameterAnnotations);
 548 
 549         if (result.length != numParameters)
 550             handleParameterNumberMismatch(result.length, numParameters);
 551         return result;
 552     }
 553 
 554     abstract void handleParameterNumberMismatch(int resultLength, int numParameters);
 555 
 556     /**
 557      * {@inheritDoc}
 558      * @throws NullPointerException  {@inheritDoc}
 559      */
 560     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 561         Objects.requireNonNull(annotationClass);
 562         return annotationClass.cast(declaredAnnotations().get(annotationClass));
 563     }
 564 
 565     /**
 566      * {@inheritDoc}
 567      * @throws NullPointerException {@inheritDoc}
 568      */
 569     @Override
 570     public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
 571         Objects.requireNonNull(annotationClass);
 572 
 573         return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass);
 574     }
 575 
 576     /**
 577      * {@inheritDoc}
 578      */
 579     public Annotation[] getDeclaredAnnotations()  {
 580         return AnnotationParser.toArray(declaredAnnotations());
 581     }
 582 
 583     private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
 584 
 585     private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
 586         Map<Class<? extends Annotation>, Annotation> declAnnos;
 587         if ((declAnnos = declaredAnnotations) == null) {
 588             synchronized (this) {
 589                 if ((declAnnos = declaredAnnotations) == null) {
 590                     Executable root = getRoot();
 591                     if (root != null) {
 592                         declAnnos = root.declaredAnnotations();
 593                     } else {
 594                         declAnnos = AnnotationParser.parseAnnotations(
 595                                 getAnnotationBytes(),
 596                                 SharedSecrets.getJavaLangAccess().
 597                                         getConstantPool(getDeclaringClass()),
 598                                 getDeclaringClass()
 599                         );
 600                     }
 601                     declaredAnnotations = declAnnos;
 602                 }
 603             }
 604         }
 605         return declAnnos;
 606     }
 607 
 608     /**
 609      * Returns an {@code AnnotatedType} object that represents the use of a type to
 610      * specify the return type of the method/constructor represented by this
 611      * Executable.
 612      *
 613      * If this {@code Executable} object represents a constructor, the {@code
 614      * AnnotatedType} object represents the type of the constructed object.
 615      *
 616      * If this {@code Executable} object represents a method, the {@code
 617      * AnnotatedType} object represents the use of a type to specify the return
 618      * type of the method.
 619      *
 620      * @return an object representing the return type of the method
 621      * or constructor represented by this {@code Executable}
 622      */
 623     public abstract AnnotatedType getAnnotatedReturnType();
 624 
 625     /* Helper for subclasses of Executable.
 626      *
 627      * Returns an AnnotatedType object that represents the use of a type to
 628      * specify the return type of the method/constructor represented by this
 629      * Executable.
 630      */
 631     AnnotatedType getAnnotatedReturnType0(Type returnType) {
 632         return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(),
 633                 SharedSecrets.getJavaLangAccess().
 634                         getConstantPool(getDeclaringClass()),
 635                 this,
 636                 getDeclaringClass(),
 637                 returnType,
 638                 TypeAnnotation.TypeAnnotationTarget.METHOD_RETURN);
 639     }
 640 
 641     /**
 642      * Returns an {@code AnnotatedType} object that represents the use of a
 643      * type to specify the receiver type of the method/constructor represented
 644      * by this {@code Executable} object.
 645      *
 646      * The receiver type of a method/constructor is available only if the
 647      * method/constructor has a receiver parameter (JLS 8.4.1). If this {@code
 648      * Executable} object <em>represents an instance method or represents a
 649      * constructor of an inner member class</em>, and the
 650      * method/constructor <em>either</em> has no receiver parameter or has a
 651      * receiver parameter with no annotations on its type, then the return
 652      * value is an {@code AnnotatedType} object representing an element with no
 653      * annotations.
 654      *
 655      * If this {@code Executable} object represents a static method or
 656      * represents a constructor of a top level, static member, local, or
 657      * anonymous class, then the return value is null.
 658      *
 659      * @return an object representing the receiver type of the method or
 660      * constructor represented by this {@code Executable} or {@code null} if
 661      * this {@code Executable} can not have a receiver parameter
 662      */
 663     public AnnotatedType getAnnotatedReceiverType() {
 664         if (Modifier.isStatic(this.getModifiers()))
 665             return null;
 666         return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes0(),
 667                 SharedSecrets.getJavaLangAccess().
 668                         getConstantPool(getDeclaringClass()),
 669                 this,
 670                 getDeclaringClass(),
 671                 getDeclaringClass(),
 672                 TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER);
 673     }
 674 
 675     /**
 676      * Returns an array of {@code AnnotatedType} objects that represent the use
 677      * of types to specify formal parameter types of the method/constructor
 678      * represented by this Executable. The order of the objects in the array
 679      * corresponds to the order of the formal parameter types in the
 680      * declaration of the method/constructor.
 681      *
 682      * Returns an array of length 0 if the method/constructor declares no
 683      * parameters.
 684      *
 685      * @return an array of objects representing the types of the
 686      * formal parameters of the method or constructor represented by this
 687      * {@code Executable}
 688      */
 689     public AnnotatedType[] getAnnotatedParameterTypes() {
 690         return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(),
 691                 SharedSecrets.getJavaLangAccess().
 692                         getConstantPool(getDeclaringClass()),
 693                 this,
 694                 getDeclaringClass(),
 695                 getAllGenericParameterTypes(),
 696                 TypeAnnotation.TypeAnnotationTarget.METHOD_FORMAL_PARAMETER);
 697     }
 698 
 699     /**
 700      * Returns an array of {@code AnnotatedType} objects that represent the use
 701      * of types to specify the declared exceptions of the method/constructor
 702      * represented by this Executable. The order of the objects in the array
 703      * corresponds to the order of the exception types in the declaration of
 704      * the method/constructor.
 705      *
 706      * Returns an array of length 0 if the method/constructor declares no
 707      * exceptions.
 708      *
 709      * @return an array of objects representing the declared
 710      * exceptions of the method or constructor represented by this {@code
 711      * Executable}
 712      */
 713     public AnnotatedType[] getAnnotatedExceptionTypes() {
 714         return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes0(),
 715                 SharedSecrets.getJavaLangAccess().
 716                         getConstantPool(getDeclaringClass()),
 717                 this,
 718                 getDeclaringClass(),
 719                 getGenericExceptionTypes(),
 720                 TypeAnnotation.TypeAnnotationTarget.THROWS);
 721     }
 722 
 723 }
--- EOF ---