don't use checker.xml for dfa (but leave it there for a while, IDEA-125426)

This commit is contained in:
peter
2014-05-23 15:43:09 +02:00
parent 7f8eae7734
commit 33929c5eab
9 changed files with 1 additions and 150 deletions
@@ -1612,26 +1612,6 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
}
}
ConditionChecker checker = ConditionCheckManager.findConditionChecker(resolved);
if (checker != null) {
ValueConstraint[] constraints = getAnyArgConstraints(params);
int checkedParam = checker.getCheckedParameterIndex();
if (checkedParam >= constraints.length) {
return Collections.emptyList();
}
ConditionChecker.Type type = checker.getConditionCheckType();
if (type == ASSERT_IS_NULL_METHOD || type == ASSERT_IS_NOT_NULL_METHOD) {
constraints[checkedParam] = type == ASSERT_IS_NOT_NULL_METHOD ? ValueConstraint.NULL_VALUE : ValueConstraint.NOT_NULL_VALUE;
return Collections.singletonList(new MethodContract(constraints, ValueConstraint.THROW_EXCEPTION));
} else if (type == IS_NOT_NULL_METHOD || type == IS_NULL_METHOD) {
constraints[checkedParam] = ValueConstraint.NULL_VALUE;
return Collections.singletonList(new MethodContract(constraints, type == IS_NULL_METHOD ? ValueConstraint.TRUE_VALUE : ValueConstraint.FALSE_VALUE));
} else { //assertTrue or assertFalse
constraints[checkedParam] = type == ASSERT_FALSE_METHOD ? ValueConstraint.TRUE_VALUE : ValueConstraint.FALSE_VALUE;
return Collections.singletonList(new MethodContract(constraints, ValueConstraint.THROW_EXCEPTION));
}
}
}
return Collections.emptyList();
@@ -28,6 +28,7 @@ import java.util.List;
/**
* @author <a href="mailto:johnnyclark@gmail.com">Johnny Clark</a>
* Creation Date: 8/3/12
* todo remove in IDEA 15
*/
@State(
name = "ConditionCheckManager",
@@ -1,9 +0,0 @@
class AssertFalse {
void bar() {
final boolean b = call();
if (Assertions.assertFalse(b)) {
if(<warning descr="Condition 'b' is always 'false'">b</warning>) {}
}
}
boolean call() {return true;}
}
@@ -1,10 +0,0 @@
import java.lang.*;
class AssertIsNotNull {
void bar() {
final Object o = call();
Assertions.assertIsNotNull(o);
if(<warning descr="Condition 'o == null' is always 'false'">o == null</warning>) {}
}
Object call() {return new Object();}
}
@@ -1,10 +0,0 @@
import java.lang.*;
class AssertIsNull {
void bar() {
final Object o = call();
Assertions.assertIsNull(o);
if(<warning descr="Condition 'o == null' is always 'true'">o == null</warning>) {}
}
Object call() {return new Object();}
}
@@ -1,9 +0,0 @@
class AssertTrue {
void bar() {
final boolean b = call();
if (Assertions.assertTrue(b)) {
if(<warning descr="Condition 'b' is always 'true'">b</warning>) {}
}
}
boolean call() {return true;}
}
@@ -1,16 +0,0 @@
class IsNotNullCheck {
void bar() {
final Value v = call();
if (Value.isNotNull(v)) {
if(<warning descr="Condition 'v == null' is always 'false'">v == null</warning>) {}
}
}
void bar2() {
final Value v = call();
System.out.println(v.hashCode());
if (Value.isNotNull(v)) {
}
}
Value call() {return new Value();}
}
@@ -1,10 +0,0 @@
class IsNullCheck {
void bar() {
final Value v = call();
if (Value.isNull(v)) {
return;
}
if(<warning descr="Condition 'v == null' is always 'false'">v == null</warning>) {}
}
Value call() {return new Value();}
}
@@ -16,17 +16,10 @@
package com.intellij.codeInspection;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.ConditionCheckManager;
import com.intellij.codeInsight.ConditionChecker;
import com.intellij.codeInspection.dataFlow.DataFlowInspection;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
/**
* @author peter
@@ -205,65 +198,6 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
public void testHonorGetterAnnotation() { doTest(); }
public void testIsNullCheck() throws Exception {
ConditionCheckManager.getInstance(myModule.getProject()).getIsNullCheckMethods().add(
buildConditionChecker("Value", "isNull", ConditionChecker.Type.IS_NULL_METHOD,
"public class Value { public static boolean isNull(Value o) {if (o == null) return true; else return false;} }"));
doTest();
}
public void testIsNotNullCheck() throws Exception {
ConditionCheckManager.getInstance(myModule.getProject()).getIsNotNullCheckMethods().add(
buildConditionChecker("Value", "isNotNull", ConditionChecker.Type.IS_NOT_NULL_METHOD,
"public class Value { public static boolean isNotNull(Value o) {if (o == null) return false; else return true;} }"));
doTest();
}
public void testAssertTrue() throws Exception {
ConditionCheckManager.getInstance(myModule.getProject()).getAssertTrueMethods().add(
buildConditionChecker("Assertions", "assertTrue", ConditionChecker.Type.ASSERT_TRUE_METHOD,
"public class Assertions { public static boolean assertTrue(boolean b) {if(!b) throw new Exception();} }"));
doTest();
}
public void testAssertFalse() throws Exception {
ConditionCheckManager.getInstance(myModule.getProject()).getAssertFalseMethods().add(
buildConditionChecker("Assertions", "assertFalse", ConditionChecker.Type.ASSERT_FALSE_METHOD,
"public class Assertions { public static boolean assertFalse(boolean b) {if(b) throw new Exception();} }"));
doTest();
}
public void testAssertIsNull() throws Exception {
ConditionCheckManager.getInstance(myModule.getProject()).getAssertIsNullMethods().add(
buildConditionChecker("Assertions", "assertIsNull", ConditionChecker.Type.ASSERT_IS_NULL_METHOD,
"public class Assertions { public static boolean assertIsNull(Object o) {if(o != null) throw new Exception();} }"));
doTest();
}
public void testAssertIsNotNull() throws Exception {
ConditionCheckManager.getInstance(myModule.getProject()).getAssertIsNotNullMethods().add(
buildConditionChecker("Assertions", "assertIsNotNull", ConditionChecker.Type.ASSERT_IS_NOT_NULL_METHOD,
"public class Assertions { public static boolean assertIsNotNull(Object o) {if(o == null) throw new Exception();} }"));
doTest();
}
@Nullable
private ConditionChecker buildConditionChecker(String className, String methodName, ConditionChecker.Type type, String classText)
throws IOException {
myFixture.addClass(classText);
PsiClass psiClass = myFixture.findClass(className);
PsiMethod psiMethod = null;
PsiMethod[] methods = psiClass.getMethods();
for (PsiMethod tempPsiMethod : methods) {
if (tempPsiMethod.getName().equals(methodName)) {
psiMethod = tempPsiMethod;
break;
}
}
assert psiMethod != null;
return new ConditionChecker.FromPsiBuilder(psiMethod, psiMethod.getParameterList().getParameters()[0], type).build();
}
public void testIgnoreAssertions() {
final DataFlowInspection inspection = new DataFlowInspection();
inspection.IGNORE_ASSERT_STATEMENTS = true;