IDEA-159977 inspector "Constant conditions & exceptions" not support org.springframework.util.Assert

This commit is contained in:
peter
2016-08-22 15:10:03 +02:00
parent 36f1a23e7b
commit c01814e651
3 changed files with 26 additions and 4 deletions
@@ -69,12 +69,12 @@ public class HardcodedContracts {
return Collections.singletonList(new MethodContract(constraints, THROW_EXCEPTION));
}
}
else if ("org.apache.commons.lang.Validate".equals(className) ||
"org.apache.commons.lang3.Validate".equals(className) ||
else if ("org.apache.commons.lang.Validate".equals(className) ||
"org.apache.commons.lang3.Validate".equals(className) ||
"org.springframework.util.Assert".equals(className)) {
if ("notNull".equals(methodName) && paramCount > 0) {
if (("isTrue".equals(methodName) || "state".equals(methodName)) && paramCount > 0) {
MethodContract.ValueConstraint[] constraints = createConstraintArray(paramCount);
constraints[0] = NULL_VALUE;
constraints[0] = FALSE_VALUE;
return Collections.singletonList(new MethodContract(constraints, THROW_EXCEPTION));
}
}
@@ -0,0 +1,15 @@
import org.springframework.util.Assert;
class Contracts {
void foo(Object o) {
Assert.isTrue(o instanceof String);
String s = (String) o;
}
void foo1(Object o) {
Assert.state(o instanceof String, "oops");
String s = (String) o;
}
}
@@ -97,5 +97,12 @@ public class HardcodedContractsTest extends DataFlowInspectionTestCase {
checkHighlighting();
}
public void testSpringAssert() {
myFixture.addClass("package org.springframework.util; public class Assert {\n" +
" public static void isTrue(boolean expression) {}\n" +
" public static void state(boolean expression, String s) {}\n" +
"}");
checkHighlighting();
}
}