public interface IElementImplSupport extends IElementImplExtension, IModelManager.Provider
IElementImplExtension
to minimize the effort required to implement that
interface. Clients may implement ("mix in") this interface directly or
extend Element
.
In general, the members first defined in this interface are not intended to be referenced outside the subtype hierarchy.
IElementImplExtension.CloseHint
Modifier and Type | Field and Description |
---|---|
static Property<java.util.Map<IElement,java.lang.Object>> |
NEW_ELEMENTS
A map containing element handle/body relationships.
|
static java.lang.Object |
NO_BODY
Special-purpose value for the
body argument of the
toStringBody_(StringBuilder, Object, IContext) method;
indicates that information about the body is not relevant. |
CLOSE_HINT, FORCE_OPEN
Modifier and Type | Method and Description |
---|---|
void |
buildStructure_(IContext context,
org.eclipse.core.runtime.IProgressMonitor monitor)
Creates and initializes bodies for this element and for each non-
openable child element (and their non-openable children,
recursively). |
default boolean |
canEqual_(java.lang.Object obj)
Returns whether this element can equal the given object.
|
default void |
close_(IContext context)
Closes this element if, and only if, the current state of this element
permits closing according to options specified in the given context.
|
default boolean |
defaultEquals_(java.lang.Object obj)
A default implementation of
IElement.equals(Object) cannot be provided in
an interface, but clients can implement equals by
delegating to this default method. |
default int |
defaultHashCode_()
A default implementation of
IElement.hashCode() cannot be provided in
an interface, but clients can implement hashCode by
delegating to this default method. |
default boolean |
exists_()
Returns whether this element exists in the model.
|
default java.lang.Object |
findBody_()
Returns the cached body for this element, or
null
if none. |
default IElement[] |
getChildrenFromBody_(java.lang.Object body)
Given a body for this element, returns the immediate children.
|
default ElementManager |
getElementManager_()
Returns the element manager for this element.
|
default IModel |
getModel_()
Returns the model that owns this element.
|
default boolean |
isOpenable_()
Returns whether this element is "openable".
|
default org.eclipse.core.runtime.CoreException |
newDoesNotExistException_()
Returns a new instance of generic "element does not exist" exception.
|
default java.lang.Object |
open_(IContext context,
org.eclipse.core.runtime.IProgressMonitor monitor)
Ensures that this element is open, i.e., it exists and is present in the
body cache.
|
default void |
openParent_(IContext context,
org.eclipse.core.runtime.IProgressMonitor monitor)
Opens the parent element if necessary.
|
default java.lang.Object |
peekAtBody_()
Returns the cached body for this element without disturbing
cache ordering, or
null if none. |
default void |
remove_(IContext context)
Removes this element from the body cache according to options specified
in the given context.
|
default void |
removing_(java.lang.Object body)
Informs this element that its body is going to be removed from the body cache.
|
default java.lang.String |
toString_(IContext context)
Returns a string representation of this element in a form suitable for
debugging purposes.
|
default void |
toStringAncestors_(java.lang.StringBuilder builder,
IContext context) |
default void |
toStringBody_(java.lang.StringBuilder builder,
java.lang.Object body,
IContext context) |
default void |
toStringChildren_(java.lang.StringBuilder builder,
java.lang.Object body,
IContext context) |
default void |
toStringName_(java.lang.StringBuilder builder,
IContext context) |
void |
validateExistence_(IContext context)
Validates that this element may be "opened", i.e., begin existence
in the model.
|
close_, getBody_, getBody_, getChildren_
equalsAndSameParentChain_, getChildrenOfType_, getHandleMemento_, getLocationUri_, getName_, getParent_, getResource_, getRoot_, toDisplayString_
getModelManager_
static final Property<java.util.Map<IElement,java.lang.Object>> NEW_ELEMENTS
static final java.lang.Object NO_BODY
body
argument of the
toStringBody_(StringBuilder, Object, IContext)
method;
indicates that information about the body is not relevant.default int defaultHashCode_()
IElement.hashCode()
cannot be provided in
an interface, but clients can implement hashCode
by
delegating to this default method.
By default, the hash code for an element is a combination of hash codes
for its name and its parent element. This method is specialized in ISourceConstructImplSupport
to include the element's occurrence count,
and in ISourceFileImplSupport
to return the hash code for the
underlying file object, if there is one. This method is not intended
to be replaced by clients; if necessary, clients should override
hashCode
directly.
default boolean defaultEquals_(java.lang.Object obj)
IElement.equals(Object)
cannot be provided in
an interface, but clients can implement equals
by
delegating to this default method.
By default, two elements that implement this interface are equal if they
are identical or if they can equal
each other
and do have equal names and equal parents. This method is specialized in
ISourceConstructImplSupport
and ISourceFileImplSupport
to also compare occurrence counts and underlying file objects
respectively. This method is not intended to be replaced by clients;
if necessary, clients should override equals
directly.
obj
- the object with which to comparetrue
if this element is equal to the given object,
and false
otherwisedefault boolean canEqual_(java.lang.Object obj)
false
, the equals
method must also
return false
for the same argument object.
This implementation compares run-time classes of the objects for equality;
as such, it does not allow creating a subclass whose instances can equal
superclass instances. Clients may provide their own implementation for
this method and use a less discriminating technique such as
instanceof
check.
For details, see https://www.artima.com/pins1ed/object-equality.html#28.2, Pitfall #4.
obj
- not null
true
if this element can equal the given object,
and false
otherwisedefault IModel getModel_()
This implementation returns getModelManager_().getModel()
.
getModel_
in interface IElementImpl
null
)default ElementManager getElementManager_()
This implementation returns getModelManager_().getElementManager()
.
null
)default IElement[] getChildrenFromBody_(java.lang.Object body)
This implementation returns ((Body)body).
.
getChildren()
getChildrenFromBody_
in interface IElementImplExtension
body
- a body for this element (not null
)null
).
Clients must not modify the returned array.default java.lang.Object findBody_()
IElementImplExtension
null
if none.findBody_
in interface IElementImplExtension
null
if nonedefault java.lang.Object peekAtBody_()
IElementImplExtension
null
if none.peekAtBody_
in interface IElementImplExtension
null
if nonedefault boolean exists_()
Handles may or may not be backed by an actual element. Handles that are backed by an actual element are said to "exist".
This implementation returns true
if there is a cached body
for this element, and false
if this element has a parent and
the parent does not exist; otherwise, it invokes validateExistence_
to determine the result.
exists_
in interface IElementImpl
true
if this element exists in the model, and
false
if this element does not existvoid validateExistence_(IContext context) throws org.eclipse.core.runtime.CoreException
Note that ancestor elements may or may not exist; this method need not explicitly verify their existence.
context
- the operation context (not null
)org.eclipse.core.runtime.CoreException
- if this element shall not existnewDoesNotExistException_()
default org.eclipse.core.runtime.CoreException newDoesNotExistException_()
null
)default java.lang.Object open_(IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
Implementations are encouraged to support the following standard options, which may be specified in the given context:
IElementImplExtension.FORCE_OPEN
- Indicates whether to forcibly reopen this element
if it is already open (i.e., already present in the body cache).
This implementation attempts to open
the parent element first. Then, if this element
is openable
and is permitted
to open, invokes buildStructure_(IContext,
IProgressMonitor)
with an appropriately augmented context, acquires the
element manager lock, updates the body cache with the built structure,
and releases the lock. When this element is already open, the update may
involve closing existing children or do nothing at all, depending on the
value of FORCE_OPEN
. If this element is not openable
and the openable parent did not create a body for this element,
this implementation throws a newDoesNotExistException_()
.
open_
in interface IElementImplExtension
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
)org.eclipse.core.runtime.CoreException
- if this element does not exist or if an
exception occurs while accessing its corresponding resourcedefault void openParent_(IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
This method is called internally; it is not intended to be invoked by clients.
This implementation attempts to open
the parent element if it supports IElementImplExtension
and
is not already open.
context
- the operation context (never null
)monitor
- a progress monitor (never null
).
The caller must not rely on IProgressMonitor.done()
having been called by the receiverorg.eclipse.core.runtime.CoreException
- if an exception occurs while opening this element's
parentorg.eclipse.core.runtime.OperationCanceledException
- if this method is canceledopen_(IContext, IProgressMonitor)
default boolean isOpenable_()
build
their
structure and can be opened
one by one. In particular, there is no need to open an openable child
when opening its parent. Non-openable elements rely on the openable
parent to build their structure. Opening of a parent element opens all
non-openable children at once.
This implementation returns true
. Non-openable elements
must override this method and return false
.
true
if this element is openable,
and false
otherwisevoid buildStructure_(IContext context, org.eclipse.core.runtime.IProgressMonitor monitor) throws org.eclipse.core.runtime.CoreException
openable
child element (and their non-openable children,
recursively). Uses the NEW_ELEMENTS
map in the given context
to associate the created bodies with their respective elements.
Note that this method does not make sense and must not be called for non-openable elements -- they rely on the openable parent to build their structure.
context
- the operation context (not null
)monitor
- a progress monitor (not null
).
The caller must not rely on IProgressMonitor.done()
having been called by the receiverorg.eclipse.core.runtime.CoreException
- if the structure could not be determinedorg.eclipse.core.runtime.OperationCanceledException
- if this method is canceleddefault void close_(IContext context)
Closing of an element removes its body from the body cache. In general, closing of a parent element also closes its children. If the current state of an open child element does not permit closing, the child element remains open, which generally does not prevent its parent from closing. Closing of an element which is not open has no effect.
Implementations are encouraged to support the following standard options, which may be specified in the given context:
IElementImplExtension.CLOSE_HINT
- Closing hint.
After checking that the current state of this element permits closing,
this implementation invokes remove_(IContext)
to actually
close this element.
close_
in interface IElementImplExtension
context
- the operation context (not null
)default void remove_(IContext context)
This is a low-level operation, which removes this element's body and
thus closes this element even if the current state of this element does
not permit closing. Consider using a higher-level close_(IContext)
method.
If there is a cached body for this element, this implementation invokes
removing_(Object)
method to notify this element of the upcoming
removal of its body, calls close_(of(CLOSE_HINT, PARENT_CLOSING))
for each of this element's children, then removes the cached body for
this element, all while holding the element manager lock.
context
- the operation context (not null
)default void removing_(java.lang.Object body)
This method is called internally; it is not intended to be invoked by clients.
body
- the cached body for this element (never null
)default java.lang.String toString_(IContext context)
IElementImpl
Implementations are encouraged to support common options defined in
ToStringOptions
and
interpret the FORMAT_STYLE
as follows:
toString_
in interface IElementImpl
context
- not null
null
)default void toStringAncestors_(java.lang.StringBuilder builder, IContext context)
default void toStringChildren_(java.lang.StringBuilder builder, java.lang.Object body, IContext context)
default void toStringBody_(java.lang.StringBuilder builder, java.lang.Object body, IContext context)
default void toStringName_(java.lang.StringBuilder builder, IContext context)
Copyright (c) 2014, 2020 1C-Soft LLC and others. Made available under the Eclipse Public License 2.0