diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java
index 599710b7ff5..d7702d07d07 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java
@@ -124,7 +124,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
);
@SuppressWarnings({"UnusedDeclaration"})
- private enum Precedence {
+ public enum Precedence {
POSTFIX(PLUSPLUS, MINUSMINUS, EXCLEXCL,
// HASH,
DOT, SAFE_ACCESS), // typeArguments? valueArguments : typeArguments : arrayAccess
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetIsExpression.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetIsExpression.java
index cfa5f853394..272082a9ac8 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetIsExpression.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetIsExpression.java
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetNodeTypes;
import org.jetbrains.jet.lexer.JetTokens;
-public class JetIsExpression extends JetExpressionImpl {
+public class JetIsExpression extends JetExpressionImpl implements JetOperationExpression {
public JetIsExpression(@NotNull ASTNode node) {
super(node);
}
@@ -47,6 +47,7 @@ public class JetIsExpression extends JetExpressionImpl {
return (JetTypeReference) findChildByType(JetNodeTypes.TYPE_REFERENCE);
}
+ @Override
@NotNull
public JetSimpleNameExpression getOperationReference() {
return (JetSimpleNameExpression) findChildByType(JetNodeTypes.OPERATION_REFERENCE);
diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java
index 99b98cfd949..92af4a42247 100644
--- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java
+++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java
@@ -29,6 +29,7 @@ import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetNodeTypes;
+import org.jetbrains.jet.lang.parsing.JetExpressionParsing;
import org.jetbrains.jet.lang.resolve.ImportPath;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.Name;
@@ -562,4 +563,62 @@ public class JetPsiUtil {
current = (JetClassOrObject) parent.getParent();
}
}
+
+ private static IElementType getOperation(@NotNull JetExpression expression) {
+ if (expression instanceof JetQualifiedExpression) {
+ return ((JetQualifiedExpression) expression).getOperationSign();
+ }
+ else if (expression instanceof JetOperationExpression) {
+ return ((JetOperationExpression) expression).getOperationReference().getReferencedNameElementType();
+ }
+ return null;
+ }
+
+ private static int getPrecedenceOfOperation(@NotNull JetExpression expression, @NotNull IElementType operation) {
+ if (expression instanceof JetPostfixExpression) return 0;
+ if (expression instanceof JetQualifiedExpression) return 0;
+ if (expression instanceof JetPrefixExpression) return 1;
+
+ for (JetExpressionParsing.Precedence precedence : JetExpressionParsing.Precedence.values()) {
+ if (precedence != JetExpressionParsing.Precedence.PREFIX && precedence != JetExpressionParsing.Precedence.POSTFIX &&
+ precedence.getOperations().contains(operation)) {
+ return precedence.ordinal();
+ }
+ }
+ throw new IllegalStateException("Unknown operation");
+ }
+
+ public static boolean areParenthesesUseless(@NotNull JetParenthesizedExpression expression) {
+ JetExpression innerExpression = expression.getExpression();
+ JetExpression parentExpression = PsiTreeUtil.getParentOfType(expression, JetExpression.class, true);
+ if (innerExpression == null || parentExpression == null) return true;
+
+ IElementType innerOperation = getOperation(innerExpression);
+ IElementType parentOperation = getOperation(parentExpression);
+
+ // 'return (@label{...})' case
+ if (parentExpression instanceof JetReturnExpression && innerOperation == JetTokens.LABEL_IDENTIFIER) {
+ return false;
+ }
+
+ // '(x: Int) < y' case
+ if (innerExpression instanceof JetBinaryExpressionWithTypeRHS && parentOperation == JetTokens.LT) {
+ return false;
+ }
+
+ // associative operations
+ if (innerOperation == parentOperation && (innerOperation == JetTokens.OROR || innerOperation == JetTokens.ANDAND)) {
+ return true;
+ }
+
+ if (innerOperation == null) return true;
+ if (parentExpression instanceof JetArrayAccessExpression) {
+ return ((JetArrayAccessExpression) parentExpression).getArrayExpression() != expression;
+ }
+ if (parentOperation == null) return true;
+
+ int innerPrecedence = getPrecedenceOfOperation(innerExpression, innerOperation);
+ int parentPrecedence = getPrecedenceOfOperation(parentExpression, parentOperation);
+ return innerPrecedence < parentPrecedence;
+ }
}
diff --git a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java
index 357adb5caff..883d1c5c524 100644
--- a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java
+++ b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java
@@ -298,7 +298,8 @@ public class GenerateTests {
"CodeTransformationsTestGenerated",
AbstractCodeTransformationTest.class,
testModel("idea/testData/codeInsight/codeTransformations/ifStatementWithAssignmentsToExpression", "doTestIfStatementWithAssignmentsToExpression"),
- testModel("idea/testData/codeInsight/codeTransformations/assignmentWithIfExpressionToStatement", "doTestAssignmentWithIfExpressionToStatement")
+ testModel("idea/testData/codeInsight/codeTransformations/assignmentWithIfExpressionToStatement", "doTestAssignmentWithIfExpressionToStatement"),
+ testModel("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses", "doTestRemoveUnnecessaryParentheses")
);
generateTest(
diff --git a/idea/resources/intentionDescriptions/RemoveUnnecessaryParenthesesIntention/after.kt.template b/idea/resources/intentionDescriptions/RemoveUnnecessaryParenthesesIntention/after.kt.template
new file mode 100644
index 00000000000..148f2088e10
--- /dev/null
+++ b/idea/resources/intentionDescriptions/RemoveUnnecessaryParenthesesIntention/after.kt.template
@@ -0,0 +1,3 @@
+fun foo(x: Int) {
+ x * x + x
+}
\ No newline at end of file
diff --git a/idea/resources/intentionDescriptions/RemoveUnnecessaryParenthesesIntention/before.kt.template b/idea/resources/intentionDescriptions/RemoveUnnecessaryParenthesesIntention/before.kt.template
new file mode 100644
index 00000000000..edb26b6863d
--- /dev/null
+++ b/idea/resources/intentionDescriptions/RemoveUnnecessaryParenthesesIntention/before.kt.template
@@ -0,0 +1,3 @@
+fun foo(x: Int) {
+ (x * x) + x
+}
\ No newline at end of file
diff --git a/idea/resources/intentionDescriptions/RemoveUnnecessaryParenthesesIntention/description.html b/idea/resources/intentionDescriptions/RemoveUnnecessaryParenthesesIntention/description.html
new file mode 100644
index 00000000000..fbc0a4849e5
--- /dev/null
+++ b/idea/resources/intentionDescriptions/RemoveUnnecessaryParenthesesIntention/description.html
@@ -0,0 +1,5 @@
+
+
+This intention removes unnecessary parentheses.
+
+
\ No newline at end of file
diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml
index 34138d17fa5..02e9934213a 100644
--- a/idea/src/META-INF/plugin.xml
+++ b/idea/src/META-INF/plugin.xml
@@ -294,6 +294,11 @@
Kotlin
+
+ org.jetbrains.jet.plugin.codeInsight.codeTransformations.RemoveUnnecessaryParenthesesIntention
+ Kotlin
+
+
diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties
index c46cae665bf..ec12e968fb3 100644
--- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties
+++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties
@@ -146,3 +146,5 @@ transform.if.statement.with.assignments.to.expression=Transform 'if' statement w
transform.assignment.with.if.expression.to.statement=Transform assignment with 'if' expression to statement
transform.if.statement.with.assignments.to.expression.family=Transform 'if' Statement with Assignments to Expression
transform.assignment.with.if.expression.to.statement.family=Transform Assignment with 'if' Expression to Statement
+remove.unnecessary.parentheses=Remove unnecessary parentheses
+remove.unnecessary.parentheses.family=Remove Unnecessary Parentheses
\ No newline at end of file
diff --git a/idea/src/org/jetbrains/jet/plugin/JetPluginUtil.java b/idea/src/org/jetbrains/jet/plugin/JetPluginUtil.java
index 15440d2e7a3..f04c8801db8 100644
--- a/idea/src/org/jetbrains/jet/plugin/JetPluginUtil.java
+++ b/idea/src/org/jetbrains/jet/plugin/JetPluginUtil.java
@@ -27,7 +27,9 @@ import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
-import org.jetbrains.jet.lang.types.*;
+import org.jetbrains.jet.lang.types.DeferredType;
+import org.jetbrains.jet.lang.types.ErrorUtils;
+import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import java.util.LinkedList;
diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/RemoveUnnecessaryParenthesesIntention.java b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/RemoveUnnecessaryParenthesesIntention.java
new file mode 100644
index 00000000000..6ccb7e3ac7d
--- /dev/null
+++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/codeTransformations/RemoveUnnecessaryParenthesesIntention.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2010-2013 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 org.jetbrains.jet.plugin.codeInsight.codeTransformations;
+
+import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
+import com.intellij.openapi.editor.Editor;
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiFile;
+import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.util.IncorrectOperationException;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.lang.psi.JetExpression;
+import org.jetbrains.jet.lang.psi.JetParenthesizedExpression;
+import org.jetbrains.jet.lang.psi.JetPsiUtil;
+import org.jetbrains.jet.plugin.JetBundle;
+
+public class RemoveUnnecessaryParenthesesIntention extends BaseIntentionAction {
+ private JetParenthesizedExpression expression;
+
+ public RemoveUnnecessaryParenthesesIntention() {
+ setText(JetBundle.message("remove.unnecessary.parentheses"));
+ }
+
+ @NotNull
+ @Override
+ public String getFamilyName() {
+ return JetBundle.message("remove.unnecessary.parentheses.family");
+ }
+
+ @Override
+ public boolean isAvailable(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
+ PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
+ expression = PsiTreeUtil.getParentOfType(element, JetParenthesizedExpression.class);
+ return expression != null && JetPsiUtil.areParenthesesUseless(expression);
+ }
+
+ @Override
+ public void invoke(
+ @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file
+ ) throws IncorrectOperationException {
+ JetExpression innerExpression = expression.getExpression();
+ assert innerExpression != null : "parenthesizedExpression.getExpression() == null despite @IfNotParsed annotation";
+ expression.replace(innerExpression);
+ }
+}
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses1.kt b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses1.kt
new file mode 100644
index 00000000000..6df69076be5
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses1.kt
@@ -0,0 +1,4 @@
+// IS_APPLICABLE: false
+fun foo(x: Int, y: Int) {
+ x + (x + y)
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses2.kt b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses2.kt
new file mode 100644
index 00000000000..996f07ea7c0
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses2.kt
@@ -0,0 +1,4 @@
+// IS_APPLICABLE: false
+fun foo() : Any {
+ return (@a{})
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses3.kt b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses3.kt
new file mode 100644
index 00000000000..a6fcf34c020
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses3.kt
@@ -0,0 +1,4 @@
+// IS_APPLICABLE: false
+fun foo(x: Int) : Any {
+ return (x as Int) < 42
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses4.kt b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses4.kt
new file mode 100644
index 00000000000..f20aac102c5
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses4.kt
@@ -0,0 +1,4 @@
+// IS_APPLICABLE: false
+fun foo(x: Int) {
+ +(+x)
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses5.kt b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses5.kt
new file mode 100644
index 00000000000..777af8bdd7d
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses5.kt
@@ -0,0 +1,8 @@
+// IS_APPLICABLE: false
+trait Foo {
+ fun get(x : Any) : Foo
+ fun plus(x : Any) : Foo
+}
+fun foo(x: Foo) {
+ (x + x)[x]
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses1.kt b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses1.kt
new file mode 100644
index 00000000000..2a3e3a7e6eb
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses1.kt
@@ -0,0 +1,3 @@
+fun foo(x: Int) {
+ (x * x / x) + x
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses1.kt.after b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses1.kt.after
new file mode 100644
index 00000000000..e38353389c3
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses1.kt.after
@@ -0,0 +1,3 @@
+fun foo(x: Int) {
+ x * x / x + x
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses2.kt b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses2.kt
new file mode 100644
index 00000000000..9b7bc72fe88
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses2.kt
@@ -0,0 +1,3 @@
+fun foo(x: Int) : Int {
+ return (x)
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses2.kt.after b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses2.kt.after
new file mode 100644
index 00000000000..e515f3040bc
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses2.kt.after
@@ -0,0 +1,3 @@
+fun foo(x: Int) : Int {
+ return x
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses3.kt b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses3.kt
new file mode 100644
index 00000000000..ad8965c1179
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses3.kt
@@ -0,0 +1,6 @@
+trait Foo {
+ fun get(x : Any) : Foo
+}
+fun foo(x: Foo) {
+ (x[x])[x]
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses3.kt.after b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses3.kt.after
new file mode 100644
index 00000000000..3830c0ed018
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses3.kt.after
@@ -0,0 +1,6 @@
+trait Foo {
+ fun get(x : Any) : Foo
+}
+fun foo(x: Foo) {
+ x[x][x]
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses4.kt b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses4.kt
new file mode 100644
index 00000000000..325def59ded
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses4.kt
@@ -0,0 +1,7 @@
+trait Foo {
+ fun inc() : Foo
+ fun not() : Foo
+}
+fun foo(x: Foo) {
+ !(x.inc())
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses4.kt.after b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses4.kt.after
new file mode 100644
index 00000000000..e7c0b19209b
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses4.kt.after
@@ -0,0 +1,7 @@
+trait Foo {
+ fun inc() : Foo
+ fun not() : Foo
+}
+fun foo(x: Foo) {
+ !x.inc()
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses5.kt b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses5.kt
new file mode 100644
index 00000000000..07ae656d922
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses5.kt
@@ -0,0 +1,3 @@
+fun foo(x: Boolean) : Boolean {
+ return x || (x || x)
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses5.kt.after b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses5.kt.after
new file mode 100644
index 00000000000..13602643906
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses5.kt.after
@@ -0,0 +1,3 @@
+fun foo(x: Boolean) : Boolean {
+ return x || x || x
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses6.kt b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses6.kt
new file mode 100644
index 00000000000..da27733d64a
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses6.kt
@@ -0,0 +1,3 @@
+fun foo(x: Boolean) : Boolean {
+ return x && (x && x)
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses6.kt.after b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses6.kt.after
new file mode 100644
index 00000000000..f3880b40199
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses6.kt.after
@@ -0,0 +1,3 @@
+fun foo(x: Boolean) : Boolean {
+ return x && x && x
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses7.kt b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses7.kt
new file mode 100644
index 00000000000..3643b9437da
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses7.kt
@@ -0,0 +1,3 @@
+fun foo(i: Int) {
+ array(42)[(i + i)]
+}
\ No newline at end of file
diff --git a/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses7.kt.after b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses7.kt.after
new file mode 100644
index 00000000000..9fb29aa8036
--- /dev/null
+++ b/idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses7.kt.after
@@ -0,0 +1,3 @@
+fun foo(i: Int) {
+ array(42)[i + i]
+}
\ No newline at end of file
diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/AbstractCodeTransformationTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/AbstractCodeTransformationTest.java
index cbe7fa96aaa..56e71ad86a9 100644
--- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/AbstractCodeTransformationTest.java
+++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/AbstractCodeTransformationTest.java
@@ -33,6 +33,10 @@ public abstract class AbstractCodeTransformationTest extends LightCodeInsightTes
doTest(path, new AssignmentWithIfExpressionToStatementIntention());
}
+ public void doTestRemoveUnnecessaryParentheses(@NotNull String path) throws Exception {
+ doTest(path, new RemoveUnnecessaryParenthesesIntention());
+ }
+
private void doTest(@NotNull String path, @NotNull IntentionAction intentionAction) throws Exception {
configureByFile(path);
diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/CodeTransformationsTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/CodeTransformationsTestGenerated.java
index 1617edda4e1..5241ce2fe83 100644
--- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/CodeTransformationsTestGenerated.java
+++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/codeTransformations/CodeTransformationsTestGenerated.java
@@ -30,7 +30,7 @@ import org.jetbrains.jet.plugin.codeInsight.codeTransformations.AbstractCodeTran
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
-@InnerTestClasses({CodeTransformationsTestGenerated.IfStatementWithAssignmentsToExpression.class, CodeTransformationsTestGenerated.AssignmentWithIfExpressionToStatement.class})
+@InnerTestClasses({CodeTransformationsTestGenerated.IfStatementWithAssignmentsToExpression.class, CodeTransformationsTestGenerated.AssignmentWithIfExpressionToStatement.class, CodeTransformationsTestGenerated.RemoveUnnecessaryParentheses.class})
public class CodeTransformationsTestGenerated extends AbstractCodeTransformationTest {
@TestMetadata("idea/testData/codeInsight/codeTransformations/ifStatementWithAssignmentsToExpression")
public static class IfStatementWithAssignmentsToExpression extends AbstractCodeTransformationTest {
@@ -93,10 +93,79 @@ public class CodeTransformationsTestGenerated extends AbstractCodeTransformation
}
+ @TestMetadata("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses")
+ public static class RemoveUnnecessaryParentheses extends AbstractCodeTransformationTest {
+ public void testAllFilesPresentInRemoveUnnecessaryParentheses() throws Exception {
+ JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses"), Pattern.compile("^(.+)\\.kt$"), true);
+ }
+
+ @TestMetadata("necessaryParentheses1.kt")
+ public void testNecessaryParentheses1() throws Exception {
+ doTestRemoveUnnecessaryParentheses("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses1.kt");
+ }
+
+ @TestMetadata("necessaryParentheses2.kt")
+ public void testNecessaryParentheses2() throws Exception {
+ doTestRemoveUnnecessaryParentheses("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses2.kt");
+ }
+
+ @TestMetadata("necessaryParentheses3.kt")
+ public void testNecessaryParentheses3() throws Exception {
+ doTestRemoveUnnecessaryParentheses("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses3.kt");
+ }
+
+ @TestMetadata("necessaryParentheses4.kt")
+ public void testNecessaryParentheses4() throws Exception {
+ doTestRemoveUnnecessaryParentheses("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses4.kt");
+ }
+
+ @TestMetadata("necessaryParentheses5.kt")
+ public void testNecessaryParentheses5() throws Exception {
+ doTestRemoveUnnecessaryParentheses("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/necessaryParentheses5.kt");
+ }
+
+ @TestMetadata("unnecessaryParentheses1.kt")
+ public void testUnnecessaryParentheses1() throws Exception {
+ doTestRemoveUnnecessaryParentheses("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses1.kt");
+ }
+
+ @TestMetadata("unnecessaryParentheses2.kt")
+ public void testUnnecessaryParentheses2() throws Exception {
+ doTestRemoveUnnecessaryParentheses("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses2.kt");
+ }
+
+ @TestMetadata("unnecessaryParentheses3.kt")
+ public void testUnnecessaryParentheses3() throws Exception {
+ doTestRemoveUnnecessaryParentheses("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses3.kt");
+ }
+
+ @TestMetadata("unnecessaryParentheses4.kt")
+ public void testUnnecessaryParentheses4() throws Exception {
+ doTestRemoveUnnecessaryParentheses("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses4.kt");
+ }
+
+ @TestMetadata("unnecessaryParentheses5.kt")
+ public void testUnnecessaryParentheses5() throws Exception {
+ doTestRemoveUnnecessaryParentheses("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses5.kt");
+ }
+
+ @TestMetadata("unnecessaryParentheses6.kt")
+ public void testUnnecessaryParentheses6() throws Exception {
+ doTestRemoveUnnecessaryParentheses("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses6.kt");
+ }
+
+ @TestMetadata("unnecessaryParentheses7.kt")
+ public void testUnnecessaryParentheses7() throws Exception {
+ doTestRemoveUnnecessaryParentheses("idea/testData/codeInsight/codeTransformations/removeUnnecessaryParentheses/unnecessaryParentheses7.kt");
+ }
+
+ }
+
public static Test suite() {
TestSuite suite = new TestSuite("CodeTransformationsTestGenerated");
suite.addTestSuite(IfStatementWithAssignmentsToExpression.class);
suite.addTestSuite(AssignmentWithIfExpressionToStatement.class);
+ suite.addTestSuite(RemoveUnnecessaryParentheses.class);
return suite;
}
}