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