1 11 package org.eclipse.swt.tools.internal; 12 13 import java.io.*; 14 import java.util.*; 15 16 public abstract class CleanupClass extends JNIGenerator { 17 18 String classSourcePath; 19 String [] sourcePath; 20 String classSource; 21 Hashtable files; 22 int usedCount, unusedCount; 23 24 void loadClassSource() { 25 if (classSourcePath == null) return; 26 File f = new File(classSourcePath); 27 classSource = loadFile(f); 28 } 29 30 void loadFiles () { 31 if (sourcePath == null) return; 33 files = new Hashtable (); 34 for (int i = 0; i < sourcePath.length; i++) { 35 File file = new File(sourcePath[i]); 36 if (file.exists()) { 37 if (!file.isDirectory()) { 38 if (file.getAbsolutePath().endsWith(".java")) { 39 files.put(file, loadFile(file)); 40 } 41 } else { 42 loadDirectory(file); 43 } 44 } 45 } 46 } 47 48 String loadFile (File file) { 49 try { 50 FileReader fr = new FileReader(file); 51 BufferedReader br = new BufferedReader(fr); 52 StringBuffer str = new StringBuffer (); 53 char[] buffer = new char[1024]; 54 int read; 55 while ((read = br.read(buffer)) != -1) { 56 str.append(buffer, 0, read); 57 } 58 fr.close(); 59 return str.toString(); 60 } catch (IOException e) { 61 e.printStackTrace(System.out); 62 } 63 return ""; 64 } 65 66 void loadDirectory(File file) { 67 String [] entries = file.list(); 68 for (int i = 0; i < entries.length; i++) { 69 String entry = entries[i]; 70 File f = new File(file, entry); 71 if (!f.isDirectory()) { 72 if (f.getAbsolutePath().endsWith(".java")) { 73 files.put(f, loadFile(f)); 74 } 75 } else { 76 loadDirectory(f); 77 } 78 } 79 } 80 81 public void generate(Class clazz) { 82 loadFiles (); 83 loadClassSource(); 84 } 85 86 public void setSourcePath(String [] sourcePath) { 87 this.sourcePath = sourcePath; 88 files = null; 89 } 90 91 public void setClassSourcePath(String classSourcePath) { 92 this.classSourcePath = classSourcePath; 93 } 94 95 } 96 | Popular Tags |