new version with WorkingCopy Management
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / SourceTypeElementInfo.java
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
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
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;
20
21
22 /** 
23  * Element info for an IType element that originated from source. 
24  */
25 public class SourceTypeElementInfo extends MemberElementInfo implements ISourceType {
26         protected static final ISourceField[] NO_FIELDS = new ISourceField[0];
27         protected static final ISourceMethod[] NO_METHODS = new ISourceMethod[0];
28         protected static final ISourceType[] NO_TYPES = new ISourceType[0];
29         /**
30          * The name of the superclass for this type. This name
31          * is fully qualified for binary types and is NOT
32          * fully qualified for source types.
33          */
34         protected char[] fSuperclassName;
35         
36         /**
37          * The names of the interfaces this type implements or
38          * extends. These names are fully qualified in the case
39          * of a binary type, and are NOT fully qualified in the
40          * case of a source type
41          */
42         protected char[][] fSuperInterfaceNames;
43         
44         /**
45          * The enclosing type name for this type.
46          *
47          * @see getEnclosingTypeName
48          */
49         protected char[] fEnclosingTypeName = null;
50
51         /**
52          * The name of the source file this type is declared in.
53          */
54         protected char[] fSourceFileName= null;
55
56         /**
57          * The name of the package this type is contained in.
58          */
59         protected char[] fPackageName= null;
60
61         /**
62          * The qualified name of this type.
63          */
64         protected char[] fQualifiedName= null;
65
66
67
68
69
70
71
72         /**
73          * The imports in this type's compilation unit
74          */
75         protected char[][] fImports= null;
76
77         /**
78          * Backpointer to my type handle - useful for translation
79          * from info to handle.
80          */
81         protected IType fHandle= null;
82          
83
84
85
86
87
88
89
90
91 /**
92  * Adds the given import to this type's collection of imports
93  */
94 protected void addImport(char[] i) {
95         if (fImports == null) {
96                 fImports = new char[][] {i};
97         } else {
98                 char[][] copy = new char[fImports.length + 1][];
99                 System.arraycopy(fImports, 0, copy, 0, fImports.length);
100                 copy[fImports.length] = i;
101                 fImports = copy;
102         }
103 }
104
105
106 /**
107  * Returns the ISourceType that is the enclosing type for this
108  * type, or <code>null</code> if this type is a top level type.
109  */
110 public ISourceType getEnclosingType() {
111         IJavaElement parent= fHandle.getParent();
112         if (parent != null && parent.getElementType() == IJavaElement.TYPE) {
113                 try {
114                         return (ISourceType)((JavaElement)parent).getElementInfo();
115                 } catch (JavaModelException e) {
116                         return null;
117                 }
118         } else {
119                 return null;
120         }
121 }
122 /**
123  * @see ISourceType
124  */
125 public char[] getEnclosingTypeName() {
126         return fEnclosingTypeName;
127 }
128 /**
129  * @see ISourceType
130  */
131 public ISourceField[] getFields() {
132         int length = fChildren.length;
133         if (length == 0) return NO_FIELDS;
134         ISourceField[] fields = new ISourceField[length];
135         int fieldIndex = 0;
136         for (int i = 0; i < length; i++) {
137                 IJavaElement child = fChildren[i];
138                 if (child instanceof SourceField) {
139                         try {
140                                 ISourceField field = (ISourceField)((SourceField)child).getElementInfo();
141                                 fields[fieldIndex++] = field;
142                         } catch (JavaModelException e) {
143                         }
144                 }
145         }
146         if (fieldIndex == 0) return NO_FIELDS;
147         System.arraycopy(fields, 0, fields = new ISourceField[fieldIndex], 0, fieldIndex);
148         return fields;
149 }
150 /**
151  * @see ISourceType
152  */
153 public char[] getFileName() {
154         return fSourceFileName;
155 }
156 /**
157  * Returns the handle for this type info
158  */
159 public IType getHandle() {
160         return fHandle;
161 }
162 /**
163  * @see ISourceType
164  */
165 public char[][] getImports() {
166         return fImports;
167 }
168 /**
169  * @see ISourceType
170  */
171 public char[][] getInterfaceNames() {
172         return fSuperInterfaceNames;
173 }
174 /**
175  * @see ISourceType
176  */
177 public ISourceType[] getMemberTypes() {
178         int length = fChildren.length;
179         if (length == 0) return NO_TYPES;
180         ISourceType[] memberTypes = new ISourceType[length];
181         int typeIndex = 0;
182         for (int i = 0; i < length; i++) {
183                 IJavaElement child = fChildren[i];
184                 if (child instanceof SourceType) {
185                         try {
186                                 ISourceType type = (ISourceType)((SourceType)child).getElementInfo();
187                                 memberTypes[typeIndex++] = type;
188                         } catch (JavaModelException e) {
189                         }
190                 }
191         }
192         if (typeIndex == 0) return NO_TYPES;
193         System.arraycopy(memberTypes, 0, memberTypes = new ISourceType[typeIndex], 0, typeIndex);
194         return memberTypes;
195 }
196 /**
197  * @see ISourceType
198  */
199 public ISourceMethod[] getMethods() {
200         int length = fChildren.length;
201         if (length == 0) return NO_METHODS;
202         ISourceMethod[] methods = new ISourceMethod[length];
203         int methodIndex = 0;
204         for (int i = 0; i < length; i++) {
205                 IJavaElement child = fChildren[i];
206                 if (child instanceof SourceMethod) {
207                         try {
208                                 ISourceMethod method = (ISourceMethod)((SourceMethod)child).getElementInfo();
209                                 methods[methodIndex++] = method;
210                         } catch (JavaModelException e) {
211                         }
212                 }
213         }
214         if (methodIndex == 0) return NO_METHODS;
215         System.arraycopy(methods, 0, methods = new ISourceMethod[methodIndex], 0, methodIndex);
216         return methods;
217 }
218 /**
219  * @see ISourceType
220  */
221 public char[] getPackageName() {
222         return fPackageName;
223 }
224 /**
225  * @see ISourceType
226  */
227 public char[] getQualifiedName() {
228         return fQualifiedName;
229 }
230 /**
231  * @see ISourceType
232  */
233 public char[] getSuperclassName() {
234         return fSuperclassName;
235 }
236 /**
237  * @see ISourceType
238  */
239 public boolean isBinaryType() {
240         return false;
241 }
242 /**
243  * @see ISourceType
244  */
245 public boolean isClass() {
246         return (this.flags & IConstants.AccInterface) == 0;
247 }
248 /**
249  * @see ISourceType
250  */
251 public boolean isInterface() {
252         return (this.flags & IConstants.AccInterface) != 0;
253 }
254 /**
255  * Sets the (unqualified) name of the type that encloses this type.
256  */
257 protected void setEnclosingTypeName(char[] enclosingTypeName) {
258         fEnclosingTypeName = enclosingTypeName;
259 }
260 /**
261  * Sets the handle for this type info
262  */
263 protected void setHandle(IType handle) {
264         fHandle= handle;
265 }
266 /**
267  * Sets the name of the package this type is declared in.
268  */
269 protected void setPackageName(char[] name) {
270         fPackageName= name;
271 }
272 /**
273  * Sets this type's qualified name.
274  */
275 protected void setQualifiedName(char[] name) {
276         fQualifiedName= name;
277 }
278 /**
279  * Sets the name of the source file this type is declared in.
280  */
281 protected void setSourceFileName(char[] name) {
282         fSourceFileName= name;
283 }
284 /**
285  * Sets the (unqualified) name of this type's superclass
286  */
287 protected void setSuperclassName(char[] superclassName) {
288         fSuperclassName = superclassName;
289 }
290 /**
291  * Sets the (unqualified) names of the interfaces this type implements or extends
292  */
293 protected void setSuperInterfaceNames(char[][] superInterfaceNames) {
294         fSuperInterfaceNames = superInterfaceNames;
295 }
296 public String toString() {
297         return "Info for " + fHandle.toString(); //$NON-NLS-1$
298 }
299 }