mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-116944 Constant Conditions & Exceptions doesn't report if statements with literal true/false condition
This commit is contained in:
+9
@@ -103,6 +103,15 @@ public class DataFlowInspectionBase extends BaseJavaBatchLocalInspectionTool {
|
||||
analyzeCodeBlock(initializer.getBody(), holder, isOnTheFly);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitIfStatement(PsiIfStatement statement) {
|
||||
PsiExpression condition = statement.getCondition();
|
||||
if (BranchingInstruction.isBoolConst(condition)) {
|
||||
LocalQuickFix fix = createSimplifyBooleanExpressionFix(condition, condition.textMatches(PsiKeyword.TRUE));
|
||||
holder.registerProblem(condition, "Condition is always " + condition.getText(), fix);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitAnnotation(PsiAnnotation annotation) {
|
||||
if (!ControlFlowAnalyzer.ORG_JETBRAINS_ANNOTATIONS_CONTRACT.equals(annotation.getQualifiedName())) return;
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public abstract class BranchingInstruction extends Instruction {
|
||||
return !isConstTrue && myIsTrueReachable != myIsFalseReachable;
|
||||
}
|
||||
|
||||
private static boolean isBoolConst(PsiElement condition) {
|
||||
public static boolean isBoolConst(PsiElement condition) {
|
||||
if (!(condition instanceof PsiLiteralExpression)) return false;
|
||||
@NonNls String text = condition.getText();
|
||||
return "true".equals(text) || "false".equals(text);
|
||||
|
||||
@@ -20,5 +20,10 @@
|
||||
<line>49</line>
|
||||
<description>Switch label 'case 2:' is unreachable</description>
|
||||
</problem>
|
||||
<problem>
|
||||
<file>CaseAndNpe.java</file>
|
||||
<line>80</line>
|
||||
<description>Condition is always true</description>
|
||||
</problem>
|
||||
</problems>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user