ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From je...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/types/optional/depend ClassFileSetTest.java
Date Tue, 15 Apr 2003 03:34:11 GMT
jesse       2003/04/14 20:34:11

  Modified:    src/etc/testcases/taskdefs/optional/depend depend.xml
               src/main/org/apache/tools/ant/util/depend/bcel
                        DependencyVisitor.java
               src/testcases/org/apache/tools/ant/taskdefs/optional/depend
                        DependTest.java
               src/testcases/org/apache/tools/ant/types/optional/depend
                        ClassFileSetTest.java
  Added:       src/etc/testcases/taskdefs/optional/depend/src4/test
                        ContainsOnlyInner.java MethodParam.java
  Log:
  Better detection of classes passed as method params like 'System.out.println(Outer.Inner.class);'
  PR: 13273
  
  Revision  Changes    Path
  1.1                  ant/src/etc/testcases/taskdefs/optional/depend/src4/test/ContainsOnlyInner.java
  
  Index: ContainsOnlyInner.java
  ===================================================================
  package test;
  
  public class ContainsOnlyInner {
      void method1() {
          System.out.println(Outer.Inner.class);
      }    
  }
  
  
  
  
  1.1                  ant/src/etc/testcases/taskdefs/optional/depend/src4/test/MethodParam.java
  
  Index: MethodParam.java
  ===================================================================
  package test;
  
  public class MethodParam {
      void method1() {
          System.out.print(ContainsOnlyInner.class);
      }
  }
  
  
  
  
  1.10      +4 -0      ant/src/etc/testcases/taskdefs/optional/depend/depend.xml
  
  Index: depend.xml
  ===================================================================
  RCS file: /home/cvs/ant/src/etc/testcases/taskdefs/optional/depend/depend.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- depend.xml	20 Dec 2002 13:57:12 -0000	1.9
  +++ depend.xml	15 Apr 2003 03:34:11 -0000	1.10
  @@ -117,6 +117,10 @@
       <fileset id="result" dir="${classes.dir}"/>
     </target>
     
  +  <target name="testmethodparaminner" depends="src4setup, compile">
  +    <classfileset id="result" dir="${classes.dir}" rootclass="test.MethodParam"/>
  +  </target>  
  +  
     <target name="testnosource" depends="src1setup, compile">
       <depend destdir="${classes.dir}" closure="yes"/>
     </target>
  
  
  
  1.6       +29 -5     ant/src/main/org/apache/tools/ant/util/depend/bcel/DependencyVisitor.java
  
  Index: DependencyVisitor.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/depend/bcel/DependencyVisitor.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DependencyVisitor.java	10 Feb 2003 14:14:40 -0000	1.5
  +++ DependencyVisitor.java	15 Apr 2003 03:34:11 -0000	1.6
  @@ -124,11 +124,35 @@
           if (obj.getSignature(constantPool).equals("Ljava/lang/Class;")
                   && name.startsWith("class$")) {
               String classname = name.substring(6).replace('$', '.');
  -            addClass(classname);
  -            int index = classname.lastIndexOf(".");
  -            if (index != -1) {
  -                classname = classname.substring(0, index) + "$" +
  -                            classname.substring(index + 1);
  +            // does the class have a package structure
  +            int index = classname.lastIndexOf(".");            
  +            if (index > 0) {
  +                char start;
  +                // check if the package structure is more than 1 level deep
  +                int index2 = classname.lastIndexOf(".", index -1);
  +                if (index2 != -1) {
  +                    // class name has more than 1 package level 'com.company.Class'
  +                    start = classname.charAt(index2 + 1);
  +                }
  +                else {
  +                    // class name has only 1 package level 'package.Class'
  +                    start = classname.charAt(0);
  +                }
  +                // Check to see if it's an inner class 'com.company.Class$Inner'
  +                if ((start > 0x40) && (start < 0x5B)) {
  +                    // first letter of the previous segment of the class name 'Class'
  +                    // is upper case ascii. so according to the spec it's an inner class
  +                    classname = classname.substring(0, index) + "$" +
  +                            classname.substring(index + 1);                           

  +                    addClass(classname);
  +                }
  +                else {
  +                    // Add the class in dotted notation 'com.company.Class'           
           
  +                    addClass(classname);
  +                }                    
  +            }
  +            else {               
  +                // Add a class with no package 'Class'
                   addClass(classname);
               }
           }
  
  
  
  1.9       +1 -1      ant/src/testcases/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java
  
  Index: DependTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DependTest.java	10 Feb 2003 14:14:53 -0000	1.8
  +++ DependTest.java	15 Apr 2003 03:34:11 -0000	1.9
  @@ -179,7 +179,7 @@
       public void testInnerClosure() {
           Project project = getProject();
           executeTarget("testinnerclosure");
  -        assertEquals("Depend did not leave correct number of files", 2,
  +        assertEquals("Depend did not leave correct number of files", 4,
               getResultFiles().size());
       }
   
  
  
  
  1.4       +26 -1     ant/src/testcases/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java
  
  Index: ClassFileSetTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ClassFileSetTest.java	10 Feb 2003 14:14:56 -0000	1.3
  +++ ClassFileSetTest.java	15 Apr 2003 03:34:11 -0000	1.4
  @@ -184,5 +184,30 @@
               files.containsKey("D.class"));
           assertTrue("Result did not contain E.class",
               files.containsKey("E.class"));
  -    }    
  +    }   
  +    
  +    /**
  +     * Test that classes included in a method "System.out.println(Outer.Inner.class)" are
included.
  +     */
  +    public void testMethodParamInner() {
  +        Project project = getProject();
  +        executeTarget("testmethodparaminner");
  +        FileSet resultFileSet = (FileSet)project.getReference(RESULT_FILESET);
  +        DirectoryScanner scanner = resultFileSet.getDirectoryScanner(project);
  +        String[] scannedFiles = scanner.getIncludedFiles();
  +        Hashtable files = new Hashtable();
  +        for (int i = 0; i < scannedFiles.length; ++i) {
  +            files.put(scannedFiles[i], scannedFiles[i]);
  +        }
  +        assertEquals("Classfileset did not pick up expected number of "
  +            + "class files", 4, files.size());
  +        assertTrue("Result did not contain test/Outer$Inner.class",
  +            files.containsKey("test/Outer$Inner.class"));
  +        assertTrue("Result did not contain test/Outer.class",
  +            files.containsKey("test/Outer.class"));
  +        assertTrue("Result did not contain test/ContainsOnlyInner.class",
  +            files.containsKey("test/ContainsOnlyInner.class"));
  +        assertTrue("Result did not contain test/ContainsOnlyInner.class",
  +            files.containsKey("test/MethodParam.class"));            
  +    }
   }
  
  
  

Mime
View raw message