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.core;
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.
18 * If a binary type cannot be parsed, its structure remains unknown.
19 * Use <code>IJavaElement.isStructureKnown</code> to determine whether this
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.
28 * This interface is not intended to be implemented by clients.
31 public interface IType extends IMember, IParent {
33 * Do code completion inside a code snippet in the context of the current type.
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.
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
51 * @param isStatic whether the current scope is in a static context
52 * @param requestor the completion requestor
59 // char[][] localVariableTypeNames,
60 // char[][] localVariableNames,
61 // int[] localVariableModifiers,
63 // ICompletionRequestor requestor)
64 // throws JavaModelException;
67 * Creates and returns a field in this type with the
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>
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>
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:
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)
94 * @return a field in this type with the given contents
96 // IField createField(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor)
97 // throws JavaModelException;
100 * Creates and returns a static initializer in this type with the
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>
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:
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)
119 * @return a static initializer in this type with the given contents
121 // IInitializer createInitializer(String contents, IJavaElement sibling, IProgressMonitor monitor)
122 // throws JavaModelException;
125 * Creates and returns a method or constructor in this type with the
128 * Optionally, the new element can be positioned before the specified
129 * sibling. If no sibling is specified, the element will be appended
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>
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:
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)
153 * @return a method or constructor in this type with the given contents
155 // IMethod createMethod(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor)
156 // throws JavaModelException;
159 * Creates and returns a type in this type with the
162 * Optionally, the new type can be positioned before the specified
163 * sibling. If no sibling is specified, the type will be appended
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>
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:
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)
186 * @return a type in this type with the given contents
188 // IType createType(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor)
189 // throws JavaModelException;
192 * Finds the methods in this type that correspond to
194 * A method m1 corresponds to another method m2 if:
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.
201 * @param method the given method
202 * @return the found method or <code>null</code> if no such methods can be found.
206 IMethod[] findMethods(IMethod method);
209 * Returns the simple name of this type, unqualified by package or enclosing type.
210 * This is a handle-only method.
212 * @return the simple name of this type
214 String getElementName();
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.
221 * @param name the given name
222 * @return the field with the specified name in this type
224 IField getField(String name);
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.
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
236 IField[] getFields() throws JavaModelException;
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.
245 * @see IType#getTypeQualifiedName()
246 * @return the fully qualified name of this type
248 String getFullyQualifiedName();
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>.
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>
270 * This is a handle-only method.
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)
277 String getFullyQualifiedName(char enclosingTypeSeparator);
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.
285 * @param occurrenceCount the specified position
286 * @return the initializer with the specified position relative to the order they are defined in the source
288 // IInitializer getInitializer(int occurrenceCount);
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.
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
300 // IInitializer[] getInitializers() throws JavaModelException;
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.
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
313 IMethod getMethod(String name, String[] parameterTypeSignatures);
316 * Returns the methods and constructors declared by this type.
317 * For binary types, this may include the special <code><clinit></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.
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
327 IMethod[] getMethods() throws JavaModelException;
330 * Returns the package fragment in which this element is defined.
331 * This is a handle-only method.
333 * @return the package fragment in which this element is defined
335 IPackageFragment getPackageFragment();
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.
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
348 String getSuperclassName() throws JavaModelException;
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.
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
364 String[] getSuperInterfaceNames() throws JavaModelException;
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.
370 * @param the given simple name
371 * @return the member type declared in this type with the given simple name
373 IType getType(String name);
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.
384 * @return the type-qualified name of this type
386 String getTypeQualifiedName();
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.
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>
410 * This is a handle-only method.
412 * @param enclosingTypeSeparator the specified enclosing type separator
413 * @return the type-qualified name of this type
416 String getTypeQualifiedName(char enclosingTypeSeparator);
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.
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
426 IType[] getTypes() throws JavaModelException;
429 * Returns whether this type represents an anonymous type.
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
436 boolean isAnonymous() throws JavaModelException;
439 * Returns whether this type represents a class.
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
445 boolean isClass() throws JavaModelException;
448 * Returns whether this type represents an interface.
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
454 boolean isInterface() throws JavaModelException;
457 * Returns whether this type represents a local type.
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
464 boolean isLocal() throws JavaModelException;
467 * Returns whether this type represents a member type.
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
474 boolean isMember() throws JavaModelException;
476 * Loads a previously saved ITypeHierarchy from an input stream. A type hierarchy can
477 * be stored using ITypeHierachy#store(OutputStream).
479 * Only hierarchies originally created by the following methods can be load:
481 * <li>IType#newSupertypeHierarchy(IProgressMonitor)</li>
482 * <li>IType#newTypeHierarchy(IJavaProject, IProgressMonitor)</li>
483 * <li>IType#newTypeHierarchy(IProgressMonitor)</li>
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)
495 // ITypeHierarchy loadTypeHierachy(InputStream input, IProgressMonitor monitor) throws JavaModelException;
497 * Creates and returns a type hierarchy for this type containing
498 * this type and all of its supertypes.
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
505 // ITypeHierarchy newSupertypeHierarchy(IProgressMonitor monitor) throws JavaModelException;
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.
513 * Note that passing an empty working copy will be as if the original compilation
514 * unit had been deleted.
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.
523 // ITypeHierarchy newSupertypeHierarchy(IWorkingCopy[] workingCopies, IProgressMonitor monitor)
524 // throws JavaModelException;
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.
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
536 // ITypeHierarchy newTypeHierarchy(IProgressMonitor monitor) throws JavaModelException;
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.
544 * Note that passing an empty working copy will be as if the original compilation
545 * unit had been deleted.
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.
555 // ITypeHierarchy newTypeHierarchy(IWorkingCopy[] workingCopies, IProgressMonitor monitor) throws JavaModelException;
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.
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
570 // ITypeHierarchy newTypeHierarchy(IJavaProject project, IProgressMonitor monitor) throws JavaModelException;
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.
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.
580 * For example, resolution of <code>"Object"</code> would typically return
581 * <code>{{"java.lang", "Object"}}</code>.
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
587 // String[][] resolveType(String typeName) throws JavaModelException;