Java: Inline redundant returned variable after moving 'return' (IDEA-182669)

This commit is contained in:
Pavel Dolgov
2017-11-29 12:59:41 +03:00
parent bb9fb0fbe6
commit 4ed027a1fe
56 changed files with 333 additions and 60 deletions
@@ -1,9 +1,8 @@
// "Move 'return' closer to computation of the value of 'r'" "true"
class T {
String f() {
String r = "";
do {
if (!hasNext()) return r;
if (!hasNext()) return "";
String s = next();
if (s != null) {
return s;
@@ -0,0 +1,10 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
T f(int k) {
if (k == 1)
return new T();
else if (k == 2)
return null;
return this;
}
}
@@ -0,0 +1,10 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(int k) {
if (k == 1)
return 1;
else if (k == 2)
return 2;
return -1;
}
}
@@ -0,0 +1,16 @@
// "Move 'return' closer to computation of the value of 'r'" "true"
class T {
int foo(String s) {
int r = s.length();
if (s.isEmpty()) {
return r;
}
String t = s.substring(1);
if (!t.isEmpty()) {
return t.length();
}
return r;
}
}
@@ -0,0 +1,10 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
final int k = 1;
int foo() {
if (k < 0)
return -1;
return k;
}
}
@@ -1,7 +1,6 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f() {
int n = -1;
for(int i=0;; i++) {
if (i % 127 == 0 && i % 129 == 0) {
return i + 1;
@@ -3,11 +3,10 @@ import java.util.*;
class T {
List<String> f(boolean b) {
List raw = null;
if (b) {
return g();
}
return raw;
return null;
}
List<String> g() {
@@ -1,7 +1,6 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(boolean b) {
int n = -1;
if (b) {
return 1;
}
@@ -1,7 +1,6 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(boolean b) {
int n = 0;
if (b) return 1;
else return 2;
}
@@ -1,9 +1,8 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(boolean b) {
int n = 0;
if (b) System.out.println("yes");
else return 2;
return n;
return 0;
}
}
@@ -1,9 +1,8 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(boolean b) {
int n = 0;
if (b) return 1;
else System.out.println("no");
return n;
return 0;
}
}
@@ -1,7 +1,6 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(boolean b) {
int n = -1;
if (b) {
throw new RuntimeException();
}
@@ -1,7 +1,6 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(boolean b, boolean c) {
int n = -1;
if (b) {
try {
return g();
@@ -13,7 +12,7 @@ class T {
else {
return 2;
}
return n;
return -1;
}
int g() {
@@ -0,0 +1,9 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int foo(int k) {
int n = k;
k++;
if (k < 0) return -1;
return n;
}
}
@@ -0,0 +1,10 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
import java.util.*;
class T {
List foo(boolean b) {
if (b)
return null;
return new ArrayList();
}
}
@@ -0,0 +1,13 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
import java.util.*;
class T {
List foo(int k) {
List n = new ArrayList();
if (k == 1)
n = new ArrayList(1);
if (k == 2)
return new ArrayList(2);
return n;
}
}
@@ -0,0 +1,10 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
import java.util.*;
class T {
List foo(boolean b) {
if (b)
return new ArrayList(1);
return new ArrayList();
}
}
@@ -1,13 +1,12 @@
// "Move 'return' closer 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;
return -1;
}
}
@@ -1,7 +1,6 @@
// "Move 'return' closer 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++) {
for (int j = 0; j < a[i].length; j++) {
@@ -10,6 +9,6 @@ class T {
}
}
}
return n;
return -1;
}
}
@@ -1,9 +1,8 @@
// "Move 'return' closer 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;
else return 0;
}
}
@@ -1,7 +1,6 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f() {
int n;
{
return 1;
}
@@ -1,12 +1,11 @@
// "Move 'return' closer 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;
return -1;
}
}
@@ -1,11 +1,10 @@
// "Move 'return' closer 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;
return -1;
}
}
@@ -1,11 +1,10 @@
// "Move 'return' closer 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;
return -1;
}
}
@@ -0,0 +1,10 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int k;
int foo() {
int n = k;
if (k < 0) return -1;
<caret>return n;
}
}
@@ -0,0 +1,9 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int foo(int k) {
int n = k;
if (n < 0)
return -1;
return n;
}
}
@@ -3,7 +3,6 @@ import java.io.*;
class T {
private static String getString() throws IOException {
String s;
try (BufferedReader r = open()) {
return r.readLine();
}
@@ -1,7 +1,6 @@
// "Move 'return' closer 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);
@@ -12,7 +11,7 @@ class T {
i = j + 1;
}
while (i >= 0);
return r;
return "";
}
boolean hasNext() {
@@ -1,12 +1,11 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(int[] a, int b) {
int n = -1;
for (int i = 0; i < a.length; i++) {
if (a[i] == b) {
return i;
}
}
return n;
return -1;
}
}
@@ -1,12 +1,11 @@
// "Move 'return' closer to computation of the value of 'r'" "true"
class T {
String f(String[] a) {
String r = "";
for (String s : a) {
if (s != null && s.contains("@")) {
return s + ":" + s.length();
}
}
return r;
return "";
}
}
@@ -1,8 +1,7 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(boolean b) {
int n = 0;
if (b) return 1;
return n;
return 0;
}
}
@@ -1,8 +1,7 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(boolean b, int d) {
int n = d;
if (b) return 1;
return n;
return d;
}
}
@@ -1,14 +1,13 @@
// "Move 'return' closer to computation of the value of 'r'" "true"
class T {
String f() {
String r = "";
while (hasNext()) {
String s = next();
if (s != null) {
return s;
}
}
return r;
return "";
}
boolean hasNext() {
@@ -1,13 +1,12 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(int a) {
int n = -1;
switch (a) {
case 1:
return 2;
case 2:
return 4;
}
return n;
return -1;
}
}
@@ -1,13 +1,12 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(int a) {
int n = -1;
switch (a) {
case 1:
return 2;
case 2:
return 4;
}
return n;
return -1;
}
}
@@ -1,7 +1,6 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(int a) {
int n = -1;
switch (a) {
case 1:
return 2;
@@ -1,7 +1,6 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(int a) {
int n = -1;
switch (a) {
case 1:
return 2;
@@ -11,6 +10,6 @@ class T {
return 0;
case 0:
}
return n;
return -1;
}
}
@@ -1,7 +1,6 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(int a) {
int n = -1;
switch (a) {
case 1:
return 2;
@@ -1,7 +1,6 @@
// "Move 'return' closer to computation of the value of 'r'" "true"
class T {
String f(String p) {
String r = null;
try {
while (true) {
String n = next();
@@ -1,11 +1,10 @@
// "Move 'return' closer 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 (n != null) return null;
if ("@".eqals(n)) {
String t = n.toLowerCase();
if (t.equals(p)) {
@@ -1,7 +1,6 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(int a) {
int n = -1;
int t = a;
while (t != null) {
if (t == 1) {
@@ -15,6 +14,6 @@ class T {
continue;
}
}
return n;
return -1;
}
}
@@ -1,7 +1,6 @@
// "Move 'return' closer to computation of the value of 'r'" "true"
class T {
long f() {
long r;
long s = System.currentTimeMillis();
long t = s;
while (true) {
@@ -0,0 +1,11 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
T f(int k) {
T n = this;
if (k == 1)
n = new T();
else if (k == 2)
n = null;
re<caret>turn n;
}
}
@@ -0,0 +1,11 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int f(int k) {
int n = -1;
if (k == 1)
n = 1;
else if (k == 2)
n = 2;
re<caret>turn n;
}
}
@@ -0,0 +1,16 @@
// "Move 'return' closer to computation of the value of 'r'" "true"
class T {
int foo(String s) {
int r = s.length();
if (s.isEmpty()) {
return r;
}
String t = s.substring(1);
if (!t.isEmpty()) {
r = t.length();
}
<caret>return r;
}
}
@@ -0,0 +1,11 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
final int k = 1;
int foo() {
int n = k;
if (k < 0)
n = -1;
<caret>return n;
}
}
@@ -0,0 +1,9 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int foo(int k) {
int n = k;
k++;
if (k < 0) n = -1;
<caret>return n;
}
}
@@ -0,0 +1,11 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
import java.util.*;
class T {
List foo(boolean b) {
List n = new ArrayList();
if (b)
n = null;
<caret>return n;
}
}
@@ -0,0 +1,13 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
import java.util.*;
class T {
List foo(int k) {
List n = new ArrayList();
if (k == 1)
n = new ArrayList(1);
if (k == 2)
n = new ArrayList(2);
<caret>return n;
}
}
@@ -0,0 +1,11 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
import java.util.*;
class T {
List foo(boolean b) {
List n = new ArrayList();
if (b)
n = new ArrayList(1);
<caret>return n;
}
}
@@ -0,0 +1,11 @@
// "Move 'return' closer to computation of the value of 'n'" "false"
class T {
int k;
int foo() {
int n = k;
if (k < 0)
return -1;
<caret>return n;
}
}
@@ -0,0 +1,9 @@
// "Move 'return' closer to computation of the value of 'n'" "true"
class T {
int foo(int k) {
int n = k;
if (n < 0)
n = -1;
<caret>return n;
}
}
@@ -5,9 +5,8 @@ class T {
}
void f(boolean b) {
g(() -> {
int n = -1;
if (b) return 1;
return n;
return -1;
});
}
@@ -4,8 +4,7 @@ import java.util.stream.Stream;
class T {
String[] f(String[] a) {
return Stream.of(a).map(s -> {
String r;
if (s.startsWith("#")) return s.substring(1);
if (s.startsWith("#")) return s.substring(1);
else if (s.startsWith("//")) return s.substring(2);
else return s;
}).toArray(String[]::new);
@@ -5,7 +5,6 @@ class T {
}
void f(boolean b) {
g(() -> {
int n = -1;
while (true) {
if (h()) {
return 1;