From 744b9288f6aa9cdabe1d3ec8da96f63709cf3f67 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Sat, 5 Jun 2021 10:13:36 +0200 Subject: Ignore pattern if either method body is empty So they can be easily (i.e. without requiring a dedicated file) disabled when no longer applicable. --- src/main/kotlin/com/replaymod/gradle/remap/PsiPatterns.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/main/kotlin/com/replaymod/gradle') diff --git a/src/main/kotlin/com/replaymod/gradle/remap/PsiPatterns.kt b/src/main/kotlin/com/replaymod/gradle/remap/PsiPatterns.kt index 1000666..3c095c4 100644 --- a/src/main/kotlin/com/replaymod/gradle/remap/PsiPatterns.kt +++ b/src/main/kotlin/com/replaymod/gradle/remap/PsiPatterns.kt @@ -36,10 +36,15 @@ internal class PsiPatterns(private val annotationFQN: String) { candidates.firstOrNull() } ?: throw RuntimeException("Failed to find updated method \"${method.name}\" (line ${methodLine + 1})") } + val replacementBody = replacementMethod.body!! if (method.text == replacementMethod.text) return - val replacementExpression = when (val statement = replacementMethod.body!!.statements.last()) { + // If either body is empty, then consider the pattern to be disabled + if (body.statements.isEmpty()) return + if (replacementBody.statements.isEmpty()) return + + val replacementExpression = when (val statement = replacementBody.statements.last()) { is PsiReturnStatement -> statement.returnValue!! else -> statement } -- cgit