AspectJ代码修改

一:

 

1 public aspect MyAspect {
2     pointcut move():
3         call(void Point.setX(int));
4     before(): move() {
5         System.out.println("before call Point.setX");
6     }
7 }

AOP后,修改了.class文件,修改后为

1   public void setXY(int x, int y)
2   {
3     System.out.println("Point.setXY is calling...");
4     MyAspect.aspectOf().ajc$before$aspects_MyAspect$1$c0539092(); setX(x);
5     setY(y);
6   }

二:

1 public aspect MyAspect {
2     pointcut move():
3         call(void Point.setX(int));
4     after(): move() {
5         System.out.println("before call Point.setX");
6     }
7 }

修改后:

1   public void setXY(int x, int y)
2   {
3     System.out.println("Point.setXY is calling...");
4     try { setX(x); } catch (Throwable localThrowable) { MyAspect.aspectOf().ajc$after$aspects_MyAspect$1$c0539092(); throw localThrowable; } MyAspect.aspectOf().ajc$after$aspects_MyAspect$1$c0539092();
5     setY(y);
6   }

三:

1 public aspect MyAspect {
2     pointcut move():
3         call(void Point.setX(int));
4     after() returning: move() {
5         System.out.println("before call Point.setX");
6     }
7 }

修改后:

1   public void setXY(int x, int y)
2   {
3     System.out.println("Point.setXY is calling...");
4     setX(x); MyAspect.aspectOf().ajc$afterReturning$aspects_MyAspect$1$c0539092();
5     setY(y);
6   }

四:

1 public aspect MyAspect {
2     pointcut move():
3         call(void Point.setX(int));
4     after() throwing: move() {
5         System.out.println("before call Point.setX");
6     }
7 }

修改后:

1   public void setXY(int x, int y)
2   {
3     System.out.println("Point.setXY is calling...");
4     try { setX(x); } catch (Throwable localThrowable) { MyAspect.aspectOf().ajc$afterThrowing$aspects_MyAspect$1$c0539092(); throw localThrowable; }
5     setY(y);
6   }

 五:

 1 public aspect MyAspect {
 2     pointcut move():
 3         call(* *.setX(int));
 4     pointcut canMove():
 5         within(javaexercise.FigureElement);
 6     
 7     Object around(): move(){
 8         System.out.println("around call Point.setX"
 9         );
10         return proceed();
11     }
12 }

 

修改后:

 1   public void setXY(int x, int y)
 2   {
 3     System.out.println("Point.setXY is calling...");
 4     int i = x; Point localPoint = this; setX_aroundBody1$advice(this, localPoint, i, MyAspect.aspectOf(), null);
 5     setY(y);
 6   }
 7   private static final void setX_aroundBody0(Point paramPoint1, Point paramPoint2, int paramInt)
 8   {
 9     paramPoint2.setX(paramInt);
10   }
11 
12   private static final Object setX_aroundBody1$advice(Point ajc$this, Point target, int x, MyAspect ajc$aspectInstance, AroundClosure ajc$aroundClosure)
13   {
14     System.out.println("around call Point.setX");
15 
16     AroundClosure localAroundClosure = ajc$aroundClosure; setX_aroundBody0(ajc$this, target, x); return null;
17   }

 六:

 1 public aspect MyAspect {
 2     pointcut move():
 3         execution(* *.setX(int));
 4     pointcut canMove():
 5         within(javaexercise.FigureElement);
 6     
 7     Object around(): move(){
 8         System.out.println("around call Point.setX"
 9         );
10         return proceed();
11     }
12 }

修改后:

 1   public void setXY(int x, int y)
 2   {
 3     System.out.println("Point.setXY is calling...");
 4     setX(x);
 5     setY(y);
 6   }
 7   public void setX(int x)
 8   {
 9     int i = x; setX_aroundBody1$advice(this, i, MyAspect.aspectOf(), null);
10   }
11   private static final void setX_aroundBody0(Point ajc$this, int x)
12   {
13     System.out.println("Point.setX is calling...");
14     ajc$this.x = x;
15   }
16 
17   private static final Object setX_aroundBody1$advice(Point ajc$this, int x, MyAspect ajc$aspectInstance, AroundClosure ajc$aroundClosure)
18   {
19     System.out.println("around call Point.setX");
20 
21     AroundClosure localAroundClosure = ajc$aroundClosure; setX_aroundBody0(ajc$this, x); return null;
22   }

七:

 1 public aspect MyAspect {
 2     pointcut move():
 3         execution(* *.setX(int));
 4     pointcut canMove():
 5         within(javaexercise.FigureElement);
 6     
 7     before(): move(){
 8         System.out.println("before call Point.setX");
 9     }
10 }

修改后:

 1   public void setXY(int x, int y)
 2   {
 3     System.out.println("Point.setXY is calling...");
 4     setX(x);
 5     setY(y);
 6   }
 7   public void setX(int x) {
 8     MyAspect.aspectOf().ajc$before$aspects_MyAspect$1$c0539092(); System.out.println("Point.setX is calling...");
 9     this.x = x;
10   }
11 aspect类里
12   @Before(value="move()", argNames="")
13   public void ajc$before$aspects_MyAspect$1$c0539092()
14   {
15     System.out.println("before call Point.setX");
16   }

八:

 1 public aspect MyAspect {
 2     pointcut move():
 3         execution(* *.setX(int));
 4     pointcut canMove():
 5         within(javaexercise.FigureElement);
 6     
 7     after(): move(){
 8         System.out.println("after call Point.setX");
 9     }
10 }

修改后:

 1   public void setXY(int x, int y)
 2   {
 3     System.out.println("Point.setXY is calling...");
 4     setX(x);
 5     setY(y);
 6   }
 7   public void setX(int x) {
 8     try {
 9       System.out.println("Point.setX is calling...");
10       this.x = x; } catch (Throwable localThrowable) {
11       MyAspect.aspectOf().ajc$after$aspects_MyAspect$1$c0539092(); throw localThrowable; } MyAspect.aspectOf().ajc$after$aspects_MyAspect$1$c0539092();
12   }

九:

 1 public aspect MyAspect {
 2     pointcut move():
 3         execution(* *.setX(int));
 4     pointcut canMove():
 5         within(javaexercise.FigureElement);
 6     
 7     after() returning: move(){
 8         System.out.println("after call Point.setX");
 9     }
10 }

修改后:

 1   public void setXY(int x, int y)
 2   {
 3     System.out.println("Point.setXY is calling...");
 4     setX(x);
 5     setY(y);
 6   }
 7   public void setX(int x) {
 8     System.out.println("Point.setX is calling...");
 9     this.x = x;
10     MyAspect.aspectOf().ajc$afterReturning$aspects_MyAspect$1$c0539092();
11   }

十:

 1 public aspect MyAspect {
 2     pointcut move():
 3         execution(* *.setX(int));
 4     pointcut canMove():
 5         within(javaexercise.FigureElement);
 6     
 7     after() throwing: move(){
 8         System.out.println("after call Point.setX");
 9     }
10 }

修改后:

 1   public void setXY(int x, int y)
 2   {
 3     System.out.println("Point.setXY is calling...");
 4     setX(x);
 5     setY(y);
 6   }
 7   public void setX(int x) {
 8     try {
 9       System.out.println("Point.setX is calling...");
10       this.x = x;
11       return; } catch (Throwable localThrowable) { MyAspect.aspectOf().ajc$afterThrowing$aspects_MyAspect$1$c0539092(); } throw localThrowable;
12   }

 十一:

declare soft:Exception:within(javaexercise.FigureFactory);

修改后:

  1 public class FigureFactory
  2 {
  3   public FigureFactory()
  4   {
  5     try
  6     {
  7       try
  8       {
  9         return; } catch (Exception localException1) { if ((localException1 instanceof RuntimeException)) throw localException1; throw new SoftException(localException1); }  } catch (Exception localException2) {
 10       if ((localException2 instanceof RuntimeException)) throw localException2; 
 11     }throw new SoftException(localException2);
 12   }
 13   public static Point makePoint(int x, int y) {
 14     try { try {  } catch (Exception localException) { if ((localException instanceof RuntimeException)) throw localException; throw new SoftException(localException); } Point p = new Point();
 15       try { p.setXY(x, y); } catch (Exception localException1) { if ((localException1 instanceof RuntimeException)) throw localException1; throw new SoftException(localException1); }
 16       return p; } catch (Exception localException2) { if ((localException2 instanceof RuntimeException)) throw localException2;  }
 17     throw new SoftException(localException2);
 18   }
 19 
 20   // ERROR //
 21   public static Line makeLine(int x1, int y1, int x2, int y2)
 22   {
 23     // Byte code:
 24     //   0: new 31    javaexercise/Line
 25     //   3: dup
 26     //   4: invokespecial 33    javaexercise/Line:<init>    ()V
 27     //   7: goto +26 -> 33
 28     //   10: astore 5
 29     //   12: aload 5
 30     //   14: instanceof 57
 31     //   17: ifeq +6 -> 23
 32     //   20: aload 5
 33     //   22: athrow
 34     //   23: new 52    org/aspectj/lang/SoftException
 35     //   26: dup
 36     //   27: aload 5
 37     //   29: invokespecial 55    org/aspectj/lang/SoftException:<init>    (Ljava/lang/Throwable;)V
 38     //   32: athrow
 39     //   33: astore 4
 40     //   35: aload 4
 41     //   37: iload_0
 42     //   38: iload_1
 43     //   39: invokestatic 34    javaexercise/FigureFactory:makePoint    (II)Ljavaexercise/Point;
 44     //   42: goto +26 -> 68
 45     //   45: astore 6
 46     //   47: aload 6
 47     //   49: instanceof 57
 48     //   52: ifeq +6 -> 58
 49     //   55: aload 6
 50     //   57: athrow
 51     //   58: new 52    org/aspectj/lang/SoftException
 52     //   61: dup
 53     //   62: aload 6
 54     //   64: invokespecial 55    org/aspectj/lang/SoftException:<init>    (Ljava/lang/Throwable;)V
 55     //   67: athrow
 56     //   68: invokevirtual 36    javaexercise/Line:setP1    (Ljavaexercise/Point;)V
 57     //   71: goto +26 -> 97
 58     //   74: astore 7
 59     //   76: aload 7
 60     //   78: instanceof 57
 61     //   81: ifeq +6 -> 87
 62     //   84: aload 7
 63     //   86: athrow
 64     //   87: new 52    org/aspectj/lang/SoftException
 65     //   90: dup
 66     //   91: aload 7
 67     //   93: invokespecial 55    org/aspectj/lang/SoftException:<init>    (Ljava/lang/Throwable;)V
 68     //   96: athrow
 69     //   97: aload 4
 70     //   99: iload_2
 71     //   100: iload_3
 72     //   101: invokestatic 34    javaexercise/FigureFactory:makePoint    (II)Ljavaexercise/Point;
 73     //   104: goto +26 -> 130
 74     //   107: astore 8
 75     //   109: aload 8
 76     //   111: instanceof 57
 77     //   114: ifeq +6 -> 120
 78     //   117: aload 8
 79     //   119: athrow
 80     //   120: new 52    org/aspectj/lang/SoftException
 81     //   123: dup
 82     //   124: aload 8
 83     //   126: invokespecial 55    org/aspectj/lang/SoftException:<init>    (Ljava/lang/Throwable;)V
 84     //   129: athrow
 85     //   130: invokevirtual 40    javaexercise/Line:setP2    (Ljavaexercise/Point;)V
 86     //   133: goto +26 -> 159
 87     //   136: astore 9
 88     //   138: aload 9
 89     //   140: instanceof 57
 90     //   143: ifeq +6 -> 149
 91     //   146: aload 9
 92     //   148: athrow
 93     //   149: new 52    org/aspectj/lang/SoftException
 94     //   152: dup
 95     //   153: aload 9
 96     //   155: invokespecial 55    org/aspectj/lang/SoftException:<init>    (Ljava/lang/Throwable;)V
 97     //   158: athrow
 98     //   159: aload 4
 99     //   161: areturn
100     //   162: astore 10
101     //   164: aload 10
102     //   166: instanceof 57
103     //   169: ifeq +6 -> 175
104     //   172: aload 10
105     //   174: athrow
106     //   175: new 52    org/aspectj/lang/SoftException
107     //   178: dup
108     //   179: aload 10
109     //   181: invokespecial 55    org/aspectj/lang/SoftException:<init>    (Ljava/lang/Throwable;)V
110     //   184: athrow
111     //
112     // Exception table:
113     //   from    to    target    type
114     //   0    7    10    java/lang/Exception
115     //   39    42    45    java/lang/Exception
116     //   68    71    74    java/lang/Exception
117     //   101    104    107    java/lang/Exception
118     //   130    133    136    java/lang/Exception
119     //   0    162    162    java/lang/Exception
120   }
121 
122   static
123   {
124     try
125     {
126       return; } catch (Exception localException) { if ((localException instanceof RuntimeException)) throw localException;  }
127     throw new SoftException(localException);
128   }
129 }

//ERROR//是什么意思,难道是没有反编译成功?

十二:

1     before():get(* javaexercise.Point.*){
2         System.out.println("before get");
3     }

修改为:

1   public int getX() {
2     System.out.println("Point.getX is called...");
3     MyAspect.aspectOf().ajc$before$aspects_MyAspect$1$54b470a9(); return this.x;
4   }

十三:

1     before():set(* javaexercise.Point.*){
2         System.out.println("before set");
3     }

修改后:

1   public void setX(int x) {
2     System.out.println("Point.setX is calling...");
3     MyAspect.aspectOf().ajc$before$aspects_MyAspect$1$48139b5(); this.x = x;
4   }

 

posted @ 2014-10-22 22:50  LeonGo  阅读(493)  评论(0编辑  收藏  举报