From 2fd6804db8aebfe6634e4df7d5e5c71fe856d4f6 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Sun, 14 Mar 2021 00:09:02 +0700 Subject: Fix 'ajdoc' tests for Java 15 build Signed-off-by: Alexander Kriegisch --- .../org/aspectj/tools/ajdoc/HtmlDecorator.java | 22 +++--- .../aspectj/tools/ajdoc/AjdocOutputChecker.java | 80 +++++++++++----------- .../org/aspectj/tools/ajdoc/AjdocTestCase.java | 40 +++++------ .../org/aspectj/tools/ajdoc/CoverageTestCase.java | 70 +++++++++++-------- 4 files changed, 111 insertions(+), 101 deletions(-) (limited to 'ajdoc/src') diff --git a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java index 42d029e06..3e3a05c07 100644 --- a/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java +++ b/ajdoc/src/main/java/org/aspectj/tools/ajdoc/HtmlDecorator.java @@ -31,6 +31,7 @@ import org.aspectj.asm.AsmManager; import org.aspectj.asm.HierarchyWalker; import org.aspectj.asm.IProgramElement; import org.aspectj.asm.IRelationship; +import org.aspectj.util.LangUtil; import org.aspectj.util.TypeSafeEnum; /** @@ -38,6 +39,10 @@ import org.aspectj.util.TypeSafeEnum; */ class HtmlDecorator { + public static final String TYPE_NAME_LABEL = LangUtil.is15VMOrGreater() + ? "type-name-label" + : (LangUtil.is1dot8VMOrGreater() ? "typeNameLabel" : "strong"); + private static final String POINTCUT_DETAIL = "Pointcut Detail"; private static final String ADVICE_DETAIL = "Advice Detail"; private static final String DECLARE_DETAIL = "Declare Detail"; @@ -267,19 +272,14 @@ class HtmlDecorator { } } else { - // Java8: - //
static class ClassA.InnerAspect
-					classStartIndex = fileContents.toString().indexOf("class ");
-					if (classStartIndex == -1) {
-						// Java7: 464604
-						// 
public class Azpect
-						classStartIndex = fileContents.toString().indexOf("class ");
-					}
+					// Java15: 
static class ClassA.InnerAspect
+					// Java8: 
static class ClassA.InnerAspect
+					// Java7 (464604): 
public class Azpect
+					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);
+						// Convert it to "aspect ClassA.InnerAspect"
+						String aspectLine = "aspect" + fileContents.substring(classStartIndex + 5, classEndIndex);
 						fileContents.delete(classStartIndex, classEndIndex);
 						fileContents.insert(classStartIndex, aspectLine);
 					}
diff --git a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java
index 431018401..3e69f4887 100644
--- a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java
+++ b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocOutputChecker.java
@@ -1,11 +1,11 @@
 /********************************************************************
- * Copyright (c) 2005 Contributors. All rights reserved. 
- * This program and the accompanying materials are made available 
- * under the terms of the Eclipse Public License v1.0 
- * which accompanies this distribution and is available at 
- * http://eclipse.org/legal/epl-v10.html 
- *  
- * Contributors: IBM Corporation - initial API and implementation 
+ * Copyright (c) 2005 Contributors. All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
  * 				 Helen Hawkins   - iniital version
  *******************************************************************/
 package org.aspectj.tools.ajdoc;
@@ -25,8 +25,8 @@ import org.aspectj.util.LangUtil;
 public class AjdocOutputChecker {
 
 	/**
-	 * Checks whether the given html file contains the required String. 
-	 * 
+	 * Checks whether the given html file contains the required String.
+	 *
 	 * @param htmlFile
 	 * @param requiredString
 	 * @return true if the file contains the given string or
@@ -53,12 +53,12 @@ public class AjdocOutputChecker {
 
 	/**
 	 * 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 getMissingStringsInFile(File htmlFile, String[] requiredStrings) throws Exception {
 		List missingStrings = new ArrayList<>();
 		for (String string : requiredStrings) {
@@ -68,16 +68,16 @@ public class AjdocOutputChecker {
 		}
 		return missingStrings;
 	}
-	
+
 	/**
 	 * Checks whether the section of the html file contains the
 	 * required String
-	 * 
+	 *
 	 * @param htmlFile
 	 * @param requiredString
 	 * @param sectionHeader
-	 * @return true if the file contains the given string within the 
-	 * required section or false otherwise (or if the file is null or 
+	 * @return true if the file contains the given string within the
+	 * required section or false otherwise (or if the file is null or
 	 * not an html file)
 	 * @throws Exception
 	 */
@@ -91,7 +91,7 @@ public class AjdocOutputChecker {
 		while (line != null) {
 			if (line.contains(sectionHeader)) {
 				String nextLine = reader.readLine();
-				while (nextLine != null && 
+				while (nextLine != null &&
 						(!nextLine.contains("========"))) {
 					if (nextLine.contains(requiredString)) {
 						reader.close();
@@ -107,11 +107,11 @@ public class AjdocOutputChecker {
 		reader.close();
 		return false;
 	}
-	
+
 	/**
 	 * Returns those strings from the given array which aren't in the
-	 * ajdoc html file	 
-	 *  
+	 * ajdoc html file
+	 *
 	 * @param htmlFile
 	 * @param an array of requiredStrings
 	 * @param sectionHeader
@@ -130,10 +130,10 @@ public class AjdocOutputChecker {
 	}
 
 	/**
-	 * Returns whether the class data section has the expected 
-	 * relationship and target i.e. have the relationships been 
+	 * Returns whether the class data section has the expected
+	 * relationship and target i.e. have the relationships been
 	 * applied to the type.
-	 * 
+	 *
 	 * @param the ajdoc html file
 	 * @param the detail sectionHeader, for example "DECLARE DETAIL SUMMARY"
 	 * @param the source of the relationship, for example "Point()"
@@ -143,7 +143,7 @@ public class AjdocOutputChecker {
 	 * false otherwise
 	 */
 	public static boolean classDataSectionContainsRel(File htmlFile,
-			HtmlDecorator.HtmlRelationshipKind relationship, 
+			HtmlDecorator.HtmlRelationshipKind relationship,
 			String target) throws Exception {
 		if (((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html"))) {
 			return false;
@@ -154,7 +154,7 @@ public class AjdocOutputChecker {
 			if (line.contains("START OF CLASS DATA")) {
 				// found the required class data section
 				String subLine = reader.readLine();
-				while(subLine != null 
+				while(subLine != null
 						&& (!subLine.contains("========"))){
 					int relIndex = subLine.indexOf(relationship.toString());
 					int targetIndex = subLine.indexOf(target);
@@ -175,11 +175,11 @@ public class AjdocOutputChecker {
 		reader.close();
 		return false;
 	}
-	
+
 	/**
-	 * Returns whether the supplied source has the expected 
+	 * Returns whether the supplied source has the expected
 	 * relationship and target within the given detail section
-	 * 
+	 *
 	 * @param the ajdoc html file
 	 * @param the detail sectionHeader, for example "DECLARE DETAIL SUMMARY"
 	 * @param the source of the relationship, for example "Point()"
@@ -188,9 +188,9 @@ public class AjdocOutputChecker {
 	 * @return true if the section contains the expected source/relationship/target,
 	 * false otherwise
 	 */
-	public static boolean detailSectionContainsRel(File htmlFile, 
-			String sectionHeader, String source, 
-			HtmlDecorator.HtmlRelationshipKind relationship, 
+	public static boolean detailSectionContainsRel(File htmlFile,
+			String sectionHeader, String source,
+			HtmlDecorator.HtmlRelationshipKind relationship,
 			String target) throws Exception {
 		if (((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html"))) {
 			return false;
@@ -210,9 +210,9 @@ public class AjdocOutputChecker {
 							nextLine.contains("NAME=\"" + source + "\"") || nextLine.contains("name=\"" + source + "\"")) {
 						// found the required subsection
 						String subLine = reader.readLine();
-						while(subLine != null 
+						while(subLine != null
 								&& (!subLine.contains("========"))
-								&& (!subLine.contains("NAME") && !subLine.contains("name"))) {
+								&& (!subLine.contains("NAME=") && !subLine.contains("name="))) {
 							int relIndex = subLine.indexOf(relationship.toString());
 							int targetIndex = subLine.indexOf(target);
 							if ((relIndex != -1) && (targetIndex != -1)) {
@@ -239,9 +239,9 @@ public class AjdocOutputChecker {
 	}
 
 	/**
-	 * Returns whether the supplied source has the expected 
+	 * Returns whether the supplied source has the expected
 	 * relationship and target within the given summary section
-	 * 
+	 *
 	 * @param the ajdoc html file
 	 * @param the detail sectionHeader, for example "DECLARE SUMMARY"
 	 * @param the source of the relationship, for example "Point()"
@@ -251,10 +251,10 @@ public class AjdocOutputChecker {
 	 * false otherwise
 	 */
 	public static boolean summarySectionContainsRel(
-			File htmlFile, 
-			String sectionHeader, 
-			String source, 
-			HtmlDecorator.HtmlRelationshipKind relationship, 
+			File htmlFile,
+			String sectionHeader,
+			String source,
+			HtmlDecorator.HtmlRelationshipKind relationship,
 			String target) throws Exception {
 		if (((htmlFile == null) || !htmlFile.getAbsolutePath().endsWith("html"))) {
 			return false;
@@ -272,7 +272,7 @@ public class AjdocOutputChecker {
 					if (nextLine.contains(source)) {
 						// found the required subsection
 						String subLine = nextLine;
-						while(subLine != null 
+						while(subLine != null
 								&& (!subLine.contains("========"))
 								&& (!subLine.contains(""))) {
 							int relIndex = subLine.indexOf(relationship.toString());
@@ -299,5 +299,5 @@ public class AjdocOutputChecker {
 		reader.close();
 		return false;
 	}
-	
+
 }
diff --git a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java
index acfb5eda4..0baeb7dcd 100644
--- a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java
+++ b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/AjdocTestCase.java
@@ -1,11 +1,11 @@
 /********************************************************************
- * Copyright (c) 2005 Contributors. All rights reserved. 
- * This program and the accompanying materials are made available 
- * under the terms of the Eclipse Public License v1.0 
- * which accompanies this distribution and is available at 
- * http://eclipse.org/legal/epl-v10.html 
- *  
- * Contributors: IBM Corporation - initial API and implementation 
+ * Copyright (c) 2005 Contributors. All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://eclipse.org/legal/epl-v10.html
+ *
+ * Contributors: IBM Corporation - initial API and implementation
  * 				 Helen Hawkins   - iniital version
  *******************************************************************/
 package org.aspectj.tools.ajdoc;
@@ -160,12 +160,12 @@ public abstract class AjdocTestCase extends TestCase {
 		if (inputFiles.length == 0) {
 			fail("need to pass some files into ajdoc");
 		}
-		if (!sourceLevel.equals("1.3") && 
-			!sourceLevel.equals("1.4") && 
-			!sourceLevel.equals("1.5") && 
-			!sourceLevel.equals("1.6") && 
-			!sourceLevel.equals("1.7") && 
-			!sourceLevel.equals("1.8") && 
+		if (!sourceLevel.equals("1.3") &&
+			!sourceLevel.equals("1.4") &&
+			!sourceLevel.equals("1.5") &&
+			!sourceLevel.equals("1.6") &&
+			!sourceLevel.equals("1.7") &&
+			!sourceLevel.equals("1.8") &&
 			!sourceLevel.equals("1.9") &&
 			!sourceLevel.equals("10")) {
 			fail("need to pass ajdoc '1.3' > '1.9' as the source level");
@@ -191,12 +191,12 @@ public abstract class AjdocTestCase extends TestCase {
 		if (!visibility.equals("public") && !visibility.equals("protected") && !visibility.equals("private")) {
 			fail("need to pass 'public','protected' or 'private' visibility to ajdoc");
 		}
-		if (!sourceLevel.equals("1.3") && 
-			!sourceLevel.equals("1.4") && 
-			!sourceLevel.equals("1.5") && 
-			!sourceLevel.equals("1.6") && 
-			!sourceLevel.equals("1.7") && 
-			!sourceLevel.equals("1.8") && 
+		if (!sourceLevel.equals("1.3") &&
+			!sourceLevel.equals("1.4") &&
+			!sourceLevel.equals("1.5") &&
+			!sourceLevel.equals("1.6") &&
+			!sourceLevel.equals("1.7") &&
+			!sourceLevel.equals("1.8") &&
 			!sourceLevel.equals("1.9") &&
 			!sourceLevel.startsWith("9") &&
 			!sourceLevel.startsWith("10")) {
@@ -217,7 +217,7 @@ public abstract class AjdocTestCase extends TestCase {
 		args[2] = sourceLevel;
 		args[3] = "-classpath";
 		StringBuilder classpath = new StringBuilder();
-		if (LangUtil.is19VMOrGreater()) {
+		if (LangUtil.is9VMOrGreater()) {
 			classpath.append(LangUtil.getJrtFsFilePath()).append(File.pathSeparator);
 		}
 		classpath.append(AjdocTests.ASPECTJRT_PATH.getPath());
diff --git a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/CoverageTestCase.java b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/CoverageTestCase.java
index ea8568cd8..3be100998 100644
--- a/ajdoc/src/test/java/org/aspectj/tools/ajdoc/CoverageTestCase.java
+++ b/ajdoc/src/test/java/org/aspectj/tools/ajdoc/CoverageTestCase.java
@@ -131,9 +131,9 @@ public class CoverageTestCase extends AjdocTestCase {
 		String[] strings = null;
 		strings = new String[] {
 			"Aspect ClassA.InnerAspect",
-			"
static aspect ClassA.InnerAspect",
+			"
static aspect ClassA.InnerAspect",
 			"Class ClassA.InnerAspect",
-			"
static class ClassA.InnerAspect"};
+			"
static class ClassA.InnerAspect"};
 		List missingStrings = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings);
 		StringBuilder buf = new StringBuilder();
 		for (String str:missingStrings) {
@@ -144,7 +144,7 @@ public class CoverageTestCase extends AjdocTestCase {
 		assertTrue(htmlFile.getName() + " should not have Class as it's title",
 				missingStrings.contains("Class ClassA.InnerAspect"));
 		assertTrue(htmlFile.getName() + " should not have class in its subtitle",
-				missingStrings.contains("
static class ClassA.InnerAspect"));
+				missingStrings.contains("
static class ClassA.InnerAspect"));
 
 		// get the html file for the enclosing class
         File htmlFileClass = new File(getAbsolutePathOutdir() + "/foo/ClassA.html");
@@ -160,21 +160,21 @@ public class CoverageTestCase extends AjdocTestCase {
 		if (LangUtil.is13VMOrGreater()) {
 			classStrings = new String[] {
 				"Class ClassA",
-				"public abstract class ClassA",
+				"public abstract class ClassA",
 				"Aspect ClassA",
-				"public abstract aspect ClassA"};
+				"public abstract aspect ClassA"};
 		} else {
 			classStrings = new String[] {
 				"Class ClassA",
-				"public abstract class ClassA",
+				"public abstract class ClassA",
 				"Aspect ClassA",
-				"public abstract aspect ClassA"};
+				"public abstract aspect ClassA"};
 		}
 		List classMissing = AjdocOutputChecker.getMissingStringsInFile(htmlFileClass,classStrings);
 		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"));
+				classMissing.contains("public abstract aspect ClassA"));
 	}
 
     /**
@@ -657,14 +657,19 @@ public class CoverageTestCase extends AjdocTestCase {
 		String[] strings = null;
 		strings = new String[] {
 				"Aspect PkgVisibleClass.NestedAspect",
-				"
static aspect PkgVisibleClass.NestedAspect",
+				"
static aspect PkgVisibleClass.NestedAspect",
 				"Class PkgVisibleClass.NestedAspect",
-				"
static class PkgVisibleClass.NestedAspect"};
-		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"));
+				"
static class PkgVisibleClass.NestedAspect"};
+		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",2,missingStrings.size());
+		assertTrue(htmlFile.getName() + " should not have Class as it's title",missingStrings.contains("Class PkgVisibleClass.NestedAspect"));
 		assertTrue(htmlFile.getName() + " should not have class in its subtitle",
-				missing.contains("
static class PkgVisibleClass.NestedAspect"));
+				missingStrings.contains("
static class PkgVisibleClass.NestedAspect"));
 		// get the html file for the enclosing class
         File htmlFileClass = new File(getAbsolutePathOutdir() + "/PkgVisibleClass.html");
 		if (!htmlFileClass.exists()) {
@@ -678,22 +683,22 @@ public class CoverageTestCase extends AjdocTestCase {
 		if (LangUtil.is13VMOrGreater()) {
 			classStrings = new String[] {
 				"Class PkgVisibleClass",
-				"
class PkgVisibleClass",
+				"
class PkgVisibleClass",
 				"Aspect PkgVisibleClass",
-				"
aspect PkgVisibleClass"};
+				"
aspect PkgVisibleClass"};
 		} else {
 			classStrings = new String[] {
 				"Class PkgVisibleClass",
-				"
class PkgVisibleClass",
+				"
class PkgVisibleClass",
 				"Aspect PkgVisibleClass",
-				"
aspect PkgVisibleClass"};
+				"
aspect PkgVisibleClass"};
 		}
 		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"));
+				classMissing.contains("
aspect PkgVisibleClass"));
 	}
 
 	/**
@@ -716,14 +721,19 @@ public class CoverageTestCase extends AjdocTestCase {
 		String[] strings = null;
 		strings = new String [] {
 			"Aspect ClassWithNestedAspect.NestedAspect",
-			"
static aspect ClassWithNestedAspect.NestedAspect",
+			"
static aspect ClassWithNestedAspect.NestedAspect",
 			"Class ClassWithNestedAspect.NestedAspect",
-			"
static class ClassWithNestedAspect.NestedAspect"};
-		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"));
+			"
static class ClassWithNestedAspect.NestedAspect"};
+		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",2,missingStrings.size());
+		assertTrue(htmlFile.getName() + " should not have Class as it's title",missingStrings.contains("Class ClassWithNestedAspect.NestedAspect"));
 		assertTrue(htmlFile.getName() + " should not have class in its subtitle",
-				missing.contains("
static class ClassWithNestedAspect.NestedAspect"));
+				missingStrings.contains("
static class ClassWithNestedAspect.NestedAspect"));
 
 		// get the html file for the enclosing class
         File htmlFileClass = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.html");
@@ -738,22 +748,22 @@ public class CoverageTestCase extends AjdocTestCase {
 		if (LangUtil.is13VMOrGreater()) {
 			classStrings = new String[] {
 				"Class ClassWithNestedAspect",
-				"public class ClassWithNestedAspect",
+				"public class ClassWithNestedAspect",
 				"Aspect ClassWithNestedAspect",
-				"public aspect ClassWithNestedAspect"};
+				"public aspect ClassWithNestedAspect"};
 		} else {
 			classStrings = new String[] {
 				"Class ClassWithNestedAspect",
-				"public class ClassWithNestedAspect",
+				"public class ClassWithNestedAspect",
 				"Aspect ClassWithNestedAspect",
-				"public aspect ClassWithNestedAspect"};
+				"public aspect ClassWithNestedAspect"};
 		}
 		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"));
+				classMissing.contains("public aspect ClassWithNestedAspect"));
 	}
 
 	/**
-- 
cgit v1.2.3