Package org.revapi.base
Class BaseElement<E extends Element<E>>
- java.lang.Object
-
- org.revapi.base.BaseElement<E>
-
- Type Parameters:
E- the parent type of all elements in the API
- All Implemented Interfaces:
Cloneable,Comparable<E>,Element<E>
public abstract class BaseElement<E extends Element<E>> extends Object implements Element<E>, Cloneable
A base class for API elements. It is not mandatory to inherit from this class but it provides a good base implementation for most of the cases.The type parameter,
<E>, denotes the parent type of all elements produced by a certainApiAnalyzer. All these types are assumed to be mutually comparable (and therefore implementComparable<E>).
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseElement(API api)protectedBaseElement(API api, Archive archive)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected EcastThis()Casts "this" toE.BaseElement<E>clone()Returns a shallow copy of this element.APIgetApi()ArchivegetArchive()SortedSet<E>getChildren()StringgetFullHumanReadableString()Provides the full "path" to the element in the forest in a human readable way.EgetParent()Set<Reference<E>>getReferencedElements()If the API analyzer supports the feature, this returns the set of elements that are referenced by this element in some way (typically, those would be the elements somehow used by this element).Set<Reference<E>>getReferencingElements()If the API analyzer supports the feature, this returns the set of elements that reference this element in some way (typically, those would be the use sites of this element).<T extends Element<E>>
Iterator<T>iterateOverChildren(Class<T> resultType, boolean recurse, Filter<? super T> filter)Similar to search methods but avoids the traversal over the whole forest.protected SortedSet<E>newChildrenInstance()Override this method if you need some specialized instance of sorted set or want to do some custom pre-populating or initialization of the children.protected Reference<E>newReference(E target, Reference.Type<E> type)Creates a new reference instance to be used in thegetReferencedElements()orgetReferencingElements().<T extends Element<E>>
List<T>searchChildren(Class<T> resultType, boolean recurse, Filter<? super T> filter)This method is functionally equivalent toElement.searchChildren(java.util.List, java.lang.Class, boolean, org.revapi.query.Filter)but returns the result in a newly allocated list instance.<T extends Element<E>>
voidsearchChildren(List<T> results, Class<T> resultType, boolean recurse, Filter<? super T> filter)Recursively searches the children of this element for elements of given type, potentially applicable to given filter.protected voidsetArchive(Archive archive)voidsetParent(E parent)Sets the parent element.-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface org.revapi.Element
as, getCumulativeReferencedElements, getCumulativeReferencingElements, stream
-
-
-
-
Method Detail
-
castThis
protected E castThis()
Casts "this" toE. This is unsafe from the language perspective but we supposeEis the base type of all elements of given API analyzer, so this should always be safe.- Returns:
- this instance as the base element type
-
getArchive
@Nullable public Archive getArchive()
- Specified by:
getArchivein interfaceElement<E extends Element<E>>- Returns:
- the archive the element comes from or null if that cannot be determined
-
getFullHumanReadableString
@Nonnull public String getFullHumanReadableString()
Description copied from interface:ElementProvides the full "path" to the element in the forest in a human readable way. This method is meant to be used by the reporters to identify the element in the reports.- Specified by:
getFullHumanReadableStringin interfaceElement<E extends Element<E>>- Returns:
- human readable representation of the element
-
setParent
public void setParent(@Nullable E parent)
Sets the parent element. No other processing is automagically done (i.e. the parent's children set is NOT updated by calling this method).
-
getChildren
@Nonnull public SortedSet<E> getChildren()
- Specified by:
getChildrenin interfaceElement<E extends Element<E>>
-
getReferencingElements
public Set<Reference<E>> getReferencingElements()
Description copied from interface:ElementIf the API analyzer supports the feature, this returns the set of elements that reference this element in some way (typically, those would be the use sites of this element).- Specified by:
getReferencingElementsin interfaceElement<E extends Element<E>>
-
getReferencedElements
public Set<Reference<E>> getReferencedElements()
Description copied from interface:ElementIf the API analyzer supports the feature, this returns the set of elements that are referenced by this element in some way (typically, those would be the elements somehow used by this element).- Specified by:
getReferencedElementsin interfaceElement<E extends Element<E>>
-
clone
public BaseElement<E> clone()
Returns a shallow copy of this element. In particular, its parent and children will be cleared.
-
newChildrenInstance
protected SortedSet<E> newChildrenInstance()
Override this method if you need some specialized instance of sorted set or want to do some custom pre-populating or initialization of the children. This default implementation merely returns an empty newTreeSetinstance.- Returns:
- a new sorted set instance to store the children in
-
searchChildren
public <T extends Element<E>> List<T> searchChildren(Class<T> resultType, boolean recurse, @Nullable Filter<? super T> filter)
Description copied from interface:ElementThis method is functionally equivalent toElement.searchChildren(java.util.List, java.lang.Class, boolean, org.revapi.query.Filter)but returns the result in a newly allocated list instance. This is basically a convenience method to enable a more succinct expressions.- Specified by:
searchChildrenin interfaceElement<E extends Element<E>>- Type Parameters:
T- the type of the elements to look for- Parameters:
resultType- the type of the elements to look forrecurse- false to search only in direct children of the element, true to search recursivelyfilter- optional filter to further trim the number of results @return the list of child elements of given type potentially satisfying given filter- Returns:
- the list of found elements
-
searchChildren
public <T extends Element<E>> void searchChildren(List<T> results, Class<T> resultType, boolean recurse, @Nullable Filter<? super T> filter)
Description copied from interface:ElementRecursively searches the children of this element for elements of given type, potentially applicable to given filter.This is identical to
Element.searchChildren(Class, boolean, org.revapi.query.Filter)in behavior but avoids the instantiation of a new list.- Specified by:
searchChildrenin interfaceElement<E extends Element<E>>- Type Parameters:
T- the type of the elements to look for- Parameters:
results- the list of the results to fillresultType- the type of the elements to look forrecurse- false to search only in direct children of the element, true to search recursivelyfilter- optional filter to further trim the number of results
-
iterateOverChildren
public <T extends Element<E>> Iterator<T> iterateOverChildren(Class<T> resultType, boolean recurse, @Nullable Filter<? super T> filter)
Description copied from interface:ElementSimilar to search methods but avoids the traversal over the whole forest. Instead the traversal is incremental and governed by the returned iterator.- Specified by:
iterateOverChildrenin interfaceElement<E extends Element<E>>- Type Parameters:
T- the type of the elements to look for- Parameters:
resultType- the type of elements to look forrecurse- if true, the iterator traverses the element forest using depth first searchfilter- optional filter to further trim the number of results- Returns:
- the iterator that will iterate over the results
- See Also:
Element.searchChildren(Class, boolean, org.revapi.query.Filter)
-
newReference
protected Reference<E> newReference(E target, Reference.Type<E> type)
Creates a new reference instance to be used in thegetReferencedElements()orgetReferencingElements(). This method should be overridden by any subclass that uses a subclass forReferencefor referencing the elements.- Parameters:
target- the target elementtype- the type of the reference- Returns:
- a new reference with given type pointing to the target element
-
-