]> source.dussan.org Git - aspectj.git/commitdiff
251277: making asmmanager non-singleton
authoraclement <aclement>
Mon, 20 Oct 2008 04:38:55 +0000 (04:38 +0000)
committeraclement <aclement>
Mon, 20 Oct 2008 04:38:55 +0000 (04:38 +0000)
ajde.core/src/org/aspectj/ajde/core/AjCompiler.java
ajde.core/src/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java
ajde.core/testsrc/org/aspectj/ajde/core/AjdeCoreTestCase.java
ajde.core/testsrc/org/aspectj/ajde/core/tests/model/AsmDeclarationsTests.java
ajde.core/testsrc/org/aspectj/ajde/core/tests/model/AsmRelationshipsTests.java
ajde.core/testsrc/org/aspectj/ajde/core/tests/model/SavedModelConsistencyTests.java
ajde.core/testsrc/org/aspectj/ajde/core/tests/model/StructureModelTests.java

index 72eb4058c333d21a839e64c5f97503476a7dd605..5755c4173b2e6ed5fc46d49f0274aff1c2ad2fad 100644 (file)
@@ -12,6 +12,7 @@ package org.aspectj.ajde.core;
 
 import org.aspectj.ajde.core.internal.AjdeCoreBuildManager;
 import org.aspectj.ajdt.internal.core.builder.IncrementalStateManager;
+import org.aspectj.asm.AsmManager;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.Message;
 import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
@@ -148,4 +149,12 @@ public class AjCompiler {
        public Object getCustomMungerFactory() {
                return buildManager.getCustomMungerFactory();
        }
+
+       public AsmManager getModel() {
+               return buildManager.getStructureModel();
+       }
+
+       // public AsmManager getStructureModel() {
+       // return buildManager.getStructureModel();
+       // }
 }
index 074222b51f3e0aafa435a8b11e687c6546c57bd6..db4fe814de92e304844c8a1ace0ba96d9dd72943 100644 (file)
@@ -63,6 +63,10 @@ public class AjdeCoreBuildManager {
                AsmManager.attemptIncrementalModelRepairs = true;
        }
 
+       // public AsmManager getStructureModel() {
+       // return ajBuildManager.
+       // }
+
        /**
         * Execute a full or incremental build
         * 
@@ -77,8 +81,9 @@ public class AjdeCoreBuildManager {
                                // No existing state so we must do a full build
                                fullBuild = true;
                        } else {
-                               AsmManager.getDefault().setRelationshipMap(existingState.getRelationshipMap());
-                               AsmManager.getDefault().setHierarchy(existingState.getStructureModel());
+                               AsmManager.setLastActiveStructureModel(existingState.getStructureModel());
+                               // AsmManager.getDefault().setRelationshipMap(existingState.getRelationshipMap());
+                               // AsmManager.getDefault().setHierarchy(existingState.getStructureModel());
                        }
                }
                try {
@@ -394,4 +399,8 @@ public class AjdeCoreBuildManager {
        public void cleanupEnvironment() {
                ajBuildManager.cleanupEnvironment();
        }
+
+       public AsmManager getStructureModel() {
+               return ajBuildManager.getStructureModel();
+       }
 }
index 80a98aa18d0471a3bdc3a7a109722bf76b12e2ba..62c8ea88be9c898ab3fb318e757a3db4266f6cbc 100644 (file)
@@ -19,104 +19,98 @@ import java.util.List;
 import junit.framework.AssertionFailedError;
 import junit.framework.TestCase;
 
-import org.aspectj.asm.AsmManager;
 import org.aspectj.tools.ajc.Ajc;
 
 /**
- * Testcase class to be used by all ajde.core tests. Provides
- * helper methods to set up the environment in a sandbox
- * as well as to drive a build.
+ * Testcase class to be used by all ajde.core tests. Provides helper methods to set up the environment in a sandbox as well as to
+ * drive a build.
  */
 public class AjdeCoreTestCase extends TestCase {
 
-    public final static String testdataSrcDir = "../ajde.core/testdata";
+       public final static String testdataSrcDir = "../ajde.core/testdata";
        protected static File sandboxDir;
-       
+
        private String projectDir;
-    private AjCompiler compiler;
+       private AjCompiler compiler;
 
-    
        protected void setUp() throws Exception {
                super.setUp();
                // Create a sandbox in which to work
                sandboxDir = Ajc.createEmptySandbox();
-               // AMC - added this next line as a temporary workaround for 
+               // AMC - added this next line as a temporary workaround for
                // listener leakage in AsmManager induced by the Ajde test suite.
-               AsmManager.getDefault().removeAllListeners();
+               // AsmManager.getDefault().removeAllListeners();
        }
-       
+
        protected void tearDown() throws Exception {
                super.tearDown();
                compiler.clearLastState();
                compiler = null;
        }
-       
+
        /**
-        * Fill in the working directory with the project files and
-        * creates a compiler instance for this project
+        * Fill in the working directory with the project files and creates a compiler instance for this project
         */
        public void initialiseProject(String projectName) throws IOException {
-               File projectSrc=new File(testdataSrcDir + File.separatorChar + projectName);
-               File destination=new File(getWorkingDir(),projectName);
-               if (!destination.exists()) {destination.mkdir();}
-               copy(projectSrc,destination);
-               projectDir = destination.getCanonicalPath();//getAbsolutePath();
-               
-               compiler = new AjCompiler(
-                               projectDir,
-                               new TestCompilerConfiguration(projectDir),
-                               new TestBuildProgressMonitor(),
-                               new TestMessageHandler()); 
+               File projectSrc = new File(testdataSrcDir + File.separatorChar + projectName);
+               File destination = new File(getWorkingDir(), projectName);
+               if (!destination.exists()) {
+                       destination.mkdir();
+               }
+               copy(projectSrc, destination);
+               projectDir = destination.getCanonicalPath();// getAbsolutePath();
+
+               compiler = new AjCompiler(projectDir, new TestCompilerConfiguration(projectDir), new TestBuildProgressMonitor(),
+                               new TestMessageHandler());
        }
-       
+
        /**
         * @return the working directory
         */
-       protected File getWorkingDir() { 
-               return sandboxDir; 
+       protected File getWorkingDir() {
+               return sandboxDir;
        }
-       
+
        /**
-        * @return the absolute path of the project directory
-        * for example c:\temp\ajcSandbox\ajcTest15200.tmp\myProject
+        * @return the absolute path of the project directory for example c:\temp\ajcSandbox\ajcTest15200.tmp\myProject
         */
        protected String getAbsoluteProjectDir() {
                return projectDir;
        }
-       
+
        /**
-        * Copy the contents of some directory to another location - the
-        * copy is recursive.
+        * Copy the contents of some directory to another location - the copy is recursive.
         */
        private void copy(File from, File to) {
                String contents[] = from.list();
-               if (contents==null) return;
+               if (contents == null)
+                       return;
                for (int i = 0; i < contents.length; i++) {
                        String string = contents[i];
-                       File f = new File(from,string);
-                       File t = new File(to,string);
-                       
+                       File f = new File(from, string);
+                       File t = new File(to, string);
+
                        if (f.isDirectory()) {
                                t.mkdir();
-                               copy(f,t);
+                               copy(f, t);
                        } else if (f.isFile()) {
                                try {
-                                       org.aspectj.util.FileUtil.copyFile(f,t);
+                                       org.aspectj.util.FileUtil.copyFile(f, t);
                                } catch (IOException e) {
                                        throw new AssertionFailedError("Unable to copy " + f + " to " + t);
                                }
-                       } 
+                       }
                }
        }
-       
+
        protected File openFile(String path) {
                return new File(projectDir + File.separatorChar + path);
        }
-       
+
        public void doBuild() {
                doBuild(true);
        }
-       
+
        public void doBuild(boolean buildFresh) {
                if (buildFresh) {
                        compiler.buildFresh();
@@ -124,29 +118,29 @@ public class AjdeCoreTestCase extends TestCase {
                        compiler.build();
                }
        }
-       
+
        public AjCompiler getCompiler() {
                return compiler;
        }
-       
+
        public boolean checkFor(String what) {
-               List ll = ((TestMessageHandler)compiler.getMessageHandler()).getMessages();
+               List ll = ((TestMessageHandler) compiler.getMessageHandler()).getMessages();
                for (Iterator iter = ll.iterator(); iter.hasNext();) {
-                       Object element =  iter.next();
+                       Object element = iter.next();
                        if (element.toString().indexOf(what) != -1)
                                return true;
                }
                return false;
        }
-       
+
        public void dumpTaskData() {
-               List ll = ((TestMessageHandler)compiler.getMessageHandler()).getMessages();
+               List ll = ((TestMessageHandler) compiler.getMessageHandler()).getMessages();
                for (Iterator iter = ll.iterator(); iter.hasNext();) {
-                       Object element =  iter.next();
-                       System.out.println("RecordedMessage>"+element);
+                       Object element = iter.next();
+                       System.out.println("RecordedMessage>" + element);
                }
        }
-       
+
        public List getSourceFileList(String[] files) {
                List sourceFiles = new ArrayList();
                for (int i = 0; i < files.length; i++) {
@@ -154,5 +148,5 @@ public class AjdeCoreTestCase extends TestCase {
                }
                return sourceFiles;
        }
-       
+
 }
index 1ce8e88a8204df7bf392dcfbe7189a1f65602c5b..046bd6688dc5ab7c85081336451a4732b5f2a863 100644 (file)
@@ -19,6 +19,7 @@ import org.aspectj.asm.IProgramElement;
 
 public class AsmDeclarationsTests extends AjdeCoreTestCase {
 
+       private AsmManager manager = null;
        private IHierarchy model = null;
 
        private final String[] files = new String[] { "ModelCoverage.java", "pkg" + File.separator + "InPackage.java" };
@@ -31,7 +32,8 @@ public class AsmDeclarationsTests extends AjdeCoreTestCase {
                compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
                compilerConfig.setProjectSourceFiles(getSourceFileList(files));
                doBuild();
-               model = AsmManager.getDefault().getHierarchy();
+               manager = AsmManager.lastActiveStructureModel;
+               model = AsmManager.lastActiveStructureModel.getHierarchy();
        }
 
        protected void tearDown() throws Exception {
@@ -47,7 +49,7 @@ public class AsmDeclarationsTests extends AjdeCoreTestCase {
        }
 
        public void testAspectAccessibility() {
-               IProgramElement packageAspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AdviceNamingCoverage");
+               IProgramElement packageAspect = model.findElementForType(null, "AdviceNamingCoverage");
                assertNotNull(packageAspect);
                assertEquals(IProgramElement.Accessibility.PACKAGE, packageAspect.getAccessibility());
                assertEquals("aspect should not have public in it's signature", "aspect AdviceNamingCoverage", packageAspect
@@ -55,7 +57,7 @@ public class AsmDeclarationsTests extends AjdeCoreTestCase {
        }
 
        public void testStaticModifiers() {
-               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "ModifiersCoverage");
+               IProgramElement aspect = model.findElementForType(null, "ModifiersCoverage");
                assertNotNull(aspect);
 
                IProgramElement staticA = model.findElementForSignature(aspect, IProgramElement.Kind.FIELD, "staticA");
@@ -64,7 +66,6 @@ public class AsmDeclarationsTests extends AjdeCoreTestCase {
                IProgramElement finalA = model.findElementForSignature(aspect, IProgramElement.Kind.FIELD, "finalA");
                assertTrue(!finalA.getModifiers().contains(IProgramElement.Modifiers.STATIC));
                assertTrue(finalA.getModifiers().contains(IProgramElement.Modifiers.FINAL));
-
        }
 
        public void testFileInPackageAndDefaultPackage() {
@@ -81,7 +82,7 @@ public class AsmDeclarationsTests extends AjdeCoreTestCase {
                IProgramElement node = model.getRoot();
                assertNotNull(node);
 
-               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "DeclareCoverage");
+               IProgramElement aspect = model.findElementForType(null, "DeclareCoverage");
                assertNotNull(aspect);
 
                String label = "declare error: \"Illegal construct..\"";
@@ -123,7 +124,7 @@ public class AsmDeclarationsTests extends AjdeCoreTestCase {
                IProgramElement node = model.getRoot();
                assertNotNull(node);
 
-               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "InterTypeDecCoverage");
+               IProgramElement aspect = model.findElementForType(null, "InterTypeDecCoverage");
                assertNotNull(aspect);
 
                String fieldMsg = "Point.xxx";
@@ -148,7 +149,7 @@ public class AsmDeclarationsTests extends AjdeCoreTestCase {
                IProgramElement node = model.getRoot();
                assertNotNull(node);
 
-               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AdviceNamingCoverage");
+               IProgramElement aspect = model.findElementForType(null, "AdviceNamingCoverage");
                assertNotNull(aspect);
 
                String ptct = "named()";
@@ -166,7 +167,7 @@ public class AsmDeclarationsTests extends AjdeCoreTestCase {
                IProgramElement node = model.getRoot();
                assertNotNull(node);
 
-               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AbstractAspect");
+               IProgramElement aspect = model.findElementForType(null, "AbstractAspect");
                assertNotNull(aspect);
 
                String abst = "abPtct()";
@@ -179,7 +180,7 @@ public class AsmDeclarationsTests extends AjdeCoreTestCase {
                IProgramElement node = model.getRoot();
                assertNotNull(node);
 
-               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "AdviceNamingCoverage");
+               IProgramElement aspect = model.findElementForType(null, "AdviceNamingCoverage");
                assertNotNull(aspect);
 
                String anon = "before(): <anonymous pointcut>";
index 919eec6e3da54f84045cd197ed42ea6257e62341..14217aa84fa22e8f56442d4c6e7d09f045c2d9e2 100644 (file)
@@ -16,7 +16,6 @@ import java.util.List;
 
 import org.aspectj.ajde.core.AjdeCoreTestCase;
 import org.aspectj.ajde.core.TestCompilerConfiguration;
-import org.aspectj.ajdt.internal.core.builder.AsmHierarchyBuilder;
 import org.aspectj.asm.AsmManager;
 import org.aspectj.asm.IProgramElement;
 import org.aspectj.asm.IRelationship;
@@ -25,21 +24,17 @@ public class AsmRelationshipsTests extends AjdeCoreTestCase {
 
        private AsmManager manager = null;
 
-       private String[] files = new String[]{
-                       "ModelCoverage.java",
-                       "pkg" + File.separator + "InPackage.java"
-       };
-       
+       private final String[] files = new String[] { "ModelCoverage.java", "pkg" + File.separator + "InPackage.java" };
+
        private TestCompilerConfiguration compilerConfig;
 
        protected void setUp() throws Exception {
                super.setUp();
                initialiseProject("coverage");
-               compilerConfig = (TestCompilerConfiguration) getCompiler()
-                               .getCompilerConfiguration();
+               compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
                compilerConfig.setProjectSourceFiles(getSourceFileList(files));
                doBuild();
-               manager = AsmManager.getDefault();
+               manager = AsmManager.lastActiveStructureModel;
        }
 
        protected void tearDown() throws Exception {
@@ -47,155 +42,152 @@ public class AsmRelationshipsTests extends AjdeCoreTestCase {
                compilerConfig = null;
                manager = null;
        }
-       
-       // see pr148027
-       public void testUsesPointcut() {
-               if (!AsmHierarchyBuilder.shouldAddUsesPointcut) return;
-               
-           IProgramElement ptUsage = AsmManager.getDefault().getHierarchy().findElementForType(null, "PointcutUsage");
-           assertNotNull(ptUsage);
-           IProgramElement pts = AsmManager.getDefault().getHierarchy().findElementForType(null, "Pointcuts");
-           assertNotNull(pts);
-           
-               IProgramElement pUsesA = manager.getHierarchy().findElementForLabel(
-                       ptUsage, 
-                               IProgramElement.Kind.POINTCUT, 
-                               "usesA()"/*Point"*/);
-               assertNotNull(pUsesA);
-
-               IProgramElement ptsA = manager.getHierarchy().findElementForLabel(
-                       pts, 
-                               IProgramElement.Kind.POINTCUT, 
-                               "a()"/*Point"*/);
-               assertNotNull(ptsA);
-               
-               assertTrue(AsmManager.getDefault().getRelationshipMap().get(pUsesA).size()>0);
-               assertTrue(AsmManager.getDefault().getRelationshipMap().get(ptsA).size()>0);
-       }
-       
-       public void testDeclareParents() {              
-               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, "DeclareCoverage");
-
-               IProgramElement dp = manager.getHierarchy().findElementForLabel(
-                               aspect, 
-                               IProgramElement.Kind.DECLARE_PARENTS, 
-                               "declare parents: implements Serializable"/*Point"*/);
-               
+
+       // // see pr148027
+       // public void testUsesPointcut() {
+       // if (!AsmHierarchyBuilder.shouldAddUsesPointcut) return;
+       //              
+       // IProgramElement ptUsage = AsmManager.getDefault().getHierarchy().findElementForType(null, "PointcutUsage");
+       // assertNotNull(ptUsage);
+       // IProgramElement pts = AsmManager.getDefault().getHierarchy().findElementForType(null, "Pointcuts");
+       // assertNotNull(pts);
+       //          
+       // IProgramElement pUsesA = manager.getHierarchy().findElementForLabel(
+       // ptUsage,
+       // IProgramElement.Kind.POINTCUT,
+       // "usesA()"/*Point"*/);
+       // assertNotNull(pUsesA);
+       //
+       // IProgramElement ptsA = manager.getHierarchy().findElementForLabel(
+       // pts,
+       // IProgramElement.Kind.POINTCUT,
+       // "a()"/*Point"*/);
+       // assertNotNull(ptsA);
+       //              
+       // assertTrue(AsmManager.getDefault().getRelationshipMap().get(pUsesA).size()>0);
+       // assertTrue(AsmManager.getDefault().getRelationshipMap().get(ptsA).size()>0);
+       // }
+
+       public void testDeclareParents() {
+               IProgramElement aspect = manager.getHierarchy().findElementForType(null, "DeclareCoverage");
+
+               IProgramElement dp = manager.getHierarchy().findElementForLabel(aspect, IProgramElement.Kind.DECLARE_PARENTS,
+                               "declare parents: implements Serializable"/* Point" */);
+
                assertNotNull(dp);
-               /*List relations = */manager.getRelationshipMap().get(dp);
-                               
-               List rels = AsmManager.getDefault().getRelationshipMap().get(dp);
-               assertTrue(rels.size()>0);
-               
-//             assertTrue(rel.getTargets().size() > 0);
-//             
-//             checkDeclareMapping("DeclareCoverage", "Point", , 
-//                     "Point", "matched by", "matches declare", 
-//                     IProgramElement.Kind.DECLARE_PARENTS);          
+               /* List relations = */manager.getRelationshipMap().get(dp);
+
+               List rels = manager.getRelationshipMap().get(dp);
+               assertTrue(rels.size() > 0);
+
+               // assertTrue(rel.getTargets().size() > 0);
+               //              
+               // checkDeclareMapping("DeclareCoverage", "Point", ,
+               // "Point", "matched by", "matches declare",
+               // IProgramElement.Kind.DECLARE_PARENTS);
        }
-       
-       public void testDeclareWarningAndError() {              
-               checkDeclareMapping("DeclareCoverage", "Point", "declare warning: \"Illegal call.\"", 
-                       "method-call(void Point.setX(int))", "matched by", "matches declare", IProgramElement.Kind.DECLARE_WARNING);            
+
+       public void testDeclareWarningAndError() {
+               checkDeclareMapping("DeclareCoverage", "Point", "declare warning: \"Illegal call.\"", "method-call(void Point.setX(int))",
+                               "matched by", "matches declare", IProgramElement.Kind.DECLARE_WARNING);
        }
-       
-       public void testInterTypeDeclarations() {               
-               checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.xxx", "Point", 
-                       "declared on", "aspect declarations", IProgramElement.Kind.INTER_TYPE_FIELD);   
-               checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.check(int,Line)", 
-                       "Point", "declared on", "aspect declarations", IProgramElement.Kind.INTER_TYPE_METHOD); 
+
+       public void testInterTypeDeclarations() {
+               checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.xxx", "Point", "declared on", "aspect declarations",
+                               IProgramElement.Kind.INTER_TYPE_FIELD);
+               checkInterTypeMapping("InterTypeDecCoverage", "Point", "Point.check(int,Line)", "Point", "declared on",
+                               "aspect declarations", IProgramElement.Kind.INTER_TYPE_METHOD);
        }
 
-       public void testAdvice() {      
-               checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..", 
-                       "setX(int)", "advises", "advised by");
-               checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): getP..", 
-                       "field-get(int Point.x)", "advises");
-               checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): setP..", 
-                       "field-set(int Point.x)", "advises");   
+       public void testAdvice() {
+               checkMapping("AdvisesRelationshipCoverage", "Point", "before(): methodExecutionP..", "setX(int)", "advises", "advised by");
+               checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): getP..", "field-get(int Point.x)", "advises");
+               checkUniDirectionalMapping("AdvisesRelationshipCoverage", "Point", "before(): setP..", "field-set(int Point.x)", "advises");
        }
 
-       private void checkDeclareMapping(String fromType, String toType, String from, String to, 
-               String forwardRelName, String backRelName, IProgramElement.Kind kind) {
-               
-               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
-               assertNotNull(aspect);          
+       private void checkDeclareMapping(String fromType, String toType, String from, String to, String forwardRelName,
+                       String backRelName, IProgramElement.Kind kind) {
+
+               IProgramElement aspect = manager.getHierarchy().findElementForType(null, fromType);
+               assertNotNull(aspect);
                String beforeExec = from;
                IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, kind, beforeExec);
                assertNotNull(beforeExecNode);
                IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.DECLARE, forwardRelName);
                assertTrue(rel.getTargets().size() > 0);
-               String handle = (String)rel.getTargets().get(0);
-               assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);  
+               String handle = (String) rel.getTargets().get(0);
+               assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);
 
-               IProgramElement clazz = AsmManager.getDefault().getHierarchy().findElementForType(null, toType);
+               IProgramElement clazz = manager.getHierarchy().findElementForType(null, toType);
                assertNotNull(clazz);
                String set = to;
                IProgramElement setNode = manager.getHierarchy().findElementForLabel(clazz, IProgramElement.Kind.CODE, set);
                assertNotNull(setNode);
                IRelationship rel2 = manager.getRelationshipMap().get(setNode, IRelationship.Kind.DECLARE, backRelName);
-               String handle2 = (String)rel2.getTargets().get(0);
+               String handle2 = (String) rel2.getTargets().get(0);
                assertEquals(manager.getHierarchy().findElementForHandle(handle2).toString(), from);
        }
-       
-       private void checkUniDirectionalMapping(String fromType, String toType, String from, 
-               String to, String relName) {
-               
-               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
-               assertNotNull(aspect);          
+
+       private void checkUniDirectionalMapping(String fromType, String toType, String from, String to, String relName) {
+
+               IProgramElement aspect = manager.getHierarchy().findElementForType(null, fromType);
+               assertNotNull(aspect);
                String beforeExec = from;
-               IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec);
+               IProgramElement beforeExecNode = manager.getHierarchy()
+                               .findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec);
                assertNotNull(beforeExecNode);
                IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, relName);
-               for (Iterator it = rel.getTargets().iterator(); it.hasNext(); ) {
-                       String currHandle = (String)it.next();
-                       if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(to)) return;
+               for (Iterator it = rel.getTargets().iterator(); it.hasNext();) {
+                       String currHandle = (String) it.next();
+                       if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(to))
+                               return;
                }
                fail(); // didn't find it
        }
 
-       private void checkMapping(String fromType, String toType, String from, String to, 
-               String forwardRelName, String backRelName) {
-               
-               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
-               assertNotNull(aspect);          
+       private void checkMapping(String fromType, String toType, String from, String to, String forwardRelName, String backRelName) {
+
+               IProgramElement aspect = manager.getHierarchy().findElementForType(null, fromType);
+               assertNotNull(aspect);
                String beforeExec = from;
-               IProgramElement beforeExecNode = manager.getHierarchy().findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec);
+               IProgramElement beforeExecNode = manager.getHierarchy()
+                               .findElementForLabel(aspect, IProgramElement.Kind.ADVICE, beforeExec);
                assertNotNull(beforeExecNode);
                IRelationship rel = manager.getRelationshipMap().get(beforeExecNode, IRelationship.Kind.ADVICE, forwardRelName);
-               String handle = (String)rel.getTargets().get(0);
-               assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);  
+               String handle = (String) rel.getTargets().get(0);
+               assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);
 
-               IProgramElement clazz = AsmManager.getDefault().getHierarchy().findElementForType(null, toType);
+               IProgramElement clazz = manager.getHierarchy().findElementForType(null, toType);
                assertNotNull(clazz);
                String set = to;
                IProgramElement setNode = manager.getHierarchy().findElementForLabel(clazz, IProgramElement.Kind.METHOD, set);
                assertNotNull(setNode);
                IRelationship rel2 = manager.getRelationshipMap().get(setNode, IRelationship.Kind.ADVICE, backRelName);
-               String handle2 = (String)rel2.getTargets().get(0);
+               String handle2 = (String) rel2.getTargets().get(0);
                assertEquals(manager.getHierarchy().findElementForHandle(handle2).toString(), from);
        }
 
-       private void checkInterTypeMapping(String fromType, String toType, String from, 
-               String to, String forwardRelName, String backRelName, IProgramElement.Kind declareKind) {
-               
-               IProgramElement aspect = AsmManager.getDefault().getHierarchy().findElementForType(null, fromType);
-               assertNotNull(aspect);          
+       private void checkInterTypeMapping(String fromType, String toType, String from, String to, String forwardRelName,
+                       String backRelName, IProgramElement.Kind declareKind) {
+
+               IProgramElement aspect = manager.getHierarchy().findElementForType(null, fromType);
+               assertNotNull(aspect);
                String beforeExec = from;
                IProgramElement fromNode = manager.getHierarchy().findElementForLabel(aspect, declareKind, beforeExec);
                assertNotNull(fromNode);
                IRelationship rel = manager.getRelationshipMap().get(fromNode, IRelationship.Kind.DECLARE_INTER_TYPE, forwardRelName);
-               String handle = (String)rel.getTargets().get(0);
-               assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);  
+               String handle = (String) rel.getTargets().get(0);
+               assertEquals(manager.getHierarchy().findElementForHandle(handle).toString(), to);
 
-               IProgramElement clazz = AsmManager.getDefault().getHierarchy().findElementForType(null, toType);
+               IProgramElement clazz = manager.getHierarchy().findElementForType(null, toType);
                assertNotNull(clazz);
-//             String set = to;
+               // String set = to;
                IRelationship rel2 = manager.getRelationshipMap().get(clazz, IRelationship.Kind.DECLARE_INTER_TYPE, backRelName);
-//             String handle2 = (String)rel2.getTargets().get(0);
-               for (Iterator it = rel2.getTargets().iterator(); it.hasNext(); ) {
-                       String currHandle = (String)it.next();
-                       if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(from)) return;
+               // String handle2 = (String)rel2.getTargets().get(0);
+               for (Iterator it = rel2.getTargets().iterator(); it.hasNext();) {
+                       String currHandle = (String) it.next();
+                       if (manager.getHierarchy().findElementForHandle(currHandle).toLabelString().equals(from))
+                               return;
                }
                fail(); // didn't find it
        }
index 99f6e354f5ba1869f09196ca229f2158e2fb180a..5c97bcbe7462c29696f8f072c712675bb542efee 100644 (file)
@@ -26,11 +26,8 @@ import org.aspectj.asm.IProgramElement;
 
 public class SavedModelConsistencyTests extends AjdeCoreTestCase {
 
-       private String[] files = new String[]{
-                       "ModelCoverage.java",
-                       "pkg" + File.separator + "InPackage.java"
-       };
-       
+       private final String[] files = new String[] { "ModelCoverage.java", "pkg" + File.separator + "InPackage.java" };
+
        private TestMessageHandler handler;
        private TestCompilerConfiguration compilerConfig;
 
@@ -38,18 +35,16 @@ public class SavedModelConsistencyTests extends AjdeCoreTestCase {
                super.setUp();
                initialiseProject("coverage");
                handler = (TestMessageHandler) getCompiler().getMessageHandler();
-               compilerConfig = (TestCompilerConfiguration) getCompiler()
-                               .getCompilerConfiguration();
+               compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
                compilerConfig.setProjectSourceFiles(getSourceFileList(files));
                // In order to get a model on the disk to read in, do a build with the right flag set !
                try {
-                       AsmManager.dumpModelPostBuild=true;
+                       AsmManager.dumpModelPostBuild = true;
                        doBuild();
                } finally {
-                       AsmManager.dumpModelPostBuild=false;
+                       AsmManager.dumpModelPostBuild = false;
                }
-               assertTrue("Expected no compiler errors but found "
-                               + handler.getErrors(), handler.getErrors().isEmpty());
+               assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty());
        }
 
        protected void tearDown() throws Exception {
@@ -57,63 +52,61 @@ public class SavedModelConsistencyTests extends AjdeCoreTestCase {
                handler = null;
                compilerConfig = null;
        }
-       
+
        public void testInterfaceIsSameInBoth() {
-               AsmManager.getDefault().readStructureModel(getAbsoluteProjectDir());
-               
-        IHierarchy model = AsmManager.getDefault().getHierarchy();
-        assertTrue("model exists", model != null);
-        
-               assertTrue("root exists", model.getRoot() != null);        // TODO-path
+               AsmManager asm = AsmManager.createNewStructureModel();
+               asm.readStructureModel(getAbsoluteProjectDir());
+
+               IHierarchy model = asm.getHierarchy();
+               assertTrue("model exists", model != null);
+
+               assertTrue("root exists", model.getRoot() != null); // TODO-path
                File testFile = openFile("ModelCoverage.java");
                assertTrue("Expected " + testFile.getAbsolutePath() + " to exist, but it did not", testFile.exists());
-               
-               IProgramElement nodePreBuild = model.findElementForSourceLine(testFile.getAbsolutePath(), 5);   
-               
+
+               IProgramElement nodePreBuild = model.findElementForSourceLine(testFile.getAbsolutePath(), 5);
+
                doBuild();
-               assertTrue("Expected no compiler errors but found "
-                               + handler.getErrors(), handler.getErrors().isEmpty());
-               
-               IProgramElement nodePostBuild = model.findElementForSourceLine(testFile.getAbsolutePath(), 5);  
-               
-               assertTrue("Nodes should be identical: Prebuild kind = "+nodePreBuild.getKind()+
-                                  "   Postbuild kind = "+nodePostBuild.getKind(),
-                                  nodePreBuild.getKind().equals(nodePostBuild.getKind()));
-               
+               assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty());
+
+               IProgramElement nodePostBuild = model.findElementForSourceLine(testFile.getAbsolutePath(), 5);
+
+               assertTrue("Nodes should be identical: Prebuild kind = " + nodePreBuild.getKind() + "   Postbuild kind = "
+                               + nodePostBuild.getKind(), nodePreBuild.getKind().equals(nodePostBuild.getKind()));
+
        }
-       
+
        public void testModelIsSamePreAndPostBuild() {
-               AsmManager.getDefault().readStructureModel(getAbsoluteProjectDir());
-        IHierarchy model = AsmManager.getDefault().getHierarchy();
-        assertTrue("model exists", model != null);
-       
-        final List preBuildKinds = new ArrayList();
+               AsmManager asm = AsmManager.createNewStructureModel();
+               asm.readStructureModel(getAbsoluteProjectDir());
+               // AsmManager.getDefault().readStructureModel(getAbsoluteProjectDir());
+               IHierarchy model = asm.getHierarchy();
+               assertTrue("model exists", model != null);
+
+               final List preBuildKinds = new ArrayList();
                HierarchyWalker walker = new HierarchyWalker() {
-                   public void preProcess(IProgramElement node) {
-                       preBuildKinds.add(node.getKind());
-                   }
-               };
-               AsmManager.getDefault().getHierarchy().getRoot().walk(walker);
-               assertFalse("Expected there to be build kinds but didn't "
-                               + "find any", preBuildKinds.isEmpty());
-               
+                       public void preProcess(IProgramElement node) {
+                               preBuildKinds.add(node.getKind());
+                       }
+               };
+               asm.getHierarchy().getRoot().walk(walker);
+               assertFalse("Expected there to be build kinds but didn't " + "find any", preBuildKinds.isEmpty());
+
                doBuild();
-               assertTrue("Expected no compiler errors but found "
-                               + handler.getErrors(), handler.getErrors().isEmpty());
-               
-        final List postBuildKinds = new ArrayList();
+               assertTrue("Expected no compiler errors but found " + handler.getErrors(), handler.getErrors().isEmpty());
+
+               final List postBuildKinds = new ArrayList();
                HierarchyWalker walker2 = new HierarchyWalker() {
-                   public void preProcess(IProgramElement node) {
-                       postBuildKinds.add(node.getKind());
-                   }
-               };
-               AsmManager.getDefault().getHierarchy().getRoot().walk(walker2); 
-               assertFalse("Expected there to be build kinds but didn't "
-                               + "find any", preBuildKinds.isEmpty());
-
-               assertTrue("Lists should be the same: PRE"+preBuildKinds.toString()
-                               +"  POST"+postBuildKinds.toString(),preBuildKinds.equals(postBuildKinds));
-               
+                       public void preProcess(IProgramElement node) {
+                               postBuildKinds.add(node.getKind());
+                       }
+               };
+               asm.getHierarchy().getRoot().walk(walker2);
+               assertFalse("Expected there to be build kinds but didn't " + "find any", preBuildKinds.isEmpty());
+
+               assertTrue("Lists should be the same: PRE" + preBuildKinds.toString() + "  POST" + postBuildKinds.toString(), preBuildKinds
+                               .equals(postBuildKinds));
+
        }
-       
+
 }
index 397ac7fdfc297cc554a91ed0e59f6b2372653ee1..f2980e141aa5700bb162c78e1df9ba53b097e50c 100644 (file)
@@ -28,27 +28,22 @@ public class StructureModelTests extends AjdeCoreTestCase {
 
        private AsmManager manager = null;
 
-       private String[] files = new String[]{
-                       "figures" + File.separator + "Debug.java",
-                       "figures" + File.separator + "Figure.java",
-                       "figures" + File.separator + "FigureElement.java",
-                       "figures" + File.separator + "Main.java",
-                       "figures" + File.separator + "composites" + File.separator + "Line.java",
+       private final String[] files = new String[] { "figures" + File.separator + "Debug.java",
+                       "figures" + File.separator + "Figure.java", "figures" + File.separator + "FigureElement.java",
+                       "figures" + File.separator + "Main.java", "figures" + File.separator + "composites" + File.separator + "Line.java",
                        "figures" + File.separator + "composites" + File.separator + "Square.java",
                        "figures" + File.separator + "primitives" + File.separator + "planar" + File.separator + "Point.java",
-                       "figures" + File.separator + "primitives" + File.separator + "solid" + File.separator + "SolidPoint.java"
-       };
-       
+                       "figures" + File.separator + "primitives" + File.separator + "solid" + File.separator + "SolidPoint.java" };
+
        private TestCompilerConfiguration compilerConfig;
 
        protected void setUp() throws Exception {
                super.setUp();
                initialiseProject("figures-coverage");
-               compilerConfig = (TestCompilerConfiguration) getCompiler()
-                               .getCompilerConfiguration();
+               compilerConfig = (TestCompilerConfiguration) getCompiler().getCompilerConfiguration();
                compilerConfig.setProjectSourceFiles(getSourceFileList(files));
                doBuild();
-               manager = AsmManager.getDefault();
+               manager = AsmManager.lastActiveStructureModel;
        }
 
        protected void tearDown() throws Exception {
@@ -56,91 +51,90 @@ public class StructureModelTests extends AjdeCoreTestCase {
                compilerConfig = null;
                manager = null;
        }
-       
+
        public void testRootForSourceFile() throws IOException {
-               File testFile = openFile("figures" + File.separator + "Figure.java");   
-               IProgramElement node = manager.getHierarchy().findElementForSourceFile(
-                       testFile.getAbsolutePath());
-               assertTrue("find result", node != null) ;       
-               String child = ((IProgramElement)node.getChildren().get(1)).getName();
-        assertTrue("expected Figure got child " + child, child.equals("Figure"));
+               File testFile = openFile("figures" + File.separator + "Figure.java");
+               IProgramElement node = manager.getHierarchy().findElementForSourceFile(testFile.getAbsolutePath());
+               assertTrue("find result", node != null);
+               String child = ((IProgramElement) node.getChildren().get(1)).getName();
+               assertTrue("expected Figure got child " + child, child.equals("Figure"));
        }
 
        public void testPointcutName() throws IOException {
-               File testFile = openFile("figures" + File.separator + "Main.java");     
-               IProgramElement node = manager.getHierarchy().findElementForSourceFile(
-                       testFile.getAbsolutePath());
-               assertTrue("find result", node != null) ;       
-               IProgramElement pNode = (IProgramElement)(node).getChildren().get(2);
-               IProgramElement pointcut = (IProgramElement)pNode.getChildren().get(0);
+               File testFile = openFile("figures" + File.separator + "Main.java");
+               IProgramElement node = manager.getHierarchy().findElementForSourceFile(testFile.getAbsolutePath());
+               assertTrue("find result", node != null);
+               IProgramElement pNode = (IProgramElement) (node).getChildren().get(2);
+               IProgramElement pointcut = (IProgramElement) pNode.getChildren().get(0);
                assertTrue("kind", pointcut.getKind().equals(IProgramElement.Kind.POINTCUT));
                assertTrue("found node: " + pointcut.getName(), pointcut.toLabelString().equals("testptct()"));
        }
 
        public void testFileNodeFind() throws IOException {
                File testFile = openFile("figures" + File.separator + "Main.java");
-               
-//             System.err.println(((IProgramElement)((IProgramElement)Ajde.getDefault().getStructureModelManager().getHierarchy().getRoot().getChildren().get(0)).getChildren().get(3)).getSourceLocation().getSourceFile().getAbsolutePath());
-//             System.err.println(testFile.getAbsolutePath());
-               
-               IProgramElement node = manager.getHierarchy().findElementForSourceLine(
-                       testFile.getAbsolutePath(), 1);
-               assertTrue("find result", node != null) ;       
-               assertEquals("find result has children", 3, node.getChildren().size()) ;        
+
+               // System.err.println(((IProgramElement)((IProgramElement)Ajde.getDefault().getStructureModelManager().getHierarchy().getRoot().getChildren().get(0)).getChildren().get(3)).getSourceLocation().getSourceFile().getAbsolutePath());
+               // System.err.println(testFile.getAbsolutePath());
+
+               IProgramElement node = manager.getHierarchy().findElementForSourceLine(testFile.getAbsolutePath(), 1);
+               assertTrue("find result", node != null);
+               assertEquals("find result has children", 3, node.getChildren().size());
                assertTrue("found node: " + node.getName(), node.getKind().equals(IProgramElement.Kind.FILE_JAVA));
        }
-  
-       /**
-        * @todo        add negative test to make sure things that aren't runnable aren't annotated
-        */ 
+
+       /**
+        * @todo add negative test to make sure things that aren't runnable aren't annotated
+        */
        public void testMainClassNodeInfo() throws IOException {
-        IHierarchy model = manager.getHierarchy();
-        assertTrue("model exists", model != null);
+               IHierarchy model = manager.getHierarchy();
+               assertTrue("model exists", model != null);
                assertTrue("root exists", model.getRoot() != null);
                File testFile = openFile("figures" + File.separator + "Main.java");
-               IProgramElement node = model.findElementForSourceLine(testFile.getAbsolutePath(), 11);  
-               assertTrue("find result", node != null);        
+               IProgramElement node = model.findElementForSourceLine(testFile.getAbsolutePath(), 11);
+               assertTrue("find result", node != null);
                IProgramElement pNode = node.getParent();
-        if (null == pNode) {
-            assertTrue("null parent of " + node, false);
-        }
+               if (null == pNode) {
+                       assertTrue("null parent of " + node, false);
+               }
                assertTrue("found node: " + pNode.getName(), pNode.isRunnable());
-       }  
-       
+       }
+
        /**
         * Integrity could be checked somewhere in the API.
-        */ 
+        */
        public void testModelIntegrity() {
                IProgramElement modelRoot = manager.getHierarchy().getRoot();
-               assertTrue("root exists", modelRoot != null);   
-               
+               assertTrue("root exists", modelRoot != null);
+
                try {
                        testModelIntegrityHelper(modelRoot);
                } catch (Exception e) {
-                       assertTrue(e.toString(), false);        
+                       assertTrue(e.toString(), false);
                }
        }
 
        private void testModelIntegrityHelper(IProgramElement node) throws Exception {
-               for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
-                       IProgramElement child = (IProgramElement)it.next();
+               for (Iterator it = node.getChildren().iterator(); it.hasNext();) {
+                       IProgramElement child = (IProgramElement) it.next();
                        if (node == child.getParent()) {
                                testModelIntegrityHelper(child);
                        } else {
                                throw new Exception("parent-child check failed for child: " + child.toString());
                        }
-               }               
+               }
+       }
+
+       public void testNoChildIsNull() {
+               HierarchyWalker walker = new HierarchyWalker() {
+                       public void preProcess(IProgramElement node) {
+                               if (node.getChildren() == null)
+                                       return;
+                               for (Iterator it = node.getChildren().iterator(); it.hasNext();) {
+                                       if (it.next() == null)
+                                               throw new NullPointerException("null child on node: " + node.getName());
+                               }
+                       }
+               };
+               manager.getHierarchy().getRoot().walk(walker);
        }
-  
-       public void testNoChildIsNull() {
-               HierarchyWalker walker = new HierarchyWalker() {
-                   public void preProcess(IProgramElement node) {
-                       if (node.getChildren() == null) return;
-                       for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
-                               if (it.next() == null) throw new NullPointerException("null child on node: " + node.getName()); 
-                       }
-                   }
-               };
-               manager.getHierarchy().getRoot().walk(walker);
-       }  
 }