Class JavaSourceSet

java.lang.Object
org.openrewrite.java.marker.JavaSourceSet
All Implemented Interfaces:
org.openrewrite.marker.Marker, org.openrewrite.marker.SourceSet

public class JavaSourceSet extends Object implements org.openrewrite.marker.SourceSet
  • Constructor Details

  • Method Details

    • dirtyProjects

      public static @Nullable Set<String> dirtyProjects(org.openrewrite.ExecutionContext ctx)
      Returns:
      the set of project names that have been marked dirty in the current recipe run, or null when 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. When sourceFile carries a ProjectIdentity marker 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 JavaSourceSet on the source file can still consult the registry — the dirty signal is project-scoped, not source-set-scoped.

    • markDirty

      public static void markDirty(org.openrewrite.ExecutionContext ctx, String projectName)
      Producer-side: mark projectName as having had its classpath invalidated by a dependency mutation earlier in this recipe run. Ambiguity-sensitive consumer recipes read the registry via isDirty(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 by sourceFile's ProjectIdentity marker as dirty. No-op when sourceFile is null or has no project marker.
    • addTypesForGav

      public JavaSourceSet addTypesForGav(String gavKey, List<JavaType.FullyQualified> types)
      Add types for the given GAV key to this source set's classpath and gavToTypes mapping.
      Parameters:
      gavKey - a "group:artifact:version" string
      types - the types provided by the artifact
      Returns:
      a new JavaSourceSet with the types added
    • removeTypesForGav

      public JavaSourceSet removeTypesForGav(String gavKey)
      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

      public JavaSourceSet removeTypesMatching(String groupIdPattern, String artifactIdPattern)
      Remove types from this source set whose GAV keys match the given groupId and artifactId glob patterns.
      Parameters:
      groupIdPattern - glob pattern for groupId matching
      artifactIdPattern - 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 the JavaSourceSet marker on a source file and replace it if changed.
      Parameters:
      sf - the source file to update
      transform - 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 the JavaSourceSet marker on a source file, using a cache keyed by JavaProject ID and source set name to avoid redundant recomputation across files in the same source set.
      Parameters:
      sf - the source file to update
      cache - a mutable map used to cache updated JavaSourceSets across calls
      transform - 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 deleted
      fullTypeInformation - Not used, does not do anything, to be deleted
    • build

      public static JavaSourceSet build(String sourceSetName, Collection<Path> classpath)
      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)