public abstract class CtElementImpl extends java.lang.Object implements CtElement, java.io.Serializable
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ERROR_MESSAGE_TO_STRING |
protected Factory |
factory
this field `factory` must be transient in order to allow proper serialization
the factory is restored in all AST nodes in
SerializationModelStreamer |
protected static org.slf4j.Logger |
LOGGER |
protected CtElement |
parent |
Constructor and Description |
---|
CtElementImpl() |
Modifier and Type | Method and Description |
---|---|
<E extends CtElement> |
addAnnotation(CtAnnotation<? extends java.lang.annotation.Annotation> annotation)
Add an annotation for this element
|
<E extends CtElement> |
addComment(CtComment comment)
Add a comment to the current element
element.addComment(element.getFactory().Code().createComment("comment", CtComment.CommentType.INLINE) |
java.lang.Iterable<CtElement> |
asIterable()
Returns an Iterable instance of this CtElement, allowing for dfs traversal of its descendants.
|
CtElement |
clone()
Clone the element which calls this method in a new object.
|
void |
comment()
Replace the statement with a CtComment having the statement as text
|
void |
delete()
Deletes the element.
|
java.util.Iterator<CtElement> |
descendantIterator()
Returns an iterator over this CtElement's descendants.
|
static <T> java.util.List<T> |
emptyList() |
static <T> java.util.Set<T> |
emptySet() |
boolean |
equals(java.lang.Object o) |
<P extends CtElement> |
filterChildren(Filter<P> predicate) |
java.util.Map<java.lang.String,java.lang.Object> |
getAllMetadata()
Retrieves all metadata stored in an element.
|
<E extends CtElement> |
getAnnotatedChildren(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Gets the child elements annotated with the given annotation type's
instances.
|
<A extends java.lang.annotation.Annotation> |
getAnnotation(java.lang.Class<A> annotationType)
Searches for an annotation of the given class that annotates the
current element.
|
<A extends java.lang.annotation.Annotation> |
getAnnotation(CtTypeReference<A> annotationType)
Gets the annotation element for a given annotation type.
|
java.util.List<CtAnnotation<? extends java.lang.annotation.Annotation>> |
getAnnotations()
Returns the annotations that are present on this element.
|
java.util.List<CtComment> |
getComments()
The list of comments
|
java.util.List<CtElement> |
getDirectChildren() |
java.lang.String |
getDocComment()
Returns the text of the documentation ("javadoc") comment of this
element.
|
<E extends CtElement> |
getElements(Filter<E> filter)
Returns all the children elements recursively matching the filter.
|
Factory |
getFactory()
Gets the factory of this object.
|
java.lang.Object |
getMetadata(java.lang.String key)
Retrieves metadata stored in an element.
|
java.util.Set<java.lang.String> |
getMetadataKeys()
Returns the metadata keys stored in an element.
|
ElementSourceFragment |
getOriginalSourceFragment()
Returns the original source code (maybe different from toString() if a transformation has been applied).
|
CtElement |
getParent()
Gets the parent of current reference.
|
<P extends CtElement> |
getParent(java.lang.Class<P> parentType)
Gets the first parent that matches the given type.
|
<E extends CtElement> |
getParent(Filter<E> filter)
Gets the first parent that matches the filter.
|
CtPath |
getPath()
Return the path from the model root to this CtElement, eg `.spoon.test.path.Foo.foo#body#statement[index=0]`
|
SourcePosition |
getPosition()
Gets the position of this element in input source files
|
java.util.Set<CtTypeReference<?>> |
getReferencedTypes()
Calculates and returns the set of all the types referenced by this
element (and sub-elements in the AST).
|
CtRole |
getRoleInParent() |
java.lang.String |
getShortRepresentation()
Build a short representation of any element.
|
<T> T |
getValueByRole(CtRole role) |
<A extends java.lang.annotation.Annotation> |
hasAnnotation(java.lang.Class<A> annotationType) |
int |
hashCode() |
boolean |
hasParent(CtElement candidate)
Tells if the given element is a direct or indirect parent.
|
boolean |
isImplicit()
Returns true if this element is not present in the code (automatically added by the
Java compiler or inferred when the model is built).
|
boolean |
isParentInitialized()
Tells if this parent has been initialized.
|
<I> CtQuery |
map(CtConsumableFunction<I> queryStep) |
<I,R> CtQuery |
map(CtFunction<I,R> function) |
java.lang.String |
prettyprint() |
<E extends CtElement> |
putMetadata(java.lang.String key,
java.lang.Object val)
Saves metadata inside an Element.
|
boolean |
removeAnnotation(CtAnnotation<? extends java.lang.annotation.Annotation> annotation)
Remove an annotation for this element
|
<E extends CtElement> |
removeComment(CtComment comment)
Remove a comment
|
<E extends CtElement> |
replace(java.util.Collection<E> elements)
Replaces this element by several elements.
|
void |
replace(CtElement element)
Replaces this element by another one.
|
<E extends CtElement> |
setAllMetadata(java.util.Map<java.lang.String,java.lang.Object> metadata)
Saves a bunch of metadata inside an Element
|
<E extends CtElement> |
setAnnotations(java.util.List<CtAnnotation<? extends java.lang.annotation.Annotation>> annotations)
Sets the annotations for this element.
|
<E extends CtElement> |
setComments(java.util.List<CtComment> comments)
Set the comment list
|
<E extends CtElement> |
setDocComment(java.lang.String docComment)
Sets the text of the documentation ("javadoc") comment of this
declaration.
|
void |
setFactory(Factory factory)
Sets the factory object.
|
<E extends CtElement> |
setImplicit(boolean implicit)
Sets this element to be implicit.
|
<E extends CtElement> |
setParent(E parent)
Manually sets the parent element of the current element.
|
<E extends CtElement> |
setPosition(SourcePosition position)
Sets the position in the Java source file.
|
<E extends CtElement> |
setPositions(SourcePosition position)
Sets the position of this element and all its children element.
|
<E extends CtElement,T> |
setValueByRole(CtRole role,
T value)
Sets a field according to a role.
|
java.lang.String |
toString() |
java.lang.String |
toStringDebug() |
static <T> java.util.List<T> |
unmodifiableList(java.util.List<T> list) |
void |
updateAllParentsBelow()
Calculates and sets all the parents below this element.
|
finalize, getClass, notify, notifyAll, wait, wait, wait
accept
protected static final org.slf4j.Logger LOGGER
public static final java.lang.String ERROR_MESSAGE_TO_STRING
protected transient Factory factory
SerializationModelStreamer
protected CtElement parent
public static <T> java.util.List<T> emptyList()
public static <T> java.util.Set<T> emptySet()
public static <T> java.util.List<T> unmodifiableList(java.util.List<T> list)
public java.lang.String getShortRepresentation()
CtElement
getShortRepresentation
in interface CtElement
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public <A extends java.lang.annotation.Annotation> A getAnnotation(java.lang.Class<A> annotationType)
CtElement
CtElement.getAnnotation(CtTypeReference)
preferably.
NOTE: before using an annotation proxy, you have to make sure that all the types referenced by the annotation have been compiled and are in the classpath so that accessed values can be converted into the actual types.
getAnnotation
in interface CtElement
A
- the annotation's typeannotationType
- the annotation's classpublic <A extends java.lang.annotation.Annotation> boolean hasAnnotation(java.lang.Class<A> annotationType)
hasAnnotation
in interface CtElement
annotationType
- the annotation typepublic <A extends java.lang.annotation.Annotation> CtAnnotation<A> getAnnotation(CtTypeReference<A> annotationType)
CtElement
getAnnotation
in interface CtElement
annotationType
- the annotation typepublic java.util.List<CtAnnotation<? extends java.lang.annotation.Annotation>> getAnnotations()
CtElement
getAnnotations
in interface CtElement
public java.lang.String getDocComment()
CtElement
CtElement.getComments()
.and CtJavaDoc
getDocComment
in interface CtElement
public SourcePosition getPosition()
CtElement
getPosition
in interface SourcePositionHolder
getPosition
in interface CtElement
SourcePosition.isValidPosition()
to detect whether return instance contains start/end indexes.public int hashCode()
hashCode
in class java.lang.Object
public <E extends CtElement> E setAnnotations(java.util.List<CtAnnotation<? extends java.lang.annotation.Annotation>> annotations)
CtElement
setAnnotations
in interface CtElement
public void delete()
CtElement
public <E extends CtElement> E addAnnotation(CtAnnotation<? extends java.lang.annotation.Annotation> annotation)
CtElement
addAnnotation
in interface CtElement
public boolean removeAnnotation(CtAnnotation<? extends java.lang.annotation.Annotation> annotation)
CtElement
removeAnnotation
in interface CtElement
public <E extends CtElement> E setDocComment(java.lang.String docComment)
CtElement
CtComment
or create a new javadoc CtComment
if
no javadoc CtComment
is available on this object.setDocComment
in interface CtElement
public <E extends CtElement> E setPosition(SourcePosition position)
CtElement
setPosition
in interface CtElement
position
- of this element in the input source filespublic <E extends CtElement> E setPositions(SourcePosition position)
CtElement
setPositions
in interface CtElement
position
- of this element and all children in the input source filepublic java.lang.String prettyprint()
prettyprint
in interface CtElement
ImportAnalyzer
which would change the model: add/remove imports, change the value `implicit` of some model elements, etc.public java.lang.String toStringDebug()
toStringDebug
in interface CtElement
public java.lang.String toString()
toString
in interface CtElement
toString
in class java.lang.Object
Environment.getPrettyPrintingMode()
.public <E extends CtElement> java.util.List<E> getAnnotatedChildren(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
CtElement
getAnnotatedChildren
in interface CtElement
E
- the element's typeannotationType
- the annotation typepublic boolean isImplicit()
CtElement
isImplicit
in interface CtElement
public <E extends CtElement> E setImplicit(boolean implicit)
CtElement
setImplicit
in interface CtElement
public java.util.Set<CtTypeReference<?>> getReferencedTypes()
CtElement
getReferencedTypes
in interface CtElement
public <E extends CtElement> java.util.List<E> getElements(Filter<E> filter)
CtElement
getElements
in interface CtElement
public <I> CtQuery map(CtConsumableFunction<I> queryStep)
map
in interface CtQueryable
CtQuery.map(CtConsumableFunction)
public <I,R> CtQuery map(CtFunction<I,R> function)
map
in interface CtQueryable
CtQuery.map(CtFunction)
public <P extends CtElement> CtQuery filterChildren(Filter<P> predicate)
filterChildren
in interface CtQueryable
CtQuery.filterChildren(Filter)
public CtElement getParent() throws ParentNotInitializedException
CtElement
getParent
in interface CtElement
ParentNotInitializedException
- when the parent of this element is not initializedpublic <E extends CtElement> E setParent(E parent)
CtElement
public boolean isParentInitialized()
CtElement
isParentInitialized
in interface CtElement
public <P extends CtElement> P getParent(java.lang.Class<P> parentType) throws ParentNotInitializedException
CtElement
getParent
in interface CtElement
ParentNotInitializedException
public <E extends CtElement> E getParent(Filter<E> filter) throws ParentNotInitializedException
CtElement
getParent
in interface CtElement
ParentNotInitializedException
public boolean hasParent(CtElement candidate)
CtElement
public CtRole getRoleInParent()
getRoleInParent
in interface CtElement
CtRole
of the parent's attribute where this element is used.
It returns the primary role. For example ((CtMethod) method).getRoleInParent() returns CtRole.TYPE_MEMBER
.
public void updateAllParentsBelow()
CtElement
updateAllParentsBelow
in interface CtElement
public Factory getFactory()
FactoryAccessor
getFactory
in interface FactoryAccessor
public void setFactory(Factory factory)
FactoryAccessor
setFactory
in interface FactoryAccessor
public void replace(CtElement element)
CtElement
public <E extends CtElement> void replace(java.util.Collection<E> elements)
CtElement
CtElement.replace(CtElement)
.
If `elements` is empty, it is equivalent to CtElement.delete()
.public <E extends CtElement> E setAllMetadata(java.util.Map<java.lang.String,java.lang.Object> metadata)
CtElement
setAllMetadata
in interface CtElement
public <E extends CtElement> E putMetadata(java.lang.String key, java.lang.Object val)
CtElement
putMetadata
in interface CtElement
public java.lang.Object getMetadata(java.lang.String key)
CtElement
getMetadata
in interface CtElement
public java.util.Map<java.lang.String,java.lang.Object> getAllMetadata()
CtElement
getAllMetadata
in interface CtElement
public java.util.Set<java.lang.String> getMetadataKeys()
CtElement
getMetadataKeys
in interface CtElement
public java.util.List<CtComment> getComments()
CtElement
getComments
in interface CtElement
public <E extends CtElement> E addComment(CtComment comment)
CtElement
element.addComment(element.getFactory().Code().createComment("comment", CtComment.CommentType.INLINE)
addComment
in interface CtElement
comment
- the commentpublic <E extends CtElement> E removeComment(CtComment comment)
CtElement
removeComment
in interface CtElement
comment
- the comment to removepublic <E extends CtElement> E setComments(java.util.List<CtComment> comments)
CtElement
setComments
in interface CtElement
public CtElement clone()
CtElement
Refactoring.copyType(CtType)
and Refactoring.copyMethod(CtMethod)
instead which does additional work beyond cloning.public <T> T getValueByRole(CtRole role)
getValueByRole
in interface CtElement
role
- the role of the returned attribute with respect to this element.
For instance, "klass.getValueByRole(CtRole.METHOD)" returns a list of methods.
See RoleHandlerHelper
for more advanced methods.public <E extends CtElement,T> E setValueByRole(CtRole role, T value)
CtElement
setValueByRole
in interface CtElement
role
- the role of the field to be setvalue
- to be assigned to this field.public CtPath getPath()
CtElement
public java.util.Iterator<CtElement> descendantIterator()
CtElement
descendantIterator
in interface CtElement
public java.lang.Iterable<CtElement> asIterable()
CtElement
asIterable
in interface CtElement
public ElementSourceFragment getOriginalSourceFragment()
SourcePositionHolder
getOriginalSourceFragment
in interface SourcePositionHolder
getOriginalSourceFragment
in interface CtElement
public void comment()
public java.util.List<CtElement> getDirectChildren()
getDirectChildren
in interface CtElement
Copyright © 2007–2021 Inria. All rights reserved.