mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
guava type migration: convert variables like Optional o = FluentIterable.from().firstMatch();
This commit is contained in:
+2
-1
@@ -128,7 +128,8 @@ public class GuavaInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
final PsiElement maybeLocalVariable = chain.getParent();
|
||||
if (maybeLocalVariable instanceof PsiLocalVariable) {
|
||||
final PsiClass aClass = PsiUtil.resolveClassInType(chain.getType());
|
||||
if (aClass != null && GuavaFluentIterableConversionRule.FLUENT_ITERABLE.equals(aClass.getQualifiedName())) {
|
||||
if (aClass != null && (GuavaFluentIterableConversionRule.FLUENT_ITERABLE.equals(aClass.getQualifiedName()) ||
|
||||
GuavaOptionalConversionRule.GUAVA_OPTIONAL.equals(aClass.getQualifiedName()))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -185,7 +185,7 @@ public class GuavaFluentIterableConversionRule extends BaseGuavaTypeConversionRu
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static GuavaChainedConversionDescriptor buildCompoundDescriptor(PsiMethodCallExpression expression,
|
||||
public static GuavaChainedConversionDescriptor buildCompoundDescriptor(PsiMethodCallExpression expression,
|
||||
PsiType to,
|
||||
TypeMigrationLabeler labeler) {
|
||||
List<TypeConversionDescriptorBase> methodDescriptors = new SmartList<TypeConversionDescriptorBase>();
|
||||
|
||||
+8
-1
@@ -78,7 +78,14 @@ public class GuavaOptionalConversionRule extends BaseGuavaTypeConversionRule {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
if (!(context instanceof PsiMethodCallExpression)) {
|
||||
return null;
|
||||
}
|
||||
final PsiClass aClass = method.getContainingClass();
|
||||
if (aClass == null || !GuavaFluentIterableConversionRule.FLUENT_ITERABLE.equals(aClass.getQualifiedName())) {
|
||||
return null;
|
||||
}
|
||||
return GuavaFluentIterableConversionRule.buildCompoundDescriptor((PsiMethodCallExpression) context, to, labeler);
|
||||
}
|
||||
|
||||
private PsiClass getParameterClass(PsiMethod method) {
|
||||
|
||||
@@ -57,6 +57,10 @@ public class GuavaInspectionTest extends JavaCodeInsightFixtureTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testOptional3() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSimpleFluentIterable() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.FluentIterable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Main7 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Optional<? extends String> image = FluentIterable.fr<caret>om(new ArrayList<String>()).firstMatch(getPredicate());
|
||||
if (image.isPresent()) {
|
||||
System.out.println(image.get());
|
||||
}
|
||||
}
|
||||
|
||||
static Predicate<String> getPredicate() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Main7 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Optional<? extends String> image = new ArrayList<String>().stream().filter(getPredicate()::apply).findFirst();
|
||||
if (image.isPresent()) {
|
||||
System.out.println(image.get());
|
||||
}
|
||||
}
|
||||
|
||||
static Predicate<String> getPredicate() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user