import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.ResolvedTypeMunger;
import org.aspectj.weaver.Shadow;
+import org.aspectj.weaver.ShadowMunger;
import org.aspectj.weaver.World;
import org.aspectj.weaver.patterns.DeclareErrorOrWarning;
import org.aspectj.weaver.patterns.IfPointcut;
import org.aspectj.weaver.patterns.Pointcut;
public class CustomMungerExtensionTest extends AjdeInteractionTestbed {
-
- File oldSandBoxDir;
-
- protected void setUp() throws Exception {
- super.setUp();
- oldSandBoxDir = sandboxDir;
- sandboxDir = new File("../tests");
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- sandboxDir = oldSandBoxDir;
- }
-
+
+ File oldSandBoxDir;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ oldSandBoxDir = sandboxDir;
+ sandboxDir = new File("../tests");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ sandboxDir = oldSandBoxDir;
+ }
+
public void testExtension() {
String testFileDir = "bugs/pointcutdoctor-bug193065";
AjCompiler compiler = getCompilerForProjectWithName(testFileDir);
compiler.setCustomMungerFactory(new DumbCustomMungerFactory());
doBuild(testFileDir);
-
- CustomMungerFactory factory = (CustomMungerFactory)compiler.getCustomMungerFactory();
- assertTrue(factory.getAllCreatedCustomShadowMungers().size()>0);
- for (Iterator i = factory.getAllCreatedCustomShadowMungers().iterator(); i.hasNext();)
- assertTrue(((DumbShadowMunger)i.next()).called);
-
- assertTrue(factory.getAllCreatedCustomTypeMungers().size()>0);
- for (Iterator i = factory.getAllCreatedCustomTypeMungers().iterator(); i.hasNext();)
- assertTrue(((DumbTypeMunger)i.next()).called);
+
+ CustomMungerFactory factory = (CustomMungerFactory) compiler.getCustomMungerFactory();
+ assertTrue(factory.getAllCreatedCustomShadowMungers().size() > 0);
+ for (Iterator<ShadowMunger> i = factory.getAllCreatedCustomShadowMungers().iterator(); i.hasNext();) {
+ assertTrue(((DumbShadowMunger) i.next()).called);
+ }
+
+ assertTrue(factory.getAllCreatedCustomTypeMungers().size() > 0);
+ for (Iterator<ConcreteTypeMunger> i = factory.getAllCreatedCustomTypeMungers().iterator(); i.hasNext();) {
+ assertTrue(((DumbTypeMunger) i.next()).called);
+ }
}
-
+
class DumbCustomMungerFactory implements CustomMungerFactory {
- Collection allShadowMungers = new ArrayList();
- Collection allTypeMungers = new ArrayList();
- public Collection createCustomShadowMungers(ResolvedType aspectType) {
- List/* ShadowMunger */ mungers = new ArrayList/*ShadowMunger*/();
+ Collection<ShadowMunger> allShadowMungers = new ArrayList<ShadowMunger>();
+ Collection<ConcreteTypeMunger> allTypeMungers = new ArrayList<ConcreteTypeMunger>();
+
+ public Collection<ShadowMunger> createCustomShadowMungers(ResolvedType aspectType) {
+ List<ShadowMunger> mungers = new ArrayList<ShadowMunger>();
Pointcut pointcut = new IfPointcut("abc");
mungers.add(new DumbShadowMunger(new DeclareErrorOrWarning(false, pointcut, "")));
allShadowMungers.addAll(mungers);
return mungers;
}
- public Collection createCustomTypeMungers(ResolvedType aspectType) {
- List/*ConcreteTypeMunger*/ mungers = new ArrayList/*ShadowMunger*/();
+ public Collection<ConcreteTypeMunger> createCustomTypeMungers(ResolvedType aspectType) {
+ List<ConcreteTypeMunger> mungers = new ArrayList<ConcreteTypeMunger>();
mungers.add(new DumbTypeMunger(null, aspectType));
allTypeMungers.addAll(mungers);
return mungers;
}
- public Collection getAllCreatedCustomShadowMungers() {
+ public Collection<ShadowMunger> getAllCreatedCustomShadowMungers() {
return allShadowMungers;
}
- public Collection getAllCreatedCustomTypeMungers() {
+ public Collection<ConcreteTypeMunger> getAllCreatedCustomTypeMungers() {
return allTypeMungers;
}
}
public ConcreteTypeMunger parameterizedFor(ResolvedType targetType) {
return null;
}
-
+
public boolean matches(ResolvedType onType) {
called = true;
return false;
}
- public ConcreteTypeMunger parameterizeWith(Map parameterizationMap,
- World world) {
+ public ConcreteTypeMunger parameterizeWith(Map parameterizationMap, World world) {
// TODO Auto-generated method stub
return null;
}
*******************************************************************************/
package org.aspectj.systemtest.ajc169;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.PrintWriter;
import junit.framework.Test;
import org.aspectj.apache.bcel.classfile.JavaClass;
import org.aspectj.apache.bcel.util.ClassPath;
import org.aspectj.apache.bcel.util.SyntheticRepository;
+import org.aspectj.asm.AsmManager;
import org.aspectj.testing.XMLBasedAjcTestCase;
/**
runTest("choice");
}
+ public void testRooScenario2() throws Exception {
+ runTest("choice2");
+ }
+
+ public void testRooScenarioWeaveInfo() throws Exception {
+ runTest("choice - weaveinfo");
+ }
+
+ public void testModel() throws Exception {
+ runTest("choice - model");
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ PrintWriter pw = new PrintWriter(baos);
+ AsmManager.dumptree(pw, AsmManager.lastActiveStructureModel.getHierarchy().getRoot(), 0);
+ pw.write(AsmManager.lastActiveStructureModel.getRelationshipMap().toString());
+ pw.flush();
+ String model = baos.toString();
+ assertTrue(model.indexOf("<{Choice.java[Choice=[aspect declarations], <{Choice.java}X[Keys=[declared on]") != -1);
+ }
+
+ public void testGenerics1() throws Exception {
+ runTest("choice - generics 1");
+ }
+
+ public void testGenerics2() throws Exception {
+ runTest("choice - generics 2");
+ }
+
// compiler limitation tests
public void testNotAllowedOnInterface() throws Exception {
runTest("on interface");
<suite>
+ <ajc-test dir="features169/itdInnerTypes" title="choice - generics 1">
+ <compile files="ChoiceGenerics1.java" options="-1.5"/>
+ </ajc-test>
+
+ <ajc-test dir="features169/itdInnerTypes" title="choice - generics 2">
+ <compile files="ChoiceGenerics2.java" options="-1.5">
+ <message kind="error" text="Type mismatch: cannot convert from String to Integer"/>
+ </compile>
+ </ajc-test>
+
<ajc-test dir="features169/itdInnerTypes" title="choice">
<compile files="Choice.java" options="-1.5"/>
<run class="Choice">
</stdout></run>
</ajc-test>
+ <ajc-test dir="features169/itdInnerTypes" title="choice - weaveinfo">
+ <compile files="Choice.java" options="-1.5 -showWeaveInfo">
+ <message kind="weave" text="Type 'Choice' (Choice.java) has intertyped member class from 'X' (Choice.java)"/>
+ </compile>
+ </ajc-test>
+
+ <ajc-test dir="features169/itdInnerTypes" title="choice - model">
+ <compile files="Choice.java" options="-1.5 -emacssym"/>
+ </ajc-test>
+
+ <ajc-test dir="features169/itdInnerTypes" title="choice2">
+ <compile files="Choice2.java" options="-1.5"/>
+ <run class="Choice2">
+ <stdout>
+ <line text="null"/>
+ </stdout></run>
+ </ajc-test>
+
<ajc-test dir="features169/itdInnerTypes" title="field access">
<compile files="FieldAccess.java" options="-1.5"/>
<run class="FieldAccess">