]> source.dussan.org Git - aspectj.git/commitdiff
Fixed Bug #56779: [ajdoc] add ajdoc support for inter-type declarations and other...
authormkersten <mkersten>
Wed, 5 Oct 2005 16:15:43 +0000 (16:15 +0000)
committermkersten <mkersten>
Wed, 5 Oct 2005 16:15:43 +0000 (16:15 +0000)
Also fixed ajdoc tests to run correctly when executed via RunTheseBeforeYouCommit tests (previously they were not being run and silently failing).

13 files changed:
ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java
ajdoc/src/org/aspectj/tools/ajdoc/StructureUtil.java
ajdoc/src/org/aspectj/tools/ajdoc/StubFileGenerator.java
ajdoc/testdata/declareForms/.cvsignore [new file with mode: 0644]
ajdoc/testdata/declareForms/DeclareCoverage.java [new file with mode: 0644]
ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTests.java
ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java
ajdoc/testsrc/org/aspectj/tools/ajdoc/DeclareFormsTest.java [new file with mode: 0644]
ajdoc/testsrc/org/aspectj/tools/ajdoc/ExecutionTestCase.java
ajdoc/testsrc/org/aspectj/tools/ajdoc/PatternsTestCase.java
ajdoc/testsrc/org/aspectj/tools/ajdoc/PointcutVisibilityTest.java
ajdoc/testsrc/org/aspectj/tools/ajdoc/SpacewarTestCase.java
asm/src/org/aspectj/asm/IRelationship.java

index a2cb7919b70880f5982b0bc15d8b333f0d363dda..3c064f573bb80eed76253665086472685c69c227 100644 (file)
 
 package org.aspectj.tools.ajdoc;
 
-import java.io.*;
-import java.util.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
 
 import org.aspectj.asm.AsmManager;
 import org.aspectj.asm.IProgramElement;
@@ -26,7 +35,13 @@ import org.aspectj.asm.IRelationship;
  */
 class HtmlDecorator {
 
-    static List visibleFileList = new ArrayList();
+    private static final String POINTCUT_DETAIL = "Pointcut Detail";
+       private static final String ADVICE_DETAIL = "Advice Detail";
+       private static final String DECLARE_DETAIL = "Declare Detail";
+       private static final String ADVICE_SUMMARY = "Advice Summary";
+       private static final String POINTCUT_SUMMARY = "Pointcut Summary";
+       private static final String DECLARE_SUMMARY = "Declare Summary";
+       static List visibleFileList = new ArrayList();
     static Hashtable declIDTable = null;
     static SymbolManager symbolManager = null;
     static File rootDir = null;
@@ -193,8 +208,8 @@ class HtmlDecorator {
         // 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");
+        int pointcutSummaryIndex = fileContents.toString().indexOf(POINTCUT_SUMMARY);
+        int adviceSummaryIndex = fileContents.toString().indexOf(ADVICE_SUMMARY);
         if (classStartIndex != -1 &&
                (adviceSummaryIndex != -1 || pointcutSummaryIndex != -1)) {
             int classEndIndex = fileContents.toString().indexOf("</H2>", classStartIndex);
@@ -214,21 +229,28 @@ class HtmlDecorator {
     static void addAspectDocumentation(IProgramElement node, StringBuffer fileBuffer, int index ) {
        List pointcuts = new ArrayList();
        List advice = new ArrayList();
+       List declares = new ArrayList();
        for (Iterator it = node.getChildren().iterator(); it.hasNext(); ) {
                IProgramElement member = (IProgramElement)it.next();
                if (member.getKind().equals(IProgramElement.Kind.POINTCUT)) {
                        pointcuts.add(member);
                } else if (member.getKind().equals(IProgramElement.Kind.ADVICE)) {
                        advice.add(member);
+               } else if (member.getKind().isDeclare() || member.getKind().isInterTypeMember()) {
+                       declares.add(member);
                }
        }
+       if (declares.size() > 0) {
+               insertDeclarationsDetails(fileBuffer, declares, DECLARE_DETAIL, index);
+               insertDeclarationsSummary(fileBuffer, declares, DECLARE_SUMMARY, index);
+       }
        if (pointcuts.size() > 0) {
-               insertDeclarationsSummary(fileBuffer, pointcuts, "Pointcut Summary", index);
-               insertDeclarationsDetails(fileBuffer, pointcuts, "Pointcut Detail", index);
+               insertDeclarationsSummary(fileBuffer, pointcuts, POINTCUT_SUMMARY, index);
+               insertDeclarationsDetails(fileBuffer, pointcuts, POINTCUT_DETAIL, index);
        }
        if (advice.size() > 0) {
-               insertDeclarationsSummary(fileBuffer, advice, "Advice Summary", index);
-               insertDeclarationsDetails(fileBuffer, advice, "Advice Detail", index);
+               insertDeclarationsSummary(fileBuffer, advice, ADVICE_SUMMARY, index);
+               insertDeclarationsDetails(fileBuffer, advice, ADVICE_DETAIL, index);
        }
     }
     
@@ -272,7 +294,7 @@ class HtmlDecorator {
                 // insert the table row accordingly
                 String comment = generateSummaryComment(decl);
                 String entry = "";
-                if ( kind.equals( "Advice Summary" ) ) {
+                if ( kind.equals( ADVICE_SUMMARY ) ) {
                     entry +=
                             "<TR><TD>" +
                             "<A HREF=\"#" + generateHREFName(decl) + "\">" +
@@ -285,7 +307,7 @@ class HtmlDecorator {
                             generateAffects(decl, false) + "</TD>" +
                             "</TR><TD>\n";
                 }
-                else if ( kind.equals( "Pointcut Summary" ) ) {
+                else if ( kind.equals( POINTCUT_SUMMARY ) ) {
                     entry +=
                             "<TR><TD WIDTH=\"1%\">" +
                             "<FONT SIZE=-1><TT>" + genAccessibility(decl) + "</TT></FONT>" +
@@ -299,15 +321,15 @@ class HtmlDecorator {
                     entry +=
                             "</TR></TD>\n";
                 }
-                else if ( kind.equals( "Introduction Summary" ) ) {
+                else if ( kind.equals( DECLARE_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) +
+                            "<TT>" + decl.toLabelString() + "</TT></A><P>" +
+                            generateIntroductionSignatures(decl, true) +
                             generateAffects(decl, true);
                 }
     
@@ -377,7 +399,7 @@ class HtmlDecorator {
     
                 // insert the table row accordingly
                 entry +=  "<A NAME=\"" + generateHREFName(decl) + "\"><!-- --></A>\n";
-                if ( kind.equals( "Advice Detail" ) ) {
+                if ( kind.equals( ADVICE_DETAIL ) ) {
                     entry += "<H3>" + decl.getName() + "</H3><P>";
                     entry +=
                             "<TT>" +
@@ -385,15 +407,15 @@ class HtmlDecorator {
                             generateDetailsComment(decl) + "<P>" +
                             generateAffects(decl, false);
                 }
-                else if (kind.equals("Pointcut Detail")) {
+                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>";
+                else if (kind.equals(DECLARE_DETAIL)) {
+                       entry += "<H3>declare " + decl.toLabelString() + "</H3><P>";
                     entry +=
                             generateIntroductionSignatures(decl, true) +
                             generateAffects(decl, true) +
@@ -454,9 +476,7 @@ class HtmlDecorator {
                                              StringBuffer fileContentsBuffer,
                                               int index ) {
        List targets = StructureUtil.getTargets(node, IRelationship.Kind.ADVICE);
-        if (targets != null && !targets.isEmpty()) {
-            String prevName = "";
-            
+        if (targets != null && !targets.isEmpty()) {            
             String adviceDoc
             = "<TABLE WIDTH=\"100%\" BGCOLOR=#FFFFFF><TR>" +
               "<TD width=\"15%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>&nbsp;Advised&nbsp;by:</font></b></td><td>";
@@ -511,14 +531,20 @@ class HtmlDecorator {
      * TODO: probably want to make this the same for intros and advice.
      */
     static String generateAffects(IProgramElement decl, boolean isIntroduction) {
-
-      List targets = StructureUtil.getTargets(decl, IRelationship.Kind.ADVICE);
-      if (targets == null) return null;
-        List packageList = new ArrayList();
-        String entry
-        = "<TABLE WIDTH=\"100%\" BGCOLOR=#FFFFFF><TR>" +
-          "<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>&nbsp;Advises:</b></font></td><td>";
-    
+       List targets = null;
+       if (isIntroduction) {
+               targets = StructureUtil.getDeclareTargets(decl);
+       } else {
+               targets = StructureUtil.getTargets(decl, IRelationship.Kind.ADVICE);
+       }
+       if (targets == null) return "";
+        String entry = "<TABLE WIDTH=\"100%\" BGCOLOR=#FFFFFF><TR>";
+        if (!isIntroduction) {
+               entry += "<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>&nbsp;Advises:</b></font></td><td>";
+        } else {
+               entry += "<TD width=\"10%\" bgcolor=\"#FFD8B0\"><B><FONT COLOR=000000>&nbsp;Affects:</b></font></td><td>";
+        }
+               
                String relativePackagePath =
                        getRelativePathFromHere(
                                decl.getPackageName().replace('.', '/') + Config.DIR_SEP_CHAR);    
@@ -634,7 +660,7 @@ class HtmlDecorator {
     }
 
     static String generateHREFName(IProgramElement decl) {
-        String hrefLink = decl.toLabelString(); // !!!
+        String hrefLink = decl.toLabelString().replace("\"", "quot;"); // !!!
         return hrefLink;
     }
 
index 25f2d4223e76ca5e821bf0284c1b1aef3e2816d5..4dfed08a32a33da82957560ee4b8f07e6d9614b1 100644 (file)
@@ -30,7 +30,7 @@ public class StructureUtil {
         */
        public static List/*IProgramElement*/ getTargets(IProgramElement node, IRelationship.Kind kind) {
            List relations = AsmManager.getDefault().getRelationshipMap().get(node);
-               List targets = null;
+               List targets = null; 
            if (relations == null) return null;
                for (Iterator it = relations.iterator(); it.hasNext(); ) {
                IRelationship rtn = (IRelationship)it.next();
@@ -40,6 +40,19 @@ public class StructureUtil {
             }
                return targets;
        }
+
+       public static List/*IProgramElement*/ getDeclareTargets(IProgramElement node) {
+           List relations = AsmManager.getDefault().getRelationshipMap().get(node);
+               List targets = null; 
+           if (relations == null) return null;
+               for (Iterator it = relations.iterator(); it.hasNext(); ) {
+               IRelationship rtn = (IRelationship)it.next();
+               if (rtn.getKind().isDeclareKind()) {
+                       targets = rtn.getTargets();
+               }
+            }
+               return targets;
+       }
        
        public static String getPackageDeclarationFromFile(File file) {
        IProgramElement fileNode = (IProgramElement)AsmManager.getDefault().getHierarchy().findElementForSourceFile(file.getAbsolutePath());
index 9843a2b94494ea74bb94df8be4e095e1f4bfd6ff..c22906558edbbf61eb926634749242d202753ebc 100644 (file)
@@ -131,7 +131,7 @@ class StubFileGenerator{
                 } 
                        
                        if (member.getKind().isDeclare()) {
-                               System.err.println("> Skipping declare (ajdoc limitation): " + member.toLabelString());
+//                             System.err.println("> Skipping declare (ajdoc limitation): " + member.toLabelString());
                        } else if (signature != null &&
                                signature != "" && 
                                !member.getKind().isInterTypeMember() &&
diff --git a/ajdoc/testdata/declareForms/.cvsignore b/ajdoc/testdata/declareForms/.cvsignore
new file mode 100644 (file)
index 0000000..8e695ec
--- /dev/null
@@ -0,0 +1 @@
+doc
diff --git a/ajdoc/testdata/declareForms/DeclareCoverage.java b/ajdoc/testdata/declareForms/DeclareCoverage.java
new file mode 100644 (file)
index 0000000..ff89cb0
--- /dev/null
@@ -0,0 +1,39 @@
+
+package foo;
+
+import java.io.*;
+import java.util.List;
+public aspect DeclareCoverage {
+
+       void foo() { }
+       
+    pointcut illegalNewFigElt(): call(Point.new(..)) && !withincode(* *.doIt(..));
+
+    declare error: illegalNewFigElt(): "Illegal constructor call.";
+    declare warning: call(* Point.setX(..)): "Illegal call.";
+
+    declare parents: Point extends java.io.Serializable;
+       declare parents: Point && Line implements java.util.Observable;
+    declare soft: SizeException : call(* Point.getX());
+       declare precedence: DeclareCoverage, InterTypeDecCoverage, *;
+}
+
+aspect InterTypeDecCoverage {
+       
+       void foo() { } 
+       
+    public int Point.xxx = 0;
+    public int Point.check(int i, int j) { return 1; }
+}
+
+class Point { 
+
+}
+
+class Line { 
+       
+}
+
+class SizeException extends Throwable { } 
+
index 1c4a1847b40a66ac73032ed91f4d8277fb4f3b22..5ec25317d8fe328867f78112910b956a592499bf 100644 (file)
@@ -22,7 +22,9 @@ import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
 public class AjdocTests extends TestCase {
-    public static File ASPECTJRT_PATH;
+    
+       public static File ASPECTJRT_PATH;
+    
     static {
         String[] paths = { "sp:aspectjrt.path", "sp:aspectjrt.jar",
                 "../lib/test/aspectjrt.jar", "../aj-build/jars/aspectj5rt-all.jar",
@@ -34,6 +36,7 @@ public class AjdocTests extends TestCase {
     public static Test suite() {
         TestSuite suite = new TestSuite(AjdocTests.class.getName());
         //$JUnit-BEGIN$
+        suite.addTestSuite(DeclareFormsTest.class);
         suite.addTestSuite(SpacewarTestCase.class);
         suite.addTestSuite(PatternsTestCase.class);
         suite.addTestSuite(CoverageTestCase.class); 
index d6a9cd1a083982972922382b8adf31efdf78da07..316f032802990dd7b7cf0774e05a7b26e8e694cf 100644 (file)
@@ -22,18 +22,18 @@ import junit.framework.TestCase;
  */
 public class CoverageTestCase extends TestCase {
 
-       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");
+       protected File file0 = new File("../ajdoc/testdata/coverage/InDefaultPackage.java");
+       protected File file1 = new File("../ajdoc/testdata/coverage/foo/ClassA.java");
+       protected File aspect1 = new File("../ajdoc/testdata/coverage/foo/UseThisAspectForLinkCheck.aj");
+       protected File file2 = new File("../ajdoc/testdata/coverage/foo/InterfaceI.java");
+       protected File file3 = new File("../ajdoc/testdata/coverage/foo/PlainJava.java");
+       protected File file4 = new File("../ajdoc/testdata/coverage/foo/ModelCoverage.java");
+       protected File file5 = new File("../ajdoc/testdata/coverage/fluffy/Fluffy.java");
+       protected File file6 = new File("../ajdoc/testdata/coverage/fluffy/bunny/Bunny.java");
+       protected File file7 = new File("../ajdoc/testdata/coverage/fluffy/bunny/rocks/Rocks.java");
+       protected File file8 = new File("../ajdoc/testdata/coverage/fluffy/bunny/rocks/UseThisAspectForLinkCheckToo.java");
+       protected File file9 = new File("../ajdoc/testdata/coverage/foo/PkgVisibleClass.java");
+       protected File file10 = new File("../ajdoc/testdata/coverage/foo/NoMembers.java");
     
        protected File outdir = new File("testdata/coverage/doc");
        
diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/DeclareFormsTest.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/DeclareFormsTest.java
new file mode 100644 (file)
index 0000000..f8c09e3
--- /dev/null
@@ -0,0 +1,51 @@
+/* *******************************************************************
+ * Copyright (c) 2003 Contributors.
+ * All rights reserved. 
+ * This program and the accompanying materials are made available 
+ * under the terms of the Common Public License v1.0 
+ * which accompanies this distribution and is available at 
+ * http://www.eclipse.org/legal/cpl-v10.html 
+ *  
+ * Contributors: 
+ *     Mik Kersten     initial implementation 
+ * ******************************************************************/
+
+package org.aspectj.tools.ajdoc;
+
+import java.io.File;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Mik Kersten
+ */
+public class DeclareFormsTest extends TestCase {
+
+       protected File file0 = new File("../ajdoc/testdata/declareForms/DeclareCoverage.java");
+       protected File outdir = new File("../ajdoc/testdata/declareForms/doc");
+       
+       public void testCoverage() {
+               assertTrue(file0.exists());
+               outdir.delete();
+               String[] args = { 
+//                     "-XajdocDebug",
+                       "-source", 
+                       "1.4",
+                       "-private",
+            "-classpath",
+            AjdocTests.ASPECTJRT_PATH.getPath(),
+                       "-d", 
+                       outdir.getAbsolutePath(),
+                       file0.getAbsolutePath(), 
+               };
+               org.aspectj.tools.ajdoc.Main.main(args);
+       }
+
+       protected void setUp() throws Exception {
+               super.setUp();
+       }
+       
+       protected void tearDown() throws Exception {
+               super.tearDown();
+       }
+}
index f14c757e65e52a30d7fe08656533fb9b2be601cb..c7ca99cf12eab23d5032ecb10e901f497e2b49f4 100644 (file)
@@ -30,7 +30,7 @@ public class ExecutionTestCase extends TestCase {
        }
        
        public void testFailingBuild() {
-               File file1 = new File("testdata/failing-build/Fail.java");
+               File file1 = new File("../ajdoc/testdata/failing-build/Fail.java");
                String[] args = { file1.getAbsolutePath() };
                
                org.aspectj.tools.ajdoc.Main.main(args);
index f8551a2db8a1446f3faeb13bb25efb85f2f557bf..d0dd93a16486b9c8b4275e25ac90398941a286d2 100644 (file)
@@ -28,7 +28,7 @@ public class PatternsTestCase extends TestCase {
 //             System.err.println(new File("testdata.figures-demo").exists());
 //             File file1 = new File("testdata/patterns/allPatterns.lst");
                File outdir = new File("testdata/patterns/doc");
-               File srcdir = new File("../docs/sandbox/ubc-design-patterns/src");
+               File srcdir = new File("../../docs/sandbox/ubc-design-patterns/src");
                
                String[] args = { 
 //                     "-XajdocDebug", 
index 760e4c22c5a613b460218eaa85be6a74eb91c797..7a5d34a33d255c6501bbfe0e4199f5f5fc438e75 100644 (file)
@@ -12,8 +12,8 @@ import junit.framework.TestCase;
  */
 public class PointcutVisibilityTest extends TestCase {
 
-    protected File file1 = new File("testdata/bug82340/Pointcuts.java");
-    protected File outdir = new File("testdata/bug82340/doc");
+    protected File file1 = new File("../ajdoc/testdata/bug82340/Pointcuts.java");
+    protected File outdir = new File("../ajdoc/testdata/bug82340/doc");
     
     public void testCoveragePublicMode() {
         outdir.delete();
index 1b3f5c5095c27d96755f5cd2d357b517aca4aba2..0825ade268744c8924d4b04dd024f35905dbaa81 100644 (file)
@@ -22,7 +22,7 @@ public class SpacewarTestCase extends TestCase {
        
        protected void setUp() throws Exception {
                super.setUp();
-               new File("testdata/spacewar/docdir").delete();
+               new File("../ajdoc/testdata/spacewar/docdir").delete();
        }
     
        public void testSimpleExample() {
@@ -44,8 +44,8 @@ public class SpacewarTestCase extends TestCase {
        }
        
        public void testPublicModeExample() {
-               File outdir = new File("testdata/spacewar/docdir");
-               File sourcepath = new File("testdata/spacewar");
+               File outdir = new File("../ajdoc/testdata/spacewar/docdir");
+               File sourcepath = new File("../ajdoc/testdata/spacewar");
                
                String[] args = { 
                        "-public",
index 500ba5b4fe338d8c5b9338bc48c32276773f9819..d54f13f7befb438e008343ec0dbaf45bb4c5dd60 100644 (file)
@@ -58,6 +58,14 @@ public interface IRelationship extends Serializable {
                        
                private final String name;
                
+               public boolean isDeclareKind() {
+                       return this == DECLARE_WARNING
+                               || this == DECLARE_ERROR
+                               || this == DECLARE
+                               || this == DECLARE_INTER_TYPE
+                               || this == DECLARE_SOFT;
+               }
+               
                private Kind(String name) {
                        this.name = name; 
                }