From c8e951296c5f95e82d4c7c3f8eb9b0a647014e20 Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Mon, 6 Oct 2014 17:35:51 -0700 Subject: Fix 436653: conditional aspect activation plus various polish Modified test expectation system so it is possible to say the test cares about one particular message and the rest do not matter (prefix message string with '*') - crude but quick. Polished many places to exploit generics Upgraded all the tests to work on Java8 - some serious changes regarding ajdoc on Java8. Hopefully it has stayed backwards compatible with earlier JDK versions (e.g. if using AspectJ 1.8.3+ with a JDK less than 8) but no explicit testing done for this. --- ajdoc/.isJava5 | 1 + ajdoc/.settings/org.eclipse.jdt.core.prefs | 12 -- .../src/org/aspectj/tools/ajdoc/HtmlDecorator.java | 28 ++- .../aspectj/tools/ajdoc/AjdocOutputChecker.java | 10 +- .../org/aspectj/tools/ajdoc/CoverageTestCase.java | 196 +++++++++++++++++---- 5 files changed, 189 insertions(+), 58 deletions(-) create mode 100644 ajdoc/.isJava5 delete mode 100644 ajdoc/.settings/org.eclipse.jdt.core.prefs (limited to 'ajdoc') diff --git a/ajdoc/.isJava5 b/ajdoc/.isJava5 new file mode 100644 index 000000000..136d06384 --- /dev/null +++ b/ajdoc/.isJava5 @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ajdoc/.settings/org.eclipse.jdt.core.prefs b/ajdoc/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 12ff67cd1..000000000 --- a/ajdoc/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -#Thu Oct 06 08:32:56 PDT 2005 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.1 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.3 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=ignore -org.eclipse.jdt.core.compiler.source=1.3 diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java b/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java index bad35529f..04af19f2d 100644 --- a/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java +++ b/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java @@ -224,7 +224,20 @@ class HtmlDecorator { classStartIndex = fileContents.toString().indexOf("

\nClass "); br = false; } - if (classStartIndex != -1) { + if (classStartIndex == -1) { + // Java8 looks more like this: + //

Class A

+ classStartIndex = fileContents.toString().indexOf("

", classStartIndex); + if (classEndIndex != -1) { + // Convert it to "

Aspect A

" + String classLine = fileContents.toString().substring(classStartIndex, classEndIndex); + String aspectLine = classLine.replaceAll("Class ","Aspect "); + fileContents.delete(classStartIndex, classEndIndex); + fileContents.insert(classStartIndex, aspectLine); + } + } + else if (classStartIndex != -1) { int classEndIndex = fileContents.toString().indexOf("", classStartIndex); if (classStartIndex != -1 && classEndIndex != -1) { String classLine = fileContents.toString().substring(classStartIndex, classEndIndex); @@ -249,6 +262,19 @@ class HtmlDecorator { fileContents.insert(secondClassStartIndex, sb.toString()); } } + else { + // Java8: + //
static class ClassA.InnerAspect
+					classStartIndex = fileContents.toString().indexOf("class ");
+					int classEndIndex = fileContents.toString().indexOf("", classStartIndex);
+					if (classEndIndex != -1) {
+						// Convert it to "aspect ClassA.InnerAspect"
+						String classLine = fileContents.toString().substring(classStartIndex, classEndIndex);
+						String aspectLine = "aspect"+fileContents.substring(classStartIndex+5,classEndIndex);
+						fileContents.delete(classStartIndex, classEndIndex);
+						fileContents.insert(classStartIndex, aspectLine);
+					}
+				}
 			}
 		}
 		file.delete();
diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocOutputChecker.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocOutputChecker.java
index 10e22fbf6..dbe5125c5 100644
--- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocOutputChecker.java
+++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocOutputChecker.java
@@ -50,20 +50,18 @@ public class AjdocOutputChecker {
 	}
 
 	/**
-	 * Returns those strings from the given array which aren't in the
-	 * html file
+	 * Returns those strings from the given array which aren't in the html file.
 	 * 
 	 * @param htmlFile
 	 * @param an array of requiredStrings
 	 * @return a List of those strings not found
 	 * @throws Exception
 	 */	
-	public static List /*String*/ getMissingStringsInFile(File htmlFile,
-			String[] requiredStrings) throws Exception {
-		List missingStrings = new ArrayList();
+	public static List getMissingStringsInFile(File htmlFile, String[] requiredStrings) throws Exception {
+		List missingStrings = new ArrayList();
 		for (int i = 0; i < requiredStrings.length; i++) {
 			String string = requiredStrings[i];
-			if (!containsString(htmlFile,string)) {
+			if (!containsString(htmlFile, string)) {
 				missingStrings.add(string);
 			}
 		}
diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java
index 0c0a0f268..afa27b319 100644
--- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java
+++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java
@@ -14,8 +14,11 @@
 import java.io.File;
 import java.util.List;
 
+import org.aspectj.util.FileUtil;
 import org.aspectj.util.LangUtil;
 
+import com.sun.org.apache.xml.internal.serializer.utils.Utils;
+
 
 /**
  * A long way to go until full coverage, but this is the place to add more.
@@ -128,14 +131,39 @@ public class CoverageTestCase extends AjdocTestCase {
         
 		// ensure that the file is entitled "Aspect ClassA.InnerAspect" rather
 		// than "Class ClassA.InnerAspect"
-		String[] strings = { "Aspect ClassA.InnerAspect",
+		
+		String[] strings = null;
+		if (LangUtil.is18VMOrGreater()) {
+			strings = new String[] {
+				"Aspect ClassA.InnerAspect",
+				"
static aspect ClassA.InnerAspect",
+				"Class ClassA.InnerAspect",
+				"
static class ClassA.InnerAspect"};
+		}
+		else {
+			strings = new String[] {
+				"Aspect ClassA.InnerAspect",
 				"
static aspect ClassA.InnerAspect
extends java.lang.Object", "Class ClassA.InnerAspect", "
static class ClassA.InnerAspect
extends java.lang.Object"}; - List missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); - assertEquals("There should be 2 missing strings",2,missing.size()); - assertTrue(htmlFile.getName() + " should not have Class as it's title",missing.contains("Class ClassA.InnerAspect")); - assertTrue(htmlFile.getName() + " should not have class in its subtitle",missing.contains("
static class ClassA.InnerAspect
extends java.lang.Object")); + } + List missingStrings = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); + StringBuilder buf = new StringBuilder(); + for (String str:missingStrings) { + buf.append(str).append("\n"); + } + buf.append("HTMLFILE=\n").append(htmlFile).append("\n"); + assertEquals("There should be 2 missing strings:\n"+buf.toString(), 2, missingStrings.size()); + assertTrue(htmlFile.getName() + " should not have Class as it's title", + missingStrings.contains("Class ClassA.InnerAspect")); + if (LangUtil.is18VMOrGreater()) { + assertTrue(htmlFile.getName() + " should not have class in its subtitle", + missingStrings.contains("
static class ClassA.InnerAspect"));
+		}
+		else {
+			assertTrue(htmlFile.getName() + " should not have class in its subtitle",
+					missingStrings.contains("
static class ClassA.InnerAspect
extends java.lang.Object")); + } // get the html file for the enclosing class File htmlFileClass = new File(getAbsolutePathOutdir() + "/foo/ClassA.html"); @@ -146,14 +174,33 @@ public class CoverageTestCase extends AjdocTestCase { // ensure that the file is entitled "Class ClassA" and // has not been changed to "Aspect ClassA" - String[] classStrings = { "Class ClassA", - "public abstract class ClassA
extends java.lang.Object
", + String[] classStrings = null; + + if (LangUtil.is18VMOrGreater()) { + classStrings = new String[] { + "Class ClassA", + "public abstract class ClassA", "Aspect ClassA", - "public abstract aspect ClassA
extends java.lang.Object
"}; + "public abstract aspect ClassA"}; + } + else { + classStrings = new String[] { + "Class ClassA", + "public abstract class ClassA
extends java.lang.Object
", + "Aspect ClassA", + "public abstract aspect ClassA
extends java.lang.Object
"}; + } List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings); - assertEquals("There should be 2 missing strings",2,classMissing.size()); + assertEquals("There should be 2 missing strings:\n"+classMissing,2,classMissing.size()); assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",classMissing.contains("Aspect ClassA")); - assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",classMissing.contains("public abstract aspect ClassA
extends java.lang.Object
")); + if (LangUtil.is18VMOrGreater()) { + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", + classMissing.contains("public abstract aspect ClassA")); + } + else { + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", + classMissing.contains("public abstract aspect ClassA
extends java.lang.Object
")); + } } /** @@ -623,15 +670,32 @@ public class CoverageTestCase extends AjdocTestCase { // ensure that the file is entitled "Aspect PkgVisibleClass.NestedAspect" rather // than "Class PkgVisibleClass.NestedAspect" - String[] strings = { "Aspect PkgVisibleClass.NestedAspect", - "
static aspect PkgVisibleClass.NestedAspect
extends java.lang.Object", - "Class PkgVisibleClass.NestedAspect", - "
static class PkgVisibleClass.NestedAspect
extends java.lang.Object"}; - List missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); + String[] strings = null; + if (LangUtil.is18VMOrGreater()) { + strings = new String[] { + "Aspect PkgVisibleClass.NestedAspect", + "
static aspect PkgVisibleClass.NestedAspect",
+					"Class PkgVisibleClass.NestedAspect",
+					"
static class PkgVisibleClass.NestedAspect"};
+		}
+		else {
+			strings = new String[] { 
+					"Aspect PkgVisibleClass.NestedAspect",
+					"
static aspect PkgVisibleClass.NestedAspect
extends java.lang.Object", + "Class PkgVisibleClass.NestedAspect", + "
static class PkgVisibleClass.NestedAspect
extends java.lang.Object"}; + } + List missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); assertEquals("There should be 2 missing strings",2,missing.size()); assertTrue(htmlFile.getName() + " should not have Class as it's title",missing.contains("Class PkgVisibleClass.NestedAspect")); - assertTrue(htmlFile.getName() + " should not have class in its subtitle",missing.contains("
static class PkgVisibleClass.NestedAspect
extends java.lang.Object")); - + if (LangUtil.is18VMOrGreater()) { + assertTrue(htmlFile.getName() + " should not have class in its subtitle", + missing.contains("
static class PkgVisibleClass.NestedAspect"));
+		}
+		else {
+			assertTrue(htmlFile.getName() + " should not have class in its subtitle",
+					missing.contains("
static class PkgVisibleClass.NestedAspect
extends java.lang.Object")); + } // get the html file for the enclosing class File htmlFileClass = new File(getAbsolutePathOutdir() + "/PkgVisibleClass.html"); if (!htmlFileClass.exists()) { @@ -641,14 +705,33 @@ public class CoverageTestCase extends AjdocTestCase { // ensure that the file is entitled "Class PkgVisibleClass" and // has not been changed to "Aspect PkgVisibleClass" - String[] classStrings = { "Class PkgVisibleClass", - "class PkgVisibleClass
extends java.lang.Object", - "Aspect PkgVisibleClass", - "aspect PkgVisibleClass
extends java.lang.Object
"}; - List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings); + String[] classStrings = null; + if (LangUtil.is18VMOrGreater()) { + classStrings = new String[] { + "Class PkgVisibleClass", + "
class PkgVisibleClass",
+				"Aspect PkgVisibleClass",
+				"
aspect PkgVisibleClass"};
+		}
+		else {
+			classStrings = new String[] {
+					"Class PkgVisibleClass",
+					"class PkgVisibleClass
extends java.lang.Object", + "Aspect PkgVisibleClass", + "aspect PkgVisibleClass
extends java.lang.Object
"}; + } + List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings); assertEquals("There should be 2 missing strings",2,classMissing.size()); - assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",classMissing.contains("Aspect PkgVisibleClass")); - assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",classMissing.contains("aspect PkgVisibleClass
extends java.lang.Object
")); + if (LangUtil.is18VMOrGreater()) { + assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title", + classMissing.contains("Aspect PkgVisibleClass")); + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", + classMissing.contains("
aspect PkgVisibleClass"));
+		}
+		else {
+			assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title",classMissing.contains("Aspect PkgVisibleClass"));
+			assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",classMissing.contains("aspect PkgVisibleClass
extends java.lang.Object
")); + } } /** @@ -668,14 +751,31 @@ public class CoverageTestCase extends AjdocTestCase { } // ensure that the file is entitled "Aspect ClassWithNestedAspect.NestedAspect" // rather than "Class ClassWithNestedAspect.NestedAspect" - String[] strings = { "Aspect ClassWithNestedAspect.NestedAspect", - "
static aspect ClassWithNestedAspect.NestedAspect
extends java.lang.Object", + String[] strings = null; + if (LangUtil.is18VMOrGreater()) { + strings = new String [] { + "Aspect ClassWithNestedAspect.NestedAspect", + "
static aspect ClassWithNestedAspect.NestedAspect",
 				"Class ClassWithNestedAspect.NestedAspect",
-				"
static class ClassWithNestedAspect.NestedAspect
extends java.lang.Object"}; - List missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); + "
static class ClassWithNestedAspect.NestedAspect"};
+		}
+		else {
+			strings = new String [] {
+					"Aspect ClassWithNestedAspect.NestedAspect",
+					"
static a;spect ClassWithNestedAspect.NestedAspect
extends java.lang.Object", + "Class ClassWithNestedAspect.NestedAspect", + "
static class ClassWithNestedAspect.NestedAspect
extends java.lang.Object"}; + } + List missing = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings); assertEquals("There should be 2 missing strings",2,missing.size()); assertTrue(htmlFile.getName() + " should not have Class as it's title",missing.contains("Class ClassWithNestedAspect.NestedAspect")); - assertTrue(htmlFile.getName() + " should not have class in its subtitle",missing.contains("
static class ClassWithNestedAspect.NestedAspect
extends java.lang.Object")); + if (LangUtil.is18VMOrGreater()) { + assertTrue(htmlFile.getName() + " should not have class in its subtitle", + missing.contains("
static class ClassWithNestedAspect.NestedAspect"));
+		}
+		else {
+			assertTrue(htmlFile.getName() + " should not have class in its subtitle",missing.contains("
static class ClassWithNestedAspect.NestedAspect
extends java.lang.Object")); + } // get the html file for the enclosing class File htmlFileClass = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.html"); @@ -686,17 +786,35 @@ public class CoverageTestCase extends AjdocTestCase { // ensure that the file is entitled "Class ClassWithNestedAspect" and // has not been changed to "Aspect ClassWithNestedAspect" - String[] classStrings = { "Class ClassWithNestedAspect", - "public class ClassWithNestedAspect
extends java.lang.Object", - "Aspect ClassWithNestedAspect", - "public aspect ClassWithNestedAspect
extends java.lang.Object"}; - List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings); + String[] classStrings = null; + if (LangUtil.is18VMOrGreater()) { + classStrings = new String[] { + "Class ClassWithNestedAspect", + "public class ClassWithNestedAspect", + "Aspect ClassWithNestedAspect", + "public aspect ClassWithNestedAspect"}; + } + else { + classStrings = new String[] { + "Class ClassWithNestedAspect", + "public class ClassWithNestedAspect
extends java.lang.Object", + "Aspect ClassWithNestedAspect", + "public aspect ClassWithNestedAspect
extends java.lang.Object"}; + } + List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings); assertEquals("There should be 2 missing strings",2,classMissing.size()); - assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title", - classMissing.contains("Aspect ClassWithNestedAspect")); - assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", - classMissing.contains("public aspect ClassWithNestedAspect
extends java.lang.Object")); - + if (LangUtil.is18VMOrGreater()) { + assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title", + classMissing.contains("Aspect ClassWithNestedAspect")); + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", + classMissing.contains("public aspect ClassWithNestedAspect")); + } + else { + assertTrue(htmlFileClass.getName() + " should not have Aspect as it's title", + classMissing.contains("Aspect ClassWithNestedAspect")); + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", + classMissing.contains("public aspect ClassWithNestedAspect
extends java.lang.Object")); + } } /** -- cgit v1.2.3