mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 14:25:04 +07:00
ExtractSetFromComparisonChainAction improvements (IDEA-CR-19606)
1. Fixed modifiers for interfaces
2. Replacement wrapped with Collections.unmodifiableSet
3. Supported Java 1.4 and lower
4. Supported Guava ImmutableSet
5. Supported comparisons like s.equals("xyz"), Objects.equals(s, "xyz")
This commit is contained in:
+2
-1
@@ -1,10 +1,11 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
// "Extract Set from comparison chain" "true"
|
||||
public class Test {
|
||||
private static final Set<String> NAMES = new HashSet<>(Arrays.asList("foo", "bar", "baz"));
|
||||
private static final Set<String> NAMES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("foo", "bar", "baz")));
|
||||
|
||||
void testOr(String name) {
|
||||
if(name == null || NAMES.contains(name)) {
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
// "Extract Set from comparison chain" "true"
|
||||
public class Test {
|
||||
private static final Set<String> NAMES = new HashSet<>(Arrays.asList("foo", "bar", "baz"));
|
||||
private static final Set<String> NAMES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("foo", "bar", "baz")));
|
||||
|
||||
interface Person {
|
||||
String getName();
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Extract Set from comparison chain" "true"
|
||||
|
||||
package com.google.common.collect;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
class ImmutableSet<T> {
|
||||
public static <T> ImmutableSet<T> of(T... elements) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class Test {
|
||||
private static final Set<String> S = com.google.common.collect.ImmutableSet.of("foo", "bar", "baz");
|
||||
|
||||
void testOr(String s) {
|
||||
if(S.contains(s)) {
|
||||
System.out.println("foobarbaz");
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
// "Extract Set from comparison chain" "true"
|
||||
public interface Test {
|
||||
Set<String> S = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("foo", "bar", "baz")));
|
||||
|
||||
default void testOr(String s) {
|
||||
if(S.contains(s)) {
|
||||
System.out.println("foobarbaz");
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
// "Extract Set from comparison chain" "true"
|
||||
public class Test {
|
||||
private static final Set S = Collections.unmodifiableSet(new HashSet(Arrays.asList(new String[]{"foo", "bar", "baz"})));
|
||||
|
||||
void testOr(String s) {
|
||||
if(S.contains(s)) {
|
||||
System.out.println("foobarbaz");
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1,11 +1,12 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
// "Extract Set from comparison chain" "true"
|
||||
public class Test {
|
||||
public static final String BAR = "bar";
|
||||
private static final Set<String> PROPERTIES = new HashSet<>(Arrays.asList("foo", BAR, "baz"));
|
||||
private static final Set<String> PROPERTIES = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("foo", BAR, "baz")));
|
||||
|
||||
void testOr(int i, String property) {
|
||||
int PROPERTIES;
|
||||
|
||||
+2
-1
@@ -1,10 +1,11 @@
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
// "Extract Set from comparison chain" "true"
|
||||
public class Test {
|
||||
private static final Set<String> S = new HashSet<>(Arrays.asList("foo", "bar", "baz"));
|
||||
private static final Set<String> S = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("foo", "bar", "baz")));
|
||||
|
||||
void testOr(String s) {
|
||||
if(S.contains(s)) {
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Extract Set from comparison chain" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Test {
|
||||
private static final Set<String> S = Collections.unmodifiableSet(new HashSet<>(Arrays.asList("foo", "bar", "baz", "quz")));
|
||||
|
||||
void testOr(String s) {
|
||||
if(Objects.equals(s, null) || S.contains(s)) {
|
||||
System.out.println("foobarbaz");
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Extract Set from comparison chain" "true"
|
||||
|
||||
package com.google.common.collect;
|
||||
|
||||
class ImmutableSet<T> {
|
||||
public static <T> ImmutableSet<T> of(T... elements) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public class Test {
|
||||
void testOr(String s) {
|
||||
if("foo"<caret>.equals(s) || "bar".equals(s) || "baz".equals(s)) {
|
||||
System.out.println("foobarbaz");
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Extract Set from comparison chain" "true"
|
||||
public interface Test {
|
||||
default void testOr(String s) {
|
||||
if("foo"<caret>.equals(s) || "bar".equals(s) || "baz".equals(s)) {
|
||||
System.out.println("foobarbaz");
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Extract Set from comparison chain" "true"
|
||||
public class Test {
|
||||
void testOr(String s) {
|
||||
if("foo"<caret>.equals(s) || "bar".equals(s) || "baz".equals(s)) {
|
||||
System.out.println("foobarbaz");
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Extract Set from comparison chain" "true"
|
||||
import java.util.Objects;
|
||||
|
||||
public class Test {
|
||||
void testOr(String s) {
|
||||
if(Objects.equals(s, null) || "foo"<caret>.equals(s) || s.equals("bar") || Objects.equals("baz", s) || Objects.equals(s, "quz")) {
|
||||
System.out.println("foobarbaz");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user