mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
lambda -> method ref: reuse comment tracker (IDEA-189934)
This commit is contained in:
@@ -5,6 +5,8 @@ class Example {
|
||||
|
||||
{
|
||||
//my comments here
|
||||
//1
|
||||
//2
|
||||
Runnable r = this::m
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,10 @@ class Example {
|
||||
{
|
||||
Runnable r = () -> {
|
||||
//my comments here
|
||||
m<caret>();
|
||||
m<caret>()
|
||||
//1
|
||||
//2
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public void test(List<Set<String>> nested) {
|
||||
/*non-equal*//*empty*/
|
||||
/*non-equal*/
|
||||
/*empty*/
|
||||
List<String> result = nested.stream().filter(Objects::nonNull).flatMap(Collection::stream).filter(str -> str./*startswith*/startsWith("xyz")).map(String::trim).collect(Collectors.toList());
|
||||
// 1
|
||||
/*target is here*/
|
||||
|
||||
@@ -34,7 +34,8 @@ class Scratch {
|
||||
}
|
||||
|
||||
void testDecl(Map<String, String> map) {
|
||||
/*5*//*6*/
|
||||
/*5*/
|
||||
/*6*/
|
||||
String res = map.values(/*0*/).stream().filter(val1 -> {
|
||||
/*1*/
|
||||
return !val1./*2*/isEmpty();
|
||||
|
||||
@@ -18,7 +18,7 @@ import com.intellij.psi.util.*;
|
||||
import com.intellij.refactoring.util.RefactoringChangeUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.siyeh.ig.psiutils.CommentTracker;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -628,16 +628,13 @@ public class LambdaCanBeMethodReferenceInspection extends AbstractBaseJavaLocalI
|
||||
final PsiType denotableFunctionalInterfaceType = RefactoringChangeUtil.getTypeByExpression(lambda);
|
||||
if (denotableFunctionalInterfaceType == null) return lambda;
|
||||
|
||||
Collection<PsiComment> comments = ContainerUtil.map(PsiTreeUtil.findChildrenOfType(lambda, PsiComment.class),
|
||||
(comment) -> (PsiComment)comment.copy());
|
||||
|
||||
final String methodRefText = createMethodReferenceText(body, functionalInterfaceType, lambda.getParameterList().getParameters());
|
||||
|
||||
if (methodRefText != null) {
|
||||
final PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
|
||||
final PsiExpression psiExpression = factory.createExpressionFromText(methodRefText, lambda);
|
||||
final SmartTypePointer typePointer = SmartTypePointerManager.getInstance(project).createSmartTypePointer(denotableFunctionalInterfaceType);
|
||||
PsiExpression replace = (PsiExpression)lambda.replace(psiExpression);
|
||||
PsiExpression replace = (PsiExpression)new CommentTracker().replaceAndRestoreComments(lambda, psiExpression);
|
||||
final PsiType functionalTypeAfterReplacement = GenericsUtil.getVariableTypeByExpressionType(((PsiMethodReferenceExpression)replace).getFunctionalInterfaceType());
|
||||
functionalInterfaceType = typePointer.getType();
|
||||
if (functionalInterfaceType != null && (functionalTypeAfterReplacement == null ||
|
||||
@@ -652,7 +649,6 @@ public class LambdaCanBeMethodReferenceInspection extends AbstractBaseJavaLocalI
|
||||
replace = (PsiExpression)replace.replace(cast);
|
||||
}
|
||||
|
||||
AnonymousCanBeLambdaInspection.restoreComments(comments, replace);
|
||||
JavaCodeStyleManager.getInstance(project).shortenClassReferences(replace);
|
||||
return replace;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user