]> source.dussan.org Git - aspectj.git/commitdiff
351592
authoraclement <aclement>
Mon, 11 Jul 2011 20:13:11 +0000 (20:13 +0000)
committeraclement <aclement>
Mon, 11 Jul 2011 20:13:11 +0000 (20:13 +0000)
tests/bugs1612/pr351592/Caching.aj [new file with mode: 0644]
tests/bugs1612/pr351592/Fib.java [new file with mode: 0644]
tests/bugs1612/pr351592/FibCaching.aj [new file with mode: 0644]
tests/bugs1612/pr351592/Test.java [new file with mode: 0644]
tests/bugs1612/pr351592_2/Caching.aj [new file with mode: 0644]
tests/bugs1612/pr351592_2/Fib.java [new file with mode: 0644]
tests/bugs1612/pr351592_2/FibCaching.aj [new file with mode: 0644]
tests/bugs1612/pr351592_2/Test.java [new file with mode: 0644]

diff --git a/tests/bugs1612/pr351592/Caching.aj b/tests/bugs1612/pr351592/Caching.aj
new file mode 100644 (file)
index 0000000..711c3a8
--- /dev/null
@@ -0,0 +1,20 @@
+package caching;
+
+import java.util.HashMap;
+import java.util.Map;
+  
+public  aspect Caching {
+       private Map<Integer,Integer> cache = new HashMap<Integer,Integer>();
+
+       Integer around(Integer a): execution(* Fib.calc*(*)) && args(a) {
+               if(cache.containsKey(a)){
+                       System.out.println("Using cached value for: " + a);
+                       return cache.get(a);
+               }
+               else {
+                       Integer result = proceed(a);
+                       cache.put(a, result);
+                       return result;
+               }
+       }
+}
diff --git a/tests/bugs1612/pr351592/Fib.java b/tests/bugs1612/pr351592/Fib.java
new file mode 100644 (file)
index 0000000..569ca46
--- /dev/null
@@ -0,0 +1,12 @@
+package caching;
+
+public class Fib {
+       public static int calc(int n){
+               if (n < 2) return 1;
+               return calc(n-1) + calc(n-2);
+       }
+       public static Integer calc2(Integer n){
+               if (n < 2) return 1;
+               return calc2(n-1) + calc2(n-2);
+       }
+}
diff --git a/tests/bugs1612/pr351592/FibCaching.aj b/tests/bugs1612/pr351592/FibCaching.aj
new file mode 100644 (file)
index 0000000..609fd1f
--- /dev/null
@@ -0,0 +1,8 @@
+//package caching;
+//
+//public aspect FibCaching extends Caching<Integer,Integer> {
+//     
+//     pointcut cached() : execution(Integer Fib.calc(Integer));
+//     
+//}
+
diff --git a/tests/bugs1612/pr351592/Test.java b/tests/bugs1612/pr351592/Test.java
new file mode 100644 (file)
index 0000000..0712558
--- /dev/null
@@ -0,0 +1,9 @@
+package caching;
+
+public class Test {
+
+       public static void main(String[] args) {
+               System.out.println(Fib.calc(30));
+               System.out.println(Fib.calc2(30));
+       }
+}
diff --git a/tests/bugs1612/pr351592_2/Caching.aj b/tests/bugs1612/pr351592_2/Caching.aj
new file mode 100644 (file)
index 0000000..7a2764e
--- /dev/null
@@ -0,0 +1,22 @@
+package caching;
+
+import java.util.HashMap;
+import java.util.Map;
+  
+public abstract aspect Caching<K,V> {
+       private Map<K,V> cache = new HashMap<K,V>();
+
+       abstract pointcut cached();
+
+       V around(K a): cached() && args(a) {
+               if(cache.containsKey(a)){
+                       System.out.println("Using cached value for: " + a);
+                       return cache.get(a);
+               }
+               else {
+                       V result = proceed(a);
+                       cache.put(a, result);
+                       return result;
+               }
+       }
+}
diff --git a/tests/bugs1612/pr351592_2/Fib.java b/tests/bugs1612/pr351592_2/Fib.java
new file mode 100644 (file)
index 0000000..c786355
--- /dev/null
@@ -0,0 +1,8 @@
+package caching;
+
+public class Fib {
+       public static int calc(int n){
+               if (n < 2) return 1;
+               return calc(n-1) + calc(n-2);
+       }
+}
diff --git a/tests/bugs1612/pr351592_2/FibCaching.aj b/tests/bugs1612/pr351592_2/FibCaching.aj
new file mode 100644 (file)
index 0000000..6e1b1da
--- /dev/null
@@ -0,0 +1,8 @@
+package caching;
+
+public aspect FibCaching extends Caching<Integer,Integer> {
+       
+       pointcut cached() : execution(int Fib.calc(int));
+       
+}
+
diff --git a/tests/bugs1612/pr351592_2/Test.java b/tests/bugs1612/pr351592_2/Test.java
new file mode 100644 (file)
index 0000000..1c9c8d2
--- /dev/null
@@ -0,0 +1,8 @@
+package caching;
+
+public class Test {
+
+       public static void main(String[] args) {
+               System.out.println(Fib.calc(30));
+       }
+}