public class ModularClassFile extends AbstractClassFile implements IModularClassFile
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 |
ModularClassFile(PackageFragment parent) |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
buildStructure(OpenableElementInfo info,
IProgressMonitor pm,
java.util.Map newElements,
IResource underlyingResource)
Creates the single child element for this class file adding the resulting
new handle (of type
IBinaryModule) and info object to the newElements table. |
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.
|
protected void |
escapeMementoName(java.lang.StringBuffer buffer,
java.lang.String mementoName) |
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. |
IBinaryModule |
getBinaryModuleInfo()
Returns the
IBinaryModule specific for this IClassFile, based
on its underlying resource, or null if unable to create
the diet class file. |
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. |
IModuleDescription |
getModule()
Returns the module description contained in this type root.
|
IType |
getType()
Returns the type contained in this class file.
|
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.
|
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, close, findNode, getAncestor, getAttachedJavadoc, getChildren, getChildrenOfType, getClassFile, 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, getAttachedJavadoc, getCorrespondingResource, getElementName, getElementType, getHandleIdentifier, getJavaModel, getJavaProject, getOpenable, getParent, getPath, getPrimaryElement, getResource, getSchedulingRule, getUnderlyingResource, isReadOnly, isStructureKnowngetChildren, hasChildrenclose, findRecommendedLineSeparator, getBuffer, hasUnsavedChanges, isConsistent, isOpen, makeConsistent, open, saveexists, getNameRange, getSource, getSourceRangecodeComplete, codeComplete, codeComplete, codeComplete, codeComplete, codeSelectprotected ModularClassFile(PackageFragment parent)
protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, java.util.Map newElements, IResource underlyingResource) throws JavaModelException
IBinaryModule) and info object to the newElements table.
Returns true if successful, or false if an error is encountered parsing the class file.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:
public IType findPrimaryType()
ITypeRootnull if no such a type exists.findPrimaryType in interface ITypeRootnull if no such a type existspublic 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 resourcepublic 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 resourcepublic IType getType()
IClassFilegetType in interface IClassFilepublic IBinaryModule getBinaryModuleInfo() throws JavaModelException
IBinaryModule specific 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 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 resourceITypeRootpublic 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()protected void escapeMementoName(java.lang.StringBuffer buffer,
java.lang.String mementoName)
escapeMementoName in class JavaElementpublic 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:
IClassFileprotected IBuffer openBuffer(IProgressMonitor pm, java.lang.Object info) throws JavaModelException
null is returned.openBuffer in class OpenableJavaModelExceptionOpenablepublic IModuleDescription getModule() throws JavaModelException
IModularClassFileIModularClassFile should always have a module.getModule in interface IModularClassFilegetModule in interface ITypeRootJavaModelException