public interface IPackageFragment extends IParent, IJavaScriptElement, IOpenable, ISourceManipulation
Package fragments elements need to be opened before they can be navigated or manipulated.
The children are of type IJavaScriptUnit
(representing a source file) or
IClassFile
(representing a read-only file).
The children are listed in no particular order.
This interface is not intended to be implemented by clients.
Provisional API: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_PACKAGE_NAME
The name of package fragment for the default package (value: the empty
string,
"" ). |
CLASS_FILE, EXPORT_CONTAINER, EXPORT_DECLARATION, FIELD, IMPORT_CONTAINER, IMPORT_DECLARATION, INITIALIZER, JAVASCRIPT_MODEL, JAVASCRIPT_PROJECT, JAVASCRIPT_UNIT, LOCAL_VARIABLE, METHOD, PACKAGE_FRAGMENT, PACKAGE_FRAGMENT_ROOT, TYPE
Modifier and Type | Method and Description |
---|---|
boolean |
containsJavaResources()
Returns whether this fragment contains at least one JavaScript resource.
|
IJavaScriptUnit |
createCompilationUnit(java.lang.String name,
java.lang.String contents,
boolean force,
IProgressMonitor monitor)
Creates and returns a javaScript unit in this package fragment
with the specified name and contents.
|
IClassFile |
getClassFile(java.lang.String name)
Returns the non-editable file with the specified name
in this folder .
|
IClassFile[] |
getClassFiles()
Returns all of the non-editable files in this source folder.
|
java.lang.String |
getElementName()
Returns the dot-separated package name of this fragment, for example
"java.lang" , or "" (the empty string),
for the default package. |
IJavaScriptUnit |
getJavaScriptUnit(java.lang.String name)
Returns the javaScript unit with the specified name
in this package (for example,
"Object.js" ). |
IJavaScriptUnit[] |
getJavaScriptUnits()
Returns all of the javaScript units in this source folder.
|
IJavaScriptUnit[] |
getJavaScriptUnits(WorkingCopyOwner owner)
Returns all of the javaScript units in this source folder that are
in working copy mode and that have the given owner.
|
int |
getKind()
Returns this package fragment's root kind encoded as an integer.
|
java.lang.Object[] |
getNonJavaScriptResources()
Returns an array of non-JavaScript resources contained in this source folder.
|
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.
|
boolean |
isSource() |
getChildren, hasChildren
exists, getAncestor, getAttachedJavadoc, getCommonSuperType, getCorrespondingResource, getDisplayName, getElementType, getHandleIdentifier, getHostPath, getJavaScriptModel, getJavaScriptProject, getOpenable, getParent, getPath, getPrimaryElement, getResource, getSchedulingRule, getUnderlyingResource, isReadOnly, isStructureKnown, isVirtual
newNameLookup, newNameLookup, newSearchableNameEnvironment, newSearchableNameEnvironment
close, findRecommendedLineSeparator, getBuffer, hasUnsavedChanges, isConsistent, isOpen, makeConsistent, open, save
copy, delete, move, rename
static final java.lang.String DEFAULT_PACKAGE_NAME
The name of package fragment for the default package (value: the empty
string, ""
).
boolean containsJavaResources() throws JavaScriptModelException
JavaScriptModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.IJavaScriptUnit createCompilationUnit(java.lang.String name, java.lang.String contents, boolean force, IProgressMonitor monitor) throws JavaScriptModelException
It is possible that a javaScript unit with the same name already exists in this
package fragment.
The value of the force
parameter effects the resolution of
such a conflict:
true
- in this case the compilation is created with the new contentsfalse
- in this case a JavaScriptModelException
is throwncontents
- the given contentsforce
- specify how to handle conflict is the same name already existsmonitor
- the given progress monitorname
- the given nameJavaScriptModelException
- if the element could not be created. Reasons include:
CoreException
occurred while creating an underlying resource
null
(INVALID_CONTENTS)
IClassFile getClassFile(java.lang.String name)
name
- the given nameIClassFile[] getClassFiles() throws JavaScriptModelException
Note: it is possible that a package fragment contains only
javaScript units (in other words, its kind is K_SOURCE
), in
which case this method returns an empty collection.
JavaScriptModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.IJavaScriptUnit getJavaScriptUnit(java.lang.String name)
"Object.js"
).
The name has to be a valid javaScript unit name.
This is a handle-only method. The javaScript unit may or may not be present.name
- the given nameJavaScriptConventions.validateCompilationUnitName(String name, String sourceLevel, String complianceLevel)
IJavaScriptUnit[] getJavaScriptUnits() throws JavaScriptModelException
Note: it is possible that a source folder contains only
read-only files (in other words, its kind is K_BINARY
), in which
case this method returns an empty collection.
JavaScriptModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.IJavaScriptUnit[] getJavaScriptUnits(WorkingCopyOwner owner) throws JavaScriptModelException
Only existing working copies are returned. So a javaScript 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 source folder contains only
read-only files (in other words, its kind is K_BINARY
), in which
case this method returns an empty collection.
owner
- the owner of the returned javaScript unitsJavaScriptModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.java.lang.String getElementName()
"java.lang"
, or ""
(the empty string),
for the default package.getElementName
in interface IJavaScriptElement
int getKind() throws JavaScriptModelException
JavaScript-like extensions
),
or .class
files. This is a convenience method.JavaScriptModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.IPackageFragmentRoot.K_SOURCE
,
IPackageFragmentRoot.K_BINARY
java.lang.Object[] getNonJavaScriptResources() throws JavaScriptModelException
Non-JavaScript resources includes other files and folders located in the same directory as the javaScript units for this package fragment. Source files excluded from this package by virtue of inclusion/exclusion patterns on the corresponding source includepath entry are considered non-JavaScript resources and will appear in the result (possibly in a folder).
IFile
s,
IFolder
s, or IStorage
s if the
package fragment is in an archive) contained in this package
fragmentJavaScriptModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.IIncludePathEntry.getInclusionPatterns()
,
IIncludePathEntry.getExclusionPatterns()
boolean hasSubpackages() throws JavaScriptModelException
JavaScriptModelException
- if this element does not exist or if an
exception occurs while accessing its corresponding resource.boolean isDefaultPackage()
boolean isSource()
Copyright (c) IBM Corp. and others 2000, 2016. All Rights Reserved.