Clover coverage report - XJavaDoc - 1.1
Coverage timestamp: Mon Oct 4 2004 23:49:51 BST
file stats: LOC: 167   Methods: 9
NCLOC: 113   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
Util.java 72.7% 81.8% 88.9% 80%
coverage coverage
 1   
 /*
 2   
  * Copyright (c) 2001-2003 The XDoclet team
 3   
  * All rights reserved.
 4   
  */
 5   
 package xjavadoc;
 6   
 
 7   
 import java.io.File;
 8   
 import java.io.FileFilter;
 9   
 import java.util.LinkedList;
 10   
 
 11   
 /**
 12   
  * Various static utility methods
 13   
  *
 14   
  * @author         Aslak Hellesøy
 15   
  * @created        20. januar 2002
 16   
  */
 17   
 public class Util
 18   
 {
 19   
 
 20   
     private final static FileFilter _javaFilter =
 21   
         new FileFilter()
 22   
         {
 23  825
             public boolean accept( File f )
 24   
             {
 25  825
                 return f.getName().endsWith( ".java" );
 26   
             }
 27   
         };
 28   
 
 29   
     private final static FileFilter _dirFilter =
 30   
         new FileFilter()
 31   
         {
 32  825
             public boolean accept( File f )
 33   
             {
 34  825
                 return f.isDirectory();
 35   
             }
 36   
         };
 37   
 
 38   
     /**
 39   
      * Returns an array of String containing relative names of all java files under
 40   
      * root.
 41   
      *
 42   
      * @param root  the root directory
 43   
      * @return      java file names
 44   
      */
 45  25
     public static String[] getJavaFiles( File root )
 46   
     {
 47  25
         LinkedList javaFileNames = new LinkedList();
 48   
 
 49  25
         descend( root, "", javaFileNames );
 50  25
         return ( String[] ) javaFileNames.toArray( new String[javaFileNames.size()] );
 51   
     }
 52   
 
 53  684
     public static String getPackageNameFor( String qualifiedName )
 54   
     {
 55  684
         String packageName = null;
 56  684
         int lastDotIndex = qualifiedName.lastIndexOf( '.' );
 57   
 
 58  684
         if( lastDotIndex == -1 )
 59   
         {
 60   
             // default package
 61  0
             packageName = "";
 62   
         }
 63   
         else
 64   
         {
 65  684
             packageName = qualifiedName.substring( 0, lastDotIndex );
 66   
         }
 67  684
         return packageName;
 68   
     }
 69   
 
 70  366
     public static String getQualifiedNameFor( String packageName, String unqualifiedName )
 71   
     {
 72  366
         if( packageName.equals( "" ) )
 73   
         {
 74  52
             return unqualifiedName;
 75   
         }
 76   
         else
 77   
         {
 78  314
             return packageName + "." + unqualifiedName;
 79   
         }
 80   
     }
 81   
 
 82  931
     public final static StringBuffer appendDimensionAsString( final int n, final StringBuffer sb )
 83   
     {
 84  931
         for( int i = 0; i < n; i++ )
 85   
         {
 86  36
             sb.append( "[]" );
 87   
         }
 88  931
         return sb;
 89   
     }
 90   
 
 91  0
     public final static String toString( Object[] array, String delimiter )
 92   
     {
 93  0
         StringBuffer sb = new StringBuffer();
 94   
 
 95  0
         for( int i = 0; i < array.length; i++ )
 96   
         {
 97  0
             sb.append( array[i].toString() );
 98  0
             if( i < array.length - 1 )
 99   
             {
 100  0
                 sb.append( delimiter );
 101   
             }
 102   
         }
 103  0
         return sb.toString();
 104   
     }
 105   
     /**
 106   
      * Return only class name of a full qualified (package+classname) string.
 107   
      *
 108   
      * @param qualifiedName
 109   
      * @return
 110   
      */
 111  1654
     public static String classNameFromQualifiedClassName( String qualifiedName )
 112   
     {
 113  1654
         if( qualifiedName == null )
 114   
         {
 115  0
             throw new IllegalArgumentException( "qualifiedName can't be null!" );
 116   
         }
 117   
 
 118  1654
         int dot_index = qualifiedName.lastIndexOf( '.' );
 119   
 
 120  1654
         if( dot_index != -1 )
 121  1008
             return qualifiedName.substring( dot_index + 1 );
 122   
         else
 123  646
             return qualifiedName;
 124   
     }
 125   
 
 126   
     /**
 127   
      * Recursively descends a directory and build a list of relative file names for
 128   
      * java files.
 129   
      *
 130   
      * @param root           the root directory
 131   
      * @param dirName        current directory relative filename
 132   
      * @param javaFileNames  the list where java file names will be added
 133   
      */
 134  200
     private static void descend( File root, String dirName, LinkedList javaFileNames )
 135   
     {
 136  200
         File dir = new File( root, dirName );
 137   
 
 138  200
         File[] javaFiles = dir.listFiles( _javaFilter );
 139   
 
 140  200
         for( int i = 0; i < javaFiles.length; i++ )
 141   
         {
 142  250
             StringBuffer javaFileName = new StringBuffer();
 143   
 
 144  250
             if( dirName.length() != 0 )
 145   
             {
 146  175
                 javaFileName.append( dirName ).append( File.separator );
 147   
             }
 148  250
             javaFileName.append( javaFiles[i].getName() );
 149  250
             javaFileNames.add( javaFileName.toString() );
 150   
         }
 151   
 
 152  200
         File[] subDirs = dir.listFiles( _dirFilter );
 153   
 
 154  200
         for( int i = 0; i < subDirs.length; i++ )
 155   
         {
 156  175
             StringBuffer subDirName = new StringBuffer( dirName );
 157   
 
 158  175
             if( dirName.length() != 0 )
 159   
             {
 160  75
                 subDirName.append( File.separator );
 161   
             }
 162  175
             subDirName.append( subDirs[i].getName() );
 163  175
             descend( root, subDirName.toString(), javaFileNames );
 164   
         }
 165   
     }
 166   
 }
 167