org.aspectj.lang.reflect.ConstructorSignature Java Examples

The following examples show how to use org.aspectj.lang.reflect.ConstructorSignature. 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 File: GuardAspect2.java    From oval with 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 File: Metrics.java    From joinery with 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()
        );
}