Package org.openrewrite.java.internal
Class TypesInUse
java.lang.Object
org.openrewrite.java.internal.TypesInUse
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TypesInUsebuild(JavaSourceFile cu) booleandeclaresMethod(MethodMatcher matcher) Whether this compilation unit declares any method matchingmatcher.booleanhasMethodUse(MethodMatcher matcher) Whether this compilation unit invokes any method matchingmatcher.booleanWhether any type referenced in this compilation unit is assignable tofullyQualifiedType.booleanhasTypeInPackage(String packageName, boolean includeImplicit) Whether this compilation unit references any type whose package equalspackageNameexactly (i.e., thecom.foo.*pattern).booleanhasTypeInPackageOrSubpackage(String packageName, boolean includeImplicit) Whether this compilation unit references any type whose package equalspackageNameor starts withpackageName + '.'(i.e., thecom.foo..*pattern).booleanhasTypeMatching(TypeNameMatcher matcher, boolean includeImplicit) Whether any FQN reachable through the assignability closure of this compilation unit matchesmatcher.static TypesInUseof(JavaSourceFile cu, Set<JavaType> typesInUse, Set<JavaType.Method> declaredMethods, Set<JavaType.Method> usedMethods, Set<JavaType.Variable> variables) Constructs aTypesInUsedirectly from pre-built sets, skipping the full LST walk performed bybuild(JavaSourceFile).
-
Constructor Details
-
TypesInUse
public TypesInUse()
-
-
Method Details
-
build
-
of
public static TypesInUse of(JavaSourceFile cu, Set<JavaType> typesInUse, Set<JavaType.Method> declaredMethods, Set<JavaType.Method> usedMethods, Set<JavaType.Variable> variables) Constructs aTypesInUsedirectly from pre-built sets, skipping the full LST walk performed bybuild(JavaSourceFile). Intended for callers that can source the same information from outside the tree (e.g. a serialized index). -
hasType
Whether any type referenced in this compilation unit is assignable tofullyQualifiedType. Mirrors the loop inUsesType.visit: types-in-use, imports, and (whenincludeImplicit) 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, matchingTypeUtils.fullyQualifiedNamesAreEqual(String, String). -
hasTypeInPackage
Whether this compilation unit references any type whose package equalspackageNameexactly (i.e., thecom.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, socom.foo.Outer.Innerfrom a canonicalized inner-class FQN does not registercom.foo.Outeras a package). -
hasTypeInPackageOrSubpackage
Whether this compilation unit references any type whose package equalspackageNameor starts withpackageName + '.'(i.e., thecom.foo..*pattern). The descendant-leaf rollup tracks only real leaves, so the answer is O(depth) regardless of trie size. -
hasTypeMatching
Whether any FQN reachable through the assignability closure of this compilation unit matchesmatcher. Walks every raw-leaf path in the trie and tests the matcher against the reconstructed FQN — equivalent to the per-element loop inUsesType'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 ofhasTypeInPackage(java.lang.String, boolean). -
hasMethodUse
Whether this compilation unit invokes any method matchingmatcher. -
declaresMethod
Whether this compilation unit declares any method matchingmatcher.
-