public interface Term
A Z construct/term.
This is the base interface for all Z constructs (also called term) and thus for the AST for Z. It contains methods that each Z term must provide.
Annotations can be used by tools to provide, for instance, type information, location information, ect. They can be used to attach any type of information to a Z term.
Note that annotations are NOT considered as children of a term,
that means they are not returned via the getChildren()
-method.
net.sourceforge.czt.base.ast
Modifier and Type | Method and Description |
---|---|
<R> R |
accept(Visitor<R> visitor)
Accepts a visitor.
|
int |
annsSize()
Returns whether the annotation list size.
|
Term |
create(Object[] args)
Creates a new object of the implementing class
with the objects in
args as its children. |
<T> T |
getAnn(Class<T> aClass)
Returns one of the
aClass annotations of this
term, or null if the term does not contain an
annotation of this type. |
List<Object> |
getAnns()
Returns a list of annotations.
|
Object[] |
getChildren()
Returns an array of all the children of this term,
thus providing the possibility to write generic
visitors that traverse a tree of Z terms without even knowing
the kind of term they are visiting.
|
boolean |
hasAnn()
Returns true when
annsSize() has more than zero elements. |
<T> boolean |
hasAnn(Class<T> aClass)
Checks whether the term has any annotation of the given class type
|
<T> void |
removeAnn(Class<T> aClass)
Removes all annotations of the specific class.
|
<T> boolean |
removeAnn(T annotation)
Removes a specific annotation, if present.
|
<R> R accept(Visitor<R> visitor)
Accepts a visitor.
This method provides support for the visitor design pattern. Depending on the kind of visitor interfaces the given visitor implements, the visited term chooses the visit-method which fits best and returns the object that a call to this method returns.
visitor
- the visitor that wants to visit this term.net.sourceforge.czt.base.visitor
Object[] getChildren()
Returns an array of all the children of this term, thus providing the possibility to write generic visitors that traverse a tree of Z terms without even knowing the kind of term they are visiting.
The order and types of children is the same as the arguments to the corresponding create method in the factory.
Term create(Object[] args)
Creates a new object of the implementing class
with the objects in args
as its children.
The order and type of the children is similar
to the one returned by getChildren()
.
This method is intended to be used together with method
getChildren()
by generic visitors.
args
- the children of the term to be created.t
such that
this.getClass() == t.getClass()
and forall i
t.getChildren()[i] == args[i]
.getChildren()
List<Object> getAnns()
Returns a list of annotations.
To add or remove elements, use the methods provided by the List interface (that's why there is no need for a setter method).
Avoid calling this method directly and prefer to check with hasAnn()
first. This delays creation of underlying arrays and lead to considerable memory
optimisation on large specs.
null
).<T> T getAnn(Class<T> aClass)
Returns one of the aClass
annotations of this
term, or null
if the term does not contain an
annotation of this type.
T
- aClass
- int annsSize()
getAnns().size()
. If 0, no array is created.boolean hasAnn()
annsSize()
has more than zero elements.<T> boolean hasAnn(Class<T> aClass)
T
- type of annotation classaClass
- class to check<T> boolean removeAnn(T annotation)
T
- type of annotationannotation
- instance to remove<T> void removeAnn(Class<T> aClass)
T
- type of annotationaClass
- class to checkCopyright © 2003–2016 Community Z Tools Project. All rights reserved.