src/share/classes/java/lang/reflect/Method.java

Print this page




  71     private Class[]             exceptionTypes;
  72     private int                 modifiers;
  73     // Generics and annotations support
  74     private transient String              signature;
  75     // generic info repository; lazily initialized
  76     private transient MethodRepository genericInfo;
  77     private byte[]              annotations;
  78     private byte[]              parameterAnnotations;
  79     private byte[]              annotationDefault;
  80     private volatile MethodAccessor methodAccessor;
  81     // For sharing of MethodAccessors. This branching structure is
  82     // currently only two levels deep (i.e., one root Method and
  83     // potentially many Method objects pointing to it.)
  84     private Method              root;
  85 
  86     // More complicated security check cache needed here than for
  87     // Class.newInstance() and Constructor.newInstance()
  88     private Class securityCheckCache;
  89     private Class securityCheckTargetClassCache;
  90 
  91     // Modifiers that can be applied to a method in source code
  92     private static final int LANGUAGE_MODIFIERS =
  93         Modifier.PUBLIC         | Modifier.PROTECTED    | Modifier.PRIVATE |
  94         Modifier.ABSTRACT       | Modifier.STATIC       | Modifier.FINAL   |
  95         Modifier.SYNCHRONIZED   | Modifier.NATIVE;
  96 
  97    // Generics infrastructure
  98 
  99     private String getGenericSignature() {return signature;}
 100 
 101     // Accessor for factory
 102     private GenericsFactory getFactory() {
 103         // create scope and factory
 104         return CoreReflectionFactory.make(this, MethodScope.make(this));
 105     }
 106 
 107     // Accessor for generic info repository
 108     private MethodRepository getGenericInfo() {
 109         // lazily initialize repository if necessary
 110         if (genericInfo == null) {
 111             // create and cache generic info repository
 112             genericInfo = MethodRepository.make(getGenericSignature(),
 113                                                 getFactory());
 114         }
 115         return genericInfo; //return cached repository
 116     }


 391     /**
 392      * Returns a string describing this {@code Method}.  The string is
 393      * formatted as the method access modifiers, if any, followed by
 394      * the method return type, followed by a space, followed by the
 395      * class declaring the method, followed by a period, followed by
 396      * the method name, followed by a parenthesized, comma-separated
 397      * list of the method's formal parameter types. If the method
 398      * throws checked exceptions, the parameter list is followed by a
 399      * space, followed by the word throws followed by a
 400      * comma-separated list of the thrown exception types.
 401      * For example:
 402      * <pre>
 403      *    public boolean java.lang.Object.equals(java.lang.Object)
 404      * </pre>
 405      *
 406      * <p>The access modifiers are placed in canonical order as
 407      * specified by "The Java Language Specification".  This is
 408      * {@code public}, {@code protected} or {@code private} first,
 409      * and then other modifiers in the following order:
 410      * {@code abstract}, {@code static}, {@code final},
 411      * {@code synchronized}, {@code native}.
 412      */
 413     public String toString() {
 414         try {
 415             StringBuffer sb = new StringBuffer();
 416             int mod = getModifiers() & LANGUAGE_MODIFIERS;
 417             if (mod != 0) {
 418                 sb.append(Modifier.toString(mod) + " ");
 419             }
 420             sb.append(Field.getTypeName(getReturnType()) + " ");
 421             sb.append(Field.getTypeName(getDeclaringClass()) + ".");
 422             sb.append(getName() + "(");
 423             Class[] params = parameterTypes; // avoid clone
 424             for (int j = 0; j < params.length; j++) {
 425                 sb.append(Field.getTypeName(params[j]));
 426                 if (j < (params.length - 1))
 427                     sb.append(",");
 428             }
 429             sb.append(")");
 430             Class[] exceptions = exceptionTypes; // avoid clone
 431             if (exceptions.length > 0) {
 432                 sb.append(" throws ");
 433                 for (int k = 0; k < exceptions.length; k++) {
 434                     sb.append(exceptions[k].getName());
 435                     if (k < (exceptions.length - 1))
 436                         sb.append(",");


 456      * If this method was declared to take a variable number of
 457      * arguments, instead of denoting the last parameter as
 458      * "<tt><i>Type</i>[]</tt>", it is denoted as
 459      * "<tt><i>Type</i>...</tt>".
 460      *
 461      * A space is used to separate access modifiers from one another
 462      * and from the type parameters or return type.  If there are no
 463      * type parameters, the type parameter list is elided; if the type
 464      * parameter list is present, a space separates the list from the
 465      * class name.  If the method is declared to throw exceptions, the
 466      * parameter list is followed by a space, followed by the word
 467      * throws followed by a comma-separated list of the generic thrown
 468      * exception types.  If there are no type parameters, the type
 469      * parameter list is elided.
 470      *
 471      * <p>The access modifiers are placed in canonical order as
 472      * specified by "The Java Language Specification".  This is
 473      * {@code public}, {@code protected} or {@code private} first,
 474      * and then other modifiers in the following order:
 475      * {@code abstract}, {@code static}, {@code final},
 476      * {@code synchronized} {@code native}.
 477      *
 478      * @return a string describing this {@code Method},
 479      * include type parameters
 480      *
 481      * @since 1.5
 482      */
 483     public String toGenericString() {
 484         try {
 485             StringBuilder sb = new StringBuilder();
 486             int mod = getModifiers() & LANGUAGE_MODIFIERS;
 487             if (mod != 0) {
 488                 sb.append(Modifier.toString(mod) + " ");
 489             }
 490             TypeVariable<?>[] typeparms = getTypeParameters();
 491             if (typeparms.length > 0) {
 492                 boolean first = true;
 493                 sb.append("<");
 494                 for(TypeVariable<?> typeparm: typeparms) {
 495                     if (!first)
 496                         sb.append(",");
 497                     // Class objects can't occur here; no need to test
 498                     // and call Class.getName().
 499                     sb.append(typeparm.toString());
 500                     first = false;
 501                 }
 502                 sb.append("> ");
 503             }
 504 
 505             Type genRetType = getGenericReturnType();
 506             sb.append( ((genRetType instanceof Class<?>)?




  71     private Class[]             exceptionTypes;
  72     private int                 modifiers;
  73     // Generics and annotations support
  74     private transient String              signature;
  75     // generic info repository; lazily initialized
  76     private transient MethodRepository genericInfo;
  77     private byte[]              annotations;
  78     private byte[]              parameterAnnotations;
  79     private byte[]              annotationDefault;
  80     private volatile MethodAccessor methodAccessor;
  81     // For sharing of MethodAccessors. This branching structure is
  82     // currently only two levels deep (i.e., one root Method and
  83     // potentially many Method objects pointing to it.)
  84     private Method              root;
  85 
  86     // More complicated security check cache needed here than for
  87     // Class.newInstance() and Constructor.newInstance()
  88     private Class securityCheckCache;
  89     private Class securityCheckTargetClassCache;
  90 






  91    // Generics infrastructure
  92 
  93     private String getGenericSignature() {return signature;}
  94 
  95     // Accessor for factory
  96     private GenericsFactory getFactory() {
  97         // create scope and factory
  98         return CoreReflectionFactory.make(this, MethodScope.make(this));
  99     }
 100 
 101     // Accessor for generic info repository
 102     private MethodRepository getGenericInfo() {
 103         // lazily initialize repository if necessary
 104         if (genericInfo == null) {
 105             // create and cache generic info repository
 106             genericInfo = MethodRepository.make(getGenericSignature(),
 107                                                 getFactory());
 108         }
 109         return genericInfo; //return cached repository
 110     }


 385     /**
 386      * Returns a string describing this {@code Method}.  The string is
 387      * formatted as the method access modifiers, if any, followed by
 388      * the method return type, followed by a space, followed by the
 389      * class declaring the method, followed by a period, followed by
 390      * the method name, followed by a parenthesized, comma-separated
 391      * list of the method's formal parameter types. If the method
 392      * throws checked exceptions, the parameter list is followed by a
 393      * space, followed by the word throws followed by a
 394      * comma-separated list of the thrown exception types.
 395      * For example:
 396      * <pre>
 397      *    public boolean java.lang.Object.equals(java.lang.Object)
 398      * </pre>
 399      *
 400      * <p>The access modifiers are placed in canonical order as
 401      * specified by "The Java Language Specification".  This is
 402      * {@code public}, {@code protected} or {@code private} first,
 403      * and then other modifiers in the following order:
 404      * {@code abstract}, {@code static}, {@code final},
 405      * {@code synchronized}, {@code native}, {@code strictfp}.
 406      */
 407     public String toString() {
 408         try {
 409             StringBuffer sb = new StringBuffer();
 410             int mod = getModifiers() & Modifier.methodModifiers();
 411             if (mod != 0) {
 412                 sb.append(Modifier.toString(mod) + " ");
 413             }
 414             sb.append(Field.getTypeName(getReturnType()) + " ");
 415             sb.append(Field.getTypeName(getDeclaringClass()) + ".");
 416             sb.append(getName() + "(");
 417             Class[] params = parameterTypes; // avoid clone
 418             for (int j = 0; j < params.length; j++) {
 419                 sb.append(Field.getTypeName(params[j]));
 420                 if (j < (params.length - 1))
 421                     sb.append(",");
 422             }
 423             sb.append(")");
 424             Class[] exceptions = exceptionTypes; // avoid clone
 425             if (exceptions.length > 0) {
 426                 sb.append(" throws ");
 427                 for (int k = 0; k < exceptions.length; k++) {
 428                     sb.append(exceptions[k].getName());
 429                     if (k < (exceptions.length - 1))
 430                         sb.append(",");


 450      * If this method was declared to take a variable number of
 451      * arguments, instead of denoting the last parameter as
 452      * "<tt><i>Type</i>[]</tt>", it is denoted as
 453      * "<tt><i>Type</i>...</tt>".
 454      *
 455      * A space is used to separate access modifiers from one another
 456      * and from the type parameters or return type.  If there are no
 457      * type parameters, the type parameter list is elided; if the type
 458      * parameter list is present, a space separates the list from the
 459      * class name.  If the method is declared to throw exceptions, the
 460      * parameter list is followed by a space, followed by the word
 461      * throws followed by a comma-separated list of the generic thrown
 462      * exception types.  If there are no type parameters, the type
 463      * parameter list is elided.
 464      *
 465      * <p>The access modifiers are placed in canonical order as
 466      * specified by "The Java Language Specification".  This is
 467      * {@code public}, {@code protected} or {@code private} first,
 468      * and then other modifiers in the following order:
 469      * {@code abstract}, {@code static}, {@code final},
 470      * {@code synchronized}, {@code native}, {@code strictfp}.
 471      *
 472      * @return a string describing this {@code Method},
 473      * include type parameters
 474      *
 475      * @since 1.5
 476      */
 477     public String toGenericString() {
 478         try {
 479             StringBuilder sb = new StringBuilder();
 480             int mod = getModifiers() & Modifier.methodModifiers();
 481             if (mod != 0) {
 482                 sb.append(Modifier.toString(mod) + " ");
 483             }
 484             TypeVariable<?>[] typeparms = getTypeParameters();
 485             if (typeparms.length > 0) {
 486                 boolean first = true;
 487                 sb.append("<");
 488                 for(TypeVariable<?> typeparm: typeparms) {
 489                     if (!first)
 490                         sb.append(",");
 491                     // Class objects can't occur here; no need to test
 492                     // and call Class.getName().
 493                     sb.append(typeparm.toString());
 494                     first = false;
 495                 }
 496                 sb.append("> ");
 497             }
 498 
 499             Type genRetType = getGenericReturnType();
 500             sb.append( ((genRetType instanceof Class<?>)?