mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
switch expression precedence
This commit is contained in:
@@ -128,7 +128,7 @@ public class PsiPrecedenceUtil {
|
||||
if (expression instanceof PsiPrefixExpression) {
|
||||
return PREFIX_PRECEDENCE;
|
||||
}
|
||||
if (expression instanceof PsiPostfixExpression) {
|
||||
if (expression instanceof PsiPostfixExpression || expression instanceof PsiSwitchExpression) {
|
||||
return POSTFIX_PRECEDENCE;
|
||||
}
|
||||
if (expression instanceof PsiPolyadicExpression) {
|
||||
|
||||
+2
-16
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.psi.impl.source.tree.java;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
@@ -143,7 +129,7 @@ public class ReplaceExpressionUtil {
|
||||
else if (i == JavaElementType.PREFIX_EXPRESSION || i == JavaElementType.TYPE_CAST_EXPRESSION) {
|
||||
return 12;
|
||||
}
|
||||
else if (i == JavaElementType.POSTFIX_EXPRESSION) {
|
||||
else if (i == JavaElementType.POSTFIX_EXPRESSION || i == JavaElementType.SWITCH_EXPRESSION) {
|
||||
return 13;
|
||||
}
|
||||
else if (i == JavaElementType.LITERAL_EXPRESSION ||
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class SwitchExpression {
|
||||
|
||||
void it() {
|
||||
long z = (long) switch(1) {
|
||||
default -> 10;
|
||||
} + 1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class SwitchExpression {
|
||||
|
||||
void it() {
|
||||
long z = (long) (<caret>switch(1) {
|
||||
default -> 10;
|
||||
}) + 1;
|
||||
}
|
||||
}
|
||||
+10
@@ -6,6 +6,16 @@ import java.util.ArrayList;
|
||||
public class UnnecessaryParenthesesInspection
|
||||
{
|
||||
|
||||
void switchExpressions() {
|
||||
String s = (switch(1) {
|
||||
case 1 -> "one";
|
||||
default -> "other";
|
||||
}).substring(1);
|
||||
int z = -<warning descr="Parentheses around '(switch(1) { default -> 10; })' are unnecessary">(switch(1) {
|
||||
default -> 10;
|
||||
})</warning> + 10;
|
||||
}
|
||||
|
||||
public int foo()
|
||||
{
|
||||
final String s = "foo" + (3 + 4); // do not warn here
|
||||
|
||||
+3
-15
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.siyeh.ig.fixes.parenthesis;
|
||||
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
@@ -47,6 +33,8 @@ public class UnnecessaryParenthesesQuickFixTest extends IGQuickFixesTestCase {
|
||||
public void testLambdaCast() { doTest(); }
|
||||
public void testLambdaBody() { doTest(); }
|
||||
public void testDivision() { doTest(); }
|
||||
public void testSwitchExpression() { doTest(); }
|
||||
|
||||
@Override
|
||||
protected BaseInspection getInspection() {
|
||||
return new UnnecessaryParenthesesInspection();
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ public class UnnecessaryParenthesesInspectionTest extends LightCodeInsightFixtur
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return JAVA_8;
|
||||
return JAVA_12;
|
||||
}
|
||||
|
||||
public void testUnnecessaryParenthesesInspection() {
|
||||
|
||||
Reference in New Issue
Block a user