From 8a64b5fcd37c6f67f9e339f6fe34714590052ed2 Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 12 Aug 2011 17:41:10 +0000 Subject: [PATCH] generics refactoring --- .../aspectj/ajde/core/AjdeCoreTestCase.java | 4 +- .../aspectj/ajde/core/TestMessageHandler.java | 87 ++++---- .../ajde/core/TestOutputLocationManager.java | 5 +- .../ajde/core/tests/AjConfigTests.java | 210 ++++++++---------- 4 files changed, 136 insertions(+), 170 deletions(-) diff --git a/ajde.core/testsrc/org/aspectj/ajde/core/AjdeCoreTestCase.java b/ajde.core/testsrc/org/aspectj/ajde/core/AjdeCoreTestCase.java index 62c8ea88b..680d19065 100644 --- a/ajde.core/testsrc/org/aspectj/ajde/core/AjdeCoreTestCase.java +++ b/ajde.core/testsrc/org/aspectj/ajde/core/AjdeCoreTestCase.java @@ -141,8 +141,8 @@ public class AjdeCoreTestCase extends TestCase { } } - public List getSourceFileList(String[] files) { - List sourceFiles = new ArrayList(); + public List getSourceFileList(String[] files) { + List sourceFiles = new ArrayList(); for (int i = 0; i < files.length; i++) { sourceFiles.add(getAbsoluteProjectDir() + File.separator + files[i]); } diff --git a/ajde.core/testsrc/org/aspectj/ajde/core/TestMessageHandler.java b/ajde.core/testsrc/org/aspectj/ajde/core/TestMessageHandler.java index aab1e98e0..a2e3efd1d 100644 --- a/ajde.core/testsrc/org/aspectj/ajde/core/TestMessageHandler.java +++ b/ajde.core/testsrc/org/aspectj/ajde/core/TestMessageHandler.java @@ -18,88 +18,83 @@ import org.aspectj.bridge.IMessage; import org.aspectj.bridge.IMessage.Kind; /** - * Test implementation of IBuildMessageHandler. By default it - * ignores INFO and WEAVEINFO messages. Stores all messages it's - * not ignoring in an ArrayList and ERRORS and ABORTS also in - * a separate ArrayList enabling users to query whether anything - * went wrong with the build. + * Test implementation of IBuildMessageHandler. By default it ignores INFO and WEAVEINFO messages. Stores all messages it's not + * ignoring in an ArrayList and ERRORS and ABORTS also in a separate ArrayList enabling users to query whether anything went wrong + * with the build. */ public class TestMessageHandler implements IBuildMessageHandler { - private List ignoring; + private List ignoring; private List messages; private List errors; - + public TestMessageHandler() { - ignoring = new ArrayList(); + ignoring = new ArrayList(); messages = new ArrayList(); errors = new ArrayList(); - ignore(IMessage.INFO); - ignore(IMessage.WEAVEINFO); + ignore(IMessage.INFO); + ignore(IMessage.WEAVEINFO); } public boolean handleMessage(IMessage message) throws AbortException { - IMessage.Kind kind = message.getKind(); - if (isIgnoring(kind)) { - return true; - } - TestMessage t = new TestMessage(message); - messages.add(t); - if (kind.equals(IMessage.ABORT) || message.getThrown() != null) { - System.err.println("> AjCompiler error: "+message.getMessage()); //$NON-NLS-1$ - message.getThrown().printStackTrace(); - errors.add(t); - } else if (kind.equals(IMessage.ERROR)) { - errors.add(t); - } - System.out.println("> "+message); //$NON-NLS-1$ + IMessage.Kind kind = message.getKind(); + if (isIgnoring(kind)) { + return true; + } + TestMessage t = new TestMessage(message); + messages.add(t); + if (kind.equals(IMessage.ABORT) || message.getThrown() != null) { + System.err.println("> AjCompiler error: " + message.getMessage()); //$NON-NLS-1$ + message.getThrown().printStackTrace(); + errors.add(t); + } else if (kind.equals(IMessage.ERROR)) { + errors.add(t); + } + System.out.println("> " + message); //$NON-NLS-1$ return true; } public void dontIgnore(Kind kind) { - if (null != kind) { - ignoring.remove(kind); - } + if (null != kind) { + ignoring.remove(kind); + } } public boolean isIgnoring(Kind kind) { return ((null != kind) && (ignoring.contains(kind))); } - + public void ignore(Kind kind) { - if ((null != kind) && (!ignoring.contains(kind))) { - ignoring.add(kind); - } + if ((null != kind) && (!ignoring.contains(kind))) { + ignoring.add(kind); + } } public List getMessages() { return messages; } - + public List getErrors() { return errors; } - + public static class TestMessage { IMessage message; - + public TestMessage(IMessage m) { message = m; } - + public IMessage getContainedMessage() { return message; } - - public String toString() { - String loc = ""; - if (null != message.getSourceLocation()) { - loc = message.getSourceLocation().getSourceFile() + ":" + message.getSourceLocation().getLine(); - } - return "TestMessage [" + message.getMessage() - + ", " + loc - + ", " + message.getKind() - + "]"; - } + + public String toString() { + String loc = ""; + if (null != message.getSourceLocation()) { + loc = message.getSourceLocation().getSourceFile() + ":" + message.getSourceLocation().getLine(); + } + return "TestMessage [" + message.getMessage() + ", " + loc + ", " + message.getKind() + "]"; + } } } diff --git a/ajde.core/testsrc/org/aspectj/ajde/core/TestOutputLocationManager.java b/ajde.core/testsrc/org/aspectj/ajde/core/TestOutputLocationManager.java index 8ce149c37..d8396a59d 100644 --- a/ajde.core/testsrc/org/aspectj/ajde/core/TestOutputLocationManager.java +++ b/ajde.core/testsrc/org/aspectj/ajde/core/TestOutputLocationManager.java @@ -26,7 +26,7 @@ public class TestOutputLocationManager implements IOutputLocationManager { private String testProjectOutputPath; private File classOutputLoc; private File resourceOutputLoc; - private List allOutputLocations; + private List allOutputLocations; private Map inpathMap = Collections.EMPTY_MAP; public TestOutputLocationManager(String testProjectPath) { @@ -47,12 +47,11 @@ public class TestOutputLocationManager implements IOutputLocationManager { initLocations(); return resourceOutputLoc; } - + public Map getInpathMap() { return inpathMap; } - // -------------- setter methods useful for testing ------------- public void setOutputLocForClass(File f) { classOutputLoc = f; diff --git a/ajde.core/testsrc/org/aspectj/ajde/core/tests/AjConfigTests.java b/ajde.core/testsrc/org/aspectj/ajde/core/tests/AjConfigTests.java index ec474444b..b49b514ab 100644 --- a/ajde.core/testsrc/org/aspectj/ajde/core/tests/AjConfigTests.java +++ b/ajde.core/testsrc/org/aspectj/ajde/core/tests/AjConfigTests.java @@ -28,8 +28,7 @@ import org.aspectj.ajde.core.internal.AjdeCoreBuildManager; import org.aspectj.ajdt.internal.core.builder.AjBuildConfig; /** - * Tests that the AjBuildConfig is populated correctly from the - * ICompilerConfiguration + * Tests that the AjBuildConfig is populated correctly from the ICompilerConfiguration */ public class AjConfigTests extends AjdeCoreTestCase { @@ -48,180 +47,153 @@ public class AjConfigTests extends AjdeCoreTestCase { ajdeBuildManager = null; compilerConfig = null; } - + public void testJavaOptionsMap() { Map options = JavaOptions.getDefaultJavaOptions(); options.put(JavaOptions.WARN_DEPRECATION, JavaOptions.WARNING); compilerConfig.setJavaOptions(options); Map found = genAjBuildConfig().getOptions().getMap(); String warning = (String) found.get(JavaOptions.WARN_DEPRECATION); - assertEquals("expected to be warning on deprecation but found setting " - + " was " + warning,JavaOptions.WARNING,warning); + assertEquals("expected to be warning on deprecation but found setting " + " was " + warning, JavaOptions.WARNING, warning); } - + public void testAspectPath() { - Set aspects = new HashSet(); - compilerConfig.setAspectPath( aspects ); + Set aspects = new HashSet(); + compilerConfig.setAspectPath(aspects); AjBuildConfig buildConfig = genAjBuildConfig(); - List aPath = buildConfig.getAspectpath(); - assertTrue( "no aspect path", aPath.isEmpty() ); - - File f = new File( "jarone.jar" ); - aspects.add( f ); + List aPath = buildConfig.getAspectpath(); + assertTrue("no aspect path", aPath.isEmpty()); + + File f = new File("jarone.jar"); + aspects.add(f); buildConfig = genAjBuildConfig(); - List aPath2 = buildConfig.getAspectpath(); - assertEquals("expected one entry on the aspectpath but found " - + aPath2.size(), 1, aPath2.size()); - assertTrue( "expected to find file " + f.getName() + " on the aspectpath" + - " but didn't", aPath2.contains(f) ); - - File f2 = new File( "jartwo.jar" ); - aspects.add( f2 ); + List aPath2 = buildConfig.getAspectpath(); + assertEquals("expected one entry on the aspectpath but found " + aPath2.size(), 1, aPath2.size()); + assertTrue("expected to find file " + f.getName() + " on the aspectpath" + " but didn't", aPath2.contains(f)); + + File f2 = new File("jartwo.jar"); + aspects.add(f2); buildConfig = genAjBuildConfig(); - List aPath3 = buildConfig.getAspectpath(); - assertEquals("expected two entries on the aspectpath but found " - + aPath3.size(), 2, aPath3.size()); - assertTrue( "expected to find file " + f.getName() + " on the aspectpath" + - " but didn't", aPath3.contains(f) ); - assertTrue( "expected to find file " + f2.getName() + " on the aspectpath" + - " but didn't", aPath3.contains(f2) ); + List aPath3 = buildConfig.getAspectpath(); + assertEquals("expected two entries on the aspectpath but found " + aPath3.size(), 2, aPath3.size()); + assertTrue("expected to find file " + f.getName() + " on the aspectpath" + " but didn't", aPath3.contains(f)); + assertTrue("expected to find file " + f2.getName() + " on the aspectpath" + " but didn't", aPath3.contains(f2)); } - + public void testInpath() { - Set jars = new HashSet(); - compilerConfig.setInpath( jars ); + Set jars = new HashSet(); + compilerConfig.setInpath(jars); AjBuildConfig buildConfig = genAjBuildConfig(); - List inJars = buildConfig.getInpath(); - assertTrue( "expected to find nothing on the inpath but found " + - inJars, inJars.isEmpty() ); - - File f = new File( "jarone.jar" ); - jars.add( f ); + List inJars = buildConfig.getInpath(); + assertTrue("expected to find nothing on the inpath but found " + inJars, inJars.isEmpty()); + + File f = new File("jarone.jar"); + jars.add(f); buildConfig = genAjBuildConfig(); - List inJars2 = buildConfig.getInpath(); - assertTrue("expected to find one file on the inpath but found " + - inJars2.size() + ": " + inJars2,inJars2.size() == 1); - assertTrue( "expected to find file " + f.getName() + " on the inpath" + - " but didn't", inJars2.contains(f) ); - - - File f2 = new File( "jartwo.jar" ); - jars.add( f2 ); + List inJars2 = buildConfig.getInpath(); + assertTrue("expected to find one file on the inpath but found " + inJars2.size() + ": " + inJars2, inJars2.size() == 1); + assertTrue("expected to find file " + f.getName() + " on the inpath" + " but didn't", inJars2.contains(f)); + + File f2 = new File("jartwo.jar"); + jars.add(f2); buildConfig = genAjBuildConfig(); - List inJars3 = buildConfig.getInpath(); - assertEquals("expected two entries on the inpath but found " - + inJars3.size(), 2, inJars3.size()); - assertTrue( "expected to find file " + f.getName() + " on the inpath" + - " but didn't", inJars3.contains(f) ); - assertTrue( "expected to find file " + f2.getName() + " on the inpath" + - " but didn't", inJars3.contains(f2) ); + List inJars3 = buildConfig.getInpath(); + assertEquals("expected two entries on the inpath but found " + inJars3.size(), 2, inJars3.size()); + assertTrue("expected to find file " + f.getName() + " on the inpath" + " but didn't", inJars3.contains(f)); + assertTrue("expected to find file " + f2.getName() + " on the inpath" + " but didn't", inJars3.contains(f2)); } - + public void testOutJar() { String outJar = "mybuild.jar"; - compilerConfig.setOutjar( outJar ); + compilerConfig.setOutjar(outJar); AjBuildConfig buildConfig = genAjBuildConfig(); - assertNotNull("expected to find a non null output jar but " + - "didn't", buildConfig.getOutputJar()); - assertEquals( "expected to find outjar 'mybuild.jar' but instead " + - "found " + buildConfig.getOutputJar().toString(), - outJar, buildConfig.getOutputJar().toString() ); + assertNotNull("expected to find a non null output jar but " + "didn't", buildConfig.getOutputJar()); + assertEquals("expected to find outjar 'mybuild.jar' but instead " + "found " + buildConfig.getOutputJar().toString(), + outJar, buildConfig.getOutputJar().toString()); } - + public void testXHasMember() { compilerConfig.setNonStandardOptions("-XhasMember"); AjBuildConfig buildConfig = genAjBuildConfig(); - assertTrue( "expected XhasMember to be enabled but wasn't ", - buildConfig.isXHasMemberEnabled() ); + assertTrue("expected XhasMember to be enabled but wasn't ", buildConfig.isXHasMemberEnabled()); } - + public void testOutputLocationManager() { IOutputLocationManager mgr = compilerConfig.getOutputLocationManager(); String expectedDefaultOutputDir = mgr.getDefaultOutputLocation().getAbsolutePath(); AjBuildConfig buildConfig = genAjBuildConfig(); - String found = buildConfig.getCompilationResultDestinationManager(). - getDefaultOutputLocation().getAbsolutePath(); - assertEquals("expected to find default output location " + - expectedDefaultOutputDir + " but found " + found, - expectedDefaultOutputDir,found); + String found = buildConfig.getCompilationResultDestinationManager().getDefaultOutputLocation().getAbsolutePath(); + assertEquals("expected to find default output location " + expectedDefaultOutputDir + " but found " + found, + expectedDefaultOutputDir, found); } - + public void testSourcePathResources() { - Map m = new HashMap(); - m.put("newFile.txt", getWorkingDir()); + Map m = new HashMap(); + m.put("newFile.txt", getWorkingDir()); compilerConfig.setSourcePathResources(m); AjBuildConfig buildConfig = genAjBuildConfig(); - Map found = buildConfig.getSourcePathResources(); - for (Iterator i = found.keySet().iterator(); i.hasNext(); ) { - String resource = (String)i.next(); - assertEquals("expected to find resource with name newFile.txt but " + - "found " + resource,"newFile.txt",resource); - File from = (File)buildConfig.getSourcePathResources().get(resource); - assertEquals("expected to find resource with file " + getWorkingDir() - + "but found " + from,getWorkingDir(),from); + Map found = buildConfig.getSourcePathResources(); + for (Iterator i = found.keySet().iterator(); i.hasNext();) { + String resource = i.next(); + assertEquals("expected to find resource with name newFile.txt but " + "found " + resource, "newFile.txt", resource); + File from = (File) buildConfig.getSourcePathResources().get(resource); + assertEquals("expected to find resource with file " + getWorkingDir() + "but found " + from, getWorkingDir(), from); } } - + public void testClasspath() { String classpath = compilerConfig.getClasspath(); - List found = genAjBuildConfig().getClasspath(); + List found = genAjBuildConfig().getClasspath(); StringBuffer sb = new StringBuffer(); - for (Iterator iterator = found.iterator(); iterator.hasNext();) { + for (Iterator iterator = found.iterator(); iterator.hasNext();) { String name = (String) iterator.next(); sb.append(name); if (iterator.hasNext()) { sb.append(File.pathSeparator); } } - assertEquals("expected to find classpath " + classpath + " but found " - + sb.toString(), classpath, sb.toString()); + assertEquals("expected to find classpath " + classpath + " but found " + sb.toString(), classpath, sb.toString()); } - + public void testNonStandardOptions() { - compilerConfig.setNonStandardOptions( "-XterminateAfterCompilation" ); - AjBuildConfig buildConfig = genAjBuildConfig(); - assertTrue( "XterminateAfterCompilation", buildConfig.isTerminateAfterCompilation() ); - compilerConfig.setNonStandardOptions( "-XserializableAspects" ); - buildConfig = genAjBuildConfig(); - assertTrue( "XserializableAspects", buildConfig.isXserializableAspects() ); - compilerConfig.setNonStandardOptions( "-XnoInline" ); - buildConfig = genAjBuildConfig(); - assertTrue( "XnoInline", buildConfig.isXnoInline()); - compilerConfig.setNonStandardOptions( "-Xlint" ); - buildConfig = genAjBuildConfig(); - assertEquals( "Xlint", AjBuildConfig.AJLINT_DEFAULT, - buildConfig.getLintMode()); - compilerConfig.setNonStandardOptions( "-Xlint:error" ); - buildConfig = genAjBuildConfig(); - assertEquals( "Xlint", AjBuildConfig.AJLINT_ERROR, - buildConfig.getLintMode()); + compilerConfig.setNonStandardOptions("-XterminateAfterCompilation"); + AjBuildConfig buildConfig = genAjBuildConfig(); + assertTrue("XterminateAfterCompilation", buildConfig.isTerminateAfterCompilation()); + compilerConfig.setNonStandardOptions("-XserializableAspects"); + buildConfig = genAjBuildConfig(); + assertTrue("XserializableAspects", buildConfig.isXserializableAspects()); + compilerConfig.setNonStandardOptions("-XnoInline"); + buildConfig = genAjBuildConfig(); + assertTrue("XnoInline", buildConfig.isXnoInline()); + compilerConfig.setNonStandardOptions("-Xlint"); + buildConfig = genAjBuildConfig(); + assertEquals("Xlint", AjBuildConfig.AJLINT_DEFAULT, buildConfig.getLintMode()); + compilerConfig.setNonStandardOptions("-Xlint:error"); + buildConfig = genAjBuildConfig(); + assertEquals("Xlint", AjBuildConfig.AJLINT_ERROR, buildConfig.getLintMode()); // and a few options thrown in at once - compilerConfig.setNonStandardOptions( "-Xlint -XnoInline -XserializableAspects" ); - buildConfig = genAjBuildConfig(); - assertEquals( "Xlint", AjBuildConfig.AJLINT_DEFAULT, - buildConfig.getLintMode()); - assertTrue( "XnoInline", buildConfig.isXnoInline()); - assertTrue( "XserializableAspects", buildConfig.isXserializableAspects() ); + compilerConfig.setNonStandardOptions("-Xlint -XnoInline -XserializableAspects"); + buildConfig = genAjBuildConfig(); + assertEquals("Xlint", AjBuildConfig.AJLINT_DEFAULT, buildConfig.getLintMode()); + assertTrue("XnoInline", buildConfig.isXnoInline()); + assertTrue("XserializableAspects", buildConfig.isXserializableAspects()); } - + public void testProjectSourceFiles() throws IOException { String f = getAbsoluteProjectDir() + File.separator + "C.java"; List files = new ArrayList(); files.add(f); compilerConfig.setProjectSourceFiles(files); AjBuildConfig buildConfig = genAjBuildConfig(); - String found = ((File)buildConfig.getFiles().get(0)).getCanonicalPath();//AbsolutePath(); - assertEquals("expected source file " + f + ", but found " + - found, f, found); + String found = ((File) buildConfig.getFiles().get(0)).getCanonicalPath();// AbsolutePath(); + assertEquals("expected source file " + f + ", but found " + found, f, found); } - + private AjBuildConfig genAjBuildConfig() { - AjBuildConfig buildConfig = ajdeBuildManager.generateAjBuildConfig(); - assertNotNull("exepected to generate a non null AjBuildConfig but " + - "didn't", buildConfig); + AjBuildConfig buildConfig = ajdeBuildManager.generateAjBuildConfig(); + assertNotNull("exepected to generate a non null AjBuildConfig but " + "didn't", buildConfig); return buildConfig; } - - + } -- 2.39.5