]> source.dussan.org Git - aspectj.git/commitdiff
- Added support for 1.4 sources (use "-source 1.4" option)
authormkersten <mkersten>
Wed, 7 Apr 2004 15:32:00 +0000 (15:32 +0000)
committermkersten <mkersten>
Wed, 7 Apr 2004 15:32:00 +0000 (15:32 +0000)
- Made output class files go to documentation directory (-d) rather than source directory.

- Added "-XajdocDebug" option that will keep the source files generated from the ASM around in order to help people send better bug reports.

- Any declare forms that ajdoc doesn't know how to generate docs for get printed to the console and indicated as a limitation.

I also extended test coverage to declare forms and added proper clearing of state for multiple invocations from test cases.

ajdoc/src/org/aspectj/tools/ajdoc/Main.java
ajdoc/src/org/aspectj/tools/ajdoc/StubFileGenerator.java
ajdoc/testdata/simple/foo/ModelCoverage.java [new file with mode: 0644]
ajdoc/testdata/simple/foo/PlainJava.java
ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java

index 8c550ea6ca8d03705829c8a715c4d6b23c661663..a6574ce047abfdd8676529898e6f90a57f50a541 100644 (file)
@@ -33,10 +33,10 @@ public class Main implements Config {
     static SymbolManager symbolManager = null;
 
     /** Command line options. */
-    static Vector options = new Vector();
+    static Vector options;
 
     /** Options to pass to ajc. */
-    static Vector ajcOptions = new Vector();
+    static Vector ajcOptions;
 
     /** All of the files to be processed by ajdoc. */
     static Vector filenames;
@@ -82,10 +82,13 @@ public class Main implements Config {
 
     public static void main(String[] args) {
        aborted = false;
+       deleteTempFilesOnExit = true;
    
         filenames = new Vector();
         fileList= new Vector();
         packageList = new Vector();
+        options = new Vector();
+        ajcOptions = new Vector();
 //     if (!JavadocRunner.has14ToolsAvailable()) {
 //             System.err.println("ajdoc requires a JDK 1.4 or later tools jar - exiting");
 //             aborted = true;
@@ -113,9 +116,11 @@ public class Main implements Config {
             }
 
             // PHASE 0: call ajc
-            ajcOptions.addElement( "-noExit" );
-                       ajcOptions.addElement( "-XjavadocsInModel" );   // TODO: wrong option to force model gen
-            String[] argsToCompiler = new String[ajcOptions.size() + inputFiles.length];
+            ajcOptions.addElement("-noExit");
+                       ajcOptions.addElement("-XjavadocsInModel");     // TODO: wrong option to force model gen
+            ajcOptions.addElement("-d"); 
+            ajcOptions.addElement(rootDir.getAbsolutePath());
+                       String[] argsToCompiler = new String[ajcOptions.size() + inputFiles.length];
             int i = 0;
             for ( ; i < ajcOptions.size(); i++ ) {
                 argsToCompiler[i] = (String)ajcOptions.elementAt(i);
@@ -126,6 +131,7 @@ public class Main implements Config {
                 i++;
             }
 
+//            System.out.println(Arrays.asList(argsToCompiler));
             System.out.println( "> Calling ajc..." );
             CompilerWrapper.main(argsToCompiler);
             if (CompilerWrapper.hasErrors()) {
@@ -308,7 +314,6 @@ public class Main implements Config {
     static File createSignatureFile(File inputFile) throws IOException {
        String packageName = StructureUtil.getPackageDeclarationFromFile(inputFile);
        
-//     System.err.println(">>> package: " + packageName);
         String filename    = "";
         if ( packageName != null ) {
             String pathName =  Config.WORKING_DIR + '/' + packageName.replace('.', '/');
@@ -331,45 +336,45 @@ public class Main implements Config {
     }
 
 
-    static void verifyPackageDirExists( String packageName, String offset ) {
-        System.err.println(">>> name: " + packageName + ", offset: " + offset);
-        if ( packageName.indexOf( "." ) != -1 ) {
-            File tempFile = new File("c:/aspectj-test/d1/d2/d3");
-            tempFile.mkdirs();
-            String currPkgDir = packageName.substring( 0, packageName.indexOf( "." ) );
-            String remainingPkg = packageName.substring( packageName.indexOf( "." )+1 );
-            String filePath = null;
-            if ( offset != null ) {
-                filePath = Config.WORKING_DIR + Config.DIR_SEP_CHAR +
-                           offset + Config.DIR_SEP_CHAR + currPkgDir ;
-            }
-            else {
-                filePath = Config.WORKING_DIR + Config.DIR_SEP_CHAR + currPkgDir;
-            }
-            File packageDir = new File( filePath );
-            if ( !packageDir.exists() ) {
-                packageDir.mkdir();
-                if (deleteTempFilesOnExit) packageDir.deleteOnExit();
-            }
-            if ( remainingPkg != "" ) {
-                verifyPackageDirExists( remainingPkg, currPkgDir );
-            }
-        }
-        else {
-            String filePath = null;
-            if ( offset != null ) {
-                filePath = Config.WORKING_DIR + Config.DIR_SEP_CHAR + offset + Config.DIR_SEP_CHAR + packageName;
-            }
-            else {
-                filePath = Config.WORKING_DIR + Config.DIR_SEP_CHAR + packageName;
-            }
-            File packageDir = new File( filePath );
-            if ( !packageDir.exists() ) {
-                packageDir.mkdir();
-                if (deleteTempFilesOnExit) packageDir.deleteOnExit();
-            }
-        }
-    }
+//    static void verifyPackageDirExists( String packageName, String offset ) {
+//        System.err.println(">>> name: " + packageName + ", offset: " + offset);
+//        if ( packageName.indexOf( "." ) != -1 ) {
+//            File tempFile = new File("c:/aspectj-test/d1/d2/d3");
+//            tempFile.mkdirs();
+//            String currPkgDir = packageName.substring( 0, packageName.indexOf( "." ) );
+//            String remainingPkg = packageName.substring( packageName.indexOf( "." )+1 );
+//            String filePath = null;
+//            if ( offset != null ) {
+//                filePath = Config.WORKING_DIR + Config.DIR_SEP_CHAR +
+//                           offset + Config.DIR_SEP_CHAR + currPkgDir ;
+//            }
+//            else {
+//                filePath = Config.WORKING_DIR + Config.DIR_SEP_CHAR + currPkgDir;
+//            }
+//            File packageDir = new File( filePath );
+//            if ( !packageDir.exists() ) {
+//                packageDir.mkdir();
+//                if (deleteTempFilesOnExit) packageDir.deleteOnExit();
+//            }
+//            if ( remainingPkg != "" ) {
+//                verifyPackageDirExists( remainingPkg, currPkgDir );
+//            }
+//        }
+//        else {
+//            String filePath = null;
+//            if ( offset != null ) {
+//                filePath = Config.WORKING_DIR + Config.DIR_SEP_CHAR + offset + Config.DIR_SEP_CHAR + packageName;
+//            }
+//            else {
+//                filePath = Config.WORKING_DIR + Config.DIR_SEP_CHAR + packageName;
+//            }
+//            File packageDir = new File( filePath );
+//            if ( !packageDir.exists() ) {
+//                packageDir.mkdir();
+//                if (deleteTempFilesOnExit) packageDir.deleteOnExit();
+//            }
+//        }
+//    }
 
     /**
      * Can read Eclipse-generated single-line arg
@@ -485,6 +490,13 @@ public class Main implements Config {
                 addNextToAJCOptions = true;
                 options.addElement( arg );
                 ajcOptions.addElement( arg );
+            } 
+            else if ( arg.equals( "-source" ) ) {
+                addNextAsOption = true;
+                addNextToAJCOptions = true;
+                addNextAsClasspath = true;
+                options.addElement( arg );
+                ajcOptions.addElement( arg );
             }
             else if ( arg.equals( "-classpath" ) ) {
                 addNextAsOption = true;
@@ -498,6 +510,9 @@ public class Main implements Config {
                 //options.addElement( arg );
                 //ajcOptions.addElement( arg );
             }
+            else if (arg.equals("-XajdocDebug")) {
+               deleteTempFilesOnExit = false;
+            } 
             else if (arg.startsWith("-") || addNextAsOption) {
                 if ( arg.equals( "-private" ) ) {
                     docModifier = "private";
@@ -533,7 +548,7 @@ public class Main implements Config {
                 } else if ( addNextAsOption ) {
                     //  pass through
                 } else {
-                       System.err.println("> uncrecognized arg: " + arg);
+                       System.err.println("> unrecognized argument: " + arg);
                     displayHelpAndExit( null );
                 }  
                 options.addElement(arg);
index 751a3b6ad84d19ad5a48f62d7e9f58b0cfd36933..e9a72a38512a462309a811e6c1393b5b3948e40b 100644 (file)
@@ -112,7 +112,10 @@ class StubFileGenerator {
                            && !member.getKind().equals(IProgramElement.Kind.ADVICE)) {
                                signature = member.getSourceSignature();//StructureUtil.genSignature(member);
                        } 
-                       if (signature != null &&
+                       
+                       if (member.getKind().isDeclare()) {
+                               System.err.println("> Skipping declare (ajdoc limitation): " + member.toLabelString());
+                       } else if (signature != null &&
                                signature != "" && 
                                !member.getKind().isInterTypeMember() &&
                                        !member.getKind().equals(IProgramElement.Kind.INITIALIZER) &&
diff --git a/ajdoc/testdata/simple/foo/ModelCoverage.java b/ajdoc/testdata/simple/foo/ModelCoverage.java
new file mode 100644 (file)
index 0000000..5c14055
--- /dev/null
@@ -0,0 +1,150 @@
+
+package foo;
+
+import java.io.*;
+import java.util.List;
+interface I { } 
+
+class Point { 
+       int x;
+       static int sx;
+
+       { 
+               System.out.println(""); 
+       } 
+
+       { x = 0; }
+       static { sx = 1; }
+       
+       public Point() { }
+       
+       public int getX() { 
+               return x;       
+       }
+       
+       public void setX(int x) { 
+               this.x = x; 
+       }
+        
+       public int changeX(int x) { 
+               this.x = x;
+               return x;
+       }
+       
+       void doIt() { 
+               try {
+                       File f = new File(".");
+                       f.getCanonicalPath();
+               } catch (IOException ioe) {
+                       System.err.println("!");        
+               }       
+//             setX(10);
+               new Point();
+       }
+} 
+
+class SubPoint extends Point { }
+
+class Line { }
+
+aspect AdvisesRelationshipCoverage {
+       pointcut methodExecutionP(): execution(void Point.setX(int));
+       before(): methodExecutionP() { }
+  
+       pointcut constructorExecutionP(): execution(Point.new());
+       before(): constructorExecutionP() { }
+
+       pointcut callMethodP(): call(* Point.setX(int));
+       before(): callMethodP() { }
+
+       pointcut callConstructorP(): call(Point.new());
+       before(): callConstructorP() { }
+
+       pointcut getP(): get(int *.*);
+       before(): getP() { }
+
+       pointcut setP(): set(int *.*) && !set(int *.xxx);
+       before(): setP() { }
+
+       pointcut initializationP(): initialization(Point.new(..));
+       before(): initializationP() { }
+
+       pointcut staticinitializationP(): staticinitialization(Point);
+       before(): staticinitializationP() { }
+
+       pointcut handlerP(): handler(IOException);
+       before(): handlerP() { }
+
+//    before(): within(*) && execution(* Point.setX(..)) { }
+//    before(): within(*) && execution(Point.new()) { }
+}
+
+aspect AdviceNamingCoverage {
+       pointcut named(): call(* *.mumble());
+       pointcut namedWithOneArg(int i): call(int Point.changeX(int)) && args(i);
+       pointcut namedWithArgs(int i, int j): set(int Point.x) && args(i, j);
+
+       after(): named() { }    
+       after(int i, int j) returning: namedWithArgs(i, j) { }
+       after() throwing: named() { }
+       after(): named() { } 
+       
+       before(): named() { }
+       
+       int around(int i): namedWithOneArg(i) { return i;}
+       int around(int i) throws SizeException: namedWithOneArg(i) { return proceed(i); }
+       
+       before(): named() { }   
+       before(int i): call(* *.mumble()) && named() && namedWithOneArg(i) { }  
+       before(int i): named() && call(* *.mumble()) && namedWithOneArg(i) { }  
+       
+       before(): call(* *.mumble()) { }
+}
+  
+abstract aspect AbstractAspect {
+       abstract pointcut abPtct();     
+}
+  
+aspect InterTypeDecCoverage {
+    public int Point.xxx = 0;
+    public int Point.check(int i, Line l) { return 1 + i; }
+}
+
+aspect DeclareCoverage {
+
+    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+ implements java.util.Observable;
+       declare parents: Point && Line implements java.util.Observable;
+    declare soft: SizeException : call(* Point.getX());
+       declare precedence: AdviceCoverage, InterTypeDecCoverage, *;
+//     public Line.new(String s) {  }
+}
+
+class SizeException extends Exception { } 
+
+aspect AdviceCoverage {
+
+}
+
+abstract class ModifiersCoverage {
+       private int a;
+       protected int b;
+       public int c;
+       int d;
+
+       static int staticA;
+       final int finalA = 0;
+       
+       abstract void abstractM();
+}
+
+
+
+
+
index a7300b07ebea660f21dc0f75f4e76d86c7a24627..ed1408b01706c17021ab77f4df8dcbea99596fda 100644 (file)
@@ -7,6 +7,7 @@ public class PlainJava {
        public int i;
         
        public int getI() { 
+               assert true;
                
                new FileFilter() {
                        public boolean accept(File f) {
index 790d8302c588cc6aa50389f225c33e93518ba9fb..7e629f96acb9aed517f90e38333f9cbbb15941b3 100644 (file)
@@ -29,14 +29,20 @@ public class CoverageTestCase extends TestCase {
                File aspect1 = new File("testdata/simple/foo/AspectA.java");
                File file2 = new File("testdata/simple/foo/InterfaceI.java");
                File file3 = new File("testdata/simple/foo/PlainJava.java");
+               File file4 = new File("testdata/simple/foo/ModelCoverage.java");
                File outdir = new File("testdata/simple/doc");
                
-               String[] args = { "-d", 
+               String[] args = { 
+//                             "-XajdocDebug",
+                               "-source",
+                               "1.4",
+                               "-d", 
                                outdir.getAbsolutePath(),
                                aspect1.getAbsolutePath(),
                                file1.getAbsolutePath(), 
                                file2.getAbsolutePath(),
-                               file3.getAbsolutePath()};
+                               file3.getAbsolutePath(),
+                               file4.getAbsolutePath()};
                
                org.aspectj.tools.ajdoc.Main.main(args);
        }