mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 07:40:42 +07:00
Java inspections: Created "Move return to computation" inspection, added a few tests (IDEA-121153)
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
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>
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
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>
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
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>
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class T {
|
||||
int f() {
|
||||
int n;
|
||||
{
|
||||
n = 1;
|
||||
}
|
||||
<warning descr="Return separated from computation of value of 'n'">return n;</warning>
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class T {
|
||||
int f() {
|
||||
int n;
|
||||
{
|
||||
n = 1;
|
||||
System.out.println();
|
||||
}
|
||||
<warning descr="Return separated from computation of value of 'n'">return n;</warning>
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class T {
|
||||
int f(boolean a, boolean b) {
|
||||
int n = -1;
|
||||
if (a) {
|
||||
if (b) {
|
||||
n = 1;
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class T {
|
||||
int f(boolean a, boolean b) {
|
||||
int n = -1;
|
||||
if (a) {
|
||||
if (b) n = 1;
|
||||
else n = 2;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class T {
|
||||
int f(boolean a, boolean b) {
|
||||
int n = -1;
|
||||
if (a) {
|
||||
if (b) n = 1;
|
||||
}
|
||||
else n = 2;
|
||||
return n;
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
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>
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
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>
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
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
@@ -0,0 +1,21 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// "Move 'return' to computation of the value of 's'" "true"
|
||||
import java.io.*;
|
||||
|
||||
class T {
|
||||
private static String getString() throws IOException {
|
||||
String s;
|
||||
try (BufferedReader reader = open()) {
|
||||
while (true) {
|
||||
s = reader.readLine();
|
||||
if (s == null || s.startsWith("$")) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private static BufferedReader open() throws FileNotFoundException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Move 'return' to computation of the value of 'r'" "true"
|
||||
class T {
|
||||
String f() {
|
||||
String r = "";
|
||||
do {
|
||||
if (!hasNext()) return r;
|
||||
String s = next();
|
||||
if (s != null) {
|
||||
return s;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
boolean hasNext() {
|
||||
return true;
|
||||
}
|
||||
|
||||
String next() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Move 'return' 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+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;
|
||||
else return 2;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Move 'return' 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;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Move 'return' 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;
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n;
|
||||
myLabel:
|
||||
{
|
||||
n = 1;
|
||||
if (b) return n;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Move 'return' to computation of the value of 'r'" "true"
|
||||
class T {
|
||||
long f() {
|
||||
long r;
|
||||
long s = System.currentTimeMillis();
|
||||
long t = s;
|
||||
while (true) {
|
||||
t = System.currentTimeMillis();
|
||||
if (t - s > 100) {
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "false"
|
||||
class T {
|
||||
int f(int a) {
|
||||
int n = a;
|
||||
assert n != 0;
|
||||
r<caret>eturn n;
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// "Move 'return' to computation of the value of 's'" "true"
|
||||
import java.io.*;
|
||||
|
||||
class T {
|
||||
private static String getString() throws IOException {
|
||||
String s;
|
||||
try (BufferedReader reader = open()) {
|
||||
while (true) {
|
||||
s = reader.readLine();
|
||||
if (s == null || s.startsWith("$")) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
r<caret>eturn s;
|
||||
}
|
||||
private static BufferedReader open() throws FileNotFoundException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// "Move 'return' to computation of the value of 'r'" "true"
|
||||
class T {
|
||||
String f() {
|
||||
String r = "";
|
||||
do {
|
||||
if (!hasNext()) break;
|
||||
String s = next();
|
||||
if (s != null) {
|
||||
r = s;
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
<caret>return r;
|
||||
}
|
||||
|
||||
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() {
|
||||
int n = -1;
|
||||
for(int i=0;; i++) {
|
||||
if (i % 127 == 0 && i % 129 == 0) {
|
||||
n = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
r<caret>eturn n;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "false"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = 0;
|
||||
if (b) System.out.println("yes");
|
||||
else System.out.println("no");
|
||||
ret<caret>urn n;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = 0;
|
||||
if (b) n = 1;
|
||||
else n = 2;
|
||||
r<caret>eturn n;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = 0;
|
||||
if (b) System.out.println("yes");
|
||||
else n = 2;
|
||||
r<caret>eturn n;
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n = 0;
|
||||
if (b) n = 1;
|
||||
else System.out.println("no");
|
||||
ret<caret>urn n;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Move 'return' to computation of the value of 'n'" "true"
|
||||
class T {
|
||||
int f(boolean b) {
|
||||
int n;
|
||||
myLabel:
|
||||
{
|
||||
n = 1;
|
||||
if (b) break myLabel;
|
||||
n = 2;
|
||||
}
|
||||
ret<caret>urn n;
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// "Move 'return' to computation of the value of 'r'" "true"
|
||||
class T {
|
||||
long f() {
|
||||
long r;
|
||||
long s = System.currentTimeMillis();
|
||||
long t = s;
|
||||
while (true) {
|
||||
t = System.currentTimeMillis();
|
||||
if (t - s > 100) {
|
||||
r = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
retu<caret>rn r;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user