]> source.dussan.org Git - aspectj.git/commitdiff
Fixed 3 bugs reported in bug#82340, including correct use of visibility modifiers.
authormkersten <mkersten>
Thu, 13 Jan 2005 15:53:01 +0000 (15:53 +0000)
committermkersten <mkersten>
Thu, 13 Jan 2005 15:53:01 +0000 (15:53 +0000)
ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java
ajdoc/src/org/aspectj/tools/ajdoc/StubFileGenerator.java
ajdoc/testdata/bug82340/.cvsignore [new file with mode: 0644]
ajdoc/testdata/bug82340/Pointcuts.java [new file with mode: 0644]
ajdoc/testdata/coverage/foo/NoMembers.java
ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java
ajdoc/testsrc/org/aspectj/tools/ajdoc/PointcutVisibilityTest.java [new file with mode: 0644]

index 43d7b1851fd9dcbea1b74cab35f5c0d3fe1e7746..a2cb7919b70880f5982b0bc15d8b333f0d363dda 100644 (file)
@@ -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("<BR>\nClass");
+        // Change "Class" to "Aspect"
+        // HACK: depends on matching presence of advice or pointcut summary
+        int classStartIndex = fileContents.toString().indexOf("<BR>\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("</H2>", 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 +=
-                        "<TR><TD>" +
-                        "<A HREF=\"#" + generateHREFName(decl) + "\">" +
-                        "<TT>" + generateAdviceSignatures(decl) +
-                                               "</TT></A><BR>&nbsp;";
-                if (!comment.equals("")) {
-                    entry += comment + "<P>";
+            if (isAboveVisibility(decl)) {                
+                // insert the table row accordingly
+                String comment = generateSummaryComment(decl);
+                String entry = "";
+                if ( kind.equals( "Advice Summary" ) ) {
+                    entry +=
+                            "<TR><TD>" +
+                            "<A HREF=\"#" + generateHREFName(decl) + "\">" +
+                            "<TT>" + generateAdviceSignatures(decl) +
+                                               "</TT></A><BR>&nbsp;";
+                    if (!comment.equals("")) {
+                        entry += comment + "<P>";
+                    }
+                    entry +=
+                            generateAffects(decl, false) + "</TD>" +
+                            "</TR><TD>\n";
                 }
-                entry +=
-                        generateAffects(decl, false) + "</TD>" +
-                        "</TR><TD>\n";
-            }
-            else if ( kind.equals( "Pointcut Summary" ) ) {
-                entry +=
-                        "<TR><TD WIDTH=\"1%\">" +
-                        "<FONT SIZE=-1><TT>" + genAccessibility(decl) + "</TT></FONT>" +
-                        "</TD>\n" +
-                        "<TD>" +
-                        "<TT><A HREF=\"#" + generateHREFName(decl) + "\">" +
-                        decl.toLabelString() + "</A></TT><BR>&nbsp;";
-                if (!comment.equals("")) {
-                    entry += comment + "<P>";
+                else if ( kind.equals( "Pointcut Summary" ) ) {
+                    entry +=
+                            "<TR><TD WIDTH=\"1%\">" +
+                            "<FONT SIZE=-1><TT>" + genAccessibility(decl) + "</TT></FONT>" +
+                            "</TD>\n" +
+                            "<TD>" +
+                            "<TT><A HREF=\"#" + generateHREFName(decl) + "\">" +
+                            decl.toLabelString() + "</A></TT><BR>&nbsp;";
+                    if (!comment.equals("")) {
+                        entry += comment + "<P>";
+                    }
+                    entry +=
+                            "</TR></TD>\n";
                 }
-                entry +=
-                        "</TR></TD>\n";
-            }
-            else if ( kind.equals( "Introduction Summary" ) ) {
-                entry +=
-                        "<TR><TD WIDTH=\"1%\">" +
-                        "<FONT SIZE=-1><TT>" + decl.getModifiers() + "</TT></FONT>" +
-                        "</TD>" +
-                        "<TD>" +
-                        "<A HREF=\"#" + generateHREFName(decl) + "\">" +
-                        "<TT>introduction " + decl.toLabelString() + "</TT></A><P>" +
-                        generateIntroductionSignatures(decl, false) +
-                        generateAffects(decl, true);
+                else if ( kind.equals( "Introduction Summary" ) ) {
+                    entry +=
+                            "<TR><TD WIDTH=\"1%\">" +
+                            "<FONT SIZE=-1><TT>" + decl.getModifiers() + "</TT></FONT>" +
+                            "</TD>" +
+                            "<TD>" +
+                            "<A HREF=\"#" + generateHREFName(decl) + "\">" +
+                            "<TT>introduction " + decl.toLabelString() + "</TT></A><P>" +
+                            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 +=  "<A NAME=\"" + generateHREFName(decl) + "\"><!-- --></A>\n";
-            if ( kind.equals( "Advice Detail" ) ) {
-                entry += "<H3>" + decl.getName() + "</H3><P>";
-                entry +=
-                        "<TT>" +
-                        generateAdviceSignatures(decl) + "</TT>\n" + "<P>" +
-                        generateDetailsComment(decl) + "<P>" +
-                        generateAffects(decl, false);
-            }
-            else if (kind.equals("Pointcut Detail")) {
-                entry +=
-                        "<H3>" +
-                        decl.toLabelString() +
-                        "</H3><P>" +
-                        generateDetailsComment(decl);
-            }
-            else if (kind.equals("Introduction Detail")) {
-               entry += "<H3>introduction " + decl.toLabelString() + "</H3><P>";
-                entry +=
-                        generateIntroductionSignatures(decl, true) +
-                        generateAffects(decl, true) +
-                        generateDetailsComment(decl);
-            }
-
-            // insert the entry
-            if (i != decls.size()-1) {
-                entry += "<P><HR>\n";
-            }
-            else {
-                entry += "<P>";
+            if (isAboveVisibility(decl)) {
+                String entry = "";
+    
+                // insert the table row accordingly
+                entry +=  "<A NAME=\"" + generateHREFName(decl) + "\"><!-- --></A>\n";
+                if ( kind.equals( "Advice Detail" ) ) {
+                    entry += "<H3>" + decl.getName() + "</H3><P>";
+                    entry +=
+                            "<TT>" +
+                            generateAdviceSignatures(decl) + "</TT>\n" + "<P>" +
+                            generateDetailsComment(decl) + "<P>" +
+                            generateAffects(decl, false);
+                }
+                else if (kind.equals("Pointcut Detail")) {
+                    entry +=
+                            "<H3>" +
+                            decl.toLabelString() +
+                            "</H3><P>" +
+                            generateDetailsComment(decl);
+                }
+                else if (kind.equals("Introduction Detail")) {
+                       entry += "<H3>introduction " + decl.toLabelString() + "</H3><P>";
+                    entry +=
+                            generateIntroductionSignatures(decl, true) +
+                            generateAffects(decl, true) +
+                            generateDetailsComment(decl);
+                }
+    
+                // insert the entry
+                if (i != decls.size()-1) {
+                    entry += "<P><HR>\n";
+                }
+                else {
+                    entry += "<P>";
+                }
+                fileBuffer.insert(insertIndex, entry);
+                insertIndex += entry.length();
             }
-            fileBuffer.insert(insertIndex, entry);
-            insertIndex += entry.length();
         }
     }
 
index ef5fdbf8d8d1c87a33d9ba0c32380110c1687112..dc4e6485d021287a6f152bcbb13b60714fa8ea9c 100644 (file)
@@ -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 (file)
index 0000000..8e695ec
--- /dev/null
@@ -0,0 +1 @@
+doc
diff --git a/ajdoc/testdata/bug82340/Pointcuts.java b/ajdoc/testdata/bug82340/Pointcuts.java
new file mode 100644 (file)
index 0000000..d36116d
--- /dev/null
@@ -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 () {
+        
+    }
+}
index d8dfcb3ce9f3e3ae028d8094284be1d1c9af87bf..f5067de998a5c6883561e59dfd5462100f64e2e0 100644 (file)
@@ -2,6 +2,8 @@
  * Created on Jan 12, 2005
  */
 
+package foo;
+
 /**
  * @author Mik Kersten
  */
index 34f22a03d5d7e60034c734ffb132f86b9b75a4c3..c03a4ecd7fc3328d03c46ff66fa4e0136a4d8f24 100644 (file)
@@ -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 (file)
index 0000000..760e4c2
--- /dev/null
@@ -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);
+    }
+}