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