Created
November 23, 2021 09:54
-
-
Save jonaslindmark/4a333ed4723a4a48d492c1b0c6217337 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.something.Inner; | |
public class Test { | |
public static void main(String[] args) { | |
var one = new Inner(); | |
var second = new Inner(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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