org.eclipse.wst.jsdt.core
Interface IPackageFragment

All Superinterfaces:
IJavaScriptElement, ILookupScope, IOpenable, IParent, ISourceManipulation

public interface IPackageFragment
extends IParent, IJavaScriptElement, IOpenable, ISourceManipulation

A package fragment (or source folder) is a portion of the workspace corresponding to an entire package, or to a portion thereof. The distinction between a package fragment and a package is that a package with some name is the union of all package fragments in the includepath which have the same name.

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.


Field Summary
static java.lang.String DEFAULT_PACKAGE_NAME
           The name of package fragment for the default package (value: the empty string, "").
 
Fields inherited from interface org.eclipse.wst.jsdt.core.IJavaScriptElement
CLASS_FILE, FIELD, IMPORT_CONTAINER, IMPORT_DECLARATION, INITIALIZER, JAVASCRIPT_MODEL, JAVASCRIPT_PROJECT, JAVASCRIPT_UNIT, LOCAL_VARIABLE, METHOD, PACKAGE_DECLARATION, PACKAGE_FRAGMENT, PACKAGE_FRAGMENT_ROOT, TYPE, TYPE_PARAMETER
 
Method Summary
 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()
           
 
Methods inherited from interface org.eclipse.wst.jsdt.core.IParent
getChildren, hasChildren
 
Methods inherited from interface org.eclipse.wst.jsdt.core.IJavaScriptElement
exists, getAncestor, getAttachedJavadoc, getCommonSuperType, getCorrespondingResource, getDisplayName, getElementType, getHandleIdentifier, getHostPath, getJavaScriptModel, getJavaScriptProject, getOpenable, getParent, getPath, getPrimaryElement, getResource, getSchedulingRule, getUnderlyingResource, isReadOnly, isStructureKnown, isVirtual
 
Methods inherited from interface org.eclipse.wst.jsdt.core.ILookupScope
newNameLookup, newNameLookup, newSearchableNameEnvironment, newSearchableNameEnvironment
 
Methods inherited from interface org.eclipse.wst.jsdt.core.IOpenable
close, findRecommendedLineSeparator, getBuffer, hasUnsavedChanges, isConsistent, isOpen, makeConsistent, open, save
 
Methods inherited from interface org.eclipse.wst.jsdt.core.ISourceManipulation
copy, delete, move, rename
 

Field Detail

DEFAULT_PACKAGE_NAME

static final java.lang.String DEFAULT_PACKAGE_NAME

The name of package fragment for the default package (value: the empty string, "").

See Also:
Constant Field Values
Method Detail

containsJavaResources

boolean containsJavaResources()
                              throws JavaScriptModelException
Returns whether this fragment contains at least one JavaScript resource.

Returns:
true if this fragment contains at least one JavaScript resource, false otherwise
Throws:
JavaScriptModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource.

createCompilationUnit

IJavaScriptUnit createCompilationUnit(java.lang.String name,
                                      java.lang.String contents,
                                      boolean force,
                                      IProgressMonitor monitor)
                                      throws JavaScriptModelException
Creates and returns a javaScript unit in this package fragment with the specified name and contents. No verification is performed on the contents.

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:

Parameters:
contents - the given contents
force - specify how to handle conflict is the same name already exists
monitor - the given progress monitor
name - the given name
Returns:
a javaScript unit in this package fragment with the specified name and contents
Throws:
JavaScriptModelException - if the element could not be created. Reasons include:
  • This JavaScript element does not exist (ELEMENT_DOES_NOT_EXIST)
  • A CoreException occurred while creating an underlying resource
  • The name is not a valid javaScript unit name (INVALID_NAME)
  • The contents are null (INVALID_CONTENTS)

getClassFile

IClassFile getClassFile(java.lang.String name)
Returns the non-editable file with the specified name in this folder . This is a handle-only method. The file may or may not be present.

Parameters:
name - the given name
Returns:
the file with the specified name in this package

getClassFiles

IClassFile[] getClassFiles()
                           throws JavaScriptModelException
Returns all of the non-editable files in this source folder.

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.

Returns:
all of the files in this source folder
Throws:
JavaScriptModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource.

getJavaScriptUnit

IJavaScriptUnit getJavaScriptUnit(java.lang.String name)
Returns the javaScript unit with the specified name in this package (for example, "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.

Parameters:
name - the given name
Returns:
the javaScript unit with the specified name in this package
See Also:
JavaScriptConventions.validateCompilationUnitName(String name, String sourceLevel, String complianceLevel)

getJavaScriptUnits

IJavaScriptUnit[] getJavaScriptUnits()
                                     throws JavaScriptModelException
Returns all of the javaScript units in this source folder.

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.

Returns:
all of the javaScript units in this source folder
Throws:
JavaScriptModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource.

getJavaScriptUnits

IJavaScriptUnit[] getJavaScriptUnits(WorkingCopyOwner owner)
                                     throws JavaScriptModelException
Returns all of the javaScript units in this source folder that are in working copy mode and that have the given owner.

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.

Parameters:
owner - the owner of the returned javaScript units
Returns:
all of the javaScript units in this source folder
Throws:
JavaScriptModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource.

getElementName

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.

Specified by:
getElementName in interface IJavaScriptElement
Returns:
the dot-separated package name of this fragment

getKind

int getKind()
            throws JavaScriptModelException
Returns this package fragment's root kind encoded as an integer. A package fragment can contain source files (i.e. files with one of the JavaScript-like extensions), or .class files. This is a convenience method.

Returns:
this package fragment's root kind encoded as an integer
Throws:
JavaScriptModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource.
See Also:
IPackageFragmentRoot.K_SOURCE, IPackageFragmentRoot.K_BINARY

getNonJavaScriptResources

java.lang.Object[] getNonJavaScriptResources()
                                             throws JavaScriptModelException
Returns an array of non-JavaScript resources contained in this source folder.

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).

Returns:
an array of non-JavaScript resources (IFiles, IFolders, or IStorages if the package fragment is in an archive) contained in this package fragment
Throws:
JavaScriptModelException - if this element does not exist or if an exception occurs while accessing its corresponding resource.
See Also:
IIncludePathEntry.getInclusionPatterns(), IIncludePathEntry.getExclusionPatterns()

hasSubpackages

boolean hasSubpackages()
                       throws JavaScriptModelException
Returns whether this package fragment's name is a prefix of other package fragments in this package fragment's root.

Returns:
true if this package fragment's name is a prefix of other package fragments in this package fragment's root, false otherwise
Throws:
JavaScriptModelException - 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.

Returns:
true if this package fragment is a default package

isSource

boolean isSource()