mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
functional expression can be folded quick fix should work in case of statement lambda
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
// "Replace with qualifier" "true"
|
||||
import java.util.function.Function;
|
||||
|
||||
class Test {
|
||||
void foo(Function<String, String> function) {
|
||||
Function<String, String> another = function;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// "Replace with qualifier" "true"
|
||||
import java.util.function.Consumer;
|
||||
|
||||
class Test {
|
||||
void foo(Consumer<String> consumer) {
|
||||
Consumer<String> another = consumer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Replace with qualifier" "true"
|
||||
import java.util.function.Function;
|
||||
|
||||
class Test {
|
||||
void foo(Function<String, String> function) {
|
||||
Function<String, String> another = s -> {
|
||||
return function.ap<caret>ply(s);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Replace with qualifier" "true"
|
||||
import java.util.function.Consumer;
|
||||
|
||||
class Test {
|
||||
void foo(Consumer<String> consumer) {
|
||||
Consumer<String> another = s -> {
|
||||
consumer.acce<caret>pt(s);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ package com.intellij.codeInspection;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.MethodSignatureUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -72,14 +73,17 @@ public class FunctionalExpressionCanBeFoldedInspection extends AbstractBaseJavaL
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
PsiElement element = descriptor.getPsiElement();
|
||||
final PsiElement parent = element != null ? element.getParent() : null;
|
||||
PsiElement parent = element != null ? element.getParent() : null;
|
||||
if (parent instanceof PsiMethodReferenceExpression) {
|
||||
final PsiExpression qualifierExpression = ((PsiMethodReferenceExpression)parent).getQualifierExpression();
|
||||
if (qualifierExpression != null) {
|
||||
parent.replace(qualifierExpression);
|
||||
}
|
||||
}
|
||||
else if (parent instanceof PsiLambdaExpression) {
|
||||
if (parent instanceof PsiReturnStatement || parent instanceof PsiExpressionStatement) {
|
||||
parent = PsiTreeUtil.getParentOfType(parent, PsiLambdaExpression.class);
|
||||
}
|
||||
if (parent instanceof PsiLambdaExpression) {
|
||||
PsiExpression expression = LambdaUtil.extractSingleExpressionFromBody(((PsiLambdaExpression)parent).getBody());
|
||||
if (expression instanceof PsiMethodCallExpression) {
|
||||
PsiExpression qualifierExpression = ((PsiMethodCallExpression)expression).getMethodExpression().getQualifierExpression();
|
||||
|
||||
Reference in New Issue
Block a user