From b460597575b05920885bd2f5f226b0140b687d6e Mon Sep 17 00:00:00 2001 From: mkersten Date: Thu, 13 Jan 2005 15:53:01 +0000 Subject: [PATCH] Fixed 3 bugs reported in bug#82340, including correct use of visibility modifiers. --- .../aspectj/tools/ajdoc/HtmlDecorator.java | 201 ++++++++++-------- .../tools/ajdoc/StubFileGenerator.java | 2 +- ajdoc/testdata/bug82340/.cvsignore | 1 + ajdoc/testdata/bug82340/Pointcuts.java | 27 +++ ajdoc/testdata/coverage/foo/NoMembers.java | 2 + .../aspectj/tools/ajdoc/CoverageTestCase.java | 26 +-- .../tools/ajdoc/PointcutVisibilityTest.java | 29 +++ 7 files changed, 184 insertions(+), 104 deletions(-) create mode 100644 ajdoc/testdata/bug82340/.cvsignore create mode 100644 ajdoc/testdata/bug82340/Pointcuts.java create mode 100644 ajdoc/testsrc/org/aspectj/tools/ajdoc/PointcutVisibilityTest.java diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java b/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java index 43d7b1851..a2cb7919b 100644 --- a/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java +++ b/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java @@ -30,6 +30,7 @@ class HtmlDecorator { static Hashtable declIDTable = null; static SymbolManager symbolManager = null; static File rootDir = null; + static String docVisibilityModifier; static void decorateHTMLFromInputFiles(Hashtable table, File newRootDir, @@ -39,6 +40,7 @@ class HtmlDecorator { rootDir = newRootDir; declIDTable = table; symbolManager = sm; + docVisibilityModifier = docModifier; for (int i = 0; i < inputFiles.length; i++) { decorateHTMLFromDecls(symbolManager.getDeclarations(inputFiles[i].getCanonicalPath()), rootDir.getCanonicalPath() + Config.DIR_SEP_CHAR, @@ -73,11 +75,7 @@ class HtmlDecorator { boolean nestedClass = false; if ( decl.isType() ) { boolean decorateFile = true; - if ( (docModifier.equals("private")) || // everything - (docModifier.equals("package") && decl.getModifiers().indexOf( "private" ) == -1) || // package - (docModifier.equals("protected") && (decl.getModifiers().indexOf( "protected" ) != -1 || - decl.getModifiers().indexOf( "public" ) != -1 )) || - (docModifier.equals("public") && decl.getModifiers().indexOf( "public" ) != -1) ) { + if (isAboveVisibility(decl.getNode())) { visibleFileList.add(decl.getSignature()); String packageName = decl.getPackageName(); String filename = ""; @@ -192,10 +190,13 @@ class HtmlDecorator { } } - // Change "Class" to "Aspect", HACK: depends on "affects:" - int classStartIndex = fileContents.toString().indexOf("
\nClass"); + // Change "Class" to "Aspect" + // HACK: depends on matching presence of advice or pointcut summary + int classStartIndex = fileContents.toString().indexOf("
\nClass "); + int pointcutSummaryIndex = fileContents.toString().indexOf("Pointcut Summary"); + int adviceSummaryIndex = fileContents.toString().indexOf("Advice Summary"); if (classStartIndex != -1 && - fileContents.toString().indexOf("Advises:") != -1) { + (adviceSummaryIndex != -1 || pointcutSummaryIndex != -1)) { int classEndIndex = fileContents.toString().indexOf("", classStartIndex); if (classStartIndex != -1 && classEndIndex != -1) { String classLine = fileContents.toString().substring(classStartIndex, classEndIndex); @@ -211,10 +212,6 @@ class HtmlDecorator { } static void addAspectDocumentation(IProgramElement node, StringBuffer fileBuffer, int index ) { -// List relations = AsmManager.getDefault().getRelationshipMap().get(node); -// System.err.println("> node: " + node + ", " + "relations: " + relations); - - List pointcuts = new ArrayList(); List advice = new ArrayList(); for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) { @@ -255,6 +252,8 @@ class HtmlDecorator { List decls, String kind, int index) { + if (!declsAboveVisibilityExist(decls)) return; + int insertIndex = findSummaryIndex(fileBuffer, index); // insert the head of the table @@ -269,52 +268,53 @@ class HtmlDecorator { // insert the body of the table for ( int i = 0; i < decls.size(); i++ ) { IProgramElement decl = (IProgramElement)decls.get(i); - - // insert the table row accordingly - String comment = generateSummaryComment(decl); - String entry = ""; - if ( kind.equals( "Advice Summary" ) ) { - entry += - "" + - "" + - "" + generateAdviceSignatures(decl) + - "
 "; - if (!comment.equals("")) { - entry += comment + "

"; + if (isAboveVisibility(decl)) { + // insert the table row accordingly + String comment = generateSummaryComment(decl); + String entry = ""; + if ( kind.equals( "Advice Summary" ) ) { + entry += + "" + + "" + + "" + generateAdviceSignatures(decl) + + "
 "; + if (!comment.equals("")) { + entry += comment + "

"; + } + entry += + generateAffects(decl, false) + "" + + "\n"; } - entry += - generateAffects(decl, false) + "" + - "\n"; - } - else if ( kind.equals( "Pointcut Summary" ) ) { - entry += - "" + - "" + genAccessibility(decl) + "" + - "\n" + - "" + - "" + - decl.toLabelString() + "
 "; - if (!comment.equals("")) { - entry += comment + "

"; + else if ( kind.equals( "Pointcut Summary" ) ) { + entry += + "" + + "" + genAccessibility(decl) + "" + + "\n" + + "" + + "" + + decl.toLabelString() + "
 "; + if (!comment.equals("")) { + entry += comment + "

"; + } + entry += + "\n"; } - entry += - "\n"; - } - else if ( kind.equals( "Introduction Summary" ) ) { - entry += - "" + - "" + decl.getModifiers() + "" + - "" + - "" + - "" + - "introduction " + decl.toLabelString() + "

" + - generateIntroductionSignatures(decl, false) + - generateAffects(decl, true); + else if ( kind.equals( "Introduction Summary" ) ) { + entry += + "" + + "" + decl.getModifiers() + "" + + "" + + "" + + "" + + "introduction " + decl.toLabelString() + "

" + + generateIntroductionSignatures(decl, false) + + generateAffects(decl, true); + } + + // insert the entry + fileBuffer.insert(insertIndex, entry); + insertIndex += entry.length(); } - - // insert the entry - fileBuffer.insert(insertIndex, entry); - insertIndex += entry.length(); } // insert the end of the table @@ -322,6 +322,24 @@ class HtmlDecorator { fileBuffer.insert(insertIndex, tableTail); insertIndex += tableTail.length(); } + + private static boolean declsAboveVisibilityExist(List decls) { + boolean exist = false; + for (Iterator it = decls.iterator(); it.hasNext();) { + IProgramElement element = (IProgramElement) it.next(); + if (isAboveVisibility(element)) exist = true; + } + return exist; + } + + private static boolean isAboveVisibility(IProgramElement element) { + return + (docVisibilityModifier.equals("private")) || // everything + (docVisibilityModifier.equals("package") && element.getAccessibility().equals(IProgramElement.Accessibility.PACKAGE)) || // package + (docVisibilityModifier.equals("protected") && (element.getAccessibility().equals(IProgramElement.Accessibility.PROTECTED) || + element.getAccessibility().equals(IProgramElement.Accessibility.PUBLIC))) || + (docVisibilityModifier.equals("public") && element.getAccessibility().equals(IProgramElement.Accessibility.PUBLIC)); + } private static String genAccessibility(IProgramElement decl) { if (decl.getAccessibility().equals(IProgramElement.Accessibility.PACKAGE)) { @@ -335,6 +353,7 @@ class HtmlDecorator { List decls, String kind, int index) { + if (!declsAboveVisibilityExist(decls)) return; int insertIndex = findDetailsIndex(fileBuffer, index); // insert the table heading @@ -353,42 +372,44 @@ class HtmlDecorator { // insert the details for ( int i = 0; i < decls.size(); i++ ) { IProgramElement decl = (IProgramElement)decls.get(i); - String entry = ""; - - // insert the table row accordingly - entry += "\n"; - if ( kind.equals( "Advice Detail" ) ) { - entry += "

" + decl.getName() + "

"; - entry += - "" + - generateAdviceSignatures(decl) + "\n" + "

" + - generateDetailsComment(decl) + "

" + - generateAffects(decl, false); - } - else if (kind.equals("Pointcut Detail")) { - entry += - "

" + - decl.toLabelString() + - "

" + - generateDetailsComment(decl); - } - else if (kind.equals("Introduction Detail")) { - entry += "

introduction " + decl.toLabelString() + "

"; - entry += - generateIntroductionSignatures(decl, true) + - generateAffects(decl, true) + - generateDetailsComment(decl); - } - - // insert the entry - if (i != decls.size()-1) { - entry += "


\n"; - } - else { - entry += "

"; + if (isAboveVisibility(decl)) { + String entry = ""; + + // insert the table row accordingly + entry += "\n"; + if ( kind.equals( "Advice Detail" ) ) { + entry += "

" + decl.getName() + "

"; + entry += + "" + + generateAdviceSignatures(decl) + "\n" + "

" + + generateDetailsComment(decl) + "

" + + generateAffects(decl, false); + } + else if (kind.equals("Pointcut Detail")) { + entry += + "

" + + decl.toLabelString() + + "

" + + generateDetailsComment(decl); + } + else if (kind.equals("Introduction Detail")) { + entry += "

introduction " + decl.toLabelString() + "

"; + entry += + generateIntroductionSignatures(decl, true) + + generateAffects(decl, true) + + generateDetailsComment(decl); + } + + // insert the entry + if (i != decls.size()-1) { + entry += "


\n"; + } + else { + entry += "

"; + } + fileBuffer.insert(insertIndex, entry); + insertIndex += entry.length(); } - fileBuffer.insert(insertIndex, entry); - insertIndex += entry.length(); } } diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/StubFileGenerator.java b/ajdoc/src/org/aspectj/tools/ajdoc/StubFileGenerator.java index ef5fdbf8d..dc4e6485d 100644 --- a/ajdoc/src/org/aspectj/tools/ajdoc/StubFileGenerator.java +++ b/ajdoc/src/org/aspectj/tools/ajdoc/StubFileGenerator.java @@ -112,7 +112,7 @@ class StubFileGenerator { if (!member.getKind().equals(IProgramElement.Kind.POINTCUT) && !member.getKind().equals(IProgramElement.Kind.ADVICE)) { signature = member.getSourceSignature();//StructureUtil.genSignature(member); - } + } if (member.getKind().isDeclare()) { System.err.println("> Skipping declare (ajdoc limitation): " + member.toLabelString()); diff --git a/ajdoc/testdata/bug82340/.cvsignore b/ajdoc/testdata/bug82340/.cvsignore new file mode 100644 index 000000000..8e695ec83 --- /dev/null +++ b/ajdoc/testdata/bug82340/.cvsignore @@ -0,0 +1 @@ +doc diff --git a/ajdoc/testdata/bug82340/Pointcuts.java b/ajdoc/testdata/bug82340/Pointcuts.java new file mode 100644 index 000000000..d36116de8 --- /dev/null +++ b/ajdoc/testdata/bug82340/Pointcuts.java @@ -0,0 +1,27 @@ +/* + * Created on Jan 12, 2005 + */ + +package foo; + +/** + * @author Mik Kersten + */ +public abstract aspect Pointcuts { + + private pointcut privatePointcut (); + protected pointcut protectedPointcut (); + public pointcut publicPointcut (); + + private void privateMethod () { + + } + + public void protectedMethod () { + + } + + public void publicMethod () { + + } +} diff --git a/ajdoc/testdata/coverage/foo/NoMembers.java b/ajdoc/testdata/coverage/foo/NoMembers.java index d8dfcb3ce..f5067de99 100644 --- a/ajdoc/testdata/coverage/foo/NoMembers.java +++ b/ajdoc/testdata/coverage/foo/NoMembers.java @@ -2,6 +2,8 @@ * Created on Jan 12, 2005 */ +package foo; + /** * @author Mik Kersten */ diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java index 34f22a03d..c03a4ecd7 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java @@ -22,20 +22,20 @@ import junit.framework.TestCase; */ public class CoverageTestCase extends TestCase { - File file0 = new File("testdata/coverage/InDefaultPackage.java"); - File file1 = new File("testdata/coverage/foo/ClassA.java"); - File aspect1 = new File("testdata/coverage/foo/UseThisAspectForLinkCheck.aj"); - File file2 = new File("testdata/coverage/foo/InterfaceI.java"); - File file3 = new File("testdata/coverage/foo/PlainJava.java"); - File file4 = new File("testdata/coverage/foo/ModelCoverage.java"); - File file5 = new File("testdata/coverage/fluffy/Fluffy.java"); - File file6 = new File("testdata/coverage/fluffy/bunny/Bunny.java"); - File file7 = new File("testdata/coverage/fluffy/bunny/rocks/Rocks.java"); - File file8 = new File("testdata/coverage/fluffy/bunny/rocks/UseThisAspectForLinkCheckToo.java"); - File file9 = new File("testdata/coverage/foo/PkgVisibleClass.java"); - File file10 = new File("testdata/coverage/foo/NoMembers.java"); + protected File file0 = new File("testdata/coverage/InDefaultPackage.java"); + protected File file1 = new File("testdata/coverage/foo/ClassA.java"); + protected File aspect1 = new File("testdata/coverage/foo/UseThisAspectForLinkCheck.aj"); + protected File file2 = new File("testdata/coverage/foo/InterfaceI.java"); + protected File file3 = new File("testdata/coverage/foo/PlainJava.java"); + protected File file4 = new File("testdata/coverage/foo/ModelCoverage.java"); + protected File file5 = new File("testdata/coverage/fluffy/Fluffy.java"); + protected File file6 = new File("testdata/coverage/fluffy/bunny/Bunny.java"); + protected File file7 = new File("testdata/coverage/fluffy/bunny/rocks/Rocks.java"); + protected File file8 = new File("testdata/coverage/fluffy/bunny/rocks/UseThisAspectForLinkCheckToo.java"); + protected File file9 = new File("testdata/coverage/foo/PkgVisibleClass.java"); + protected File file10 = new File("testdata/coverage/foo/NoMembers.java"); - File outdir = new File("testdata/coverage/doc"); + protected File outdir = new File("testdata/coverage/doc"); public void testOptions() { outdir.delete(); diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/PointcutVisibilityTest.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/PointcutVisibilityTest.java new file mode 100644 index 000000000..760e4c22c --- /dev/null +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/PointcutVisibilityTest.java @@ -0,0 +1,29 @@ +/* + * Created on Jan 12, 2005 + */ +package org.aspectj.tools.ajdoc; + +import java.io.File; + +import junit.framework.TestCase; + +/** + * @author Mik Kersten + */ +public class PointcutVisibilityTest extends TestCase { + + protected File file1 = new File("testdata/bug82340/Pointcuts.java"); + protected File outdir = new File("testdata/bug82340/doc"); + + public void testCoveragePublicMode() { + outdir.delete(); + String[] args = { + "-XajdocDebug", + "-protected", + "-d", + outdir.getAbsolutePath(), + file1.getAbsolutePath() + }; + org.aspectj.tools.ajdoc.Main.main(args); + } +} -- 2.39.5