public class Elements
extends java.lang.Object
IElement
s.
Methods annotated as "handle-only" do not require underlying elements
to exist. Methods that require underlying elements to exist throw a
CoreException
when the underlying element is missing.
Note that, despite having a dependency on IResource
and IFile
,
this class can safely be used even when org.eclipse.core.resources
bundle is not available. This is based on the "outward impression" of late
resolution of symbolic references a JVM must provide according to the JVMS.
Modifier and Type | Field and Description |
---|---|
static Property<ISnapshot> |
BASE_SNAPSHOT
Specifies a base snapshot.
|
static Property<java.lang.Boolean> |
CREATE_BUFFER
Indicates whether a new buffer should be created if none already exists.
|
static IElement[] |
EMPTY_ARRAY
A zero-length array of the runtime type
IElement[] . |
static Property<java.lang.Boolean> |
FORCE_RECONCILING
Indicates whether reconciling has to be performed even if
the working copy buffer has not been modified since the last time
the working copy was reconciled.
|
static ISourceElementInfo |
NO_SOURCE_ELEMENT_INFO
A 'null object' indicating that no info is available for source element,
e.g., because the element does not exist.
|
Modifier and Type | Method and Description |
---|---|
static <T extends java.util.Collection<? super IElement>> |
collectParentChain(IElement element,
T collection)
Adds elements to the given collection starting from the given element
(inclusive) and going up through the parent chain to the root element
(inclusive).
|
static <T extends java.util.Collection<? super IElement>> |
collectParentChainUntil(IElement element,
T collection,
java.util.function.Predicate<? super IElement> until)
Adds elements to the given collection starting from the given element
(inclusive) and going up through the parent chain to the ancestor matched
by the given predicate (exclusive).
|
static boolean |
ensureReconciled(ISourceElement element,
org.eclipse.core.runtime.IProgressMonitor monitor)
Ensures that, if the given element is contained in a source file,
the source file is reconciled.
|
static boolean |
equalsAndSameParentChain(IElement element,
IElement other)
Returns whether the elements are equal and belong to the same parent chain.
|
static boolean |
exists(IElement element)
Returns whether the element exists in the model.
|
static <T> T |
findAncestorOfType(IElement element,
java.lang.Class<T> type)
Finds and returns the first element that has the given type starting from
the given element (inclusive) and going up through the parent chain.
|
static <T> T |
findAncestorOfTypeUntil(IElement element,
java.lang.Class<T> type,
java.util.function.Predicate<? super IElement> until)
Finds and returns the first element that has the given type starting from
the given element (inclusive) and going up through the parent chain
no further than the element matched by the given predicate (exclusive).
|
static IElement |
findCommonAncestor(IElement element,
IElement other)
Finds and returns the closest common ancestor of the given elements,
viewing each element as its own ancestor.
|
static IElement |
findCommonAncestor(java.lang.Iterable<? extends IElement> elements)
Finds and returns the closest common ancestor of the given elements,
viewing each element as its own ancestor.
|
static IElement |
findCommonAncestorUntil(IElement element,
IElement other,
java.util.function.Predicate<? super IElement> until)
Finds and returns the closest common ancestor of the given elements,
viewing each element as its own ancestor and looking no further in each
parent chain than the element matched by the given predicate (exclusive).
|
static IElement |
findCommonAncestorUntil(java.lang.Iterable<? extends IElement> elements,
java.util.function.Predicate<? super IElement> until)
Finds and returns the closest common ancestor of the given elements,
viewing each element as its own ancestor and looking no further in each
parent chain than the element matched by the given predicate (exclusive).
|
static <T> T |
findLastAncestorOfType(IElement element,
java.lang.Class<T> type)
Finds and returns the last element that has the given type starting from
the given element (inclusive) and going up through the parent chain to the
root element (inclusive).
|
static <T> T |
findLastAncestorOfTypeUntil(IElement element,
java.lang.Class<T> type,
java.util.function.Predicate<? super IElement> until)
Finds and returns the last element that has the given type starting from
the given element (inclusive) and going up through the parent chain to the
element matched by the given predicate (exclusive).
|
static IElement |
findLastMatchingAncestor(IElement element,
java.util.function.Predicate<? super IElement> filter)
Finds and returns the last element that matches the given predicate
starting from the given element (inclusive) and going up through the
parent chain to the root element (inclusive).
|
static IElement |
findLastMatchingAncestorUntil(IElement element,
java.util.function.Predicate<? super IElement> filter,
java.util.function.Predicate<? super IElement> until)
Finds and returns the last element that matches the given
filter
predicate starting from the given element (inclusive) and going up through
the parent chain to the element matched by the given until
predicate (exclusive). |
static IElement |
findMatchingAncestor(IElement element,
java.util.function.Predicate<? super IElement> filter)
Finds and returns the first element that matches the given predicate
starting from the given element (inclusive) and going up through
the parent chain.
|
static IElement |
findMatchingAncestorUntil(IElement element,
java.util.function.Predicate<? super IElement> filter,
java.util.function.Predicate<? super IElement> until)
Finds and returns the first element that matches the given
filter
predicate starting from the given element (inclusive) and going up through
the parent chain no further than the element matched by the given
until predicate (exclusive). |
static IBuffer |
getBuffer(ISourceFile sourceFile)
Returns a buffer opened for the source file.
|
static IBuffer |
getBuffer(ISourceFile sourceFile,
IContext context,
org.eclipse.core.runtime.IProgressMonitor monitor)
Returns a buffer opened for the source file.
|
static IElement[] |
getChildren(IElement element)
Returns the immediate children of the element.
|
static IElement[] |
getChildren(IElement element,
IContext context,
org.eclipse.core.runtime.IProgressMonitor monitor)
Returns the immediate children of the element.
|
static <T> T[] |
getChildrenOfType(IElement element,
java.lang.Class<T> type)
Returns the immediate children of the element that have the given type.
|
static <T> T[] |
getChildrenOfType(IElement element,
java.lang.Class<T> type,
IContext context,
org.eclipse.core.runtime.IProgressMonitor monitor)
Returns the immediate children of the element that have the given type.
|
static org.eclipse.core.resources.IFile |
getFile(ISourceFile sourceFile)
Returns the underlying
IFile , or null
if the source file has no underlying file in the workspace. |
static java.lang.String |
getHandleMemento(IElement element)
Returns a string representation of the element handle that can be used
to recreate the handle via the model's
IElementHandleFactory . |
static java.net.URI |
getLocationUri(IElement element)
Returns a file system location for the element.
|
static IModel |
getModel(IElement element)
Returns the model that owns the element.
|
static int |
getModelApiLevel(IElement element)
Returns the Handly API level supported by the element's model;
one of the level constants declared in
ApiLevel . |
static IContext |
getModelContext(IElement element)
Returns a context which provides information and services pertaining
to the element's model.
|
static java.lang.String |
getName(IElement element)
Returns the name of the element, or
null
if the element has no name. |
static IElement |
getParent(IElement element)
Returns the immediate parent of the element,
or
null if the element has no parent. |
static java.lang.Iterable<IElement> |
getParentChain(IElement element)
Returns an
Iterable that starts from the given element
(inclusive) and goes up through the parent chain to the root element
(inclusive). |
static java.lang.Iterable<IElement> |
getParentChainUntil(IElement element,
java.util.function.Predicate<? super IElement> until)
Returns an
Iterable that starts from the given element
(inclusive) and goes up through the parent chain to the ancestor matched
by the given predicate (exclusive). |
static org.eclipse.core.resources.IResource |
getResource(IElement element)
Returns the innermost resource enclosing the element, or
null
if the element is not enclosed in a workspace resource. |
static IElement |
getRoot(IElement element)
Returns the root element for the element.
|
static ISourceElement |
getSourceElementAt(ISourceElement element,
int position,
IContext context,
org.eclipse.core.runtime.IProgressMonitor monitor)
Returns the smallest element that includes the given source position,
or
null if the given position is not within the source range
of the given element. |
static ISourceElement |
getSourceElementAt(ISourceElement element,
int position,
ISnapshot base)
Returns the smallest element that includes the given source position,
or
null if the given position is not within the source range
of the given element. |
static ISourceElement |
getSourceElementAt2(ISourceElement element,
int position,
ISnapshot base)
Returns the smallest element that includes the given position,
or
null if the given position is not within the source
range of the given element, or if the given element does not exist or
an exception occurs while accessing its corresponding resource, or if
snapshot inconsistency is detected. |
static ISourceElementInfo |
getSourceElementInfo(ISourceElement element)
Returns an object holding cached structure and properties for the
source element.
|
static ISourceElementInfo |
getSourceElementInfo(ISourceElement element,
IContext context,
org.eclipse.core.runtime.IProgressMonitor monitor)
Returns an object holding cached structure and properties for the
source element.
|
static ISourceElementInfo |
getSourceElementInfo2(ISourceElement element)
Returns an object holding cached structure and properties for the
source element, or
NO_SOURCE_ELEMENT_INFO if no such info
is available. |
static ISourceFile |
getSourceFile(IElement element)
Returns the source file that contains the given element,
or
null if the given element is not contained in a
source file. |
static boolean |
isAncestorOf(IElement element,
IElement other)
Returns whether both elements belong to the same parent chain and the
first element is equal to or is an ancestor of the other element.
|
static boolean |
isOfModel(IElement element,
IModel model)
Returns whether the element belongs to the given model.
|
static boolean |
isWorkingCopy(ISourceFile sourceFile)
Returns whether the source file is a working copy.
|
static boolean |
needsReconciling(ISourceFile sourceFile)
Returns whether the source file needs reconciling.
|
static void |
reconcile(ISourceFile sourceFile,
IContext context,
org.eclipse.core.runtime.IProgressMonitor monitor)
Reconciles the source file.
|
static void |
reconcile(ISourceFile sourceFile,
org.eclipse.core.runtime.IProgressMonitor monitor)
Reconciles the source file.
|
static void |
removeDescendants(java.util.Collection<? extends IElement> elements)
Removes descendants from the given collection of elements; in other words,
removes those elements for which an ancestor is also present in the given
collection.
|
static void |
splitIntoElementsAndResources(java.lang.Iterable<?> objects,
java.util.Collection<? super IElement> elements,
IModel model,
java.util.Collection<? super org.eclipse.core.resources.IResource> resources,
IElementHandleFactory elementHandleFactory)
Splits the given objects into a collection of
IElement s and
a collection of IResource s, ignoring objects that are neither
elements nor resources. |
static java.util.stream.Stream<IElement> |
streamParentChain(IElement element)
Returns a sequential ordered stream that starts from the given element
(inclusive) and goes up through the parent chain to the root element
(inclusive).
|
static java.util.stream.Stream<IElement> |
streamParentChainUntil(IElement element,
java.util.function.Predicate<? super IElement> until)
Returns a sequential ordered stream that starts from the given element
(inclusive) and goes up through the parent chain to the ancestor matched
by the given predicate (exclusive).
|
static java.lang.String |
toDisplayString(IElement element,
IContext context)
Returns a string representation of the element in a form suitable for
displaying to the user, e.g., in message dialogs.
|
static java.lang.String |
toString(IElement element,
IContext context)
Returns a string representation of the element in a form suitable for
debugging purposes.
|
public static final IElement[] EMPTY_ARRAY
IElement[]
.public static final ISourceElementInfo NO_SOURCE_ELEMENT_INFO
The instance methods return either null
(if allowed
by method contract) or an appropriate 'null object' (such as
a zero-length array).
getSourceElementInfo2(ISourceElement)
public static final Property<java.lang.Boolean> FORCE_RECONCILING
false
.public static final Property<java.lang.Boolean> CREATE_BUFFER
true
.public static java.lang.String getName(IElement element)
null
if the element has no name. This is a handle-only method.element
- not null
null
if the element has no namepublic static IElement getParent(IElement element)
null
if the element has no parent.
This is a handle-only method.element
- not null
null
if the element has
no parentpublic static IElement getRoot(IElement element)
element
- not null
null
)public static java.lang.Iterable<IElement> getParentChain(IElement element)
Iterable
that starts from the given element
(inclusive) and goes up through the parent chain to the root element
(inclusive). This is a handle-only method.
This method is equivalent to getParentChainUntil(element, null)
.
element
- may be null
, in which case an empty iterable
will be returnednull
)public static java.lang.Iterable<IElement> getParentChainUntil(IElement element, java.util.function.Predicate<? super IElement> until)
Iterable
that starts from the given element
(inclusive) and goes up through the parent chain to the ancestor matched
by the given predicate (exclusive). If the predicate is not matched or
is null
, all ancestors will be included. If the predicate
matches the given element, the returned iterable will be empty.
This is a handle-only method.element
- may be null
, in which case an empty iterable
will be returneduntil
- may be null
null
)public static java.util.stream.Stream<IElement> streamParentChain(IElement element)
This method is equivalent to streamParentChainUntil(element, null)
.
element
- may be null
, in which case an empty stream
will be returnednull
)public static java.util.stream.Stream<IElement> streamParentChainUntil(IElement element, java.util.function.Predicate<? super IElement> until)
null
, all ancestors will be included. If the predicate
matches the given element, the returned stream will be empty.
This is a handle-only method.element
- may be null
, in which case an empty stream
will be returneduntil
- may be null
null
)public static <T extends java.util.Collection<? super IElement>> T collectParentChain(IElement element, T collection)
This method is equivalent to collectParentChainUntil(element, null)
.
element
- may be null
, in which case no elements
will be added to the given collectioncollection
- not null
collection
instancepublic static <T extends java.util.Collection<? super IElement>> T collectParentChainUntil(IElement element, T collection, java.util.function.Predicate<? super IElement> until)
null
, all ancestors will be included. If the predicate
matches the given element, no elements will be added to the collection.
This is a handle-only method.element
- may be null
, in which case no elements
will be added to the given collectioncollection
- not null
until
- may be null
collection
instancepublic static IElement findMatchingAncestor(IElement element, java.util.function.Predicate<? super IElement> filter)
null
if no such element
can be found. This is a handle-only method.
This method is equivalent to findMatchingAncestorUntil(element,
filter, null)
.
element
- may be null
, in which case null
will be returnedfilter
- not null
null
if no such element
can be foundpublic static IElement findMatchingAncestorUntil(IElement element, java.util.function.Predicate<? super IElement> filter, java.util.function.Predicate<? super IElement> until)
filter
predicate starting from the given element (inclusive) and going up through
the parent chain no further than the element matched by the given
until
predicate (exclusive). Returns null
if no such element can be found. If the until
predicate
is not matched or is null
, all ancestors will be included.
If the until
predicate matches the given element,
null
will be returned. This is a handle-only method.element
- may be null
, in which case null
will be returnedfilter
- not null
until
- may be null
null
if no such element
can be foundpublic static <T> T findAncestorOfType(IElement element, java.lang.Class<T> type)
null
if no such element can be found. This is a handle-only
method.
This method is equivalent to findAncestorOfTypeUntil(element,
type, null)
.
element
- may be null
, in which case null
will be returnedtype
- not null
null
if no such element
can be foundpublic static <T> T findAncestorOfTypeUntil(IElement element, java.lang.Class<T> type, java.util.function.Predicate<? super IElement> until)
null
if no such element can be found. If the predicate
is not matched or is null
, all ancestors will be included.
If the predicate matches the given element, null
will be
returned. This is a handle-only method.element
- may be null
, in which case null
will be returnedtype
- not null
until
- may be null
null
if no such element
can be foundpublic static IElement findLastMatchingAncestor(IElement element, java.util.function.Predicate<? super IElement> filter)
null
if no such element can be found. This is a handle-only method.
This method is equivalent to findLastMatchingAncestorUntil(element,
filter, null)
.
element
- may be null
, in which case null
will be returnedfilter
- not null
null
if no such element
can be foundpublic static IElement findLastMatchingAncestorUntil(IElement element, java.util.function.Predicate<? super IElement> filter, java.util.function.Predicate<? super IElement> until)
filter
predicate starting from the given element (inclusive) and going up through
the parent chain to the element matched by the given until
predicate (exclusive). Returns null
if no such element can
be found. If the until
predicate is not matched or is
null
, all ancestors will be included. If the until
predicate matches the given element, null
will be returned.
This is a handle-only method.element
- may be null
, in which case null
will be returnedfilter
- not null
until
- may be null
null
if no such element
can be foundpublic static <T> T findLastAncestorOfType(IElement element, java.lang.Class<T> type)
null
if no such element
can be found. This is a handle-only method.
This method is equivalent to findLastAncestorOfTypeUntil(element,
type, null)
.
element
- may be null
, in which case null
will be returnedtype
- not null
null
if no such element
can be foundpublic static <T> T findLastAncestorOfTypeUntil(IElement element, java.lang.Class<T> type, java.util.function.Predicate<? super IElement> until)
null
if no such element can be found. If the predicate is not matched or is
null
, all ancestors will be included. If the predicate
matches the given element, null
will be returned.
This is a handle-only method.element
- may be null
, in which case null
will be returnedtype
- not null
until
- may be null
null
if no such element
can be foundpublic static IElement findCommonAncestor(IElement element, IElement other)
null
if no such element can be found. This is a handle-only method.
This method is equivalent to
findCommonAncestorUntil(element, other, null)
.
element
- may be null
, in which case null
will be returnedother
- may be null
, in which case null
will be returnednull
if no such element
can be foundpublic static IElement findCommonAncestorUntil(IElement element, IElement other, java.util.function.Predicate<? super IElement> until)
null
if no such element can be found. If the predicate
is not matched or is null
, all ancestors will be included.
If the predicate matches any of the given elements, null
will be returned. This is a handle-only method.element
- may be null
, in which case null
will be returnedother
- may be null
, in which case null
will be returneduntil
- may be null
null
if no such element
can be foundpublic static IElement findCommonAncestor(java.lang.Iterable<? extends IElement> elements)
null
if no such element can be found. This is a handle-only method.
This method is equivalent to
findCommonAncestorUntil(elements, null)
.
elements
- not null
, may contain nullsnull
if no such element
can be foundpublic static IElement findCommonAncestorUntil(java.lang.Iterable<? extends IElement> elements, java.util.function.Predicate<? super IElement> until)
null
if no such element can be found. If the predicate
is not matched or is null
, all ancestors will be included.
If the predicate matches any of the given elements, null
will be returned. This is a handle-only method.elements
- not null
, may contain nullsuntil
- may be null
null
if no such element
can be foundpublic static boolean isAncestorOf(IElement element, IElement other)
element
- not null
other
- may be null
, in which case false
will be returnedtrue
if both elements belong to the same parent
chain and the first element is equal to or an ancestor of the other
element, and false
otherwisepublic static void removeDescendants(java.util.Collection<? extends IElement> elements)
elements
- not null
, must not contain null
elementspublic static boolean equalsAndSameParentChain(IElement element, IElement other)
In the most general case, equal elements may belong to different parent chains. For example, in JDT, equal JarPackageFragmentRoots may belong to different Java projects.
element
- not null
other
- may be null
true
if the elements are equal and belong to the same
parent chain, and false
otherwisepublic static IModel getModel(IElement element)
element
- not null
null
)public static boolean isOfModel(IElement element, IModel model)
true
if, and only if, model.equals(getModel(element))
.
This is a handle-only method.element
- not null
model
- not null
true
if the element belongs to the given model,
and false
otherwisepublic static IContext getModelContext(IElement element)
element
- not null
null
)public static int getModelApiLevel(IElement element)
ApiLevel
. This is a handle-only method.element
- not null
public static java.lang.String getHandleMemento(IElement element)
IElementHandleFactory
.
The format of the string is not specified, but the representation is
stable across workbench sessions. This is a handle-only method.element
- not null
null
if the element is unable to provide a handle mementopublic static org.eclipse.core.resources.IResource getResource(IElement element)
null
if the element is not enclosed in a workspace resource.
This is a handle-only method.
Note that it is safe to call this method and test the return value
for null
even when org.eclipse.core.resources
bundle is not available.
element
- not null
null
if the element is not enclosed in a workspace resourcepublic static void splitIntoElementsAndResources(java.lang.Iterable<?> objects, java.util.Collection<? super IElement> elements, IModel model, java.util.Collection<? super org.eclipse.core.resources.IResource> resources, IElementHandleFactory elementHandleFactory)
IElement
s and
a collection of IResource
s, ignoring objects that are neither
elements nor resources. The given element handle factory is used to
translate resources to elements; if a resource has a corresponding
existing element, the element will be added instead of the resource.
This is a handle-only method.objects
- not null
, may contain null
elementselements
- not null
model
- may be null
. If not null
, only
elements belonging to the model will be added to the elements
collectionresources
- may be null
. If null
,
no checks for instanceof IResource
will be doneelementHandleFactory
- may be null
. If null
,
resources will be added without first trying to translate them to elementspublic static java.net.URI getLocationUri(IElement element)
EFS.getStore(URI)
. Returns
null
if no location can be determined.element
- not null
null
if no location can be determinedpublic static boolean exists(IElement element)
Handles may or may not be backed by an actual element. Handles that are backed by an actual element are said to "exist".
element
- not null
true
if the element exists in the model, and
false
if the element does not existpublic static IElement[] getChildren(IElement element) throws org.eclipse.core.runtime.CoreException
element
- not null
null
).
Clients must not modify the returned array.org.eclipse.core.runtime.CoreException
- if the element does not exist or if an
exception occurs while accessing its corresponding resourcepublic static IElement[] getChildren(IElement element, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
element
- not null
context
- the operation context (not null
)monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receivernull
).
Clients must not modify the returned array.org.eclipse.core.runtime.CoreException
- if the element does not exist or if an
exception occurs while accessing its corresponding resourcepublic static <T> T[] getChildrenOfType(IElement element, java.lang.Class<T> type) throws org.eclipse.core.runtime.CoreException
element
- not null
type
- not null
null
). Clients must not modify the returned
array.org.eclipse.core.runtime.CoreException
- if the element does not exist or if an
exception occurs while accessing its corresponding resourcepublic static <T> T[] getChildrenOfType(IElement element, java.lang.Class<T> type, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
element
- not null
type
- not null
context
- the operation context (not null
)monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receivernull
). Clients must not modify the returned
array.org.eclipse.core.runtime.CoreException
- if the element does not exist or if an
exception occurs while accessing its corresponding resourcepublic static java.lang.String toString(IElement element, IContext context)
Model implementations are encouraged to support common options defined in
ToStringOptions
and
interpret the FORMAT_STYLE
as follows:
element
- not null
context
- not null
null
)public static java.lang.String toDisplayString(IElement element, IContext context)
Model implementations are encouraged to support common options defined in
ToStringOptions
and may
interpret the FORMAT_STYLE
as they see fit in a way that is specific to the model.
No hard rules apply, but usually the string representation does not list
the element's children regardless of the format style, and a FULL
representation fully identifies the element within the model.
element
- not null
context
- not null
null
)public static ISourceElement getSourceElementAt(ISourceElement element, int position, ISnapshot base) throws org.eclipse.core.runtime.CoreException
null
if the given position is not within the source range
of the given element. If no finer grained element is found at the
position, the given element itself is returned.element
- a source element (not null
)position
- a source position (0-based)base
- a snapshot on which the given position is based,
or null
if the snapshot is unknown or does not matternull
if none (including the given element itself)org.eclipse.core.runtime.CoreException
- if the given element does not exist or if an
exception occurs while accessing its corresponding resourceStaleSnapshotException
- if snapshot inconsistency is detected,
i.e., the given element's current structure and properties are based on
a different snapshotpublic static ISourceElement getSourceElementAt(ISourceElement element, int position, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
null
if the given position is not within the source range
of the given element. If no finer grained element is found at the
position, the given element itself is returned.
Model implementations are encouraged to support the following standard options, which may be specified in the given context:
BASE_SNAPSHOT
- A snapshot on which the given position is based,
or null
if the snapshot is unknown or does not matter.
element
- a source element (not null
)position
- a source position (0-based)context
- the operation context (not null
)monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receivernull
if none (including the given element itself)org.eclipse.core.runtime.CoreException
- if the given element does not exist or if an
exception occurs while accessing its corresponding resourceStaleSnapshotException
- if snapshot inconsistency is detected,
i.e., the given element's current structure and properties are based on
a different snapshotpublic static ISourceElement getSourceElementAt2(ISourceElement element, int position, ISnapshot base)
null
if the given position is not within the source
range of the given element, or if the given element does not exist or
an exception occurs while accessing its corresponding resource, or if
snapshot inconsistency is detected. If no finer grained element is
found at the position, the given element itself is returned.element
- a source element (not null
)position
- a source position (0-based)base
- a snapshot on which the given position is based,
or null
if the snapshot is unknown or does not matternull
if none (including the given element itself)public static ISourceElementInfo getSourceElementInfo(ISourceElement element) throws org.eclipse.core.runtime.CoreException
element
- not null
ISourceElementInfo
for the element
(never null
)org.eclipse.core.runtime.CoreException
- if the element does not exist or if an
exception occurs while accessing its corresponding resourcepublic static ISourceElementInfo getSourceElementInfo(ISourceElement element, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
element
- not null
context
- the operation context (not null
)monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receiverISourceElementInfo
for the element
(never null
)org.eclipse.core.runtime.CoreException
- if the element does not exist or if an
exception occurs while accessing its corresponding resourcepublic static ISourceElementInfo getSourceElementInfo2(ISourceElement element)
NO_SOURCE_ELEMENT_INFO
if no such info
is available.element
- not null
ISourceElementInfo
for the element
(never null
)public static ISourceFile getSourceFile(IElement element)
null
if the given element is not contained in a
source file. Returns the given element itself if it is a source file.
This is a handle-only method.element
- may be null
, in which case null
will be returnednull
if nonepublic static boolean ensureReconciled(ISourceElement element, org.eclipse.core.runtime.IProgressMonitor monitor)
element
- not null
monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receivertrue
if the call completed successfully,
and false
in case of a failureorg.eclipse.core.runtime.OperationCanceledException
- if this method is canceledpublic static org.eclipse.core.resources.IFile getFile(ISourceFile sourceFile)
IFile
, or null
if the source file has no underlying file in the workspace.
This is a handle-only method.
This method returns the same value as getResource(IElement)
,
but saves a downcast.
sourceFile
- not null
IFile
, or null
if the source file has no underlying file in the workspacepublic static boolean isWorkingCopy(ISourceFile sourceFile)
sourceFile
- not null
true
if the source file is a working copy,
and false
otherwisepublic static boolean needsReconciling(ISourceFile sourceFile)
sourceFile
- not null
true
if the source file needs reconciling,
and false
otherwisepublic static void reconcile(ISourceFile sourceFile, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
sourceFile
- not null
monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receiverorg.eclipse.core.runtime.CoreException
- if the working copy could not be reconciledorg.eclipse.core.runtime.OperationCanceledException
- if this method is canceledpublic static void reconcile(ISourceFile sourceFile, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
Model implementations are encouraged to support the following standard options, which may be specified in the given context:
FORCE_RECONCILING
- Indicates whether reconciling has to be
performed even if the working copy buffer has not been modified since
the last time the working copy was reconciled.
sourceFile
- not null
context
- the operation context (not null
)monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receiverorg.eclipse.core.runtime.CoreException
- if the working copy could not be reconciledorg.eclipse.core.runtime.OperationCanceledException
- if this method is canceledpublic static IBuffer getBuffer(ISourceFile sourceFile) throws org.eclipse.core.runtime.CoreException
The client takes (potentially shared) ownership of the returned buffer and is responsible for releasing it when finished. The buffer will be disposed only after it is released by every owner. The buffer must not be accessed by clients which do not own it.
A new object may be returned, even for the same underlying buffer, each time this method is invoked. For working copies, the relationship between the source file and the underlying working copy buffer does not change over the lifetime of a working copy.
sourceFile
- not null
null
)org.eclipse.core.runtime.CoreException
- if the source file does not exist or if an
exception occurs while accessing its corresponding resourcepublic static IBuffer getBuffer(ISourceFile sourceFile, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
The client takes (potentially shared) ownership of the returned buffer and is responsible for releasing it when finished. The buffer will be disposed only after it is released by every owner. The buffer must not be accessed by clients which do not own it.
A new object may be returned, even for the same underlying buffer, each time this method is invoked. For working copies, the relationship between the source file and the underlying working copy buffer does not change over the lifetime of a working copy.
Model implementations are encouraged to support the following standard options, which may be specified in the given context:
CREATE_BUFFER
- Indicates whether a new buffer should be created
if none already exists for the source file.
sourceFile
- not null
context
- the operation context (not null
)monitor
- a progress monitor, or null
if progress reporting is not desired. The caller must not rely on
IProgressMonitor.done()
having been called by the receivernull
if CREATE_BUFFER
is false
in the given context
and there is no buffer currently opened for the source fileorg.eclipse.core.runtime.CoreException
- if the source file does not exist or if an
exception occurs while accessing its corresponding resourceorg.eclipse.core.runtime.OperationCanceledException
- if this method is canceledCopyright (c) 2014, 2018 1C-Soft LLC and others. Made available under the Eclipse Public License 2.0