aboutsummaryrefslogtreecommitdiffstats
path: root/tests/java5/pertypewithin
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-03-09 14:10:39 +0000
committeracolyer <acolyer>2005-03-09 14:10:39 +0000
commit82fa47384f23d3ed0cf20b531fff947182b08a84 (patch)
treef984dac2428b08762c4a6d859e8e321f47fb19c8 /tests/java5/pertypewithin
parent69845b3545539b7961e8b4a3ef4a5ac416a305bb (diff)
downloadaspectj-82fa47384f23d3ed0cf20b531fff947182b08a84.tar.gz
aspectj-82fa47384f23d3ed0cf20b531fff947182b08a84.zip
completing the set of AJDK examples coded up as test cases
Diffstat (limited to 'tests/java5/pertypewithin')
-rw-r--r--tests/java5/pertypewithin/ajdk/AJDKExamples.aj34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/java5/pertypewithin/ajdk/AJDKExamples.aj b/tests/java5/pertypewithin/ajdk/AJDKExamples.aj
new file mode 100644
index 000000000..433270cf4
--- /dev/null
+++ b/tests/java5/pertypewithin/ajdk/AJDKExamples.aj
@@ -0,0 +1,34 @@
+import java.util.*;
+public aspect AJDKExamples pertypewithin(org.xyz..*) {
+
+ // use WeakHashMap for auto-garbage collection of keys
+ private Map<Object,Boolean> instances = new WeakHashMap<Object,Boolean>();
+
+ after(Object o) returning() : execution(new(..)) && this(o) {
+ instances.put(o,true);
+ }
+
+ public Set<?> getInstances() {
+ return instances.keySet();
+ }
+
+
+ public static void main(String[] args) {
+ A a = new A();
+ A a2 = new A();
+ B b = new B();
+ B b2 = new B();
+ B b3 = new B();
+
+ System.out.println(AJDKExamples.hasAspect(A.class));
+ System.out.println(AJDKExamples.hasAspect(B.class));
+ Set<?> as = AJDKExamples.aspectOf(A.class).getInstances();
+ Set<?> bs = AJDKExamples.aspectOf(B.class).getInstances();
+ System.out.println("There are " + as.size() + " As");
+ System.out.println("There are " + bs.size() + " Bs");
+ }
+}
+
+class A {}
+
+class B {} \ No newline at end of file