From 821de12d59814c657e2afc1f43ae2550d8fa61bb Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Thu, 20 Jun 2019 23:05:06 +0200 Subject: [PATCH] Cleanup (minor optimization; warnings; typos; formatting) GitOrigin-RevId: 52498af662d79e96030a36434f38a88535b33988 --- .../daemon/impl/analysis/HighlightUtil.java | 9 ++++---- .../LightJavaCodeInsightFixtureTestCase.java | 9 +++----- .../siyeh/ig/psiutils/ControlFlowUtils.java | 21 +++++++------------ 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java index b57f147bf61a..87e9d02e5373 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightUtil.java @@ -2117,13 +2117,12 @@ public class HighlightUtil extends HighlightUtilBase { for (PsiSwitchLabeledRuleStatement rule = (PsiSwitchLabeledRuleStatement)lastStatement; rule != null; rule = PsiTreeUtil.getPrevSiblingOfType(rule, PsiSwitchLabeledRuleStatement.class)) { - PsiStatement ruleBody = rule.getBody(); // the expression and throw statements are fine, only the block statement could be an issue if (ruleBody instanceof PsiBlockStatement && ControlFlowUtils.statementMayCompleteNormally(ruleBody)) { PsiElement target = ObjectUtils.notNull(ObjectUtils.tryCast(rule.getFirstChild(), PsiKeyword.class), rule); - results.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(target) - .descriptionAndTooltip(JavaErrorMessages.message("switch.expr.rule.should.produce.result")).create()); + String message = JavaErrorMessages.message("switch.expr.rule.should.produce.result"); + results.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(target).descriptionAndTooltip(message).create()); } } return results; @@ -2131,8 +2130,8 @@ public class HighlightUtil extends HighlightUtilBase { // previous statements may have no result as well, but in that case they fall through to the last one, which needs to be checked anyway if (lastStatement != null && ControlFlowUtils.statementMayCompleteNormally(lastStatement)) { PsiElement target = ObjectUtils.notNull(ObjectUtils.tryCast(switchExpression.getFirstChild(), PsiKeyword.class), switchExpression); - return Collections.singletonList(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(target) - .descriptionAndTooltip(JavaErrorMessages.message("switch.expr.should.produce.result")).create()); + String message = JavaErrorMessages.message("switch.expr.should.produce.result"); + return Collections.singletonList(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(target).descriptionAndTooltip(message).create()); } } return null; diff --git a/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java b/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java index 0d28c0ea983f..4c2929d6cf0c 100644 --- a/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java +++ b/java/testFramework/src/com/intellij/testFramework/fixtures/LightJavaCodeInsightFixtureTestCase.java @@ -7,10 +7,7 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.projectRoots.Sdk; -import com.intellij.openapi.roots.ContentEntry; -import com.intellij.openapi.roots.LanguageLevelModuleExtension; -import com.intellij.openapi.roots.LanguageLevelProjectExtension; -import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.*; import com.intellij.pom.java.AcceptedLanguageLevelsSettings; import com.intellij.pom.java.LanguageLevel; import com.intellij.psi.*; @@ -121,7 +118,7 @@ public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase } /** - * Returns relative path to the test data. + * Returns a relative path to the test data. */ protected String getBasePath() { return ""; @@ -133,7 +130,7 @@ public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase } /** - * Return absolute path to the test data. Not intended to be overridden. + * Return an absolute path to the test data. Not intended to be overridden. * * @see #getBasePath() */ diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ControlFlowUtils.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ControlFlowUtils.java index 41683d931902..0810187d3758 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ControlFlowUtils.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/ControlFlowUtils.java @@ -27,7 +27,6 @@ import com.intellij.util.ArrayUtil; import com.intellij.util.ObjectUtils; import one.util.streamex.StreamEx; import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -38,8 +37,7 @@ import java.util.List; import static com.siyeh.ig.psiutils.ControlFlowUtils.InitializerUsageStatus.*; public class ControlFlowUtils { - - private ControlFlowUtils() {} + private ControlFlowUtils() { } public static boolean isElseIf(PsiIfStatement ifStatement) { PsiElement parent = ifStatement.getParent(); @@ -80,7 +78,7 @@ public class ControlFlowUtils { if (method == null) { return true; } - @NonNls final String methodName = method.getName(); + final String methodName = method.getName(); if (!methodName.equals("exit")) { return true; } @@ -501,15 +499,10 @@ public class ControlFlowUtils { @Nullable public static PsiStatement getLastStatementInBlock(@Nullable PsiCodeBlock codeBlock) { - return getLastChildOfType(codeBlock, PsiStatement.class); - } - - private static T getLastChildOfType(@Nullable PsiElement element, @NotNull Class aClass) { - if (element == null) return null; - for (PsiElement child = element.getLastChild(); child != null; child = child.getPrevSibling()) { - if (aClass.isInstance(child)) { - //noinspection unchecked - return (T)child; + if (codeBlock == null) return null; + for (PsiElement child = codeBlock.getLastChild(); child != null; child = child.getPrevSibling()) { + if (child instanceof PsiStatement) { + return (PsiStatement)child; } } return null; @@ -1181,7 +1174,7 @@ public class ControlFlowUtils { if (method == null) { return; } - @NonNls final String methodName = method.getName(); + final String methodName = method.getName(); if (!methodName.equals("exit")) { return; }