// Prevent the spread of subversive ideas... // AspectJ subverts the principles of abstraction that defines modern OOP. // However, it just happens to be useful for stopping these subversive // activities in the first place. We can write an advice to block the // execution of all other advice. // And along the way, we will use the opportunity to get rid of some other // improper sentiments as well... The leadership will be pleased! import java.io.PrintStream; // PrintStream is the superclass of System.out, suckers! privileged aspect Antisubversion { // Advice to block all advice, except good advice... before(): adviceexecution() && !within(Antisubversion) { throw new Error("AspectJ IS NOT ALLOWED! You will be reported to the authorities for proper indoctrination..."); } // along the way, we'll correct some other subversive thoughts as well... void around(String s):call( void PrintStream+.print*(..)) && args(s,..) { s = s.replaceAll("hell","heck"); s = s.replaceAll("damn","darn"); s = s.replaceAll("123 sucks","123 rocks"); s = s.replaceAll("Liang is the worst","Liang is the best"); proceed(s); } declare precedence: Antisubversion, *; // we have precedence over you... } // SUBVERT THIS! /* The pointcut expression for the around advice captures the first arg passed during the call, which must be a String. However, note that the arguments to the advice are not necessarily the same as the arguments to the called function as identified by the pointcut. For example, if we also want to know the instance of the class that the function is called on we would write something like around(String s, Myclass inst): call(*.print(..)) && args(s,..) && target(inst) However, System.out.print* are static methods, so it doesn't make sense to capture the class instance in this case. */