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

    • JavaSourceSet

      public JavaSourceSet()
  • Method Details

    • findClasspathType

      public Optional<JavaType.FullyQualified> findClasspathType(String fqn)
      Resolve a fully-qualified type name through this source set's classpath. Equivalent to walking
      invalid reference
      #getClasspath()
      and matching via TypeUtils.fullyQualifiedNamesAreEqual(String, String), but uses the JavaSourceSet.ClasspathIndex fast path when the backing list provides one. Recipes that previously hand-rolled the loop over getClasspath() should prefer this accessor.
    • classpathTypesInPackage

      public Stream<JavaType.FullyQualified> classpathTypesInPackage(String packageName)
      Stream the classpath types whose package name equals packageName. Uses the JavaSourceSet.ClasspathIndex fast path when available; otherwise filters
      invalid reference
      #getClasspath()
      via JavaType.FullyQualified.getPackageName(). Recipes that need to enumerate or test types in a specific package should prefer this over scanning the full classpath.
    • 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)