What about the stack trace ? com.example.InvalidInputException at com.example.ValidationAspect.advice(ValidationAspect.java:35) at com.example.MyClass.setPassword(UserAccount.java:83) at com.example.test.UserAccount.onSubmit(UserAccount.java:42) ... 5 more
@Aspect @DeclarePrecedence("around1, before2, after3, around4, before5, after6") public class OrderingAspect { // Applied to the same pointcut, the result will be // around1 { // before2 // around4 { // before5 // joinpoint // after3 // } // } // after4 } Ordering advices
Compile time checks @Aspect public class CoreCheckAspect { @Pointcut("within(com.example.core.*)") public void withinCorePackage() {} @Pointcut("call(* com.example.ui..*..*(..))") public void callToUIMethod() {} @DeclareError("withinCorePackage() && callToUIMethod()") static final String SEP_OF_CONCERNS = "Core classes should not call UI methods"; }
Mixins @Aspect public class NamedAspect { @DeclareMixin("com.example..*") public static INamed makeNamed(Object namedObject) { return new NamedImpl(namedObject); } } class Foo { public void hello (){ Log.i("Hello", "My name is " + ((INamed) this).getName()); } }
Errors to avoid ◎ Pokeball : gotta catch’em all Pointcuts must be as precise as possible ◎ Octopuss : arms reaching everywher Pointcuts matching unrelated joinpoints ◎ Asp’ception : because aspect is code too Pointcuts matching the advice itself ◎ Aspector Gadget : single responsibility SOLID principles apply to AOP as well