Java Code Examples for org.aspectj.lang.reflect.FieldSignature

The following examples show how to use org.aspectj.lang.reflect.FieldSignature. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: joinery   Source File: Metrics.java    License: GNU General Public License v3.0 6 votes vote down vote up
private static Annotation getAnnotation(final Signature signature,
                            final Class<? extends Annotation> annotationClass) {
    if (signature instanceof ConstructorSignature) {
        final Constructor<?> ctor = ConstructorSignature.class.cast(signature)
                                .getConstructor();
        return ctor.getAnnotation(annotationClass);
    } else if (signature instanceof MethodSignature) {
        return MethodSignature.class.cast(signature)
                .getMethod()
                .getAnnotation(annotationClass);
    } else if (signature instanceof FieldSignature) {
        return FieldSignature.class.cast(signature)
                .getField()
                .getAnnotation(annotationClass);
    }

    throw new RuntimeException(
            "Unsupported signature type " + signature.getClass().getName()
        );
}
 
Example 2
Source Project: allure1   Source File: AllureParametersAspects.java    License: Apache License 2.0 5 votes vote down vote up
@After("setValueToAnyField() && withParameterAnnotation()")
public void parameterValueChanged(JoinPoint joinPoint) {
    try {
        FieldSignature fieldSignature = (FieldSignature) joinPoint.getSignature();
        Parameter parameter = fieldSignature.getField().getAnnotation(Parameter.class);
        String name = parameter.value().isEmpty() ? fieldSignature.getName() : parameter.value();
        Allure.LIFECYCLE.fire(new AddParameterEvent(name, joinPoint.getArgs()[0].toString()));
    } catch (Exception ignored) {
    }
}