diff options
author | aclement <aclement> | 2006-01-16 15:24:18 +0000 |
---|---|---|
committer | aclement <aclement> | 2006-01-16 15:24:18 +0000 |
commit | dd97ef1adfcd1df2709c7287275215dc585dc572 (patch) | |
tree | 3611921d9151a8421af5356f05067232dee2eb69 /ajdoc | |
parent | 2208126bd1792695ff11d86118c53a9160ab9fee (diff) | |
download | aspectj-dd97ef1adfcd1df2709c7287275215dc585dc572.tar.gz aspectj-dd97ef1adfcd1df2709c7287275215dc585dc572.zip |
pr121711 - from Helen - comment #19
Diffstat (limited to 'ajdoc')
4 files changed, 281 insertions, 5 deletions
diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java b/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java index 87dc9d72c..d491694a1 100644 --- a/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java +++ b/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java @@ -204,7 +204,18 @@ class HtmlDecorator { // addIntroductionDocumentation(decl, fileContents, index); // addAdviceDocumentation(decl, fileContents, index); // addPointcutDocumentation(decl, fileContents, index); - addAspectDocumentation(decl, fileContents, index); + String fullname = ""; + if (decl.getParent().getKind().equals(IProgramElement.Kind.ASPECT) + || decl.getParent().getKind().equals(IProgramElement.Kind.CLASS)) { + fullname += decl.getParent().toSignatureString().concat(".").concat(decl.toSignatureString()); + } else { + fullname += decl.toSignatureString(); + } + // only add aspect documentation if we're in the correct + // file for the given IProgramElement + if (file.getName().indexOf(fullname + ".html") != -1) { + addAspectDocumentation(decl, fileContents, index); + } } else { decorateMemberDocumentation(decl, fileContents, index); @@ -215,12 +226,36 @@ class HtmlDecorator { // the case with an inner aspect not having the title "Aspect" if(decl.getKind().equals(IProgramElement.Kind.ASPECT) && file.getName().indexOf(decl.toSignatureString()) != -1) { + // only want to change "Class" to "Aspect" if we're in the + // file corresponding to the IProgramElement + String fullname = ""; + if (decl.getParent().getKind().equals(IProgramElement.Kind.ASPECT) + || decl.getParent().getKind().equals(IProgramElement.Kind.CLASS)) { + fullname += decl.getParent().toSignatureString().concat(".").concat(decl.toSignatureString()); + } else { + fullname += decl.toSignatureString(); + } + if (file.getName().indexOf(fullname + ".html") == -1) { + // we're still in the file for a parent IPE + continue; + } + + boolean br = true; int classStartIndex = fileContents.toString().indexOf("<BR>\nClass "); + if (classStartIndex == -1) { + classStartIndex = fileContents.toString().indexOf("<H2>\nClass "); + br = false; + } if (classStartIndex != -1) { int classEndIndex = fileContents.toString().indexOf("</H2>", classStartIndex); if (classStartIndex != -1 && classEndIndex != -1) { String classLine = fileContents.toString().substring(classStartIndex, classEndIndex); - String aspectLine = "<BR>\n" + "Aspect " + classLine.substring(11, classLine.length()); + String aspectLine = ""; + if (br) { + aspectLine += "<BR>\n" + "Aspect " + classLine.substring(11, classLine.length()); + } else { + aspectLine += "<H2>\n" + "Aspect " + classLine.substring(11, classLine.length()); + } fileContents.delete(classStartIndex, classEndIndex); fileContents.insert(classStartIndex, aspectLine); } @@ -593,11 +628,33 @@ class HtmlDecorator { hrefName = currDecl.getPackageName().replace('.', '/'); // hrefLink = "";//+ currDecl.getPackageName() + Config.DIR_SEP_CHAR; } + + // in the case of nested classes, in order for the links to work, + // need to have the correct file name which is something of the + // form parentClass.nestedAspect.html + List names = new ArrayList(); + IProgramElement parent = currDecl; + while (parent != null + && parent.getParent() != null + && (!parent.getParent().getKind().equals(IProgramElement.Kind.FILE_JAVA) + && !parent.getParent().getKind().equals(IProgramElement.Kind.FILE_ASPECTJ))) { + parent = parent.getParent(); + names.add(parent.toLinkLabelString()); + } + StringBuffer sbuff = new StringBuffer(); + for (int i = names.size() - 1; i >= 0; i--) { + String element = (String)names.get(i); + if (i == 0) { + sbuff.append(element); + } else { + sbuff.append(element + "."); + } + } // use the currDecl.toLabelString rather than currDecl.getName() // because two distinct advice blocks can have the same // currDecl.getName() and wouldn't both appear in the ajdoc hrefName += Config.DIR_SEP_CHAR + - currDecl.getParent().toLinkLabelString() + sbuff.toString() + "." + currDecl.toLabelString(); // need to replace " with quot; otherwise the links wont work @@ -609,8 +666,7 @@ class HtmlDecorator { sb.insert(nextQuote,"quot;"); nextQuote = sb.toString().indexOf("\""); } - hrefLink += currDecl.getParent().toLinkLabelString() + ".html" - + "#" + sb.toString(); + hrefLink += sbuff.toString() + ".html" + "#" + sb.toString(); if (!addedNames.contains(hrefName)) { adviceDoc = adviceDoc + diff --git a/ajdoc/testdata/coverage/pkg/ClassWithNestedAspect.java b/ajdoc/testdata/coverage/pkg/ClassWithNestedAspect.java new file mode 100644 index 000000000..153fd86bf --- /dev/null +++ b/ajdoc/testdata/coverage/pkg/ClassWithNestedAspect.java @@ -0,0 +1,15 @@ +package pkg; + +public class ClassWithNestedAspect { + + public void amethod() { + } + + static aspect NestedAspect { + pointcut p() : execution(* ClassWithNestedAspect.amethod(..)); + + before() : p() { + } + } + +} diff --git a/ajdoc/testdata/coverage/pkg/ClassWithNestedAspect2.java b/ajdoc/testdata/coverage/pkg/ClassWithNestedAspect2.java new file mode 100644 index 000000000..1a4650a5b --- /dev/null +++ b/ajdoc/testdata/coverage/pkg/ClassWithNestedAspect2.java @@ -0,0 +1,20 @@ +package pkg; + +public class ClassWithNestedAspect2 { + + public void amethod() { + } + + class InnerClass { + + aspect NestedAspect { + pointcut p() : execution(* ClassWithNestedAspect.amethod(..)); + + before() : p() { + } + } + + } + + +} diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java index 33a97d486..f0d86072d 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java @@ -597,6 +597,191 @@ public class CoverageTestCase extends AjdocTestCase { runAjdoc("private","1.4",files); } + /** + * Test that nested aspects appear with "aspect" in their title + * when the ajdoc file is written slightly differently (when it's + * written for this apsect, it's different than for testInnerAspect()) + */ + public void testNestedAspect() throws Exception { + File[] files = {file9}; + runAjdoc("private","1.4",files); + + File htmlFile = new File(getAbsolutePathOutdir() + "/PkgVisibleClass.NestedAspect.html"); + if (htmlFile == null || !htmlFile.exists()) { + fail("couldn't find " + htmlFile.getAbsolutePath() + + " - were there compilation errors?"); + } + + // ensure that the file is entitled "Aspect PkgVisibleClass.NestedAspect" rather + // than "Class PkgVisibleClass.NestedAspect" + String[] strings = { "Aspect PkgVisibleClass.NestedAspect", + "<PRE>static aspect <B>PkgVisibleClass.NestedAspect</B><DT>extends java.lang.Object</DL>", + "Class PkgVisibleClass.NestedAspect", + "<PRE>static class <B>PkgVisibleClass.NestedAspect</B><DT>extends java.lang.Object</DL>"}; + 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("<PRE>static class <B>PkgVisibleClass.NestedAspect</B><DT>extends java.lang.Object</DL>")); + + // get the html file for the enclosing class + File htmlFileClass = new File(getAbsolutePathOutdir() + "/PkgVisibleClass.html"); + if (htmlFileClass == null || !htmlFileClass.exists()) { + fail("couldn't find " + htmlFileClass.getAbsolutePath() + + " - were there compilation errors?"); + } + + // ensure that the file is entitled "Class PkgVisibleClass" and + // has not been changed to "Aspect PkgVisibleClass" + String[] classStrings = { "Class PkgVisibleClass</H2>", + "class <B>PkgVisibleClass</B><DT>extends java.lang.Object</DL>", + "Aspect PkgVisibleClass</H2>", + "aspect <B>PkgVisibleClass</B><DT>extends java.lang.Object<DT>"}; + 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</H2>")); + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle",classMissing.contains("aspect <B>PkgVisibleClass</B><DT>extends java.lang.Object<DT>")); + } + + /** + * Test that in the case when you have a nested aspect whose + * name is part of the enclosing class, for example a class called + * ClassWithNestedAspect has nested aspect called NestedAspect, + * that the titles for the ajdoc are correct. + */ + public void testNestedAspectWithSimilarName() throws Exception { + File[] files = {new File(getAbsoluteProjectDir() + "/pkg/ClassWithNestedAspect.java")}; + runAjdoc("private","1.4",files); + + File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.NestedAspect.html"); + if (htmlFile == null || !htmlFile.exists()) { + fail("couldn't find " + htmlFile.getAbsolutePath() + + " - were there compilation errors?"); + } + // ensure that the file is entitled "Aspect ClassWithNestedAspect.NestedAspect" + // rather than "Class ClassWithNestedAspect.NestedAspect" + String[] strings = { "Aspect ClassWithNestedAspect.NestedAspect", + "<PRE>static aspect <B>ClassWithNestedAspect.NestedAspect</B><DT>extends java.lang.Object</DL>", + "Class ClassWithNestedAspect.NestedAspect", + "<PRE>static class <B>ClassWithNestedAspect.NestedAspect</B><DT>extends java.lang.Object</DL>"}; + 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("<PRE>static class <B>ClassWithNestedAspect.NestedAspect</B><DT>extends java.lang.Object</DL>")); + + // get the html file for the enclosing class + File htmlFileClass = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.html"); + if (htmlFileClass == null || !htmlFileClass.exists()) { + fail("couldn't find " + htmlFileClass.getAbsolutePath() + + " - were there compilation errors?"); + } + + // ensure that the file is entitled "Class ClassWithNestedAspect" and + // has not been changed to "Aspect ClassWithNestedAspect" + String[] classStrings = { "Class ClassWithNestedAspect</H2>", + "public class <B>ClassWithNestedAspect</B><DT>extends java.lang.Object</DL>", + "Aspect ClassWithNestedAspect</H2>", + "public aspect <B>ClassWithNestedAspect</B><DT>extends java.lang.Object</DL>"}; + 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</H2>")); + assertTrue(htmlFileClass.getName() + " should not have aspect in its subtitle", + classMissing.contains("public aspect <B>ClassWithNestedAspect</B><DT>extends java.lang.Object</DL>")); + + } + + /** + * Test that everythings being decorated correctly within the ajdoc + * for the aspect when the aspect is a nested aspect + */ + public void testAdviceInNestedAspect() throws Exception { + File[] files = {new File(getAbsoluteProjectDir() + "/pkg/ClassWithNestedAspect.java")}; + runAjdoc("private","1.4",files); + + File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.NestedAspect.html"); + if (htmlFile == null || !htmlFile.exists()) { + fail("couldn't find " + htmlFile.getAbsolutePath() + + " - were there compilation errors?"); + } + + boolean b = AjdocOutputChecker.detailSectionContainsRel( + htmlFile,"ADVICE DETAIL SUMMARY", + "before(): p..", + HtmlDecorator.HtmlRelationshipKind.ADVISES, + "HREF=\"../pkg/ClassWithNestedAspect.html#amethod()\""); + assertTrue("Should have 'before(): p.. advises HREF=\"../pkg/ClassWithNestedAspect.html#amethod()\"" + + "' in the Advice Detail section", b); + b = AjdocOutputChecker.summarySectionContainsRel( + htmlFile,"ADVICE SUMMARY", + "before(): p..", + HtmlDecorator.HtmlRelationshipKind.ADVISES, + "HREF=\"../pkg/ClassWithNestedAspect.html#amethod()\""); + assertTrue("Should have 'before(): p.. advises HREF=\"../pkg/ClassWithNestedAspect.html#amethod()\"" + + "' in the Advice Summary section", b); + + } + + /** + * Test that everythings being decorated correctly within the ajdoc + * for the advised class when the aspect is a nested aspect + */ + public void testAdvisedByInNestedAspect() throws Exception { + File[] files = {new File(getAbsoluteProjectDir() + "/pkg/ClassWithNestedAspect.java")}; + runAjdoc("private","1.4",files); + + File htmlFile = new File(getAbsolutePathOutdir() + "/pkg/ClassWithNestedAspect.html"); + if (htmlFile == null || !htmlFile.exists()) { + fail("couldn't find " + htmlFile.getAbsolutePath() + + " - were there compilation errors?"); + } + + boolean b = AjdocOutputChecker.containsString(htmlFile,"POINTCUT SUMMARY "); + assertFalse(htmlFile.getName() + " should not contain a pointcut summary section",b); + b = AjdocOutputChecker.containsString(htmlFile,"ADVICE SUMMARY "); + assertFalse(htmlFile.getName() + " should not contain an adivce summary section",b); + b = AjdocOutputChecker.containsString(htmlFile,"POINTCUT DETAIL "); + assertFalse(htmlFile.getName() + " should not contain a pointcut detail section",b); + b = AjdocOutputChecker.containsString(htmlFile,"ADVICE DETAIL "); + assertFalse(htmlFile.getName() + " should not contain an advice detail section",b); + + b = AjdocOutputChecker.detailSectionContainsRel( + htmlFile,"=== METHOD DETAIL", + "amethod()", + HtmlDecorator.HtmlRelationshipKind.ADVISED_BY, + "HREF=\"../pkg/ClassWithNestedAspect.NestedAspect.html#before(): p..\""); + assertTrue("Should have 'amethod() advised by " + + "HREF=\"../pkg/ClassWithNestedAspect.NestedAspect.html#before(): p..\"" + + "' in the Method Detail section", b); + + b = AjdocOutputChecker.detailSectionContainsRel( + htmlFile,"=== METHOD DETAIL", + "amethod()", + HtmlDecorator.HtmlRelationshipKind.ADVISED_BY, + "pkg.ClassWithNestedAspect.NestedAspect.NestedAspect.before(): p.."); + assertFalse("Should not have the label " + + "pkg.ClassWithNestedAspect.NestedAspect.NestedAspect.before(): p.." + + " in the Method Detail section", b); + + b = AjdocOutputChecker.summarySectionContainsRel( + htmlFile,"=== METHOD SUMMARY", + "amethod()", + HtmlDecorator.HtmlRelationshipKind.ADVISED_BY, + "HREF=\"../pkg/ClassWithNestedAspect.NestedAspect.html#before(): p..\""); + assertTrue("Should have 'amethod() advised by " + + "HREF=\"../pkg/ClassWithNestedAspect.NestedAspect.html#before(): p..\"" + + "' in the Method Summary section", b); + + b = AjdocOutputChecker.detailSectionContainsRel( + htmlFile,"=== METHOD SUMMARY", + "amethod()", + HtmlDecorator.HtmlRelationshipKind.ADVISED_BY, + "pkg.ClassWithNestedAspect.NestedAspect.NestedAspect.before(): p.."); + assertFalse("Should not have the label " + + "pkg.ClassWithNestedAspect.NestedAspect.NestedAspect.before(): p.." + + " in the Method Summary section", b); + + } + private void createFiles() { file0 = new File(getAbsoluteProjectDir() + "/InDefaultPackage.java"); file1 = new File(getAbsoluteProjectDir() + "/foo/ClassA.java"); |