From b14837d42a22ba6d602eafe3b9c1b7de23fa4fec 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..6fb2b35b056 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 test_abstractShouldBePrintedOnceAndWithProperSpacing() { + Consumer> modifyStaticClass = 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", modifyStaticClass, 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 + { + + } +}