Interface IPackageFragmentRoot
- All Superinterfaces:
org.eclipse.core.runtime.IAdaptable, IJavaElement, IOpenable, IParent
- All Known Implementing Classes:
ExternalPackageFragmentRoot, JarPackageFragmentRoot, JModPackageFragmentRoot, JrtPackageFragmentRoot, PackageFragmentRoot
IPackageFragment, and are in no particular order.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringEmpty root pathstatic final intUpdate model flag constant (bit mask value 8) indicating that the operation is to update the classpath of the destination project.static final intKind constant for a binary path root.static final intKind constant for a source path root.static final intUpdate model flag constant (bit mask value 1) indicating that the operation is to not copy/move/delete the package fragment root resource.static final intUpdate model flag constant (bit mask value 2) indicating that the operation is to update the classpath of the originating project.static final intUpdate model flag constant (bit mask value 4) indicating that the operation is to update the classpath of all referring projects except the originating project.static final intUpdate model flag constant (bit mask value 16) indicating that the operation is to replace the resource and the destination project's classpath entry.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 TypeMethodDescriptionvoidattachSource(org.eclipse.core.runtime.IPath sourcePath, org.eclipse.core.runtime.IPath rootPath, org.eclipse.core.runtime.IProgressMonitor monitor) Attaches the source archive identified by the given absolute path to this binary package fragment root.voidcopy(org.eclipse.core.runtime.IPath destination, int updateResourceFlags, int updateModelFlags, IClasspathEntry sibling, org.eclipse.core.runtime.IProgressMonitor monitor) Copies the resource of this package fragment root to the destination path as specified byIResource.copy(IPath, int, IProgressMonitor)but excluding nested source folders.createPackageFragment(String name, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) Creates and returns a package fragment in this root with the given dot-separated package name.voiddelete(int updateResourceFlags, int updateModelFlags, org.eclipse.core.runtime.IProgressMonitor monitor) Deletes the resource of this package fragment root as specified byIResource.delete(int, IProgressMonitor)but excluding nested source folders.intgetKind()Returns this package fragment root's kind encoded as an integer.Returns theIModuleDescriptionthat this package fragment root contains.Object[]Returns an array of non-Java resources contained in this package fragment root.getPackageFragment(String packageName) Returns the package fragment with the given package name.Returns the first raw classpath entry that corresponds to this package fragment root.Returns the first resolved classpath entry that corresponds to this package fragment root.org.eclipse.core.runtime.IPathReturns the absolute path to the source archive attached to this package fragment root's binary archive.org.eclipse.core.runtime.IPathReturns the path within this package fragment root's source archive.booleanReturns whether this package fragment root's underlying resource is a binary archive (a JAR or zip file).booleanReturns whether this package fragment root is external to the workbench (that is, a local file), and has no underlying resource.voidmove(org.eclipse.core.runtime.IPath destination, int updateResourceFlags, int updateModelFlags, IClasspathEntry sibling, org.eclipse.core.runtime.IProgressMonitor monitor) Moves the resource of this package fragment root to the destination path as specified byIResource.move(IPath,int,IProgressMonitor)but excluding nested source folders.Methods inherited from interface org.eclipse.core.runtime.IAdaptable
getAdapterMethods 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.
-
Field Details
-
K_SOURCE
static final int K_SOURCEKind constant for a source path root. Indicates this root only contains source files.- See Also:
-
K_BINARY
static final int K_BINARYKind constant for a binary path root. Indicates this root only contains binary files.- See Also:
-
DEFAULT_PACKAGEROOT_PATH
-
NO_RESOURCE_MODIFICATION
static final int NO_RESOURCE_MODIFICATIONUpdate model flag constant (bit mask value 1) indicating that the operation is to not copy/move/delete the package fragment root resource.- Since:
- 2.1
- See Also:
-
ORIGINATING_PROJECT_CLASSPATH
static final int ORIGINATING_PROJECT_CLASSPATHUpdate model flag constant (bit mask value 2) indicating that the operation is to update the classpath of the originating project.- Since:
- 2.1
- See Also:
-
OTHER_REFERRING_PROJECTS_CLASSPATH
static final int OTHER_REFERRING_PROJECTS_CLASSPATHUpdate model flag constant (bit mask value 4) indicating that the operation is to update the classpath of all referring projects except the originating project.- Since:
- 2.1
- See Also:
-
DESTINATION_PROJECT_CLASSPATH
static final int DESTINATION_PROJECT_CLASSPATHUpdate model flag constant (bit mask value 8) indicating that the operation is to update the classpath of the destination project.- Since:
- 2.1
- See Also:
-
REPLACE
static final int REPLACEUpdate model flag constant (bit mask value 16) indicating that the operation is to replace the resource and the destination project's classpath entry.- Since:
- 2.1
- See Also:
-
-
Method Details
-
attachSource
void attachSource(org.eclipse.core.runtime.IPath sourcePath, org.eclipse.core.runtime.IPath rootPath, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Attaches the source archive identified by the given absolute path to this binary package fragment root.rootPathspecifies the location of the root within the archive or folder (empty specifies the default root andnullspecifies the root path should be detected). Once a source archive or folder is attached to the package fragment root, thegetSourceandgetSourceRangemethods become operational for binary types/members. To detach a source archive or folder from a package fragment root, specifynullas the source path.- Parameters:
sourcePath- the given absolute path to the source archive or folderrootPath- specifies the location of the root within the archive (empty specifies the default root andnullspecifies automatic detection of the root path)monitor- the given progress monitor- Throws:
JavaModelException- if this operation fails. Reasons include:- This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreExceptionoccurred while updating a server property - This package fragment root is not of kind binary (INVALID_ELEMENT_TYPES)
- The path provided is not absolute (RELATIVE_PATH)
-
copy
void copy(org.eclipse.core.runtime.IPath destination, int updateResourceFlags, int updateModelFlags, IClasspathEntry sibling, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Copies the resource of this package fragment root to the destination path as specified byIResource.copy(IPath, int, IProgressMonitor)but excluding nested source folders.If
NO_RESOURCE_MODIFICATIONis specified inupdateModelFlagsor if this package fragment root is external, this operation doesn't copy the resource.updateResourceFlagsis then ignored.If
DESTINATION_PROJECT_CLASSPATHis specified inupdateModelFlags, updates the classpath of the destination's project (if it is a Java project). If a non-nullsibling is specified, a copy of this root's classpath entry is inserted before the sibling on the destination project's raw classpath. Ifnullis specified, the classpath entry is added at the end of the raw classpath.If
REPLACEis specified inupdateModelFlags, 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(usingIResource.NONE), the default behavior applies: the resource is copied (if this package fragment root is not external) and the classpath is not updated.- Parameters:
destination- the destination pathupdateResourceFlags- bit-wise or of update resource flag constants (IResource.FORCEandIResource.SHALLOW)updateModelFlags- bit-wise or of update resource flag constants (DESTINATION_PROJECT_CLASSPATHandNO_RESOURCE_MODIFICATION)sibling- the classpath entry before which a copy of the classpath entry should be inserted ornullif the classpath entry should be inserted at the endmonitor- a progress monitor- Throws:
JavaModelException- if this root could not be copied. Reasons include:- This root does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreExceptionoccurred while copying the resource or updating a classpath -
The destination is not inside an existing project and
updateModelFlagshas been specified asDESTINATION_PROJECT_CLASSPATH(INVALID_DESTINATION) - The sibling is not a classpath entry on the destination project's raw classpath (INVALID_SIBLING)
- The same classpath entry already exists on the destination project's
classpath (NAME_COLLISION) and
updateModelFlagshas not been specified asREPLACE
- Since:
- 2.1
- See Also:
-
createPackageFragment
IPackageFragment createPackageFragment(String name, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Creates and returns a package fragment in this root with the given dot-separated package name. An empty string specifies the default package. This has the side effect of creating all package fragments that are a prefix of the new package fragment which do not exist yet. If the package fragment already exists, this has no effect. For a description of theforceflag, seeIFolder.create.- Parameters:
name- 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 monitor- Returns:
- a package fragment in this root with the given dot-separated package name
- Throws:
JavaModelException- if the element could not be created. Reasons include:- This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreExceptionoccurred while creating an underlying resource - This package fragment root is read only (READ_ONLY)
- The name is not a valid package name (INVALID_NAME)
- See Also:
-
delete
void delete(int updateResourceFlags, int updateModelFlags, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Deletes the resource of this package fragment root as specified byIResource.delete(int, IProgressMonitor)but excluding nested source folders.If
NO_RESOURCE_MODIFICATIONis specified inupdateModelFlagsor if this package fragment root is external, this operation doesn't delete the resource.updateResourceFlagsis then ignored.If
ORIGINATING_PROJECT_CLASSPATHis specified inupdateModelFlags, update the raw classpath of this package fragment root's project by removing the corresponding classpath entry.If
OTHER_REFERRING_PROJECTS_CLASSPATHis specified inupdateModelFlags, 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(usingIResource.NONE), the default behavior applies: the resource is deleted (if this package fragment root is not external) and no classpaths are updated.- Parameters:
updateResourceFlags- bit-wise or of update resource flag constants (IResource.FORCEandIResource.KEEP_HISTORY)updateModelFlags- bit-wise or of update resource flag constants (ORIGINATING_PROJECT_CLASSPATH,OTHER_REFERRING_PROJECTS_CLASSPATHandNO_RESOURCE_MODIFICATION)monitor- a progress monitor- Throws:
JavaModelException- if this root could not be deleted. Reasons include:- This root does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreExceptionoccurred while deleting the resource or updating a classpath
- Since:
- 2.1
- See Also:
-
getKind
Returns this package fragment root's kind encoded as an integer. A package fragment root can contain source files (i.e. files with one of theJava-like extensions, or.classfiles, but not both. If the underlying folder or archive contains other kinds of files, they are ignored. In particular,.classfiles are ignored under a source package fragment root, and source files are ignored under a binary package fragment root.- Returns:
- this package fragment root's kind encoded as an integer
- Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its corresponding resource.- See Also:
-
getNonJavaResources
Returns an array of non-Java resources contained in this package fragment root.Non-Java resources includes other files and folders located in the same directories as the compilation units or class files under this package fragment root. Resources excluded from this package fragment root by virtue of inclusion/exclusion patterns on the corresponding source classpath entry are considered non-Java resources and will appear in the result (possibly in a folder). Thus when a nested source folder is excluded, it will appear in the non-Java resources of the outer folder.
Since 3.3, if this package fragment root is an archive, the non-Java resources are a tree of
IJarEntryResources. One can navigate this tree using theIJarEntryResource.getChildren()andIJarEntryResource.getParent()methods.- Returns:
- an array of non-Java resources (
IFiles,IFolders, orIStorages if the package fragment root is in archive) contained in this package fragment root - Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its corresponding resource.- See Also:
-
getPackageFragment
Returns the package fragment with the given package name. An empty string indicates the default package. This is a handle-only operation. The package fragment may or may not exist.- Parameters:
packageName- the given package name- Returns:
- the package fragment with the given package name
-
getRawClasspathEntry
Returns the first raw classpath entry that corresponds to this package fragment root. A raw classpath entry corresponds to a package fragment root if once resolved this entry's path is equal to the root's path.- Returns:
- the first raw classpath entry that corresponds to this package fragment root
- Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its corresponding resource.- Since:
- 2.0
-
getResolvedClasspathEntry
Returns the first resolved classpath entry that corresponds to this package fragment root. A resolved classpath entry is said to correspond to a root if the path of the resolved entry is equal to the root's path.- Returns:
- the first resolved classpath entry that corresponds to this package fragment root
- Throws:
JavaModelException- if this element does not exist or if an exception occurs while accessing its corresponding resource.- Since:
- 3.6
-
getSourceAttachmentPath
Returns the absolute path to the source archive attached to this package fragment root's binary archive.- Returns:
- the absolute path to the corresponding source archive,
or
nullif this package fragment root's binary archive has no corresponding source archive, or if this package fragment root is not a binary archive - Throws:
JavaModelException- if this operation fails
-
getSourceAttachmentRootPath
Returns the path within this package fragment root's source archive. An empty path indicates that packages are located at the root of the source archive.- Returns:
- the path within the corresponding source archive,
or
nullif this package fragment root's binary archive has no corresponding source archive, or if this package fragment root is not a binary archive - Throws:
JavaModelException- if this operation fails
-
isArchive
boolean isArchive()Returns whether this package fragment root's underlying resource is a binary archive (a JAR or zip file).This is a handle-only method.
- Returns:
- true if this package fragment root's underlying resource is a binary archive, false otherwise
-
isExternal
boolean isExternal()Returns whether this package fragment root is external to the workbench (that is, a local file), and has no underlying resource.This is a handle-only method.
- Returns:
- true if this package fragment root is external to the workbench (that is, a local file), and has no underlying resource, false otherwise
-
move
void move(org.eclipse.core.runtime.IPath destination, int updateResourceFlags, int updateModelFlags, IClasspathEntry sibling, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Moves the resource of this package fragment root to the destination path as specified byIResource.move(IPath,int,IProgressMonitor)but excluding nested source folders.If
NO_RESOURCE_MODIFICATIONis specified inupdateModelFlagsor if this package fragment root is external, this operation doesn't move the resource.updateResourceFlagsis then ignored.If
DESTINATION_PROJECT_CLASSPATHis specified inupdateModelFlags, updates the classpath of the destination's project (if it is a Java project). If a non-nullsibling is specified, a copy of this root's classpath entry is inserted before the sibling on the destination project's raw classpath. Ifnullis specified, the classpath entry is added at the end of the raw classpath.If
ORIGINATING_PROJECT_CLASSPATHis specified inupdateModelFlags, update the raw classpath of this package fragment root's project by removing the corresponding classpath entry.If
OTHER_REFERRING_PROJECTS_CLASSPATHis specified inupdateModelFlags, update the raw classpaths of all other Java projects referring to this root's resource by removing the corresponding classpath entries.If
REPLACEis specified inupdateModelFlags, 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(usingIResource.NONE), the default behavior applies: the resource is moved (if this package fragment root is not external) and no classpaths are updated.- Parameters:
destination- the destination pathupdateResourceFlags- bit-wise or of update flag constants (IResource.FORCE,IResource.KEEP_HISTORYandIResource.SHALLOW)updateModelFlags- bit-wise or of update resource flag constants (DESTINATION_PROJECT_CLASSPATH,ORIGINATING_PROJECT_CLASSPATH,OTHER_REFERRING_PROJECTS_CLASSPATHandNO_RESOURCE_MODIFICATION)sibling- the classpath entry before which a copy of the classpath entry should be inserted ornullif the classpath entry should be inserted at the endmonitor- a progress monitor- Throws:
JavaModelException- if this root could not be moved. Reasons include:- This root does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreExceptionoccurred while copying the resource or updating a classpath -
The destination is not inside an existing project and
updateModelFlagshas been specified asDESTINATION_PROJECT_CLASSPATH(INVALID_DESTINATION) - The sibling is not a classpath entry on the destination project's raw classpath (INVALID_SIBLING)
- The same classpath entry already exists on the destination project's
classpath (NAME_COLLISION) and
updateModelFlagshas not been specified asREPLACE
- Since:
- 2.1
- See Also:
-
getModuleDescription
IModuleDescription getModuleDescription()Returns theIModuleDescriptionthat this package fragment root contains. Returnsnullif 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.- Returns:
- the
IModuleDescriptionthis root contains. - Since:
- 3.14
-