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
-
Constructor Summary
ConstructorsConstructorDescriptionJavaSourceSet(UUID id, String name, List<JavaType.FullyQualified> classpath, Map<String, List<JavaType.FullyQualified>> gavToTypes) JavaSourceSet(UUID id, String name, List<JavaType.FullyQualified> classpath, Map<String, List<JavaType.FullyQualified>> gavToTypes, @Nullable JavaTypeFactory typeFactory) -
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.dirtyProjects(org.openrewrite.ExecutionContext ctx) static booleanisDirty(org.openrewrite.ExecutionContext ctx, @Nullable org.openrewrite.SourceFile sourceFile) Whether a source file's classpath may be stale because a dependency-mutating recipe ran earlier in this recipe run.static voidProducer-side: markprojectNameas having had its classpath invalidated by a dependency mutation earlier in this recipe run.static voidmarkDirty(org.openrewrite.ExecutionContext ctx, @Nullable org.openrewrite.SourceFile sourceFile) Producer-side: mark the project identified bysourceFile'sProjectIdentitymarker as dirty.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(UUID id, String name, List<JavaType.FullyQualified> classpath, Map<String, List<JavaType.FullyQualified>> gavToTypes) -
JavaSourceSet
@ConstructorProperties({"id","name","classpath","gavToTypes","typeFactory"}) public JavaSourceSet(UUID id, String name, List<JavaType.FullyQualified> classpath, Map<String, List<JavaType.FullyQualified>> gavToTypes, @Nullable JavaTypeFactory typeFactory)
-
-
Method Details
-
dirtyProjects
- Returns:
- the set of project names that have been marked dirty in the current recipe run,
or
nullwhen no project has been marked dirty. Returned set is the internal registry; callers must not mutate it.
-
isDirty
public static boolean isDirty(org.openrewrite.ExecutionContext ctx, @Nullable org.openrewrite.SourceFile sourceFile) Whether a source file's classpath may be stale because a dependency-mutating recipe ran earlier in this recipe run. WhensourceFilecarries aProjectIdentitymarker the check is project-scoped; otherwise it falls back to "any project in the run is dirty" so ambiguity-sensitive decisions still take the safe path conservatively.This is a static accessor (not an instance method) so that callers which can't find a
JavaSourceSeton the source file can still consult the registry — the dirty signal is project-scoped, not source-set-scoped. -
markDirty
Producer-side: markprojectNameas having had its classpath invalidated by a dependency mutation earlier in this recipe run. Ambiguity-sensitive consumer recipes read the registry viaisDirty(ExecutionContext, SourceFile)and take the safe path when the project is dirty. -
markDirty
public static void markDirty(org.openrewrite.ExecutionContext ctx, @Nullable org.openrewrite.SourceFile sourceFile) Producer-side: mark the project identified bysourceFile'sProjectIdentitymarker as dirty. No-op whensourceFileisnullor has no project marker. -
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)
-