01: package net.sourceforge.importscrubber;
02:
03: import java.io.File;
04: import java.io.IOException;
05: import java.util.ListIterator;
06:
07: /**
08: * Encapsulates the data needed to clean up the import statements of one file
09: */
10: public class ScrubTask implements IReferenceFoundListener {
11: private SourceFile _sourceFile;
12: private final FilePair _pair;
13: private StatementFormat _format;
14: private String _encoding;
15:
16: public ScrubTask(FilePair pair, StatementFormat format,
17: String encoding) throws IOException {
18: _pair = pair;
19: _format = format;
20: _encoding = encoding;
21: }
22:
23: public void run() throws IOException {
24: _sourceFile = new SourceFile(_pair.getSourceFile(), _encoding);
25: for (ListIterator iter = _pair.getClassFiles(); iter.hasNext();) {
26: ClassParserWrapper.parse((File) iter.next(), this );
27: }
28: _sourceFile.save(_format);
29: }
30:
31: public void referenceFound(String className) {
32: _sourceFile.addImport(className);
33: }
34:
35: public String toString() {
36: return getSourcePath();
37: }
38:
39: public String getSourcePath() {
40: return _pair.getSourceFile().getAbsolutePath();
41: }
42:
43: public static void main(String[] args) {
44: FilePair pair = new FilePair(new File(
45: "d:\\importscrubber\\tmp\\NodeListener.java"),
46: new File("d:\\importscrubber\\tmp\\NodeListener.class"));
47: for (ListIterator iter = pair.getClassFiles(); iter.hasNext();) {
48: try {
49: ClassParserWrapper.parse((File) iter.next(),
50: new PrintListener());
51: } catch (Exception e) {
52: e.printStackTrace();
53: }
54: }
55: }
56: }
|