public interface CtElement extends FactoryAccessor, CtVisitable, java.lang.Cloneable, CtQueryable, java.io.Serializable, SourcePositionHolder
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 |
delete()
Deletes the element.
|
java.util.Iterator<CtElement> |
descendantIterator()
Returns an iterator over this CtElement's descendants.
|
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.
|
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) |
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.
|
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>> annotation)
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.
|
<E extends CtElement> |
setImplicit(boolean b)
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() |
void |
updateAllParentsBelow()
Calculates and sets all the parents below this element.
|
getFactory, setFactory
accept
filterChildren, map, map
<A extends java.lang.annotation.Annotation> A getAnnotation(java.lang.Class<A> annotationType)
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.
A
- the annotation's typeannotationType
- the annotation's class<A extends java.lang.annotation.Annotation> CtAnnotation<A> getAnnotation(CtTypeReference<A> annotationType)
annotationType
- the annotation type<A extends java.lang.annotation.Annotation> boolean hasAnnotation(java.lang.Class<A> annotationType)
annotationType
- the annotation typejava.util.List<CtAnnotation<? extends java.lang.annotation.Annotation>> getAnnotations()
java.lang.String getDocComment()
getComments()
.and CtJavaDoc
java.lang.String getShortRepresentation()
SourcePosition getPosition()
getPosition
in interface SourcePositionHolder
SourcePosition.isValidPosition()
to detect whether return instance contains start/end indexes.void replace(CtElement element)
<E extends CtElement> void replace(java.util.Collection<E> elements)
replace(CtElement)
.
If `elements` is empty, it is equivalent to delete()
.<E extends CtElement> E addAnnotation(CtAnnotation<? extends java.lang.annotation.Annotation> annotation)
annotation
- boolean removeAnnotation(CtAnnotation<? extends java.lang.annotation.Annotation> annotation)
annotation
- <E extends CtElement> E setDocComment(java.lang.String docComment)
<E extends CtElement> E setPosition(SourcePosition position)
position
- of this element in the input source files<E extends CtElement> java.util.List<E> getAnnotatedChildren(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
E
- the element's typeannotationType
- the annotation typeboolean isImplicit()
<E extends CtElement> E setImplicit(boolean b)
java.util.Set<CtTypeReference<?>> getReferencedTypes()
<E extends CtElement> java.util.List<E> getElements(Filter<E> filter)
<E extends CtElement> E setPositions(SourcePosition position)
position
- of this element and all children in the input source file<E extends CtElement> E setAnnotations(java.util.List<CtAnnotation<? extends java.lang.annotation.Annotation>> annotation)
CtElement getParent() throws ParentNotInitializedException
ParentNotInitializedException
- when the parent of this element is not initialized<P extends CtElement> P getParent(java.lang.Class<P> parentType) throws ParentNotInitializedException
ParentNotInitializedException
<E extends CtElement> E getParent(Filter<E> filter) throws ParentNotInitializedException
ParentNotInitializedException
<E extends CtElement> E setParent(E parent)
parent
- parent reference.boolean isParentInitialized()
boolean hasParent(CtElement candidate)
void updateAllParentsBelow()
CtRole getRoleInParent()
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
.
void delete()
<E extends CtElement> E setAllMetadata(java.util.Map<java.lang.String,java.lang.Object> metadata)
<E extends CtElement> E putMetadata(java.lang.String key, java.lang.Object val)
java.lang.Object getMetadata(java.lang.String key)
java.util.Map<java.lang.String,java.lang.Object> getAllMetadata()
java.util.Set<java.lang.String> getMetadataKeys()
<E extends CtElement> E setComments(java.util.List<CtComment> comments)
java.util.List<CtComment> getComments()
<E extends CtElement> E addComment(CtComment comment)
element.addComment(element.getFactory().Code().createComment("comment", CtComment.CommentType.INLINE)
comment
- the comment<E extends CtElement> E removeComment(CtComment comment)
comment
- the comment to removeCtElement clone()
Refactoring.copyType(CtType)
and Refactoring.copyMethod(CtMethod)
instead which does additional work beyond cloning.<T> T getValueByRole(CtRole role)
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.<E extends CtElement,T> E setValueByRole(CtRole role, T value)
role
- the role of the field to be setvalue
- to be assigned to this field.CtPath getPath()
java.util.Iterator<CtElement> descendantIterator()
java.lang.Iterable<CtElement> asIterable()
java.util.List<CtElement> getDirectChildren()
java.lang.String toString()
toString
in class java.lang.Object
Environment.getPrettyPrintingMode()
.java.lang.String toStringDebug()
java.lang.String prettyprint()
ImportAnalyzer
which would change the model: add/remove imports, change the value `implicit` of some model elements, etc.ElementSourceFragment getOriginalSourceFragment()
SourcePositionHolder
getOriginalSourceFragment
in interface SourcePositionHolder
Copyright © 2007–2021 Inria. All rights reserved.