Package de.monticore.utils
Class Link<S extends ASTNode,T extends ASTNode>
- java.lang.Object
-
- de.monticore.utils.Link<S,T>
-
- All Implemented Interfaces:
java.lang.Iterable<Link<?,?>>
public final class Link<S extends ASTNode,T extends ASTNode> extends java.lang.Object implements java.lang.Iterable<Link<?,?>>
Represents a link between two ASTNodes.When writing transformations that translate from one AST to another, it is often cleaner not to translate all information in a single operation. Splitting this translation process however necessitates that sequentially executed translations always operate on the same source and target nodes. For this purpose a Link provides a way for the program to "remember" which source nodes are associated with which target nodes.
Going beyond that, Links also form a tree that mirrors the structure in both ASTs. This is based on the assumption that the overall structure of both source and target AST will also be equivalent.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddChildLink(Link<?,?> childLink)<O extends ASTNode,D extends ASTNode>
java.util.Set<Link<O,D>>getLinks(java.lang.Class<O> sourceType, java.lang.Class<D> targetType)Looks up all Links in the subtree spanned by this Link by type of source and target.java.util.Iterator<Link<?,?>>iterator()Link<?,?>parent()Link<?,?>rootLink()Ssource()Ttarget()
-
-
-
Method Detail
-
addChildLink
protected void addChildLink(Link<?,?> childLink)
-
source
public S source()
- Returns:
- the source node of this Link
-
target
public T target()
- Returns:
- the target node of this Link
-
parent
public Link<?,?> parent()
- Returns:
- the parent Link of this Link
-
rootLink
public Link<?,?> rootLink()
- Returns:
- the topmost Link in the tree to which this Link belongs
-
iterator
public java.util.Iterator<Link<?,?>> iterator()
-
getLinks
public <O extends ASTNode,D extends ASTNode> java.util.Set<Link<O,D>> getLinks(java.lang.Class<O> sourceType, java.lang.Class<D> targetType)
Looks up all Links in the subtree spanned by this Link by type of source and target. You can use super classes like 'ASTNode.class' if you want to filter more loosely.- Parameters:
sourceType- the class of the source nodetargetType- the class of the target node- Returns:
- the set of all Links with the specified source and target types
-
-