Class MethodReference

java.lang.Object
io.sundr.model.repo.MethodReference

public class MethodReference extends Object
Represents a method reference along with its owning TypeDef. Provides functionality to analyze method dependencies and find all method references that are called directly or transitively from a given method.
  • Constructor Details

    • MethodReference

      public MethodReference(Method method, TypeDef owningType)
      Visitor that collects all MethodCall instances found during AST traversal. This includes both direct method calls and method calls embedded within expressions.
  • Method Details

    • getMethod

      public Method getMethod()
    • getOwningType

      public TypeDef getOwningType()
    • getDirectMethodReferences

      public static Set<MethodReference> getDirectMethodReferences(Method method, DefinitionRepository repository)
      Get all method references that are called directly from the given method (non-recursive). This method analyzes only the method body to find direct method calls.
      Parameters:
      method - the method to analyze (cannot be null)
      repository - the definition repository containing type definitions (cannot be null)
      Returns:
      set of direct method references
      Throws:
      IllegalArgumentException - if method or repository is null
    • getMethodReferences

      public static Set<MethodReference> getMethodReferences(Method method, DefinitionRepository repository)
      Get all method references that are called directly or transitively from the given method. This method analyzes the method body and recursively follows method calls to find all methods from types in the DefinitionRepository that are referenced.
      Parameters:
      method - the method to analyze (cannot be null)
      repository - the definition repository containing type definitions (cannot be null)
      Returns:
      set of all method references (direct and transitive)
      Throws:
      IllegalArgumentException - if method or repository is null
    • getMethodReferences

      public static Set<MethodReference> getMethodReferences(Method method)
      Get all method references that are called directly or transitively from the given method. This method uses the default DefinitionRepository instance.
      Parameters:
      method - the method to analyze (cannot be null)
      Returns:
      set of all method references (direct and transitive)
      Throws:
      IllegalArgumentException - if method is null
    • getDirectMethodCallers

      public static Set<MethodReference> getDirectMethodCallers(MethodReference targetMethod, DefinitionRepository repository)
      Find all methods that directly call the specified target method. This is the reverse of getDirectMethodReferences() - instead of finding what a method calls, this finds what methods call the target method.
      Parameters:
      targetMethod - the method reference to find callers for
      repository - the definition repository containing type definitions
      Returns:
      set of method references that directly call the target method
    • getMethodCallers

      public static Set<MethodReference> getMethodCallers(MethodReference targetMethod, DefinitionRepository repository)
      Find all methods that directly or transitively call the specified target method. This is the reverse of getMethodReferences() - instead of finding what a method calls, this finds all methods that call the target method either directly or through a chain of calls.
      Parameters:
      targetMethod - the method reference to find callers for
      repository - the definition repository containing type definitions
      Returns:
      set of method references that directly or transitively call the target method
    • clearCache

      public static void clearCache()
      Clears the method resolution cache. This should be called when the repository changes to ensure cached results remain valid.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object