summaryrefslogtreecommitdiffstats
path: root/weaver/testsrc
diff options
context:
space:
mode:
authoraclement <aclement>2008-09-04 23:29:49 +0000
committeraclement <aclement>2008-09-04 23:29:49 +0000
commit31a415662a0ffa6f0425e5096e04fc1902726c9e (patch)
tree0a00982ef69f27c0dbafb5e8103c0f11a0126537 /weaver/testsrc
parentec9ebe73bbce1ac45e064be0ebd287b3563d4835 (diff)
downloadaspectj-31a415662a0ffa6f0425e5096e04fc1902726c9e.tar.gz
aspectj-31a415662a0ffa6f0425e5096e04fc1902726c9e.zip
breaking the weaver apart
Diffstat (limited to 'weaver/testsrc')
-rw-r--r--weaver/testsrc/org/aspectj/weaver/TestUtils.java47
-rw-r--r--weaver/testsrc/org/aspectj/weaver/bcel/AfterThrowingWeaveTestCase.java28
-rw-r--r--weaver/testsrc/org/aspectj/weaver/bcel/BcelTestUtils.java65
-rw-r--r--weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java437
-rw-r--r--weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java217
-rw-r--r--weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java699
6 files changed, 730 insertions, 763 deletions
diff --git a/weaver/testsrc/org/aspectj/weaver/TestUtils.java b/weaver/testsrc/org/aspectj/weaver/TestUtils.java
index 9be8f50bb..456cd2bfc 100644
--- a/weaver/testsrc/org/aspectj/weaver/TestUtils.java
+++ b/weaver/testsrc/org/aspectj/weaver/TestUtils.java
@@ -15,11 +15,6 @@ import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
-import org.aspectj.weaver.bcel.BcelAdvice;
-import org.aspectj.weaver.patterns.FormalBinding;
-import org.aspectj.weaver.patterns.Pointcut;
-import org.aspectj.weaver.patterns.SimpleScope;
-
public class TestUtils {
private static final String[] ZERO_STRINGS = new String[0];
@@ -289,7 +284,7 @@ public class TestUtils {
return MemberImpl.method(declaringTy, mods, returnTy, name, UnresolvedType.forNames(paramTypeNames));
}
- private static String[] parseIds(String str) {
+ public static String[] parseIds(String str) {
if (str.length() == 0)
return ZERO_STRINGS;
List l = new ArrayList();
@@ -306,44 +301,4 @@ public class TestUtils {
return (String[]) l.toArray(new String[l.size()]);
}
- /**
- * Moved from BcelWorld to here
- *
- * Parse a string into advice.
- *
- * <blockquote>
- *
- * <pre>
- * Kind ( Id , ... ) : Pointcut -&gt; MethodSignature
- * </pre>
- *
- * </blockquote>
- */
- public static Advice shadowMunger(World w, String str, int extraFlag) {
- str = str.trim();
- int start = 0;
- int i = str.indexOf('(');
- AdviceKind kind = AdviceKind.stringToKind(str.substring(start, i));
- start = ++i;
- i = str.indexOf(')', i);
- String[] ids = parseIds(str.substring(start, i).trim());
- // start = ++i;
-
- i = str.indexOf(':', i);
- start = ++i;
- i = str.indexOf("->", i);
- Pointcut pointcut = Pointcut.fromString(str.substring(start, i).trim());
- Member m = TestUtils.methodFromString(str.substring(i + 2, str.length()).trim());
-
- // now, we resolve
- UnresolvedType[] types = m.getParameterTypes();
- FormalBinding[] bindings = new FormalBinding[ids.length];
- for (int j = 0, len = ids.length; j < len; j++) {
- bindings[j] = new FormalBinding(types[j], ids[j], j, 0, 0);
- }
-
- Pointcut p = pointcut.resolve(new SimpleScope(w, bindings));
-
- return new BcelAdvice(kind, p, m, extraFlag, 0, 0, null, null);
- }
}
diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/AfterThrowingWeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/AfterThrowingWeaveTestCase.java
index 8e2a54042..b0c3f04ce 100644
--- a/weaver/testsrc/org/aspectj/weaver/bcel/AfterThrowingWeaveTestCase.java
+++ b/weaver/testsrc/org/aspectj/weaver/bcel/AfterThrowingWeaveTestCase.java
@@ -10,12 +10,13 @@
* PARC initial implementation
* ******************************************************************/
-
package org.aspectj.weaver.bcel;
import java.io.IOException;
-import org.aspectj.weaver.*;
+import org.aspectj.weaver.Advice;
+import org.aspectj.weaver.ResolvedType;
+import org.aspectj.weaver.ShadowMunger;
public class AfterThrowingWeaveTestCase extends WeaveTestCase {
{
@@ -25,19 +26,20 @@ public class AfterThrowingWeaveTestCase extends WeaveTestCase {
public AfterThrowingWeaveTestCase(String name) {
super(name);
}
-
+
public void testAfterThrowing() throws IOException {
weaveTest(getStandardTargets(), "AfterThrowing", makeAdviceAll("afterThrowing"));
}
- public void testAfterThrowingParam() throws IOException {
- BcelWorld world = new BcelWorld();
-
- ShadowMunger myMunger =
- TestUtils.shadowMunger(world,"afterThrowing(): get(* *.out) -> static void Aspect.ajc_afterThrowing_field_get(java.lang.Throwable)",
- Advice.ExtraArgument);
- ShadowMunger cm = myMunger.concretize(ResolvedType.MISSING, world, null);
-
- weaveTest(getStandardTargets(), "AfterThrowingParam", cm);
- }
+
+ public void testAfterThrowingParam() throws IOException {
+ BcelWorld world = new BcelWorld();
+
+ ShadowMunger myMunger = BcelTestUtils.shadowMunger(world,
+ "afterThrowing(): get(* *.out) -> static void Aspect.ajc_afterThrowing_field_get(java.lang.Throwable)",
+ Advice.ExtraArgument);
+ ShadowMunger cm = myMunger.concretize(ResolvedType.MISSING, world, null);
+
+ weaveTest(getStandardTargets(), "AfterThrowingParam", cm);
+ }
}
diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/BcelTestUtils.java b/weaver/testsrc/org/aspectj/weaver/bcel/BcelTestUtils.java
new file mode 100644
index 000000000..bc9f47a85
--- /dev/null
+++ b/weaver/testsrc/org/aspectj/weaver/bcel/BcelTestUtils.java
@@ -0,0 +1,65 @@
+/* *******************************************************************
+ * Copyright (c) 2008 Contributors
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andy Clement initial implementation
+ * ******************************************************************/
+package org.aspectj.weaver.bcel;
+
+import org.aspectj.weaver.Advice;
+import org.aspectj.weaver.AdviceKind;
+import org.aspectj.weaver.Member;
+import org.aspectj.weaver.TestUtils;
+import org.aspectj.weaver.UnresolvedType;
+import org.aspectj.weaver.World;
+import org.aspectj.weaver.patterns.FormalBinding;
+import org.aspectj.weaver.patterns.Pointcut;
+import org.aspectj.weaver.patterns.SimpleScope;
+
+public class BcelTestUtils {
+ /**
+ * Moved from BcelWorld to here
+ *
+ * Parse a string into advice.
+ *
+ * <blockquote>
+ *
+ * <pre>
+ * Kind ( Id , ... ) : Pointcut -&gt; MethodSignature
+ * </pre>
+ *
+ * </blockquote>
+ */
+ public static Advice shadowMunger(World w, String str, int extraFlag) {
+ str = str.trim();
+ int start = 0;
+ int i = str.indexOf('(');
+ AdviceKind kind = AdviceKind.stringToKind(str.substring(start, i));
+ start = ++i;
+ i = str.indexOf(')', i);
+ String[] ids = TestUtils.parseIds(str.substring(start, i).trim());
+ // start = ++i;
+
+ i = str.indexOf(':', i);
+ start = ++i;
+ i = str.indexOf("->", i);
+ Pointcut pointcut = Pointcut.fromString(str.substring(start, i).trim());
+ Member m = TestUtils.methodFromString(str.substring(i + 2, str.length()).trim());
+
+ // now, we resolve
+ UnresolvedType[] types = m.getParameterTypes();
+ FormalBinding[] bindings = new FormalBinding[ids.length];
+ for (int j = 0, len = ids.length; j < len; j++) {
+ bindings[j] = new FormalBinding(types[j], ids[j], j, 0, 0);
+ }
+
+ Pointcut p = pointcut.resolve(new SimpleScope(w, bindings));
+
+ return new BcelAdvice(kind, p, m, extraFlag, 0, 0, null, null);
+ }
+}
diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java
index 05ff1257e..656020656 100644
--- a/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java
+++ b/weaver/testsrc/org/aspectj/weaver/bcel/WeaveTestCase.java
@@ -10,19 +10,32 @@
* PARC initial implementation
* ******************************************************************/
-
package org.aspectj.weaver.bcel;
-import java.io.*;
-import java.util.*;
-import junit.framework.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
import org.aspectj.apache.bcel.Constants;
-import org.aspectj.apache.bcel.generic.*;
-import org.aspectj.weaver.*;
-import org.aspectj.weaver.patterns.*;
+import org.aspectj.apache.bcel.generic.InstructionFactory;
+import org.aspectj.apache.bcel.generic.InstructionList;
+import org.aspectj.apache.bcel.generic.InvokeInstruction;
+import org.aspectj.apache.bcel.generic.Type;
import org.aspectj.testing.util.TestUtil;
import org.aspectj.util.FileUtil;
+import org.aspectj.weaver.Advice;
+import org.aspectj.weaver.BcweaverTests;
+import org.aspectj.weaver.ShadowMunger;
+import org.aspectj.weaver.patterns.FormalBinding;
+import org.aspectj.weaver.patterns.PerClause;
+import org.aspectj.weaver.patterns.Pointcut;
+import org.aspectj.weaver.patterns.SimpleScope;
public abstract class WeaveTestCase extends TestCase {
@@ -30,92 +43,82 @@ public abstract class WeaveTestCase extends TestCase {
public boolean runTests = true;
public boolean behave15 = false;
- File outDir;
- String outDirPath;
-
+ File outDir;
+ String outDirPath;
+
public BcelWorld world = new BcelWorld();
- {
- world.addPath(classDir);
- // Some of the tests in here rely on comparing output from dumping the delegates - if
- // we are using ASM delegates we don't know the names of parameters (they are irrelevant...)
- // and are missing from the dumping of asm delegates. This switch ensures we
- // continue to use BCEL for these tests.
-// world.setFastDelegateSupport(false);
- }
-
- public WeaveTestCase(String name) {
- super(name);
- }
-
- public void setUp() {
- outDir = BcweaverTests.getOutdir();
- outDirPath = outDir.getAbsolutePath();
- }
- public void tearDown() throws Exception {
- super.tearDown();
- BcweaverTests.removeOutDir();
- outDir = null;
- outDirPath = null;
- }
+ {
+ world.addPath(classDir);
+ // Some of the tests in here rely on comparing output from dumping the delegates - if
+ // we are using ASM delegates we don't know the names of parameters (they are irrelevant...)
+ // and are missing from the dumping of asm delegates. This switch ensures we
+ // continue to use BCEL for these tests.
+ // world.setFastDelegateSupport(false);
+ }
+
+ public WeaveTestCase(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ outDir = BcweaverTests.getOutdir();
+ outDirPath = outDir.getAbsolutePath();
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ BcweaverTests.removeOutDir();
+ outDir = null;
+ outDirPath = null;
+ }
public static InstructionList getAdviceTag(BcelShadow shadow, String where) {
- String methodName =
- "ajc_" + where + "_" + shadow.getKind().toLegalJavaIdentifier();
+ String methodName = "ajc_" + where + "_" + shadow.getKind().toLegalJavaIdentifier();
InstructionFactory fact = shadow.getFactory();
- InvokeInstruction il =
- fact.createInvoke("Aspect", methodName, Type.VOID, new Type[] {
- }, Constants.INVOKESTATIC);
- return new InstructionList(il);
+ InvokeInstruction il = fact.createInvoke("Aspect", methodName, Type.VOID, new Type[] {}, Constants.INVOKESTATIC);
+ return new InstructionList(il);
}
-
+
public void weaveTest(String name, String outName, ShadowMunger planner) throws IOException {
- List l = new ArrayList(1);
- l.add(planner);
- weaveTest(name, outName, l);
- }
-
- //static String classDir = "../weaver/bin";
+ List l = new ArrayList(1);
+ l.add(planner);
+ weaveTest(name, outName, l);
+ }
+
+ // static String classDir = "../weaver/bin";
static String classDir = BcweaverTests.TESTDATA_PATH + File.separator + "bin";
-
-
+
public void weaveTest(String name, String outName, List planners) throws IOException {
- BcelWeaver weaver = new BcelWeaver(world);
- try {
- if (behave15) world.setBehaveInJava5Way(true);
-
- UnwovenClassFile classFile = makeUnwovenClassFile(classDir, name, outDirPath);
-
- weaver.addClassFile(classFile);
- weaver.setShadowMungers(planners);
- weaveTestInner(weaver, classFile, name, outName);
- } finally {
- if (behave15) world.setBehaveInJava5Way(false);
- }
+ BcelWeaver weaver = new BcelWeaver(world);
+ try {
+ if (behave15)
+ world.setBehaveInJava5Way(true);
+
+ UnwovenClassFile classFile = makeUnwovenClassFile(classDir, name, outDirPath);
+
+ weaver.addClassFile(classFile);
+ weaver.setShadowMungers(planners);
+ weaveTestInner(weaver, classFile, name, outName);
+ } finally {
+ if (behave15)
+ world.setBehaveInJava5Way(false);
+ }
}
-
-
- protected void weaveTestInner(
- BcelWeaver weaver,
- UnwovenClassFile classFile,
- String name,
- String outName)
- throws IOException
- {
- //int preErrors = currentResult.errorCount();
- BcelObjectType classType =
- BcelWorld.getBcelObjectType(world.resolve(classFile.getClassName()));
+
+ protected void weaveTestInner(BcelWeaver weaver, UnwovenClassFile classFile, String name, String outName) throws IOException {
+ // int preErrors = currentResult.errorCount();
+ BcelObjectType classType = BcelWorld.getBcelObjectType(world.resolve(classFile.getClassName()));
LazyClassGen gen = weaver.weave(classFile, classType);
if (gen == null) {
// we didn't do any weaving, but let's make a gen anyway
- gen = classType.getLazyClassGen(); //new LazyClassGen(classType);
+ gen = classType.getLazyClassGen(); // new LazyClassGen(classType);
}
try {
checkClass(gen, outDirPath, outName + ".txt");
if (runTests) {
- System.out.println(
- "*******RUNNING: " + outName + " " + name + " *******");
- TestUtil.runMain(makeClassPath(outDirPath), name);
+ System.out.println("*******RUNNING: " + outName + " " + name + " *******");
+ TestUtil.runMain(makeClassPath(outDirPath), name);
}
} catch (Error e) {
System.err.println("Comparing to " + outName + ".txt");
@@ -126,148 +129,111 @@ public abstract class WeaveTestCase extends TestCase {
throw e;
}
}
-
- public String makeClassPath(String outDir) {
- return outDir
- + File.pathSeparator
- + getTraceJar()
- + File.pathSeparator
- + classDir
- + File.pathSeparator
- + System.getProperty("java.class.path");
- }
-
-
- /** '/' in the name indicates the location of the class
+
+ public String makeClassPath(String outDir) {
+ return outDir + File.pathSeparator + getTraceJar() + File.pathSeparator + classDir + File.pathSeparator
+ + System.getProperty("java.class.path");
+ }
+
+ /**
+ * '/' in the name indicates the location of the class
*/
- public static UnwovenClassFile makeUnwovenClassFile(
- String classDir,
- String name,
- String outDir) throws IOException {
- File outFile = new File(outDir, name+".class");
+ public static UnwovenClassFile makeUnwovenClassFile(String classDir, String name, String outDir) throws IOException {
+ File outFile = new File(outDir, name + ".class");
if (classDir.endsWith(".jar")) {
- String fname = name+".class";
- UnwovenClassFile ret =
- new UnwovenClassFile(outFile.getAbsolutePath(),
- FileUtil.readAsByteArray(FileUtil.getStreamFromZip(classDir, fname)));
- return ret;
+ String fname = name + ".class";
+ UnwovenClassFile ret = new UnwovenClassFile(outFile.getAbsolutePath(), FileUtil.readAsByteArray(FileUtil
+ .getStreamFromZip(classDir, fname)));
+ return ret;
} else {
- File inFile = new File(classDir, name+".class");
+ File inFile = new File(classDir, name + ".class");
return new UnwovenClassFile(outFile.getAbsolutePath(), FileUtil.readAsByteArray(inFile));
}
}
- public void checkClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException {
- if (regenerate) genClass(gen, outDir, expectedFile);
- else realCheckClass(gen, outDir, expectedFile);
- }
- static final File TESTDATA_DIR = new File(BcweaverTests.TESTDATA_PATH);
- void genClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException {
- //ClassGen b = getJavaClass(outDir, className);
- FileOutputStream out = new FileOutputStream(new File(TESTDATA_DIR, expectedFile));
- PrintStream ps = new PrintStream(out);
- gen.print(ps);
- ps.flush();
-
- }
-
- void realCheckClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException {
- TestUtil.assertMultiLineStringEquals(expectedFile/*"classes"*/,
- FileUtil.readAsString(new File(TESTDATA_DIR, expectedFile)),
- gen.toLongString());
- }
+ public void checkClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException {
+ if (regenerate)
+ genClass(gen, outDir, expectedFile);
+ else
+ realCheckClass(gen, outDir, expectedFile);
+ }
+
+ static final File TESTDATA_DIR = new File(BcweaverTests.TESTDATA_PATH);
+
+ void genClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException {
+ // ClassGen b = getJavaClass(outDir, className);
+ FileOutputStream out = new FileOutputStream(new File(TESTDATA_DIR, expectedFile));
+ PrintStream ps = new PrintStream(out);
+ gen.print(ps);
+ ps.flush();
+ }
+
+ void realCheckClass(LazyClassGen gen, String outDir, String expectedFile) throws IOException {
+ TestUtil.assertMultiLineStringEquals(expectedFile/* "classes" */, FileUtil
+ .readAsString(new File(TESTDATA_DIR, expectedFile)), gen.toLongString());
+ }
// ----
- public ShadowMunger makeConcreteAdvice(String mungerString) {
- return makeConcreteAdvice(mungerString, 0, null);
- }
+ public ShadowMunger makeConcreteAdvice(String mungerString) {
+ return makeConcreteAdvice(mungerString, 0, null);
+ }
- public ShadowMunger makeConcreteAdvice(String mungerString, int extraArgFlag) {
+ public ShadowMunger makeConcreteAdvice(String mungerString, int extraArgFlag) {
return makeConcreteAdvice(mungerString, extraArgFlag, null);
- }
-
- protected ShadowMunger makeConcreteAdvice(String mungerString, int extraArgFlag, PerClause perClause) {
- Advice myMunger =
- TestUtils.shadowMunger(world,mungerString, extraArgFlag);
-
-// PerSingleton s = new PerSingleton();
-// s.concretize(world.resolve("Aspect"));
- //System.err.println(((KindedPointcut)myMunger.getPointcut().getPointcut()).getKind());
- Advice cm = (Advice) myMunger.concretize(myMunger.getDeclaringAspect().resolve(world),
- world, perClause);
- return cm;
- }
-
- public ShadowMunger makeAdviceField(String kind, String extraArgType) {
- return makeConcreteAdvice(
- kind
- + "(): get(* *.*) -> static void Aspect.ajc_"
- + kind
- + "_field_get("
- + extraArgType
- + ")",
- 1);
- }
-
- public List makeAdviceAll(String kind, boolean matchOnlyPrintln) {
- List ret = new ArrayList();
- if (matchOnlyPrintln) {
- ret.add(
- makeConcreteAdvice(
- kind
- + "(): call(* *.println(..)) -> static void Aspect.ajc_"
- + kind
- + "_method_execution()"));
- } else {
- ret.add(
- makeConcreteAdvice(
- kind
- + "(): call(* *.*(..)) -> static void Aspect.ajc_"
- + kind
- + "_method_call()"));
- ret.add(
- makeConcreteAdvice(
- kind
- + "(): call(*.new(..)) -> static void Aspect.ajc_"
- + kind
- + "_constructor_call()"));
- ret.add(
- makeConcreteAdvice(
- kind
- + "(): execution(* *.*(..)) -> static void Aspect.ajc_"
- + kind
- + "_method_execution()"));
- ret.add(
- makeConcreteAdvice(
- kind
- + "(): execution(*.new(..)) -> static void Aspect.ajc_"
- + kind
- + "_constructor_execution()"));
-// ret.add(
-// makeConcreteMunger(
-// kind
-// + "(): staticinitialization(*) -> static void Aspect.ajc_"
-// + kind
-// + "_staticinitialization()"));
- ret.add(
- makeConcreteAdvice(
- kind + "(): get(* *.*) -> static void Aspect.ajc_" + kind + "_field_get()"));
-// ret.add(
-// makeConcreteMunger(
-// kind + "(): set(* *.*) -> static void Aspect.ajc_" + kind + "_field_set()"));
+ }
+
+ protected ShadowMunger makeConcreteAdvice(String mungerString, int extraArgFlag, PerClause perClause) {
+ Advice myMunger = BcelTestUtils.shadowMunger(world, mungerString, extraArgFlag);
+
+ // PerSingleton s = new PerSingleton();
+ // s.concretize(world.resolve("Aspect"));
+ // System.err.println(((KindedPointcut)myMunger.getPointcut().getPointcut()).getKind());
+ Advice cm = (Advice) myMunger.concretize(myMunger.getDeclaringAspect().resolve(world), world, perClause);
+ return cm;
+ }
+
+ public ShadowMunger makeAdviceField(String kind, String extraArgType) {
+ return makeConcreteAdvice(kind + "(): get(* *.*) -> static void Aspect.ajc_" + kind + "_field_get(" + extraArgType + ")", 1);
+ }
+
+ public List makeAdviceAll(String kind, boolean matchOnlyPrintln) {
+ List ret = new ArrayList();
+ if (matchOnlyPrintln) {
+ ret
+ .add(makeConcreteAdvice(kind + "(): call(* *.println(..)) -> static void Aspect.ajc_" + kind
+ + "_method_execution()"));
+ } else {
+ ret.add(makeConcreteAdvice(kind + "(): call(* *.*(..)) -> static void Aspect.ajc_" + kind + "_method_call()"));
+ ret.add(makeConcreteAdvice(kind + "(): call(*.new(..)) -> static void Aspect.ajc_" + kind + "_constructor_call()"));
+ ret
+ .add(makeConcreteAdvice(kind + "(): execution(* *.*(..)) -> static void Aspect.ajc_" + kind
+ + "_method_execution()"));
+ ret.add(makeConcreteAdvice(kind + "(): execution(*.new(..)) -> static void Aspect.ajc_" + kind
+ + "_constructor_execution()"));
+ // ret.add(
+ // makeConcreteMunger(
+ // kind
+ // + "(): staticinitialization(*) -> static void Aspect.ajc_"
+ // + kind
+ // + "_staticinitialization()"));
+ ret.add(makeConcreteAdvice(kind + "(): get(* *.*) -> static void Aspect.ajc_" + kind + "_field_get()"));
+ // ret.add(
+ // makeConcreteMunger(
+ // kind + "(): set(* *.*) -> static void Aspect.ajc_" + kind + "_field_set()"));
// XXX no test for advice execution, staticInitialization or (god help us) preInitialization
- }
- return ret;
- }
-
- public List makeAdviceAll(final String kind) {
- return makeAdviceAll(kind, false);
- }
+ }
+ return ret;
+ }
+
+ public List makeAdviceAll(final String kind) {
+ return makeAdviceAll(kind, false);
+ }
public Pointcut makePointcutAll() {
return makeConcretePointcut("get(* *.*) || call(* *.*(..)) || execution(* *.*(..)) || call(*.new(..)) || execution(*.new(..))");
}
+
public Pointcut makePointcutNoZeroArg() {
return makeConcretePointcut("call(* *.*(*, ..)) || execution(* *.*(*, ..)) || call(*.new(*, ..)) || execution(*.new(*, ..))");
}
@@ -275,22 +241,20 @@ public abstract class WeaveTestCase extends TestCase {
public Pointcut makePointcutPrintln() {
return makeConcretePointcut("call(* *.println(..))");
}
-
-
+
public Pointcut makeConcretePointcut(String s) {
return makeResolvedPointcut(s).concretize(null, null, 0);
}
-
+
public Pointcut makeResolvedPointcut(String s) {
Pointcut pointcut0 = Pointcut.fromString(s);
return pointcut0.resolve(new SimpleScope(world, FormalBinding.NONE));
}
-
// ----
public String[] getStandardTargets() {
- return new String[] {"HelloWorld", "FancyHelloWorld"};
+ return new String[] { "HelloWorld", "FancyHelloWorld" };
}
public String getTraceJar() {
@@ -299,55 +263,44 @@ public abstract class WeaveTestCase extends TestCase {
// ----
- protected void weaveTest(
- String[] inClassNames,
- String outKind,
- ShadowMunger patternMunger) throws IOException {
+ protected void weaveTest(String[] inClassNames, String outKind, ShadowMunger patternMunger) throws IOException {
for (int i = 0; i < inClassNames.length; i++) {
String inFileName = inClassNames[i];
weaveTest(inFileName, outKind + inFileName, patternMunger);
}
}
- protected void weaveTest(
- String[] inClassNames,
- String outKind,
- List patternMungers) throws IOException {
- for (int i = 0; i < inClassNames.length; i++) {
- String inFileName = inClassNames[i];
- weaveTest(inFileName, outKind + inFileName, patternMungers);
- }
- }
+
+ protected void weaveTest(String[] inClassNames, String outKind, List patternMungers) throws IOException {
+ for (int i = 0; i < inClassNames.length; i++) {
+ String inFileName = inClassNames[i];
+ weaveTest(inFileName, outKind + inFileName, patternMungers);
+ }
+ }
protected List addLexicalOrder(List l) {
int i = 10;
for (Iterator iter = l.iterator(); iter.hasNext();) {
Advice element = (Advice) iter.next();
- element.setLexicalPosition(i+=10);
+ element.setLexicalPosition(i += 10);
}
return l;
}
- //XXX cut-and-paster from IdWeaveTestCase
- public void checkShadowSet(List l, String[] ss) {
- outer:
- for (int i = 0, len = ss.length; i < len; i++) {
- //inner:
- for (Iterator j = l.iterator(); j.hasNext(); ) {
- BcelShadow shadow = (BcelShadow) j.next();
- String shadowString = shadow.toString();
- if (shadowString.equals(ss[i])) {
- j.remove();
- continue outer;
- }
- }
- assertTrue("didn't find " + ss[i] + " in " + l, false);
- }
- assertTrue("too many things in " + l, l.size() == 0);
- }
-
-
-
-
+ // XXX cut-and-paster from IdWeaveTestCase
+ public void checkShadowSet(List l, String[] ss) {
+ outer: for (int i = 0, len = ss.length; i < len; i++) {
+ // inner:
+ for (Iterator j = l.iterator(); j.hasNext();) {
+ BcelShadow shadow = (BcelShadow) j.next();
+ String shadowString = shadow.toString();
+ if (shadowString.equals(ss[i])) {
+ j.remove();
+ continue outer;
+ }
+ }
+ assertTrue("didn't find " + ss[i] + " in " + l, false);
+ }
+ assertTrue("too many things in " + l, l.size() == 0);
+ }
}
-
diff --git a/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java b/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java
index ccfcee954..926cc2d00 100644
--- a/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java
+++ b/weaver/testsrc/org/aspectj/weaver/bcel/WorldTestCase.java
@@ -10,131 +10,135 @@
* PARC initial implementation
* ******************************************************************/
-
package org.aspectj.weaver.bcel;
import java.lang.reflect.Modifier;
-import org.aspectj.weaver.*;
+import org.aspectj.weaver.AbstractWorldTestCase;
+import org.aspectj.weaver.Advice;
+import org.aspectj.weaver.BcweaverTests;
+import org.aspectj.weaver.Member;
+import org.aspectj.weaver.MemberImpl;
+import org.aspectj.weaver.ResolvedMember;
+import org.aspectj.weaver.ResolvedType;
+import org.aspectj.weaver.ShadowMunger;
+import org.aspectj.weaver.TestUtils;
+import org.aspectj.weaver.UnresolvedType;
+import org.aspectj.weaver.World;
/**
* This is a test case for the nameType parts of worlds.
*/
public class WorldTestCase extends AbstractWorldTestCase {
- public WorldTestCase(String name) {
- super(name);
- }
-
- private final BcelWorld world
- = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/tracing.jar");
+ public WorldTestCase(String name) {
+ super(name);
+ }
+
+ private final BcelWorld world = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/tracing.jar");
protected World getWorld() {
return world;
}
// XXX fix the various XXXs before expecting this test to work
- public void xtestTraceJar() {
- ResolvedType trace = world.resolve(UnresolvedType.forName("Trace"),true);
- assertTrue("Couldnt find type Trace",!trace.isMissing());
- fieldsTest(trace, Member.NONE);
- /*Member constr = */TestUtils.methodFromString("void Trace.<init>()");
- //XXX need attribute fix -
- //methodsTest(trace, new Member[] { constr });
-
- interfacesTest(trace, ResolvedType.NONE);
- superclassTest(trace, UnresolvedType.OBJECT);
- isInterfaceTest(trace, false);
- isClassTest(trace, false);
- isAspectTest(trace, true);
-
- pointcutsTest(trace,
- new Member[] {
- MemberImpl.pointcut(trace, "traced", "(Ljava/lang/Object;)V"),
- });
-
- modifiersTest(trace.findPointcut("traced"),
- Modifier.PUBLIC | Modifier.ABSTRACT);
-
- mungersTest(trace,
- new ShadowMunger[] {
- TestUtils.shadowMunger(world,"before(foo): traced(foo) -> void Trace.ajc_before_4(java.lang.Object))",
- 0),
- TestUtils.shadowMunger(world,"afterReturning(foo): traced(foo) -> void Trace.ajc_afterreturning_3(java.lang.Object, java.lang.Object))",
- Advice.ExtraArgument),
- TestUtils.shadowMunger(world,"around(): execution(* doit(..)) -> java.lang.Object Trace.ajc_around_2(org.aspectj.runtime.internal.AroundClosure))",
- Advice.ExtraArgument),
- TestUtils.shadowMunger(world,"around(foo): traced(foo) -> java.lang.Object Trace.ajc_around_1(java.lang.Object, org.aspectj.runtime.internal.AroundClosure))",
- Advice.ExtraArgument),
- });
-
- ResolvedType myTrace = world.resolve(UnresolvedType.forName("MyTrace"),true);
- assertTrue("Couldnt find type MyTrace",!myTrace.isMissing());
-
- interfacesTest(myTrace, ResolvedType.NONE);
- superclassTest(myTrace, trace);
- isInterfaceTest(myTrace, false);
- isClassTest(myTrace, false);
- isAspectTest(myTrace, true);
-
- //XXX need attribute fix -
- //fieldsTest(myTrace, Member.NONE);
-
-
- pointcutsTest(trace,
- new Member[] {
- MemberImpl.pointcut(trace, "traced", "(Ljava/lang/Object;)V"),
- });
-
- modifiersTest(myTrace.findPointcut("traced"),
- Modifier.PUBLIC);
-
- // this tests for declared mungers
- mungersTest(myTrace, ShadowMunger.NONE);
-
- }
-
- public void testIterator() {
- int abstractPublic = Modifier.ABSTRACT | Modifier.PUBLIC;
- ResolvedType iter = world.getCoreType(UnresolvedType.forRawTypeName("java.util.Iterator"));
-
- modifiersTest(iter, abstractPublic | Modifier.INTERFACE);
- fieldsTest(iter, ResolvedMember.NONE);
- methodsTest(iter,
- new Member[] {
- MemberImpl.method(iter, 0, "hasNext", "()Z"),
- MemberImpl.method(iter, 0, "remove", "()V"),
- MemberImpl.method(iter, 0, "next", "()Ljava/lang/Object;"),
- });
- ResolvedMember remove = iter.lookupMethod(MemberImpl.method(iter, 0, "remove", "()V"));
- assertNotNull("iterator doesn't have remove" , remove);
- modifiersTest(remove, abstractPublic | Modifier.INTERFACE);
- exceptionsTest(remove, UnresolvedType.NONE);
-
- ResolvedMember clone = iter.lookupMethod(MemberImpl.method(UnresolvedType.OBJECT, 0, "clone", "()Ljava/lang/Object;"));
- assertNotNull("iterator doesn't have clone" , clone);
- //AV: JRockit Object.clone() is not native.. corrupted test here:
- //modifiersTest(clone, Modifier.PROTECTED | Modifier.NATIVE);
- assertTrue("should be protected" + clone.toString(), clone.isProtected());
- exceptionsTest(clone, UnresolvedType.forNames(new String[] {"java.lang.CloneNotSupportedException"}));
-
- interfacesTest(iter, ResolvedType.NONE);
- superclassTest(iter, UnresolvedType.OBJECT);
- pointcutsTest(iter, ResolvedMember.NONE);
- mungersTest(iter, ShadowMunger.NONE);
- isInterfaceTest(iter, true);
- isClassTest(iter, false);
- isAspectTest(iter, false);
- }
+ public void xtestTraceJar() {
+ ResolvedType trace = world.resolve(UnresolvedType.forName("Trace"), true);
+ assertTrue("Couldnt find type Trace", !trace.isMissing());
+ fieldsTest(trace, Member.NONE);
+ /* Member constr = */TestUtils.methodFromString("void Trace.<init>()");
+ // XXX need attribute fix -
+ // methodsTest(trace, new Member[] { constr });
+
+ interfacesTest(trace, ResolvedType.NONE);
+ superclassTest(trace, UnresolvedType.OBJECT);
+ isInterfaceTest(trace, false);
+ isClassTest(trace, false);
+ isAspectTest(trace, true);
+
+ pointcutsTest(trace, new Member[] { MemberImpl.pointcut(trace, "traced", "(Ljava/lang/Object;)V"), });
+
+ modifiersTest(trace.findPointcut("traced"), Modifier.PUBLIC | Modifier.ABSTRACT);
+
+ mungersTest(
+ trace,
+ new ShadowMunger[] {
+ BcelTestUtils.shadowMunger(world, "before(foo): traced(foo) -> void Trace.ajc_before_4(java.lang.Object))",
+ 0),
+ BcelTestUtils
+ .shadowMunger(
+ world,
+ "afterReturning(foo): traced(foo) -> void Trace.ajc_afterreturning_3(java.lang.Object, java.lang.Object))",
+ Advice.ExtraArgument),
+ BcelTestUtils
+ .shadowMunger(
+ world,
+ "around(): execution(* doit(..)) -> java.lang.Object Trace.ajc_around_2(org.aspectj.runtime.internal.AroundClosure))",
+ Advice.ExtraArgument),
+ BcelTestUtils
+ .shadowMunger(
+ world,
+ "around(foo): traced(foo) -> java.lang.Object Trace.ajc_around_1(java.lang.Object, org.aspectj.runtime.internal.AroundClosure))",
+ Advice.ExtraArgument), });
+
+ ResolvedType myTrace = world.resolve(UnresolvedType.forName("MyTrace"), true);
+ assertTrue("Couldnt find type MyTrace", !myTrace.isMissing());
+
+ interfacesTest(myTrace, ResolvedType.NONE);
+ superclassTest(myTrace, trace);
+ isInterfaceTest(myTrace, false);
+ isClassTest(myTrace, false);
+ isAspectTest(myTrace, true);
+
+ // XXX need attribute fix -
+ // fieldsTest(myTrace, Member.NONE);
+
+ pointcutsTest(trace, new Member[] { MemberImpl.pointcut(trace, "traced", "(Ljava/lang/Object;)V"), });
+
+ modifiersTest(myTrace.findPointcut("traced"), Modifier.PUBLIC);
+
+ // this tests for declared mungers
+ mungersTest(myTrace, ShadowMunger.NONE);
+
+ }
+
+ public void testIterator() {
+ int abstractPublic = Modifier.ABSTRACT | Modifier.PUBLIC;
+ ResolvedType iter = world.getCoreType(UnresolvedType.forRawTypeName("java.util.Iterator"));
+
+ modifiersTest(iter, abstractPublic | Modifier.INTERFACE);
+ fieldsTest(iter, ResolvedMember.NONE);
+ methodsTest(iter, new Member[] { MemberImpl.method(iter, 0, "hasNext", "()Z"), MemberImpl.method(iter, 0, "remove", "()V"),
+ MemberImpl.method(iter, 0, "next", "()Ljava/lang/Object;"), });
+ ResolvedMember remove = iter.lookupMethod(MemberImpl.method(iter, 0, "remove", "()V"));
+ assertNotNull("iterator doesn't have remove", remove);
+ modifiersTest(remove, abstractPublic | Modifier.INTERFACE);
+ exceptionsTest(remove, UnresolvedType.NONE);
+
+ ResolvedMember clone = iter.lookupMethod(MemberImpl.method(UnresolvedType.OBJECT, 0, "clone", "()Ljava/lang/Object;"));
+ assertNotNull("iterator doesn't have clone", clone);
+ // AV: JRockit Object.clone() is not native.. corrupted test here:
+ // modifiersTest(clone, Modifier.PROTECTED | Modifier.NATIVE);
+ assertTrue("should be protected" + clone.toString(), clone.isProtected());
+ exceptionsTest(clone, UnresolvedType.forNames(new String[] { "java.lang.CloneNotSupportedException" }));
+
+ interfacesTest(iter, ResolvedType.NONE);
+ superclassTest(iter, UnresolvedType.OBJECT);
+ pointcutsTest(iter, ResolvedMember.NONE);
+ mungersTest(iter, ShadowMunger.NONE);
+ isInterfaceTest(iter, true);
+ isClassTest(iter, false);
+ isAspectTest(iter, false);
+ }
public void testObjectCoersion() {
assertCouldBeCoercibleFrom("java.lang.Object", "java.lang.String");
assertCouldBeCoercibleFrom("java.lang.Integer", "java.lang.Object");
- assertCouldBeCoercibleFrom("java.io.Serializable", "java.lang.Runnable");
- assertCouldBeCoercibleFrom("java.util.Stack", "java.lang.Runnable");
- assertCouldNotBeCoercibleFrom("java.lang.Runnable", "java.lang.Integer");
- assertCouldNotBeCoercibleFrom("java.lang.Integer", "java.lang.String");
- assertCouldNotBeCoercibleFrom("java.lang.Integer", "java.lang.Runnable");
+ assertCouldBeCoercibleFrom("java.io.Serializable", "java.lang.Runnable");
+ assertCouldBeCoercibleFrom("java.util.Stack", "java.lang.Runnable");
+ assertCouldNotBeCoercibleFrom("java.lang.Runnable", "java.lang.Integer");
+ assertCouldNotBeCoercibleFrom("java.lang.Integer", "java.lang.String");
+ assertCouldNotBeCoercibleFrom("java.lang.Integer", "java.lang.Runnable");
}
// ----
@@ -145,7 +149,6 @@ public class WorldTestCase extends AbstractWorldTestCase {
private void assertCouldNotBeCoercibleFrom(String a, String b) {
isCoerceableFromTest(world.resolve(a), world.resolve(b), false);
- }
-
+ }
}
diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java
index d6592da54..917fe816b 100644
--- a/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java
+++ b/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java
@@ -10,7 +10,6 @@
* PARC initial implementation
* ******************************************************************/
-
package org.aspectj.weaver.patterns;
import java.util.ArrayList;
@@ -26,42 +25,35 @@ import org.aspectj.weaver.BcweaverTests;
import org.aspectj.weaver.Shadow;
import org.aspectj.weaver.UnresolvedType;
import org.aspectj.weaver.World;
-import org.aspectj.weaver.bcel.BcelShadow;
import org.aspectj.weaver.bcel.BcelWorld;
/**
* @author hugunin
- *
- * To change this generated comment edit the template variable "typecomment":
- * Window>Preferences>Java>Templates.
- * To enable and disable the creation of type comments go to
- * Window>Preferences>Java>Code Generation.
+ *
+ * To change this generated comment edit the template variable "typecomment": Window>Preferences>Java>Templates. To enable
+ * and disable the creation of type comments go to Window>Preferences>Java>Code Generation.
*/
public class ParserTestCase extends TestCase {
public ParserTestCase(String arg0) {
super(arg0);
}
-
+
World world = new BcelWorld(BcweaverTests.TESTDATA_PATH + "/testcode.jar");
-
+
public void testNamePatterns() {
-
-
-// checkNoMatch("abc *", "abcd");
-// checkNoMatch("* d", "abcd");
- }
-
-
-
+
+ // checkNoMatch("abc *", "abcd");
+ // checkNoMatch("* d", "abcd");
+ }
+
public void testParse() {
PatternParser parser = new PatternParser("execution(void Hello.*(..))");
KindedPointcut p = (KindedPointcut) parser.parsePointcut();
- //System.out.println(p);
- assertEquals(p.kind, BcelShadow.MethodExecution);
+ // System.out.println(p);
+ assertEquals(p.kind, Shadow.MethodExecution);
assertTrue(p.getSignature().getName().matches("foobar"));
-
-
+
try {
new PatternParser("initialization(void foo())").parsePointcut();
fail("should have been a parse error");
@@ -69,336 +61,336 @@ public class ParserTestCase extends TestCase {
// good
}
}
-
+
public void testParseExecutionWithAnnotation() {
PatternParser parser = new PatternParser("execution(@SimpleAnnotation void Hello.*(..))");
KindedPointcut p = (KindedPointcut) parser.parsePointcut();
// XXX - needs finishing...
- p.resolveBindings(makeSimpleScope(),new Bindings(3));
- assertEquals("execution(@p.SimpleAnnotation void Hello.*(..))",p.toString());
+ p.resolveBindings(makeSimpleScope(), new Bindings(3));
+ assertEquals("execution(@p.SimpleAnnotation void Hello.*(..))", p.toString());
assertEquals(p.kind, Shadow.MethodExecution);
assertTrue(p.getSignature().getName().matches("foobar"));
}
-
+
// note... toString on a pointcut is a very quick and easy way to test a successful parse
public void testParseExecutionWithMultipleAnnotations() {
- PatternParser parser = new PatternParser("execution(@SimpleAnnotation (@Foo Integer) (@Goo Hello).*(..))");
- KindedPointcut p = (KindedPointcut) parser.parsePointcut();
- assertEquals("execution(@(SimpleAnnotation) (@(Foo) Integer) (@(Goo) Hello).*(..))",p.toString());
+ PatternParser parser = new PatternParser("execution(@SimpleAnnotation (@Foo Integer) (@Goo Hello).*(..))");
+ KindedPointcut p = (KindedPointcut) parser.parsePointcut();
+ assertEquals("execution(@(SimpleAnnotation) (@(Foo) Integer) (@(Goo) Hello).*(..))", p.toString());
}
-
+
public void testParseCallWithMultipleAnnotations() {
- PatternParser parser = new PatternParser("call(@SimpleAnnotation (@Foo Integer) (@Goo Hello).*(..))");
- KindedPointcut p = (KindedPointcut) parser.parsePointcut();
- assertEquals("call(@(SimpleAnnotation) (@(Foo) Integer) (@(Goo) Hello).*(..))",p.toString());
+ PatternParser parser = new PatternParser("call(@SimpleAnnotation (@Foo Integer) (@Goo Hello).*(..))");
+ KindedPointcut p = (KindedPointcut) parser.parsePointcut();
+ assertEquals("call(@(SimpleAnnotation) (@(Foo) Integer) (@(Goo) Hello).*(..))", p.toString());
}
-
+
public void testParseGetWithAnnotations() {
- PatternParser parser = new PatternParser("get(@Foo (@SimpleAnnotation ReturnType) (@Foo @Goo Hello).*)");
- KindedPointcut p = (KindedPointcut) parser.parsePointcut();
- assertEquals("get(@(Foo) (@(SimpleAnnotation) ReturnType) (@(Foo) @(Goo) Hello).*)",p.toString());
+ PatternParser parser = new PatternParser("get(@Foo (@SimpleAnnotation ReturnType) (@Foo @Goo Hello).*)");
+ KindedPointcut p = (KindedPointcut) parser.parsePointcut();
+ assertEquals("get(@(Foo) (@(SimpleAnnotation) ReturnType) (@(Foo) @(Goo) Hello).*)", p.toString());
}
-
+
public void testParseBadGetWithAnnotations() {
- PatternParser parser = new PatternParser("get(@Foo (@Foo @Goo Hello).*)");
- try {
-// KindedPointcut p = (KindedPointcut)
- parser.parsePointcut();
- fail("Expected parser exception");
- } catch (ParserException pEx) {
- assertEquals("name pattern",pEx.getMessage());
- }
- }
-
+ PatternParser parser = new PatternParser("get(@Foo (@Foo @Goo Hello).*)");
+ try {
+ // KindedPointcut p = (KindedPointcut)
+ parser.parsePointcut();
+ fail("Expected parser exception");
+ } catch (ParserException pEx) {
+ assertEquals("name pattern", pEx.getMessage());
+ }
+ }
+
public void testParseGetWithAndAggregationAnnotations() {
- PatternParser parser = new PatternParser("get(@Foo @SimpleAnnotation ReturnType (@Foo @Goo Hello).*)");
- KindedPointcut p = (KindedPointcut) parser.parsePointcut();
- assertEquals("get(@(Foo) @(SimpleAnnotation) ReturnType (@(Foo) @(Goo) Hello).*)",p.toString());
+ PatternParser parser = new PatternParser("get(@Foo @SimpleAnnotation ReturnType (@Foo @Goo Hello).*)");
+ KindedPointcut p = (KindedPointcut) parser.parsePointcut();
+ assertEquals("get(@(Foo) @(SimpleAnnotation) ReturnType (@(Foo) @(Goo) Hello).*)", p.toString());
}
-
-
+
public void testParseSetWithAnnotations() {
- PatternParser parser = new PatternParser("set(@Foo (@SimpleAnnotation ReturnType) (@Foo @Goo Hello).*)");
- KindedPointcut p = (KindedPointcut) parser.parsePointcut();
- assertEquals("set(@(Foo) (@(SimpleAnnotation) ReturnType) (@(Foo) @(Goo) Hello).*)",p.toString());
+ PatternParser parser = new PatternParser("set(@Foo (@SimpleAnnotation ReturnType) (@Foo @Goo Hello).*)");
+ KindedPointcut p = (KindedPointcut) parser.parsePointcut();
+ assertEquals("set(@(Foo) (@(SimpleAnnotation) ReturnType) (@(Foo) @(Goo) Hello).*)", p.toString());
}
-
+
public void testParseHandlerWithAnnotations() {
- PatternParser parser = new PatternParser("handler(@Critical Exception+)");
- Pointcut p = parser.parsePointcut();
- assertEquals("handler((@(Critical) Exception+))",p.toString());
+ PatternParser parser = new PatternParser("handler(@Critical Exception+)");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("handler((@(Critical) Exception+))", p.toString());
}
public void testParseInitializationWithAnnotations() {
- PatternParser parser = new PatternParser("initialization(@Foo (@Goo Hello).new(@Foo Integer))");
- Pointcut p = parser.parsePointcut();
- assertEquals("initialization(@(Foo) (@(Goo) Hello).new((@(Foo) Integer)))",p.toString());
-
+ PatternParser parser = new PatternParser("initialization(@Foo (@Goo Hello).new(@Foo Integer))");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("initialization(@(Foo) (@(Goo) Hello).new((@(Foo) Integer)))", p.toString());
+
}
-
+
public void testParsePreInitializationWithAnnotations() {
- PatternParser parser = new PatternParser("preinitialization(@Foo (@Goo Hello).new(@Foo Integer))");
- Pointcut p = parser.parsePointcut();
- assertEquals("preinitialization(@(Foo) (@(Goo) Hello).new((@(Foo) Integer)))",p.toString());
+ PatternParser parser = new PatternParser("preinitialization(@Foo (@Goo Hello).new(@Foo Integer))");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("preinitialization(@(Foo) (@(Goo) Hello).new((@(Foo) Integer)))", p.toString());
}
-
+
public void testStaticInitializationWithAnnotations() {
- PatternParser parser = new PatternParser("staticinitialization(@Foo @Boo @Goo Moo)");
- Pointcut p = parser.parsePointcut();
- assertEquals("staticinitialization((@(Foo) @(Boo) @(Goo) Moo).<clinit>())",p.toString());
+ PatternParser parser = new PatternParser("staticinitialization(@Foo @Boo @Goo Moo)");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("staticinitialization((@(Foo) @(Boo) @(Goo) Moo).<clinit>())", p.toString());
}
-
+
public void testWithinWithAnnotations() {
- PatternParser parser = new PatternParser("within(@Foo *)");
- Pointcut p = parser.parsePointcut();
- assertEquals("within((@(Foo) *))",p.toString());
+ PatternParser parser = new PatternParser("within(@Foo *)");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("within((@(Foo) *))", p.toString());
}
-
+
public void testWithinCodeWithAnnotations() {
- PatternParser parser = new PatternParser("withincode(@Foo * *.*(..))");
- Pointcut p = parser.parsePointcut();
- assertEquals("withincode(@(Foo) * *.*(..))",p.toString());
+ PatternParser parser = new PatternParser("withincode(@Foo * *.*(..))");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("withincode(@(Foo) * *.*(..))", p.toString());
}
-
+
public void testAtAnnotation() {
- PatternParser parser = new PatternParser("@annotation(Foo)");
- AnnotationPointcut p = (AnnotationPointcut) parser.parsePointcut();
- assertEquals("@annotation(Foo)",p.toString());
+ PatternParser parser = new PatternParser("@annotation(Foo)");
+ AnnotationPointcut p = (AnnotationPointcut) parser.parsePointcut();
+ assertEquals("@annotation(Foo)", p.toString());
}
-
+
public void testBadAtAnnotation() {
- PatternParser parser = new PatternParser("@annotation(!Foo)");
- try {
-// Pointcut p =
- parser.parsePointcut();
- fail("Expected parser exception");
- } catch (ParserException pEx) {
- assertEquals("identifier",pEx.getMessage());
- }
- }
-
+ PatternParser parser = new PatternParser("@annotation(!Foo)");
+ try {
+ // Pointcut p =
+ parser.parsePointcut();
+ fail("Expected parser exception");
+ } catch (ParserException pEx) {
+ assertEquals("identifier", pEx.getMessage());
+ }
+ }
+
public void testAtAnnotationWithBinding() {
- PatternParser parser = new PatternParser("@annotation(foo)");
- AnnotationPointcut p = (AnnotationPointcut) parser.parsePointcut();
- assertEquals("@annotation(foo)",p.toString());
+ PatternParser parser = new PatternParser("@annotation(foo)");
+ AnnotationPointcut p = (AnnotationPointcut) parser.parsePointcut();
+ assertEquals("@annotation(foo)", p.toString());
}
-
+
public void testDoubleAtAnnotation() {
- PatternParser parser = new PatternParser("@annotation(Foo Goo)");
- try {
-// Pointcut p =
- parser.parsePointcut();
- fail("Expected parser exception");
- } catch (ParserException pEx) {
- assertEquals(")",pEx.getMessage());
- }
- }
-
+ PatternParser parser = new PatternParser("@annotation(Foo Goo)");
+ try {
+ // Pointcut p =
+ parser.parsePointcut();
+ fail("Expected parser exception");
+ } catch (ParserException pEx) {
+ assertEquals(")", pEx.getMessage());
+ }
+ }
+
public void testAtWithin() {
- PatternParser parser = new PatternParser("@within(foo)");
- WithinAnnotationPointcut p = (WithinAnnotationPointcut) parser.parsePointcut();
- assertEquals("@within(foo)",p.toString());
- parser = new PatternParser("@within(Foo))");
- p = (WithinAnnotationPointcut) parser.parsePointcut();
- assertEquals("@within(Foo)",p.toString());
- }
-
+ PatternParser parser = new PatternParser("@within(foo)");
+ WithinAnnotationPointcut p = (WithinAnnotationPointcut) parser.parsePointcut();
+ assertEquals("@within(foo)", p.toString());
+ parser = new PatternParser("@within(Foo))");
+ p = (WithinAnnotationPointcut) parser.parsePointcut();
+ assertEquals("@within(Foo)", p.toString());
+ }
+
public void testAtWithinCode() {
- PatternParser parser = new PatternParser("@withincode(foo)");
- WithinCodeAnnotationPointcut p = (WithinCodeAnnotationPointcut) parser.parsePointcut();
- assertEquals("@withincode(foo)",p.toString());
- parser = new PatternParser("@withincode(Foo))");
- p = (WithinCodeAnnotationPointcut) parser.parsePointcut();
- assertEquals("@withincode(Foo)",p.toString());
- }
-
+ PatternParser parser = new PatternParser("@withincode(foo)");
+ WithinCodeAnnotationPointcut p = (WithinCodeAnnotationPointcut) parser.parsePointcut();
+ assertEquals("@withincode(foo)", p.toString());
+ parser = new PatternParser("@withincode(Foo))");
+ p = (WithinCodeAnnotationPointcut) parser.parsePointcut();
+ assertEquals("@withincode(Foo)", p.toString());
+ }
+
public void testAtThis() {
- PatternParser parser = new PatternParser("@this(foo)");
- ThisOrTargetAnnotationPointcut p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut();
- assertEquals("@this(foo)",p.toString());
- assertTrue("isThis",p.isThis());
- parser = new PatternParser("@this(Foo))");
- p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut();
- assertTrue("isThis",p.isThis());
- assertEquals("@this(Foo)",p.toString());
+ PatternParser parser = new PatternParser("@this(foo)");
+ ThisOrTargetAnnotationPointcut p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut();
+ assertEquals("@this(foo)", p.toString());
+ assertTrue("isThis", p.isThis());
+ parser = new PatternParser("@this(Foo))");
+ p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut();
+ assertTrue("isThis", p.isThis());
+ assertEquals("@this(Foo)", p.toString());
}
public void testAtTarget() {
- PatternParser parser = new PatternParser("@target(foo)");
- ThisOrTargetAnnotationPointcut p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut();
- assertEquals("@target(foo)",p.toString());
- assertTrue("isTarget",!p.isThis());
- parser = new PatternParser("@target(Foo))");
- p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut();
- assertTrue("isTarget",!p.isThis());
- assertEquals("@target(Foo)",p.toString());
- }
-
+ PatternParser parser = new PatternParser("@target(foo)");
+ ThisOrTargetAnnotationPointcut p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut();
+ assertEquals("@target(foo)", p.toString());
+ assertTrue("isTarget", !p.isThis());
+ parser = new PatternParser("@target(Foo))");
+ p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut();
+ assertTrue("isTarget", !p.isThis());
+ assertEquals("@target(Foo)", p.toString());
+ }
+
public void testAtArgs() {
- PatternParser parser = new PatternParser("@args(Foo,Goo,*,..,Moo)");
- Pointcut p = parser.parsePointcut();
- assertEquals("@args(Foo, Goo, ANY, .., Moo)",p.toString());
+ PatternParser parser = new PatternParser("@args(Foo,Goo,*,..,Moo)");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("@args(Foo, Goo, ANY, .., Moo)", p.toString());
}
-
+
public void testParseSimpleTypeVariable() {
PatternParser parser = new PatternParser("T");
TypeVariablePattern tv = parser.parseTypeVariable();
TypeVariablePattern expected = new TypeVariablePattern("T");
- assertEquals("Expected simple type variable T",expected,tv);
+ assertEquals("Expected simple type variable T", expected, tv);
}
-
+
public void testParseExtendingTypeVariable() {
PatternParser parser = new PatternParser("T extends Number");
TypeVariablePattern tv = parser.parseTypeVariable();
- TypeVariablePattern expected = new TypeVariablePattern("T",new PatternParser("Number").parseTypePattern());
- assertEquals("Expected type variable T extends Number",expected,tv);
+ TypeVariablePattern expected = new TypeVariablePattern("T", new PatternParser("Number").parseTypePattern());
+ assertEquals("Expected type variable T extends Number", expected, tv);
}
-
+
public void testParseExtendingTypeVariableWithPattern() {
PatternParser parser = new PatternParser("T extends Number+");
TypeVariablePattern tv = parser.parseTypeVariable();
- TypeVariablePattern expected = new TypeVariablePattern("T",new PatternParser("Number+").parseTypePattern());
- assertEquals("Expected type variable T extends Number+",expected,tv);
+ TypeVariablePattern expected = new TypeVariablePattern("T", new PatternParser("Number+").parseTypePattern());
+ assertEquals("Expected type variable T extends Number+", expected, tv);
}
-
+
public void testParseExtendingTypeVariableWithInterface() {
PatternParser parser = new PatternParser("T extends Number & Comparable");
TypeVariablePattern tv = parser.parseTypeVariable();
- TypeVariablePattern expected = new TypeVariablePattern("T",new PatternParser("Number").parseTypePattern(),
- new TypePattern[] {new PatternParser("Comparable").parseTypePattern()},null);
- assertEquals("Expected type variable T extends Number",expected,tv);
+ TypeVariablePattern expected = new TypeVariablePattern("T", new PatternParser("Number").parseTypePattern(),
+ new TypePattern[] { new PatternParser("Comparable").parseTypePattern() }, null);
+ assertEquals("Expected type variable T extends Number", expected, tv);
}
-
+
public void testParseExtendingTypeVariableWithInterfaceList() {
PatternParser parser = new PatternParser("T extends Number & Comparable & Cloneable");
TypeVariablePattern tv = parser.parseTypeVariable();
- TypeVariablePattern expected = new TypeVariablePattern("T",new PatternParser("Number").parseTypePattern(),
- new TypePattern[] {new PatternParser("Comparable").parseTypePattern(),
- new PatternParser("Cloneable").parseTypePattern()},null);
- assertEquals("Expected type variable T extends Number",expected,tv);
+ TypeVariablePattern expected = new TypeVariablePattern("T", new PatternParser("Number").parseTypePattern(),
+ new TypePattern[] { new PatternParser("Comparable").parseTypePattern(),
+ new PatternParser("Cloneable").parseTypePattern() }, null);
+ assertEquals("Expected type variable T extends Number", expected, tv);
}
-
+
public void testParseTypeParameterList() {
PatternParser parser = new PatternParser("<T>");
TypeVariablePatternList list = parser.maybeParseTypeVariableList();
TypeVariablePattern[] patterns = list.getTypeVariablePatterns();
TypeVariablePattern expected = new TypeVariablePattern("T");
- assertEquals("Expected simple type variable T",expected,patterns[0]);
- assertEquals("One pattern in list",1,patterns.length);
+ assertEquals("Expected simple type variable T", expected, patterns[0]);
+ assertEquals("One pattern in list", 1, patterns.length);
}
-
+
public void testParseTypeParameterListWithSeveralTypeParameters() {
PatternParser parser = new PatternParser("<T,S extends Number, R>");
TypeVariablePatternList list = parser.maybeParseTypeVariableList();
TypeVariablePattern[] patterns = list.getTypeVariablePatterns();
TypeVariablePattern expected0 = new TypeVariablePattern("T");
- assertEquals("Expected simple type variable T",expected0,patterns[0]);
- TypeVariablePattern expected1 = new TypeVariablePattern("S",new PatternParser("Number").parseTypePattern());
- assertEquals("Expected type variable S extends Number",expected1,patterns[1]);
+ assertEquals("Expected simple type variable T", expected0, patterns[0]);
+ TypeVariablePattern expected1 = new TypeVariablePattern("S", new PatternParser("Number").parseTypePattern());
+ assertEquals("Expected type variable S extends Number", expected1, patterns[1]);
TypeVariablePattern expected2 = new TypeVariablePattern("R");
- assertEquals("Expected simple type variable R",expected2,patterns[2]);
-
- assertEquals("3 patterns in list",3,patterns.length);
+ assertEquals("Expected simple type variable R", expected2, patterns[2]);
+
+ assertEquals("3 patterns in list", 3, patterns.length);
}
-
-
+
public void testParseAllowedSuperInTypeVariable() {
PatternParser parser = new PatternParser("T super Number+");
TypeVariablePattern tv = parser.parseTypeVariable();
- TypeVariablePattern expected = new TypeVariablePattern("T",new ExactTypePattern(UnresolvedType.OBJECT,false,false),null,new PatternParser("Number+").parseTypePattern());
- assertEquals("Expected type variable T super Number+",expected,tv);
+ TypeVariablePattern expected = new TypeVariablePattern("T", new ExactTypePattern(UnresolvedType.OBJECT, false, false),
+ null, new PatternParser("Number+").parseTypePattern());
+ assertEquals("Expected type variable T super Number+", expected, tv);
}
-
+
public void testParseAnythingTypeVariable() {
PatternParser parser = new PatternParser("?");
- WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true,false);
- assertEquals("Expected type variable ?","?",tp.maybeGetSimpleName());
+ WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true, false);
+ assertEquals("Expected type variable ?", "?", tp.maybeGetSimpleName());
}
public void testParseAnythingExtendsTypeVariable() {
PatternParser parser = new PatternParser("? extends Number");
- WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true,false);
- assertEquals("Expected type variable ?","?",tp.maybeGetSimpleName());
- assertEquals("upper Bound of Number",new PatternParser("Number").parseTypePattern(),tp.getUpperBound());
+ WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true, false);
+ assertEquals("Expected type variable ?", "?", tp.maybeGetSimpleName());
+ assertEquals("upper Bound of Number", new PatternParser("Number").parseTypePattern(), tp.getUpperBound());
}
-
+
public void testParseAnythingSuperTypeVariable() {
PatternParser parser = new PatternParser("? super Number+");
- WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true,false);
- assertEquals("Expected type variable ?","?",tp.maybeGetSimpleName());
- assertEquals("lower Bound of Number+",new PatternParser("Number+").parseTypePattern(),tp.getLowerBound());
+ WildTypePattern tp = (WildTypePattern) parser.parseTypePattern(true, false);
+ assertEquals("Expected type variable ?", "?", tp.maybeGetSimpleName());
+ assertEquals("lower Bound of Number+", new PatternParser("Number+").parseTypePattern(), tp.getLowerBound());
}
-
+
public void testParseDeclareParentsWithTypeParameterList() {
try {
PatternParser parser = new PatternParser("declare parents<T> : Foo<T> implements IveGoneMad");
- //DeclareParents decp = (DeclareParents)
- parser.parseDeclare();
-// String[] tvp = decp.getTypeParameterNames();
-// assertEquals("one type parameter",1,tvp.length);
-// assertEquals("expecting T","T",tvp[0]);
+ // DeclareParents decp = (DeclareParents)
+ parser.parseDeclare();
+ // String[] tvp = decp.getTypeParameterNames();
+ // assertEquals("one type parameter",1,tvp.length);
+ // assertEquals("expecting T","T",tvp[0]);
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals(":",pEx.getMessage());
+ assertEquals(":", pEx.getMessage());
}
}
-
+
public void testParameterizedTypePatternsAny() {
try {
PatternParser parser = new PatternParser("*<T,S extends Number>");
-// WildTypePattern wtp = (WildTypePattern)
- parser.parseTypePattern(false,false);
- // TypePatternList tvs = wtp.getTypeParameters();
- // assertEquals("2 type parameters",2,tvs.getTypePatterns().length);
- // assertEquals("T",new PatternParser("T").parseTypePattern(),tvs.getTypePatterns()[0]);
- // assertEquals("S extends Number",new PatternParser("S extends Number").parseTypePattern(false),tvs.getTypePatterns()[1]);
+ // WildTypePattern wtp = (WildTypePattern)
+ parser.parseTypePattern(false, false);
+ // TypePatternList tvs = wtp.getTypeParameters();
+ // assertEquals("2 type parameters",2,tvs.getTypePatterns().length);
+ // assertEquals("T",new PatternParser("T").parseTypePattern(),tvs.getTypePatterns()[0]);
+ // assertEquals("S extends Number",new
+ // PatternParser("S extends Number").parseTypePattern(false),tvs.getTypePatterns()[1]);
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals(">",pEx.getMessage());
+ assertEquals(">", pEx.getMessage());
}
}
-
+
public void testParameterizedTypePatternsSimple() {
PatternParser parser = new PatternParser("List<String>");
WildTypePattern wtp = (WildTypePattern) parser.parseTypePattern();
TypePatternList tvs = wtp.getTypeParameters();
- assertEquals("1 type parameter",1,tvs.getTypePatterns().length);
- assertEquals("String",new PatternParser("String").parseTypePattern(),tvs.getTypePatterns()[0]);
- assertEquals("List",wtp.getNamePatterns()[0].toString());
+ assertEquals("1 type parameter", 1, tvs.getTypePatterns().length);
+ assertEquals("String", new PatternParser("String").parseTypePattern(), tvs.getTypePatterns()[0]);
+ assertEquals("List", wtp.getNamePatterns()[0].toString());
}
-
+
public void testNestedParameterizedTypePatterns() {
PatternParser parser = new PatternParser("List<List<List<String>>>");
WildTypePattern wtp = (WildTypePattern) parser.parseTypePattern();
TypePatternList typeParameters = wtp.getTypeParameters();
WildTypePattern expected = (WildTypePattern) typeParameters.getTypePatterns()[0];
- assertEquals("expecting a List", "List",expected.maybeGetSimpleName());
+ assertEquals("expecting a List", "List", expected.maybeGetSimpleName());
typeParameters = expected.getTypeParameters();
expected = (WildTypePattern) typeParameters.getTypePatterns()[0];
- assertEquals("expecting a List", "List",expected.maybeGetSimpleName());
+ assertEquals("expecting a List", "List", expected.maybeGetSimpleName());
typeParameters = expected.getTypeParameters();
expected = (WildTypePattern) typeParameters.getTypePatterns()[0];
- assertEquals("expecting a String", "String",expected.maybeGetSimpleName());
+ assertEquals("expecting a String", "String", expected.maybeGetSimpleName());
}
public void testSimpleTypeVariableList() {
PatternParser parser = new PatternParser("<T,S,V>");
String[] tl = parser.maybeParseSimpleTypeVariableList();
- assertEquals("3 patterns",3,tl.length);
- assertEquals("T",tl[0]);
- assertEquals("S",tl[1]);
- assertEquals("V",tl[2]);
+ assertEquals("3 patterns", 3, tl.length);
+ assertEquals("T", tl[0]);
+ assertEquals("S", tl[1]);
+ assertEquals("V", tl[2]);
}
-
+
public void testSimpleTypeVariableListError() {
PatternParser parser = new PatternParser("<T extends Number>");
try {
-// String[] tl =
- parser.maybeParseSimpleTypeVariableList();
+ // String[] tl =
+ parser.maybeParseSimpleTypeVariableList();
fail();
} catch (ParserException ex) {
- assertEquals("Expecting ',' or '>'","',' or '>'",ex.getMessage());
- }
+ assertEquals("Expecting ',' or '>'", "',' or '>'", ex.getMessage());
+ }
}
// test cases for pointcuts involving type variable specification.
@@ -406,53 +398,53 @@ public class ParserTestCase extends TestCase {
PatternParser parser = new PatternParser("call<T>(* Foo<T>.*(T))");
try {
parser.parsePointcut();
-// String[] tvps = pc.getTypeVariablesInScope();
-// assertEquals("1 type variable",1,tvps.length);
-// assertEquals("T",tvps[0]);
+ // String[] tvps = pc.getTypeVariablesInScope();
+ // assertEquals("1 type variable",1,tvps.length);
+ // assertEquals("T",tvps[0]);
fail("should have been a parse error");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
+ assertEquals("(", pEx.getMessage());
}
}
-
+
public void testParseCallPCDWithIllegalBounds() {
PatternParser parser = new PatternParser("call<T extends Number>(* Foo<T>.*(T))");
try {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
+ assertEquals("(", pEx.getMessage());
}
}
-
+
public void testNoTypeVarsForHandler() {
PatternParser parser = new PatternParser("handler<T>(Exception<T>)");
try {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
-
+
public void testNoTypeVarsForThis() {
PatternParser parser = new PatternParser("this<T>(Exception<T>)");
try {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
-
+
public void testNoTypeVarsForTarget() {
PatternParser parser = new PatternParser("target<T>(Exception<T>)");
try {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
public void testNoTypeVarsForArgs() {
@@ -461,8 +453,8 @@ public class ParserTestCase extends TestCase {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
public void testNoTypeVarsForIf() {
@@ -471,8 +463,8 @@ public class ParserTestCase extends TestCase {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
public void testNoTypeVarsForCflow() {
@@ -481,8 +473,8 @@ public class ParserTestCase extends TestCase {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
public void testNoTypeVarsForCflowbelow() {
@@ -491,8 +483,8 @@ public class ParserTestCase extends TestCase {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
public void testNoTypeVarsForAtWithin() {
@@ -501,8 +493,8 @@ public class ParserTestCase extends TestCase {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
public void testNoTypeVarsForAtAnnotation() {
@@ -511,8 +503,8 @@ public class ParserTestCase extends TestCase {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
public void testNoTypeVarsForAtWithinCode() {
@@ -521,8 +513,8 @@ public class ParserTestCase extends TestCase {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
public void testNoTypeVarsForAtThis() {
@@ -531,18 +523,18 @@ public class ParserTestCase extends TestCase {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
-
+
public void testNoTypeVarsForAtTarget() {
PatternParser parser = new PatternParser("@target<T>(Exception<T>)");
try {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
public void testNoTypeVarsForAtArgs() {
@@ -551,49 +543,49 @@ public class ParserTestCase extends TestCase {
parser.parsePointcut();
fail("Expecting parse exception");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
-
+
public void testExecutionWithTypeVariables() {
PatternParser parser = new PatternParser("execution<T>(T Bar<T>.doSomething())");
try {
-// Pointcut pc =
- parser.parsePointcut();
-// String[] tvs = pc.getTypeVariablesInScope();
-// assertEquals("1 type pattern",1,tvs.length);
-// assertEquals("T",tvs[0]);
+ // Pointcut pc =
+ parser.parsePointcut();
+ // String[] tvs = pc.getTypeVariablesInScope();
+ // assertEquals("1 type pattern",1,tvs.length);
+ // assertEquals("T",tvs[0]);
fail("should have been a parse error");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
+ assertEquals("(", pEx.getMessage());
}
}
-
+
public void testInitializationWithTypeVariables() {
PatternParser parser = new PatternParser("initialization<T>(Bar<T>.new())");
try {
-// Pointcut pc =
- parser.parsePointcut();
-// String[] tvs = pc.getTypeVariablesInScope();
-// assertEquals("1 type pattern",1,tvs.length);
-// assertEquals("T",tvs[0]);
+ // Pointcut pc =
+ parser.parsePointcut();
+ // String[] tvs = pc.getTypeVariablesInScope();
+ // assertEquals("1 type pattern",1,tvs.length);
+ // assertEquals("T",tvs[0]);
fail("should have been a parse error");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
+ assertEquals("(", pEx.getMessage());
}
}
public void testPreInitializationWithTypeVariables() {
PatternParser parser = new PatternParser("preinitialization<T>(Bar<T>.new())");
try {
-// Pointcut pc =
- parser.parsePointcut();
-// String[] tvs = pc.getTypeVariablesInScope();
-// assertEquals("1 type pattern",1,tvs.length);
-// assertEquals("T",tvs[0]);
+ // Pointcut pc =
+ parser.parsePointcut();
+ // String[] tvs = pc.getTypeVariablesInScope();
+ // assertEquals("1 type pattern",1,tvs.length);
+ // assertEquals("T",tvs[0]);
fail("should have been a parse error");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
+ assertEquals("(", pEx.getMessage());
}
}
@@ -601,112 +593,114 @@ public class ParserTestCase extends TestCase {
PatternParser parser = new PatternParser("staticinitialization<T>(Bar<T>)");
try {
parser.parsePointcut();
-// String[] tvs = pc.getTypeVariablesInScope();
-// assertEquals("1 type pattern",1,tvs.length);
-// assertEquals("T",tvs[0]);
+ // String[] tvs = pc.getTypeVariablesInScope();
+ // assertEquals("1 type pattern",1,tvs.length);
+ // assertEquals("T",tvs[0]);
fail("should have been a parse error");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
+ assertEquals("(", pEx.getMessage());
}
}
-
+
public void testWithinWithTypeVariables() {
PatternParser parser = new PatternParser("within<T>(Bar<T>)");
try {
parser.parsePointcut();
- // String[] tvs = pc.getTypeVariablesInScope();
- // assertEquals("1 type pattern",1,tvs.length);
- // assertEquals("T",tvs[0]);
- fail("should have been a parse error");
+ // String[] tvs = pc.getTypeVariablesInScope();
+ // assertEquals("1 type pattern",1,tvs.length);
+ // assertEquals("T",tvs[0]);
+ fail("should have been a parse error");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
+ assertEquals("(", pEx.getMessage());
}
}
public void testTypeParamList() {
PatternParser parser = new PatternParser("Bar<T,S extends T, R extends S>");
try {
- parser.parseTypePattern(false,false);
-// TypePattern[] tps = tp.getTypeParameters().getTypePatterns();
-// assertEquals("3 type patterns",3,tps.length);
-// assertEquals("T",tps[0].toString());
-// assertEquals("S",tps[1].toString());
-// assertEquals("R",tps[2].toString());
+ parser.parseTypePattern(false, false);
+ // TypePattern[] tps = tp.getTypeParameters().getTypePatterns();
+ // assertEquals("3 type patterns",3,tps.length);
+ // assertEquals("T",tps[0].toString());
+ // assertEquals("S",tps[1].toString());
+ // assertEquals("R",tps[2].toString());
fail("should have been a parse error");
} catch (ParserException pEx) {
- assertEquals(">",pEx.getMessage());
+ assertEquals(">", pEx.getMessage());
}
}
-
+
public void testWithinCodeWithTypeVariables() {
PatternParser parser = new PatternParser("withincode<T,S,R>(Bar<T,S extends T, R extends S>.new())");
try {
parser.parsePointcut();
-// String[] tvs = pc.getTypeVariablesInScope();
-// assertEquals("3 type patterns",3,tvs.length);
-// assertEquals("T",tvs[0]);
-// assertEquals("S",tvs[1]);
-// assertEquals("R",tvs[2]);
- fail("should have been a parse error");
+ // String[] tvs = pc.getTypeVariablesInScope();
+ // assertEquals("3 type patterns",3,tvs.length);
+ // assertEquals("T",tvs[0]);
+ // assertEquals("S",tvs[1]);
+ // assertEquals("R",tvs[2]);
+ fail("should have been a parse error");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
public void testCallWithTypeVariables() {
PatternParser parser = new PatternParser("call<T>(* Bar<T>.*(..))");
try {
-// Pointcut pc =
- parser.parsePointcut();
-// String[] tvs = pc.getTypeVariablesInScope();
-// assertEquals("1 type pattern",1,tvs.length);
-// assertEquals("T",tvs[0]);
+ // Pointcut pc =
+ parser.parsePointcut();
+ // String[] tvs = pc.getTypeVariablesInScope();
+ // assertEquals("1 type pattern",1,tvs.length);
+ // assertEquals("T",tvs[0]);
fail("should have been a parse error");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
public void testGetWithTypeVariables() {
PatternParser parser = new PatternParser("get<T>(* Bar<T>.*)");
try {
-// Pointcut pc =
- parser.parsePointcut();
-// String[] tvs = pc.getTypeVariablesInScope();
-// assertEquals("1 type pattern",1,tvs.length);
-// assertEquals("T",tvs[0]);
+ // Pointcut pc =
+ parser.parsePointcut();
+ // String[] tvs = pc.getTypeVariablesInScope();
+ // assertEquals("1 type pattern",1,tvs.length);
+ // assertEquals("T",tvs[0]);
fail("should have been a parse error");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
public void testSetWithTypeVariables() {
PatternParser parser = new PatternParser("set<T>(* Bar<T>.*)");
try {
-// Pointcut pc =
- parser.parsePointcut();
-// String[] tvs = pc.getTypeVariablesInScope();
-// assertEquals("1 type pattern",1,tvs.length);
-// assertEquals("T",tvs[0]);
+ // Pointcut pc =
+ parser.parsePointcut();
+ // String[] tvs = pc.getTypeVariablesInScope();
+ // assertEquals("1 type pattern",1,tvs.length);
+ // assertEquals("T",tvs[0]);
fail("should have been a parse error");
} catch (ParserException pEx) {
- assertEquals("(",pEx.getMessage());
- }
+ assertEquals("(", pEx.getMessage());
+ }
}
-
+
public void testIntAnnotationVal() {
PatternParser parser = new PatternParser("execution(@ComplexAnnotation(ival=5) * *(..))");
Pointcut pc = parser.parsePointcut();
- assertEquals("Expected annotation value not found","ival=5",getValueString(pc));
+ assertEquals("Expected annotation value not found", "ival=5", getValueString(pc));
}
-
+
private String getValueString(Pointcut pc) {
- if (!(pc instanceof KindedPointcut)) fail("Expected KindedPointcut but was "+pc.getClass());
- KindedPointcut kpc = (KindedPointcut)pc;
+ if (!(pc instanceof KindedPointcut))
+ fail("Expected KindedPointcut but was " + pc.getClass());
+ KindedPointcut kpc = (KindedPointcut) pc;
AnnotationTypePattern atp = kpc.getSignature().getAnnotationPattern();
- if (!(atp instanceof WildAnnotationTypePattern)) fail("Expected WildAnnotationTypePattern but was "+atp.getClass());
- WildAnnotationTypePattern watp = (WildAnnotationTypePattern)atp;
+ if (!(atp instanceof WildAnnotationTypePattern))
+ fail("Expected WildAnnotationTypePattern but was " + atp.getClass());
+ WildAnnotationTypePattern watp = (WildAnnotationTypePattern) atp;
Map m = watp.annotationValues;
Set keys = m.keySet();
List orderedKeys = new ArrayList();
@@ -716,7 +710,8 @@ public class ParserTestCase extends TestCase {
for (Iterator iterator = orderedKeys.iterator(); iterator.hasNext();) {
String object = (String) iterator.next();
sb.append(object).append("=").append(m.get(object));
- if (iterator.hasNext()) sb.append(",");
+ if (iterator.hasNext())
+ sb.append(",");
}
return sb.toString();
}
@@ -724,78 +719,72 @@ public class ParserTestCase extends TestCase {
public void testByteAnnotationVal() {
PatternParser parser = new PatternParser("execution(@ComplexAnnotation(bval=5) * *(..))");
Pointcut pc = parser.parsePointcut();
- assertEquals("Expected annotation value not found","bval=5",getValueString(pc));
+ assertEquals("Expected annotation value not found", "bval=5", getValueString(pc));
}
public void testCharAnnotationVal() {
PatternParser parser = new PatternParser("execution(@ComplexAnnotation(cval='5') * *(..))");
Pointcut pc = parser.parsePointcut();
- assertEquals("Expected annotation value not found","cval='5'",getValueString(pc));
+ assertEquals("Expected annotation value not found", "cval='5'", getValueString(pc));
}
-
+
public void testLongAnnotationVal() {
PatternParser parser = new PatternParser("execution(@ComplexAnnotation(jval=123123) * *(..))");
- Pointcut pc = parser.parsePointcut();
- assertEquals("Expected annotation value not found","jval=123123",getValueString(pc));
+ Pointcut pc = parser.parsePointcut();
+ assertEquals("Expected annotation value not found", "jval=123123", getValueString(pc));
}
public void testDoubleAnnotationVal() {
PatternParser parser = new PatternParser("execution(@ComplexAnnotation(dval=123.3) * *(..))");
Pointcut pc = parser.parsePointcut();
- assertEquals("Expected annotation value not found","dval=123.3",getValueString(pc));
+ assertEquals("Expected annotation value not found", "dval=123.3", getValueString(pc));
}
public void testBooleanAnnotationVal() {
PatternParser parser = new PatternParser("execution(@ComplexAnnotation(zval=true) * *(..))");
Pointcut pc = parser.parsePointcut();
- assertEquals("Expected annotation value not found","zval=true",getValueString(pc));
+ assertEquals("Expected annotation value not found", "zval=true", getValueString(pc));
}
public void testShortAnnotationVal() {
PatternParser parser = new PatternParser("execution(@ComplexAnnotation(sval=43) * *(..))");
Pointcut pc = parser.parsePointcut();
- assertEquals("Expected annotation value not found","sval=43",getValueString(pc));
+ assertEquals("Expected annotation value not found", "sval=43", getValueString(pc));
}
-
+
public void testEnumAnnotationVal() {
PatternParser parser = new PatternParser("execution(@ComplexAnnotation(enumval=Color.GREEN) * *(..))");
Pointcut pc = parser.parsePointcut();
- assertEquals("Expected annotation value not found","enumval=Color.GREEN",getValueString(pc));
+ assertEquals("Expected annotation value not found", "enumval=Color.GREEN", getValueString(pc));
}
public void testStringAnnotationVal() {
PatternParser parser = new PatternParser("execution(@ComplexAnnotation(strval=\"abc\") * *(..))");
Pointcut pc = parser.parsePointcut();
// notice quotes stripped...
- assertEquals("Expected annotation value not found","strval=abc",getValueString(pc));
+ assertEquals("Expected annotation value not found", "strval=abc", getValueString(pc));
}
public void testClassAnnotationVal() {
PatternParser parser = new PatternParser("execution(@ComplexAnnotation(classval=String.class) * *(..))");
Pointcut pc = parser.parsePointcut();
- assertEquals("Expected annotation value not found","classval=String.class",getValueString(pc));
+ assertEquals("Expected annotation value not found", "classval=String.class", getValueString(pc));
}
// failing as {1 is treated as a single token and so we don't realise the , is within the curlies
-// public void testArrayAnnotationVal() {
-// PatternParser parser = new PatternParser("execution(@ComplexAnnotation(arrayval={1,2,3}) * *(..))");
-// Pointcut pc = parser.parsePointcut();
-// assertEquals("Expected annotation value not found","arrayval={1,2,3}",getValueString(pc));
-// }
-
-
-
-
+ // public void testArrayAnnotationVal() {
+ // PatternParser parser = new PatternParser("execution(@ComplexAnnotation(arrayval={1,2,3}) * *(..))");
+ // Pointcut pc = parser.parsePointcut();
+ // assertEquals("Expected annotation value not found","arrayval={1,2,3}",getValueString(pc));
+ // }
+
// ---
-
public TestScope makeSimpleScope() {
world.setBehaveInJava5Way(true);
- TestScope s = new TestScope(new String[] {"int", "java.lang.String"}, new String[] {"a", "b"}, world);
- s.setImportedPrefixes(new String[]{"p."});
+ TestScope s = new TestScope(new String[] { "int", "java.lang.String" }, new String[] { "a", "b" }, world);
+ s.setImportedPrefixes(new String[] { "p." });
return s;
}
}
-
-