Schnittstelle IPackageFragment
- Alle Superschnittstellen:
org.eclipse.core.runtime.IAdaptable
,IJavaElement
,IOpenable
,IParent
,ISourceManipulation
- Alle bekannten Implementierungsklassen:
PackageFragment
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.
-
Feldübersicht
Modifizierer und TypFeldBeschreibungstatic final String
The name of package fragment for the default package (value: the empty string,""
).Von Schnittstelle geerbte Felder org.aspectj.org.eclipse.jdt.core.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_PARAMETER
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungboolean
Returns whether this fragment contains at least one Java resource.createCompilationUnit
(String name, String contents, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) Creates and returns a compilation unit in this package fragment with the specified name and contents.Returns all of the class files in this package fragment.getClassFile
(String name) Returns the class file with the specified name in this package (for example,"Object.class"
).Veraltet.getCompilationUnit
(String name) Returns the compilation unit with the specified name in this package (for example,"Object.java"
).Returns all of the compilation units in this package fragment.Returns all of the compilation units in this package fragment that are in working copy mode and that have the given owner.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.Returns the class file for"module-info.class"
in this package.Object[]
Returns an array of non-Java resources contained in this package fragment.getOrdinaryClassFile
(String name) Returns the class file with the specified name in this package (for example,"Object.class"
).Returns all of the ordinary class files in this package fragment, i.e., not including the modular class file "module-info.class".boolean
Returns whether this package fragment's name is a prefix of other package fragments in this package fragment's root.boolean
Returns whether this package fragment is a default package.Von Schnittstelle geerbte Methoden org.eclipse.core.runtime.IAdaptable
getAdapter
Von Schnittstelle geerbte Methoden org.aspectj.org.eclipse.jdt.core.IJavaElement
exists, getAncestor, getAttachedJavadoc, getCorrespondingResource, getElementType, getHandleIdentifier, getJavaModel, getJavaProject, getOpenable, getParent, getPath, getPrimaryElement, getResource, getSchedulingRule, getUnderlyingResource, isReadOnly, isStructureKnown
Von Schnittstelle geerbte Methoden org.aspectj.org.eclipse.jdt.core.IOpenable
close, findRecommendedLineSeparator, getBuffer, hasUnsavedChanges, isConsistent, isOpen, makeConsistent, open, save
Von Schnittstelle geerbte Methoden org.aspectj.org.eclipse.jdt.core.IParent
getChildren, hasChildren
Von Schnittstelle geerbte Methoden org.aspectj.org.eclipse.jdt.core.ISourceManipulation
copy, delete, move, rename
-
Felddetails
-
DEFAULT_PACKAGE_NAME
The name of package fragment for the default package (value: the empty string,
""
).- Siehe auch:
-
-
Methodendetails
-
containsJavaResources
Returns whether this fragment contains at least one Java resource.- Gibt zurück:
- true if this fragment contains at least one Java resource, false otherwise
- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource.
-
createCompilationUnit
ICompilationUnit createCompilationUnit(String name, String contents, boolean force, org.eclipse.core.runtime.IProgressMonitor monitor) throws JavaModelException Creates and returns a compilation unit in this package fragment with the specified name and contents. No verification is performed on the contents.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 contents -
false
- in this case aJavaModelException
is thrown
- Parameter:
name
- the given namecontents
- the given contentsforce
- specify how to handle conflict is the same name already existsmonitor
- the given progress monitor- Gibt zurück:
- a compilation unit in this package fragment with the specified name and contents
- Löst aus:
JavaModelException
- if the element could not be created. Reasons include:- This Java element does not exist (ELEMENT_DOES_NOT_EXIST)
- A
CoreException
occurred while creating an underlying resource - The name is not a valid compilation unit name (INVALID_NAME)
- The contents are
null
(INVALID_CONTENTS)
-
-
getClassFile
Returns the class file with the specified name in this package (for example,"Object.class"
). The ".class" suffix is required. This is a handle-only method. The class file may or may not be present.This method can handle ordinary class files or modular class files denoted by the name
"module-info.class"
.- Parameter:
name
- the given name- Gibt zurück:
- the class file with the specified name in this package
-
getOrdinaryClassFile
Returns the class file with the specified name in this package (for example,"Object.class"
). The ".class" suffix is required. This is a handle-only method. The class file may or may not be present.This method is not applicable to the files
"module-info.class"
as introduced in Java 9. For those please usegetModularClassFile()
.- Parameter:
name
- the given name- Gibt zurück:
- the class file with the specified name in this package
- Seit:
- 3.14
-
getModularClassFile
IModularClassFile getModularClassFile()Returns the class file for"module-info.class"
in this package. This is a handle-only method. The class file may or may not be present. If the class file is present, then it is guaranteed to contain anIModuleDescription
.- Gibt zurück:
- the class file representing "module-info.class" in this package.
- Seit:
- 3.14
-
getAllClassFiles
Returns all of the class files in this package fragment.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.Note: the returned list may contain ordinary class files as well as a modular class file (for "module-info.class").
- Gibt zurück:
- all of the class files in this package fragment
- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource.- Seit:
- 3.14
-
getClassFiles
Veraltet.Clients are advised to specifically use eithergetOrdinaryClassFiles()
orgetAllClassFiles()
to express their intent.Returns all of the ordinary class files in this package fragment.Note: this list never includes a modular class file (see
getModularClassFile()
).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.- Gibt zurück:
- all of the ordinary class files in this package fragment
- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource.
-
getOrdinaryClassFiles
Returns all of the ordinary class files in this package fragment, i.e., not including the modular class file "module-info.class".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.- Gibt zurück:
- all of the ordinary class files in this package fragment
- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource.- Seit:
- 3.14
-
getCompilationUnit
Returns the compilation unit with the specified name in this package (for example,"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.- Parameter:
name
- the given name- Gibt zurück:
- the compilation unit with the specified name in this package
- Siehe auch:
-
getCompilationUnits
Returns all of the compilation units in this package fragment.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.- Gibt zurück:
- all of the compilation units in this package fragment
- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource.
-
getCompilationUnits
Returns all of the compilation units in this package fragment that are in working copy mode and that have the given owner.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.- Parameter:
owner
- the owner of the returned compilation units- Gibt zurück:
- all of the compilation units in this package fragment
- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource.- Seit:
- 3.0
-
getElementName
String getElementName()Returns the dot-separated package name of this fragment, for example"java.lang"
, or""
(the empty string), for the default package.- Angegeben von:
getElementName
in SchnittstelleIJavaElement
- Gibt zurück:
- the dot-separated package name of this fragment
-
getKind
Returns this package fragment's root kind encoded as an integer. A package fragment can contain source files (i.e. files with one of theJava-like extensions
), or.class
files. This is a convenience method.- Gibt zurück:
- this package fragment's root kind encoded as an integer
- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource.- Siehe auch:
-
getNonJavaResources
Returns an array of non-Java resources contained in this package fragment.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 theIJarEntryResource.getChildren()
andIJarEntryResource.getParent()
methods.- Gibt zurück:
- an array of non-Java resources (
IFile
s,IFolder
s, orIStorage
s if the package fragment is in an archive) contained in this package fragment - Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource.- Siehe auch:
-
hasSubpackages
Returns whether this package fragment's name is a prefix of other package fragments in this package fragment's root.- Gibt zurück:
- true if this package fragment's name is a prefix of other package fragments in this package fragment's root, false otherwise
- Löst aus:
JavaModelException
- if this element does not exist or if an exception occurs while accessing its corresponding resource.
-
isDefaultPackage
boolean isDefaultPackage()Returns whether this package fragment is a default package. This is a handle-only method.- Gibt zurück:
- true if this package fragment is a default package
-
getOrdinaryClassFiles()
orgetAllClassFiles()
to express their intent.