Class AddImport<P>

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

public class AddImport<P> extends JavaIsoVisitor<P>
A Java refactoring visitor that can be used to add an import (or static import) to a given compilation unit. This visitor can also be configured to only add the import if the imported class/method are referenced within the compilation unit.

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

The statik is an optional method within the imported type. The staticMethod can be set to "*" to represent a static wildcard import.

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/method.

  • Constructor Details

    • AddImport

      public AddImport(String type, @Nullable @Nullable String statik, boolean onlyIfReferenced)
  • Method Details

    • preVisit

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