From 30110c23719ba929a9fe25aa2f817754bc77d541 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Fri, 1 Mar 2013 12:00:56 +0100 Subject: [PATCH] "space within method declaration parentheses" code style option (PY-8818) --- .../formatter/PyLanguageCodeStyleSettingsProvider.java | 1 + .../python/formatter/PythonFormattingModelBuilder.java | 1 + .../testData/formatter/spaceWithinDeclarationParentheses.py | 2 ++ .../formatter/spaceWithinDeclarationParentheses_after.py | 2 ++ python/testSrc/com/jetbrains/python/PyFormatterTest.java | 5 +++++ 5 files changed, 11 insertions(+) create mode 100644 python/testData/formatter/spaceWithinDeclarationParentheses.py create mode 100644 python/testData/formatter/spaceWithinDeclarationParentheses_after.py diff --git a/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java b/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java index c7ae487a20eb..63a8683d9134 100644 --- a/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java +++ b/python/src/com/jetbrains/python/formatter/PyLanguageCodeStyleSettingsProvider.java @@ -46,6 +46,7 @@ public class PyLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettin "SPACE_AROUND_MULTIPLICATIVE_OPERATORS", "SPACE_AROUND_SHIFT_OPERATORS", "SPACE_WITHIN_METHOD_CALL_PARENTHESES", + "SPACE_WITHIN_METHOD_PARENTHESES", "SPACE_WITHIN_BRACKETS", "SPACE_AFTER_COMMA", "SPACE_BEFORE_COMMA", diff --git a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java index 63f8003108a3..59994eece62f 100644 --- a/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java +++ b/python/src/com/jetbrains/python/formatter/PythonFormattingModelBuilder.java @@ -96,6 +96,7 @@ public class PythonFormattingModelBuilder implements FormattingModelBuilderEx, C .around(DOT).spaces(0) .before(SEMICOLON).spaceIf(commonSettings.SPACE_BEFORE_SEMICOLON) .withinPairInside(LPAR, RPAR, ARGUMENT_LIST).spaceIf(commonSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES) + .withinPairInside(LPAR, RPAR, PARAMETER_LIST).spaceIf(commonSettings.SPACE_WITHIN_METHOD_PARENTHESES) .before(LBRACKET).spaceIf(pySettings.SPACE_BEFORE_LBRACKET) .withinPair(LBRACE, RBRACE).spaceIf(pySettings.SPACE_WITHIN_BRACES) diff --git a/python/testData/formatter/spaceWithinDeclarationParentheses.py b/python/testData/formatter/spaceWithinDeclarationParentheses.py new file mode 100644 index 000000000000..0f74b8576b43 --- /dev/null +++ b/python/testData/formatter/spaceWithinDeclarationParentheses.py @@ -0,0 +1,2 @@ +def foo(x, y): + pass diff --git a/python/testData/formatter/spaceWithinDeclarationParentheses_after.py b/python/testData/formatter/spaceWithinDeclarationParentheses_after.py new file mode 100644 index 000000000000..f4d1a4b80d26 --- /dev/null +++ b/python/testData/formatter/spaceWithinDeclarationParentheses_after.py @@ -0,0 +1,2 @@ +def foo( x, y ): + pass diff --git a/python/testSrc/com/jetbrains/python/PyFormatterTest.java b/python/testSrc/com/jetbrains/python/PyFormatterTest.java index a63c5b269cdb..960118f7ad4c 100644 --- a/python/testSrc/com/jetbrains/python/PyFormatterTest.java +++ b/python/testSrc/com/jetbrains/python/PyFormatterTest.java @@ -317,6 +317,11 @@ public class PyFormatterTest extends PyTestCase { doTest(); } + public void testSpaceWithinDeclarationParentheses() { // PY-8818 + settings().SPACE_WITHIN_METHOD_PARENTHESES = true; + doTest(); + } + private void doTest() { myFixture.configureByFile("formatter/" + getTestName(true) + ".py"); ApplicationManager.getApplication().runWriteAction(new Runnable() {