Package org.openrewrite.java.marker
Class JavaSourceSet
java.lang.Object
org.openrewrite.java.marker.JavaSourceSet
- All Implemented Interfaces:
org.openrewrite.marker.Marker,org.openrewrite.marker.SourceSet
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceSPI forclasspathbackings that can resolve a fully-qualified name without scanning the entire list. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddTypesForGav(String gavKey, List<JavaType.FullyQualified> types) Add types for the given GAV key to this source set's classpath and gavToTypes mapping.static JavaSourceSetbuild(String sourceSetName, Collection<Path> classpath) Extract type information from the provided classpath.static JavaSourceSetbuild(String sourceSetName, Collection<Path> classpath, JavaTypeCache ignore, boolean fullTypeInformation) Deprecated.classpathTypesInPackage(String packageName) Stream the classpath types whose package name equalspackageName.findClasspathType(String fqn) Resolve a fully-qualified type name through this source set's classpath.removeTypesForGav(String gavKey) Remove all types associated with the given GAV key from this source set's classpath and gavToTypes mapping.removeTypesMatching(String groupIdPattern, String artifactIdPattern) Remove types from this source set whose GAV keys match the given groupId and artifactId glob patterns.static List<JavaType.FullyQualified> typesFromPath(Path path, @Nullable String acceptPackage) static org.openrewrite.SourceFileupdateOnSourceFile(org.openrewrite.SourceFile sf, Function<JavaSourceSet, JavaSourceSet> transform) Apply a transformation to theJavaSourceSetmarker on a source file and replace it if changed.static org.openrewrite.SourceFileupdateOnSourceFile(org.openrewrite.SourceFile sf, Map<String, JavaSourceSet> cache, Function<JavaSourceSet, JavaSourceSet> transform) Apply a transformation to theJavaSourceSetmarker on a source file, using a cache keyed byJavaProjectID and source set name to avoid redundant recomputation across files in the same source set.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openrewrite.marker.Marker
getId, print, withIdMethods inherited from interface org.openrewrite.marker.SourceSet
getName, withName
-
Constructor Details
-
JavaSourceSet
public JavaSourceSet()
-
-
Method Details
-
findClasspathType
Resolve a fully-qualified type name through this source set's classpath. Equivalent to walkingand matching viainvalid reference
#getClasspath()TypeUtils.fullyQualifiedNamesAreEqual(String, String), but uses theJavaSourceSet.ClasspathIndexfast path when the backing list provides one. Recipes that previously hand-rolled the loop overgetClasspath()should prefer this accessor. -
classpathTypesInPackage
Stream the classpath types whose package name equalspackageName. Uses theJavaSourceSet.ClasspathIndexfast path when available; otherwise filtersviainvalid reference
#getClasspath()JavaType.FullyQualified.getPackageName(). Recipes that need to enumerate or test types in a specific package should prefer this over scanning the full classpath. -
addTypesForGav
Add types for the given GAV key to this source set's classpath and gavToTypes mapping.- Parameters:
gavKey- a "group:artifact:version" stringtypes- the types provided by the artifact- Returns:
- a new JavaSourceSet with the types added
-
removeTypesForGav
Remove all types associated with the given GAV key from this source set's classpath and gavToTypes mapping.- Parameters:
gavKey- a "group:artifact:version" string- Returns:
- a new JavaSourceSet with the types removed, or this instance if the key is not present
-
removeTypesMatching
Remove types from this source set whose GAV keys match the given groupId and artifactId glob patterns.- Parameters:
groupIdPattern- glob pattern for groupId matchingartifactIdPattern- glob pattern for artifactId matching- Returns:
- a new JavaSourceSet with matching types removed, or this instance if no keys match
-
updateOnSourceFile
public static org.openrewrite.SourceFile updateOnSourceFile(org.openrewrite.SourceFile sf, Function<JavaSourceSet, JavaSourceSet> transform) Apply a transformation to theJavaSourceSetmarker on a source file and replace it if changed.- Parameters:
sf- the source file to updatetransform- a function that takes the current JavaSourceSet and returns an updated one- Returns:
- the source file with the updated marker, or unchanged if no JavaSourceSet is present or the transform is a no-op
-
updateOnSourceFile
public static org.openrewrite.SourceFile updateOnSourceFile(org.openrewrite.SourceFile sf, Map<String, JavaSourceSet> cache, Function<JavaSourceSet, JavaSourceSet> transform) Apply a transformation to theJavaSourceSetmarker on a source file, using a cache keyed byJavaProjectID and source set name to avoid redundant recomputation across files in the same source set.- Parameters:
sf- the source file to updatecache- a mutable map used to cache updated JavaSourceSets across callstransform- a function that takes the current JavaSourceSet and returns an updated one- Returns:
- the source file with the updated marker, or unchanged if no JavaSourceSet/JavaProject is present
-
build
@Deprecated public static JavaSourceSet build(String sourceSetName, Collection<Path> classpath, JavaTypeCache ignore, boolean fullTypeInformation) Deprecated.Extract type information from the provided classpath. Uses ClassGraph to compute the classpath.Does not support gavToTypes or typeToGav mapping
- Parameters:
ignore- Not used, does not do anything, to be deletedfullTypeInformation- Not used, does not do anything, to be deleted
-
build
Extract type information from the provided classpath. Uses file I/O to compute the classpath. -
typesFromPath
public static List<JavaType.FullyQualified> typesFromPath(Path path, @Nullable String acceptPackage)
-