Class ClassFile
- All Implemented Interfaces:
IBufferChangedListener
,IClassFile
,ICodeAssist
,IJavaElement
,IOpenable
,IOrdinaryClassFile
,IParent
,ISourceReference
,ITypeRoot
,SuffixConstants
,org.eclipse.core.runtime.IAdaptable
- See Also:
IClassFile
-
Field Summary
Fields inherited from class org.aspectj.org.eclipse.jdt.internal.core.AbstractClassFile
name
Fields inherited from class org.aspectj.org.eclipse.jdt.internal.core.JavaElement
JEM_ANNOTATION, JEM_CLASSFILE, JEM_COMPILATIONUNIT, JEM_COUNT, JEM_DELIMITER_ESCAPE, JEM_ESCAPE, JEM_FIELD, JEM_IMPORTDECLARATION, JEM_INITIALIZER, JEM_JAVAPROJECT, JEM_LAMBDA_EXPRESSION, JEM_LAMBDA_METHOD, JEM_LOCALVARIABLE, JEM_METHOD, JEM_MODULAR_CLASSFILE, JEM_MODULE, JEM_PACKAGEDECLARATION, JEM_PACKAGEFRAGMENT, JEM_PACKAGEFRAGMENTROOT, JEM_STRING, JEM_TYPE, JEM_TYPE_PARAMETER, NO_ELEMENTS, NO_INFO, NO_STRINGS
Fields inherited from interface org.aspectj.org.eclipse.jdt.core.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_PARAMETER
Fields inherited from interface org.aspectj.org.eclipse.jdt.internal.compiler.util.SuffixConstants
EXTENSION_aj, EXTENSION_AJ, EXTENSION_class, EXTENSION_CLASS, EXTENSION_java, EXTENSION_JAVA, EXTENSION_jmod, EXTENSION_JMOD, SUFFIX_aj, SUFFIX_AJ, SUFFIX_class, SUFFIX_CLASS, SUFFIX_java, SUFFIX_JAVA, SUFFIX_STRING_aj, SUFFIX_STRING_AJ, SUFFIX_STRING_class, SUFFIX_STRING_CLASS, SUFFIX_STRING_java, SUFFIX_STRING_JAVA
-
Constructor Summary
ModifierConstructorDescriptionprotected
ClassFile(PackageFragment parent, String nameWithoutExtension)
-
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
buildStructure(OpenableElementInfo info, org.eclipse.core.runtime.IProgressMonitor pm, Map newElements, org.eclipse.core.resources.IResource underlyingResource)
Creates the children elements for this class file adding the resulting new handles and info objects to the newElements table.void
close()
Closes this element and its buffer (if any).void
codeComplete(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.codeSelect(int offset, int length, WorkingCopyOwner owner)
Returns the Java elements corresponding to the given selected text in this compilation unit.boolean
Finds 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), ornull
if no such a type exists.getAttachedJavadoc(org.eclipse.core.runtime.IProgressMonitor monitor)
Returns the Javadoc as HTML source if this element has attached Javadoc,null
otherwise.Returns theClassFileReader
specific for this IClassFile, based on its underlying resource, ornull
if unable to create the diet class file.getElementAt(int position)
Returns the smallest element within this Java type root that includes the given source position (that is, a method, field, etc.), ornull
if 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.getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner)
protected char
Returns thechar
that marks the start of this handles contribution to a memento.getName()
getType()
Returns the type contained in this class file.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.boolean
isClass()
Returns whether this type represents a class.boolean
Returns whether this type represents an interface.protected IBuffer
openBuffer(org.eclipse.core.runtime.IProgressMonitor pm, Object info)
Opens and returns buffer on the source code associated with this class file.static char[]
translatedName(char[] name)
Returns the Java Model representation of the given name which is provided in diet class file format, ornull
if the given name isnull
.Methods inherited from class org.aspectj.org.eclipse.jdt.internal.core.AbstractClassFile
becomeWorkingCopy, codeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeSelect, createElementInfo, equals, findElement, getBuffer, getBytes, getClassFileContent, getCorrespondingResource, getElementAtConsideringSibling, getElementName, getElementType, getNameRange, getPath, getPathIdentifier, getSource, getSourceRange, getTypeRoot, getWorkingCopy, hasBuffer, hashCode, isReadOnly, resource, validateExistence
Methods inherited from class org.aspectj.org.eclipse.jdt.internal.core.Openable
bufferChanged, canBeRemovedFromCache, canBufferBeRemovedFromCache, closeBuffer, closing, codeComplete, codeSelect, exists, findRecommendedLineSeparator, generateInfos, getBufferFactory, getBufferManager, getOpenable, getPackageFragmentRoot, getResource, getUnderlyingResource, hasUnsavedChanges, ignoreErrorStatus, isConsistent, isOpen, isSourceElement, isStructureKnown, makeConsistent, open, openAncestors, resource, resourceExists, save
Methods inherited from class org.aspectj.org.eclipse.jdt.internal.core.JavaElement
appendEscapedDelimiter, escapeMementoName, findNode, getAncestor, getChildren, getChildrenOfType, getCompilationUnit, getElementInfo, getElementInfo, getHandleFromMemento, getHandleIdentifier, getHandleMemento, getHandleMemento, getJavadocBaseLocation, getJavaModel, getJavaProject, getLibraryJavadocLocation, getOpenableParent, getParent, getPrimaryElement, getPrimaryElement, getSchedulingRule, getSourceElementAt, getSourceMapper, getURLContents, hasChildren, isAncestorOf, newDoesNotExistStatus, newJavaModelException, newNotPresentException, openWhenClosed, readableName, resolved, setParent, tabString, toDebugString, toString, toString, toStringAncestors, toStringChildren, toStringInfo, toStringInfo, toStringName, toStringWithAncestors, toStringWithAncestors, unresolved, validateAndCache
Methods inherited from class org.eclipse.core.runtime.PlatformObject
getAdapter
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapter
Methods inherited from interface org.aspectj.org.eclipse.jdt.core.IClassFile
becomeWorkingCopy, getBytes, getWorkingCopy
Methods inherited from interface org.aspectj.org.eclipse.jdt.core.ICodeAssist
codeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeSelect
Methods inherited from interface org.aspectj.org.eclipse.jdt.core.IJavaElement
exists, getAncestor, getCorrespondingResource, getElementName, getElementType, getHandleIdentifier, getJavaModel, getJavaProject, getOpenable, getParent, getPath, getPrimaryElement, getResource, getSchedulingRule, getUnderlyingResource, isReadOnly, isStructureKnown
Methods inherited from interface org.aspectj.org.eclipse.jdt.core.IOpenable
findRecommendedLineSeparator, getBuffer, hasUnsavedChanges, isConsistent, isOpen, makeConsistent, open, save
Methods inherited from interface org.aspectj.org.eclipse.jdt.core.IParent
getChildren, hasChildren
Methods inherited from interface org.aspectj.org.eclipse.jdt.core.ISourceReference
exists, getNameRange, getSource, getSourceRange
-
Field Details
-
binaryType
-
-
Constructor Details
-
ClassFile
-
-
Method Details
-
buildStructure
protected boolean buildStructure(OpenableElementInfo info, org.eclipse.core.runtime.IProgressMonitor pm, Map newElements, org.eclipse.core.resources.IResource underlyingResource) throws JavaModelExceptionCreates the children elements for this class file adding the resulting new handles and info objects to the newElements table. Returns true if successful, or false if an error is encountered parsing the class file.- Specified by:
buildStructure
in classOpenable
- Throws:
JavaModelException
- See Also:
Openable
,Signature
-
codeComplete
public void codeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner owner, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelExceptionDescription copied from interface:ICodeAssist
Performs code completion at the given offset position in this compilation unit, reporting results to the given completion requestor. Theoffset
is the 0-based index of the character, after which code assist is desired. Anoffset
of -1 indicates to code assist at the beginning of this compilation unit. It considers types in the working copies with the given owner first. In other words, the owner's working copies will take precedence over their original compilation units in the workspace.Note that if a working copy is empty, it will be as if the original compilation unit had been deleted.
If
IProgressMonitor
is notnull
then some proposals which can be very long to compute are proposed. To avoid that the code assist operation take too much time aIProgressMonitor
which automatically cancel the code assist operation when a specified amount of time is reached could be used.new IProgressMonitor() { private final static int TIMEOUT = 500; //ms private long endTime; public void beginTask(String name, int totalWork) { fEndTime= System.currentTimeMillis() + TIMEOUT; } public boolean isCanceled() { return endTime <= System.currentTimeMillis(); } ... };
- Specified by:
codeComplete
in interfaceICodeAssist
- Specified by:
codeComplete
in classAbstractClassFile
- Parameters:
offset
- the given offset positionrequestor
- the given completion requestorowner
- the owner of working copies that take precedence over their original compilation unitsmonitor
- the progress monitor used to report progress- Throws:
JavaModelException
- if code assist could not be performed. Reasons include:- This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- The position specified is < -1 or is greater than this compilation unit's source length (INDEX_OUT_OF_BOUNDS)
-
codeSelect
public IJavaElement[] codeSelect(int offset, int length, WorkingCopyOwner owner) throws JavaModelExceptionDescription copied from interface:ICodeAssist
Returns the Java elements corresponding to the given selected text in this compilation unit. Theoffset
is the 0-based index of the first selected character. Thelength
is the number of selected characters. It considers types in the working copies with the given owner first. In other words, the owner's working copies will take precedence over their original compilation units in the workspace.Note that if the
length
is 0 and theoffset
is inside an identifier or the index just after an identifier then this identifier is considered as the selection.Note that if a working copy is empty, it will be as if the original compilation unit had been deleted.
- Specified by:
codeSelect
in interfaceICodeAssist
- Specified by:
codeSelect
in classAbstractClassFile
- Parameters:
offset
- the given offset positionlength
- the number of selected charactersowner
- the owner of working copies that take precedence over their original compilation units- Returns:
- the Java elements corresponding to the given selected text
- Throws:
JavaModelException
- if code resolve could not be performed. Reasons include:- This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- The range specified is not within this element's source range (INDEX_OUT_OF_BOUNDS)
- See Also:
ICodeAssist.codeSelect(int, int, WorkingCopyOwner)
-
existsUsingJarTypeCache
public boolean existsUsingJarTypeCache() -
findPrimaryType
Description copied from interface:ITypeRoot
Finds 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), ornull
if no such a type exists.- Specified by:
findPrimaryType
in interfaceITypeRoot
- Returns:
- the found primary type of this Java type root, or
null
if no such a type exists - See Also:
ITypeRoot.findPrimaryType()
-
getAttachedJavadoc
public String getAttachedJavadoc(org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelExceptionDescription copied from interface:IJavaElement
Returns the Javadoc as HTML source if this element has attached Javadoc,
null
otherwise.This should be used only for binary elements. Source elements will always return
null
.The encoding used to read the Javadoc is the one defined by the content type of the file. If none is defined, then the project's encoding of this Java element is used. If the project's encoding cannot be retrieved, then the platform encoding is used.
In case the Javadoc doesn't exist for this element,
null
is returned.The HTML is extracted from the attached Javadoc and provided as is. No transformation or validation is done.
- Specified by:
getAttachedJavadoc
in interfaceIJavaElement
- Overrides:
getAttachedJavadoc
in classJavaElement
- Parameters:
monitor
- the given progress monitor, can benull
- Returns:
- the extracted javadoc from the attached javadoc,
null
if none - Throws:
JavaModelException
- if:- this element does not exist
- retrieving the attached javadoc fails (timed-out, invalid URL, ...)
- the format of the javadoc doesn't match expected standards (different anchors,...)
- See Also:
IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME
-
getBinaryTypeInfo
Returns theClassFileReader
specific for this IClassFile, based on its underlying resource, ornull
if unable to create the diet class file. There are two cases to consider:- a class file corresponding to an IFile resource
- a class file corresponding to a zip entry in a JAR
- Throws:
JavaModelException
- when the IFile resource or JAR is not available or when this class file is not present in the JAR
-
getName
-
close
Description copied from interface:IOpenable
Closes this element and its buffer (if any). Closing an element which is not open has no effect.Note: Although
IOpenable.close()
is exposed in the API, clients are not expected to open and close elements - the Java model does this automatically as elements are accessed.- Specified by:
close
in interfaceIOpenable
- Overrides:
close
in classJavaElement
- Throws:
JavaModelException
- if an error occurs closing this element- See Also:
IOpenable
-
getClassFile
- Overrides:
getClassFile
in classJavaElement
- See Also:
IMember
-
getElementAt
Description copied from interface:ITypeRoot
Returns the smallest element within this Java type root that includes the given source position (that is, a method, field, etc.), ornull
if 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.- Specified by:
getElementAt
in interfaceITypeRoot
- Parameters:
position
- a source position inside the Java type root- Returns:
- the innermost Java element enclosing a given source position or
null
if none (excluding the Java type root). - Throws:
JavaModelException
- if the Java type root does not exist or if an exception occurs while accessing its corresponding resource- See Also:
IClassFile
-
getHandleFromMemento
public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner)- Specified by:
getHandleFromMemento
in classJavaElement
-
getHandleMementoDelimiter
protected char getHandleMementoDelimiter()Description copied from class:JavaElement
Returns thechar
that marks the start of this handles contribution to a memento.- Specified by:
getHandleMementoDelimiter
in classJavaElement
- See Also:
JavaElement.getHandleMemento()
-
getTopLevelTypeName
-
getType
Description copied from interface:IOrdinaryClassFile
Returns the type contained in this class file. This is a handle-only method. The type may or may not exist.This method supersedes the corresponding super method. This method will never throw
UnsupportedOperationException
.- Specified by:
getType
in interfaceIClassFile
- Specified by:
getType
in interfaceIOrdinaryClassFile
- Returns:
- the type contained in this class file
- See Also:
IClassFile
-
getTypeName
-
getWorkingCopy
public ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelExceptionDescription copied from interface:ITypeRoot
Returns a shared working copy on this compilation unit or class file using the given working copy owner to create the buffer. If this is already a working copy of the given owner, the element itself is returned. This API can only answer an already existing working copy if it is based on the same original Java type root AND was using the same working copy owner (that is, as defined byObject.equals(java.lang.Object)
).The life time of a shared working copy is as follows:
- The first call to
ITypeRoot.getWorkingCopy(WorkingCopyOwner, IProgressMonitor)
creates a new working copy for this element - Subsequent calls increment an internal counter.
- A call to
ICompilationUnit.discardWorkingCopy()
decrements the internal counter. - When this counter is 0, the working copy is discarded.
Note that the working copy owner will be used for the life time of the shared working copy, that is if the working copy is closed then reopened, this owner will be used. The buffer will be automatically initialized with the original's Java type root content upon creation.
When the shared working copy instance is created, an ADDED IJavaElementDelta is reported on this working copy.
A working copy can be created on a not-yet existing compilation unit. In particular, such a working copy can then be committed in order to create the corresponding compilation unit.
Note that possible problems of this working copy are reported using this method only if the given working copy owner returns a problem requestor for this working copy (see
WorkingCopyOwner.getProblemRequestor(ICompilationUnit)
).- Specified by:
getWorkingCopy
in interfaceITypeRoot
- Parameters:
owner
- the working copy owner that creates a buffer that is used to get the content of the working copymonitor
- a progress monitor used to report progress while opening this compilation unit ornull
if no progress should be reported- Returns:
- a new working copy of this Java type root using the given owner to create the buffer, or this Java type root if it is already a working copy
- Throws:
JavaModelException
- if the contents of this element can not be determined.
- The first call to
-
isClass
Description copied from interface:IClassFile
Returns whether this type represents a class. This is not guaranteed to be instantaneous, as it may require parsing the underlying file.- Specified by:
isClass
in interfaceIClassFile
- Returns:
true
if the class file represents a class.- Throws:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource- See Also:
IClassFile
-
isInterface
Description copied from interface:IClassFile
Returns whether this type represents an interface. This is not guaranteed to be instantaneous, as it may require parsing the underlying file.- Specified by:
isInterface
in interfaceIClassFile
- Returns:
true
if the class file represents an interface.- Throws:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource- See Also:
IClassFile
-
openBuffer
protected IBuffer openBuffer(org.eclipse.core.runtime.IProgressMonitor pm, Object info) throws JavaModelExceptionOpens and returns buffer on the source code associated with this class file. Maps the source code to the children elements of this class file. If no source code is associated with this class file,null
is returned.- Overrides:
openBuffer
in classOpenable
- Throws:
JavaModelException
- See Also:
Openable
-
translatedName
public static char[] translatedName(char[] name)Returns the Java Model representation of the given name which is provided in diet class file format, ornull
if the given name isnull
.ClassFileReader
format is similar to "java/lang/Object", and corresponding Java Model format is "java.lang.Object".
-