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;
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;
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.
23 * If a binary type cannot be parsed, its structure remains unknown.
24 * Use <code>IJavaElement.isStructureKnown</code> to determine whether this
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.
33 * This interface is not intended to be implemented by clients.
36 public interface IType extends IMember, IParent {
38 * Do code completion inside a code snippet in the context of the current type.
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.
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
56 * @param isStatic whether the current scope is in a static context
57 * @param requestor the completion requestor
64 // char[][] localVariableTypeNames,
65 // char[][] localVariableNames,
66 // int[] localVariableModifiers,
68 // ICompletionRequestor requestor)
69 // throws JavaModelException;
72 * Creates and returns a field in this type with the
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>
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>
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:
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)
99 * @return a field in this type with the given contents
101 // IField createField(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor)
102 // throws JavaModelException;
105 * Creates and returns a static initializer in this type with the
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>
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:
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)
124 * @return a static initializer in this type with the given contents
126 // IInitializer createInitializer(String contents, IJavaElement sibling, IProgressMonitor monitor)
127 // throws JavaModelException;
130 * Creates and returns a method or constructor in this type with the
133 * Optionally, the new element can be positioned before the specified
134 * sibling. If no sibling is specified, the element will be appended
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>
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:
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)
158 * @return a method or constructor in this type with the given contents
160 // IMethod createMethod(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor)
161 // throws JavaModelException;
164 * Creates and returns a type in this type with the
167 * Optionally, the new type can be positioned before the specified
168 * sibling. If no sibling is specified, the type will be appended
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>
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:
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)
191 * @return a type in this type with the given contents
193 // IType createType(String contents, IJavaElement sibling, boolean force, IProgressMonitor monitor)
194 // throws JavaModelException;
197 * Finds the methods in this type that correspond to
199 * A method m1 corresponds to another method m2 if:
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.
206 * @param method the given method
207 * @return the found method or <code>null</code> if no such methods can be found.
211 IMethod[] findMethods(IMethod method);
214 * Returns the simple name of this type, unqualified by package or enclosing type.
215 * This is a handle-only method.
217 * @return the simple name of this type
219 String getElementName();
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.
226 * @param name the given name
227 * @return the field with the specified name in this type
229 IField getField(String name);
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.
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
241 IField[] getFields() throws JavaModelException;
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.
250 * @see IType#getTypeQualifiedName()
251 * @return the fully qualified name of this type
253 String getFullyQualifiedName();
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>.
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>
275 * This is a handle-only method.
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)
282 String getFullyQualifiedName(char enclosingTypeSeparator);
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.
290 * @param occurrenceCount the specified position
291 * @return the initializer with the specified position relative to the order they are defined in the source
293 // IInitializer getInitializer(int occurrenceCount);
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.
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
305 // IInitializer[] getInitializers() throws JavaModelException;
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.
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
318 IMethod getMethod(String name, String[] parameterTypeSignatures);
321 * Returns the methods and constructors declared by this type.
322 * For binary types, this may include the special <code><clinit></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.
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
332 IMethod[] getMethods() throws JavaModelException;
335 * Returns the package fragment in which this element is defined.
336 * This is a handle-only method.
338 * @return the package fragment in which this element is defined
340 IPackageFragment getPackageFragment();
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.
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
353 String getSuperclassName() throws JavaModelException;
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.
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
369 String[] getSuperInterfaceNames() throws JavaModelException;
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.
375 * @param the given simple name
376 * @return the member type declared in this type with the given simple name
378 IType getType(String name);
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.
389 * @return the type-qualified name of this type
391 String getTypeQualifiedName();
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.
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>
415 * This is a handle-only method.
417 * @param enclosingTypeSeparator the specified enclosing type separator
418 * @return the type-qualified name of this type
421 String getTypeQualifiedName(char enclosingTypeSeparator);
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.
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
431 IType[] getTypes() throws JavaModelException;
434 * Returns whether this type represents an anonymous type.
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
441 boolean isAnonymous() throws JavaModelException;
444 * Returns whether this type represents a class.
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
450 boolean isClass() throws JavaModelException;
453 * Returns whether this type represents an interface.
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
459 boolean isInterface() throws JavaModelException;
462 * Returns whether this type represents a local type.
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
469 boolean isLocal() throws JavaModelException;
472 * Returns whether this type represents a member type.
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
479 boolean isMember() throws JavaModelException;
481 * Loads a previously saved ITypeHierarchy from an input stream. A type hierarchy can
482 * be stored using ITypeHierachy#store(OutputStream).
484 * Only hierarchies originally created by the following methods can be load:
486 * <li>IType#newSupertypeHierarchy(IProgressMonitor)</li>
487 * <li>IType#newTypeHierarchy(IJavaProject, IProgressMonitor)</li>
488 * <li>IType#newTypeHierarchy(IProgressMonitor)</li>
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)
500 // ITypeHierarchy loadTypeHierachy(InputStream input, IProgressMonitor monitor) throws JavaModelException;
502 * Creates and returns a type hierarchy for this type containing
503 * this type and all of its supertypes.
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
510 // ITypeHierarchy newSupertypeHierarchy(IProgressMonitor monitor) throws JavaModelException;
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.
518 * Note that passing an empty working copy will be as if the original compilation
519 * unit had been deleted.
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.
528 // ITypeHierarchy newSupertypeHierarchy(IWorkingCopy[] workingCopies, IProgressMonitor monitor)
529 // throws JavaModelException;
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.
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
541 // ITypeHierarchy newTypeHierarchy(IProgressMonitor monitor) throws JavaModelException;
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.
549 * Note that passing an empty working copy will be as if the original compilation
550 * unit had been deleted.
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.
560 // ITypeHierarchy newTypeHierarchy(IWorkingCopy[] workingCopies, IProgressMonitor monitor) throws JavaModelException;
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.
568 * Note that if a working copy is empty, it will be as if the original compilation
569 * unit had been deleted.
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.
580 // ITypeHierarchy newTypeHierarchy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException;
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.
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
595 // ITypeHierarchy newTypeHierarchy(IJavaProject project, IProgressMonitor monitor) throws JavaModelException;
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.
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.
605 * For example, resolution of <code>"Object"</code> would typically return
606 * <code>{{"java.lang", "Object"}}</code>.
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
612 // String[][] resolveType(String typeName) throws JavaModelException;