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

Print this page




 209      *     the type variables declared by this generic declaration
 210      * @throws GenericSignatureFormatError if the generic
 211      *     signature of this generic declaration does not conform to
 212      *     the format specified in
 213      *     <cite>The Java&trade; Virtual Machine Specification</cite>
 214      */
 215     public abstract TypeVariable<?>[] getTypeParameters();
 216 
 217     /**
 218      * Returns an array of {@code Class} objects that represent the formal
 219      * parameter types, in declaration order, of the executable
 220      * represented by this object.  Returns an array of length
 221      * 0 if the underlying executable takes no parameters.
 222      *
 223      * @return the parameter types for the executable this object
 224      * represents
 225      */
 226     public abstract Class<?>[] getParameterTypes();
 227 
 228     /**












 229      * Returns an array of {@code Type} objects that represent the formal
 230      * parameter types, in declaration order, of the executable represented by
 231      * this object. Returns an array of length 0 if the
 232      * underlying executable takes no parameters.
 233      *
 234      * <p>If a formal parameter type is a parameterized type,
 235      * the {@code Type} object returned for it must accurately reflect
 236      * the actual type parameters used in the source code.
 237      *
 238      * <p>If a formal parameter type is a type variable or a parameterized
 239      * type, it is created. Otherwise, it is resolved.
 240      *
 241      * @return an array of {@code Type}s that represent the formal
 242      *     parameter types of the underlying executable, in declaration order
 243      * @throws GenericSignatureFormatError
 244      *     if the generic method signature does not conform to the format
 245      *     specified in
 246      *     <cite>The Java&trade; Virtual Machine Specification</cite>
 247      * @throws TypeNotPresentException if any of the parameter
 248      *     types of the underlying executable refers to a non-existent type
 249      *     declaration
 250      * @throws MalformedParameterizedTypeException if any of
 251      *     the underlying executable's parameter types refer to a parameterized
 252      *     type that cannot be instantiated for any reason
 253      */
 254     public Type[] getGenericParameterTypes() {
 255         if (hasGenericInformation())
 256             return getGenericInfo().getParameterTypes();
 257         else
 258             return getParameterTypes();
 259     }
 260 
 261     /**























































 262      * Returns an array of {@code Class} objects that represent the
 263      * types of exceptions declared to be thrown by the underlying
 264      * executable represented by this object.  Returns an array of
 265      * length 0 if the executable declares no exceptions in its {@code
 266      * throws} clause.
 267      *
 268      * @return the exception types declared as being thrown by the
 269      * executable this object represents
 270      */
 271     public abstract Class<?>[] getExceptionTypes();
 272 
 273     /**
 274      * Returns an array of {@code Type} objects that represent the
 275      * exceptions declared to be thrown by this executable object.
 276      * Returns an array of length 0 if the underlying executable declares
 277      * no exceptions in its {@code throws} clause.
 278      *
 279      * <p>If an exception type is a type variable or a parameterized
 280      * type, it is created. Otherwise, it is resolved.
 281      *


 386 
 387     /**
 388      * {@inheritDoc}
 389      */
 390     public Annotation[] getDeclaredAnnotations()  {
 391         return AnnotationSupport.unpackToArray(declaredAnnotations());
 392     }
 393 
 394     private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
 395 
 396     private synchronized  Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
 397         if (declaredAnnotations == null) {
 398             declaredAnnotations = AnnotationParser.parseAnnotations(
 399                 getAnnotationBytes(),
 400                 sun.misc.SharedSecrets.getJavaLangAccess().
 401                 getConstantPool(getDeclaringClass()),
 402                 getDeclaringClass());
 403         }
 404         return declaredAnnotations;
 405     }

 406 }


 209      *     the type variables declared by this generic declaration
 210      * @throws GenericSignatureFormatError if the generic
 211      *     signature of this generic declaration does not conform to
 212      *     the format specified in
 213      *     <cite>The Java&trade; Virtual Machine Specification</cite>
 214      */
 215     public abstract TypeVariable<?>[] getTypeParameters();
 216 
 217     /**
 218      * Returns an array of {@code Class} objects that represent the formal
 219      * parameter types, in declaration order, of the executable
 220      * represented by this object.  Returns an array of length
 221      * 0 if the underlying executable takes no parameters.
 222      *
 223      * @return the parameter types for the executable this object
 224      * represents
 225      */
 226     public abstract Class<?>[] getParameterTypes();
 227 
 228     /**
 229      * Returns the number of formal parameters (including any
 230      * synthetic or synthesized parameters) for the executable
 231      * represented by this object.
 232      *
 233      * @return The number of formal parameters for the executable this
 234      * object represents
 235      */
 236     public int getParameterCount() {
 237         throw new AbstractMethodError();
 238     }
 239 
 240     /**
 241      * Returns an array of {@code Type} objects that represent the formal
 242      * parameter types, in declaration order, of the executable represented by
 243      * this object. Returns an array of length 0 if the
 244      * underlying executable takes no parameters.
 245      *
 246      * <p>If a formal parameter type is a parameterized type,
 247      * the {@code Type} object returned for it must accurately reflect
 248      * the actual type parameters used in the source code.
 249      *
 250      * <p>If a formal parameter type is a type variable or a parameterized
 251      * type, it is created. Otherwise, it is resolved.
 252      *
 253      * @return an array of {@code Type}s that represent the formal
 254      *     parameter types of the underlying executable, in declaration order
 255      * @throws GenericSignatureFormatError
 256      *     if the generic method signature does not conform to the format
 257      *     specified in
 258      *     <cite>The Java&trade; Virtual Machine Specification</cite>
 259      * @throws TypeNotPresentException if any of the parameter
 260      *     types of the underlying executable refers to a non-existent type
 261      *     declaration
 262      * @throws MalformedParameterizedTypeException if any of
 263      *     the underlying executable's parameter types refer to a parameterized
 264      *     type that cannot be instantiated for any reason
 265      */
 266     public Type[] getGenericParameterTypes() {
 267         if (hasGenericInformation())
 268             return getGenericInfo().getParameterTypes();
 269         else
 270             return getParameterTypes();
 271     }
 272 
 273     /**
 274      * Returns an array of {@code Parameter} objects that represent
 275      * all the parameters to the underlying executable represented by
 276      * this object.  Returns an array of length 0 if the executable
 277      * has no parameters.
 278      *
 279      * @return an array of {@code Parameter} objects representing all
 280      * the parameters to the executable this object represents
 281      */
 282     public Parameter[] getParameters() {
 283         // TODO: This may eventually need to be guarded by security
 284         // mechanisms similar to those in Field, Method, etc.
 285         //
 286         // Need to copy the cached array to prevent users from messing
 287         // with it.  Since parameters are immutable, we can
 288         // shallow-copy.
 289         return privateGetParameters().clone();
 290     }
 291 
 292     private Parameter[] synthesizeAllParams() {
 293         final int realparams = getParameterCount();
 294         final Parameter[] out = new Parameter[realparams];
 295         for (int i = 0; i < realparams; i++)
 296             // TODO: is there a way to synthetically derive the
 297             // modifiers?  Probably not in the general case, since
 298             // we'd have no way of knowing about them, but there
 299             // may be specific cases.
 300             out[i] = new Parameter("arg" + i, 0, this, i);
 301         return out;
 302     }
 303 
 304     private Parameter[] privateGetParameters() {
 305         // Use tmp to avoid multiple writes to a volatile.
 306         Parameter[] tmp = parameters;
 307 
 308         if (tmp == null) {
 309 
 310             // Otherwise, go to the JVM to get them
 311             tmp = getParameters0();
 312 
 313             // If we get back nothing, then synthesize parameters
 314             if (tmp == null)
 315                 tmp = synthesizeAllParams();
 316 
 317             parameters = tmp;
 318 
 319         }
 320 
 321         return tmp;
 322     }
 323 
 324     private transient volatile Parameter[] parameters;
 325 
 326     private native Parameter[] getParameters0();
 327 
 328     /**
 329      * Returns an array of {@code Class} objects that represent the
 330      * types of exceptions declared to be thrown by the underlying
 331      * executable represented by this object.  Returns an array of
 332      * length 0 if the executable declares no exceptions in its {@code
 333      * throws} clause.
 334      *
 335      * @return the exception types declared as being thrown by the
 336      * executable this object represents
 337      */
 338     public abstract Class<?>[] getExceptionTypes();
 339 
 340     /**
 341      * Returns an array of {@code Type} objects that represent the
 342      * exceptions declared to be thrown by this executable object.
 343      * Returns an array of length 0 if the underlying executable declares
 344      * no exceptions in its {@code throws} clause.
 345      *
 346      * <p>If an exception type is a type variable or a parameterized
 347      * type, it is created. Otherwise, it is resolved.
 348      *


 453 
 454     /**
 455      * {@inheritDoc}
 456      */
 457     public Annotation[] getDeclaredAnnotations()  {
 458         return AnnotationSupport.unpackToArray(declaredAnnotations());
 459     }
 460 
 461     private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
 462 
 463     private synchronized  Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
 464         if (declaredAnnotations == null) {
 465             declaredAnnotations = AnnotationParser.parseAnnotations(
 466                 getAnnotationBytes(),
 467                 sun.misc.SharedSecrets.getJavaLangAccess().
 468                 getConstantPool(getDeclaringClass()),
 469                 getDeclaringClass());
 470         }
 471         return declaredAnnotations;
 472     }
 473 
 474 }