1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
13 import net.sourceforge.phpdt.core.IJavaElement;
14 import net.sourceforge.phpdt.core.IType;
15 import net.sourceforge.phpdt.core.JavaModelException;
16 import net.sourceforge.phpdt.internal.compiler.env.IConstants;
17 import net.sourceforge.phpdt.internal.compiler.env.ISourceField;
18 import net.sourceforge.phpdt.internal.compiler.env.ISourceMethod;
19 import net.sourceforge.phpdt.internal.compiler.env.ISourceType;
22 * Element info for an IType element that originated from source.
24 public class SourceTypeElementInfo extends MemberElementInfo implements
26 protected static final ISourceField[] NO_FIELDS = new ISourceField[0];
28 protected static final ISourceMethod[] NO_METHODS = new ISourceMethod[0];
30 protected static final ISourceType[] NO_TYPES = new ISourceType[0];
33 * The name of the superclass for this type. This name is fully qualified
34 * for binary types and is NOT fully qualified for source types.
36 protected char[] fSuperclassName;
39 * The names of the interfaces this type implements or extends. These names
40 * are fully qualified in the case of a binary type, and are NOT fully
41 * qualified in the case of a source type
43 protected char[][] fSuperInterfaceNames;
46 * The enclosing type name for this type.
48 * @see getEnclosingTypeName
50 protected char[] fEnclosingTypeName = null;
53 * The name of the source file this type is declared in.
55 protected char[] fSourceFileName = null;
58 * The name of the package this type is contained in.
60 protected char[] fPackageName = null;
63 * The qualified name of this type.
65 protected char[] fQualifiedName = null;
68 * The imports in this type's compilation unit
70 protected char[][] fImports = null;
73 * Backpointer to my type handle - useful for translation from info to
76 protected IType fHandle = null;
79 * Adds the given import to this type's collection of imports
81 protected void addImport(char[] i) {
82 if (fImports == null) {
83 fImports = new char[][] { i };
85 char[][] copy = new char[fImports.length + 1][];
86 System.arraycopy(fImports, 0, copy, 0, fImports.length);
87 copy[fImports.length] = i;
93 * Returns the ISourceType that is the enclosing type for this type, or
94 * <code>null</code> if this type is a top level type.
96 public ISourceType getEnclosingType() {
97 IJavaElement parent = fHandle.getParent();
98 if (parent != null && parent.getElementType() == IJavaElement.TYPE) {
100 return (ISourceType) ((JavaElement) parent).getElementInfo();
101 } catch (JavaModelException e) {
112 public char[] getEnclosingTypeName() {
113 return fEnclosingTypeName;
119 public ISourceField[] getFields() {
120 int length = fChildren.length;
123 ISourceField[] fields = new ISourceField[length];
125 for (int i = 0; i < length; i++) {
126 IJavaElement child = fChildren[i];
127 if (child instanceof SourceField) {
129 ISourceField field = (ISourceField) ((SourceField) child)
131 fields[fieldIndex++] = field;
132 } catch (JavaModelException e) {
138 System.arraycopy(fields, 0, fields = new ISourceField[fieldIndex], 0,
146 public char[] getFileName() {
147 return fSourceFileName;
151 * Returns the handle for this type info
153 public IType getHandle() {
160 public char[][] getImports() {
167 public char[][] getInterfaceNames() {
168 return fSuperInterfaceNames;
174 public ISourceType[] getMemberTypes() {
175 int length = fChildren.length;
178 ISourceType[] memberTypes = new ISourceType[length];
180 for (int i = 0; i < length; i++) {
181 IJavaElement child = fChildren[i];
182 if (child instanceof SourceType) {
184 ISourceType type = (ISourceType) ((SourceType) child)
186 memberTypes[typeIndex++] = type;
187 } catch (JavaModelException e) {
193 System.arraycopy(memberTypes, 0,
194 memberTypes = new ISourceType[typeIndex], 0, typeIndex);
201 public ISourceMethod[] getMethods() {
202 int length = fChildren.length;
205 ISourceMethod[] methods = new ISourceMethod[length];
207 for (int i = 0; i < length; i++) {
208 IJavaElement child = fChildren[i];
209 if (child instanceof SourceMethod) {
211 ISourceMethod method = (ISourceMethod) ((SourceMethod) child)
213 methods[methodIndex++] = method;
214 } catch (JavaModelException e) {
218 if (methodIndex == 0)
220 System.arraycopy(methods, 0, methods = new ISourceMethod[methodIndex],
228 public char[] getPackageName() {
235 public char[] getQualifiedName() {
236 return fQualifiedName;
242 public char[] getSuperclassName() {
243 return fSuperclassName;
249 public boolean isBinaryType() {
256 public boolean isClass() {
257 return (this.flags & IConstants.AccInterface) == 0;
263 public boolean isInterface() {
264 return (this.flags & IConstants.AccInterface) != 0;
268 * Sets the (unqualified) name of the type that encloses this type.
270 protected void setEnclosingTypeName(char[] enclosingTypeName) {
271 fEnclosingTypeName = enclosingTypeName;
275 * Sets the handle for this type info
277 protected void setHandle(IType handle) {
282 * Sets the name of the package this type is declared in.
284 protected void setPackageName(char[] name) {
289 * Sets this type's qualified name.
291 protected void setQualifiedName(char[] name) {
292 fQualifiedName = name;
296 * Sets the name of the source file this type is declared in.
298 protected void setSourceFileName(char[] name) {
299 fSourceFileName = name;
303 * Sets the (unqualified) name of this type's superclass
305 protected void setSuperclassName(char[] superclassName) {
306 fSuperclassName = superclassName;
310 * Sets the (unqualified) names of the interfaces this type implements or
313 protected void setSuperInterfaceNames(char[][] superInterfaceNames) {
314 fSuperInterfaceNames = superInterfaceNames;
317 public String toString() {
318 return "Info for " + fHandle.toString(); //$NON-NLS-1$