Java inspection: More tests for "Move return to computation" (IDEA-121153)

This commit is contained in:
Pavel Dolgov
2016-09-06 19:05:05 +03:00
parent 04430d7f73
commit 34872c5443
37 changed files with 384 additions and 135 deletions
@@ -1,13 +0,0 @@
class T {
int f(int[] a) {
int n = -1;
myLabel:
for (int i = 0; i < a.length; i++) {
if (a[0] == 0) {
n = i;
break myLabel;
}
}
<warning descr="Return separated from computation of value of 'n'">return n;</warning>
}
}
@@ -1,11 +0,0 @@
class T {
int f(int[] a) {
int n = -1;
myLabel:
for (int i = 0; i < a.length; i++) {
n = i;
if (a[0] == 0) break myLabel;
}
<warning descr="Return separated from computation of value of 'n'">return n;</warning>
}
}
@@ -1,9 +0,0 @@
class T {
int f(boolean b) {
int n = 0;
myLabel:
if (b) n = 1;
else break myLabel;
<warning descr="Return separated from computation of value of 'n'">return n;</warning>
}
}
@@ -1,9 +0,0 @@
class T {
int f() {
int n;
{
n = 1;
}
<warning descr="Return separated from computation of value of 'n'">return n;</warning>
}
}
@@ -1,10 +0,0 @@
class T {
int f() {
int n;
{
n = 1;
System.out.println();
}
<warning descr="Return separated from computation of value of 'n'">return n;</warning>
}
}
@@ -1,11 +0,0 @@
class T {
int f(boolean a, boolean b) {
int n = -1;
if (a) {
if (b) {
n = 1;
}
}
return n;
}
}
@@ -1,10 +0,0 @@
class T {
int f(boolean a, boolean b) {
int n = -1;
if (a) {
if (b) n = 1;
else n = 2;
}
return n;
}
}
@@ -1,10 +0,0 @@
class T {
int f(boolean a, boolean b) {
int n = -1;
if (a) {
if (b) n = 1;
}
else n = 2;
return n;
}
}
@@ -1,15 +0,0 @@
import java.io.*;
class T {
private static String getString() throws IOException {
String s;
try (BufferedReader r = open()) {
s = r.readLine();
}
<warning descr="Return separated from computation of value of 's'">return s;</warning>
}
private static BufferedReader open() throws FileNotFoundException {
return null;
}
}
@@ -1,25 +0,0 @@
class T {
String f(String a) {
String r = "";
int i = 0;
do {
int j = a.indexOf(",", i);
String s = j > i ? a.substring(i, j) : a.substring(i);
if (s.startsWith("@")) {
r = s;
break;
}
i = j + 1;
}
while (i >= 0);
<warning descr="Return separated from computation of value of 'r'">return r;</warning>
}
boolean hasNext() {
return true;
}
String next() {
return null;
}
}
@@ -1,12 +0,0 @@
class T {
String f(String[] a) {
String r = "";
for (String s : a) {
if (s != null && s.contains("@")) {
r = s + ":" + s.length();
break;
}
}
<warning descr="Return separated from computation of value of 'r'">return r;</warning>
}
}
@@ -0,0 +1,13 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f(int[] a) {
int n = -1;
myLabel:
for (int i = 0; i < a.length; i++) {
if (a[0] == 0) {
return i;
}
}
return n;
}
}
@@ -0,0 +1,12 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f(int[] a) {
int n = -1;
myLabel:
for (int i = 0; i < a.length; i++) {
n = i;
if (a[0] == 0) return n;
}
return n;
}
}
@@ -0,0 +1,9 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f(boolean b) {
int n = 0;
myLabel:
if (b) return 1;
else return n;
}
}
@@ -0,0 +1,9 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f() {
int n;
{
return 1;
}
}
}
@@ -0,0 +1,11 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f() {
int n;
{
n = 1;
System.out.println();
return n;
}
}
}
@@ -0,0 +1,12 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f(boolean a, boolean b) {
int n = -1;
if (a) {
if (b) {
return 1;
}
}
return n;
}
}
@@ -0,0 +1,11 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f(boolean a, boolean b) {
int n = -1;
if (a) {
if (b) return 1;
else return 2;
}
return n;
}
}
@@ -0,0 +1,11 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f(boolean a, boolean b) {
int n = -1;
if (a) {
if (b) return 1;
}
else return 2;
return n;
}
}
@@ -0,0 +1,15 @@
// "Move 'return' to computation of the value of 'n'" "true"
import java.io.*;
class T {
private static String getString() throws IOException {
String s;
try (BufferedReader r = open()) {
return r.readLine();
}
}
private static BufferedReader open() throws FileNotFoundException {
return null;
}
}
@@ -0,0 +1,25 @@
// "Move 'return' to computation of the value of 'r'" "true"
class T {
String f(String a) {
String r = "";
int i = 0;
do {
int j = a.indexOf(",", i);
String s = j > i ? a.substring(i, j) : a.substring(i);
if (s.startsWith("@")) {
return s;
}
i = j + 1;
}
while (i >= 0);
return r;
}
boolean hasNext() {
return true;
}
String next() {
return null;
}
}
@@ -0,0 +1,12 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
String f(String[] a) {
String r = "";
for (String s : a) {
if (s != null && s.contains("@")) {
return s + ":" + s.length();
}
}
return r;
}
}
@@ -0,0 +1,23 @@
// "Move 'return' to computation of the value of 'r'" "true"
class T {
String f(String p) {
String r = null;
try {
while (true) {
String n = next();
if (n != null) {
String t = n.toLowerCase();
if (t.equals(p)) {
return n;
}
}
}
} finally {
System.out.println();
}
}
String next() {
return "";
}
}
@@ -0,0 +1,24 @@
// "Move 'return' to computation of the value of 'r'" "true"
class T {
String f(String p) {
String r = null;
try {
while (true) {
String n = next();
if (n != null) return r;
if ("@".eqals(n)) {
String t = n.toLowerCase();
if (t.equals(p)) {
return n;
}
}
}
} finally {
System.out.println();
}
}
String next() {
return "";
}
}
@@ -0,0 +1,14 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f(int[] a) {
int n = -1;
myLabel:
for (int i = 0; i < a.length; i++) {
if (a[0] == 0) {
n = i;
break myLabel;
}
}
re<caret>turn n;
}
}
@@ -0,0 +1,12 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f(int[] a) {
int n = -1;
myLabel:
for (int i = 0; i < a.length; i++) {
n = i;
if (a[0] == 0) break myLabel;
}
re<caret>turn n;
}
}
@@ -0,0 +1,10 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f(boolean b) {
int n = 0;
myLabel:
if (b) n = 1;
else break myLabel;
ret<caret>urn n;
}
}
@@ -0,0 +1,10 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f() {
int n;
{
n = 1;
}
ret<caret>urn n;
}
}
@@ -0,0 +1,11 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f() {
int n;
{
n = 1;
System.out.println();
}
return n;
}
}
@@ -0,0 +1,12 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f(boolean a, boolean b) {
int n = -1;
if (a) {
if (b) {
n = 1;
}
}
ret<caret>urn n;
}
}
@@ -0,0 +1,11 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f(boolean a, boolean b) {
int n = -1;
if (a) {
if (b) n = 1;
else n = 2;
}
r<return>eturn n;
}
}
@@ -0,0 +1,11 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
int f(boolean a, boolean b) {
int n = -1;
if (a) {
if (b) n = 1;
}
else n = 2;
re<before>turn n;
}
}
@@ -0,0 +1,16 @@
// "Move 'return' to computation of the value of 'n'" "true"
import java.io.*;
class T {
private static String getString() throws IOException {
String s;
try (BufferedReader r = open()) {
s = r.readLine();
}
re<return>turn s;
}
private static BufferedReader open() throws FileNotFoundException {
return null;
}
}
@@ -0,0 +1,26 @@
// "Move 'return' to computation of the value of 'r'" "true"
class T {
String f(String a) {
String r = "";
int i = 0;
do {
int j = a.indexOf(",", i);
String s = j > i ? a.substring(i, j) : a.substring(i);
if (s.startsWith("@")) {
r = s;
break;
}
i = j + 1;
}
while (i >= 0);
retu<caret>rn r;
}
boolean hasNext() {
return true;
}
String next() {
return null;
}
}
@@ -0,0 +1,13 @@
// "Move 'return' to computation of the value of 'n'" "true"
class T {
String f(String[] a) {
String r = "";
for (String s : a) {
if (s != null && s.contains("@")) {
r = s + ":" + s.length();
break;
}
}
r<caret>eturn r;
}
}
@@ -0,0 +1,25 @@
// "Move 'return' to computation of the value of 'r'" "true"
class T {
String f(String p) {
String r = null;
try {
while (true) {
String n = next();
if (n != null) {
String t = n.toLowerCase();
if (t.equals(p)) {
r = n;
break;
}
}
}
} finally {
System.out.println();
}
re<caret>turn r;
}
String next() {
return "";
}
}
@@ -0,0 +1,26 @@
// "Move 'return' to computation of the value of 'r'" "true"
class T {
String f(String p) {
String r = null;
try {
while (true) {
String n = next();
if (n != null) break;
if ("@".eqals(n)) {
String t = n.toLowerCase();
if (t.equals(p)) {
r = n;
break;
}
}
}
} finally {
System.out.println();
}
re<caret>turn r;
}
String next() {
return "";
}
}