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