diff --git a/java/java-impl/src/com/intellij/codeInspection/ReadWriteStringCanBeUsedInspection.java b/java/java-impl/src/com/intellij/codeInspection/ReadWriteStringCanBeUsedInspection.java index 5c77a1be31ac..cba2420773e1 100644 --- a/java/java-impl/src/com/intellij/codeInspection/ReadWriteStringCanBeUsedInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/ReadWriteStringCanBeUsedInspection.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2019 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.codeInspection; import com.intellij.openapi.project.Project; @@ -138,7 +138,7 @@ public class ReadWriteStringCanBeUsedInspection extends AbstractBaseJavaLocalIns if (!isUtf8Charset(charsetExpression)) { argumentList.addAfter(ct.markUnchanged(charsetExpression), bytesArg); } - PsiLocalVariable variable = ExpressionUtils.resolveLocalVariable(PsiUtil.skipParenthesizedExprDown(bytesArg)); + PsiLocalVariable variable = ExpressionUtils.resolveLocalVariable(bytesArg); ct.replaceAndRestoreComments(bytesArg, stringExpression); if (variable != null) { ct = new CommentTracker(); diff --git a/java/java-impl/src/com/intellij/codeInspection/WrapWithMutableCollectionFix.java b/java/java-impl/src/com/intellij/codeInspection/WrapWithMutableCollectionFix.java index af1997b45455..2065846c1a8d 100644 --- a/java/java-impl/src/com/intellij/codeInspection/WrapWithMutableCollectionFix.java +++ b/java/java-impl/src/com/intellij/codeInspection/WrapWithMutableCollectionFix.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2019 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.codeInspection; import com.intellij.codeInsight.daemon.impl.analysis.HighlightControlFlowUtil; @@ -90,7 +90,7 @@ public class WrapWithMutableCollectionFix implements LocalQuickFix { anchor = ((PsiReferenceExpression)anchor.getParent()).getQualifierExpression(); } if (!(anchor instanceof PsiExpression)) return null; - return ExpressionUtils.resolveLocalVariable(PsiUtil.skipParenthesizedExprDown((PsiExpression)anchor)); + return ExpressionUtils.resolveLocalVariable((PsiExpression)anchor); } @Contract("null -> null") diff --git a/java/java-impl/src/com/intellij/codeInspection/streamMigration/StreamApiMigrationInspection.java b/java/java-impl/src/com/intellij/codeInspection/streamMigration/StreamApiMigrationInspection.java index 20321f1e900e..201c5797a888 100644 --- a/java/java-impl/src/com/intellij/codeInspection/streamMigration/StreamApiMigrationInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/streamMigration/StreamApiMigrationInspection.java @@ -982,14 +982,14 @@ public class StreamApiMigrationInspection extends AbstractBaseJavaLocalInspectio if (!JavaTokenType.NE.equals(binOp.getOperationTokenType())) return null; PsiExpression operand = ExpressionUtils.getValueComparedWithNull(binOp); if (operand == null) return null; - PsiAssignmentExpression assignment = ExpressionUtils.getAssignment(PsiUtil.skipParenthesizedExprDown(operand)); + PsiAssignmentExpression assignment = ExpressionUtils.getAssignment(operand); if (assignment == null) return null; PsiMethodCallExpression readerCall = tryCast(PsiUtil.skipParenthesizedExprDown(assignment.getRExpression()), PsiMethodCallExpression.class); if (!BUFFERED_READER_READ_LINE.test(readerCall)) return null; PsiExpression reader = readerCall.getMethodExpression().getQualifierExpression(); - PsiLocalVariable lineVar = ExpressionUtils.resolveLocalVariable(PsiUtil.skipParenthesizedExprDown(assignment.getLExpression())); + PsiLocalVariable lineVar = ExpressionUtils.resolveLocalVariable(assignment.getLExpression()); if (lineVar == null) return null; if (ReferencesSearch.search(lineVar).anyMatch(ref -> !PsiTreeUtil.isAncestor(loopStatement, ref.getElement(), true))) { return null; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/unrollLoop/beforeUnrollVar.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/unrollLoop/beforeUnrollVar.java index c5324f16b96f..d210eabadf49 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/unrollLoop/beforeUnrollVar.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/unrollLoop/beforeUnrollVar.java @@ -1,8 +1,8 @@ // "Unroll loop" "true" class Test { void test() { - boolean steps = {true, false}; - for(boolean step : steps) { + boolean[] steps = {true, false}; + for(boolean step : (steps)) { foo(step); unresolved(!step); } diff --git a/java/java-tests/testData/codeInsight/joinLines/AssignmentAndCall.java b/java/java-tests/testData/codeInsight/joinLines/AssignmentAndCall.java index c2a181cdcb77..296aad2e3b8c 100644 --- a/java/java-tests/testData/codeInsight/joinLines/AssignmentAndCall.java +++ b/java/java-tests/testData/codeInsight/joinLines/AssignmentAndCall.java @@ -2,7 +2,7 @@ class Foo { void test() { StringBuilder sb; sb = new StringBuilder(); - sb.append("foo"); + (sb).append("foo"); sb.append("bar"); sb.append("baz"); } diff --git a/java/java-tests/testData/inspection/castCanBeRemovedNarrowingVariableType/beforeSimpleCast.java b/java/java-tests/testData/inspection/castCanBeRemovedNarrowingVariableType/beforeSimpleCast.java index 9f4a089b4031..97cfba50fad7 100644 --- a/java/java-tests/testData/inspection/castCanBeRemovedNarrowingVariableType/beforeSimpleCast.java +++ b/java/java-tests/testData/inspection/castCanBeRemovedNarrowingVariableType/beforeSimpleCast.java @@ -2,7 +2,7 @@ class Test { void test() { Object x = " hello "; - System.out.println(((String)x).trim()); - System.out.println(((String)x).substring(1)); + System.out.println(((String)(x)).trim()); + System.out.println(((String)(x)).substring(1)); } } \ No newline at end of file diff --git a/java/java-tests/testData/inspection/collectionAddAllCanBeReplacedWithConstructor/beforeSimple.java b/java/java-tests/testData/inspection/collectionAddAllCanBeReplacedWithConstructor/beforeSimple.java index 48dc95556662..7e653675d323 100644 --- a/java/java-tests/testData/inspection/collectionAddAllCanBeReplacedWithConstructor/beforeSimple.java +++ b/java/java-tests/testData/inspection/collectionAddAllCanBeReplacedWithConstructor/beforeSimple.java @@ -8,6 +8,6 @@ import java.util.Collection; class C { void m() { final Collection strings = new ArrayList(); - strings.addAll(new HashSet()); + (strings).addAll(new HashSet()); } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/KeySetIterationMayUseEntrySetInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/KeySetIterationMayUseEntrySetInspection.java index b16c9ff6be0c..3759cd984830 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/KeySetIterationMayUseEntrySetInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/performance/KeySetIterationMayUseEntrySetInspection.java @@ -1,18 +1,4 @@ -/* - * Copyright 2008-2017 Bas Leijdekkers - * - * 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-2019 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.performance; import com.intellij.codeInspection.CommonQuickFixBundle; @@ -373,7 +359,6 @@ public class KeySetIterationMayUseEntrySetInspection extends BaseInspection { @Nullable @Contract("null -> null") private static PsiExpression getIteratedExpression(PsiExpression iteratedValue) { - iteratedValue = PsiUtil.skipParenthesizedExprDown(iteratedValue); PsiLocalVariable variable = ExpressionUtils.resolveLocalVariable(iteratedValue); if (variable != null) { final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(variable, PsiMethod.class); diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ExpressionUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ExpressionUtils.java index 2cc9c2e19161..a66a46de096e 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ExpressionUtils.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ExpressionUtils.java @@ -1,18 +1,4 @@ -/* - * Copyright 2005-2019 Bas Leijdekkers - * - * 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-2019 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.psiutils; import com.intellij.codeInsight.AnnotationUtil; @@ -1034,6 +1020,7 @@ public class ExpressionUtils { @Contract(value = "null -> null") @Nullable public static PsiLocalVariable resolveLocalVariable(@Nullable PsiExpression expression) { + expression = ParenthesesUtils.stripParentheses(expression); PsiReferenceExpression referenceExpression = tryCast(expression, PsiReferenceExpression.class); if(referenceExpression == null) return null; return tryCast(referenceExpression.resolve(), PsiLocalVariable.class); diff --git a/plugins/InspectionGadgets/src/com/intellij/codeInspection/redundantCast/CastCanBeRemovedNarrowingVariableTypeInspection.java b/plugins/InspectionGadgets/src/com/intellij/codeInspection/redundantCast/CastCanBeRemovedNarrowingVariableTypeInspection.java index 60bcb87a1dce..76b3b69d2846 100644 --- a/plugins/InspectionGadgets/src/com/intellij/codeInspection/redundantCast/CastCanBeRemovedNarrowingVariableTypeInspection.java +++ b/plugins/InspectionGadgets/src/com/intellij/codeInspection/redundantCast/CastCanBeRemovedNarrowingVariableTypeInspection.java @@ -1,4 +1,4 @@ -// 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. +// Copyright 2000-2019 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.codeInspection.redundantCast; import com.intellij.codeInspection.*; @@ -28,8 +28,7 @@ public class CastCanBeRemovedNarrowingVariableTypeInspection extends AbstractBas if (castTypeElement == null || castTypeElement.getAnnotations().length > 0) return; PsiType castType = cast.getType(); if (!(castType instanceof PsiClassType) || ((PsiClassType)castType).isRaw()) return; - PsiReferenceExpression ref = tryCast(cast.getOperand(), PsiReferenceExpression.class); - PsiLocalVariable variable = ExpressionUtils.resolveLocalVariable(ref); + PsiLocalVariable variable = ExpressionUtils.resolveLocalVariable(cast.getOperand()); if (variable == null) return; PsiTypeElement variableTypeElement = variable.getTypeElement(); if (variableTypeElement.isInferredType() || variableTypeElement.getAnnotations().length > 0) return; diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/key_set_with_entry_set/Reference.after.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/key_set_with_entry_set/Reference.after.java index 97d7ac5be88a..7a15f9a66c7a 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/key_set_with_entry_set/Reference.after.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/key_set_with_entry_set/Reference.after.java @@ -4,7 +4,7 @@ import java.util.Set; class Reference { void m(Map map) { - for (String s : map.values()) { + for (String s : (map.values())) { System.out.println(s); } } diff --git a/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/key_set_with_entry_set/Reference.java b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/key_set_with_entry_set/Reference.java index 39da129b0e62..5cf80b90a18f 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/key_set_with_entry_set/Reference.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igfixes/performance/key_set_with_entry_set/Reference.java @@ -5,7 +5,7 @@ class Reference { void m(Map map) { Set keys = (map.keySet()); - for (String key : keys) { + for (String key : (keys)) { System.out.println(map.get(key)); } }