Class AddImport<P>

java.lang.Object
org.openrewrite.TreeVisitor<org.openrewrite.java.tree.J,P>
org.openrewrite.java.JavaVisitor<P>

public class AddImport<P> extends KotlinIsoVisitor<P>
A Kotlin refactoring visitor that can be used to add imports to a given compilation unit. This visitor can also be configured to only add the import if the imported class / member is referenced within the compilation unit.

The fullyQualifiedName must be supplied and represents a fully qualified class name.

The member is an optional member within the imported type. It can be set to "*" to represent a wildcard import.

The import can optionally also be configured with an alias.

The onlyIfReferenced is a flag (defaulted to true) to indicate if the import should only be added if there is a reference to the imported class / member.

  • Constructor Details

    • AddImport

      public AddImport(@Nullable @Nullable String packageName, String typeName, @Nullable @Nullable String member, @Nullable @Nullable String alias, boolean onlyIfReferenced)
  • Method Details

    • preVisit

      @Nullable public @Nullable org.openrewrite.java.tree.J preVisit(org.openrewrite.java.tree.J tree, P p)
      Overrides:
      preVisit in class org.openrewrite.TreeVisitor<org.openrewrite.java.tree.J,P>