Skip to content

Instantly share code, notes, and snippets.

@jonaslindmark
Created November 23, 2021 09:54
Show Gist options
  • Save jonaslindmark/4a333ed4723a4a48d492c1b0c6217337 to your computer and use it in GitHub Desktop.
Save jonaslindmark/4a333ed4723a4a48d492c1b0c6217337 to your computer and use it in GitHub Desktop.
import com.something.Inner;
public class Test {
public static void main(String[] args) {
var one = new Inner();
var second = new Inner();
}
}
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import org.openrewrite.InMemoryExecutionContext;
import org.openrewrite.Result;
import org.openrewrite.java.ChangeType;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.tree.J;
public class Rewrite {
public static void main(final String... args) throws Exception {
final InMemoryExecutionContext ctx = new InMemoryExecutionContext();
final List<Path> paths = List.of(
Paths.get("/path/to/Test.java"));
final JavaParser javaParser =
JavaParser.fromJavaVersion()
.logCompilationWarningsAndErrors(false)
.build();
final List<J.CompilationUnit> compilationUnits = javaParser.parse(paths, null, ctx);
var recipe = new ChangeType("com.something.Outer.Inner", "com.something.Inner");
final List<Result> results = recipe.run(compilationUnits);
results.forEach(result -> System.out.println(result.diff()));
}
}
import com.something.Outer.Inner;
import com.something.Outer;
public class Test {
public static void main(String[] args) {
var one = new Inner();
var second = new Outer.Inner();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment