From d50f621e157120b45d7149cb302eeca1fee16e04 Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Sat, 1 Feb 2014 22:00:44 +0400 Subject: [PATCH] IDEA-118325 honor "maximum blank lines" setting --- .../processors/GroovySpacingProcessor.java | 22 ++++++++----------- .../lang/formatter/FormatterTest.groovy | 2 ++ .../testdata/groovy/formatter/extraLines.test | 14 ++++++++++++ 3 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 plugins/groovy/testdata/groovy/formatter/extraLines.test diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java index 84a6807b1594..e64154c3a14b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/formatter/processors/GroovySpacingProcessor.java @@ -370,27 +370,27 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { @Override public void visitFile(GroovyFileBase file) { if (isAfterElementOrSemi(PACKAGE_DEFINITION)) { - myResult = Spacing.createSpacing(0, 0, mySettings.BLANK_LINES_AFTER_PACKAGE + 1, mySettings.KEEP_LINE_BREAKS, Integer.MAX_VALUE / 2); + myResult = Spacing.createSpacing(0, 0, mySettings.BLANK_LINES_AFTER_PACKAGE + 1, mySettings.KEEP_LINE_BREAKS, keepBlankLines()); } else if (myType2 == PACKAGE_DEFINITION) { - myResult = Spacing.createSpacing(0, 0, mySettings.BLANK_LINES_BEFORE_PACKAGE + 1, mySettings.KEEP_LINE_BREAKS, Integer.MAX_VALUE / 2); + myResult = Spacing.createSpacing(0, 0, mySettings.BLANK_LINES_BEFORE_PACKAGE + 1, mySettings.KEEP_LINE_BREAKS, keepBlankLines()); } else if (isLeftOrRight(TYPE_DEFINITION_TYPES)) { if (myType1 == GROOVY_DOC_COMMENT) { createLF(true); } else { - myResult = Spacing.createSpacing(0, 0, mySettings.BLANK_LINES_AROUND_CLASS + 1, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_DECLARATIONS); + myResult = Spacing.createSpacing(0, 0, mySettings.BLANK_LINES_AROUND_CLASS + 1, mySettings.KEEP_LINE_BREAKS, keepBlankLines()); } } else if (isAfterElementOrSemi(IMPORT_STATEMENT) && myType2 != IMPORT_STATEMENT) { //after imports - myResult = Spacing.createSpacing(0, 0, mySettings.BLANK_LINES_AFTER_IMPORTS + 1, mySettings.KEEP_LINE_BREAKS, Integer.MAX_VALUE / 2); + myResult = Spacing.createSpacing(0, 0, mySettings.BLANK_LINES_AFTER_IMPORTS + 1, mySettings.KEEP_LINE_BREAKS, keepBlankLines()); } else if (myType1 != IMPORT_STATEMENT && !isSemiAfter(IMPORT_STATEMENT) && myType2 == IMPORT_STATEMENT) { //before imports - myResult = Spacing.createSpacing(0, 0, mySettings.BLANK_LINES_BEFORE_IMPORTS, mySettings.KEEP_LINE_BREAKS, Integer.MAX_VALUE / 2); + myResult = Spacing.createSpacing(0, 0, mySettings.BLANK_LINES_BEFORE_IMPORTS, mySettings.KEEP_LINE_BREAKS, keepBlankLines()); } else if (isAfterElementOrSemi(IMPORT_STATEMENT) && myType2 == IMPORT_STATEMENT) { - myResult = Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, Integer.MAX_VALUE / 2); + myResult = Spacing.createSpacing(0, 0, 1, mySettings.KEEP_LINE_BREAKS, keepBlankLines()); } else { processClassMembers(null); @@ -582,7 +582,7 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { @Override public void visitTypeArgumentList(GrTypeArgumentList typeArgumentList) { if (myType1 == mLT || myType2 == mGT) { - createSpaceProperty(false, true, 1); + createSpaceInCode(false); } } @@ -858,7 +858,7 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { } private void createLazySpace() { - myResult = Spacing.createSpacing(0, Integer.MAX_VALUE, 0, mySettings.KEEP_LINE_BREAKS, mySettings.KEEP_BLANK_LINES_IN_CODE); + myResult = Spacing.createSpacing(0, Integer.MAX_VALUE, 0, mySettings.KEEP_LINE_BREAKS, keepBlankLines()); } public void visitDocTag(GrDocTag docTag) { @@ -1021,11 +1021,7 @@ public class GroovySpacingProcessor extends GroovyElementVisitor { } private void createSpaceInCode(final boolean space) { - createSpaceProperty(space, keepBlankLines()); - } - - private void createSpaceProperty(boolean space, int keepBlankLines) { - createSpaceProperty(space, mySettings.KEEP_LINE_BREAKS, keepBlankLines); + createSpaceProperty(space, mySettings.KEEP_LINE_BREAKS, keepBlankLines()); } private void createSpaceProperty(boolean space, boolean keepLineBreaks, final int keepBlankLines) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy index 72bb95deddbf..7b76abec59fe 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/formatter/FormatterTest.groovy @@ -770,6 +770,8 @@ def foo() { void testSpreadArg() { doTest() } + void testExtraLines() { doTest() } + void testLabelWithDescription() { GroovyCodeStyleSettings customSettings = myTempSettings.getCustomSettings(GroovyCodeStyleSettings.class) CommonCodeStyleSettings commonSettings = myTempSettings.getCommonSettings(GroovyFileType.GROOVY_LANGUAGE) diff --git a/plugins/groovy/testdata/groovy/formatter/extraLines.test b/plugins/groovy/testdata/groovy/formatter/extraLines.test new file mode 100644 index 000000000000..1fa2e574326d --- /dev/null +++ b/plugins/groovy/testdata/groovy/formatter/extraLines.test @@ -0,0 +1,14 @@ +package abc + + + + + + + +print 1 +----- +package abc + + +print 1 \ No newline at end of file