mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
guava type migration: added test for complex structure
This commit is contained in:
+1
-2
@@ -92,13 +92,12 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
|
||||
DESCRIPTORS_MAP.put("isEmpty", new TypeConversionDescriptorFactory("$q$.isEmpty()", "$q$.findAny().isPresent()", false));
|
||||
DESCRIPTORS_MAP.put("skip", new TypeConversionDescriptorFactory("$q$.skip($p$)", "$q$.skip($p$)", false, true, true));
|
||||
DESCRIPTORS_MAP.put("limit", new TypeConversionDescriptorFactory("$q$.limit($p$)", "$q$.limit($p$)", false, true, true));
|
||||
DESCRIPTORS_MAP.put("first", new TypeConversionDescriptorFactory("$q$.first()", "$q$.findFirst()", false));
|
||||
DESCRIPTORS_MAP.put("first", new TypeConversionDescriptorFactory("$q$.first()", "$q$.findFirst()", false, true, false));
|
||||
DESCRIPTORS_MAP.put("transform", new TypeConversionDescriptorFactory("$q$.transform($params$)", "$q$.map($params$)", true, true, true));
|
||||
|
||||
DESCRIPTORS_MAP.put("allMatch", new TypeConversionDescriptorFactory("$it$.allMatch($c$)", "$it$." + StreamApiConstants.ALL_MATCH + "($c$)", true));
|
||||
DESCRIPTORS_MAP.put("anyMatch", new TypeConversionDescriptorFactory("$it$.anyMatch($c$)", "$it$." + StreamApiConstants.ANY_MATCH + "($c$)", true));
|
||||
|
||||
DESCRIPTORS_MAP.put("first", new TypeConversionDescriptorFactory("$it$.first()", "$it$." + StreamApiConstants.FIND_FIRST + "()", false));
|
||||
DESCRIPTORS_MAP.put("firstMatch", new TypeConversionDescriptorFactory("$it$.firstMatch($p$)", "$it$.filter($p$).findFirst()", true, true, false));
|
||||
DESCRIPTORS_MAP.put("size", new TypeConversionDescriptorFactory("$it$.size()", "(int) $it$.count()", false));
|
||||
|
||||
|
||||
@@ -162,6 +162,14 @@ public class GuavaInspectionTest extends JavaCodeInsightFixtureTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFluentIterableMigrationInInheritance() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFluentIterableAndOptional() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTestNoQuickFixes(final Class<? extends IntentionAction>... quickFixesClasses) {
|
||||
myFixture.configureByFile(getTestName(true) + ".java");
|
||||
myFixture.enableInspections(new GuavaInspection());
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Main18 {
|
||||
|
||||
class A {
|
||||
private String i = "12";
|
||||
|
||||
Optional<String> getOpt() {
|
||||
return Optional.fromNullable(i);
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
FluentIt<caret>erable<String> getFIterable() {
|
||||
return FluentIterable.from(new ArrayList<String>()).filter(String.class);
|
||||
}
|
||||
}
|
||||
|
||||
void m(A a, B b) {
|
||||
String sss = b.getFIterable().transform(s -> s).first().or(a.getOpt()).get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main18 {
|
||||
|
||||
class A {
|
||||
private String i = "12";
|
||||
|
||||
Optional<String> getOpt() {
|
||||
return Optional.fromNullable(i);
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
Stream<String> getFIterable() {
|
||||
return new ArrayList<String>().stream().filter(String.class::isInstance);
|
||||
}
|
||||
}
|
||||
|
||||
void m(A a, B b) {
|
||||
String sss = java.util.Optional.ofNullable(b.getFIterable().map(s -> s).findFirst().orElseGet(a.getOpt()::get)).get();
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Main17 {
|
||||
|
||||
interface A {
|
||||
FluentIterable<String> getIterable();
|
||||
}
|
||||
|
||||
class B implements A {
|
||||
@Override
|
||||
public FluentIter<caret>able<String> getIterable() {
|
||||
return FluentIterable.from(new ArrayList<String>()).transform(new Function<String, String>() {
|
||||
@Override
|
||||
public String apply(String s) {
|
||||
return s.intern();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static void m(A a) {
|
||||
int s = a.getIterable().transform(s1 -> s1).size();
|
||||
}
|
||||
|
||||
static void m2(B b) {
|
||||
int s = b.getIterable().size();
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class Main17 {
|
||||
|
||||
interface A {
|
||||
Stream<String> getIterable();
|
||||
}
|
||||
|
||||
class B implements A {
|
||||
@Override
|
||||
public Stream<String> getIterable() {
|
||||
return new ArrayList<String>().stream().map(s -> s.intern());
|
||||
}
|
||||
}
|
||||
|
||||
static void m(A a) {
|
||||
int s = (int) a.getIterable().map(s1 -> s1).count();
|
||||
}
|
||||
|
||||
static void m2(B b) {
|
||||
int s = (int) b.getIterable().count();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user