diff --git a/src/test/java/spoon/test/prettyprinter/TestSniperPrinter.java b/src/test/java/spoon/test/prettyprinter/TestSniperPrinter.java index dc56523bd4f..afc452e97d4 100644 --- a/src/test/java/spoon/test/prettyprinter/TestSniperPrinter.java +++ b/src/test/java/spoon/test/prettyprinter/TestSniperPrinter.java @@ -7,6 +7,7 @@ */ package spoon.test.prettyprinter; +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import spoon.Launcher; @@ -40,6 +41,7 @@ import spoon.support.modelobs.ChangeCollector; import spoon.support.modelobs.SourceFragmentCreator; import spoon.support.sniper.SniperJavaPrettyPrinter; +import spoon.test.GitHubIssue; import spoon.test.prettyprinter.testclasses.OneLineMultipleVariableDeclaration; import spoon.test.prettyprinter.testclasses.Throw; import spoon.test.prettyprinter.testclasses.InvocationReplacement; @@ -772,6 +774,21 @@ void testSniperRespectsDeletionInForUpdate() { testSniper("ForLoop", deleteForUpdate, assertNotStaticFindFirstIsEmpty); } + + @Test + @Disabled("UnresolvedBug") + @GitHubIssue(issueNumber = 4021) + void testSniperRespectsSuperWithUnaryOperator() { + // Combining CtSuperAccess and CtUnaryOperator leads to SpoonException with Sniper + + // Noop + Consumer> deleteForUpdate = type -> {}; + + BiConsumer, String> assertContainsSuperWithUnaryOperator = (type, result) -> + assertThat(result, containsString("super.a(-x);")); + + testSniper("superCall.SuperCallSniperTestClass", deleteForUpdate, assertContainsSuperWithUnaryOperator); + } /** * 1) Runs spoon using sniper mode, diff --git a/src/test/resources/superCall/SuperCallSniperTestClass.java b/src/test/resources/superCall/SuperCallSniperTestClass.java new file mode 100644 index 00000000000..f4696dfdbe1 --- /dev/null +++ b/src/test/resources/superCall/SuperCallSniperTestClass.java @@ -0,0 +1,18 @@ +package superCall; + +/** + * Test class to reproduce issue #4021 + */ +public class SuperCallSniperTestClass { + int m = 0; + + public int a(int x) { + return x; + } +} + +class Child extends SuperCallSniperTestClass { + public int b(int x) { + return super.a(-x); + } +}