diff options
Diffstat (limited to 'tests/bugs1612')
-rw-r--r-- | tests/bugs1612/pr351592/Caching.aj | 20 | ||||
-rw-r--r-- | tests/bugs1612/pr351592/Fib.java | 12 | ||||
-rw-r--r-- | tests/bugs1612/pr351592/FibCaching.aj | 8 | ||||
-rw-r--r-- | tests/bugs1612/pr351592/Test.java | 9 | ||||
-rw-r--r-- | tests/bugs1612/pr351592_2/Caching.aj | 22 | ||||
-rw-r--r-- | tests/bugs1612/pr351592_2/Fib.java | 8 | ||||
-rw-r--r-- | tests/bugs1612/pr351592_2/FibCaching.aj | 8 | ||||
-rw-r--r-- | tests/bugs1612/pr351592_2/Test.java | 8 |
8 files changed, 95 insertions, 0 deletions
diff --git a/tests/bugs1612/pr351592/Caching.aj b/tests/bugs1612/pr351592/Caching.aj new file mode 100644 index 000000000..711c3a82e --- /dev/null +++ b/tests/bugs1612/pr351592/Caching.aj @@ -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 index 000000000..569ca46af --- /dev/null +++ b/tests/bugs1612/pr351592/Fib.java @@ -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 index 000000000..609fd1f06 --- /dev/null +++ b/tests/bugs1612/pr351592/FibCaching.aj @@ -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 index 000000000..071255820 --- /dev/null +++ b/tests/bugs1612/pr351592/Test.java @@ -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 index 000000000..7a2764e55 --- /dev/null +++ b/tests/bugs1612/pr351592_2/Caching.aj @@ -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 index 000000000..c78635557 --- /dev/null +++ b/tests/bugs1612/pr351592_2/Fib.java @@ -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 index 000000000..6e1b1da79 --- /dev/null +++ b/tests/bugs1612/pr351592_2/FibCaching.aj @@ -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 index 000000000..1c9c8d275 --- /dev/null +++ b/tests/bugs1612/pr351592_2/Test.java @@ -0,0 +1,8 @@ +package caching; + +public class Test { + + public static void main(String[] args) { + System.out.println(Fib.calc(30)); + } +} |