From cde89808e3d9730fe784597bd6bbfc51753663a1 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Fri, 27 May 2022 07:39:18 +0200 Subject: Add support for adding missing and removing unused imports This adds a post-process step which automatically adds unambiguous imports, removes unused imports and sorts the import list (formatting matches standard IntelliJ settings). This will preserve line count across versions at all cost. Java only for now because it's a lot more tricky with Kotlin and we don't yet use Kotlin ourselves (and won't be preprocessing it in the future either). --- src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/test/kotlin/com/replaymod/gradle/remap/util') diff --git a/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt b/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt index c5b8851..d1ed905 100644 --- a/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt +++ b/src/test/kotlin/com/replaymod/gradle/remap/util/TestData.kt @@ -48,14 +48,21 @@ object TestData { findClasspathEntry("BMarkerKt"), ) patternAnnotation = "remap.Pattern" + manageImports = true } - fun remap(content: String, patternsBefore: String = "", patternsAfter: String = ""): String = transformer.remap(mapOf( - "test.java" to content, + fun remap(content: String): String = + remap("test.java", content) + fun remap(fileName: String, content: String): String = + remap(fileName, content, "", "") + fun remap(content: String, patternsBefore: String, patternsAfter: String): String = + remap("test.java", content, patternsBefore, patternsAfter) + fun remap(fileName: String, content: String, patternsBefore: String, patternsAfter: String): String = transformer.remap(mapOf( + fileName to content, "pattern.java" to "class Patterns {\n$patternsBefore\n}", ), mapOf( "pattern.java" to "class Patterns {\n$patternsAfter\n}", - ))["test.java"]!!.first + ))[fileName]!!.first fun remapWithErrors(content: String) = transformer.remap(mapOf("test.java" to content))["test.java"]!! fun remapKt(content: String): String = transformer.remap(mapOf("test.kt" to content))["test.kt"]!!.first -- cgit