DFA instruction visitor refactoring wave#5

CheckReturnValueInstruction replaced with checkReturnValue call (PSI-based)
beforeExpressionPush for typecast result
Control flow: &&/|| handling unified and simplified (less jumps, less states)
ContractChecker rewritten (now visitor-based)
This commit is contained in:
Tagir Valeev
2018-06-25 13:49:39 +07:00
parent 664b9a4d4c
commit fd66719ce0
24 changed files with 391 additions and 477 deletions
@@ -1,45 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Test.java</file>
<line>14</line>
<description>Condition &lt;code&gt;c&lt;/code&gt; is always &lt;code&gt;false&lt;/code&gt;.</description>
</problem>
<problem>
<file>Test.java</file>
<line>20</line>
<description>Condition &lt;code&gt;c&lt;/code&gt; is always &lt;code&gt;true&lt;/code&gt;.</description>
</problem>
<problem>
<file>Test.java</file>
<line>33</line>
<description>Condition &lt;code&gt;o&lt;/code&gt; is always &lt;code&gt;true&lt;/code&gt;.</description>
</problem>
<problem>
<file>Test.java</file>
<line>39</line>
<description>Condition &lt;code&gt;o&lt;/code&gt; is always &lt;code&gt;false&lt;/code&gt;.</description>
</problem>
<problem>
<file>Test.java</file>
<line>45</line>
<description>Condition &lt;code&gt;o&lt;/code&gt; is always &lt;code&gt;true&lt;/code&gt;.</description>
</problem>
<problem>
<file>Test.java</file>
<line>51</line>
<description>Condition &lt;code&gt;o&lt;/code&gt; at the left side of assignment expression is always &lt;code&gt;false&lt;/code&gt;. Can be simplified.</description>
</problem>
<problem>
<file>Test.java</file>
<line>62</line>
<description>Condition &lt;code&gt;o&lt;/code&gt; is always &lt;code&gt;true&lt;/code&gt;</description>
</problem>
</problems>
@@ -1,65 +0,0 @@
public class S {
void f(Boolean override) {
if (override == null) {
//doSomething();
} else if (override) { // always false?
//doOverride();
}
}
public void te0(boolean b){
Boolean c = false;
// if (b) c = true;
if (c) {
}
}
public void te1(boolean b){
Boolean c = true;
// if (b) c = true;
if (c) {
}
}
public void te2(boolean b){
Boolean c = false;
if (b) c = true;
if (c) {
}
}
public void te3(boolean b){
Boolean c = Boolean.FALSE;
boolean o = !c;
if (o) {
}
}
public void te4(boolean b){
Boolean c = Boolean.FALSE;
boolean o = c;
if (o) {
}
}
public void te5(boolean b){
Boolean c = Boolean.TRUE;
boolean o = b||c;
if (o) {
}
}
public void te6(boolean b){
Boolean c = Boolean.TRUE;
boolean o = !c;
o |= c&b;
if (o) {
}
}
public void flushOriginal(boolean b){
boolean o;
{
Boolean c = Boolean.FALSE;
o = !c;
}
if (o) {
}
}
}
@@ -3,7 +3,7 @@ import java.util.List;
class Some {
public static void appendTokenTypes(StringBuilder sb, List<String> tokenTypes) {
for (int count = 0, line = 0, size = tokenTypes.size(); count < size; count++) {
boolean newLine = count == 2 || <warning descr="Condition 'line > 0' is always 'false' when reached">line > 0</warning> && (count - 2) % 6 == 0;
boolean newLine = count == 2 || <warning descr="Condition 'line > 0 && (count - 2) % 6 == 0' is always 'false' when reached"><warning descr="Condition 'line > 0' is always 'false' when reached">line > 0</warning> && (count - 2) % 6 == 0</warning>;
newLine &= (size - count) > 2;
}
}
@@ -0,0 +1,65 @@
class S {
void f(Boolean override) {
if (override == null) {
//doSomething();
} else if (override) { // always false?
//doOverride();
}
}
public void te0(boolean b){
Boolean c = false;
// if (b) c = true;
if (<warning descr="Condition 'c' is always 'false'">c</warning>) {
}
}
public void te1(boolean b){
Boolean c = true;
// if (b) c = true;
if (<warning descr="Condition 'c' is always 'true'">c</warning>) {
}
}
public void te2(boolean b){
Boolean c = false;
if (b) c = true;
if (c) {
}
}
public void te3(boolean b){
Boolean c = Boolean.FALSE;
boolean o = !c;
if (<warning descr="Condition 'o' is always 'true'">o</warning>) {
}
}
public void te4(boolean b){
Boolean c = Boolean.FALSE;
boolean o = c;
if (<warning descr="Condition 'o' is always 'false'">o</warning>) {
}
}
public void te5(boolean b){
Boolean c = Boolean.TRUE;
boolean o = <warning descr="Condition 'b||c' is always 'true'">b||<warning descr="Condition 'c' is always 'true' when reached">c</warning></warning>;
if (<warning descr="Condition 'o' is always 'true'">o</warning>) {
}
}
public void te6(boolean b){
Boolean c = Boolean.TRUE;
boolean o = !c;
<warning descr="Condition 'o' at the left side of assignment expression is always 'false'. Can be simplified">o</warning> |= c&b;
if (o) {
}
}
public void flushOriginal(boolean b){
boolean o;
{
Boolean c = Boolean.FALSE;
o = !c;
}
if (<warning descr="Condition 'o' is always 'true'">o</warning>) {
}
}
}
@@ -8,7 +8,7 @@ class X {
final char c = pattern.charAt(i);
if (c == '*') { }
else if (c == ' ') { }
else if (c == ':' || prevIsUppercase) { }
else if (c == ':' || <warning descr="Condition 'prevIsUppercase' is always 'false' when reached">prevIsUppercase</warning>) { }
}
System.out.println(forCompletion);
System.out.println(exactPrefixLen);
@@ -32,6 +32,6 @@ public class DoubleNaN {
void test2() {
System.out.println(<warning descr="Condition '1.0 == Double.NaN' is always 'false'">1.0 == Double.NaN</warning>);
System.out.println(!(<warning descr="Condition '1.0 < Double.NaN' is always 'false'">1.0 < Double.NaN</warning>));
System.out.println(<warning descr="Condition '!(1.0 < Double.NaN)' is always 'true'">!(<warning descr="Condition '1.0 < Double.NaN' is always 'false'">1.0 < Double.NaN</warning>)</warning>);
}
}
@@ -11,7 +11,7 @@ class Test {
System.out.println("never");
}
y = x;
if(x.equals(y)) {
if(<warning descr="Condition 'x.equals(y)' is always 'true'">x.equals(y)</warning>) {
System.out.println("always");
}
}
@@ -29,8 +29,8 @@ class Test {
maybe = Optional.empty();
System.out.println(maybe.<warning descr="The call to 'get' always fails, according to its method contracts">get</warning>());
}
boolean b = <warning descr="Condition '((maybe.isPresent()))' is always 'false'">((<warning descr="Condition 'maybe.isPresent()' is always 'false'">maybe.isPresent()</warning>))</warning> && maybe.get() == 1;
boolean c = <warning descr="Condition '(!maybe.isPresent())' is always 'true'">(!<warning descr="Condition 'maybe.isPresent()' is always 'false'">maybe.isPresent()</warning>)</warning> || maybe.get() == 1;
boolean b = <warning descr="Condition '((maybe.isPresent())) && maybe.get() == 1' is always 'false'"><warning descr="Condition '((maybe.isPresent()))' is always 'false'">((<warning descr="Condition 'maybe.isPresent()' is always 'false'">maybe.isPresent()</warning>))</warning> && maybe.get() == 1</warning>;
boolean c = <warning descr="Condition '(!maybe.isPresent()) || maybe.get() == 1' is always 'true'"><warning descr="Condition '(!maybe.isPresent())' is always 'true'">(<warning descr="Condition '!maybe.isPresent()' is always 'true'">!<warning descr="Condition 'maybe.isPresent()' is always 'false'">maybe.isPresent()</warning></warning>)</warning> || maybe.get() == 1</warning>;
Integer value = <warning descr="Condition '!maybe.isPresent()' is always 'true'">!<warning descr="Condition 'maybe.isPresent()' is always 'false'">maybe.isPresent()</warning></warning> ? 0 : maybe.get();
}
@@ -2,7 +2,7 @@ class BrokenAlignment {
boolean smth() {
if (<warning descr="Condition '2 == 2' is always 'true'">2 == 2</warning>) {
return true;
System.out.println("True");
}
boolean b = <warning descr="Condition '3 == 3' is always 'true'">3 == 3</warning>;
@@ -38,7 +38,7 @@ class Test {
private static void testOrNotFail(boolean a, boolean b, boolean c) {
if(b) {
assert <warning descr="Condition '!(a || b || c)' is always 'false'">!(a || <warning descr="Condition 'b' is always 'true'">b</warning> || c)</warning>;
assert <warning descr="Condition '!(a || b || c)' is always 'false'">!(<warning descr="Condition 'a || b || c' is always 'true'">a || <warning descr="Condition 'b' is always 'true'">b</warning> || c</warning>)</warning>;
}
}