1 /* 2 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package java.lang.reflect; 27 28 import java.lang.annotation.*; 29 import java.util.Map; 30 import java.util.Objects; 31 32 import jdk.internal.misc.SharedSecrets; 33 import sun.reflect.annotation.AnnotationParser; 34 import sun.reflect.annotation.AnnotationSupport; 35 import sun.reflect.annotation.TypeAnnotationParser; 36 import sun.reflect.annotation.TypeAnnotation; 37 import sun.reflect.generics.repository.ConstructorRepository; 38 39 /** 40 * A shared superclass for the common functionality of {@link Method} 41 * and {@link Constructor}. 42 * 43 * @since 1.8 44 */ 45 public abstract class Executable extends AccessibleObject 46 implements Member, GenericDeclaration { 47 /* 48 * Only grant package-visibility to the constructor. 49 */ 50 Executable() {} 51 52 /** 53 * Accessor method to allow code sharing 54 */ 55 abstract byte[] getAnnotationBytes(); 56 57 /** 58 * Accessor method to allow code sharing 59 */ 60 abstract Executable getRoot(); 61 62 /** 63 * Does the Executable have generic information. 64 */ 65 abstract boolean hasGenericInformation(); 66 67 abstract ConstructorRepository getGenericInfo(); 68 69 boolean equalParamTypes(Class<?>[] params1, Class<?>[] params2) { 70 /* Avoid unnecessary cloning */ 71 if (params1.length == params2.length) { 72 for (int i = 0; i < params1.length; i++) { 73 if (params1[i] != params2[i]) 74 return false; 75 } 76 return true; 77 } 78 return false; 79 } 80 81 Annotation[][] parseParameterAnnotations(byte[] parameterAnnotations) { 82 return AnnotationParser.parseParameterAnnotations( 83 parameterAnnotations, 84 SharedSecrets.getJavaLangAccess(). 85 getConstantPool(getDeclaringClass()), 86 getDeclaringClass()); 87 } 88 89 void separateWithCommas(Class<?>[] types, StringBuilder sb) { 90 for (int j = 0; j < types.length; j++) { 91 sb.append(types[j].getTypeName()); 92 if (j < (types.length - 1)) 93 sb.append(","); 94 } 95 96 } 97 98 void printModifiersIfNonzero(StringBuilder sb, int mask, boolean isDefault) { 99 int mod = getModifiers() & mask; 100 101 if (mod != 0 && !isDefault) { 102 sb.append(Modifier.toString(mod)).append(' '); 103 } else { 104 int access_mod = mod & Modifier.ACCESS_MODIFIERS; 105 if (access_mod != 0) 106 sb.append(Modifier.toString(access_mod)).append(' '); 107 if (isDefault) 108 sb.append("default "); 109 mod = (mod & ~Modifier.ACCESS_MODIFIERS); 110 if (mod != 0) 111 sb.append(Modifier.toString(mod)).append(' '); 112 } 113 } 114 115 String sharedToString(int modifierMask, 116 boolean isDefault, 117 Class<?>[] parameterTypes, 118 Class<?>[] exceptionTypes) { 119 try { 120 StringBuilder sb = new StringBuilder(); 121 122 printModifiersIfNonzero(sb, modifierMask, isDefault); 123 specificToStringHeader(sb); 124 125 sb.append('('); 126 separateWithCommas(parameterTypes, sb); 127 sb.append(')'); 128 if (exceptionTypes.length > 0) { 129 sb.append(" throws "); 130 separateWithCommas(exceptionTypes, sb); 131 } 132 return sb.toString(); 133 } catch (Exception e) { 134 return "<" + e + ">"; 135 } 136 } 137 138 /** 139 * Generate toString header information specific to a method or 140 * constructor. 141 */ 142 abstract void specificToStringHeader(StringBuilder sb); 143 144 String sharedToGenericString(int modifierMask, boolean isDefault) { 145 try { 146 StringBuilder sb = new StringBuilder(); 147 148 printModifiersIfNonzero(sb, modifierMask, isDefault); 149 150 TypeVariable<?>[] typeparms = getTypeParameters(); 151 if (typeparms.length > 0) { 152 boolean first = true; 153 sb.append('<'); 154 for(TypeVariable<?> typeparm: typeparms) { 155 if (!first) 156 sb.append(','); 157 // Class objects can't occur here; no need to test 158 // and call Class.getName(). 159 sb.append(typeparm.toString()); 160 first = false; 161 } 162 sb.append("> "); 163 } 164 165 specificToGenericStringHeader(sb); 166 167 sb.append('('); 168 Type[] params = getGenericParameterTypes(); 169 for (int j = 0; j < params.length; j++) { 170 String param = params[j].getTypeName(); 171 if (isVarArgs() && (j == params.length - 1)) // replace T[] with T... 172 param = param.replaceFirst("\\[\\]$", "..."); 173 sb.append(param); 174 if (j < (params.length - 1)) 175 sb.append(','); 176 } 177 sb.append(')'); 178 Type[] exceptions = getGenericExceptionTypes(); 179 if (exceptions.length > 0) { 180 sb.append(" throws "); 181 for (int k = 0; k < exceptions.length; k++) { 182 sb.append((exceptions[k] instanceof Class)? 183 ((Class)exceptions[k]).getName(): 184 exceptions[k].toString()); 185 if (k < (exceptions.length - 1)) 186 sb.append(','); 187 } 188 } 189 return sb.toString(); 190 } catch (Exception e) { 191 return "<" + e + ">"; 192 } 193 } 194 195 /** 196 * Generate toGenericString header information specific to a 197 * method or constructor. 198 */ 199 abstract void specificToGenericStringHeader(StringBuilder sb); 200 201 /** 202 * Returns the {@code Class} object representing the class or interface 203 * that declares the executable represented by this object. 204 */ 205 public abstract Class<?> getDeclaringClass(); 206 207 /** 208 * Returns the name of the executable represented by this object. 209 */ 210 public abstract String getName(); 211 212 /** 213 * Returns the Java language {@linkplain Modifier modifiers} for 214 * the executable represented by this object. 215 */ 216 public abstract int getModifiers(); 217 218 /** 219 * Returns an array of {@code TypeVariable} objects that represent the 220 * type variables declared by the generic declaration represented by this 221 * {@code GenericDeclaration} object, in declaration order. Returns an 222 * array of length 0 if the underlying generic declaration declares no type 223 * variables. 224 * 225 * @return an array of {@code TypeVariable} objects that represent 226 * the type variables declared by this generic declaration 227 * @throws GenericSignatureFormatError if the generic 228 * signature of this generic declaration does not conform to 229 * the format specified in 230 * <cite>The Java™ Virtual Machine Specification</cite> 231 */ 232 public abstract TypeVariable<?>[] getTypeParameters(); 233 234 /** 235 * Returns an array of {@code Class} objects that represent the formal 236 * parameter types, in declaration order, of the executable 237 * represented by this object. Returns an array of length 238 * 0 if the underlying executable takes no parameters. 239 * 240 * @return the parameter types for the executable this object 241 * represents 242 */ 243 public abstract Class<?>[] getParameterTypes(); 244 245 /** 246 * Returns the number of formal parameters (whether explicitly 247 * declared or implicitly declared or neither) for the executable 248 * represented by this object. 249 * 250 * @return The number of formal parameters for the executable this 251 * object represents 252 */ 253 public int getParameterCount() { 254 throw new AbstractMethodError(); 255 } 256 257 /** 258 * Returns an array of {@code Type} objects that represent the formal 259 * parameter types, in declaration order, of the executable represented by 260 * this object. Returns an array of length 0 if the 261 * underlying executable takes no parameters. 262 * 263 * <p>If a formal parameter type is a parameterized type, 264 * the {@code Type} object returned for it must accurately reflect 265 * the actual type parameters used in the source code. 266 * 267 * <p>If a formal parameter type is a type variable or a parameterized 268 * type, it is created. Otherwise, it is resolved. 269 * 270 * @return an array of {@code Type}s that represent the formal 271 * parameter types of the underlying executable, in declaration order 272 * @throws GenericSignatureFormatError 273 * if the generic method signature does not conform to the format 274 * specified in 275 * <cite>The Java™ Virtual Machine Specification</cite> 276 * @throws TypeNotPresentException if any of the parameter 277 * types of the underlying executable refers to a non-existent type 278 * declaration 279 * @throws MalformedParameterizedTypeException if any of 280 * the underlying executable's parameter types refer to a parameterized 281 * type that cannot be instantiated for any reason 282 */ 283 public Type[] getGenericParameterTypes() { 284 if (hasGenericInformation()) 285 return getGenericInfo().getParameterTypes(); 286 else 287 return getParameterTypes(); 288 } 289 290 /** 291 * Behaves like {@code getGenericParameterTypes}, but returns type 292 * information for all parameters, including synthetic parameters. 293 */ 294 Type[] getAllGenericParameterTypes() { 295 final boolean genericInfo = hasGenericInformation(); 296 297 // Easy case: we don't have generic parameter information. In 298 // this case, we just return the result of 299 // getParameterTypes(). 300 if (!genericInfo) { 301 return getParameterTypes(); 302 } else { 303 final boolean realParamData = hasRealParameterData(); 304 final Type[] genericParamTypes = getGenericParameterTypes(); 305 final Type[] nonGenericParamTypes = getParameterTypes(); 306 final Type[] out = new Type[nonGenericParamTypes.length]; 307 final Parameter[] params = getParameters(); 308 int fromidx = 0; 309 // If we have real parameter data, then we use the 310 // synthetic and mandate flags to our advantage. 311 if (realParamData) { 312 for (int i = 0; i < out.length; i++) { 313 final Parameter param = params[i]; 314 if (param.isSynthetic() || param.isImplicit()) { 315 // If we hit a synthetic or mandated parameter, 316 // use the non generic parameter info. 317 out[i] = nonGenericParamTypes[i]; 318 } else { 319 // Otherwise, use the generic parameter info. 320 out[i] = genericParamTypes[fromidx]; 321 fromidx++; 322 } 323 } 324 } else { 325 // Otherwise, use the non-generic parameter data. 326 // Without method parameter reflection data, we have 327 // no way to figure out which parameters are 328 // synthetic/mandated, thus, no way to match up the 329 // indexes. 330 return genericParamTypes.length == nonGenericParamTypes.length ? 331 genericParamTypes : nonGenericParamTypes; 332 } 333 return out; 334 } 335 } 336 337 /** 338 * Returns an array of {@code Parameter} objects that represent 339 * all the parameters to the underlying executable represented by 340 * this object. Returns an array of length 0 if the executable 341 * has no parameters. 342 * 343 * <p>The parameters of the underlying executable do not necessarily 344 * have unique names, or names that are legal identifiers in the 345 * Java programming language (JLS 3.8). 346 * 347 * @throws MalformedParametersException if the class file contains 348 * a MethodParameters attribute that is improperly formatted. 349 * @return an array of {@code Parameter} objects representing all 350 * the parameters to the executable this object represents. 351 */ 352 public Parameter[] getParameters() { 353 // TODO: This may eventually need to be guarded by security 354 // mechanisms similar to those in Field, Method, etc. 355 // 356 // Need to copy the cached array to prevent users from messing 357 // with it. Since parameters are immutable, we can 358 // shallow-copy. 359 return privateGetParameters().clone(); 360 } 361 362 private Parameter[] synthesizeAllParams() { 363 final int realparams = getParameterCount(); 364 final Parameter[] out = new Parameter[realparams]; 365 for (int i = 0; i < realparams; i++) 366 // TODO: is there a way to synthetically derive the 367 // modifiers? Probably not in the general case, since 368 // we'd have no way of knowing about them, but there 369 // may be specific cases. 370 out[i] = new Parameter("arg" + i, 0, this, i); 371 return out; 372 } 373 374 private void verifyParameters(final Parameter[] parameters) { 375 final int mask = Modifier.FINAL | Modifier.SYNTHETIC | Modifier.MANDATED; 376 377 if (getParameterTypes().length != parameters.length) 378 throw new MalformedParametersException("Wrong number of parameters in MethodParameters attribute"); 379 380 for (Parameter parameter : parameters) { 381 final String name = parameter.getRealName(); 382 final int mods = parameter.getModifiers(); 383 384 if (name != null) { 385 if (name.isEmpty() || name.indexOf('.') != -1 || 386 name.indexOf(';') != -1 || name.indexOf('[') != -1 || 387 name.indexOf('/') != -1) { 388 throw new MalformedParametersException("Invalid parameter name \"" + name + "\""); 389 } 390 } 391 392 if (mods != (mods & mask)) { 393 throw new MalformedParametersException("Invalid parameter modifiers"); 394 } 395 } 396 } 397 398 private Parameter[] privateGetParameters() { 399 // Use tmp to avoid multiple writes to a volatile. 400 Parameter[] tmp = parameters; 401 402 if (tmp == null) { 403 404 // Otherwise, go to the JVM to get them 405 try { 406 tmp = getParameters0(); 407 } catch(IllegalArgumentException e) { 408 // Rethrow ClassFormatErrors 409 throw new MalformedParametersException("Invalid constant pool index"); 410 } 411 412 // If we get back nothing, then synthesize parameters 413 if (tmp == null) { 414 hasRealParameterData = false; 415 tmp = synthesizeAllParams(); 416 } else { 417 hasRealParameterData = true; 418 verifyParameters(tmp); 419 } 420 421 parameters = tmp; 422 } 423 424 return tmp; 425 } 426 427 boolean hasRealParameterData() { 428 // If this somehow gets called before parameters gets 429 // initialized, force it into existence. 430 if (parameters == null) { 431 privateGetParameters(); 432 } 433 return hasRealParameterData; 434 } 435 436 private transient volatile boolean hasRealParameterData; 437 private transient volatile Parameter[] parameters; 438 439 private native Parameter[] getParameters0(); 440 native byte[] getTypeAnnotationBytes0(); 441 442 // Needed by reflectaccess 443 byte[] getTypeAnnotationBytes() { 444 return getTypeAnnotationBytes0(); 445 } 446 447 /** 448 * Returns an array of {@code Class} objects that represent the 449 * types of exceptions declared to be thrown by the underlying 450 * executable represented by this object. Returns an array of 451 * length 0 if the executable declares no exceptions in its {@code 452 * throws} clause. 453 * 454 * @return the exception types declared as being thrown by the 455 * executable this object represents 456 */ 457 public abstract Class<?>[] getExceptionTypes(); 458 459 /** 460 * Returns an array of {@code Type} objects that represent the 461 * exceptions declared to be thrown by this executable object. 462 * Returns an array of length 0 if the underlying executable declares 463 * no exceptions in its {@code throws} clause. 464 * 465 * <p>If an exception type is a type variable or a parameterized 466 * type, it is created. Otherwise, it is resolved. 467 * 468 * @return an array of Types that represent the exception types 469 * thrown by the underlying executable 470 * @throws GenericSignatureFormatError 471 * if the generic method signature does not conform to the format 472 * specified in 473 * <cite>The Java™ Virtual Machine Specification</cite> 474 * @throws TypeNotPresentException if the underlying executable's 475 * {@code throws} clause refers to a non-existent type declaration 476 * @throws MalformedParameterizedTypeException if 477 * the underlying executable's {@code throws} clause refers to a 478 * parameterized type that cannot be instantiated for any reason 479 */ 480 public Type[] getGenericExceptionTypes() { 481 Type[] result; 482 if (hasGenericInformation() && 483 ((result = getGenericInfo().getExceptionTypes()).length > 0)) 484 return result; 485 else 486 return getExceptionTypes(); 487 } 488 489 /** 490 * Returns a string describing this {@code Executable}, including 491 * any type parameters. 492 * @return a string describing this {@code Executable}, including 493 * any type parameters 494 */ 495 public abstract String toGenericString(); 496 497 /** 498 * Returns {@code true} if this executable was declared to take a 499 * variable number of arguments; returns {@code false} otherwise. 500 * 501 * @return {@code true} if an only if this executable was declared 502 * to take a variable number of arguments. 503 */ 504 public boolean isVarArgs() { 505 return (getModifiers() & Modifier.VARARGS) != 0; 506 } 507 508 /** 509 * Returns {@code true} if this executable is a synthetic 510 * construct; returns {@code false} otherwise. 511 * 512 * @return true if and only if this executable is a synthetic 513 * construct as defined by 514 * <cite>The Java™ Language Specification</cite>. 515 * @jls 13.1 The Form of a Binary 516 */ 517 public boolean isSynthetic() { 518 return Modifier.isSynthetic(getModifiers()); 519 } 520 521 /** 522 * Returns an array of arrays of {@code Annotation}s that 523 * represent the annotations on the formal parameters, in 524 * declaration order, of the {@code Executable} represented by 525 * this object. Synthetic and mandated parameters (see 526 * explanation below), such as the outer "this" parameter to an 527 * inner class constructor will be represented in the returned 528 * array. If the executable has no parameters (meaning no formal, 529 * no synthetic, and no mandated parameters), a zero-length array 530 * will be returned. If the {@code Executable} has one or more 531 * parameters, a nested array of length zero is returned for each 532 * parameter with no annotations. The annotation objects contained 533 * in the returned arrays are serializable. The caller of this 534 * method is free to modify the returned arrays; it will have no 535 * effect on the arrays returned to other callers. 536 * 537 * A compiler may add extra parameters that are implicitly 538 * declared in source ("mandated"), as well as parameters that 539 * are neither implicitly nor explicitly declared in source 540 * ("synthetic") to the parameter list for a method. See {@link 541 * java.lang.reflect.Parameter} for more information. 542 * 543 * @see java.lang.reflect.Parameter 544 * @see java.lang.reflect.Parameter#getAnnotations 545 * @return an array of arrays that represent the annotations on 546 * the formal and implicit parameters, in declaration order, of 547 * the executable represented by this object 548 */ 549 public abstract Annotation[][] getParameterAnnotations(); 550 551 Annotation[][] sharedGetParameterAnnotations(Class<?>[] parameterTypes, 552 byte[] parameterAnnotations) { 553 int numParameters = parameterTypes.length; 554 if (parameterAnnotations == null) 555 return new Annotation[numParameters][0]; 556 557 Annotation[][] result = parseParameterAnnotations(parameterAnnotations); 558 559 if (result.length != numParameters) 560 handleParameterNumberMismatch(result.length, numParameters); 561 return result; 562 } 563 564 abstract void 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 = 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 }