summaryrefslogtreecommitdiffstats
path: root/tests/java5
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-09-21 14:59:55 +0000
committeracolyer <acolyer>2005-09-21 14:59:55 +0000
commita39f595c0cdcddf8eac0b99e1918d0578f2dc501 (patch)
tree94865da1d5f277582d9d0720347693cd3b3c258a /tests/java5
parentfc2d08e2ae9d03fb377bd0ed0bd56983af4687a5 (diff)
downloadaspectj-a39f595c0cdcddf8eac0b99e1918d0578f2dc501.tar.gz
aspectj-a39f595c0cdcddf8eac0b99e1918d0578f2dc501.zip
tests and implementation for 108120 - runtime pointcut parsing and matching.
Diffstat (limited to 'tests/java5')
-rw-r--r--tests/java5/ataspectj/annotationGen/PCLib.aj7
-rw-r--r--tests/java5/ataspectj/annotationGen/PointcutsWithParams.aj8
-rw-r--r--tests/java5/ataspectj/annotationGen/RuntimePointcuts.java32
3 files changed, 47 insertions, 0 deletions
diff --git a/tests/java5/ataspectj/annotationGen/PCLib.aj b/tests/java5/ataspectj/annotationGen/PCLib.aj
new file mode 100644
index 000000000..f41c9412f
--- /dev/null
+++ b/tests/java5/ataspectj/annotationGen/PCLib.aj
@@ -0,0 +1,7 @@
+public aspect PCLib {
+
+ public pointcut anyMethodExecution() : execution(* *(..));
+
+ public pointcut joinPointWithStringArg(String s) : args(s);
+
+} \ No newline at end of file
diff --git a/tests/java5/ataspectj/annotationGen/PointcutsWithParams.aj b/tests/java5/ataspectj/annotationGen/PointcutsWithParams.aj
index d6902c9ea..6c1e3b8f3 100644
--- a/tests/java5/ataspectj/annotationGen/PointcutsWithParams.aj
+++ b/tests/java5/ataspectj/annotationGen/PointcutsWithParams.aj
@@ -12,12 +12,20 @@ public aspect PointcutsWithParams {
Class[] params = p1.getParameterTypes();
if (params.length != 1) throw new RuntimeException("expecting one param");
if (!params[0].equals(String.class)) throw new RuntimeException("expecting a String");
+ String[] names = p1.getParameterNames();
+ if (names.length != 1) throw new RuntimeException("expecting one name");
+ if (!names[0].equals("s")) throw new RuntimeException("expecting 's', found " + names[0]);
Pointcut p2 = myType.getPointcut("pc2");
params = p2.getParameterTypes();
if (params.length != 3) throw new RuntimeException("expecting three params");
if (!params[0].equals(Integer.class)) throw new RuntimeException("expecting an Integer");
if (!params[1].equals(Double.class)) throw new RuntimeException("expecting a Double");
if (!params[2].equals(String.class)) throw new RuntimeException("expecting a String");
+ names = p2.getParameterNames();
+ if (names.length != 3) throw new RuntimeException("expecting one name");
+ if (!names[0].equals("i")) throw new RuntimeException("expecting 'i', found '" + names[0] + "'");
+ if (!names[1].equals("d")) throw new RuntimeException("expecting 'd', found '" + names[1] + "'");
+ if (!names[2].equals("s")) throw new RuntimeException("expecting 's', found '" + names[2] + "'");
}
} \ No newline at end of file
diff --git a/tests/java5/ataspectj/annotationGen/RuntimePointcuts.java b/tests/java5/ataspectj/annotationGen/RuntimePointcuts.java
new file mode 100644
index 000000000..8f9e530d5
--- /dev/null
+++ b/tests/java5/ataspectj/annotationGen/RuntimePointcuts.java
@@ -0,0 +1,32 @@
+import org.aspectj.weaver.tools.*;
+import java.lang.reflect.*;
+
+public class RuntimePointcuts {
+
+
+ public static void main(String[] args) throws Exception {
+ PointcutParser parser = new PointcutParser();
+ PointcutExpression pc1 = parser.parsePointcutExpression("PCLib.anyMethodExecution()");
+ PointcutParameter param = parser.createPointcutParameter("s",String.class);
+ PointcutExpression pc2 = parser.parsePointcutExpression("PCLib.joinPointWithStringArg(s)",RuntimePointcuts.class,new PointcutParameter[] {param});
+ Method foo = RuntimePointcuts.class.getDeclaredMethod("foo", new Class[0]);
+ Method bar = RuntimePointcuts.class.getDeclaredMethod("bar",new Class[] {String.class});
+ ShadowMatch fooMatch1 = pc1.matchesMethodExecution(foo);
+ if (!fooMatch1.alwaysMatches()) throw new RuntimeException("fooMatch1 should always match");
+ ShadowMatch fooMatch2 = pc2.matchesMethodExecution(foo);
+ if (!fooMatch2.neverMatches()) throw new RuntimeException("fooMatch2 should never match");
+ ShadowMatch barMatch1 = pc1.matchesMethodExecution(bar);
+ if (!barMatch1.alwaysMatches()) throw new RuntimeException("barMatch1 should always match");
+ ShadowMatch barMatch2 = pc2.matchesMethodExecution(bar);
+ if (!barMatch2.alwaysMatches()) throw new RuntimeException("barMatch2 should always match");
+ JoinPointMatch jpm = barMatch2.matchesJoinPoint(new Object(),new Object(),new Object[] {"hello"});
+ if (!jpm.matches()) throw new RuntimeException("should match at join point");
+ if (!jpm.getParameterBindings()[0].getBinding().toString().equals("hello"))
+ throw new RuntimeException("expecting s to be bound to hello");
+ }
+
+ public void foo() {}
+
+ public void bar(String s) {}
+
+} \ No newline at end of file