367 * specified in 368 * <cite>The Java™ Virtual Machine Specification</cite> 369 * @throws TypeNotPresentException if the underlying executable's 370 * {@code throws} clause refers to a non-existent type declaration 371 * @throws MalformedParameterizedTypeException if 372 * the underlying executable's {@code throws} clause refers to a 373 * parameterized type that cannot be instantiated for any reason 374 */ 375 public Type[] getGenericExceptionTypes() { 376 Type[] result; 377 if (hasGenericInformation() && 378 ((result = getGenericInfo().getExceptionTypes()).length > 0)) 379 return result; 380 else 381 return getExceptionTypes(); 382 } 383 384 /** 385 * Returns a string describing this {@code Executable}, including 386 * any type parameters. 387 */ 388 public abstract String toGenericString(); 389 390 /** 391 * Returns {@code true} if this executable was declared to take a 392 * variable number of arguments; returns {@code false} otherwise. 393 * 394 * @return {@code true} if an only if this executable was declared 395 * to take a variable number of arguments. 396 */ 397 public boolean isVarArgs() { 398 return (getModifiers() & Modifier.VARARGS) != 0; 399 } 400 401 /** 402 * Returns {@code true} if this executable is a synthetic 403 * construct; returns {@code false} otherwise. 404 * 405 * @return true if and only if this executable is a synthetic 406 * construct as defined by 479 declaredAnnotations = AnnotationParser.parseAnnotations( 480 getAnnotationBytes(), 481 sun.misc.SharedSecrets.getJavaLangAccess(). 482 getConstantPool(getDeclaringClass()), 483 getDeclaringClass()); 484 } 485 return declaredAnnotations; 486 } 487 488 /** 489 * Returns an AnnotatedType object that represents the use of a type to 490 * specify the return type of the method/constructor represented by this 491 * Executable. 492 * 493 * If this Executable represents a constructor, the AnnotatedType object 494 * represents the type of the constructed object. 495 * 496 * If this Executable represents a method, the AnnotatedType object 497 * represents the use of a type to specify the return type of the method. 498 * 499 * @since 1.8 500 */ 501 public abstract AnnotatedType getAnnotatedReturnType(); 502 503 /* Helper for subclasses of Executable. 504 * 505 * Returns an AnnotatedType object that represents the use of a type to 506 * specify the return type of the method/constructor represented by this 507 * Executable. 508 * 509 * @since 1.8 510 */ 511 AnnotatedType getAnnotatedReturnType0(Type returnType) { 512 return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes(), 513 sun.misc.SharedSecrets.getJavaLangAccess(). 514 getConstantPool(getDeclaringClass()), 515 this, 516 getDeclaringClass(), 517 returnType, 518 TypeAnnotation.TypeAnnotationTarget.METHOD_RETURN); 519 } 520 521 /** 522 * Returns an AnnotatedType object that represents the use of a type to 523 * specify the receiver type of the method/constructor represented by this 524 * Executable. The receiver type of a method/constructor is available only 525 * if the method/constructor declares a formal parameter called 'this'. 526 * 527 * Returns null if this Executable represents a constructor or instance 528 * method that either declares no formal parameter called 'this', or 529 * declares a formal parameter called 'this' with no annotations on its 530 * type. 531 * 532 * Returns null if this Executable represents a static method. 533 * 534 * @since 1.8 535 */ 536 public AnnotatedType getAnnotatedReceiverType() { 537 return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes(), 538 sun.misc.SharedSecrets.getJavaLangAccess(). 539 getConstantPool(getDeclaringClass()), 540 this, 541 getDeclaringClass(), 542 getDeclaringClass(), 543 TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER); 544 } 545 546 /** 547 * Returns an array of AnnotatedType objects that represent the use of 548 * types to specify formal parameter types of the method/constructor 549 * represented by this Executable. The order of the objects in the array 550 * corresponds to the order of the formal parameter types in the 551 * declaration of the method/constructor. 552 * 553 * Returns an array of length 0 if the method/constructor declares no 554 * parameters. 555 * 556 * @since 1.8 557 */ 558 public AnnotatedType[] getAnnotatedParameterTypes() { 559 return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes(), 560 sun.misc.SharedSecrets.getJavaLangAccess(). 561 getConstantPool(getDeclaringClass()), 562 this, 563 getDeclaringClass(), 564 getParameterTypes(), 565 TypeAnnotation.TypeAnnotationTarget.METHOD_FORMAL_PARAMETER); 566 } 567 568 /** 569 * Returns an array of AnnotatedType objects that represent the use of 570 * types to specify the declared exceptions of the method/constructor 571 * represented by this Executable. The order of the objects in the array 572 * corresponds to the order of the exception types in the declaration of 573 * the method/constructor. 574 * 575 * Returns an array of length 0 if the method/constructor declares no 576 * exceptions. 577 * 578 * @since 1.8 579 */ 580 public AnnotatedType[] getAnnotatedExceptionTypes() { 581 return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes(), 582 sun.misc.SharedSecrets.getJavaLangAccess(). 583 getConstantPool(getDeclaringClass()), 584 this, 585 getDeclaringClass(), 586 getGenericExceptionTypes(), 587 TypeAnnotation.TypeAnnotationTarget.THROWS); 588 } 589 590 } | 367 * specified in 368 * <cite>The Java™ Virtual Machine Specification</cite> 369 * @throws TypeNotPresentException if the underlying executable's 370 * {@code throws} clause refers to a non-existent type declaration 371 * @throws MalformedParameterizedTypeException if 372 * the underlying executable's {@code throws} clause refers to a 373 * parameterized type that cannot be instantiated for any reason 374 */ 375 public Type[] getGenericExceptionTypes() { 376 Type[] result; 377 if (hasGenericInformation() && 378 ((result = getGenericInfo().getExceptionTypes()).length > 0)) 379 return result; 380 else 381 return getExceptionTypes(); 382 } 383 384 /** 385 * Returns a string describing this {@code Executable}, including 386 * any type parameters. 387 * @return a string describing this {@code Executable}, including 388 * any type parameters 389 */ 390 public abstract String toGenericString(); 391 392 /** 393 * Returns {@code true} if this executable was declared to take a 394 * variable number of arguments; returns {@code false} otherwise. 395 * 396 * @return {@code true} if an only if this executable was declared 397 * to take a variable number of arguments. 398 */ 399 public boolean isVarArgs() { 400 return (getModifiers() & Modifier.VARARGS) != 0; 401 } 402 403 /** 404 * Returns {@code true} if this executable is a synthetic 405 * construct; returns {@code false} otherwise. 406 * 407 * @return true if and only if this executable is a synthetic 408 * construct as defined by 481 declaredAnnotations = AnnotationParser.parseAnnotations( 482 getAnnotationBytes(), 483 sun.misc.SharedSecrets.getJavaLangAccess(). 484 getConstantPool(getDeclaringClass()), 485 getDeclaringClass()); 486 } 487 return declaredAnnotations; 488 } 489 490 /** 491 * Returns an AnnotatedType object that represents the use of a type to 492 * specify the return type of the method/constructor represented by this 493 * Executable. 494 * 495 * If this Executable represents a constructor, the AnnotatedType object 496 * represents the type of the constructed object. 497 * 498 * If this Executable represents a method, the AnnotatedType object 499 * represents the use of a type to specify the return type of the method. 500 * 501 * @return an object representing the return type of this method 502 * or constructor 503 * @since 1.8 504 */ 505 public abstract AnnotatedType getAnnotatedReturnType(); 506 507 /* Helper for subclasses of Executable. 508 * 509 * Returns an AnnotatedType object that represents the use of a type to 510 * specify the return type of the method/constructor represented by this 511 * Executable. 512 * 513 * @since 1.8 514 */ 515 AnnotatedType getAnnotatedReturnType0(Type returnType) { 516 return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes(), 517 sun.misc.SharedSecrets.getJavaLangAccess(). 518 getConstantPool(getDeclaringClass()), 519 this, 520 getDeclaringClass(), 521 returnType, 522 TypeAnnotation.TypeAnnotationTarget.METHOD_RETURN); 523 } 524 525 /** 526 * Returns an AnnotatedType object that represents the use of a type to 527 * specify the receiver type of the method/constructor represented by this 528 * Executable. The receiver type of a method/constructor is available only 529 * if the method/constructor declares a formal parameter called 'this'. 530 * 531 * Returns null if this Executable represents a constructor or instance 532 * method that either declares no formal parameter called 'this', or 533 * declares a formal parameter called 'this' with no annotations on its 534 * type. 535 * 536 * Returns null if this Executable represents a static method. 537 * 538 * @return an object representing the receiver type of the 539 * method or constructor represented by this Executable 540 * 541 * @since 1.8 542 */ 543 public AnnotatedType getAnnotatedReceiverType() { 544 return TypeAnnotationParser.buildAnnotatedType(getTypeAnnotationBytes(), 545 sun.misc.SharedSecrets.getJavaLangAccess(). 546 getConstantPool(getDeclaringClass()), 547 this, 548 getDeclaringClass(), 549 getDeclaringClass(), 550 TypeAnnotation.TypeAnnotationTarget.METHOD_RECEIVER); 551 } 552 553 /** 554 * Returns an array of AnnotatedType objects that represent the use of 555 * types to specify formal parameter types of the method/constructor 556 * represented by this Executable. The order of the objects in the array 557 * corresponds to the order of the formal parameter types in the 558 * declaration of the method/constructor. 559 * 560 * Returns an array of length 0 if the method/constructor declares no 561 * parameters. 562 * 563 * @return an array of objects representing the types of the 564 * formal parameters of this method or constructor 565 * 566 * @since 1.8 567 */ 568 public AnnotatedType[] getAnnotatedParameterTypes() { 569 return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes(), 570 sun.misc.SharedSecrets.getJavaLangAccess(). 571 getConstantPool(getDeclaringClass()), 572 this, 573 getDeclaringClass(), 574 getParameterTypes(), 575 TypeAnnotation.TypeAnnotationTarget.METHOD_FORMAL_PARAMETER); 576 } 577 578 /** 579 * Returns an array of AnnotatedType objects that represent the use of 580 * types to specify the declared exceptions of the method/constructor 581 * represented by this Executable. The order of the objects in the array 582 * corresponds to the order of the exception types in the declaration of 583 * the method/constructor. 584 * 585 * Returns an array of length 0 if the method/constructor declares no 586 * exceptions. 587 * 588 * @return an array of objects representing the declared 589 * exceptions of this method or constructor 590 * 591 * @since 1.8 592 */ 593 public AnnotatedType[] getAnnotatedExceptionTypes() { 594 return TypeAnnotationParser.buildAnnotatedTypes(getTypeAnnotationBytes(), 595 sun.misc.SharedSecrets.getJavaLangAccess(). 596 getConstantPool(getDeclaringClass()), 597 this, 598 getDeclaringClass(), 599 getGenericExceptionTypes(), 600 TypeAnnotation.TypeAnnotationTarget.THROWS); 601 } 602 603 } |