Class Link<S extends ASTNode,T extends ASTNode>

java.lang.Object
de.monticore.utils.Link<S,T>
All Implemented Interfaces:
Iterable<Link<?,?>>

public final class Link<S extends ASTNode,T extends ASTNode> extends Object implements 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.

  • Field Details

    • source

      protected final S extends ASTNode source
    • target

      protected final T extends ASTNode target
    • parent

      protected final Link<?,?> parent
  • Constructor Details

    • Link

      public Link(S source, T target, @Nullable Link<?,?> parent)
  • Method Details

    • 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 Iterator<Link<?,?>> iterator()
      Specified by:
      iterator in interface Iterable<S extends ASTNode>
    • getLinks

      public <O extends ASTNode, D extends ASTNode> Set<Link<O,D>> getLinks(Class<O> sourceType, 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 node
      targetType - the class of the target node
      Returns:
      the set of all Links with the specified source and target types