01: package tide.project;
02:
03: import java.io.*;
04: import java.util.zip.*;
05:
06: /** ProjClass: a class of the project (from compiled source or from classpath).
07: * Used for compiler "undo" TODO.
08: * Used for completion (reflection, ASM, ...)
09: * Used for analysis.
10: * Takses a lot of mem => keep small !
11: * Inner classes A$B and private classes are also included.
12: */
13: @net.jcip.annotations.Immutable
14: public final class ProjClass //implements Comparable<ProjClass>
15: {
16:
17: private final File classFile;
18: private final ZipEntry ze;
19: private final ZipFile zf;
20:
21: // if null, recomputed on the fly, using the zip entry name. => takes less memory !
22: final private String javaName;
23:
24: // to know if uptodate... (TODO)
25: //public long readTime;
26:
27: public ProjClass(File classFile, String javaName) {
28: this .classFile = classFile;
29: this .ze = null;
30: this .zf = null;
31: this .javaName = javaName;
32: }
33:
34: public ProjClass(ZipEntry ze, ZipFile zf)//, String javaName)
35: {
36: this .classFile = null;
37: this .ze = ze;
38: this .zf = zf;
39: this .javaName = null;
40: }
41:
42: public String getJavaName() {
43: if (javaName != null)
44: return javaName;
45: return createJavaNameFromClassFileName(ze.getName());
46: }
47:
48: private static String createJavaNameFromClassFileName(String cn) {
49: return cn.substring(0, cn.length() - 6).replace('/', '.')
50: .replace('$', '.');
51: }
52:
53: public InputStream getClassContent() throws Exception {
54: if (zf != null)
55: return zf.getInputStream(ze);
56: if (classFile.exists())
57: return new FileInputStream(classFile);
58: return null;
59: }
60:
61: @Override
62: public final String toString() {
63: StringBuilder sb = new StringBuilder();
64: sb.append("ProjClass ");
65: sb.append(getJavaName());
66: return sb.toString();
67: }
68: /*
69: // comparable
70:
71: public final int compareTo( ProjClass po ) {
72: return getJavaName().compareTo( po.getJavaName());
73: }
74:
75: @Override final public boolean equals( Object obj ) {
76: ProjClass pc = (ProjClass) obj;
77: if(classFile!=null && pc.classFile!=null) return classFile == pc.classFile;
78: if(ze!=null && pc.ze!=null) return ze == pc.ze;
79:
80: return getJavaName().equals( po.getJavaName() );
81: }*/
82: /*
83: public final int compareTo( Object o ) {
84: return compareTo((ProjClass) o);
85: }*/
86:
87: }
|