public class ClassFile extends AbstractClassFile implements IOrdinaryClassFile
IClassFile| Modifier and Type | Field and Description |
|---|---|
protected BinaryType |
binaryType |
nameJEM_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, parentANNOTATION, 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_PARAMETEREXTENSION_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| Modifier | Constructor and Description |
|---|---|
protected |
ClassFile(PackageFragment parent,
java.lang.String nameWithoutExtension) |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
buildStructure(OpenableElementInfo info,
IProgressMonitor pm,
java.util.Map newElements,
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,
IProgressMonitor monitor)
Performs code completion at the given offset position in this compilation unit,
reporting results to the given completion requestor.
|
IJavaElement[] |
codeSelect(int offset,
int length,
WorkingCopyOwner owner)
Returns the Java elements corresponding to the given selected text in this compilation unit.
|
boolean |
existsUsingJarTypeCache() |
IType |
findPrimaryType()
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), or
null if no such a type exists. |
java.lang.String |
getAttachedJavadoc(IProgressMonitor monitor)
Returns the Javadoc as HTML source if this element has attached Javadoc,
null otherwise. |
IBinaryType |
getBinaryTypeInfo()
Returns the
ClassFileReaderspecific for this IClassFile, based
on its underlying resource, or null if unable to create
the diet class file. |
IClassFile |
getClassFile() |
IJavaElement |
getElementAt(int position)
Returns the smallest element within this Java type root that
includes the given source position (that is, a method, field, etc.), or
null 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. |
IJavaElement |
getHandleFromMemento(java.lang.String token,
MementoTokenizer memento,
WorkingCopyOwner owner) |
protected char |
getHandleMementoDelimiter()
Returns the
char that marks the start of this handles
contribution to a memento. |
java.lang.String |
getName() |
java.lang.String |
getTopLevelTypeName() |
IType |
getType()
Returns the type contained in this class file.
|
java.lang.String |
getTypeName() |
ICompilationUnit |
getWorkingCopy(WorkingCopyOwner owner,
IProgressMonitor monitor)
Returns a working copy on the source associated with this class file using the given
factory to create the buffer, or
null if there is no source associated
with the class file. |
boolean |
isClass()
Returns whether this type represents a class.
|
boolean |
isInterface()
Returns whether this type represents an interface.
|
protected IBuffer |
openBuffer(IProgressMonitor pm,
java.lang.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, or
null
if the given name is null. |
becomeWorkingCopy, codeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeSelect, createElementInfo, equals, findElement, getBuffer, getBytes, getClassFileContent, getCorrespondingResource, getElementAtConsideringSibling, getElementName, getElementType, getNameRange, getPath, getSource, getSourceRange, getTypeRoot, hasBuffer, hashCode, isReadOnly, resource, validateExistencebufferChanged, 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, saveappendEscapedDelimiter, 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, tabString, toDebugString, toString, toString, toStringAncestors, toStringChildren, toStringInfo, toStringInfo, toStringName, toStringWithAncestors, toStringWithAncestors, unresolved, validateAndCacheclone, finalize, getClass, notify, notifyAll, wait, wait, waitbecomeWorkingCopy, getBytesexists, getAncestor, getCorrespondingResource, getElementName, getElementType, getHandleIdentifier, getJavaModel, getJavaProject, getOpenable, getParent, getPath, getPrimaryElement, getResource, getSchedulingRule, getUnderlyingResource, isReadOnly, isStructureKnowngetChildren, hasChildrenfindRecommendedLineSeparator, getBuffer, hasUnsavedChanges, isConsistent, isOpen, makeConsistent, open, saveexists, getNameRange, getSource, getSourceRangecodeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeSelectprotected BinaryType binaryType
protected ClassFile(PackageFragment parent, java.lang.String nameWithoutExtension)
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, java.util.Map newElements, IResource underlyingResource) throws JavaModelException
buildStructure in class OpenableJavaModelExceptionOpenable,
Signaturepublic void codeComplete(int offset,
CompletionRequestor requestor,
WorkingCopyOwner owner,
IProgressMonitor monitor)
throws JavaModelException
ICodeAssistoffset
is the 0-based index of the character, after which code assist is desired.
An offset 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 not null then some proposals which
can be very long to compute are proposed. To avoid that the code assist operation
take too much time a IProgressMonitor 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();
}
...
};
codeComplete in interface ICodeAssistcodeComplete in class AbstractClassFileoffset - 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 progressJavaModelException - if code assist could not be performed. Reasons include:public IJavaElement[] codeSelect(int offset, int length, WorkingCopyOwner owner) throws JavaModelException
ICodeAssistoffset is the 0-based index of the first selected character.
The length 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 the offset 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.
codeSelect in interface ICodeAssistcodeSelect in class AbstractClassFileoffset - the given offset positionlength - the number of selected charactersowner - the owner of working copies that take precedence over their original compilation unitsJavaModelException - if code resolve could not be performed. Reasons include:
ICodeAssist.codeSelect(int, int, WorkingCopyOwner)public boolean existsUsingJarTypeCache()
public IType findPrimaryType()
ITypeRootnull if no such a type exists.findPrimaryType in interface ITypeRootnull if no such a type existsITypeRoot.findPrimaryType()public java.lang.String getAttachedJavadoc(IProgressMonitor monitor)
throws JavaModelException
IJavaElementReturns 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.
getAttachedJavadoc in interface IJavaElementgetAttachedJavadoc in class JavaElementmonitor - the given progress monitor, can be nullnull if noneJavaModelException - if:IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAMEpublic IBinaryType getBinaryTypeInfo() throws JavaModelException
ClassFileReaderspecific for this IClassFile, based
on its underlying resource, or null if unable to create
the diet class file.
There are two cases to consider:JavaModelException - when the IFile resource or JAR is not available
or when this class file is not present in the JARpublic java.lang.String getName()
public void close()
throws JavaModelException
IOpenableNote: 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.
close in interface IOpenableclose in class JavaElementJavaModelException - if an error occurs closing this elementIOpenablepublic IClassFile getClassFile()
getClassFile in class JavaElementIMemberpublic IJavaElement getElementAt(int position) throws JavaModelException
ITypeRootnull 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.getElementAt in interface ITypeRootposition - a source position inside the Java type rootnull
if none (excluding the Java type root).JavaModelException - if the Java type root does not exist or if an
exception occurs while accessing its corresponding resourceIClassFilepublic IJavaElement getHandleFromMemento(java.lang.String token, MementoTokenizer memento, WorkingCopyOwner owner)
getHandleFromMemento in class JavaElementprotected char getHandleMementoDelimiter()
JavaElementchar that marks the start of this handles
contribution to a memento.getHandleMementoDelimiter in class JavaElementJavaElement.getHandleMemento()public java.lang.String getTopLevelTypeName()
public IType getType()
IOrdinaryClassFileThis method supersedes the corresponding super method.
This method will never throw UnsupportedOperationException.
getType in interface IClassFilegetType in interface IOrdinaryClassFileIClassFilepublic java.lang.String getTypeName()
public ICompilationUnit getWorkingCopy(WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException
IClassFilenull if 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() or getOriginalElement.
getWorkingCopy in interface IClassFilegetWorkingCopy in interface ITypeRootgetWorkingCopy in class AbstractClassFileowner - a progress monitor used to report progress while opening this compilation unit
or null if no progress should be reportedmonitor - the factory that creates a buffer that is used to get the content of the working copy
or null if the internal factory should be usedJavaModelException - if the source of this class file can
not be determined. Reasons include:
IClassFilepublic boolean isClass()
throws JavaModelException
IClassFileisClass in interface IClassFiletrue if the class file represents a class.JavaModelException - if this element does not exist or if an
exception occurs while accessing its corresponding resourceIClassFilepublic boolean isInterface()
throws JavaModelException
IClassFileisInterface in interface IClassFiletrue if the class file represents an interface.JavaModelException - if this element does not exist or if an
exception occurs while accessing its corresponding resourceIClassFileprotected IBuffer openBuffer(IProgressMonitor pm, java.lang.Object info) throws JavaModelException
null is returned.openBuffer in class OpenableJavaModelExceptionOpenablepublic static char[] translatedName(char[] name)
null
if the given name is null.
ClassFileReader format is similar to "java/lang/Object",
and corresponding Java Model format is "java.lang.Object".