Fix unnecessary parenthesis around 'this' in refactorings
Operator priority calculation for 'this' expressions was incorrect in JetPsiUtil.getPriority(): it would return a very low value for a JetThisExpression, causing the IDE to report that parenthesis are necessary in an expression like '(this)[1]'. Fix this by making JetThisExpression not implement JetStatementExpression by removing the implements clause from JetLabelQualifiedInstanceExpression and adding it to all other subclasses of JetLabelQualifiedInstanceExpression. Fixes KT-4513.
This commit is contained in:
committed by
Nikolay Krasko
parent
85c46019d3
commit
9ce40cd17b
+1
-2
@@ -20,8 +20,7 @@ import com.intellij.lang.ASTNode;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.JetNodeTypes;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
|
|
||||||
public abstract class JetLabelQualifiedInstanceExpression extends JetLabelQualifiedExpression
|
public abstract class JetLabelQualifiedInstanceExpression extends JetLabelQualifiedExpression {
|
||||||
implements JetStatementExpression {
|
|
||||||
|
|
||||||
public JetLabelQualifiedInstanceExpression(@NotNull ASTNode node) {
|
public JetLabelQualifiedInstanceExpression(@NotNull ASTNode node) {
|
||||||
super(node);
|
super(node);
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.JetNodeTypes;
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
|
|
||||||
public class JetSuperExpression extends JetLabelQualifiedInstanceExpression {
|
public class JetSuperExpression extends JetLabelQualifiedInstanceExpression implements JetStatementExpression {
|
||||||
|
|
||||||
public JetSuperExpression(@NotNull ASTNode node) {
|
public JetSuperExpression(@NotNull ASTNode node) {
|
||||||
super(node);
|
super(node);
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
class C() {
|
||||||
|
fun get(i: Int) = i + 1
|
||||||
|
|
||||||
|
// KT-4513: Unnecessary parenthesis around 'this'
|
||||||
|
val foo = (th<caret>is)[41]
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
class C() {
|
||||||
|
fun get(i: Int) = i + 1
|
||||||
|
|
||||||
|
// KT-4513: Unnecessary parenthesis around 'this'
|
||||||
|
val foo = this[41]
|
||||||
|
}
|
||||||
@@ -1176,6 +1176,11 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
|
|||||||
doTestRemoveUnnecessaryParentheses("idea/testData/intentions/removeUnnecessaryParentheses/unnecessaryParentheses7.kt");
|
doTestRemoveUnnecessaryParentheses("idea/testData/intentions/removeUnnecessaryParentheses/unnecessaryParentheses7.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unnecessaryParentheses8.kt")
|
||||||
|
public void testUnnecessaryParentheses8() throws Exception {
|
||||||
|
doTestRemoveUnnecessaryParentheses("idea/testData/intentions/removeUnnecessaryParentheses/unnecessaryParentheses8.kt");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
|
|||||||
Reference in New Issue
Block a user