All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vladmihalcea.util.ReflectionUtils Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
/*
 * Copyright 2013 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.vladmihalcea.util;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.annotation.AnnotationUtils;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

/**
 * ReflectionUtils - ReflectionUtils
 *
 * @author Vlad Mihalcea
 */
public class ReflectionUtils {

    public static  T getAnnotation(ProceedingJoinPoint pjp, Class annotationClass) throws NoSuchMethodException {
        MethodSignature signature = (MethodSignature) pjp.getSignature();
        Method method = signature.getMethod();
        T annotation = AnnotationUtils.findAnnotation(method, annotationClass);

        if (annotation != null) {
            return annotation;
        }

        method = pjp.getTarget().getClass().getMethod(pjp.getSignature().getName(), signature.getParameterTypes());
        return AnnotationUtils.findAnnotation(method, annotationClass);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy