public class PackageFragmentRoot extends Openable implements IPackageFragmentRoot
IPackageFragmentRoot| Modifier and Type | Field and Description |
|---|---|
protected static char |
ATTACHMENT_PROPERTY_DELIMITER
The delimiter between the source path and root path in the
attachment server property.
|
static java.lang.String |
NO_SOURCE_ATTACHMENT |
protected IResource |
resource
The resource associated with this root (null for external jar)
|
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, parentDEFAULT_PACKAGEROOT_PATH, DESTINATION_PROJECT_CLASSPATH, K_BINARY, K_SOURCE, NO_RESOURCE_MODIFICATION, ORIGINATING_PROJECT_CLASSPATH, OTHER_REFERRING_PROJECTS_CLASSPATH, REPLACEANNOTATION, 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| Modifier | Constructor and Description |
|---|---|
protected |
PackageFragmentRoot(IResource resource,
JavaProject project)
Constructs a package fragment root which is the root of the java package
directory hierarchy.
|
| Modifier and Type | Method and Description |
|---|---|
void |
attachSource(IPath sourcePath,
IPath rootPath,
IProgressMonitor monitor)
Attaches the source archive identified by the given absolute path to this
binary package fragment root.
|
protected boolean |
buildStructure(OpenableElementInfo info,
IProgressMonitor pm,
java.util.Map newElements,
IResource underlyingResource)
Builds this element's structure and properties in the given
info object, based on this element's current contents (reuse buffer
contents if this element has an open buffer, or resource contents
if this element does not have an open buffer).
|
protected boolean |
computeChildren(OpenableElementInfo info,
IResource underlyingResource)
Compute the package fragment children of this package fragment root.
|
protected void |
computeFolderChildren(IContainer folder,
boolean isIncluded,
java.lang.String[] pkgName,
java.util.ArrayList vChildren,
char[][] inclusionPatterns,
char[][] exclusionPatterns)
Starting at this folder, create package fragments and add the fragments that are not excluded
to the collection of children.
|
void |
copy(IPath destination,
int updateResourceFlags,
int updateModelFlags,
IClasspathEntry sibling,
IProgressMonitor monitor)
Copies the resource of this package fragment root to the destination path
as specified by
IResource.copy(IPath, int, IProgressMonitor)
but excluding nested source folders. |
protected java.lang.Object |
createElementInfo()
Returns a new element info for this element.
|
IPackageFragment |
createPackageFragment(java.lang.String pkgName,
boolean force,
IProgressMonitor monitor)
Creates and returns a package fragment in this root with the
given dot-separated package name.
|
void |
delete(int updateResourceFlags,
int updateModelFlags,
IProgressMonitor monitor)
Deletes the resource of this package fragment root as specified by
IResource.delete(int, IProgressMonitor) but excluding nested
source folders. |
protected int |
determineKind(IResource underlyingResource)
Returns the root's kind - K_SOURCE or K_BINARY, defaults
to K_SOURCE if it is not on the classpath.
|
boolean |
equals(java.lang.Object o)
Compares two objects for equality;
for
PackageFragmentRoots, equality is having the
same parent, same resources, and occurrence count. |
char[][] |
fullExclusionPatternChars() |
char[][] |
fullInclusionPatternChars() |
IModuleDescription |
getAutomaticModuleDescription() |
java.lang.String |
getClassFilePath(java.lang.String classname)
Returns the relative path within an archive for the given class file name.
|
java.lang.String |
getElementName()
Returns the name of this element.
|
int |
getElementType()
Returns this element's kind encoded as an integer.
|
IJavaElement |
getHandleFromMemento(java.lang.String token,
MementoTokenizer memento,
WorkingCopyOwner owner) |
protected void |
getHandleMemento(java.lang.StringBuffer buff) |
protected char |
getHandleMementoDelimiter()
Returns the
char that marks the start of this handles
contribution to a memento. |
int |
getKind()
Returns this package fragment root's kind encoded as an integer.
|
java.util.jar.Manifest |
getManifest()
Convenience lookup, though currently only JarPackageFragmentRoot is searched for a manifest.
|
IModuleDescription |
getModuleDescription()
Returns the
IModuleDescription that this package fragment root contains. |
java.lang.Object[] |
getNonJavaResources()
Returns an array of non-java resources contained in the receiver.
|
IPackageFragment |
getPackageFragment(java.lang.String packageName)
Returns the package fragment with the given package name.
|
PackageFragment |
getPackageFragment(java.lang.String[] pkgName) |
PackageFragment |
getPackageFragment(java.lang.String[] pkgName,
java.lang.String mod) |
protected java.lang.String |
getPackageName(IFolder folder)
Returns the package name for the given folder
(which is a decendent of this root).
|
IPath |
getPath()
Returns the path to the innermost resource enclosing this element.
|
IClasspathEntry |
getRawClasspathEntry()
Returns the first raw classpath entry that corresponds to this package
fragment root.
|
IClasspathEntry |
getResolvedClasspathEntry()
Returns the first resolved classpath entry that corresponds to this package fragment root.
|
IPath |
getSourceAttachmentPath()
Returns the absolute path to the source archive attached to
this package fragment root's binary archive.
|
IPath |
getSourceAttachmentRootPath()
Returns the path within this package fragment root's source archive.
|
SourceMapper |
getSourceMapper()
Returns the SourceMapper facility for this element, or
null if this element does not have a
SourceMapper. |
IResource |
getUnderlyingResource()
Returns the smallest underlying resource that contains
this element, or
null if this element is not contained
in a resource. |
boolean |
hasChildren()
Returns whether this element has one or more immediate children.
|
boolean |
hasCompilationUnit(java.lang.String qualifiedPackageName,
java.lang.String moduleName) |
int |
hashCode()
Returns the hash code for this Java element.
|
boolean |
ignoreOptionalProblems() |
IPath |
internalPath() |
boolean |
isArchive()
Returns whether this package fragment root's underlying
resource is a binary archive (a JAR or zip file).
|
protected boolean |
isComplianceJava9OrHigher() |
boolean |
isExternal()
Returns whether this package fragment root is external
to the workbench (that is, a local file), and has no
underlying resource.
|
void |
move(IPath destination,
int updateResourceFlags,
int updateModelFlags,
IClasspathEntry sibling,
IProgressMonitor monitor)
Moves the resource of this package fragment root to the destination path
as specified by
IResource.move(IPath,int,IProgressMonitor)
but excluding nested source folders. |
IResource |
resource() |
IResource |
resource(PackageFragmentRoot root) |
void |
setSourceMapper(SourceMapper mapper)
For use by
AttachSourceOperation only. |
protected void |
toStringInfo(int tab,
java.lang.StringBuffer buffer,
java.lang.Object info,
boolean showResolvedInfo)
Debugging purposes
|
protected IStatus |
validateExistence(IResource underlyingResource) |
protected IStatus |
validateOnClasspath() |
protected void |
verifyAttachSource(IPath sourcePath)
Possible failures:
ELEMENT_NOT_PRESENT - the root supplied to the operation
does not exist
INVALID_ELEMENT_TYPES - the root is not of kind K_BINARY
RELATIVE_PATH - the path supplied to this operation must be
an absolute path
|
bufferChanged, canBeRemovedFromCache, canBufferBeRemovedFromCache, closeBuffer, closing, codeComplete, codeSelect, exists, findRecommendedLineSeparator, generateInfos, getBuffer, getBufferFactory, getBufferManager, getCorrespondingResource, getOpenable, getPackageFragmentRoot, getResource, hasBuffer, hasUnsavedChanges, ignoreErrorStatus, isConsistent, isOpen, isSourceElement, isStructureKnown, makeConsistent, open, openAncestors, openBuffer, resourceExists, saveappendEscapedDelimiter, close, escapeMementoName, findNode, getAncestor, getAttachedJavadoc, getChildren, getChildrenOfType, getClassFile, getCompilationUnit, getElementInfo, getElementInfo, getHandleFromMemento, getHandleIdentifier, getHandleMemento, getJavadocBaseLocation, getJavaModel, getJavaProject, getLibraryJavadocLocation, getOpenableParent, getParent, getPrimaryElement, getPrimaryElement, getSchedulingRule, getSourceElementAt, getURLContents, isAncestorOf, isReadOnly, newDoesNotExistStatus, newJavaModelException, newNotPresentException, openWhenClosed, readableName, resolved, tabString, toDebugString, toString, toString, toStringAncestors, toStringChildren, toStringInfo, toStringName, toStringWithAncestors, toStringWithAncestors, unresolved, validateAndCacheclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetChildrenexists, getAncestor, getAttachedJavadoc, getCorrespondingResource, getHandleIdentifier, getJavaModel, getJavaProject, getOpenable, getParent, getPrimaryElement, getResource, getSchedulingRule, isReadOnly, isStructureKnownclose, findRecommendedLineSeparator, getBuffer, hasUnsavedChanges, isConsistent, isOpen, makeConsistent, open, saveprotected static final char ATTACHMENT_PROPERTY_DELIMITER
public static final java.lang.String NO_SOURCE_ATTACHMENT
protected IResource resource
protected PackageFragmentRoot(IResource resource,
JavaProject project)
public void attachSource(IPath sourcePath,
IPath rootPath,
IProgressMonitor monitor)
throws JavaModelException
IPackageFragmentRootrootPath specifies the location
of the root within the archive or folder (empty specifies the default root
and null specifies the root path should be detected).
Once a source archive or folder is attached to the package fragment root,
the getSource and getSourceRange
methods become operational for binary types/members.
To detach a source archive or folder from a package fragment root, specify
null as the source path.attachSource in interface IPackageFragmentRootsourcePath - the given absolute path to the source archive or folderrootPath - specifies the location of the root within the archive
(empty specifies the default root and null specifies
automatic detection of the root path)monitor - the given progress monitorJavaModelException - if this operation fails. Reasons include:
CoreException occurred while updating a server property
IPackageFragmentRootprotected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, java.util.Map newElements, IResource underlyingResource) throws JavaModelException
OpenablebuildStructure in class OpenableJavaModelExceptionOpenablepublic void delete(int updateResourceFlags,
int updateModelFlags,
IProgressMonitor monitor)
throws JavaModelException
IPackageFragmentRootIResource.delete(int, IProgressMonitor) but excluding nested
source folders.
If NO_RESOURCE_MODIFICATION is specified in
updateModelFlags or if this package fragment root is external,
this operation doesn't delete the resource. updateResourceFlags
is then ignored.
If ORIGINATING_PROJECT_CLASSPATH is specified in
updateModelFlags, update the raw classpath of this package
fragment root's project by removing the corresponding classpath entry.
If OTHER_REFERRING_PROJECTS_CLASSPATH is specified in
updateModelFlags, update the raw classpaths of all other Java
projects referring to this root's resource by removing the corresponding classpath
entries.
If no flags is specified in updateModelFlags (using
IResource.NONE), the default behavior applies: the
resource is deleted (if this package fragment root is not external) and no
classpaths are updated.
delete in interface IPackageFragmentRootupdateResourceFlags - bit-wise or of update resource flag constants
(IResource.FORCE and IResource.KEEP_HISTORY)updateModelFlags - bit-wise or of update resource flag constants
(ORIGINATING_PROJECT_CLASSPATH,
OTHER_REFERRING_PROJECTS_CLASSPATH and
NO_RESOURCE_MODIFICATION)monitor - a progress monitorJavaModelException - if this root could not be deleted. Reasons
include:
CoreException occurred while deleting the resource
or updating a classpath
org.eclipse.core.resources.IResource#delete(boolean, IProgressMonitor)protected boolean computeChildren(OpenableElementInfo info, IResource underlyingResource) throws JavaModelException
JavaModelException - The resource associated with this package fragment root does not existprotected void computeFolderChildren(IContainer folder,
boolean isIncluded,
java.lang.String[] pkgName,
java.util.ArrayList vChildren,
char[][] inclusionPatterns,
char[][] exclusionPatterns)
throws JavaModelException
JavaModelException - The resource associated with this package fragment does not existpublic void copy(IPath destination,
int updateResourceFlags,
int updateModelFlags,
IClasspathEntry sibling,
IProgressMonitor monitor)
throws JavaModelException
IPackageFragmentRootIResource.copy(IPath, int, IProgressMonitor)
but excluding nested source folders.
If NO_RESOURCE_MODIFICATION is specified in
updateModelFlags or if this package fragment root is external,
this operation doesn't copy the resource. updateResourceFlags
is then ignored.
If DESTINATION_PROJECT_CLASSPATH is specified in
updateModelFlags, updates the classpath of the
destination's project (if it is a Java project). If a non-null
sibling is specified, a copy of this root's classpath entry is inserted before the
sibling on the destination project's raw classpath. If null is
specified, the classpath entry is added at the end of the raw classpath.
If REPLACE is specified in updateModelFlags,
overwrites the resource at the destination path if any.
If the same classpath entry already exists on the destination project's raw
classpath, then the sibling is ignored and the new classpath entry replaces the
existing one.
If no flags is specified in updateModelFlags (using
IResource.NONE), the default behavior applies: the
resource is copied (if this package fragment root is not external) and the
classpath is not updated.
copy in interface IPackageFragmentRootdestination - the destination pathupdateResourceFlags - bit-wise or of update resource flag constants
(IResource.FORCE and IResource.SHALLOW)updateModelFlags - bit-wise or of update resource flag constants
(DESTINATION_PROJECT_CLASSPATH and
NO_RESOURCE_MODIFICATION)sibling - the classpath entry before which a copy of the classpath
entry should be inserted or null if the classpath entry should
be inserted at the endmonitor - a progress monitorJavaModelException - if this root could not be copied. Reasons
include:
CoreException occurred while copying the
resource or updating a classpathupdateModelFlags
has been specified as DESTINATION_PROJECT_CLASSPATH
(INVALID_DESTINATION)updateModelFlags
has not been specified as REPLACEorg.eclipse.core.resources.IResource#copy(IPath, boolean, IProgressMonitor)protected java.lang.Object createElementInfo()
createElementInfo in class Openablepublic IPackageFragment createPackageFragment(java.lang.String pkgName, boolean force, IProgressMonitor monitor) throws JavaModelException
IPackageFragmentRootforce flag, see IFolder.create.createPackageFragment in interface IPackageFragmentRootpkgName - the given dot-separated package nameforce - a flag controlling how to deal with resources that
are not in sync with the local file systemmonitor - the given progress monitorJavaModelException - if the element could not be created. Reasons include:
CoreException occurred while creating an underlying resource
IPackageFragmentRootprotected int determineKind(IResource underlyingResource)
throws JavaModelException
JavaModelException - if the project and root do
not exist.public boolean equals(java.lang.Object o)
PackageFragmentRoots, equality is having the
same parent, same resources, and occurrence count.equals in class JavaElementObject.equals(java.lang.Object)public char[][] fullExclusionPatternChars()
public char[][] fullInclusionPatternChars()
public java.lang.String getElementName()
IJavaElementgetElementName in interface IJavaElementgetElementName in class JavaElementIAdaptablepublic int getElementType()
IJavaElementgetElementType in interface IJavaElementIJavaElementIJavaElementprotected char getHandleMementoDelimiter()
JavaElementchar that marks the start of this handles
contribution to a memento.getHandleMementoDelimiter in class JavaElementJavaElement.getHandleMemento()public IJavaElement getHandleFromMemento(java.lang.String token, MementoTokenizer memento, WorkingCopyOwner owner)
getHandleFromMemento in class JavaElementprotected void getHandleMemento(java.lang.StringBuffer buff)
getHandleMemento in class JavaElementJavaElement.getHandleMemento(StringBuffer)public int getKind()
throws JavaModelException
IPackageFragmentRootJava-like extensions,
or .class files, but not both.
If the underlying folder or archive contains other kinds of files, they are ignored.
In particular, .class files are ignored under a source package fragment root,
and source files are ignored under a binary package fragment root.getKind in interface IPackageFragmentRootJavaModelException - if this element does not exist or if an
exception occurs while accessing its corresponding resource.IPackageFragmentRootpublic java.lang.Object[] getNonJavaResources()
throws JavaModelException
getNonJavaResources in interface IPackageFragmentRootIFiles,
IFolders, or IStorages if the
package fragment root is in archive) contained in this package
fragment rootJavaModelException - if this element does not exist or if an
exception occurs while accessing its corresponding resource.IClasspathEntry.getInclusionPatterns(),
IClasspathEntry.getExclusionPatterns()public IPackageFragment getPackageFragment(java.lang.String packageName)
IPackageFragmentRootgetPackageFragment in interface IPackageFragmentRootpackageName - the given package nameIPackageFragmentRootpublic PackageFragment getPackageFragment(java.lang.String[] pkgName)
public PackageFragment getPackageFragment(java.lang.String[] pkgName, java.lang.String mod)
protected java.lang.String getPackageName(IFolder folder)
public IPath getPath()
IJavaElementgetPath in interface IJavaElementIJavaElementpublic IPath internalPath()
public IClasspathEntry getRawClasspathEntry() throws JavaModelException
IPackageFragmentRootgetRawClasspathEntry in interface IPackageFragmentRootJavaModelException - if this element does not exist or if an
exception occurs while accessing its corresponding resource.public IClasspathEntry getResolvedClasspathEntry() throws JavaModelException
IPackageFragmentRootgetResolvedClasspathEntry in interface IPackageFragmentRootJavaModelException - if this element does not exist or if an
exception occurs while accessing its corresponding resource.public IResource resource(PackageFragmentRoot root)
public IPath getSourceAttachmentPath()
throws JavaModelException
IPackageFragmentRootgetSourceAttachmentPath in interface IPackageFragmentRootnull if this package fragment root's binary archive
has no corresponding source archive, or if this package fragment root
is not a binary archiveJavaModelException - if this operation failsIPackageFragmentRootpublic void setSourceMapper(SourceMapper mapper) throws JavaModelException
AttachSourceOperation only.
Sets the source mapper associated with this root.JavaModelExceptionpublic IPath getSourceAttachmentRootPath()
throws JavaModelException
IPackageFragmentRootgetSourceAttachmentRootPath in interface IPackageFragmentRootnull if this package fragment root's binary archive
has no corresponding source archive, or if this package fragment root
is not a binary archiveJavaModelException - if this operation failsIPackageFragmentRootpublic SourceMapper getSourceMapper()
JavaElementnull if this element does not have a
SourceMapper.getSourceMapper in class JavaElementJavaElementpublic IResource getUnderlyingResource()
throws JavaModelException
IJavaElementnull if this element is not contained
in a resource.getUnderlyingResource in interface IJavaElementgetUnderlyingResource in class Openablenull if noneJavaModelException - if this element does not exist or if an
exception occurs while accessing its underlying resourceIJavaElementpublic boolean hasChildren()
throws JavaModelException
IParentgetChildren is an empty array.hasChildren in interface IParenthasChildren in class JavaElementJavaModelException - if this element does not exist or if an
exception occurs while accessing its corresponding resourceIParentpublic int hashCode()
JavaElementhashCode in class JavaElementpublic boolean ignoreOptionalProblems()
public boolean isArchive()
IPackageFragmentRootThis is a handle-only method.
isArchive in interface IPackageFragmentRootIPackageFragmentRootpublic boolean isExternal()
IPackageFragmentRootThis is a handle-only method.
isExternal in interface IPackageFragmentRootIPackageFragmentRootprotected IStatus validateOnClasspath()
public void move(IPath destination,
int updateResourceFlags,
int updateModelFlags,
IClasspathEntry sibling,
IProgressMonitor monitor)
throws JavaModelException
IPackageFragmentRootIResource.move(IPath,int,IProgressMonitor)
but excluding nested source folders.
If NO_RESOURCE_MODIFICATION is specified in
updateModelFlags or if this package fragment root is external,
this operation doesn't move the resource. updateResourceFlags
is then ignored.
If DESTINATION_PROJECT_CLASSPATH is specified in
updateModelFlags, updates the classpath of the
destination's project (if it is a Java project). If a non-null
sibling is specified, a copy of this root's classpath entry is inserted before the
sibling on the destination project's raw classpath. If null is
specified, the classpath entry is added at the end of the raw classpath.
If ORIGINATING_PROJECT_CLASSPATH is specified in
updateModelFlags, update the raw classpath of this package
fragment root's project by removing the corresponding classpath entry.
If OTHER_REFERRING_PROJECTS_CLASSPATH is specified in
updateModelFlags, update the raw classpaths of all other Java
projects referring to this root's resource by removing the corresponding classpath
entries.
If REPLACE is specified in updateModelFlags,
overwrites the resource at the destination path if any.
If the same classpath entry already exists on the destination project's raw
classpath, then the sibling is ignored and the new classpath entry replaces the
existing one.
If no flags is specified in updateModelFlags (using
IResource.NONE), the default behavior applies: the
resource is moved (if this package fragment root is not external) and no
classpaths are updated.
move in interface IPackageFragmentRootdestination - the destination pathupdateResourceFlags - bit-wise or of update flag constants
(IResource.FORCE, IResource.KEEP_HISTORY
and IResource.SHALLOW)updateModelFlags - bit-wise or of update resource flag constants
(DESTINATION_PROJECT_CLASSPATH,
ORIGINATING_PROJECT_CLASSPATH,
OTHER_REFERRING_PROJECTS_CLASSPATH and
NO_RESOURCE_MODIFICATION)sibling - the classpath entry before which a copy of the classpath
entry should be inserted or null if the classpath entry should
be inserted at the endmonitor - a progress monitorJavaModelException - if this root could not be moved. Reasons
include:
CoreException occurred while copying the
resource or updating a classpathupdateModelFlags
has been specified as DESTINATION_PROJECT_CLASSPATH
(INVALID_DESTINATION)updateModelFlags
has not been specified as REPLACEorg.eclipse.core.resources.IResource#move(IPath, boolean, IProgressMonitor)protected void toStringInfo(int tab,
java.lang.StringBuffer buffer,
java.lang.Object info,
boolean showResolvedInfo)
JavaElementtoStringInfo in class JavaElementshowResolvedInfo - TODOprotected IStatus validateExistence(IResource underlyingResource)
validateExistence in class Openableprotected void verifyAttachSource(IPath sourcePath)
throws JavaModelException
JavaModelExceptionpublic java.lang.String getClassFilePath(java.lang.String classname)
classname - public IModuleDescription getModuleDescription()
IPackageFragmentRootIModuleDescription that this package fragment root contains.
Returns null if the root doesn't contain any named module or if the project compiler compliance is 1.8 or lower.
If present the module descriptor is found as a child of the package fragment representing the default package.
Note that only one of the source package fragment roots in a Java Project can legally
contain a module descriptor.getModuleDescription in interface IPackageFragmentRootIModuleDescription this root contains.public IModuleDescription getAutomaticModuleDescription() throws JavaModelException
JavaModelExceptionpublic boolean hasCompilationUnit(java.lang.String qualifiedPackageName,
java.lang.String moduleName)
public java.util.jar.Manifest getManifest()
protected boolean isComplianceJava9OrHigher()