summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraclement <aclement>2008-12-10 20:01:33 +0000
committeraclement <aclement>2008-12-10 20:01:33 +0000
commit1c5d4bc331f4273083b547923b122571b8387bfe (patch)
treed4882a33c83596f0cd7b1b942c90178dceaedcf4
parenta84b3a8bb1904644942ed38277960ebd97bd9b51 (diff)
downloadaspectj-1c5d4bc331f4273083b547923b122571b8387bfe.tar.gz
aspectj-1c5d4bc331f4273083b547923b122571b8387bfe.zip
some annotation matching tests
-rw-r--r--org.aspectj.matcher/.classpath1
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/reflect/StandardShadow.java1
-rw-r--r--org.aspectj.matcher/src/org/aspectj/weaver/tools/StandardPointcutParser.java1
-rw-r--r--org.aspectj.matcher/testdata/AnnotatedClass.java11
-rw-r--r--org.aspectj.matcher/testdata/MethodLevelAnnotation.java5
-rw-r--r--org.aspectj.matcher/testdata/SomeAnnotation.java6
-rw-r--r--org.aspectj.matcher/testdata/testdata.jarbin0 -> 1241 bytes
-rw-r--r--org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/CommonAdvancedPointcutExpressionTests.java (renamed from org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/FurtherCommonPointcutExpressionTests.java)55
8 files changed, 70 insertions, 10 deletions
diff --git a/org.aspectj.matcher/.classpath b/org.aspectj.matcher/.classpath
index 856780f91..544d974e4 100644
--- a/org.aspectj.matcher/.classpath
+++ b/org.aspectj.matcher/.classpath
@@ -8,5 +8,6 @@
<classpathentry kind="src" path="/bridge"/>
<classpathentry kind="lib" path="/lib/commons/commons.jar" sourcepath="/lib/commons/commons-src.zip"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="lib" path="testdata/testdata.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/StandardShadow.java b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/StandardShadow.java
index 411ccdd91..9a750481a 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/reflect/StandardShadow.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/reflect/StandardShadow.java
@@ -103,7 +103,6 @@ public class StandardShadow extends Shadow {
ResolvedMember[] members = forType.getDeclaredMethods();
int clinit = -1;
for (int i = 0; i < members.length && clinit == -1; i++) {
- System.out.println(members[i]);
if (members[i].getName().equals("<clinit>")) {
clinit = i;
}
diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/tools/StandardPointcutParser.java b/org.aspectj.matcher/src/org/aspectj/weaver/tools/StandardPointcutParser.java
index eee063f0f..226ae8b78 100644
--- a/org.aspectj.matcher/src/org/aspectj/weaver/tools/StandardPointcutParser.java
+++ b/org.aspectj.matcher/src/org/aspectj/weaver/tools/StandardPointcutParser.java
@@ -237,6 +237,7 @@ public class StandardPointcutParser {
} catch (ParserException pEx) {
throw new IllegalArgumentException(buildUserMessageFromParserException(expression, pEx));
} catch (ReflectionWorld.ReflectionWorldException rwEx) {
+ rwEx.printStackTrace();
throw new IllegalArgumentException(rwEx.getMessage());
}
return pcExpr;
diff --git a/org.aspectj.matcher/testdata/AnnotatedClass.java b/org.aspectj.matcher/testdata/AnnotatedClass.java
new file mode 100644
index 000000000..80dbda413
--- /dev/null
+++ b/org.aspectj.matcher/testdata/AnnotatedClass.java
@@ -0,0 +1,11 @@
+package testdata;
+
+@SomeAnnotation
+public class AnnotatedClass {
+
+ @MethodLevelAnnotation
+ public void annotatedMethod() { }
+
+ public void nonAnnotatedMethod() {
+ }
+}
diff --git a/org.aspectj.matcher/testdata/MethodLevelAnnotation.java b/org.aspectj.matcher/testdata/MethodLevelAnnotation.java
new file mode 100644
index 000000000..2f46dd8ab
--- /dev/null
+++ b/org.aspectj.matcher/testdata/MethodLevelAnnotation.java
@@ -0,0 +1,5 @@
+package testdata;
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface MethodLevelAnnotation {}
diff --git a/org.aspectj.matcher/testdata/SomeAnnotation.java b/org.aspectj.matcher/testdata/SomeAnnotation.java
new file mode 100644
index 000000000..25a4991d6
--- /dev/null
+++ b/org.aspectj.matcher/testdata/SomeAnnotation.java
@@ -0,0 +1,6 @@
+package testdata;
+
+import java.lang.annotation.*;
+
+@Retention(RetentionPolicy.RUNTIME)
+@interface SomeAnnotation {}
diff --git a/org.aspectj.matcher/testdata/testdata.jar b/org.aspectj.matcher/testdata/testdata.jar
new file mode 100644
index 000000000..7bbb39068
--- /dev/null
+++ b/org.aspectj.matcher/testdata/testdata.jar
Binary files differ
diff --git a/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/FurtherCommonPointcutExpressionTests.java b/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/CommonAdvancedPointcutExpressionTests.java
index 03860c008..e5fa8b0c0 100644
--- a/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/FurtherCommonPointcutExpressionTests.java
+++ b/org.aspectj.matcher/testsrc/org/aspectj/matcher/tools/CommonAdvancedPointcutExpressionTests.java
@@ -25,9 +25,17 @@ import org.aspectj.weaver.tools.StandardPointcutParser;
*
* This is based on the Reflection oriented PointcutExpressionTest in the weaver project.
*
+ * TESTDATA. The testdata for these tests is kept in org.aspectj.matcher/testdata. It is a series of .java files that need to be
+ * compiled and available at runtime. Since they are java5 (they include annotations) they cannot be in a source folder for the
+ * project, so they are compiled separately and then jar'd into a testdata.jar file in that folder. This folder is defined to be on
+ * the classpath for org.aspectj.matcher, this enables them to be seen by a simple world that uses the classpath of the matcher
+ * project as the definition of what it can see. Other worlds, for example JDT World, will need to have those types defined in a
+ * project that is accessible in the JDT World instance. Because these tests exercise Java5 matching, the concrete ReflectionWorld
+ * subtype is not defined in here, it is defined in weaver5 (messy, but works well).
+ *
* @author Andy Clement
*/
-public abstract class FurtherCommonPointcutExpressionTests extends TestCase {
+public abstract class CommonAdvancedPointcutExpressionTests extends TestCase {
private World world;
private StandardPointcutParser pointcutParser;
@@ -40,15 +48,44 @@ public abstract class FurtherCommonPointcutExpressionTests extends TestCase {
pointcutParser = StandardPointcutParser.getPointcutParserSupportingAllPrimitives(world);
}
- // public void testResolvingOneType() {
- // // do it via name
- // ResolvedType type = world.resolve("java.lang.String");
- // assertNotNull(type);
- // // do it via signature
- // type = world.resolve(UnresolvedType.forSignature("Ljava/lang/String;"));
- // assertNotNull(type);
- // }
+ public void testResolvingOneType() {
+ assertFalse(world.resolve("testdata.SomeAnnotation").isMissing());
+ assertFalse(world.resolve("testdata.MethodLevelAnnotation").isMissing());
+ assertFalse(world.resolve("testdata.AnnotatedClass").isMissing());
+ }
+
+ public void testTypeLevelAnnotationMatchingWithStaticInitialization01() {
+ StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("staticinitialization(@testdata.SomeAnnotation *)");
+ ResolvedType jlString = world.resolve("java.lang.String");
+ ResolvedType tAnnotatedClass = world.resolve("testdata.AnnotatedClass");
+
+ assertTrue(ex.matchesStaticInitialization(tAnnotatedClass).alwaysMatches());
+ assertTrue(ex.matchesStaticInitialization(jlString).neverMatches());
+ }
+
+ public void testTypeLevelAnnotationMatchingWithExecution01() {
+ StandardPointcutExpression ex = pointcutParser.parsePointcutExpression("execution(* (@testdata.SomeAnnotation *).*(..))");
+ ResolvedType jlString = world.resolve("java.lang.String");
+ ResolvedType tAnnotatedClass = world.resolve("testdata.AnnotatedClass");
+ assertTrue(ex.matchesMethodExecution(getMethod(tAnnotatedClass, "annotatedMethod", "()V")).alwaysMatches());
+ assertTrue(ex.matchesMethodExecution(getMethod(jlString, "valueOf", "(Z)Ljava/lang/String;")).neverMatches());
+ }
+
+ public void testMethodLevelAnnotationMatchingWithExecution01() {
+ StandardPointcutExpression ex = pointcutParser
+ .parsePointcutExpression("execution(@testdata.MethodLevelAnnotation * *(..))");
+ ResolvedType jlString = world.resolve("java.lang.String");
+ ResolvedType tAnnotatedClass = world.resolve("testdata.AnnotatedClass");
+ assertTrue(ex.matchesMethodExecution(getMethod(tAnnotatedClass, "annotatedMethod", "()V")).alwaysMatches());
+ assertTrue(ex.matchesMethodExecution(getMethod(tAnnotatedClass, "nonAnnotatedMethod", "()V")).neverMatches());
+ assertTrue(ex.matchesMethodExecution(getMethod(jlString, "valueOf", "(Z)Ljava/lang/String;")).neverMatches());
+ }
+
//
+ // ResolvedMember stringSplitMethod = getMethod(jlString, "split", "(Ljava/lang/String;I)[Ljava/lang/String;");
+ // ResolvedMember stringValueOfIntMethod = getMethod(jlString, "valueOf", "(I)Ljava/lang/String;");
+ // ResolvedMember listAddMethod = getMethod(juList, "add", "(Ljava/lang/Object;)Z");
+
// public void testResolveTypeAndRetrieveMethod() {
// ResolvedType type = world.resolve("java.lang.String");
// assertNotNull(type);