mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEABKL-4394 Automatically remove redundant result variable when inlining the method
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
class A {
|
||||
{
|
||||
int result;
|
||||
try {
|
||||
result = 0;
|
||||
} catch (Error e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
+3
-2
@@ -19,8 +19,9 @@ class Main {
|
||||
|
||||
public final void doSomething(Object obj) {
|
||||
try {
|
||||
Object result;
|
||||
result = null == null ? fooBar() : null;
|
||||
if (null == null) {
|
||||
fooBar();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -4,12 +4,11 @@ public class NotRaw<T> {
|
||||
|
||||
class Raw extends NotRaw {
|
||||
void foo() {
|
||||
Object result;
|
||||
Object o;
|
||||
Object tt = null;
|
||||
if ( null == null) {
|
||||
result = null;
|
||||
o = null;
|
||||
} else
|
||||
result = null;
|
||||
Object o = result;
|
||||
o = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import java.util.*;
|
||||
|
||||
class Test {
|
||||
void useTest() {
|
||||
String color = <caret>makeColor(Math.random() > 0.5);
|
||||
System.out.println("Color is " + color);
|
||||
}
|
||||
|
||||
private String makeColor(boolean b) {
|
||||
if (b) {
|
||||
return "Foo";
|
||||
} else {
|
||||
return "Fie";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class Test {
|
||||
void useTest() {
|
||||
String color;
|
||||
if (Math.random() > 0.5) {
|
||||
color = "Foo";
|
||||
} else {
|
||||
color = "Fie";
|
||||
}
|
||||
System.out.println("Color is " + color);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,7 @@ class Tester {
|
||||
}
|
||||
|
||||
void caller(String v) {
|
||||
String g = <caret>callee(v);
|
||||
final String g = <caret>callee(v);
|
||||
System.out.println(g);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
class Tester {
|
||||
|
||||
void caller(String v) {
|
||||
String result = null;
|
||||
String g = null;
|
||||
if (v != null) {
|
||||
result = v;
|
||||
g = v;
|
||||
}
|
||||
String g = result;
|
||||
System.out.println(g);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
class Tester {
|
||||
// IDEA-37432
|
||||
String callee(String x) {
|
||||
if (x == null) {
|
||||
return null;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
void caller(String v) {
|
||||
String g = <caret>callee(v);
|
||||
Runnable r = () -> System.out.println(g);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Tester {
|
||||
|
||||
void caller(String v) {
|
||||
String result = null;
|
||||
if (v != null) {
|
||||
result = v;
|
||||
}
|
||||
String g = result;
|
||||
Runnable r = () -> System.out.println(g);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user