mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Java control flow: Improved "Move return to computation" inspection, added more tests (IDEA-121153)
This commit is contained in:
-12
@@ -1,12 +0,0 @@
|
||||
class T {
|
||||
int f(int[] a, int b) {
|
||||
int n = -1;
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
if (a[i] == b) {
|
||||
n = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
<warning descr="Return separated from computation of value of 'n'">return n;</warning>
|
||||
}
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = 0;
|
||||
if (b) n = 1;
|
||||
<warning descr="Return separated from computation of value of 'n'">return n;</warning>
|
||||
}
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
class T {
|
||||
String f() {
|
||||
String r = "";
|
||||
while (hasNext()) {
|
||||
String s = next();
|
||||
if (s != null) {
|
||||
r = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
<warning descr="Return separated from computation of value of 'r'">return r;</warning>
|
||||
}
|
||||
|
||||
boolean hasNext() {
|
||||
return true;
|
||||
}
|
||||
|
||||
String next() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = -1;
|
||||
if (b) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,6 +4,6 @@ class T {
|
||||
int n = 0;
|
||||
if (b) System.out.println("yes");
|
||||
else return 2;
|
||||
return n;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,6 +4,6 @@ class T {
|
||||
int n = 0;
|
||||
if (b) return 1;
|
||||
else System.out.println("no");
|
||||
return n;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = -1;
|
||||
if (b) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
else {
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b, boolean c) {
|
||||
int n = -1;
|
||||
if (b) {
|
||||
try {
|
||||
return g();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
d(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 2;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
int g() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void d(Exception e) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Move 'return' 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 -1;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = 0;
|
||||
if (b) return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = g();
|
||||
if (b) return 1;
|
||||
return n;
|
||||
}
|
||||
int g() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b, int d) {
|
||||
int n = d;
|
||||
if (b) return 1;
|
||||
return d;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Move 'return' 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 "";
|
||||
}
|
||||
|
||||
boolean hasNext() {
|
||||
return true;
|
||||
}
|
||||
|
||||
String next() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = -1;
|
||||
if (b) {
|
||||
n = 1;
|
||||
}
|
||||
else {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
r<caret>eturn n;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "false"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = -1;
|
||||
if (b) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
r<caret>eturn n;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = -1;
|
||||
if (b) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
else {
|
||||
n = 2;
|
||||
}
|
||||
r<caret>eturn n;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b, boolean c) {
|
||||
int n = -1;
|
||||
if (b) {
|
||||
try {
|
||||
n = g();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
d(e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
n = 2;
|
||||
}
|
||||
r<caret>eturn n;
|
||||
}
|
||||
|
||||
int g() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void d(Exception e) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Move 'return' 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) {
|
||||
n = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
r<caret>eturn n;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = 0;
|
||||
if (b) n = 1;
|
||||
re<caret>turn n;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = g();
|
||||
if (b) n = 1;
|
||||
re<caret>turn n;
|
||||
}
|
||||
int g() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b, int d) {
|
||||
int n = d;
|
||||
if (b) n = 1;
|
||||
re<caret>turn n;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// "Move 'return' to computation of the value of 'r'" "true"
|
||||
class T {
|
||||
String f() {
|
||||
String r = "";
|
||||
while (hasNext()) {
|
||||
String s = next();
|
||||
if (s != null) {
|
||||
r = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
re<caret>turn r;
|
||||
}
|
||||
|
||||
boolean hasNext() {
|
||||
return true;
|
||||
}
|
||||
|
||||
String next() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user