Class TopologicalIndex
 java.lang.Object

 software.amazon.smithy.codegen.core.TopologicalIndex

 All Implemented Interfaces:
KnowledgeIndex
public final class TopologicalIndex extends java.lang.Object implements KnowledgeIndex
Creates a reversetopological ordering of shapes.This kind of reverse topological ordering is useful for languages like C++ that need to define shapes before they can be referenced. Only nonrecursive shapes are reversetopologically ordered using
getOrderedShapes()
. However, recursive shapes are queryable throughgetRecursiveShapes()
. When this returnedSet
is iterated, recursive shapes are ordered by their degree of recursion (the number of edges across all recursive closures), and then by shape ID when multiple shapes have the same degree of recursion.The recursion closures of a shape can be queried using
getRecursiveClosure(ToShapeId)
. This method returns a list of paths from the shape back to itself. This list can be useful for code generation to generate different code based on if a recursive path passes through particular types of shapes.


Constructor Summary
Constructors Constructor Description TopologicalIndex(Model model)

Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<Shape>
getOrderedShapes()
Gets all reversetopologically ordered shapes, including members.java.util.Set<PathFinder.Path>
getRecursiveClosure(ToShapeId shape)
Gets the recursive closure of a given shape represented asPathFinder.Path
objects.java.util.Set<Shape>
getRecursiveShapes()
Gets all shapes that have edges that are part of a recursive closure, including container shapes (list/set/map/structure/union) and members.boolean
isRecursive(ToShapeId shape)
Checks if the given shape has edges with recursive references.static TopologicalIndex
of(Model model)
Creates a newTopologicalIndex
.



Constructor Detail

TopologicalIndex
public TopologicalIndex(Model model)


Method Detail

of
public static TopologicalIndex of(Model model)
Creates a newTopologicalIndex
. Parameters:
model
 Model to create the index from. Returns:
 The created (or previously cached)
TopologicalIndex
.

getOrderedShapes
public java.util.Set<Shape> getOrderedShapes()
Gets all reversetopologically ordered shapes, including members.When the returned
Set
is iterated, shapes are returned in reversetopological. Note that the returned set does not contain recursive shapes. Returns:
 Nonrecursive shapes in a reversetopological ordered
Set
.

getRecursiveShapes
public java.util.Set<Shape> getRecursiveShapes()
Gets all shapes that have edges that are part of a recursive closure, including container shapes (list/set/map/structure/union) and members.When iterated, the returned
Set
is ordered from fewest number of edges to the most number of edges in the recursive closures, and then alphabetically by shape ID when there are multiple entries with the same number of edges. Returns:
 All shapes that are part of a recursive closure.

isRecursive
public boolean isRecursive(ToShapeId shape)
Checks if the given shape has edges with recursive references. Parameters:
shape
 Shape to check. Returns:
 True if the shape has recursive edges.

getRecursiveClosure
public java.util.Set<PathFinder.Path> getRecursiveClosure(ToShapeId shape)
Gets the recursive closure of a given shape represented asPathFinder.Path
objects.The first element of each path is the given
shape
, and the last element of each path is the first shape that is encountered a second time in the path (i.e., the point of recursion). Parameters:
shape
 Shape to get the recursive closures of. Returns:
 The closures of the shape, or an empty
Set
if the shape is not recursive.

