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