Class Elements
- java.lang.Object
-
- org.eclipse.handly.model.Elements
-
public class Elements extends java.lang.ObjectProvides static methods for generic access toIElements.Methods annotated as "handle-only" do not require underlying elements to exist. Methods that require underlying elements to exist throw a
CoreExceptionwhen the underlying element is missing.Note that, despite having a dependency on
IResourceandIFile, this class can safely be used even whenorg.eclipse.core.resourcesbundle is not available. This is based on the "outward impression" of late resolution of symbolic references a JVM must provide according to the JVMS. Since 1.3, there is also a similar dependency onIFileStore.
-
-
Field Summary
Fields Modifier and Type Field Description static Property<ISnapshot>BASE_SNAPSHOTSpecifies a base snapshot.static Property<java.lang.Boolean>CREATE_BUFFERIndicates whether a new buffer should be created if none already exists.static IElement[]EMPTY_ARRAYA zero-length array of the runtime typeIElement[].static Property<java.lang.Boolean>FORCE_RECONCILINGIndicates 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 ISourceElementInfoNO_SOURCE_ELEMENT_INFOA 'null object' indicating that no info is available for source element, e.g., because the element does not exist.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends java.util.Collection<? super IElement>>
TcollectParentChain(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>>
TcollectParentChainUntil(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 booleanensureReconciled(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 booleanequalsAndSameParentChain(IElement element, IElement other)Returns whether the elements are equal and belong to the same parent chain.static booleanexists(IElement element)Returns whether the element exists in the model.static <T> TfindAncestorOfType(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> TfindAncestorOfTypeUntil(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 IElementfindCommonAncestor(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 IElementfindCommonAncestor(IElement element, IElement other)Finds and returns the closest common ancestor of the given elements, viewing each element as its own ancestor.static IElementfindCommonAncestorUntil(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 IElementfindCommonAncestorUntil(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 <T> TfindLastAncestorOfType(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> TfindLastAncestorOfTypeUntil(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 IElementfindLastMatchingAncestor(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 IElementfindLastMatchingAncestorUntil(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 givenfilterpredicate starting from the given element (inclusive) and going up through the parent chain to the element matched by the givenuntilpredicate (exclusive).static IElementfindMatchingAncestor(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 IElementfindMatchingAncestorUntil(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 givenfilterpredicate starting from the given element (inclusive) and going up through the parent chain no further than the element matched by the givenuntilpredicate (exclusive).static IBuffergetBuffer(ISourceFile sourceFile)Returns a buffer opened for the source file.static IBuffergetBuffer(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.IFilegetFile(ISourceFile sourceFile)Returns the underlyingIFile, ornullif the source file has no underlying file in the workspace.static org.eclipse.core.filesystem.IFileStoregetFileStore(ISourceFile sourceFile)Returns the correspondingIFileStore, ornullif the source file has no corresponding file store.static java.lang.StringgetHandleMemento(IElement element)Returns a string representation of the element handle that can be used to recreate the handle via the model'sIElementHandleFactory.static java.net.URIgetLocationUri(IElement element)Returns a file system location for the element.static IModelgetModel(IElement element)Returns the model that owns the element.static intgetModelApiLevel(IElement element)Returns the Handly API level supported by the element's model; one of the level constants declared inApiLevel.static IContextgetModelContext(IElement element)Returns a context which provides information and services pertaining to the element's model.static java.lang.StringgetName(IElement element)Returns the name of the element, ornullif the element has no name.static IElementgetParent(IElement element)Returns the immediate parent of the element, ornullif the element has no parent.static java.lang.Iterable<IElement>getParentChain(IElement element)Returns anIterablethat 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 anIterablethat 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.IResourcegetResource(IElement element)Returns the innermost resource enclosing the element, ornullif the element is not enclosed in a workspace resource.static IElementgetRoot(IElement element)Returns the root element for the element.static ISourceElementgetSourceElementAt(ISourceElement element, int position, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor)Returns the smallest element that includes the given source position, ornullif the given position is not within the source range of the given element.static ISourceElementgetSourceElementAt(ISourceElement element, int position, ISnapshot base)Returns the smallest element that includes the given source position, ornullif the given position is not within the source range of the given element.static ISourceElementgetSourceElementAt2(ISourceElement element, int position, ISnapshot base)Returns the smallest element that includes the given position, ornullif 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 ISourceElementInfogetSourceElementInfo(ISourceElement element)Returns an object holding cached structure and properties for the source element.static ISourceElementInfogetSourceElementInfo(ISourceElement element, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor)Returns an object holding cached structure and properties for the source element.static ISourceElementInfogetSourceElementInfo2(ISourceElement element)Returns an object holding cached structure and properties for the source element, orNO_SOURCE_ELEMENT_INFOif no such info is available.static ISourceFilegetSourceFile(IElement element)Returns the source file that contains the given element, ornullif the given element is not contained in a source file.static booleanisAncestorOf(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 booleanisOfModel(IElement element, IModel model)Returns whether the element belongs to the given model.static booleanisWorkingCopy(ISourceFile sourceFile)Returns whether the source file is a working copy.static booleanneedsReconciling(ISourceFile sourceFile)Returns whether the source file needs reconciling.static voidreconcile(ISourceFile sourceFile, org.eclipse.core.runtime.IProgressMonitor monitor)Reconciles the source file.static voidreconcile(ISourceFile sourceFile, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor)Reconciles the source file.static voidremoveDescendants(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 voidsplitIntoElementsAndResources(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 ofIElements and a collection ofIResources, 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.StringtoDisplayString(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.StringtoString(IElement element, IContext context)Returns a string representation of the element in a form suitable for debugging purposes.
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final IElement[] EMPTY_ARRAY
A zero-length array of the runtime typeIElement[].
-
NO_SOURCE_ELEMENT_INFO
public static final 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.The instance methods return either
null(if allowed by method contract) or an appropriate 'null object' (such as a zero-length array).- See Also:
getSourceElementInfo2(ISourceElement)
-
FORCE_RECONCILING
public static final 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. Default value:false.
-
CREATE_BUFFER
public static final Property<java.lang.Boolean> CREATE_BUFFER
Indicates whether a new buffer should be created if none already exists. Default value:true.
-
-
Method Detail
-
getName
public static java.lang.String getName(IElement element)
Returns the name of the element, ornullif the element has no name. This is a handle-only method.- Parameters:
element- notnull- Returns:
- the element name, or
nullif the element has no name
-
getParent
public static IElement getParent(IElement element)
Returns the immediate parent of the element, ornullif the element has no parent. This is a handle-only method.- Parameters:
element- notnull- Returns:
- the parent element, or
nullif the element has no parent
-
getRoot
public static IElement getRoot(IElement element)
Returns the root element for the element. Returns the element itself if it has no parent. This is a handle-only method.- Parameters:
element- notnull- Returns:
- the root element (never
null)
-
getParentChain
public static java.lang.Iterable<IElement> getParentChain(IElement element)
Returns anIterablethat 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).- Parameters:
element- may benull, in which case an empty iterable will be returned- Returns:
- an iterable representing the specified parent chain
(never
null)
-
getParentChainUntil
public static java.lang.Iterable<IElement> getParentChainUntil(IElement element, java.util.function.Predicate<? super IElement> until)
Returns anIterablethat 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 isnull, all ancestors will be included. If the predicate matches the given element, the returned iterable will be empty. This is a handle-only method.- Parameters:
element- may benull, in which case an empty iterable will be returneduntil- may benull- Returns:
- an iterable representing the specified parent chain
(never
null)
-
streamParentChain
public 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). This is a handle-only method.This method is equivalent to
streamParentChainUntil(element, null).- Parameters:
element- may benull, in which case an empty stream will be returned- Returns:
- a stream representing the specified parent chain
(never
null)
-
streamParentChainUntil
public 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). If the predicate is not matched or isnull, all ancestors will be included. If the predicate matches the given element, the returned stream will be empty. This is a handle-only method.- Parameters:
element- may benull, in which case an empty stream will be returneduntil- may benull- Returns:
- a stream representing the specified parent chain
(never
null)
-
collectParentChain
public static <T extends java.util.Collection<? super IElement>> T 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). This is a handle-only method.This method is equivalent to
collectParentChainUntil(element, null).- Parameters:
element- may benull, in which case no elements will be added to the given collectioncollection- notnull- Returns:
- the given
collectioninstance
-
collectParentChainUntil
public static <T extends java.util.Collection<? super IElement>> T 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). If the predicate is not matched or isnull, 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.- Parameters:
element- may benull, in which case no elements will be added to the given collectioncollection- notnulluntil- may benull- Returns:
- the given
collectioninstance
-
findMatchingAncestor
public 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. Returnsnullif no such element can be found. This is a handle-only method.This method is equivalent to
findMatchingAncestorUntil(element, filter, null).- Parameters:
element- may benull, in which casenullwill be returnedfilter- notnull- Returns:
- the matching element, or
nullif no such element can be found
-
findMatchingAncestorUntil
public 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 givenfilterpredicate starting from the given element (inclusive) and going up through the parent chain no further than the element matched by the givenuntilpredicate (exclusive). Returnsnullif no such element can be found. If theuntilpredicate is not matched or isnull, all ancestors will be included. If theuntilpredicate matches the given element,nullwill be returned. This is a handle-only method.- Parameters:
element- may benull, in which casenullwill be returnedfilter- notnulluntil- may benull- Returns:
- the matching element, or
nullif no such element can be found
-
findAncestorOfType
public 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. Returnsnullif no such element can be found. This is a handle-only method.This method is equivalent to
findAncestorOfTypeUntil(element, type, null).- Parameters:
element- may benull, in which casenullwill be returnedtype- notnull- Returns:
- the matching element, or
nullif no such element can be found
-
findAncestorOfTypeUntil
public 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). Returnsnullif no such element can be found. If the predicate is not matched or isnull, all ancestors will be included. If the predicate matches the given element,nullwill be returned. This is a handle-only method.- Parameters:
element- may benull, in which casenullwill be returnedtype- notnulluntil- may benull- Returns:
- the matching element, or
nullif no such element can be found
-
findLastMatchingAncestor
public 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). Returnsnullif no such element can be found. This is a handle-only method.This method is equivalent to
findLastMatchingAncestorUntil(element, filter, null).- Parameters:
element- may benull, in which casenullwill be returnedfilter- notnull- Returns:
- the matching element, or
nullif no such element can be found
-
findLastMatchingAncestorUntil
public 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 givenfilterpredicate starting from the given element (inclusive) and going up through the parent chain to the element matched by the givenuntilpredicate (exclusive). Returnsnullif no such element can be found. If theuntilpredicate is not matched or isnull, all ancestors will be included. If theuntilpredicate matches the given element,nullwill be returned. This is a handle-only method.- Parameters:
element- may benull, in which casenullwill be returnedfilter- notnulluntil- may benull- Returns:
- the matching element, or
nullif no such element can be found
-
findLastAncestorOfType
public 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). Returnsnullif no such element can be found. This is a handle-only method.This method is equivalent to
findLastAncestorOfTypeUntil(element, type, null).- Parameters:
element- may benull, in which casenullwill be returnedtype- notnull- Returns:
- the matching element, or
nullif no such element can be found
-
findLastAncestorOfTypeUntil
public 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). Returnsnullif no such element can be found. If the predicate is not matched or isnull, all ancestors will be included. If the predicate matches the given element,nullwill be returned. This is a handle-only method.- Parameters:
element- may benull, in which casenullwill be returnedtype- notnulluntil- may benull- Returns:
- the matching element, or
nullif no such element can be found
-
findCommonAncestor
public 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. Returnsnullif no such element can be found. This is a handle-only method.This method is equivalent to
findCommonAncestorUntil(element, other, null).- Parameters:
element- may benull, in which casenullwill be returnedother- may benull, in which casenullwill be returned- Returns:
- the matching element, or
nullif no such element can be found
-
findCommonAncestorUntil
public 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). Returnsnullif no such element can be found. If the predicate is not matched or isnull, all ancestors will be included. If the predicate matches any of the given elements,nullwill be returned. This is a handle-only method.- Parameters:
element- may benull, in which casenullwill be returnedother- may benull, in which casenullwill be returneduntil- may benull- Returns:
- the matching element, or
nullif no such element can be found
-
findCommonAncestor
public 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. Returnsnullif no such element can be found. This is a handle-only method.This method is equivalent to
findCommonAncestorUntil(elements, null).- Parameters:
elements- notnull, may contain nulls- Returns:
- the matching element, or
nullif no such element can be found
-
findCommonAncestorUntil
public 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). Returnsnullif no such element can be found. If the predicate is not matched or isnull, all ancestors will be included. If the predicate matches any of the given elements,nullwill be returned. This is a handle-only method.- Parameters:
elements- notnull, may contain nullsuntil- may benull- Returns:
- the matching element, or
nullif no such element can be found
-
isAncestorOf
public 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. This is a handle-only method.- Parameters:
element- notnullother- may benull, in which casefalsewill be returned- Returns:
trueif both elements belong to the same parent chain and the first element is equal to or an ancestor of the other element, andfalseotherwise
-
removeDescendants
public 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. This is a handle-only method.- Parameters:
elements- notnull, must not containnullelements
-
equalsAndSameParentChain
public static boolean equalsAndSameParentChain(IElement element, IElement other)
Returns whether the elements are equal and belong to the same parent chain. This is a handle-only method.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.
- Parameters:
element- notnullother- may benull- Returns:
trueif the elements are equal and belong to the same parent chain, andfalseotherwise
-
getModel
public static IModel getModel(IElement element)
Returns the model that owns the element. This is a handle-only method.- Parameters:
element- notnull- Returns:
- the element's model (never
null)
-
isOfModel
public static boolean isOfModel(IElement element, IModel model)
Returns whether the element belongs to the given model. More formally, returnstrueif, and only if,model.equals(getModel(element)). This is a handle-only method.- Parameters:
element- notnullmodel- notnull- Returns:
trueif the element belongs to the given model, andfalseotherwise
-
getModelContext
public static IContext getModelContext(IElement element)
Returns a context which provides information and services pertaining to the element's model. The context, as a set of bindings, is immutable. This is a handle-only method.- Parameters:
element- notnull- Returns:
- the model context for the element (never
null)
-
getModelApiLevel
public static int getModelApiLevel(IElement element)
Returns the Handly API level supported by the element's model; one of the level constants declared inApiLevel. This is a handle-only method.- Parameters:
element- notnull- Returns:
- the Handly API level supported by the element's model
-
getHandleMemento
public 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'sIElementHandleFactory. The format of the string is not specified, but the representation is stable across workbench sessions. This is a handle-only method.- Parameters:
element- notnull- Returns:
- the handle memento for the element, or
nullif the element is unable to provide a handle memento
-
getResource
public static org.eclipse.core.resources.IResource getResource(IElement element)
Returns the innermost resource enclosing the element, ornullif 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
nulleven whenorg.eclipse.core.resourcesbundle is not available.- Parameters:
element- notnull- Returns:
- the innermost resource enclosing the element, or
nullif the element is not enclosed in a workspace resource
-
splitIntoElementsAndResources
public 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 ofIElements and a collection ofIResources, 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.- Parameters:
objects- notnull, may containnullelementselements- notnullmodel- may benull. If notnull, only elements belonging to the model will be added to theelementscollectionresources- may benull. Ifnull, no checks forinstanceof IResourcewill be doneelementHandleFactory- may benull. Ifnull, resources will be added without first trying to translate them to elements
-
getLocationUri
public static java.net.URI getLocationUri(IElement element)
Returns a file system location for the element. The resulting URI is suitable to passing toEFS.getStore(URI). Returnsnullif no location can be determined.- Parameters:
element- notnull- Returns:
- a file system location for the element,
or
nullif no location can be determined
-
exists
public static boolean exists(IElement element)
Returns whether the element exists in the model.Handles may or may not be backed by an actual element. Handles that are backed by an actual element are said to "exist".
- Parameters:
element- notnull- Returns:
trueif the element exists in the model, andfalseif the element does not exist
-
getChildren
public static IElement[] getChildren(IElement element) throws org.eclipse.core.runtime.CoreException
Returns the immediate children of the element. Unless otherwise specified by the parent element, the children are in no particular order.- Parameters:
element- notnull- Returns:
- the immediate children of the element (never
null). Clients must not modify the returned array. - Throws:
org.eclipse.core.runtime.CoreException- if the element does not exist or if an exception occurs while accessing its corresponding resource
-
getChildren
public static IElement[] getChildren(IElement element, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
Returns the immediate children of the element. Unless otherwise specified by the parent element, the children are in no particular order.- Parameters:
element- notnullcontext- the operation context (notnull)monitor- a progress monitor, ornullif progress reporting is not desired. The caller must not rely onIProgressMonitor.done()having been called by the receiver- Returns:
- the immediate children of the element (never
null). Clients must not modify the returned array. - Throws:
org.eclipse.core.runtime.CoreException- if the element does not exist or if an exception occurs while accessing its corresponding resource
-
getChildrenOfType
public static <T> T[] getChildrenOfType(IElement element, java.lang.Class<T> type) throws org.eclipse.core.runtime.CoreException
Returns the immediate children of the element that have the given type. Unless otherwise specified by the parent element, the children are in no particular order.- Parameters:
element- notnulltype- notnull- Returns:
- the immediate children of the element that have the given type
(never
null). Clients must not modify the returned array. - Throws:
org.eclipse.core.runtime.CoreException- if the element does not exist or if an exception occurs while accessing its corresponding resource
-
getChildrenOfType
public 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
Returns the immediate children of the element that have the given type. Unless otherwise specified by the parent element, the children are in no particular order.- Parameters:
element- notnulltype- notnullcontext- the operation context (notnull)monitor- a progress monitor, ornullif progress reporting is not desired. The caller must not rely onIProgressMonitor.done()having been called by the receiver- Returns:
- the immediate children of the element that have the given type
(never
null). Clients must not modify the returned array. - Throws:
org.eclipse.core.runtime.CoreException- if the element does not exist or if an exception occurs while accessing its corresponding resource
-
toString
public static java.lang.String toString(IElement element, IContext context)
Returns a string representation of the element in a form suitable for debugging purposes. Clients can influence the result with options specified in the given context; unrecognized options are ignored and an empty context is permitted.Model implementations are encouraged to support common options defined in
ToStringOptionsand interpret theFORMAT_STYLEas follows:- Parameters:
element- notnullcontext- notnull- Returns:
- a string representation of the element (never
null)
-
toDisplayString
public 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. Clients can influence the result with options specified in the given context; unrecognized options are ignored and an empty context is permitted.Model implementations are encouraged to support common options defined in
ToStringOptionsand may interpret theFORMAT_STYLEas 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 aFULLrepresentation fully identifies the element within the model.- Parameters:
element- notnullcontext- notnull- Returns:
- a string representation of the element (never
null)
-
getSourceElementAt
public static ISourceElement getSourceElementAt(ISourceElement element, int position, ISnapshot base) throws org.eclipse.core.runtime.CoreException
Returns the smallest element that includes the given source position, ornullif 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.- Parameters:
element- a source element (notnull)position- a source position (0-based)base- a snapshot on which the given position is based, ornullif the snapshot is unknown or does not matter- Returns:
- the innermost element enclosing the given source position,
or
nullif none (including the given element itself) - Throws:
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 snapshot
-
getSourceElementAt
public static ISourceElement getSourceElementAt(ISourceElement element, int position, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
Returns the smallest element that includes the given source position, ornullif 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, ornullif the snapshot is unknown or does not matter.
- Parameters:
element- a source element (notnull)position- a source position (0-based)context- the operation context (notnull)monitor- a progress monitor, ornullif progress reporting is not desired. The caller must not rely onIProgressMonitor.done()having been called by the receiver- Returns:
- the innermost element enclosing the given source position,
or
nullif none (including the given element itself) - Throws:
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 snapshot
-
-
getSourceElementAt2
public static ISourceElement getSourceElementAt2(ISourceElement element, int position, ISnapshot base)
Returns the smallest element that includes the given position, ornullif 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.- Parameters:
element- a source element (notnull)position- a source position (0-based)base- a snapshot on which the given position is based, ornullif the snapshot is unknown or does not matter- Returns:
- the innermost element enclosing the given source position,
or
nullif none (including the given element itself)
-
getSourceElementInfo
public static ISourceElementInfo getSourceElementInfo(ISourceElement element) throws org.eclipse.core.runtime.CoreException
Returns an object holding cached structure and properties for the source element.- Parameters:
element- notnull- Returns:
- an
ISourceElementInfofor the element (nevernull) - Throws:
org.eclipse.core.runtime.CoreException- if the element does not exist or if an exception occurs while accessing its corresponding resource
-
getSourceElementInfo
public static ISourceElementInfo getSourceElementInfo(ISourceElement element, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
Returns an object holding cached structure and properties for the source element.- Parameters:
element- notnullcontext- the operation context (notnull)monitor- a progress monitor, ornullif progress reporting is not desired. The caller must not rely onIProgressMonitor.done()having been called by the receiver- Returns:
- an
ISourceElementInfofor the element (nevernull) - Throws:
org.eclipse.core.runtime.CoreException- if the element does not exist or if an exception occurs while accessing its corresponding resource
-
getSourceElementInfo2
public static ISourceElementInfo getSourceElementInfo2(ISourceElement element)
Returns an object holding cached structure and properties for the source element, orNO_SOURCE_ELEMENT_INFOif no such info is available.- Parameters:
element- notnull- Returns:
- an
ISourceElementInfofor the element (nevernull)
-
getSourceFile
public static ISourceFile getSourceFile(IElement element)
Returns the source file that contains the given element, ornullif 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.- Parameters:
element- may benull, in which casenullwill be returned- Returns:
- the source file containing the given element,
or
nullif none
-
ensureReconciled
public 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. Note that the call may result in the change of existence status for the given element: if the element did not exist before, it may be brought into existence; conversely, if the element existed, it may cease to exist.- Parameters:
element- notnullmonitor- a progress monitor, ornullif progress reporting is not desired. The caller must not rely onIProgressMonitor.done()having been called by the receiver- Returns:
trueif the call completed successfully, andfalsein case of a failure- Throws:
org.eclipse.core.runtime.OperationCanceledException- if this method is canceled
-
getFile
public static org.eclipse.core.resources.IFile getFile(ISourceFile sourceFile)
Returns the underlyingIFile, ornullif 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.- Parameters:
sourceFile- notnull- Returns:
- the underlying
IFile, ornullif the source file has no underlying file in the workspace
-
getFileStore
public static org.eclipse.core.filesystem.IFileStore getFileStore(ISourceFile sourceFile)
Returns the correspondingIFileStore, ornullif the source file has no corresponding file store.- Parameters:
sourceFile- notnull- Returns:
- the corresponding
IFileStore, ornullif this source file has no corresponding file store - Since:
- 1.3
-
isWorkingCopy
public static boolean isWorkingCopy(ISourceFile sourceFile)
Returns whether the source file is a working copy.- Parameters:
sourceFile- notnull- Returns:
trueif the source file is a working copy, andfalseotherwise
-
needsReconciling
public static boolean needsReconciling(ISourceFile sourceFile)
Returns whether the source file needs reconciling. A source file needs reconciling if it is a working copy and its buffer has been modified since the last time it was reconciled.- Parameters:
sourceFile- notnull- Returns:
trueif the source file needs reconciling, andfalseotherwise
-
reconcile
public static void reconcile(ISourceFile sourceFile, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
Reconciles the source file. Does nothing if the source file is not in working copy mode or if its buffer has not been modified since the last time it was reconciled.- Parameters:
sourceFile- notnullmonitor- a progress monitor, ornullif progress reporting is not desired. The caller must not rely onIProgressMonitor.done()having been called by the receiver- Throws:
org.eclipse.core.runtime.CoreException- if the working copy could not be reconciledorg.eclipse.core.runtime.OperationCanceledException- if this method is canceled
-
reconcile
public static void reconcile(ISourceFile sourceFile, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
Reconciles the source file. Does nothing if the source file is not in working copy mode.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.
- Parameters:
sourceFile- notnullcontext- the operation context (notnull)monitor- a progress monitor, ornullif progress reporting is not desired. The caller must not rely onIProgressMonitor.done()having been called by the receiver- Throws:
org.eclipse.core.runtime.CoreException- if the working copy could not be reconciledorg.eclipse.core.runtime.OperationCanceledException- if this method is canceled
-
-
getBuffer
public static IBuffer getBuffer(ISourceFile sourceFile) throws org.eclipse.core.runtime.CoreException
Returns a buffer opened for the source file. Note that buffers may be shared by multiple clients, so the returned buffer may have unsaved changes if it has been modified by another client.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.
- Parameters:
sourceFile- notnull- Returns:
- a buffer opened for the source file (never
null) - Throws:
org.eclipse.core.runtime.CoreException- if the source file does not exist or if an exception occurs while accessing its corresponding resource
-
getBuffer
public static IBuffer getBuffer(ISourceFile sourceFile, IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
Returns a buffer opened for the source file. Note that buffers may be shared by multiple clients, so the returned buffer may have unsaved changes if it has been modified by another client.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.
- Parameters:
sourceFile- notnullcontext- the operation context (notnull)monitor- a progress monitor, ornullif progress reporting is not desired. The caller must not rely onIProgressMonitor.done()having been called by the receiver- Returns:
- a buffer opened for the source file. May return
nullifCREATE_BUFFERisfalsein the given context and there is no buffer currently opened for the source file - Throws:
org.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 canceled
-
-
-