From fb549b50398a100b944975c80745a6515a7740d7 Mon Sep 17 00:00:00 2001 From: aclement Date: Mon, 20 Oct 2008 04:41:58 +0000 Subject: [PATCH] 251277: making asmmanager non-singleton --- .../org/aspectj/ajde/AjdeTestCase.java | 97 +++++------ .../org/aspectj/ajde/ExtensionTests.java | 150 ++++++++---------- .../ajde/SymbolFileGenerationTest.java | 54 +++---- .../ajde/ui/StructureViewManagerTest.java | 87 +++++----- 4 files changed, 176 insertions(+), 212 deletions(-) diff --git a/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java b/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java index 3d8f52f22..5f2b2f2f7 100644 --- a/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java +++ b/ajde/testsrc/org/aspectj/ajde/AjdeTestCase.java @@ -20,8 +20,6 @@ import java.util.List; import junit.framework.AssertionFailedError; import junit.framework.TestCase; -import org.aspectj.ajde.Ajde; -import org.aspectj.ajde.IconRegistry; import org.aspectj.ajde.core.AjCompiler; import org.aspectj.ajde.ui.utils.TestBuildProgressMonitor; import org.aspectj.ajde.ui.utils.TestCompilerConfiguration; @@ -29,118 +27,109 @@ import org.aspectj.ajde.ui.utils.TestEditorAdapter; import org.aspectj.ajde.ui.utils.TestIdeUIAdapter; import org.aspectj.ajde.ui.utils.TestMessageHandler; import org.aspectj.ajde.ui.utils.TestRuntimeProperties; -import org.aspectj.asm.AsmManager; import org.aspectj.tools.ajc.Ajc; public class AjdeTestCase extends TestCase { - public final static String testdataSrcDir = "../ajde/testdata"; + public final static String testdataSrcDir = "../ajde/testdata"; protected static File sandboxDir; - + private String projectDir; - + 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(); + // Ajde.getDefault().getModel().removeAllListeners(); } - + protected void tearDown() throws Exception { super.tearDown(); projectDir = null; sandboxDir = 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) { - - - File projectSrc=new File(testdataSrcDir + File.separatorChar + projectName); - File destination=new File(getWorkingDir(),projectName); - if (!destination.exists()) {destination.mkdir();} - copy(projectSrc,destination); + + File projectSrc = new File(testdataSrcDir + File.separatorChar + projectName); + File destination = new File(getWorkingDir(), projectName); + if (!destination.exists()) { + destination.mkdir(); + } + copy(projectSrc, destination); projectDir = destination.getAbsolutePath(); // need to initialize via AjdeUIManager - Ajde.getDefault().init( - new TestCompilerConfiguration(projectDir), - new TestMessageHandler(), - new TestBuildProgressMonitor(), - new TestEditorAdapter(), - new TestIdeUIAdapter(), - new IconRegistry(), - null, //new JFrame(), - new TestRuntimeProperties(), - true); + Ajde.getDefault().init(new TestCompilerConfiguration(projectDir), new TestMessageHandler(), new TestBuildProgressMonitor(), + new TestEditorAdapter(), new TestIdeUIAdapter(), new IconRegistry(), null, // new JFrame(), + new TestRuntimeProperties(), true); } - + /** * @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(String configFile) { getCompilerForConfigFileWithName(configFile).build(); } - + public AjCompiler getCompilerForConfigFileWithName(String configFileName) { return Ajde.getDefault().getCompilerForConfigFile(projectDir + File.separator + configFileName); } public List getErrorMessages(String configFileName) { - return ((TestMessageHandler)getCompilerForConfigFileWithName(configFileName).getMessageHandler()).getErrors(); + return ((TestMessageHandler) getCompilerForConfigFileWithName(configFileName).getMessageHandler()).getErrors(); } - + public List getMessages(String configFileName) { - return ((TestMessageHandler)getCompilerForConfigFileWithName(configFileName).getMessageHandler()).getMessages(); + return ((TestMessageHandler) getCompilerForConfigFileWithName(configFileName).getMessageHandler()).getMessages(); + } + + protected String genStructureModelExternFilePath(String configFilePath) { + return configFilePath.substring(0, configFilePath.lastIndexOf(".lst")) + ".ajsym"; } - - protected String genStructureModelExternFilePath(String configFilePath) { - return configFilePath.substring(0, configFilePath.lastIndexOf(".lst")) + ".ajsym"; - } } diff --git a/ajde/testsrc/org/aspectj/ajde/ExtensionTests.java b/ajde/testsrc/org/aspectj/ajde/ExtensionTests.java index b1c4e40ef..f2fd49bcf 100644 --- a/ajde/testsrc/org/aspectj/ajde/ExtensionTests.java +++ b/ajde/testsrc/org/aspectj/ajde/ExtensionTests.java @@ -10,141 +10,131 @@ *******************************************************************************/ package org.aspectj.ajde; +import java.io.File; import java.util.Iterator; import java.util.List; -//import java.util.Properties; -import java.io.File; import org.aspectj.asm.AsmManager; import org.aspectj.asm.IProgramElement; import org.aspectj.bridge.IMessage; +import org.aspectj.org.eclipse.jdt.core.compiler.IProblem; import org.aspectj.tools.ajc.AjcTestCase; import org.aspectj.tools.ajc.CompilationResult; -import org.aspectj.org.eclipse.jdt.core.compiler.IProblem; /** - * Tests the 'extensions' to AJDE: - * 1) ID is now available on messages to allow you to see what 'kind' of - * message it is - this activates quick fixes/etc in Eclipse. + * Tests the 'extensions' to AJDE: 1) ID is now available on messages to allow you to see what 'kind' of message it is - this + * activates quick fixes/etc in Eclipse. */ public class ExtensionTests extends AjcTestCase { public static final String PROJECT_DIR = "extensions"; private static final boolean debugTests = false; private File baseDir; - + protected void setUp() throws Exception { super.setUp(); - // TODO-path - baseDir = new File("../ajde/testdata",PROJECT_DIR); + // TODO-path + baseDir = new File("../ajde/testdata", PROJECT_DIR); } - + /** * Aim: Check that the ID of certain message kinds are correct * - * ajc -warn:unusedImport UnusedImport.java + * ajc -warn:unusedImport UnusedImport.java * * Expected result is that id matches IProblem.UnusedImport */ - public void testMessageID () { - String[] args = new String[] {"UnusedImport.java","-warn:unusedImport"}; - CompilationResult result = ajc(baseDir,args); + public void testMessageID() { + String[] args = new String[] { "UnusedImport.java", "-warn:unusedImport" }; + CompilationResult result = ajc(baseDir, args); List l = result.getWarningMessages(); - IMessage m = ((IMessage)l.get(0)); - assertTrue("Expected ID of message to be "+IProblem.UnusedImport+" (UnusedImport) but found an ID of "+m.getID(), - m.getID()==IProblem.UnusedImport); + IMessage m = ((IMessage) l.get(0)); + assertTrue("Expected ID of message to be " + IProblem.UnusedImport + " (UnusedImport) but found an ID of " + m.getID(), m + .getID() == IProblem.UnusedImport); } - + public void testInnerClassesInASM() { - String[] args = new String[] {"InnerClasses.java","-emacssym"}; - CompilationResult result = ajc(baseDir,args); - /*List l = */result.getWarningMessages(); - /*Properties p = */AsmManager.ModelInfo.summarizeModel().getProperties(); - if (debugTests) System.out.println("Structure Model for InnerClasses.java:"); - walkit(AsmManager.getDefault().getHierarchy().getRoot(),0); + String[] args = new String[] { "InnerClasses.java", "-emacssym" }; + CompilationResult result = ajc(baseDir, args); + /* List l = */result.getWarningMessages(); + /* Properties p = */AsmManager.lastActiveStructureModel.summarizeModel().getProperties(); + if (debugTests) + System.out.println("Structure Model for InnerClasses.java:"); + walkit(AsmManager.lastActiveStructureModel.getHierarchy().getRoot(), 0); foundNode = null; - findChild("main",AsmManager.getDefault().getHierarchy().getRoot()); - assertTrue("Should have found node 'main' in the model",foundNode!=null); - IProgramElement runnableChild = getChild(foundNode,"new Runnable() {..}"); - assertTrue("'main' should have a child 'new Runnable() {..}'", - runnableChild!=null); - assertTrue("'new Runnable() {..}' should have a 'run' child", - getChild(runnableChild,"run")!=null); - - /* Left hand side is before the fix, right hand side is after: - - InnerClasses.java - import declarations - InnerClasses - A A - method method - 1 new Runnable() {..} - run run - main main - 2 new Runnable() {..} - run run - 3 new Object() {..} - toString toString - 4 new Runnable - run run + findChild("main", AsmManager.lastActiveStructureModel.getHierarchy().getRoot()); + assertTrue("Should have found node 'main' in the model", foundNode != null); + IProgramElement runnableChild = getChild(foundNode, "new Runnable() {..}"); + assertTrue("'main' should have a child 'new Runnable() {..}'", runnableChild != null); + assertTrue("'new Runnable() {..}' should have a 'run' child", getChild(runnableChild, "run") != null); + + /* + * Left hand side is before the fix, right hand side is after: InnerClasses.java import declarations InnerClasses A A + * method method 1 new Runnable() {..} run run main main 2 new Runnable() {..} run run 3 new Object() {..} toString toString + * 4 new Runnable run run */ } - - private IProgramElement getChild(IProgramElement parent,String s) { + + private IProgramElement getChild(IProgramElement parent, String s) { List kids = parent.getChildren(); for (Iterator iter = kids.iterator(); iter.hasNext();) { IProgramElement element = (IProgramElement) iter.next(); - if (element.getName().indexOf(s)!=-1) return element; + if (element.getName().indexOf(s) != -1) + return element; } return null; } - + private IProgramElement foundNode = null; - - private void findChild(String s,IProgramElement ipe) { - if (ipe == null) return; - if (ipe.getName().indexOf(s)!=-1) {foundNode = ipe; return;} - if (ipe.getChildren()!=null) { + + private void findChild(String s, IProgramElement ipe) { + if (ipe == null) + return; + if (ipe.getName().indexOf(s) != -1) { + foundNode = ipe; + return; + } + if (ipe.getChildren() != null) { List kids = ipe.getChildren(); for (Iterator iter = kids.iterator(); iter.hasNext();) { IProgramElement element = (IProgramElement) iter.next(); - findChild(s,element); + findChild(s, element); } } } - - public void walkit(IProgramElement ipe,int indent) { - if (ipe!=null) { - if (debugTests) for (int i = 0 ;i