Class TypesInUse

java.lang.Object
org.openrewrite.java.internal.TypesInUse

public class TypesInUse extends Object
  • Constructor Details

    • TypesInUse

      public TypesInUse()
  • Method Details

    • build

      public static TypesInUse build(JavaSourceFile cu)
    • of

      public static TypesInUse of(JavaSourceFile cu, Set<JavaType> typesInUse, Set<JavaType.Method> declaredMethods, Set<JavaType.Method> usedMethods, Set<JavaType.Variable> variables)
      Constructs a TypesInUse directly from pre-built sets, skipping the full LST walk performed by build(JavaSourceFile). Intended for callers that can source the same information from outside the tree (e.g. a serialized index).
    • hasType

      public boolean hasType(String fullyQualifiedType, boolean includeImplicit)
      Whether any type referenced in this compilation unit is assignable to fullyQualifiedType. Mirrors the loop in UsesType.visit: types-in-use, imports, and (when includeImplicit) the declaring/return/parameter types of used methods.

      The first call materializes the closure for the file and caches it; subsequent calls are O(1). $ and . are treated as equivalent in inner-class FQNs, matching TypeUtils.fullyQualifiedNamesAreEqual(String, String).

    • hasTypeInPackage

      public boolean hasTypeInPackage(String packageName, boolean includeImplicit)
      Whether this compilation unit references any type whose package equals packageName exactly (i.e., the com.foo.* pattern). Navigation to the package node is O(depth); matching is a constant-time check for any real-leaf child (alias children are deliberately ignored, so com.foo.Outer.Inner from a canonicalized inner-class FQN does not register com.foo.Outer as a package).
    • hasTypeInPackageOrSubpackage

      public boolean hasTypeInPackageOrSubpackage(String packageName, boolean includeImplicit)
      Whether this compilation unit references any type whose package equals packageName or starts with packageName + '.' (i.e., the com.foo..* pattern). The descendant-leaf rollup tracks only real leaves, so the answer is O(depth) regardless of trie size.
    • hasTypeMatching

      public boolean hasTypeMatching(TypeNameMatcher matcher, boolean includeImplicit)
      Whether any FQN reachable through the assignability closure of this compilation unit matches matcher. Walks every raw-leaf path in the trie and tests the matcher against the reconstructed FQN — equivalent to the per-element loop in UsesType's pre-cache implementation, but iterated once per (file, matcher) pair regardless of how many recipe instances ask. Alias paths are excluded so canonical inner-class FQNs only match through their raw form, mirroring the semantics of hasTypeInPackage(java.lang.String, boolean).
    • hasMethodUse

      public boolean hasMethodUse(MethodMatcher matcher)
      Whether this compilation unit invokes any method matching matcher.
    • declaresMethod

      public boolean declaresMethod(MethodMatcher matcher)
      Whether this compilation unit declares any method matching matcher.