Cleanup (minor optimization; warnings; typos; formatting)

GitOrigin-RevId: 52498af662d79e96030a36434f38a88535b33988
This commit is contained in:
Roman Shevchenko
2019-07-02 06:52:16 +03:00
committed by intellij-monorepo-bot
parent 06d3d41999
commit 821de12d59
3 changed files with 14 additions and 25 deletions
@@ -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;
@@ -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()
*/
@@ -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 extends PsiElement> T getLastChildOfType(@Nullable PsiElement element, @NotNull Class<T> 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;
}