/** * Factory method that creates a new {@link BeforeAdviceMethodInvocationAdapter} instance * using the AspectJ {@link JoinPoint} provided. If the joint point passed in is not * a method joint point, this method throws an {@link IllegalArgumentException}. * * @param aJoinPoint The AspectJ {@link JoinPoint} to use to adapt the advice. * @return The created instance. * @throws IllegalArgumentException If the join point passed in does not involve a method call. */ public static BeforeAdviceMethodInvocationAdapter createFrom(JoinPoint aJoinPoint) { if (aJoinPoint.getSignature() instanceof MethodSignature) { return new BeforeAdviceMethodInvocationAdapter(aJoinPoint.getThis(), ((MethodSignature) aJoinPoint.getSignature()).getMethod(), aJoinPoint.getArgs()); } else if (aJoinPoint.getSignature() instanceof AdviceSignature) { return new BeforeAdviceMethodInvocationAdapter(aJoinPoint.getThis(), ((AdviceSignature) aJoinPoint.getSignature()).getAdvice(), aJoinPoint.getArgs()); } else { throw new IllegalArgumentException("The joint point signature is invalid: expected a MethodSignature or an AdviceSignature but was " + aJoinPoint.getSignature()); } }
assertFalse(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget())); ITestBean thisProxy = (ITestBean) AbstractAspectJAdvice.currentJoinPoint().getThis(); assertTrue(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis())); assertSame(thisProxy, AbstractAspectJAdvice.currentJoinPoint().getThis());
@Override public Object getThis() { return this.joinpoint.getThis(); }
@Override public Object getThis() { return this.joinpoint.getThis(); }
@Aspect public class ExceptionLogging { private static Logger log = null; @Pointcut ("call(* *.*(..))) public void exceptionLogMethods(){ } @AfterThrowing(pointcut="exceptionLogMethods()", throwing="e") public void handleException(Throwable ex, JoinPoint jointPoint) { log = Logger.getLogger(jointPoint.getThis().getClass()); log.debug(jointPoint.getThis().getClass() + ex.getMessage()); } }
@AfterThrowing(pointcut="execution(* com.company.xyz.method())", throwing="exception") public Object invoke(JoinPoint jp, ThrottlingException exception) throws Throwable { return RetryingCallable.newRetryingCallable(new Callable<Object>() { @Override public Object call() throws Exception { MethodSignature signature = (MethodSignature) p.getSignature(); Method method = signature.getMethod(); return method.invoke(jp.getThis(), (Object[]) null); } }, retryPolicy).call();
/** * Logs the call of a method to the generated sequence diagram. * * @param call * the call */ public void message(final JoinPoint call) { this.message(call.getThis(), call); }
@Before("execution(* android.app.Activity.onResume(..))") public void onActivityResume(JoinPoint joinPoint) { AopUtils.updateActiveActivity((Activity) joinPoint.getThis()); }
@Aspect public class TraceAspect { @Pointcut("call(* java.io.PrintStream.*(..))") public void sysoutPointcut() { } @Pointcut("within(demo..*)") public void packagePointcut() { } @Before("sysoutPointcut() && packagePointcut()") public void beforeSysoutCallInsideDemoPackage(JoinPoint joinPoint) { System.out.print(joinPoint.getThis().getClass().getName() + ":" + joinPoint.getSourceLocation().getLine() + " - "); } }
static List<Field> getThisFields(JoinPoint joinPoint) { Object obj = joinPoint.getThis(); return /*obj != null ? getFieldsDeep(obj) : */asList(joinPoint.getSignature().getDeclaringType().getFields()); } static String getActionNameFromTemplate(MethodSignature method, String value,
static String getElementName(JoinPoint joinPoint) { Object obj = joinPoint.getThis(); return obj != null ? obj.toString() : joinPoint.getSignature().getDeclaringType().getSimpleName(); } static List<Field> getThisFields(JoinPoint joinPoint) {
static String getElementName(JoinPoint joinPoint) { Object obj = joinPoint.getThis(); return obj != null ? obj.toString() : joinPoint.getSignature().getDeclaringType().getSimpleName(); } static List<Field> getThisFields(JoinPoint joinPoint) {
/** * Used by InjectomaticAspect. */ @SuppressWarnings({"UnusedDeclaration"}) static void inject(final JoinPoint joinPoint) { if (enabled) { Object target = joinPoint.getThis(); if (log.isTraceEnabled()) { log.trace("Requesting injecting; join-point: {}, target: {}", joinPoint, OID.get(target)); } injecto.inject(target); } else if (log.isTraceEnabled()) { log.trace("Aspect-based injection is disabled; ignoring join-point: {}", joinPoint); } }
static List<Field> getThisFields(JoinPoint joinPoint) { Object obj = joinPoint.getThis(); return obj != null ? getFields(obj) : asList(joinPoint.getSignature().getDeclaringType().getFields()); } static String getActionName(MethodSignature method, String value,
@After("onXXXMethods()") public void callManagerMethods(JoinPoint point) { IShatterHost activity = (IShatterHost) point.getThis(); if (!(activity instanceof Activity)) { return; } String methodName = point.getSignature().getName(); if (activity.toString().equals(oldActivityName) && methodName.equals(oldMethod)) { return; } else { oldActivityName = activity.toString(); oldMethod = methodName; } ShatterManager manager = activity.getShatterManager(); MethodExecutor.scheduleMethod(methodName, manager, point.getArgs()); }
private String getTargetName(final JoinPoint execution) { Object thisObject = execution.getThis(); if (thisObject == null) { StackTraceElement element = StackTraceScanner.find(execution.getSignature()); try { return this.getVarnameFor(Class.forName(element.getClassName())); } catch (ClassNotFoundException ex) { LOG.debug("Classname of " + element + " not found.", ex); return "unknown"; } } else { return this.getVarnameFor(thisObject); } }
public String createTitle(JoinPoint joinPoint) { MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature(); Step step = methodSignature.getMethod().getAnnotation(Step.class); return step == null ? "" : getTitle(step.value(), methodSignature.getName(), joinPoint.getThis(), joinPoint.getArgs()); }
static MapArray<String, Object> classFields(JoinPoint joinPoint) { return new MapArray<>(getThisFields(joinPoint), Field::getName, value -> getValueField(value, joinPoint.getThis())); }
static MapArray<String, Object> classFields(JoinPoint joinPoint) { return toMap(()->new MapArray<>(getThisFields(joinPoint), Field::getName, value -> getValueField(value, joinPoint.getThis()))); }
private static void processNewPage(JoinPoint joinPoint) { getWindows(); Object element = joinPoint.getThis(); if (element != null) { // TODO support static pages WebPage page = getPage(element); String currentPage = getCurrentPage(); if (currentPage != null && page != null) { if (!currentPage.equals(page.getName())) { setCurrentPage(page); BEFORE_NEW_PAGE.execute(page); } else BEFORE_EACH_PAGE.execute(page); } } }