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