From 496a4d18d4d1ef9648531ba1f2668ff82650e973 Mon Sep 17 00:00:00 2001 From: Aman Sharma Date: Tue, 30 Nov 2021 14:08:44 +0100 Subject: [PATCH] Reproduce SpoonLabs/sorald#601 --- .../spoon/test/prettyprinter/TestSniperPrinter.java | 13 +++++++++++++ .../PrintAbstractOnceWithProperSpacing.java | 8 ++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/test/resources/sniperPrinter/PrintAbstractOnceWithProperSpacing.java diff --git a/src/test/java/spoon/test/prettyprinter/TestSniperPrinter.java b/src/test/java/spoon/test/prettyprinter/TestSniperPrinter.java index 1e289ed1f55..67a6e17befc 100644 --- a/src/test/java/spoon/test/prettyprinter/TestSniperPrinter.java +++ b/src/test/java/spoon/test/prettyprinter/TestSniperPrinter.java @@ -841,6 +841,19 @@ void testSniperAddsSpaceAfterFinal() { testSniper("sniperPrinter.SpaceAfterFinal", modifyField, assertContainsSpaceAfterFinal); } + @Test + void testAbstractShouldBePrintedOnceAndWithProperSpacing() { + Consumer> noOpModifyStaticClass = type -> { + CtType staticClass = type.filterChildren(CtType.class::isInstance).first(); + staticClass.descendantIterator().forEachRemaining(TestSniperPrinter::markElementForSniperPrinting); + }; + + BiConsumer, String> assertDoesNotContainDiff = (type, result) -> + assertThat(result, not(containsString("abstractstatic abstract class AbstractFoo"))); + + testSniper("sniperPrinter.PrintAbstractOnceWithProperSpacing", noOpModifyStaticClass, assertDoesNotContainDiff); + } + /** * 1) Runs spoon using sniper mode, * 2) runs `typeChanger` to modify the code, diff --git a/src/test/resources/sniperPrinter/PrintAbstractOnceWithProperSpacing.java b/src/test/resources/sniperPrinter/PrintAbstractOnceWithProperSpacing.java new file mode 100644 index 00000000000..287d446b62c --- /dev/null +++ b/src/test/resources/sniperPrinter/PrintAbstractOnceWithProperSpacing.java @@ -0,0 +1,8 @@ +package sniperPrinter; + +public class PrintAbstractOnceWithProperSpacing { + static abstract class AbstractFoo + { + + } +}