Clover coverage report - XJavaDoc - 1.1 Coverage timestamp: Sun Oct 3 2004 19:56:54 BST FRAMES NO FRAMES |
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% |

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 | 1650 |
                 public boolean accept( File f )
24 |  |
                 {
25 | 1650 |
                     return f.getName().endsWith( ".java" );
26 |  |
                 }
27 |  |
             };
28 |  |
29 |  |
         private final static FileFilter _dirFilter =
30 |  |
             new FileFilter()
31 |  |
             {
32 | 1650 |
                 public boolean accept( File f )
33 |  |
                 {
34 | 1650 |
                     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 | 50 |
         public static String[] getJavaFiles( File root )
46 |  |
         {
47 | 50 |
             LinkedList javaFileNames = new LinkedList();
48 |  |
49 | 50 |
             descend( root, "", javaFileNames );
50 | 50 |
             return ( String[] ) javaFileNames.toArray( new String[javaFileNames.size()] );
51 |  |
         }
52 |  |
53 | 1368 |
         public static String getPackageNameFor( String qualifiedName )
54 |  |
         {
55 | 1368 |
             String packageName = null;
56 | 1368 |
             int lastDotIndex = qualifiedName.lastIndexOf( '.' );
57 |  |
58 | 1368 |
             if( lastDotIndex == -1 )
59 |  |
             {
60 |  |
                 // default package
61 | 0 |
                 packageName = "";
62 |  |
             }
63 |  |
             else
64 |  |
             {
65 | 1368 |
                 packageName = qualifiedName.substring( 0, lastDotIndex );
66 |  |
             }
67 | 1368 |
             return packageName;
68 |  |
         }
69 |  |
70 | 732 |
         public static String getQualifiedNameFor( String packageName, String unqualifiedName )
71 |  |
         {
72 | 732 |
             if( packageName.equals( "" ) )
73 |  |
             {
74 | 104 |
                 return unqualifiedName;
75 |  |
             }
76 |  |
             else
77 |  |
             {
78 | 628 |
                 return packageName + "." + unqualifiedName;
79 |  |
             }
80 |  |
         }
81 |  |
82 | 1862 |
         public final static StringBuffer appendDimensionAsString( final int n, final StringBuffer sb )
83 |  |
         {
84 | 1862 |
             for( int i = 0; i < n; i++ )
85 |  |
             {
86 | 72 |
                 sb.append( "[]" );
87 |  |
             }
88 | 1862 |
             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 | 3308 |
         public static String classNameFromQualifiedClassName( String qualifiedName )
112 |  |
         {
113 | 3308 |
             if( qualifiedName == null )
114 |  |
             {
115 | 0 |
                 throw new IllegalArgumentException( "qualifiedName can't be null!" );
116 |  |
             }
117 |  |
118 | 3308 |
             int dot_index = qualifiedName.lastIndexOf( '.' );
119 |  |
120 | 3308 |
             if( dot_index != -1 )
121 | 2016 |
                 return qualifiedName.substring( dot_index + 1 );
122 |  |
             else
123 | 1292 |
                 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 | 400 |
         private static void descend( File root, String dirName, LinkedList javaFileNames )
135 |  |
         {
136 | 400 |
             File dir = new File( root, dirName );
137 |  |
138 | 400 |
             File[] javaFiles = dir.listFiles( _javaFilter );
139 |  |
140 | 400 |
             for( int i = 0; i < javaFiles.length; i++ )
141 |  |
             {
142 | 500 |
                 StringBuffer javaFileName = new StringBuffer();
143 |  |
144 | 500 |
                 if( dirName.length() != 0 )
145 |  |
                 {
146 | 350 |
                     javaFileName.append( dirName ).append( File.separator );
147 |  |
                 }
148 | 500 |
                 javaFileName.append( javaFiles[i].getName() );
149 | 500 |
                 javaFileNames.add( javaFileName.toString() );
150 |  |
             }
151 |  |
152 | 400 |
             File[] subDirs = dir.listFiles( _dirFilter );
153 |  |
154 | 400 |
             for( int i = 0; i < subDirs.length; i++ )
155 |  |
             {
156 | 350 |
                 StringBuffer subDirName = new StringBuffer( dirName );
157 |  |
158 | 350 |
                 if( dirName.length() != 0 )
159 |  |
                 {
160 | 150 |
                     subDirName.append( File.separator );
161 |  |
                 }
162 | 350 |
                 subDirName.append( subDirs[i].getName() );
163 | 350 |
                 descend( root, subDirName.toString(), javaFileNames );
164 |  |
             }
165 |  |
         }
166 |  |
     }
167 |  |