mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
add hardcoded contracts for Guava checkArgument/checkState (IDEA-126005)
This commit is contained in:
+5
@@ -50,6 +50,11 @@ public class HardcodedContracts {
|
||||
constraints[0] = NULL_VALUE;
|
||||
return Collections.singletonList(new MethodContract(constraints, THROW_EXCEPTION));
|
||||
}
|
||||
if (("checkArgument".equals(methodName) || "checkState".equals(methodName)) && paramCount > 0) {
|
||||
MethodContract.ValueConstraint[] constraints = createConstraintArray(paramCount);
|
||||
constraints[0] = FALSE_VALUE;
|
||||
return Collections.singletonList(new MethodContract(constraints, THROW_EXCEPTION));
|
||||
}
|
||||
}
|
||||
else if ("java.util.Objects".equals(className)) {
|
||||
if ("requireNonNull".equals(methodName) && paramCount > 0) {
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class Contracts {
|
||||
|
||||
private void check(@Nullable Object o, @Nullable Object o2) {
|
||||
com.google.common.base.Preconditions.checkArgument(o != null);
|
||||
com.google.common.base.Preconditions.checkState(o2 != null, "");
|
||||
System.out.println(o.hashCode());
|
||||
System.out.println(o2.hashCode());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -364,6 +364,16 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testBooleanPreconditions() {
|
||||
myFixture.addClass("package com.google.common.base; public class Preconditions { " +
|
||||
"public static <T> T checkArgument(boolean b) {}\n" +
|
||||
"public static <T> T checkArgument(boolean b, String msg) {}\n" +
|
||||
"public static <T> T checkState(boolean b, String msg) {}\n" +
|
||||
"}");
|
||||
myFixture.enableInspections(new DataFlowInspection());
|
||||
myFixture.testHighlighting(true, false, true, getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
public void testGuavaCheckNotNull() {
|
||||
myFixture.addClass("package com.google.common.base; public class Preconditions { " +
|
||||
"public static <T> T checkNotNull(T reference) {}\n" +
|
||||
|
||||
Reference in New Issue
Block a user