Interface LabeledCallGraph<L>

Type Parameters:
L - the type of the labels attached to the calls
All Superinterfaces:
CallGraph
All Known Subinterfaces:
MutableLabeledCallGraph<L>
All Known Implementing Classes:
LabeledGraphBasedCallGraph

public interface LabeledCallGraph<L> extends CallGraph
A call graph whose calls (edges) can carry labels of type L. The label type is not restricted, e.g. an enum, a record or a sealed interface to combine several kinds of labels:

 enum Hotness { HOT, COLD }

 LabeledCallGraph<Hotness> cg = LabeledGraphBasedCallGraph.of(callGraph);
 Set<Hotness> labels = cg.getLabels(call);
 
Labels are compared with Object.equals(Object), so a label is stored at most once per call. Call graphs that do not need labels should keep using CallGraph, which has no overhead for labels.
  • Method Details

    • getLabels

      @NonNull Set<L> getLabels(@NonNull CallGraph.Call call)
      This method returns all labels attached to a call in the call graph.
      Parameters:
      call - the requested call in the call graph
      Returns:
      an unmodifiable set of the labels of the call. It is empty if the call has no labels or is not contained in the call graph.
    • hasLabel

      default boolean hasLabel(@NonNull CallGraph.Call call, @NonNull L label)
      This method checks if a given label is attached to a call in the call graph.
      Parameters:
      call - the requested call in the call graph
      label - the requested label
      Returns:
      true if the label is attached to the call, otherwise false
    • callsFrom

      default @NonNull Set<CallGraph.Call> callsFrom(@NonNull MethodSignature sourceMethod, @NonNull Predicate<? super L> labelFilter)
      This method returns all outgoing calls of a given method signature that carry at least one label matching the given filter.
      Parameters:
      sourceMethod - the method signature of the requested node in the call graph
      labelFilter - the filter the labels of the calls are tested against
      Returns:
      a set of outgoing calls with at least one matching label
    • callsTo

      default @NonNull Set<CallGraph.Call> callsTo(@NonNull MethodSignature targetMethod, @NonNull Predicate<? super L> labelFilter)
      This method returns all incoming calls of a given method signature that carry at least one label matching the given filter.
      Parameters:
      targetMethod - the method signature of the requested node in the call graph
      labelFilter - the filter the labels of the calls are tested against
      Returns:
      a set of incoming calls with at least one matching label
    • toDotEdge

      default StringBuilder toDotEdge(CallGraph.Call call)
      exports a call of the call graph to an edge in a dot file. The edge label contains the line number of the call and, if present, the labels of the call.
      Specified by:
      toDotEdge in interface CallGraph
      Parameters:
      call - the data of the call
      Returns:
      an edge defining the call in the dot file
    • copy

      @NonNull MutableLabeledCallGraph<L> copy()
      This method copies the call graph including the labels of its calls.
      Specified by:
      copy in interface CallGraph
      Returns:
      a mutable copy of the call graph with the same labels