01: package org.acm.seguin.pmd.swingui;
02:
03: import org.acm.seguin.pmd.RuleSet;
04:
05: import java.io.File;
06: import java.io.FileFilter;
07: import java.util.ArrayList;
08: import java.util.List;
09:
10: /**
11: *
12: * @author Donald A. Leckie
13: * @since August 27, 2002
14: * @version $Revision: 1.1 $, $Date: 2003/07/29 20:51:59 $
15: */
16: class SearchResultsViewer extends ResultsViewer {
17:
18: /**
19: ********************************************************************************
20: *
21: */
22: protected SearchResultsViewer() {
23: super ();
24:
25: }
26:
27: /**
28: ********************************************************************************
29: *
30: * @param ruleSet
31: * @param directory
32: */
33: protected void analyze(File directory, RuleSet ruleSet) {
34: List fileList;
35: FileFilter fileFilter;
36: File[] sourceFiles;
37:
38: fileList = new ArrayList(20);
39: fileFilter = new FilesFilter();
40: buildFileList(directory, fileList, fileFilter);
41: sourceFiles = new File[fileList.size()];
42: sourceFiles = (File[]) fileList.toArray(sourceFiles);
43: fileList.clear();
44: analyze(sourceFiles, ruleSet);
45: }
46:
47: /**
48: *******************************************************************************
49: *
50: * @param directory
51: * @param fileList
52: * @param fileFilter
53: */
54: private void buildFileList(File directory, List fileList,
55: FileFilter fileFilter) {
56: File[] files = directory.listFiles(fileFilter);
57:
58: for (int n = 0; n < files.length; n++) {
59: if (files[n].isDirectory()) {
60: buildFileList(files[n], fileList, fileFilter);
61: } else {
62: fileList.add(files[n]);
63: }
64:
65: files[n] = null;
66: }
67: }
68:
69: /**
70: *******************************************************************************
71: *******************************************************************************
72: *******************************************************************************
73: */
74: private class FilesFilter implements FileFilter {
75:
76: private String fileExtension = ".java";
77:
78: public boolean accept(File file) {
79: if (file.isDirectory() && (file.isHidden() == false)) {
80: return true;
81: }
82:
83: if (file.isFile() && (file.isHidden() == false)) {
84: String fileName = file.getName().toLowerCase();
85:
86: return (fileName.endsWith(fileExtension));
87: }
88:
89: return false;
90:
91: }
92: }
93: }
|