diff --git a/python/resources/postfixTemplates/PyParenthesizedExpressionPostfixTemplate/after.py.template b/python/resources/postfixTemplates/PyParenthesizedExpressionPostfixTemplate/after.py.template new file mode 100644 index 000000000000..1c94823fef48 --- /dev/null +++ b/python/resources/postfixTemplates/PyParenthesizedExpressionPostfixTemplate/after.py.template @@ -0,0 +1,3 @@ +def f(): + a = (1, 2) + return a \ No newline at end of file diff --git a/python/resources/postfixTemplates/PyParenthesizedExpressionPostfixTemplate/before.py.template b/python/resources/postfixTemplates/PyParenthesizedExpressionPostfixTemplate/before.py.template new file mode 100644 index 000000000000..960e494370ac --- /dev/null +++ b/python/resources/postfixTemplates/PyParenthesizedExpressionPostfixTemplate/before.py.template @@ -0,0 +1,3 @@ +def f(): + a = 1, 2 + return a \ No newline at end of file diff --git a/python/resources/postfixTemplates/PyParenthesizedExpressionPostfixTemplate/description.html b/python/resources/postfixTemplates/PyParenthesizedExpressionPostfixTemplate/description.html new file mode 100644 index 000000000000..635faf501b68 --- /dev/null +++ b/python/resources/postfixTemplates/PyParenthesizedExpressionPostfixTemplate/description.html @@ -0,0 +1,5 @@ + + +Parenthesizes the expression. + + \ No newline at end of file diff --git a/python/src/com/jetbrains/python/codeInsight/postfix/PyParenthesizedExpressionPostfixTemplate.java b/python/src/com/jetbrains/python/codeInsight/postfix/PyParenthesizedExpressionPostfixTemplate.java new file mode 100644 index 000000000000..1a7a1d722a99 --- /dev/null +++ b/python/src/com/jetbrains/python/codeInsight/postfix/PyParenthesizedExpressionPostfixTemplate.java @@ -0,0 +1,32 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jetbrains.python.codeInsight.postfix; + +import com.intellij.codeInsight.template.postfix.templates.ParenthesizedPostfixTemplate; +import com.intellij.codeInsight.template.postfix.templates.PostfixTemplateExpressionSelector; +import com.intellij.codeInsight.template.postfix.templates.PostfixTemplatePsiInfo; +import org.jetbrains.annotations.NotNull; + +public class PyParenthesizedExpressionPostfixTemplate extends ParenthesizedPostfixTemplate { + public PyParenthesizedExpressionPostfixTemplate() { + this(PyPostfixUtils.PY_PSI_INFO, PyPostfixUtils.selectorAllExpressionsWithCurrentOffset()); + } + + public PyParenthesizedExpressionPostfixTemplate(PostfixTemplatePsiInfo psiInfo, + @NotNull PostfixTemplateExpressionSelector selector) { + super(psiInfo, selector); + } +} diff --git a/python/testData/postfix/par/nestedParentheses.py b/python/testData/postfix/par/nestedParentheses.py new file mode 100644 index 000000000000..4f54c1ba7bbb --- /dev/null +++ b/python/testData/postfix/par/nestedParentheses.py @@ -0,0 +1 @@ +1 * (1 + 2).par \ No newline at end of file diff --git a/python/testData/postfix/par/nestedParentheses_after.py b/python/testData/postfix/par/nestedParentheses_after.py new file mode 100644 index 000000000000..1ab1bd524a34 --- /dev/null +++ b/python/testData/postfix/par/nestedParentheses_after.py @@ -0,0 +1 @@ +(1 * (1 + 2)) \ No newline at end of file diff --git a/python/testData/postfix/par/number.py b/python/testData/postfix/par/number.py new file mode 100644 index 000000000000..ac418b42528e --- /dev/null +++ b/python/testData/postfix/par/number.py @@ -0,0 +1 @@ +1.par \ No newline at end of file diff --git a/python/testData/postfix/par/number_after.py b/python/testData/postfix/par/number_after.py new file mode 100644 index 000000000000..f7772003305f --- /dev/null +++ b/python/testData/postfix/par/number_after.py @@ -0,0 +1 @@ +(1) \ No newline at end of file diff --git a/python/testData/postfix/par/while.py b/python/testData/postfix/par/while.py new file mode 100644 index 000000000000..b85ac0b81442 --- /dev/null +++ b/python/testData/postfix/par/while.py @@ -0,0 +1,2 @@ +while 1 + 1.par: + pass \ No newline at end of file diff --git a/python/testData/postfix/par/while_after.py b/python/testData/postfix/par/while_after.py new file mode 100644 index 000000000000..34346443a038 --- /dev/null +++ b/python/testData/postfix/par/while_after.py @@ -0,0 +1,2 @@ +while (1 + 1): + pass \ No newline at end of file diff --git a/python/testSrc/com/jetbrains/python/postfix/PyParenthesizedExpressionPostfixTemplateTest.java b/python/testSrc/com/jetbrains/python/postfix/PyParenthesizedExpressionPostfixTemplateTest.java new file mode 100644 index 000000000000..1efdf9529f4c --- /dev/null +++ b/python/testSrc/com/jetbrains/python/postfix/PyParenthesizedExpressionPostfixTemplateTest.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.jetbrains.python.postfix; + +public class PyParenthesizedExpressionPostfixTemplateTest extends PyPostfixTemplateTestCase { + + public void testNumber() { + doTest(); + } + + public void testWhile() { + doTest(); + } + + public void testNestedParentheses() { + doTest(); + } + + @Override + protected String getTestDataPath() { + return super.getTestDataPath() + "par/"; + } +}