Interface IClassFile
- All Superinterfaces:
org.eclipse.core.runtime.IAdaptable, ICodeAssist, IJavaElement, IOpenable, IParent, ISourceReference, ITypeRoot
- All Known Subinterfaces:
IModularClassFile, IOrdinaryClassFile
- All Known Implementing Classes:
AbstractClassFile, ClassFile, ModularClassFile
.class file, holding the binary form
of either a type or a module:
- A class file of type
IOrdinaryClassFilehas a single child of typeIType, - a class file of type
IModularClassFilehas a single child of typeIModuleDescription.
IJavaElement.isStructureKnown to determine whether this is the
case.
Note: IClassFile extends ISourceReference.
Source can be obtained for a class file if and only if source has been attached to this
class file. The source associated with a class file is the source code of
the compilation unit it was (nominally) generated from.
- See Also:
-
Field Summary
Fields inherited from interface IJavaElement
ANNOTATION, CLASS_FILE, COMPILATION_UNIT, FIELD, IMPORT_CONTAINER, IMPORT_DECLARATION, INITIALIZER, JAVA_MODEL, JAVA_MODULE, JAVA_PROJECT, LOCAL_VARIABLE, METHOD, PACKAGE_DECLARATION, PACKAGE_FRAGMENT, PACKAGE_FRAGMENT_ROOT, TYPE, TYPE_PARAMETERModifier and TypeFieldDescriptionstatic final intConstant representing an annotation.static final intConstant representing a class file.static final intConstant representing a Java compilation unit.static final intConstant representing a field.static final intConstant representing all import declarations within a compilation unit.static final intConstant representing an import declaration within a compilation unit.static final intConstant representing a stand-alone instance or class initializer.static final intConstant representing a Java model (workspace level object).static final intConstant represents a module descriptor.static final intConstant representing a Java project.static final intConstant representing a local variable declaration.static final intConstant representing a method or constructor.static final intConstant representing a package declaration within a compilation unit.static final intConstant representing a package fragment.static final intConstant representing a package fragment root.static final intConstant representing a type (a class or interface).static final intConstant representing a type parameter declaration. -
Method Summary
Modifier and TypeMethodDescriptionbecomeWorkingCopy(IProblemRequestor problemRequestor, WorkingCopyOwner owner, org.eclipse.core.runtime.IProgressMonitor monitor) Deprecated.byte[]getBytes()Returns the bytes contained in this class file.getType()Deprecated.should only be used asIOrdinaryClassFile.getType().getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor monitor, IBufferFactory factory) Deprecated.booleanisClass()Returns whether this type represents a class.booleanReturns whether this type represents an interface.Methods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapterMethods inherited from interface ICodeAssist
codeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeSelect, codeSelectModifier and TypeMethodDescriptionvoidcodeComplete(int offset, CompletionRequestor requestor) Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor.voidcodeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner owner) Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor.voidcodeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner owner, org.eclipse.core.runtime.IProgressMonitor monitor) Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor.voidcodeComplete(int offset, CompletionRequestor requestor, org.eclipse.core.runtime.IProgressMonitor monitor) Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor.voidcodeComplete(int offset, ICodeCompletionRequestor requestor) Deprecated.UseICodeAssist.codeComplete(int, ICompletionRequestor)instead.voidcodeComplete(int offset, ICompletionRequestor requestor) Deprecated.UseICodeAssist.codeComplete(int, CompletionRequestor)instead.voidcodeComplete(int offset, ICompletionRequestor requestor, WorkingCopyOwner owner) Deprecated.codeSelect(int offset, int length) Returns the Java elements corresponding to the given selected text in this compilation unit.codeSelect(int offset, int length, WorkingCopyOwner owner) Returns the Java elements corresponding to the given selected text in this compilation unit.Methods inherited from interface IJavaElement
exists, getAncestor, getAttachedJavadoc, getCorrespondingResource, getElementName, getElementType, getHandleIdentifier, getJavaModel, getJavaProject, getOpenable, getParent, getPath, getPrimaryElement, getResource, getSchedulingRule, getUnderlyingResource, isReadOnly, isStructureKnownModifier and TypeMethodDescriptionbooleanexists()Returns whether this Java element exists in the model.getAncestor(int ancestorType) Returns this Java element or the first ancestor of this element that has the given type.getAttachedJavadoc(org.eclipse.core.runtime.IProgressMonitor monitor) Returns the Javadoc as HTML source if this element has attached Javadoc,nullotherwise.org.eclipse.core.resources.IResourceReturns the resource that corresponds directly to this element, ornullif there is no resource that corresponds to this element.Returns the name of this element.intReturns this element's kind encoded as an integer.Returns a string representation of this element handle.Returns the Java model.Returns the Java project this element is contained in, ornullif this element is not contained in any Java project (for instance, theIJavaModelis not contained in any Java project).Returns the first openable parent.Returns the element directly containing this element, ornullif this element has no parent.org.eclipse.core.runtime.IPathgetPath()Returns the path to the innermost resource enclosing this element.Returns the primary element (whose compilation unit is the primary compilation unit) this working copy element was created from, or this element if it is a descendant of a primary compilation unit or if it is not a descendant of a working copy (e.g.org.eclipse.core.resources.IResourceReturns the innermost resource enclosing this element.org.eclipse.core.runtime.jobs.ISchedulingRuleReturns the scheduling rule associated with this Java element.org.eclipse.core.resources.IResourceReturns the smallest underlying resource that contains this element, ornullif this element is not contained in a resource.booleanReturns whether this Java element is read-only.booleanReturns whether the structure of this element is known.Methods inherited from interface IOpenable
close, findRecommendedLineSeparator, getBuffer, hasUnsavedChanges, isConsistent, isOpen, makeConsistent, open, saveModifier and TypeMethodDescriptionvoidclose()Closes this element and its buffer (if any).Finds and returns the recommended line separator for this element.Returns the buffer opened for this element, ornullif this element does not have a buffer.booleanReturnstrueif this element is open and: its buffer has unsaved changes, or one of its descendants has unsaved changes, or a working copy has been created on one of this element's children and has not yet destroyedbooleanReturns whether the element is consistent with its underlying resource or buffer.booleanisOpen()Returns whether this openable is open.voidmakeConsistent(org.eclipse.core.runtime.IProgressMonitor progress) Makes this element consistent with its underlying resource or buffer by updating the element's structure and properties as necessary.voidopen(org.eclipse.core.runtime.IProgressMonitor progress) Opens this element and all parent elements that are not already open.voidsave(org.eclipse.core.runtime.IProgressMonitor progress, boolean force) Saves any changes in this element's buffer to its underlying resource via a workspace resource operation.Methods inherited from interface IParent
getChildren, hasChildrenModifier and TypeMethodDescriptionReturns the immediate children of this element.booleanReturns whether this element has one or more immediate children.Methods inherited from interface ISourceReference
exists, getNameRange, getSource, getSourceRangeModifier and TypeMethodDescriptionbooleanexists()Returns whether this element exists in the model.Returns the name range associated with this element.Returns the source code associated with this element.Returns the source range associated with this element.Methods inherited from interface ITypeRoot
findPrimaryType, getElementAt, getModule, getWorkingCopyModifier and TypeMethodDescriptionFinds the primary type of this Java type root (that is, the type with the same name as the compilation unit, or the type of a class file), ornullif no such a type exists.getElementAt(int position) Returns the smallest element within this Java type root that includes the given source position (that is, a method, field, etc.), ornullif there is no element other than the Java type root itself at the given position, or if the given position is not within the source range of the source of this Java type root.default IModuleDescriptionReturns the module description contained in this type root or null if there is no module in this type root.getWorkingCopy(WorkingCopyOwner owner, org.eclipse.core.runtime.IProgressMonitor monitor) Returns a shared working copy on this compilation unit or class file using the given working copy owner to create the buffer.
-
Method Details
-
becomeWorkingCopy
ICompilationUnit becomeWorkingCopy(IProblemRequestor problemRequestor, WorkingCopyOwner owner, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Deprecated.UseITypeRoot.getWorkingCopy(WorkingCopyOwner, IProgressMonitor)instead. Note that if this deprecated method is used, problems will be reported to the given problem requestor as well as the problem requestor returned by the working copy owner (if not null).Changes this class file handle into a working copy. A newIBufferis created using the given owner. Uses the primary owner ifnullis specified.When switching to working copy mode, problems are reported to the given
IProblemRequestor. Note that once in working copy mode, the givenIProblemRequestoris ignored. Only the originalIProblemRequestoris used to report subsequent problems.Once in working copy mode, changes to this working copy or its children are done in memory. Only the new buffer is affected.
Using
ICompilationUnit.commitWorkingCopy(boolean, IProgressMonitor)on the working copy will throw aJavaModelExceptionas a class file is implicetly read-only.If this class file was already in working copy mode, an internal counter is incremented and no other action is taken on this working copy. To bring this working copy back into the original mode (where it reflects the underlying resource),
ICompilationUnit.discardWorkingCopy()must be call as many times asbecomeWorkingCopy(IProblemRequestor, WorkingCopyOwner, IProgressMonitor).The primary compilation unit of a class file's working copy does not exist if the class file is not in working copy mode (
classFileWorkingCopy.getPrimary().exists() == false).The resource of a class file's working copy is
nullif the class file is in an external jar file.- Parameters:
problemRequestor- a requestor which will get notified of problems detected during reconciling as they are discovered. The requestor can be set tonullindicating that the client is not interested in problems.owner- the givenWorkingCopyOwner, ornullfor the primary ownermonitor- a progress monitor used to report progress while opening this compilation unit ornullif no progress should be reported- Returns:
- a working copy for this class file
- Throws:
JavaModelException- if this compilation unit could not become a working copy.- Since:
- 3.2
- See Also:
-
getBytes
Returns the bytes contained in this class file.- Returns:
- the bytes contained in this class file
- Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its corresponding resource- Since:
- 3.3
-
getType
Deprecated.should only be used asIOrdinaryClassFile.getType().Returns the type contained in this class file. This is a handle-only method. The type may or may not exist.- Returns:
- the type contained in this class file
- Throws:
UnsupportedOperationException- when invoked on an instance representing a modular class file.
-
getWorkingCopy
IJavaElement getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor monitor, IBufferFactory factory) throws JavaModelException Deprecated.Returns a working copy on the source associated with this class file using the given factory to create the buffer, ornullif there is no source associated with the class file.The buffer will be automatically initialized with the source of the class file upon creation.
The only valid operations on this working copy are
getBuffer()orgetOriginalElement.- Parameters:
monitor- a progress monitor used to report progress while opening this compilation unit ornullif no progress should be reportedfactory- the factory that creates a buffer that is used to get the content of the working copy ornullif the internal factory should be used- Returns:
- a a working copy on the source associated with this class file
- Throws:
JavaModelException- if the source of this class file can not be determined. Reasons include:- This class file does not exist (ELEMENT_DOES_NOT_EXIST)
- Since:
- 2.0
-
isClass
Returns whether this type represents a class. This is not guaranteed to be instantaneous, as it may require parsing the underlying file.- Returns:
trueif the class file represents a class.- Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its corresponding resource
-
isInterface
Returns whether this type represents an interface. This is not guaranteed to be instantaneous, as it may require parsing the underlying file.- Returns:
trueif the class file represents an interface.- Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its corresponding resource
-
ITypeRoot.getWorkingCopy(WorkingCopyOwner, IProgressMonitor)instead.