IDEA-162190 Inspection to convert anonymous ThreadLocal subclass to ThreadLocal.withInitial

This commit is contained in:
Tagir Valeev
2016-10-10 15:21:24 +07:00
parent 8ea44292ca
commit c844054768
13 changed files with 399 additions and 83 deletions
@@ -0,0 +1,11 @@
// "Replace anonymous class with constructor accepting lambda" "true"
public class Main {
public void testThread() {
// Comment outside
// Ending comment
new Thread(() -> {
// Comment inside
System.out.println("Hello from thread!");
}).start();
}
}
@@ -0,0 +1,5 @@
// "Replace anonymous class with ThreadLocal.withInitial" "true"
public class Main {
// comment
ThreadLocal<? extends CharSequence> tlr = ThreadLocal.withInitial(() -> "initial");
}
@@ -0,0 +1,14 @@
// "Replace anonymous class with constructor accepting lambda" "true"
public class Main {
public void testThread() {
new <caret>Thread() {
// Comment outside
@Override
public void run() {
// Comment inside
System.out.println("Hello from thread!");
}
// Ending comment
}.start();
}
}
@@ -0,0 +1,18 @@
// "Replace anonymous class with constructor accepting lambda" "false"
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
public class Main {
@Retention(RetentionPolicy.RUNTIME)
@interface Anno{}
public void testThread() {
new <caret>Thread() {
@Override
@Anno
public void run() {
System.out.println("Hello from thread! "+x);
}
}.start();
}
}
@@ -0,0 +1,13 @@
// "Replace anonymous class with constructor accepting lambda" "false"
public class Main {
public void testThread() {
new <caret>Thread() {
int x = 5;
@Override
public void run() {
System.out.println("Hello from thread! "+x);
}
}.start();
}
}
@@ -0,0 +1,10 @@
// "Replace anonymous class with ThreadLocal.withInitial" "true"
public class Main {
ThreadLocal<? extends CharSequence> tlr = new Th<caret>readLocal<String>() {
// comment
@Override
protected String initialValue() {
return "initial";
}
};
}
@@ -0,0 +1,12 @@
// "Replace anonymous class with constructor accepting lambda" "false"
public class Main {
public void testThread() {
new <caret>Thread() {
@Override
public void run() {
System.out.println("Hello from thread!");
super.run();
}
}.start();
}
}
@@ -0,0 +1,11 @@
// "Replace anonymous class with constructor accepting lambda" "false"
public class Main {
public void testThread() {
new <caret>Thread() {
@Override
public void start() {
System.out.println("Hello from thread!");
}
}.start();
}
}