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