< prev index next >

src/java.base/share/classes/java/lang/reflect/Parameter.java

Print this page




 263      */
 264     public boolean isSynthetic() {
 265         return Modifier.isSynthetic(getModifiers());
 266     }
 267 
 268     /**
 269      * Returns {@code true} if this parameter represents a variable
 270      * argument list; returns {@code false} otherwise.
 271      *
 272      * @return {@code true} if an only if this parameter represents a
 273      * variable argument list.
 274      */
 275     public boolean isVarArgs() {
 276         return executable.isVarArgs() &&
 277             index == executable.getParameterCount() - 1;
 278     }
 279 
 280 
 281     /**
 282      * {@inheritDoc}

 283      * @throws NullPointerException {@inheritDoc}
 284      */

 285     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 286         Objects.requireNonNull(annotationClass);
 287         return annotationClass.cast(declaredAnnotations().get(annotationClass));
 288     }
 289 
 290     /**
 291      * {@inheritDoc}

 292      * @throws NullPointerException {@inheritDoc}
 293      */
 294     @Override
 295     public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
 296         Objects.requireNonNull(annotationClass);
 297 
 298         return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass);
 299     }
 300 
 301     /**
 302      * {@inheritDoc}

 303      */

 304     public Annotation[] getDeclaredAnnotations() {
 305         return executable.getParameterAnnotations()[index];
 306     }
 307 
 308     /**


 309      * @throws NullPointerException {@inheritDoc}
 310      */

 311     public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
 312         // Only annotations on classes are inherited, for all other
 313         // objects getDeclaredAnnotation is the same as
 314         // getAnnotation.
 315         return getAnnotation(annotationClass);
 316     }
 317 
 318     /**


 319      * @throws NullPointerException {@inheritDoc}
 320      */
 321     @Override
 322     public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
 323         // Only annotations on classes are inherited, for all other
 324         // objects getDeclaredAnnotations is the same as
 325         // getAnnotations.
 326         return getAnnotationsByType(annotationClass);
 327     }
 328 
 329     /**
 330      * {@inheritDoc}

 331      */

 332     public Annotation[] getAnnotations() {
 333         return getDeclaredAnnotations();
 334     }
 335 
 336     private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
 337 
 338     private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
 339         if(null == declaredAnnotations) {
 340             declaredAnnotations = new HashMap<>();
 341             for (Annotation a : getDeclaredAnnotations())
 342                 declaredAnnotations.put(a.annotationType(), a);
 343         }
 344         return declaredAnnotations;
 345    }
 346 
 347 }


 263      */
 264     public boolean isSynthetic() {
 265         return Modifier.isSynthetic(getModifiers());
 266     }
 267 
 268     /**
 269      * Returns {@code true} if this parameter represents a variable
 270      * argument list; returns {@code false} otherwise.
 271      *
 272      * @return {@code true} if an only if this parameter represents a
 273      * variable argument list.
 274      */
 275     public boolean isVarArgs() {
 276         return executable.isVarArgs() &&
 277             index == executable.getParameterCount() - 1;
 278     }
 279 
 280 
 281     /**
 282      * {@inheritDoc}
 283      * <p>Any annotation returned by this method is a declaration annotation.
 284      * @throws NullPointerException {@inheritDoc}
 285      */
 286     @Override
 287     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
 288         Objects.requireNonNull(annotationClass);
 289         return annotationClass.cast(declaredAnnotations().get(annotationClass));
 290     }
 291 
 292     /**
 293      * {@inheritDoc}
 294      * <p>Any annotations returned by this method are declaration annotations.
 295      * @throws NullPointerException {@inheritDoc}
 296      */
 297     @Override
 298     public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
 299         Objects.requireNonNull(annotationClass);
 300 
 301         return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass);
 302     }
 303 
 304     /**
 305      * {@inheritDoc}
 306      * <p>Any annotations returned by this method are declaration annotations.
 307      */
 308     @Override
 309     public Annotation[] getDeclaredAnnotations() {
 310         return executable.getParameterAnnotations()[index];
 311     }
 312 
 313     /**
 314      * {@inheritDoc}
 315      * <p>Any annotation returned by this method is a declaration annotation.
 316      * @throws NullPointerException {@inheritDoc}
 317      */
 318     @Override
 319     public <T extends Annotation> T getDeclaredAnnotation(Class<T> annotationClass) {
 320         // Only annotations on classes are inherited, for all other
 321         // objects getDeclaredAnnotation is the same as
 322         // getAnnotation.
 323         return getAnnotation(annotationClass);
 324     }
 325 
 326     /**
 327      * {@inheritDoc}
 328      * <p>Any annotations returned by this method are declaration annotations.
 329      * @throws NullPointerException {@inheritDoc}
 330      */
 331     @Override
 332     public <T extends Annotation> T[] getDeclaredAnnotationsByType(Class<T> annotationClass) {
 333         // Only annotations on classes are inherited, for all other
 334         // objects getDeclaredAnnotations is the same as
 335         // getAnnotations.
 336         return getAnnotationsByType(annotationClass);
 337     }
 338 
 339     /**
 340      * {@inheritDoc}
 341      * <p>Any annotations returned by this method are declaration annotations.
 342      */
 343     @Override
 344     public Annotation[] getAnnotations() {
 345         return getDeclaredAnnotations();
 346     }
 347 
 348     private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
 349 
 350     private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
 351         if(null == declaredAnnotations) {
 352             declaredAnnotations = new HashMap<>();
 353             for (Annotation a : getDeclaredAnnotations())
 354                 declaredAnnotations.put(a.annotationType(), a);
 355         }
 356         return declaredAnnotations;
 357    }
 358 
 359 }
< prev index next >