1 11 package org.eclipse.jdt.internal.core; 12 13 import java.util.HashMap ; 14 15 import org.eclipse.jdt.core.*; 16 import org.eclipse.jdt.core.compiler.CharOperation; 17 import org.eclipse.jdt.internal.compiler.env.ISourceField; 18 import org.eclipse.jdt.internal.compiler.env.ISourceImport; 19 import org.eclipse.jdt.internal.compiler.env.ISourceMethod; 20 import org.eclipse.jdt.internal.compiler.env.ISourceType; 21 22 25 public class SourceTypeElementInfo extends MemberElementInfo implements ISourceType { 26 27 protected static final ISourceImport[] NO_IMPORTS = new ISourceImport[0]; 28 protected static final InitializerElementInfo[] NO_INITIALIZERS = new InitializerElementInfo[0]; 29 protected static final SourceField[] NO_FIELDS = new SourceField[0]; 30 protected static final SourceMethod[] NO_METHODS = new SourceMethod[0]; 31 protected static final SourceType[] NO_TYPES = new SourceType[0]; 32 37 protected char[] superclassName; 38 39 45 protected char[][] superInterfaceNames; 46 47 51 protected IType handle = null; 52 53 56 protected ITypeParameter[] typeParameters = TypeParameter.NO_TYPE_PARAMETERS; 57 58 61 protected HashMap categories; 62 63 protected void addCategories(IJavaElement element, char[][] elementCategories) { 64 if (elementCategories == null) return; 65 if (this.categories == null) 66 this.categories = new HashMap (); 67 this.categories.put(element, CharOperation.toStrings(elementCategories)); 68 } 69 70 73 public HashMap getCategories() { 74 return this.categories; 75 } 76 77 81 public ISourceType getEnclosingType() { 82 IJavaElement parent= this.handle.getParent(); 83 if (parent != null && parent.getElementType() == IJavaElement.TYPE) { 84 try { 85 return (ISourceType)((JavaElement)parent).getElementInfo(); 86 } catch (JavaModelException e) { 87 return null; 88 } 89 } else { 90 return null; 91 } 92 } 93 96 public ISourceField[] getFields() { 97 SourceField[] fieldHandles = getFieldHandles(); 98 int length = fieldHandles.length; 99 ISourceField[] fields = new ISourceField[length]; 100 for (int i = 0; i < length; i++) { 101 try { 102 ISourceField field = (ISourceField) fieldHandles[i].getElementInfo(); 103 fields[i] = field; 104 } catch (JavaModelException e) { 105 } 107 } 108 return fields; 109 } 110 public SourceField[] getFieldHandles() { 111 int length = this.children.length; 112 if (length == 0) return NO_FIELDS; 113 SourceField[] fields = new SourceField[length]; 114 int fieldIndex = 0; 115 for (int i = 0; i < length; i++) { 116 IJavaElement child = this.children[i]; 117 if (child instanceof SourceField) 118 fields[fieldIndex++] = (SourceField) child; 119 } 120 if (fieldIndex == 0) return NO_FIELDS; 121 if (fieldIndex < length) 122 System.arraycopy(fields, 0, fields = new SourceField[fieldIndex], 0, fieldIndex); 123 return fields; 124 } 125 128 public char[] getFileName() { 129 return this.handle.getPath().toString().toCharArray(); 130 } 131 134 public IType getHandle() { 135 return this.handle; 136 } 137 141 public InitializerElementInfo[] getInitializers() { 142 int length = this.children.length; 143 if (length == 0) return NO_INITIALIZERS; 144 InitializerElementInfo[] initializers = new InitializerElementInfo[length]; 145 int initializerIndex = 0; 146 for (int i = 0; i < length; i++) { 147 IJavaElement child = this.children[i]; 148 if (child instanceof Initializer) { 149 try { 150 InitializerElementInfo initializer = (InitializerElementInfo)((Initializer)child).getElementInfo(); 151 initializers[initializerIndex++] = initializer; 152 } catch (JavaModelException e) { 153 } 155 } 156 } 157 if (initializerIndex == 0) return NO_INITIALIZERS; 158 System.arraycopy(initializers, 0, initializers = new InitializerElementInfo[initializerIndex], 0, initializerIndex); 159 return initializers; 160 } 161 164 public char[][] getInterfaceNames() { 165 if (this.handle.getElementName().length() == 0) { return null; 167 } 168 return this.superInterfaceNames; 169 } 170 171 174 public ISourceType[] getMemberTypes() { 175 SourceType[] memberTypeHandles = getMemberTypeHandles(); 176 int length = memberTypeHandles.length; 177 ISourceType[] memberTypes = new ISourceType[length]; 178 for (int i = 0; i < length; i++) { 179 try { 180 ISourceType type = (ISourceType) memberTypeHandles[i].getElementInfo(); 181 memberTypes[i] = type; 182 } catch (JavaModelException e) { 183 } 185 } 186 return memberTypes; 187 } 188 public SourceType[] getMemberTypeHandles() { 189 int length = this.children.length; 190 if (length == 0) return NO_TYPES; 191 SourceType[] memberTypes = new SourceType[length]; 192 int typeIndex = 0; 193 for (int i = 0; i < length; i++) { 194 IJavaElement child = this.children[i]; 195 if (child instanceof SourceType) 196 memberTypes[typeIndex++] = (SourceType)child; 197 } 198 if (typeIndex == 0) return NO_TYPES; 199 if (typeIndex < length) 200 System.arraycopy(memberTypes, 0, memberTypes = new SourceType[typeIndex], 0, typeIndex); 201 return memberTypes; 202 } 203 206 public ISourceMethod[] getMethods() { 207 SourceMethod[] methodHandles = getMethodHandles(); 208 int length = methodHandles.length; 209 ISourceMethod[] methods = new ISourceMethod[length]; 210 int methodIndex = 0; 211 for (int i = 0; i < length; i++) { 212 try { 213 ISourceMethod method = (ISourceMethod) methodHandles[i].getElementInfo(); 214 methods[methodIndex++] = method; 215 } catch (JavaModelException e) { 216 } 218 } 219 return methods; 220 } 221 public SourceMethod[] getMethodHandles() { 222 int length = this.children.length; 223 if (length == 0) return NO_METHODS; 224 SourceMethod[] methods = new SourceMethod[length]; 225 int methodIndex = 0; 226 for (int i = 0; i < length; i++) { 227 IJavaElement child = this.children[i]; 228 if (child instanceof SourceMethod) 229 methods[methodIndex++] = (SourceMethod) child; 230 } 231 if (methodIndex == 0) return NO_METHODS; 232 if (methodIndex < length) 233 System.arraycopy(methods, 0, methods = new SourceMethod[methodIndex], 0, methodIndex); 234 return methods; 235 } 236 239 public char[] getName() { 240 return this.handle.getElementName().toCharArray(); 241 } 242 245 public char[] getSuperclassName() { 246 if (this.handle.getElementName().length() == 0) { char[][] interfaceNames = this.superInterfaceNames; 248 if (interfaceNames != null && interfaceNames.length > 0) { 249 return interfaceNames[0]; 250 } 251 } 252 return this.superclassName; 253 } 254 public char[][][] getTypeParameterBounds() { 255 int length = this.typeParameters.length; 256 char[][][] typeParameterBounds = new char[length][][]; 257 for (int i = 0; i < length; i++) { 258 try { 259 TypeParameterElementInfo info = (TypeParameterElementInfo) ((JavaElement)this.typeParameters[i]).getElementInfo(); 260 typeParameterBounds[i] = info.bounds; 261 } catch (JavaModelException e) { 262 } 264 } 265 return typeParameterBounds; 266 } 267 public char[][] getTypeParameterNames() { 268 int length = this.typeParameters.length; 269 if (length == 0) return CharOperation.NO_CHAR_CHAR; 270 char[][] typeParameterNames = new char[length][]; 271 for (int i = 0; i < length; i++) { 272 typeParameterNames[i] = this.typeParameters[i].getElementName().toCharArray(); 273 } 274 return typeParameterNames; 275 } 276 279 public boolean isBinaryType() { 280 return false; 281 } 282 285 public boolean isAnonymousMember() { 286 return false; 287 } 288 291 protected void setHandle(IType handle) { 292 this.handle = handle; 293 } 294 297 protected void setSuperclassName(char[] superclassName) { 298 this.superclassName = superclassName; 299 } 300 303 protected void setSuperInterfaceNames(char[][] superInterfaceNames) { 304 this.superInterfaceNames = superInterfaceNames; 305 } 306 public String toString() { 307 return "Info for " + this.handle.toString(); } 309 } 310 | Popular Tags |