Here you can find the source of invokeValue(AnnotatedElement element, Class extends Annotation> annotationClass)
Parameter | Description |
---|---|
element | The annotated element. |
annotationClass | The type of the annotation. |
private static <T> Object invokeValue(AnnotatedElement element, Class<? extends Annotation> annotationClass)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { /**/*from w w w .j a v a2s . c o m*/ * Reads the value from the annotation using reflection. * * @param element * The annotated element. * @param annotationClass * The type of the annotation. * @return The value of the annotation or null if the annotation is not * applied. */ private static <T> Object invokeValue(AnnotatedElement element, Class<? extends Annotation> annotationClass) { try { final Annotation annotation = element.getAnnotation(annotationClass); if (annotation != null) { final Method valueMethod = annotationClass.getDeclaredMethod("value"); return valueMethod.invoke(annotation); } } catch (final SecurityException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } }