Differences
This shows you the differences between two versions of the page.
| research:mao:iiia-examples-fixed [2010/11/24 19:25] – created etanter | research:mao:iiia-examples-fixed [2010/11/24 19:59] (current) – etanter | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Fixed versions ====== | ||
| + | The following example shows the " | ||
| + | |||
| + | < | ||
| + | xpi Jps{ | ||
| + | joinpointtype void JP(int i); | ||
| + | joinpointtype void JPA(int i) extends JP; | ||
| + | joinpointtype void JPB(int i) extends JP; | ||
| + | } | ||
| + | |||
| + | module Base{ | ||
| + | contains C; | ||
| + | from Jps exhibits { | ||
| + | void JPA(int i): call(* foo(..)) && args(i,*); | ||
| + | void JPB(int i): call(* foo(..)) && args(i,*); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | class C { | ||
| + | static void foo(int a, int b) { | ||
| + | System.out.println(" | ||
| + | } | ||
| + | public static void main(String args[]) { | ||
| + | foo(1,2); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | module Aspects { | ||
| + | contains DoubleAspect; | ||
| + | } | ||
| + | |||
| + | aspect DoubleAspect{ | ||
| + | void around Jps.JP(int i) { | ||
| + | System.out.println(System.identityHashCode(thisJoinPoint)); | ||
| + | System.out.println(i); | ||
| + | proceed(i * -1); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | This is the example of looping in the case of " | ||
| + | |||
| + | < | ||
| + | xpi Jps { | ||
| + | joinpointtype void JP(); | ||
| + | } | ||
| + | |||
| + | module Base { | ||
| + | contains Main, A, B; | ||
| + | exhibits from Jps { | ||
| + | void JP(): call(* print*(..)); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | class Main { | ||
| + | public static void main(String args[]) { | ||
| + | new A().foo(); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | class B extends A { | ||
| + | public void foo() { | ||
| + | //some other code here | ||
| + | super.foo(); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | class A { | ||
| + | public void foo() { | ||
| + | System.out.println(" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | module Aspects { | ||
| + | contains Asp; | ||
| + | } | ||
| + | |||
| + | aspect Asp { | ||
| + | after(): Jps.JP() { | ||
| + | new B().foo(); | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | Similar for the case with the " | ||
| + | |||
| + | < | ||
| + | xpi Jps { | ||
| + | | ||
| + | } | ||
| + | |||
| + | |||
| + | module Base { | ||
| + | contains A, Util; | ||
| + | exhibits void JP() : call(* print*(..)); | ||
| + | } | ||
| + | |||
| + | class A { | ||
| + | public static void main(String args[]) { | ||
| + | Util.print(" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | class Util { | ||
| + | public static void print(String s) { | ||
| + | System.out.println(s); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | module Aspect { | ||
| + | contains Asp; | ||
| + | } | ||
| + | |||
| + | aspect Asp { | ||
| + | after JP() { | ||
| + | Util.print(" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </ | ||

