1 24 25 package org.aspectj.compiler.base.bytecode; 26 27 import org.aspectj.compiler.base.*; 28 import org.aspectj.compiler.base.ast.*; 29 30 31 import java.io.*; 32 import java.util.zip.*; 33 import java.util.StringTokenizer ; 34 35 import java.util.*; 36 37 abstract public class ClassManager extends CompilerObject { 38 private ASTConnection astConnection = null; 39 40 public ClassManager(JavaCompiler compiler) { 41 super(compiler); 42 } 43 44 private ASTConnection getASTConnection() { 45 if (astConnection == null) { 46 astConnection = new ASTConnection(getCompiler()); 47 } 48 return astConnection; 49 } 50 51 public abstract TypeDec findTypeDec(String name); 52 public abstract ClassManager makeSubPackageManager(String subPackageName); 53 54 59 public abstract Collection getAllPossibleTypeNames(); 60 61 public TypeDec makeTypeDec(String name, InputStream inputStream) { 62 if (inputStream == null) return null; 64 65 try { 66 ClassFile classFile = new ClassFile(); 67 try { 68 DataInputStream dataStream = 69 new DataInputStream(prereadInputStream(inputStream)); 70 classFile.readFrom(dataStream); 71 } catch (IOException e) { 72 System.err.println("ioexception for: "+name+", "+inputStream); 73 e.printStackTrace(); 74 return null; 75 } catch (InvalidClassFileException icfe) { 76 System.err.println("bad class file for: "+name+", "+inputStream); 77 icfe.printStackTrace(); 78 return null; 79 } 80 81 if (getCompiler().getOptionVerbose()) { 82 getCompiler().showMessage("loading: "+name); 83 } 84 85 TypeDec typeDec = getASTConnection().makeTypeDec(classFile); 86 87 return typeDec; 88 } finally { 89 try { 90 inputStream.close(); 91 } catch (IOException e) {} 92 } 93 } 94 95 public Collection getPathStrings() { 96 Collection ret = new LinkedList(); 97 ret.add(getPathString()); 98 return ret; 99 } 100 101 protected String getPathString() { 102 throw new UnsupportedOperationException ("no simple string"); 103 } 104 105 106 private static byte[] bytes = new byte[500*1024]; 109 private InputStream prereadInputStream(InputStream stream) throws IOException { 110 int index = 0; 111 while (true) { 112 int nread = stream.read(bytes, index, bytes.length-index); 113 if (nread == -1) break; 114 index = index+nread; 115 } 116 stream.close(); 117 118 return new ByteArrayInputStream(bytes, 0, index); 119 } 120 121 public List filenameToClassName(String filename) { 122 int last = 0; 123 List ret = new ArrayList(); 124 for (int i=0, len = filename.length(); i < len; i++) { 125 char ch = filename.charAt(i); 126 if (ch == '.' || ch == '/' || ch == '\\' || ch == '$') { 127 ret.add(filename.substring(last, i)); 128 last = i+1; 129 } 130 } 131 133 return ret; 134 } 135 } 136 | Popular Tags |