mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
preserve comments when transform expr lambda to code block (IDEA-179643)
This commit is contained in:
@@ -889,16 +889,13 @@ public class RefactoringUtil {
|
||||
final PsiElement invalidBody = lambdaExpression.getBody();
|
||||
if (invalidBody == null) return declaration;
|
||||
|
||||
final PsiLambdaExpression expressionFromText = (PsiLambdaExpression)elementFactory
|
||||
.createExpressionFromText(lambdaExpression.getParameterList().getText() + " -> {}", lambdaExpression.getParent());
|
||||
String lambdaParamListWithArrowAndComments = lambdaExpression.getText()
|
||||
.substring(0, (declaration.isPhysical() ? declaration : invalidBody).getStartOffsetInParent());
|
||||
final PsiLambdaExpression expressionFromText = (PsiLambdaExpression)elementFactory.createExpressionFromText(lambdaParamListWithArrowAndComments + "{}", lambdaExpression.getParent());
|
||||
PsiCodeBlock newBody = (PsiCodeBlock)expressionFromText.getBody();
|
||||
LOG.assertTrue(newBody != null);
|
||||
newBody.add(declaration);
|
||||
|
||||
lambdaExpression =
|
||||
(PsiLambdaExpression)lambdaExpression.replace(elementFactory.createExpressionFromText(
|
||||
lambdaExpression.getParameterList().getText() + " -> " + invalidBody.getText(), lambdaExpression));
|
||||
|
||||
final PsiElement lambdaExpressionBody = lambdaExpression.getBody();
|
||||
LOG.assertTrue(lambdaExpressionBody != null);
|
||||
final PsiStatement lastBodyStatement;
|
||||
|
||||
+2
-1
@@ -8,7 +8,8 @@ class X {
|
||||
public void foo(Class<?> cls)
|
||||
{
|
||||
Stream.of(cls.getMethods())
|
||||
.filter(method -> {
|
||||
.filter(method ->//my comment to keep
|
||||
{
|
||||
Class<?> c = method.getReturnType();
|
||||
return Collection.class.isAssignableFrom(c) || Map.class.isAssignableFrom(c);
|
||||
})
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ class X {
|
||||
public void foo(Class<?> cls)
|
||||
{
|
||||
Stream.of(cls.getMethods())
|
||||
.filter(method ->
|
||||
.filter(method ->//my comment to keep
|
||||
Collection.class.isAssignableFrom(<selection>method.getReturnType()</selection>) || Map.class.isAssignableFrom(method.getReturnType()))
|
||||
.collect(Collectors.<Method>toList());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user