From 689bd19050a5474ee734110c8702f40b595e300f Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 20 Oct 2008 04:38:55 +0000 Subject: 251277: making asmmanager non-singleton --- .../src/org/aspectj/ajde/core/AjCompiler.java | 9 + .../ajde/core/internal/AjdeCoreBuildManager.java | 13 +- .../org/aspectj/ajde/core/AjdeCoreTestCase.java | 102 +++++----- .../core/tests/model/AsmDeclarationsTests.java | 19 +- .../core/tests/model/AsmRelationshipsTests.java | 216 ++++++++++----------- .../tests/model/SavedModelConsistencyTests.java | 113 +++++------ .../ajde/core/tests/model/StructureModelTests.java | 124 ++++++------ 7 files changed, 294 insertions(+), 302 deletions(-) (limited to 'ajde.core') diff --git a/ajde.core/src/org/aspectj/ajde/core/AjCompiler.java b/ajde.core/src/org/aspectj/ajde/core/AjCompiler.java index 72eb4058c..5755c4173 100644 --- a/ajde.core/src/org/aspectj/ajde/core/AjCompiler.java +++ b/ajde.core/src/org/aspectj/ajde/core/AjCompiler.java @@ -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(); + // } } diff --git a/ajde.core/src/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java b/ajde.core/src/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java index 074222b51..db4fe814d 100644 --- a/ajde.core/src/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java +++ b/ajde.core/src/org/aspectj/ajde/core/internal/AjdeCoreBuildManager.java @@ -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(); + } } diff --git a/ajde.core/testsrc/org/aspectj/ajde/core/AjdeCoreTestCase.java b/ajde.core/testsrc/org/aspectj/ajde/core/AjdeCoreTestCase.java index 80a98aa18..62c8ea88b 100644 --- a/ajde.core/testsrc/org/aspectj/ajde/core/AjdeCoreTestCase.java +++ b/ajde.core/testsrc/org/aspectj/ajde/core/AjdeCoreTestCase.java @@ -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; } - + } diff --git a/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/AsmDeclarationsTests.java b/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/AsmDeclarationsTests.java index 1ce8e88a8..046bd6688 100644 --- a/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/AsmDeclarationsTests.java +++ b/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/AsmDeclarationsTests.java @@ -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(): "; diff --git a/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/AsmRelationshipsTests.java b/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/AsmRelationshipsTests.java index 919eec6e3..14217aa84 100644 --- a/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/AsmRelationshipsTests.java +++ b/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/AsmRelationshipsTests.java @@ -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 } diff --git a/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/SavedModelConsistencyTests.java b/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/SavedModelConsistencyTests.java index 99f6e354f..5c97bcbe7 100644 --- a/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/SavedModelConsistencyTests.java +++ b/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/SavedModelConsistencyTests.java @@ -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)); + } - + } diff --git a/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/StructureModelTests.java b/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/StructureModelTests.java index 397ac7fdf..f2980e141 100644 --- a/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/StructureModelTests.java +++ b/ajde.core/testsrc/org/aspectj/ajde/core/tests/model/StructureModelTests.java @@ -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); - } } -- cgit v1.2.3