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

The following examples show how to use org.aspectj.lang.reflect.ConstructorSignature. 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: oval   Source File: GuardAspect2.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Around("execution((@net.sf.oval.guard.Guarded *).new(..))")
public Object allConstructors(final ProceedingJoinPoint thisJoinPoint) throws Throwable { // CHECKSTYLE:IGNORE IllegalThrow
   final ConstructorSignature signature = (ConstructorSignature) thisJoinPoint.getSignature();

   LOG.debug("aroundConstructor() {1}", signature);

   final Constructor<?> ctor = signature.getConstructor();
   final Object[] args = thisJoinPoint.getArgs();
   final Object target = thisJoinPoint.getTarget();

   // pre conditions
   {
      guard.guardConstructorPre(target, ctor, args);
   }

   final Object result = thisJoinPoint.proceed();

   // post conditions
   {
      guard.guardConstructorPost(target, ctor, args);
   }

   return result;
}
 
Example 2
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()
        );
}