improved PHP parser
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / core / IType.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.core;
12
13 import org.eclipse.core.runtime.IProgressMonitor;
14 import net.sourceforge.phpdt.core.ITypeHierarchy;
15 import net.sourceforge.phpdt.core.JavaModelException;
16 import net.sourceforge.phpdt.core.WorkingCopyOwner;
17
18
19 /**
20  * Represents either a source type in a compilation unit (either a top-level
21  * type or a member type) or a binary type in a class file.
22  * <p>
23  * If a binary type cannot be parsed, its structure remains unknown.
24  * Use <code>IJavaElement.isStructureKnown</code> to determine whether this
25  * is the case.
26  * </p>
27  * <p>
28  * The children are of type <code>IMember</code>, which includes <code>IField</code>,
29  * <code>IMethod</code>, <code>IInitializer</code> and <code>IType</code>.
30  * The children are listed in the order in which they appear in the source or class file.
31  * </p>
32  * <p>
33  * This interface is not intended to be implemented by clients.
34  * </p>
35  */
36 public interface IType extends IMember, IParent {
37         /**
38          * Do code completion inside a code snippet in the context of the current type.
39          * 
40          * If the type can access to his source code and the insertion position is valid,
41          * then completion is performed against source. Otherwise the completion is performed
42          * against type structure and given locals variables.
43          * 
44          * @param snippet the code snippet
45          * @param insertion the position with in source where the snippet
46          * is inserted. This position must not be in comments.
47          * A possible value is -1, if the position is not known.
48          * @param position the position with in snippet where the user 
49          * is performing code assist.
50          * @param localVariableTypesNames an array (possibly empty) of fully qualified 
51          * type names of local variables visible at the current scope
52          * @param localVariableNames an array (possibly empty) of local variable names 
53          * that are visible at the current scope
54          * @param localVariableModifiers an array (possible empty) of modifiers for 
55          * local variables
56          * @param isStatic whether the current scope is in a static context
57          * @param requestor the completion requestor
58          * @since 2.0
59          */
60 //      void codeComplete(
61 //              char[] snippet,
62 //              int insertion,
63 //              int position,
64 //              char[][] localVariableTypeNames,
65 //              char[][] localVariableNames,
66 //              int[] localVariableModifiers,
67 //              boolean isStatic,
68 //              ICompletionRequestor requestor)
69 //              throws JavaModelException;
70
71         /**
72          * Creates and returns a field in this type with the
73          * given contents.
74          * <p>
75          * Optionally, the new element can be positioned before the specified
76          * sibling. If no sibling is specified, the element will be inserted
77          * as the last field declaration in this type.</p>
78          *
79          * <p>It is possible that a field with the same name already exists in this type.
80          * The value of the <code>force</code> parameter effects the resolution of
81          * such a conflict:<ul>
82          * <li> <code>true</code> - in this case the field is created with the new contents</li>
83          * <li> <code>false</code> - in this case a <code>JavaModelException</code> is thrown</li>
84          * </ul></p>
85          *
86          * @param contents the given contents
87          * @param sibling the given sibling
88          * @param force a flag in case the same name already exists in this type
89          * @param monitor the given progress monitor
90          * @exception JavaModelException if the element could not be created. Reasons include:
91          * <ul>
92          * <li> This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
93          * <li> A <code>CoreException</code> occurred while updating an underlying resource
94          * <li> The specified sibling is not a child of this type (INVALID_SIBLING)
95          * <li> The contents could not be recognized as a field declaration (INVALID_CONTENTS)
96          * <li> This type is read-only (binary) (READ_ONLY)
97          * <li> There was a naming collision with an existing field (NAME_COLLISION)
98          * </ul>
99          * @return a field in this type with the given contents
100          */
101 //      IField createField(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor)
102 //              throws JavaModelException;
103                 
104         /**
105          * Creates and returns a static initializer in this type with the
106          * given contents.
107          * <p>
108          * Optionally, the new element can be positioned before the specified
109          * sibling. If no sibling is specified, the new initializer is positioned
110          * after the last existing initializer declaration, or as the first member
111          * in the type if there are no initializers.</p>
112          *
113          * @param contents the given contents
114          * @param sibling the given sibling
115          * @param monitor the given progress monitor
116          * @exception JavaModelException if the element could not be created. Reasons include:
117          * <ul>
118          * <li> This element does not exist
119          * <li> A <code>CoreException</code> occurred while updating an underlying resource
120          * <li> The specified sibling is not a child of this type (INVALID_SIBLING)
121          * <li> The contents could not be recognized as an initializer declaration (INVALID_CONTENTS)
122          * <li> This type is read-only (binary) (READ_ONLY)
123          * </ul>
124          * @return a static initializer in this type with the given contents
125          */
126 //      IInitializer createInitializer(String contents, IJavaElement sibling, IProgressMonitor monitor)
127 //              throws JavaModelException;
128                 
129         /**
130          * Creates and returns a method or constructor in this type with the
131          * given contents.
132          * <p>
133          * Optionally, the new element can be positioned before the specified
134          * sibling. If no sibling is specified, the element will be appended
135          * to this type.
136          *
137          * <p>It is possible that a method with the same signature already exists in this type.
138          * The value of the <code>force</code> parameter effects the resolution of
139          * such a conflict:<ul>
140          * <li> <code>true</code> - in this case the method is created with the new contents</li>
141          * <li> <code>false</code> - in this case a <code>JavaModelException</code> is thrown</li>
142          * </ul></p>
143          *
144          * @param contents the given contents
145          * @param sibling the given sibling
146          * @param force a flag in case the same name already exists in this type
147          * @param monitor the given progress monitor
148          * @exception JavaModelException if the element could not be created. Reasons include:
149          * <ul>
150          * <li> This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
151          * <li> A <code>CoreException</code> occurred while updating an underlying resource
152          * <li> The specified sibling is not a child of this type (INVALID_SIBLING)
153          * <li> The contents could not be recognized as a method or constructor
154          *              declaration (INVALID_CONTENTS)
155          * <li> This type is read-only (binary) (READ_ONLY)
156          * <li> There was a naming collision with an existing method (NAME_COLLISION)
157          * </ul>
158          * @return a method or constructor in this type with the given contents
159          */
160 //      IMethod createMethod(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor)
161 //              throws JavaModelException;
162                 
163         /**
164          * Creates and returns a type in this type with the
165          * given contents.
166          * <p>
167          * Optionally, the new type can be positioned before the specified
168          * sibling. If no sibling is specified, the type will be appended
169          * to this type.
170          *
171          * <p>It is possible that a type with the same name already exists in this type.
172          * The value of the <code>force</code> parameter effects the resolution of
173          * such a conflict:<ul>
174          * <li> <code>true</code> - in this case the type is created with the new contents</li>
175          * <li> <code>false</code> - in this case a <code>JavaModelException</code> is thrown</li>
176          * </ul></p>
177          *
178          * @param contents the given contents
179          * @param sibling the given sibling
180          * @param force a flag in case the same name already exists in this type
181          * @param monitor the given progress monitor
182          * @exception JavaModelException if the element could not be created. Reasons include:
183          * <ul>
184          * <li> This Java element does not exist (ELEMENT_DOES_NOT_EXIST)</li>
185          * <li> A <code>CoreException</code> occurred while updating an underlying resource
186          * <li> The specified sibling is not a child of this type (INVALID_SIBLING)
187          * <li> The contents could not be recognized as a type declaration (INVALID_CONTENTS)
188          * <li> This type is read-only (binary) (READ_ONLY)
189          * <li> There was a naming collision with an existing field (NAME_COLLISION)
190          * </ul>
191          * @return a type in this type with the given contents
192          */
193 //      IType createType(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor)
194 //              throws JavaModelException;
195                 
196         /** 
197          * Finds the methods in this type that correspond to
198          * the given method.
199          * A method m1 corresponds to another method m2 if:
200          * <ul>
201          * <li>m1 has the same element name as m2.
202          * <li>m1 has the same number of arguments as m2 and
203          *     the simple names of the argument types must be equals.
204          * <li>m1 exists.
205          * </ul>
206          * @param method the given method
207          * @return the found method or <code>null</code> if no such methods can be found.
208          * 
209          * @since 2.0 
210          */
211         IMethod[] findMethods(IMethod method);
212         
213         /**
214          * Returns the simple name of this type, unqualified by package or enclosing type.
215          * This is a handle-only method.
216          * 
217          * @return the simple name of this type
218          */
219         String getElementName();
220         
221         /**
222          * Returns the field with the specified name
223          * in this type (for example, <code>"bar"</code>).
224          * This is a handle-only method.  The field may or may not exist.
225          * 
226          * @param name the given name
227          * @return the field with the specified name in this type
228          */
229         IField getField(String name);
230         
231         /**
232          * Returns the fields declared by this type.
233          * If this is a source type, the results are listed in the order
234          * in which they appear in the source, otherwise, the results are
235          * in no particular order.  For binary types, this includes synthetic fields.
236          *
237          * @exception JavaModelException if this element does not exist or if an
238          *              exception occurs while accessing its corresponding resource.
239          * @return the fields declared by this type
240          */
241         IField[] getFields() throws JavaModelException;
242         
243         /**
244          * Returns the fully qualified name of this type, 
245          * including qualification for any containing types and packages.
246          * This is the name of the package, followed by <code>'.'</code>,
247          * followed by the type-qualified name.
248          * This is a handle-only method.
249          *
250          * @see IType#getTypeQualifiedName()
251          * @return the fully qualified name of this type
252          */
253         String getFullyQualifiedName();
254         
255         /**
256          * Returns the fully qualified name of this type, 
257          * including qualification for any containing types and packages.
258          * This is the name of the package, followed by <code>'.'</code>,
259          * followed by the type-qualified name using the <code>enclosingTypeSeparator</code>.
260          * 
261          * For example:
262          * <ul>
263          * <li>the fully qualified name of a class B defined as a member of a class A in a compilation unit A.java 
264          *     in a package x.y using the '.' separator is "x.y.A.B"</li>
265          * <li>the fully qualified name of a class B defined as a member of a class A in a compilation unit A.java 
266          *     in a package x.y using the '$' separator is "x.y.A$B"</li>
267          * <li>the fully qualified name of a binary type whose class file is x/y/A$B.class
268          *     using the '.' separator is "x.y.A.B"</li>
269          * <li>the fully qualified name of a binary type whose class file is x/y/A$B.class
270          *     using the '$' separator is "x.y.A$B"</li>
271          * <li>the fully qualified name of an anonymous binary type whose class file is x/y/A$1.class
272          *     using the '.' separator is "x.y.A$1"</li>
273          * </ul>
274          * 
275          * This is a handle-only method.
276          *
277          * @param enclosingTypeSeparator the given enclosing type separator
278          * @return the fully qualified name of this type, including qualification for any containing types and packages
279          * @see IType#getTypeQualifiedName(char)
280          * @since 2.0
281          */
282         String getFullyQualifiedName(char enclosingTypeSeparator);
283         
284         /**
285          * Returns the initializer with the specified position relative to
286          * the order they are defined in the source.
287          * Numbering starts at 1 (thus the first occurrence is occurrence 1, not occurrence 0).
288          * This is a handle-only method.  The initializer may or may not be present.
289          * 
290          * @param occurrenceCount the specified position
291          * @return the initializer with the specified position relative to the order they are defined in the source
292          */
293 //      IInitializer getInitializer(int occurrenceCount);
294         
295         /**
296          * Returns the initializers declared by this type.
297          * For binary types this is an empty collection.
298          * If this is a source type, the results are listed in the order
299          * in which they appear in the source.
300          *
301          * @exception JavaModelException if this element does not exist or if an
302          *              exception occurs while accessing its corresponding resource.
303          * @return the initializers declared by this type
304          */
305 //      IInitializer[] getInitializers() throws JavaModelException;
306         
307         /**
308          * Returns the method with the specified name and parameter types
309          * in this type (for example, <code>"foo", {"I", "QString;"}</code>). To get the
310          * handle for a constructor, the name specified must be the simple
311          * name of the enclosing type.
312          * This is a handle-only method.  The method may or may not be present.
313          * 
314          * @param name the given name
315          * @param parameterTypeSignatures the given parameter types
316          * @return the method with the specified name and parameter types in this type
317          */
318         IMethod getMethod(String name, String[] parameterTypeSignatures);
319         
320         /**
321          * Returns the methods and constructors declared by this type.
322          * For binary types, this may include the special <code>&lt;clinit&gt</code>; method 
323          * and synthetic methods.
324          * If this is a source type, the results are listed in the order
325          * in which they appear in the source, otherwise, the results are
326          * in no particular order.
327          *
328          * @exception JavaModelException if this element does not exist or if an
329          *              exception occurs while accessing its corresponding resource.
330          * @return the methods and constructors declared by this type
331          */
332         IMethod[] getMethods() throws JavaModelException;
333         
334         /**
335          * Returns the package fragment in which this element is defined.
336          * This is a handle-only method.
337          * 
338          * @return the package fragment in which this element is defined
339          */
340         IPackageFragment getPackageFragment();
341         
342         /**
343          * Returns the name of this type's superclass, or <code>null</code>
344          * for source types that do not specify a superclass.
345          * For interfaces, the superclass name is always <code>"java.lang.Object"</code>.
346          * For source types, the name as declared is returned, for binary types,
347          * the resolved, qualified name is returned.
348          *
349          * @exception JavaModelException if this element does not exist or if an
350          *              exception occurs while accessing its corresponding resource.
351          * @return the name of this type's superclass, or <code>null</code> for source types that do not specify a superclass
352          */
353         String getSuperclassName() throws JavaModelException;
354         
355         /**
356          * Returns the names of interfaces that this type implements or extends,
357          * in the order in which they are listed in the source.
358          * For classes, this gives the interfaces that this class implements.
359          * For interfaces, this gives the interfaces that this interface extends.
360          * An empty collection is returned if this type does not implement or
361          * extend any interfaces. For source types, simple names are returned,
362          * for binary types, qualified names are returned.
363          *
364          * @exception JavaModelException if this element does not exist or if an
365          *              exception occurs while accessing its corresponding resource.
366          * @return  the names of interfaces that this type implements or extends, in the order in which they are listed in the source, 
367          * an empty collection if none
368          */
369         String[] getSuperInterfaceNames() throws JavaModelException;
370         
371         /**
372          * Returns the member type declared in this type with the given simple name.
373          * This is a handle-only method. The type may or may not exist.
374          * 
375          * @param the given simple name
376          * @return the member type declared in this type with the given simple name
377          */
378         IType getType(String name);
379         
380         /**
381          * Returns the type-qualified name of this type, 
382          * including qualification for any enclosing types,
383          * but not including package qualification.
384          * For source types, this consists of the simple names of
385          * any enclosing types, separated by <code>"$"</code>, followed by the simple name of this type.
386          * For binary types, this is the name of the class file without the ".class" suffix.
387          * This is a handle-only method.
388          * 
389          * @return the type-qualified name of this type
390          */
391         String getTypeQualifiedName();
392         
393         /**
394          * Returns the type-qualified name of this type, 
395          * including qualification for any enclosing types,
396          * but not including package qualification.
397          * This consists of the simple names of any enclosing types, 
398          * separated by the <code>enclosingTypeSeparator</code>, 
399          * followed by the simple name of this type.
400          * 
401          * For example:
402          * <ul>
403          * <li>the type qualified name of a class B defined as a member of a class A
404          *     using the '.' separator is "A.B"</li>
405          * <li>the type qualified name of a class B defined as a member of a class A
406          *     using the '$' separator is "A$B"</li>
407          * <li>the type qualified name of a binary type whose class file is A$B.class
408          *     using the '.' separator is "A.B"</li>
409          * <li>the type qualified name of a binary type whose class file is A$B.class
410          *     using the '$' separator is "A$B"</li>
411          * <li>the type qualified name of an anonymous binary type whose class file is A$1.class
412          *     using the '.' separator is "A$1"</li>
413          * </ul>
414          *
415          * This is a handle-only method.
416          * 
417          * @param enclosingTypeSeparator the specified enclosing type separator
418          * @return the type-qualified name of this type
419          * @since 2.0
420          */
421         String getTypeQualifiedName(char enclosingTypeSeparator);
422         
423         /**
424          * Returns the immediate member types declared by this type.
425          * The results are listed in the order in which they appear in the source or class file.
426          *
427          * @exception JavaModelException if this element does not exist or if an
428          *              exception occurs while accessing its corresponding resource.
429          * @return the immediate member types declared by this type
430          */
431         IType[] getTypes() throws JavaModelException;
432         
433         /**
434          * Returns whether this type represents an anonymous type.
435          *
436          * @exception JavaModelException if this element does not exist or if an
437          *              exception occurs while accessing its corresponding resource.
438          * @return true if this type represents an anonymous type, false otherwise
439          * @since 2.0
440          */
441         boolean isAnonymous() throws JavaModelException;
442
443         /**
444          * Returns whether this type represents a class.
445          *
446          * @exception JavaModelException if this element does not exist or if an
447          *              exception occurs while accessing its corresponding resource.
448          * @return true if this type represents a class, false otherwise
449          */
450         boolean isClass() throws JavaModelException;
451         
452         /**
453          * Returns whether this type represents an interface.
454          *
455          * @exception JavaModelException if this element does not exist or if an
456          *              exception occurs while accessing its corresponding resource.
457          * @return true if this type represents an interface, false otherwise
458          */
459         boolean isInterface() throws JavaModelException;
460         
461         /**
462          * Returns whether this type represents a local type.
463          *
464          * @exception JavaModelException if this element does not exist or if an
465          *              exception occurs while accessing its corresponding resource.
466          * @return true if this type represents a local type, false otherwise
467          * @since 2.0
468          */
469         boolean isLocal() throws JavaModelException;
470
471         /**
472          * Returns whether this type represents a member type.
473          *
474          * @exception JavaModelException if this element does not exist or if an
475          *              exception occurs while accessing its corresponding resource.
476          * @return true if this type represents a member type, false otherwise
477          * @since 2.0
478          */
479         boolean isMember() throws JavaModelException;
480         /**
481          * Loads a previously saved ITypeHierarchy from an input stream. A type hierarchy can
482          * be stored using ITypeHierachy#store(OutputStream).
483          * 
484          * Only hierarchies originally created by the following methods can be load:
485          * <ul>
486          * <li>IType#newSupertypeHierarchy(IProgressMonitor)</li>
487          * <li>IType#newTypeHierarchy(IJavaProject, IProgressMonitor)</li>
488          * <li>IType#newTypeHierarchy(IProgressMonitor)</li>
489          * </u>
490          * 
491          * @param input stream where hierarchy will be read
492          * @param monitor the given progress monitor
493          * @return the stored hierarchy
494          * @exception JavaModelException if the hierarchy could not be restored, reasons include:
495          *      - type is not the focus of the hierarchy or 
496          *              - unable to read the input stream (wrong format, IOException during reading, ...)
497          * @see ITypeHierarchy#store(OutputStream, IProgressMonitor)
498          * @since 2.1
499          */
500 //      ITypeHierarchy loadTypeHierachy(InputStream input, IProgressMonitor monitor) throws JavaModelException;
501         /**
502          * Creates and returns a type hierarchy for this type containing
503          * this type and all of its supertypes.
504          *
505          * @exception JavaModelException if this element does not exist or if an
506          *              exception occurs while accessing its corresponding resource.
507          * @param monitor the given progress monitor
508          * @return a type hierarchy for this type containing this type and all of its supertypes
509          */
510 //      ITypeHierarchy newSupertypeHierarchy(IProgressMonitor monitor) throws JavaModelException;
511         
512         /**
513          * Creates and returns a type hierarchy for this type containing
514          * this type and all of its supertypes, considering types in the given 
515          * working copies. In other words, the list of working copies will take 
516          * precedence over their original compilation units in the workspace.
517          * <p>
518          * Note that passing an empty working copy will be as if the original compilation
519          * unit had been deleted.
520          *
521          * @param workingCopies the working copies that take precedence over their original compilation units
522          * @param monitor the given progress monitor
523          * @return a type hierarchy for this type containing this type and all of its supertypes
524          * @exception JavaModelException if this element does not exist or if an
525          *              exception occurs while accessing its corresponding resource.
526          * @since 2.0
527          */
528 //      ITypeHierarchy newSupertypeHierarchy(IWorkingCopy[] workingCopies, IProgressMonitor monitor)
529 //              throws JavaModelException;
530                 
531         /**
532          * Creates and returns a type hierarchy for this type containing
533          * this type, all of its supertypes, and all its subtypes in the workspace.
534          *
535          * @exception JavaModelException if this element does not exist or if an
536          *              exception occurs while accessing its corresponding resource.
537          * @param monitor the given progress monitor
538          * @return a type hierarchy for this type containing
539          * this type, all of its supertypes, and all its subtypes in the workspace
540          */
541 //      ITypeHierarchy newTypeHierarchy(IProgressMonitor monitor) throws JavaModelException;
542         
543         /**
544          * Creates and returns a type hierarchy for this type containing
545          * this type, all of its supertypes, and all its subtypes in the workspace, 
546          * considering types in the given working copies. In other words, the list of working 
547          * copies that will take precedence over their original compilation units in the workspace.
548          * <p>
549          * Note that passing an empty working copy will be as if the original compilation
550          * unit had been deleted.
551          *
552          * @param workingCopies the working copies that take precedence over their original compilation units
553          * @param monitor the given progress monitor
554          * @return a type hierarchy for this type containing
555          * this type, all of its supertypes, and all its subtypes in the workspace
556          * @exception JavaModelException if this element does not exist or if an
557          *              exception occurs while accessing its corresponding resource.
558          * @since 2.0
559          */
560 //      ITypeHierarchy newTypeHierarchy(IWorkingCopy[] workingCopies, IProgressMonitor monitor) throws JavaModelException;
561         /**
562          * Creates and returns a type hierarchy for this type containing
563          * this type, all of its supertypes, and all its subtypes in the workspace, 
564          * considering types in the working copies with the given owner. 
565          * In other words, the owner's working copies will take 
566          * precedence over their original compilation units in the workspace.
567          * <p>
568          * Note that if a working copy is empty, it will be as if the original compilation
569          * unit had been deleted.
570          * <p>
571          *
572          * @param owner the owner of working copies that take precedence over their original compilation units
573          * @param monitor the given progress monitor
574          * @return a type hierarchy for this type containing
575          * this type, all of its supertypes, and all its subtypes in the workspace
576          * @exception JavaModelException if this element does not exist or if an
577          *              exception occurs while accessing its corresponding resource.
578          * @since 3.0
579          */
580 //      ITypeHierarchy newTypeHierarchy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
581         
582         /**
583          * Creates and returns a type hierarchy for this type containing
584          * this type, all of its supertypes, and all its subtypes 
585          * in the context of the given project.
586          *
587          * @param project the given project
588          * @param monitor the given progress monitor
589          * @exception JavaModelException if this element does not exist or if an
590          *              exception occurs while accessing its corresponding resource.
591          * @return a type hierarchy for this type containing
592          * this type, all of its supertypes, and all its subtypes 
593          * in the context of the given project
594          */
595 //      ITypeHierarchy newTypeHierarchy(IJavaProject project, IProgressMonitor monitor) throws JavaModelException;
596         
597         /**
598          * Resolves the given type name within the context of this type (depending on the type hierarchy 
599          * and its imports). Multiple answers might be found in case there are ambiguous matches.
600          *
601          * Each matching type name is decomposed as an array of two strings, the first denoting the package
602          * name (dot-separated) and the second being the type name.
603          * Returns <code>null</code> if unable to find any matching type.
604          *
605          * For example, resolution of <code>"Object"</code> would typically return
606          * <code>{{"java.lang", "Object"}}</code>.
607          * 
608          * @param typeName the given type name
609          * @exception JavaModelException if code resolve could not be performed. 
610          * @return the resolved type names or <code>null</code> if unable to find any matching type
611          */
612 //      String[][] resolveType(String typeName) throws JavaModelException;
613 }