*/
class HtmlDecorator {
- public static final String TYPE_NAME_LABEL = LangUtil.is15VMOrGreater()
- ? "type-name-label"
- : (LangUtil.is1dot8VMOrGreater() ? "typeNameLabel" : "strong");
+ public static final String TYPE_NAME_LABEL;
+ public static final String CLOSING_SPAN;
+
+ static {
+ if (LangUtil.is16VMOrGreater())
+ TYPE_NAME_LABEL = "element-name type-name-label";
+ else if (LangUtil.is15VMOrGreater())
+ TYPE_NAME_LABEL = "type-name-label";
+ else if (LangUtil.is1dot8VMOrGreater())
+ TYPE_NAME_LABEL = "typeNameLabel";
+ else
+ TYPE_NAME_LABEL = "strong";
+
+ if (LangUtil.is16VMOrGreater())
+ CLOSING_SPAN = "</span>";
+ else
+ CLOSING_SPAN = "";
+ }
private static final String POINTCUT_DETAIL = "Pointcut Detail";
private static final String ADVICE_DETAIL = "Advice Detail";
}
boolean br = true;
- int classStartIndex = fileContents.toString().indexOf("<BR>\nClass ");
+ contents = fileContents.toString();
+ int classStartIndex = contents.indexOf("<BR>\nClass ");
if (classStartIndex == -1) {
- classStartIndex = fileContents.toString().indexOf("<H2>\nClass ");
+ classStartIndex = contents.indexOf("<H2>\nClass ");
br = false;
}
if (classStartIndex == -1) {
// Java8 looks more like this:
// <h2 title="Class A" class="title">Class A</h2>
- classStartIndex = fileContents.toString().indexOf("<h2 title=\"Class ");
- int classEndIndex = fileContents.toString().indexOf("</h2>", classStartIndex);
+ classStartIndex = contents.indexOf("<h2 title=\"Class ");
+ int classEndIndex = contents.indexOf("</h2>", classStartIndex);
if (classStartIndex == -1) {
// Java 13 - replaced h2 with h1 here
- classStartIndex = fileContents.toString().indexOf("<h1 title=\"Class ");
- classEndIndex = fileContents.toString().indexOf("</h1>", classStartIndex);
+ classStartIndex = contents.indexOf("<h1 title=\"Class ");
+ classEndIndex = contents.indexOf("</h1>", classStartIndex);
}
if (classEndIndex != -1) {
// Convert it to "<h2 title="Aspect A" class="title">Aspect A</h2>"
- String classLine = fileContents.toString().substring(classStartIndex, classEndIndex);
+ String classLine = contents.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("</H2>", classStartIndex);
- if (classStartIndex != -1 && classEndIndex != -1) {
- String classLine = fileContents.toString().substring(classStartIndex, classEndIndex);
+ contents = fileContents.toString();
+ int classEndIndex = contents.indexOf("</H2>", classStartIndex);
+ if (classEndIndex != -1) {
+ String classLine = contents.substring(classStartIndex, classEndIndex);
String aspectLine = "";
if (br) {
aspectLine += "<BR>\n" + "Aspect " + classLine.substring(11, classLine.length());
fileContents.insert(classStartIndex, aspectLine);
}
}
- int secondClassStartIndex = fileContents.toString().indexOf("class <B>");
+ contents = fileContents.toString();
+ int secondClassStartIndex = contents.indexOf("class <B>");
if (secondClassStartIndex != -1) {
String name = decl.toSignatureString();
- int classEndIndex = fileContents.toString().indexOf(name + "</B><DT>");
- if (secondClassStartIndex != -1 && classEndIndex != -1) {
- StringBuffer sb = new StringBuffer(fileContents.toString().substring(secondClassStartIndex, classEndIndex));
+ int classEndIndex = contents.indexOf(name + "</B><DT>");
+ if (classEndIndex != -1) {
+ StringBuffer sb = new StringBuffer(contents.substring(secondClassStartIndex, classEndIndex));
sb.replace(0, 5, "aspect");
fileContents.delete(secondClassStartIndex, classEndIndex);
fileContents.insert(secondClassStartIndex, sb.toString());
}
}
else {
+ contents = fileContents.toString();
+ // Java16: <span class="modifiers">static class </span><span class="type-name-label">ClassA.InnerAspect</span>
// Java15: <pre>static class <span class="type-name-label">ClassA.InnerAspect</span>
// Java8: <pre>static class <span class="typeNameLabel">ClassA.InnerAspect</span>
// Java7 (464604): <pre>public class <span class="strong">Azpect</span>
- classStartIndex = fileContents.toString().indexOf("class <span class=\"" + TYPE_NAME_LABEL + "\">");
- int classEndIndex = fileContents.toString().indexOf("</span>", classStartIndex);
+ String startString = "class " + CLOSING_SPAN + "<span class=\"";
+ classStartIndex = contents.indexOf(startString + TYPE_NAME_LABEL + "\">");
+ int classEndIndex = contents.indexOf("</span>", classStartIndex + startString.length());
// This is where after Java version upgrades usually tests fail or the first time.
// Logging context information helps fixing the issue quickly.
if (classEndIndex != -1) {
// Convert it to "aspect <span class="TYPE_NAME_LABEL">ClassA.InnerAspect</span>"
- String aspectLine = "aspect" + fileContents.substring(classStartIndex + 5, classEndIndex);
+ String aspectLine = "aspect" + contents.substring(classStartIndex + 5, classEndIndex);
fileContents.delete(classStartIndex, classEndIndex);
fileContents.insert(classStartIndex, aspectLine);
}
import org.aspectj.util.LangUtil;
+import static org.aspectj.tools.ajdoc.HtmlDecorator.CLOSING_SPAN;
import static org.aspectj.tools.ajdoc.HtmlDecorator.TYPE_NAME_LABEL;
/**
* Test that the ajdoc for an inner aspect is entitled "Aspect" rather
* than "Class", but that the enclosing class is still "Class"
*/
- public void testInnerAspect() throws Exception {
- File[] files = {file1, file2};
- runAjdoc("private",AJDocConstants.VERSION,files);
-
- File htmlFile = new File(getAbsolutePathOutdir() + "/foo/ClassA.InnerAspect.html");
- if (!htmlFile.exists()) {
- fail("couldn't find " + htmlFile.getAbsolutePath()
- + " - were there compilation errors?");
- }
-
- // ensure that the file is entitled "Aspect ClassA.InnerAspect" rather
- // than "Class ClassA.InnerAspect"
+ public void testInnerAspect() throws Exception {
+ File[] files = { file1, file2 };
+ runAjdoc("private", AJDocConstants.VERSION, files);
- String[] strings = null;
- strings = new String[] {
- "Aspect ClassA.InnerAspect",
- "<pre>static aspect <span class=\"" + TYPE_NAME_LABEL + "\">ClassA.InnerAspect</span>",
- "Class ClassA.InnerAspect",
- "<pre>static class <span class=\"" + TYPE_NAME_LABEL + "\">ClassA.InnerAspect</span>"};
- List<String> 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"));
- assertTrue(htmlFile.getName() + " should not have class in its subtitle",
- missingStrings.contains("<pre>static class <span class=\"" + TYPE_NAME_LABEL + "\">ClassA.InnerAspect</span>"));
+ // Get the HTML file for the inner aspect
+ File htmlFile = new File(getAbsolutePathOutdir() + "/foo/ClassA.InnerAspect.html");
+ if (!htmlFile.exists()) {
+ fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
+ }
- // get the html file for the enclosing class
- File htmlFileClass = new File(getAbsolutePathOutdir() + "/foo/ClassA.html");
- if (!htmlFileClass.exists()) {
- fail("couldn't find " + htmlFileClass.getAbsolutePath()
- + " - were there compilation errors?");
- }
+ // Ensure that the file is entitled "Aspect ClassA.InnerAspect" rather than "Class ClassA.InnerAspect"
+
+ String[] strings = new String[] {
+ // These 2 should be missing because they reference "class", not "aspect"
+ "Class ClassA.InnerAspect",
+ "static class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassA.InnerAspect</span>",
+ // These 2 should be present (i.e. 0 missing) after AJ doc creation
+ "Aspect ClassA.InnerAspect",
+ "static aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassA.InnerAspect</span>"
+ };
+ List<String> missingStrings = AjdocOutputChecker.getMissingStringsInFile(htmlFile, strings);
+
+ StringBuilder buf = new StringBuilder();
+ buf.append("HTML file = ").append(htmlFile).append("\nMissing strings:\n");
+ for (String str : missingStrings)
+ buf.append(str).append("\n");
+
+ assertEquals(
+ "In " + htmlFile.getName() + " there should be 2 missing strings:\n" + buf,
+ 2, missingStrings.size()
+ );
+ assertEquals(
+ "In " + htmlFile.getName() + " no missing string should be aspect-related:\n" + buf,
+ 0, missingStrings.stream().filter(s -> s.contains("static aspect")).count()
+ );
+
+ // Get the HTML file for the enclosing class
+ htmlFile = new File(getAbsolutePathOutdir() + "/foo/ClassA.html");
+ if (!htmlFile.exists()) {
+ fail("couldn't find " + htmlFile.getAbsolutePath() + " - were there compilation errors?");
+ }
- // ensure that the file is entitled "Class ClassA" and
- // has not been changed to "Aspect ClassA"
- String[] classStrings = null;
+ // Ensure that the file is entitled "Class ClassA" and has not been changed to "Aspect ClassA"
- if (LangUtil.is13VMOrGreater()) {
- classStrings = new String[] {
- "Class ClassA</h1>",
- "public abstract class <span class=\"" + TYPE_NAME_LABEL + "\">ClassA</span>",
+ strings = new String[] {
+ // These 3 should be missing because they reference "aspect", not "class"
"Aspect ClassA</H2>",
- "public abstract aspect <span class=\"" + TYPE_NAME_LABEL + "\">ClassA</span>"};
- } else {
- classStrings = new String[] {
+ "Aspect ClassA</h2>",
+ "public abstract aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassA</span>",
+ // Of these 3, 2 should be present (i.e. 1 missing) after AJ doc creation
+ "Class ClassA</h1>",
"Class ClassA</h2>",
- "public abstract class <span class=\"" + TYPE_NAME_LABEL + "\">ClassA</span>",
- "Aspect ClassA</H2>",
- "public abstract aspect <span class=\"" + TYPE_NAME_LABEL + "\">ClassA</span>"};
+ "public abstract class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassA</span>"
+ };
+ missingStrings = AjdocOutputChecker.getMissingStringsInFile(htmlFile, strings);
+
+ buf = new StringBuilder();
+ buf.append("HTML file = ").append(htmlFile).append("\nMissing strings:\n");
+ for (String str : missingStrings)
+ buf.append(str).append("\n");
+
+ assertEquals(
+ "In " + htmlFile.getName() + " there should be 4 missing strings:\n" + buf,
+ 4, missingStrings.size()
+ );
+ assertEquals(
+ "In " + htmlFile.getName() + " 3 missing string should be aspect-related:\n" + buf,
+ 3, missingStrings.stream().filter(s -> s.contains("abstract aspect") || s.contains("Aspect ClassA")).count()
+ );
}
- List<String> 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</H2>"));
- assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",
- classMissing.contains("public abstract aspect <span class=\"" + TYPE_NAME_LABEL + "\">ClassA</span>"));
- }
/**
* Test that all the different types of advice appear
String[] strings = null;
strings = new String[] {
"Aspect PkgVisibleClass.NestedAspect",
- "<pre>static aspect <span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass.NestedAspect</span>",
+ "static aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass.NestedAspect</span>",
"Class PkgVisibleClass.NestedAspect",
- "<pre>static class <span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass.NestedAspect</span>"};
+ "static class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass.NestedAspect</span>"};
List<String> missingStrings = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings);
StringBuilder buf = new StringBuilder();
for (String str:missingStrings) {
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",
- missingStrings.contains("<pre>static class <span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass.NestedAspect</span>"));
+ missingStrings.contains("static class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass.NestedAspect</span>"));
// get the html file for the enclosing class
File htmlFileClass = new File(getAbsolutePathOutdir() + "/PkgVisibleClass.html");
if (!htmlFileClass.exists()) {
if (LangUtil.is13VMOrGreater()) {
classStrings = new String[] {
"Class PkgVisibleClass</h1>",
- "<pre>class <span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>",
+ "class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>",
"Aspect PkgVisibleClass</h2>",
- "<pre>aspect <span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>"};
+ "aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>"};
} else {
classStrings = new String[] {
"Class PkgVisibleClass</h2>",
- "<pre>class <span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>",
+ "class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>",
"Aspect PkgVisibleClass</h2>",
- "<pre>aspect <span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>"};
+ "aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>"};
}
List<String> 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</h2>"));
assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",
- classMissing.contains("<pre>aspect <span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>"));
+ classMissing.contains("aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">PkgVisibleClass</span>"));
}
/**
String[] strings = null;
strings = new String [] {
"Aspect ClassWithNestedAspect.NestedAspect",
- "<pre>static aspect <span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect.NestedAspect</span>",
+ "static aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect.NestedAspect</span>",
"Class ClassWithNestedAspect.NestedAspect",
- "<pre>static class <span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect.NestedAspect</span>"};
+ "static class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect.NestedAspect</span>"};
List<String> missingStrings = AjdocOutputChecker.getMissingStringsInFile(htmlFile,strings);
StringBuilder buf = new StringBuilder();
for (String str:missingStrings) {
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",
- missingStrings.contains("<pre>static class <span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect.NestedAspect</span>"));
+ missingStrings.contains("static class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect.NestedAspect</span>"));
// get the html file for the enclosing class
File htmlFileClass = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.html");
if (LangUtil.is13VMOrGreater()) {
classStrings = new String[] {
"Class ClassWithNestedAspect</h1>",
- "public class <span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>",
+ "public class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>",
"Aspect ClassWithNestedAspect</h2>",
- "public aspect <span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>"};
+ "public aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>"};
} else {
classStrings = new String[] {
"Class ClassWithNestedAspect</h2>",
- "public class <span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>",
+ "public class " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>",
"Aspect ClassWithNestedAspect</h2>",
- "public aspect <span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>"};
+ "public aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>"};
}
List<String> 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</h2>"));
assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",
- classMissing.contains("public aspect <span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>"));
+ classMissing.contains("public aspect " + CLOSING_SPAN + "<span class=\"" + TYPE_NAME_LABEL + "\">ClassWithNestedAspect</span>"));
}
/**