mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
dfa: support contracts with no args (IDEA-127768)
This commit is contained in:
+10
-4
@@ -89,10 +89,16 @@ public class MethodContract {
|
||||
throw new ParseException("A contract clause must be in form arg1, ..., argN -> return-value");
|
||||
}
|
||||
|
||||
String[] argStrings = clause.substring(0, arrowIndex).split(",");
|
||||
ValueConstraint[] args = new ValueConstraint[argStrings.length];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
args[i] = parseConstraint(argStrings[i]);
|
||||
String beforeArrow = clause.substring(0, arrowIndex);
|
||||
ValueConstraint[] args;
|
||||
if (StringUtil.isNotEmpty(beforeArrow)) {
|
||||
String[] argStrings = beforeArrow.split(",");
|
||||
args = new ValueConstraint[argStrings.length];
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
args[i] = parseConstraint(argStrings[i]);
|
||||
}
|
||||
} else {
|
||||
args = new ValueConstraint[0];
|
||||
}
|
||||
result.add(new MethodContract(args, parseConstraint(clause.substring(arrowIndex + arrow.length()))));
|
||||
}
|
||||
|
||||
+1
-1
@@ -19,6 +19,6 @@
|
||||
}
|
||||
|
||||
public static void bar() throws CheckedException {
|
||||
throw new CheckedException();
|
||||
if (new Random().nextInt() > 2) throw new CheckedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</problem>
|
||||
<problem>
|
||||
<file>IDEADEV10489.java</file>
|
||||
<line>12</line>
|
||||
<line>8</line>
|
||||
<description>Method invocation 's.length()' may produce NullPointerException</description>
|
||||
</problem>
|
||||
</problems>
|
||||
@@ -1,7 +1,5 @@
|
||||
class IDEADEV10489 {
|
||||
static String getS() {
|
||||
return null;
|
||||
}
|
||||
static native String getS();
|
||||
|
||||
static void f() {
|
||||
String s = getS();
|
||||
@@ -17,7 +15,5 @@ class IDEADEV10489 {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean foo() {
|
||||
return false;
|
||||
}
|
||||
private static native boolean foo();
|
||||
}
|
||||
@@ -18,7 +18,5 @@ class Test {
|
||||
}
|
||||
}
|
||||
|
||||
private static @NotNull String createString() {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
private static native @NotNull String createString();
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import java.util.Random;
|
||||
|
||||
class BrokenAlignment {
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -20,7 +22,7 @@ class BrokenAlignment {
|
||||
}
|
||||
|
||||
public static void doSomething() {
|
||||
throw new RuntimeException("dummy");
|
||||
if (new Random().nextInt() > 2) throw new RuntimeException("dummy");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class Doo {
|
||||
|
||||
@NotNull
|
||||
public String doSomething() {
|
||||
String s = getSomeString();
|
||||
if (s == null) {
|
||||
throwSomeError();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
private static void throwSomeError() {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getSomeString() {
|
||||
return Math.random() > 0.5 ? null : "Yeah";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -252,6 +252,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
public void testRootThrowableCause() { doTest(); }
|
||||
|
||||
public void testUseInferredContracts() { doTest(); }
|
||||
public void testContractWithNoArgs() { doTest(); }
|
||||
public void testContractInferenceBewareOverriding() { doTest(); }
|
||||
|
||||
public void testNumberComparisonsWhenValueIsKnown() { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user