| [b]Join Points[/b] | [b]说明[/b] | [b]示例[/b] |
|---|---|---|
| [b]method call[/b] | 函数调用 | 比如调用Log.e(),这是一处JPoint |
| [b]method execution[/b] | 函数执行 | 比如Log.e()的执行内部,是一处Join Points。注意它和method call的区别。method call是调用某个函数的地方。而execution是某个函数执行的内部。 |
| [b]constructor call[/b] | 构造函数调用 | 和method call类似 |
| [b]constructor execution[/b] | 构造函数执行 | 和method execution类似 |
| [b]field get[/b] | 获取某个变量 | 比如读取DemoActivity.debug成员 |
| [b]field set[/b] | 设置某个变量 | 比如设置DemoActivity.debug成员 |
| [b]pre-initialization[/b] | Object在构造函数中做得一些工作。 | |
| [b]initialization[/b] | Object在构造函数中做得工作 | |
| [b]static initialization[/b] | 类初始化 | 比如类的static{} |
| [b]handler[/b] | 异常处理 | 比如try catch(xxx)中,对应catch内的执行 |
| [b]advice execution[/b] | 这个是AspectJ的内容,稍后再说 |
@Before("execution(* android.app.Activity.on**(..))")
public void onActivityMethodBefore(JoinPoint joinPoint) throws Throwable {
}
@Around("execution(* com.xys.aspectjxdemo.MainActivity.testAOP())")
public void onActivityMethodAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
String key = proceedingJoinPoint.getSignature().toString();
Log.d(TAG, "onActivityMethodAroundFirst: " + key);
proceedingJoinPoint.proceed();
Log.d(TAG, "onActivityMethodAroundSecond: " + key);
}
@Retention(RetentionPolicy.CLASS)
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD})
public @interface DebugTrace {
}
public class MainActivity extends AppCompatActivity {
final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
logTest();
}
@DebugTrace
public void logTest() {
Log.e(TAG, "log test");
}
}
@Pointcut("execution(@com.kun.aspectjtest.aspect.DebugTrace * *..*.*(..))")
public void DebugTraceMethod() {}
@Before("DebugTraceMethod()")
public void beforeDebugTraceMethod(JoinPoint joinPoint) throws Throwable {
String key = joinPoint.getSignature().toString();
Log.e(TAG, "beforeDebugTraceMethod: " + key);
}
Call(Before)
Pointcut{
Pointcut Method
}
Call(After)
Pointcut{
execution(Before)
Pointcut Method
execution(After)
}
public class MainActivity extends AppCompatActivity {
final String TAG = MainActivity.class.getSimpleName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
aspectJ1();
aspectJ2();
aspectJ3();
}
public void aspectJTest() {
Log.e(TAG, "execute aspectJTest");
}
public void aspectJ1(){
aspectJTest();
}
public void aspectJ2(){
aspectJTest();
}
public void aspectJ3(){
aspectJTest();
}
}
@Pointcut("(call(* *..aspectJTest()))&&withincode(* *..aspectJ2())")
public void invokeAspectJTestInAspectJ2() {
}
@Before("invokeAspectJTestInAspectJ2()")
public void beforeInvokeaspectJTestInAspectJ2(JoinPoint joinPoint) throws Throwable {
Log.e(TAG, "method:" + getMethodName(joinPoint).getName());
}
private MethodSignature getMethodName(JoinPoint joinPoint) {
if (joinPoint == null) return null;
return (MethodSignature) joinPoint.getSignature();
}
04-02 23:44:40.681 12107-12107/ E/MainActivity: execute aspectJTest 04-02 23:44:40.681 12107-12107/ E/AspectTest: method:aspectJTest 04-02 23:44:40.681 12107-12107/ E/MainActivity: execute aspectJTest 04-02 23:44:40.681 12107-12107/ E/MainActivity: execute aspectJTest
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有