List of usage examples for org.aspectj.lang.reflect ConstructorSignature getConstructor
Constructor getConstructor();
From source file:com.github.wnameless.nullproof.aspectj.AbstractNullProofAspect.java
License:Apache License
@Before("constructorOfRejectNullAnnotatedClassWithoutAcceptNull()") public void rejectNullForConsructors(JoinPoint jointPoint) { ConstructorSignature sig = (ConstructorSignature) jointPoint.getSignature(); NullBlocker.blockNulls(sig.getConstructor(), jointPoint.getArgs()); }
From source file:net.sf.oval.guard.GuardAspect2.java
License:Open Source License
@Around("execution((@net.sf.oval.guard.Guarded *).new(..))") public Object allConstructors(final ProceedingJoinPoint thisJoinPoint) throws Throwable { 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 {/*from w w w . ja v a2 s . c o m*/ guard.guardConstructorPre(target, ctor, args); } final Object result = thisJoinPoint.proceed(); // post conditions { guard.guardConstructorPost(target, ctor, args); } return result; }
From source file:net.sf.oval.guard.ParameterNameResolverAspectJImpl.java
License:Open Source License
private void determineParamterNames(final Class<?> clazz) throws IllegalArgumentException, IllegalAccessException { assert clazz != null; for (final Field field : clazz.getDeclaredFields()) { // search for static fields of type JoinPoint.StaticPart if (ReflectionUtils.isStatic(field) && field.getType() == JoinPoint.StaticPart.class) { // access the StaticPart object field.setAccessible(true);//from w w w. j av a 2 s .c om final JoinPoint.StaticPart staticPart = (JoinPoint.StaticPart) field.get(null); if (staticPart == null) { break; } if (staticPart.getSignature() instanceof ConstructorSignature) { final ConstructorSignature sig = (ConstructorSignature) staticPart.getSignature(); final String[] parameterNames = sig.getParameterNames(); final Constructor<?> constr = sig.getConstructor(); if (parameterNames.length > 0) { parameterNamesCache.put(constr, parameterNames); } } else if (staticPart.getSignature() instanceof MethodSignature) { final MethodSignature sig = (MethodSignature) staticPart.getSignature(); final String[] parameterNames = sig.getParameterNames(); final Method method = sig.getMethod(); if (parameterNames.length > 0) { parameterNamesCache.put(method, parameterNames); } } } } }
From source file:org.failearly.ajunit.internal.universe.matcher.ConstructorJoinPointMatcher.java
License:Open Source License
@Override protected boolean doMatchSignature(ConstructorSignature signature, AjJoinPoint ajUnitJoinPoint) { return signature.getConstructor().equals(ajUnitJoinPoint.getConstructor()); }
From source file:org.failearly.ajunit.internal.universe.matcher.ConstructorJoinPointMatcherTest.java
License:Open Source License
private Signature createConstructorSignatureMock(Class<?>... parameterClasses) { final ConstructorSignature constructorSignature = mock(ConstructorSignature.class); when(constructorSignature.getConstructor()).thenReturn(resolveConstructor(parameterClasses)); LOGGER.debug("ConstructorSignature Mock - getConstructor() = {}", constructorSignature.getConstructor()); return constructorSignature; }
From source file:se.jguru.nazgul.tools.validation.aspect.ValidationAspect.java
License:Apache License
/** * Validation aspect, performing its job after calling any constructor except * non-private default ones (having no arguments). * * @param joinPoint The currently executing joinPoint. * @param validatable The validatable instance just created. * @throws InternalStateValidationException if the validation of the validatable failed. *//*from w ww .ja v a 2 s .co m*/ @AfterReturning(value = "anyNonDefaultConstructor(joinPoint, validatable)", argNames = "joinPoint, validatable") public void performValidationAfterCompoundConstructor(final JoinPoint joinPoint, final Validatable validatable) throws InternalStateValidationException { if (log.isDebugEnabled()) { log.debug("Validating instance of type [" + validatable.getClass().getName() + "]"); } if (joinPoint.getStaticPart() == null) { log.warn("Static part of join point was null for validatable of type: " + validatable.getClass().getName(), new IllegalStateException()); return; } // Ignore calling validateInternalState when we execute constructors in // any class but the concrete Validatable class. final ConstructorSignature sig = (ConstructorSignature) joinPoint.getSignature(); final Class<?> constructorDefinitionClass = sig.getConstructor().getDeclaringClass(); if (validatable.getClass() == constructorDefinitionClass) { // Now fire the validateInternalState method. validatable.validateInternalState(); } else { log.debug( "Ignored firing validatable for constructor defined in [" + constructorDefinitionClass.getName() + "] and Validatable of type [" + validatable.getClass().getName() + "]"); } }