Java Reflection Annotation getAnnotation(ProceedingJoinPoint pjp, Class annotationClass)

Here you can find the source of getAnnotation(ProceedingJoinPoint pjp, Class annotationClass)

Description

get Annotation

License

Apache License

Declaration

public static <T> T getAnnotation(ProceedingJoinPoint pjp, Class<T> annotationClass) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import java.lang.annotation.Annotation;

public class Main {
    public static <T> T getAnnotation(ProceedingJoinPoint pjp, Class<T> annotationClass) {
        final MethodSignature methodSignature = ((MethodSignature) pjp.getSignature());
        final Annotation[] annotations = methodSignature.getMethod().getAnnotations();
        T lookupAnnotation = null;//from w  w w  .  ja v a 2 s.  c  o  m
        for (Annotation annotation : annotations) {
            if (annotation.annotationType().equals(annotationClass)) {
                lookupAnnotation = (T) annotation;
                break;
            }
        }
        return lookupAnnotation;
    }
}

Related

  1. getAnnotation(Object context, Class annotation)
  2. getAnnotation(Object instance, Class type)
  3. getAnnotation(Object obj, Class annClass)
  4. getAnnotation(Object obj, Class acl)
  5. getAnnotation(Object obj, Class annotation)
  6. getAnnotationAttribute(Annotation a, String attrName)
  7. getAnnotationAttribute(final Annotation anno, final String attrName, final Class attrType)
  8. getAnnotationAttributes(Annotation annotation)
  9. getAnnotationAttributes(Annotation annotation)