IDEA-169518 Convert "Move assignment to field declaration" to the inspection

This commit is contained in:
Tagir Valeev
2017-03-20 16:23:16 +07:00
parent c90b64b7e8
commit efdfa0a22c
23 changed files with 436 additions and 265 deletions

View File

@@ -1,4 +1,4 @@
// "Move assignment to field declaration" "true"
// "Move assignment to field declaration" "INFORMATION"
class X {
int f = 0;

View File

@@ -1,10 +1,12 @@
// "Move assignment to field declaration" "true"
// "Move assignment to field declaration" "GENERIC_ERROR_OR_WARNING"
class X {
static int f = 0;
static {
<caret>}
X(int i) {
/*
Set to zero
*/
static int f = 0;
X(int i) {
}
void x() {
int i = f;

View File

@@ -1,15 +1,16 @@
// "Move assignment to field declaration" "true"
class X {
Object f = new Runnable() {
void x(int p) {
int f = p;
}
// Create default runnable
Object f = new Runnable() {
void x(int p) {
int f = p;
}
public void run() {
public void run() {
}
};
}
};
X() {
<caret>//
}

View File

@@ -0,0 +1,23 @@
// "Move assignment to field declaration" "INFORMATION"
public class Test {
static LoggingSystem LOG = LoggingSystem.getLogger();
static {
LoggingSystem.init();
}
}
class LoggingSystem {
private static LoggingSystem L;
static LoggingSystem getLogger() {
return L;
}
static void init() {
if(L == null) {
L = new LoggingSystem();
}
}
}

View File

@@ -1,6 +1,4 @@
// "Move assignment to field declaration" "true"
public class X {
int i = 0;
{
}
}

View File

@@ -0,0 +1,12 @@
// "Move assignment to field declaration" "INFORMATION"
public class Test {
String myField = getValue();
private String value;
void f() {
}
public static String getValue() {
return value;
}
}

View File

@@ -1,4 +1,4 @@
// "Move assignment to field declaration" "true"
// "Move assignment to field declaration" "INFORMATION"
class X {
int f;

View File

@@ -1,9 +1,12 @@
// "Move assignment to field declaration" "true"
// "Move assignment to field declaration" "GENERIC_ERROR_OR_WARNING"
class X {
static int f;
static {
f = <caret>0;
/*
Set to zero
*/
<caret>f = 0;
}
X(int i) {
}

View File

@@ -3,6 +3,7 @@
class X {
Object f;
X() {
// Create default runnable
<caret>f = new Runnable() {
void x(int p) {
int f = p;

View File

@@ -0,0 +1,24 @@
// "Move assignment to field declaration" "INFORMATION"
public class Test {
static LoggingSystem LOG;
static {
LoggingSystem.init();
<caret>LOG = LoggingSystem.getLogger();
}
}
class LoggingSystem {
private static LoggingSystem L;
static LoggingSystem getLogger() {
return L;
}
static void init() {
if(L == null) {
L = new LoggingSystem();
}
}
}

View File

@@ -0,0 +1,13 @@
// "Move assignment to field declaration" "false"
public class Test {
String myField;
private String value;
void f() {
<caret>myField = getValue();
}
public String getValue() {
return value;
}
}

View File

@@ -2,6 +2,6 @@
public class X {
int i;
{
(i)=<caret>0;
(<caret>i)=0;
}
}

View File

@@ -0,0 +1,8 @@
// "Move assignment to field declaration" "false"
public class Test {
final static String FIELD;
static {
String data = " foo ";
<caret>FIELD = data.trim();
}
}

View File

@@ -0,0 +1,13 @@
// "Move assignment to field declaration" "INFORMATION"
public class Test {
String myField;
private String value;
void f() {
<caret>myField = getValue();
}
public static String getValue() {
return value;
}
}