public interface IPackageFragment extends IParent, IJavaElement, IOpenable, ISourceManipulation
Package fragments elements need to be opened before they can be navigated or manipulated.
The children are of type ICompilationUnit
(representing a source file) or
IClassFile
(representing a binary class file).
The children are listed in no particular order.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_PACKAGE_NAME
The name of package fragment for the default package (value: the empty
string,
"" ). |
ANNOTATION, CLASS_FILE, COMPILATION_UNIT, FIELD, IMPORT_CONTAINER, IMPORT_DECLARATION, INITIALIZER, JAVA_MODEL, JAVA_PROJECT, LOCAL_VARIABLE, METHOD, PACKAGE_DECLARATION, PACKAGE_FRAGMENT, PACKAGE_FRAGMENT_ROOT, TYPE, TYPE_PARAMETER
Modifier and Type | Method and Description |
---|---|
boolean |
containsJavaResources()
Returns whether this fragment contains at least one Java resource.
|
ICompilationUnit |
createCompilationUnit(String name,
String contents,
boolean force,
IProgressMonitor monitor)
Creates and returns a compilation unit in this package fragment
with the specified name and contents.
|
IClassFile |
getClassFile(String name)
Returns the class file with the specified name
in this package (for example,
"Object.class" ). |
IClassFile[] |
getClassFiles()
Returns all of the class files in this package fragment.
|
ICompilationUnit |
getCompilationUnit(String name)
Returns the compilation unit with the specified name
in this package (for example,
"Object.java" ). |
ICompilationUnit[] |
getCompilationUnits()
Returns all of the compilation units in this package fragment.
|
ICompilationUnit[] |
getCompilationUnits(WorkingCopyOwner owner)
Returns all of the compilation units in this package fragment that are
in working copy mode and that have the given owner.
|
String |
getElementName()
Returns the dot-separated package name of this fragment, for example
"java.lang" , or "" (the empty string),
for the default package. |
int |
getKind()
Returns this package fragment's root kind encoded as an integer.
|
Object[] |
getNonJavaResources()
Returns an array of non-Java resources contained in this package fragment.
|
boolean |
hasSubpackages()
Returns whether this package fragment's name is
a prefix of other package fragments in this package fragment's
root.
|
boolean |
isDefaultPackage()
Returns whether this package fragment is a default package.
|
getChildren, hasChildren
exists, getAncestor, getAttachedJavadoc, getCorrespondingResource, getElementType, getHandleIdentifier, getJavaModel, getJavaProject, getOpenable, getParent, getPath, getPrimaryElement, getResource, getSchedulingRule, getUnderlyingResource, isReadOnly, isStructureKnown
getAdapter
close, findRecommendedLineSeparator, getBuffer, hasUnsavedChanges, isConsistent, isOpen, makeConsistent, open, save
copy, delete, move, rename
static final String DEFAULT_PACKAGE_NAME
The name of package fragment for the default package (value: the empty
string, ""
).
boolean containsJavaResources() throws JavaModelException
JavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.ICompilationUnit createCompilationUnit(String name, String contents, boolean force, IProgressMonitor monitor) throws JavaModelException
It is possible that a compilation unit with the same name already exists in this
package fragment.
The value of the force
parameter affects the resolution of
such a conflict:
true
- in this case the compilation is created with the new contentsfalse
- in this case a JavaModelException
is throwncontents
- the given contentsforce
- specify how to handle conflict is the same name already existsmonitor
- the given progress monitorname
- the given nameJavaModelException
- if the element could not be created. Reasons include:
CoreException
occurred while creating an underlying resource
null
(INVALID_CONTENTS)
IClassFile getClassFile(String name)
"Object.class"
).
The ".class" suffix is required.
This is a handle-only method. The class file may or may not be present.name
- the given nameIClassFile[] getClassFiles() throws JavaModelException
Note: it is possible that a package fragment contains only
compilation units (in other words, its kind is K_SOURCE
), in
which case this method returns an empty collection.
JavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.ICompilationUnit getCompilationUnit(String name)
"Object.java"
).
The name has to be a valid compilation unit name.
This is a handle-only method. The compilation unit may or may not be present.name
- the given nameJavaConventions.validateCompilationUnitName(String name, String sourceLevel, String complianceLevel)
ICompilationUnit[] getCompilationUnits() throws JavaModelException
Note: it is possible that a package fragment contains only
class files (in other words, its kind is K_BINARY
), in which
case this method returns an empty collection.
JavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.ICompilationUnit[] getCompilationUnits(WorkingCopyOwner owner) throws JavaModelException
Only existing working copies are returned. So a compilation unit handle that has no corresponding resource on disk will be included if and only if is in working copy mode.
Note: it is possible that a package fragment contains only
class files (in other words, its kind is K_BINARY
), in which
case this method returns an empty collection.
owner
- the owner of the returned compilation unitsJavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.String getElementName()
"java.lang"
, or ""
(the empty string),
for the default package.getElementName
in interface IJavaElement
int getKind() throws JavaModelException
Java-like extensions
),
or .class
files. This is a convenience method.JavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.IPackageFragmentRoot.K_SOURCE
,
IPackageFragmentRoot.K_BINARY
Object[] getNonJavaResources() throws JavaModelException
Non-Java resources includes other files and folders located in the same directory as the compilation units or class files for this package fragment. Source files excluded from this package 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).
Since 3.3, if this package fragment is inside an archive, the non-Java resources
are a tree of IJarEntryResource
s. One can navigate this tree using
the IJarEntryResource.getChildren()
and
IJarEntryResource.getParent()
methods.
IFile
s,
IFolder
s, or IStorage
s if the
package fragment is in an archive) contained in this package
fragmentJavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.IClasspathEntry.getInclusionPatterns()
,
IClasspathEntry.getExclusionPatterns()
boolean hasSubpackages() throws JavaModelException
JavaModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.boolean isDefaultPackage()
Copyright (c) 2000, 2015 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.