KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > importscrubber > ScrubTask


1 package net.sourceforge.importscrubber;
2
3 import java.io.File JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.util.ListIterator JavaDoc;
6
7 /**
8  * Encapsulates the data needed to clean up the import statements of one file
9  */

10 public class ScrubTask implements IReferenceFoundListener
11 {
12     private SourceFile _sourceFile;
13     private final FilePair _pair;
14     private StatementFormat _format;
15     private String JavaDoc _encoding;
16
17     public ScrubTask(FilePair pair, StatementFormat format, String JavaDoc encoding) throws IOException JavaDoc
18     {
19         _pair = pair;
20         _format = format;
21         _encoding = encoding;
22     }
23
24     public void run() throws IOException JavaDoc
25     {
26         _sourceFile = new SourceFile(_pair.getSourceFile(), _encoding);
27         for (ListIterator JavaDoc iter = _pair.getClassFiles(); iter.hasNext();) {
28             ClassParserWrapper.parse((File JavaDoc)iter.next(), this);
29         }
30         _sourceFile.save(_format);
31     }
32
33     public void referenceFound(String JavaDoc className)
34     {
35         _sourceFile.addImport(className);
36     }
37
38     public String JavaDoc toString()
39     {
40         return getSourcePath();
41     }
42
43     public String JavaDoc getSourcePath()
44     {
45         return _pair.getSourceFile().getAbsolutePath();
46     }
47
48     public static void main(String JavaDoc[] args)
49     {
50         FilePair pair = new FilePair(new File JavaDoc("d:\\importscrubber\\tmp\\NodeListener.java"), new File JavaDoc("d:\\importscrubber\\tmp\\NodeListener.class"));
51         for (ListIterator JavaDoc iter = pair.getClassFiles(); iter.hasNext();) {
52             try {
53                 ClassParserWrapper.parse((File JavaDoc)iter.next(), new PrintListener());
54             } catch (Exception JavaDoc e) {
55                 e.printStackTrace();
56             }
57         }
58     }
59 }
60
Popular Tags