99 * Brock Janiczak - initial API and implementation
1010 *
1111 *******************************************************************************/
12- package edu .rice .cs .drjava .ui ;
12+ package edu .rice .cs .drjava .ui . coverage ;
1313
1414import java .io .File ;
1515import java .io .FileInputStream ;
@@ -89,12 +89,13 @@ protected Class<?> loadClass(final String name, final boolean resolve)
8989 }
9090 }
9191
92- private InputStream getTargetClass (final String name ) {
92+ /** Public getters and setters */
93+ public InputStream getTargetClass (final String name ) {
9394 final String resource = '/' + name .replace ('.' , '/' ) + ".class" ;
9495 return getClass ().getResourceAsStream (resource );
9596 }
9697
97- private InputStream getTargetClass (final File file ) throws Exception {
98+ public InputStream getTargetClass (final File file ) throws Exception {
9899 return new FileInputStream (file .getCanonicalPath ().replace (".java" ,
99100 ".class" ));
100101 }
@@ -138,90 +139,88 @@ private String getColor(final int status) {
138139 return "" ;
139140 }
140141
141- /**
142- * Create a new generator based for the given file.
143- *
144- */
145- public ReportGenerator (final SingleDisplayModel _model ,
146- /* final GlobalModel _model, */
147- final List <OpenDefinitionsDocument > docs ,
148- final File destDirectory ) throws Exception {
149-
150- File src = docs .get (0 ).getFile ().getParentFile ();
151- String packageName = docs .get (0 ).getPackageName ();
152- if (!packageName .equals ("" )) {
153- // If there's package, go up until the root dir
154- int numUp = packageName .split ("\\ ." ).length ;
155- for (int i = 0 ; i < numUp ; i ++) {
156- src = src .getParentFile ();
157- }
158- }
159- this .sourceDirectory = src ;
160- this .title = src .getName ();
161-
162- List <File > targets = new ArrayList <File >();
163- for (File dir :CollectUtil .makeList (_model .getClassPath ())) {
164- if (!dir .isDirectory () || dir .getName ().equals ("lib" ) ||
165- dir .getName ().equals ("base" ) || dir .getName ().equals ("test" )) {
166- continue ;
167- }
168- targets .addAll (rec_init_target (dir ));
169- }
170- this .targets = targets ;
171-
172- ArrayList <String > targetNames = new ArrayList <String >();
173- for (File f : targets ) {
174- targetNames .add (getTargetClassName (f ));
175- }
176-
177- this .targetNames = targetNames ;
178- this .reportDirectory = destDirectory ;
179- this .mainClassFileName = getTargetClassName (docs .get (0 ).getFile ());
180- }
181-
142+ /**
143+ * Create a new generator based for the given file.
144+ *
145+ */
146+ public ReportGenerator (final GlobalModel _model ,
147+ final List <OpenDefinitionsDocument > docs ,
148+ final File destDirectory ) throws Exception {
149+
150+ File src = docs .get (0 ).getFile ().getParentFile ();
151+ String packageName = docs .get (0 ).getPackageName ();
152+ if (!packageName .equals ("" )) {
153+ // If there's package, go up until the root dir
154+ int numUp = packageName .split ("\\ ." ).length ;
155+ for (int i = 0 ; i < numUp ; i ++) {
156+ src = src .getParentFile ();
157+ }
158+ }
159+ this .sourceDirectory = src ;
160+ this .title = src .getName ();
182161
183- /**
184- * Create a new generator based for the given project.
185- */
186- public ReportGenerator (final SingleDisplayModel _model ,
187- File sourceDirectory , String mainClassPath , File destDirectory )
188- throws Exception {
162+ List <File > targets = new ArrayList <File >();
163+ for (File dir :CollectUtil .makeList (_model .getClassPath ())) {
164+ if (!dir .isDirectory () || dir .getName ().equals ("lib" ) ||
165+ dir .getName ().equals ("base" ) || dir .getName ().equals ("test" )) {
166+ continue ;
167+ }
168+ targets .addAll (rec_init_target (dir ));
169+ }
170+ this .targets = targets ;
189171
190- this . sourceDirectory = sourceDirectory ;
191- this . reportDirectory = destDirectory ;
192- this . title = sourceDirectory . getName ();
193- this . mainClassFileName = mainClassPath ;
172+ ArrayList < String > targetNames = new ArrayList < String >() ;
173+ for ( File f : targets ) {
174+ targetNames . add ( getTargetClassName ( f ));
175+ }
194176
195- this .targets = rec_init_src (sourceDirectory );
196- ArrayList <String > targetNames = new ArrayList <String >();
197- for (File f : targets ) {
198- targetNames .add (getTargetClassName (f ));
199- }
177+ this .targetNames = targetNames ;
178+ this .reportDirectory = destDirectory ;
179+ this .mainClassFileName = getTargetClassName (docs .get (0 ).getFile ());
180+ }
200181
201- this .targetNames = targetNames ;
202- }
182+ /**
183+ * Create a new generator based for the given project.
184+ */
185+ public ReportGenerator (final GlobalModel _model ,
186+ File sourceDirectory , String mainClassPath , File destDirectory )
187+ throws Exception {
188+
189+ this .sourceDirectory = sourceDirectory ;
190+ this .reportDirectory = destDirectory ;
191+ this .title = sourceDirectory .getName ();
192+ this .mainClassFileName = mainClassPath ;
193+
194+ this .targets = rec_init_src (sourceDirectory );
195+ ArrayList <String > targetNames = new ArrayList <String >();
196+ for (File f : targets ) {
197+ targetNames .add (getTargetClassName (f ));
198+ }
203199
204- public List <File > rec_init_src (File sourceDirectory ) {
200+ this .targetNames = targetNames ;
201+ }
205202
206- ArrayList <File > files = new ArrayList <File >();
207- for (File f : sourceDirectory .listFiles ()) {
208- if (f .isFile ()) {
209- int i = f .getPath ().lastIndexOf ('.' );
210- if (i > 0 ) {
211- String extension = f .getPath ().substring (i +1 );
212- if (extension .equals ("java" )) {
213- files .add (f );
214- }
215- }
216- } else if (f .isDirectory ()) {
217- files .addAll (rec_init_src (f ));
218- }
219- }
203+ public List <File > rec_init_src (File sourceDirectory ) {
204+
205+ ArrayList <File > files = new ArrayList <File >();
206+ for (File f : sourceDirectory .listFiles ()) {
207+ if (f .isFile ()) {
208+ int i = f .getPath ().lastIndexOf ('.' );
209+ if (i > 0 ) {
210+ String extension = f .getPath ().substring (i +1 );
211+ if (extension .equals ("java" )) {
212+ files .add (f );
213+ }
214+ }
215+ } else if (f .isDirectory ()) {
216+ files .addAll (rec_init_src (f ));
217+ }
218+ }
220219
221- return files ;
222- }
220+ return files ;
221+ }
223222
224- public List <File > rec_init_target (File sourceDirectory ){
223+ public List <File > rec_init_target (File sourceDirectory ){
225224 ArrayList <File > files = new ArrayList <File >();
226225 for (File f : sourceDirectory .listFiles ()) {
227226 if (f .isFile ()) {
@@ -237,9 +236,8 @@ public List<File> rec_init_target(File sourceDirectory){
237236 }
238237 }
239238
240- return files ;
241- }
242-
239+ return files ;
240+ }
243241
244242 /**
245243 * Create the report.
@@ -336,7 +334,11 @@ public void createReport(final IBundleCoverage bundleCoverage,
336334 visitor .visitEnd ();
337335 }
338336
339-
337+ /** Public getters and setters */
338+ public File getSourceDirectory () {
339+ return this .sourceDirectory ;
340+ }
341+
340342 public ArrayList <String > getLineColorsForClass (String className ) {
341343
342344 ArrayList <String > lineColors = new ArrayList <String >();
0 commit comments