1 11 package org.eclipse.jdt.internal.core.hierarchy; 12 13 import org.eclipse.jdt.core.Signature; 14 import org.eclipse.jdt.core.compiler.CharOperation; 15 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; 16 import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; 17 import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation; 18 import org.eclipse.jdt.internal.compiler.env.IBinaryField; 19 import org.eclipse.jdt.internal.compiler.env.IBinaryMethod; 20 import org.eclipse.jdt.internal.compiler.env.IBinaryNestedType; 21 import org.eclipse.jdt.internal.compiler.env.IBinaryType; 22 import org.eclipse.jdt.internal.core.search.indexing.IIndexConstants; 23 24 public class HierarchyBinaryType implements IBinaryType { 25 private int modifiers; 26 private char[] sourceName; 27 private char[] name; 28 private char[] enclosingTypeName; 29 private char[] superclass; 30 private char[][] superInterfaces = NoInterface; 31 private char[][] typeParameterSignatures; 32 private char[] genericSignature; 33 34 public HierarchyBinaryType(int modifiers, char[] qualification, char[] sourceName, char[] enclosingTypeName, char[][] typeParameterSignatures, char typeSuffix){ 35 36 this.modifiers = modifiers; 37 this.sourceName = sourceName; 38 if (enclosingTypeName == null){ 39 this.name = CharOperation.concat(qualification, sourceName, '/'); 40 } else { 41 this.name = CharOperation.concat(qualification, '/', enclosingTypeName, '$', sourceName); this.enclosingTypeName = CharOperation.concat(qualification, enclosingTypeName,'/'); 43 CharOperation.replace(this.enclosingTypeName, '.', '/'); 44 } 45 this.typeParameterSignatures = typeParameterSignatures; 46 CharOperation.replace(this.name, '.', '/'); 47 } 48 55 public char[] getEnclosingTypeName() { 56 return this.enclosingTypeName; 57 } 58 61 public IBinaryField[] getFields() { 62 return null; 63 } 64 67 public char[] getFileName() { 68 return null; 69 } 70 public char[] getGenericSignature() { 71 if (this.typeParameterSignatures != null && this.genericSignature == null) { 72 StringBuffer buffer = new StringBuffer (); 73 buffer.append('<'); 74 for (int i = 0, length = this.typeParameterSignatures.length; i < length; i++) { 75 buffer.append(this.typeParameterSignatures[i]); 76 } 77 buffer.append('>'); 78 if (this.superclass == null) 79 buffer.append(Signature.createTypeSignature("java.lang.Object", true)); else 81 buffer.append(Signature.createTypeSignature(this.superclass, true)); 82 if (this.superInterfaces != null) 83 for (int i = 0, length = this.superInterfaces.length; i < length; i++) 84 buffer.append(Signature.createTypeSignature(this.superInterfaces[i], true)); 85 this.genericSignature = buffer.toString().toCharArray(); 86 CharOperation.replace(this.genericSignature, '.', '/'); 87 } 88 return this.genericSignature; 89 } 90 97 public char[][] getInterfaceNames() { 98 return this.superInterfaces; 99 } 100 106 public IBinaryNestedType[] getMemberTypes() { 107 return null; 108 } 109 112 public IBinaryMethod[] getMethods() { 113 return null; 114 } 115 119 public int getModifiers() { 120 return this.modifiers; 121 } 122 128 public char[] getName() { 129 return this.name; 130 } 131 132 public char[] getSourceName() { 133 return this.sourceName; 134 } 135 136 143 public char[] getSuperclassName() { 144 return this.superclass; 145 } 146 public boolean isAnonymous() { 147 return false; } 149 150 154 public boolean isBinaryType() { 155 return true; 156 } 157 public boolean isLocal() { 158 return false; } 160 public boolean isMember() { 161 return false; } 163 164 public void recordSuperType(char[] superTypeName, char[] superQualification, char superClassOrInterface){ 165 166 if (superQualification != null){ 168 int length = superQualification.length; 169 if (superQualification[length-1] == '$'){ 170 char[] enclosingSuperName = CharOperation.lastSegment(superQualification, '.'); 171 superTypeName = CharOperation.concat(enclosingSuperName, superTypeName); 172 superQualification = CharOperation.subarray(superQualification, 0, length - enclosingSuperName.length - 1); 173 } 174 } 175 176 if (superClassOrInterface == IIndexConstants.CLASS_SUFFIX){ 177 if (TypeDeclaration.kind(this.modifiers) == TypeDeclaration.INTERFACE_DECL) return; 180 char[] encodedName = CharOperation.concat(superQualification, superTypeName, '/'); 181 CharOperation.replace(encodedName, '.', '/'); 182 this.superclass = encodedName; 183 } else { 184 char[] encodedName = CharOperation.concat(superQualification, superTypeName, '/'); 185 CharOperation.replace(encodedName, '.', '/'); 186 if (this.superInterfaces == NoInterface){ 187 this.superInterfaces = new char[][] { encodedName }; 188 } else { 189 int length = this.superInterfaces.length; 190 System.arraycopy(this.superInterfaces, 0, this.superInterfaces = new char[length+1][], 0, length); 191 this.superInterfaces[length] = encodedName; 192 } 193 } 194 } 195 public String toString() { 196 StringBuffer buffer = new StringBuffer (); 197 if (this.modifiers == ClassFileConstants.AccPublic) { 198 buffer.append("public "); } 200 switch (TypeDeclaration.kind(this.modifiers)) { 201 case TypeDeclaration.CLASS_DECL : 202 buffer.append("class "); break; 204 case TypeDeclaration.INTERFACE_DECL : 205 buffer.append("interface "); break; 207 case TypeDeclaration.ENUM_DECL : 208 buffer.append("enum "); break; 210 } 211 if (this.name != null) { 212 buffer.append(this.name); 213 } 214 if (this.superclass != null) { 215 buffer.append("\n extends "); buffer.append(this.superclass); 217 } 218 int length; 219 if (this.superInterfaces != null && (length = this.superInterfaces.length) != 0) { 220 buffer.append("\n implements "); for (int i = 0; i < length; i++) { 222 buffer.append(this.superInterfaces[i]); 223 if (i != length - 1) { 224 buffer.append(", "); } 226 } 227 } 228 return buffer.toString(); 229 } 230 231 234 public IBinaryAnnotation[] getAnnotations() { 235 return null; 236 } 237 238 241 public char[] sourceFileName() { 242 return null; 243 } 244 public long getTagBits() { 246 return 0; 247 } 248 } 249 | Popular Tags |