mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
preserve comments: anonym -> for comments inside parent new expression
This commit is contained in:
+2
-2
@@ -271,7 +271,7 @@ public class AnonymousCanBeLambdaInspection extends AbstractBaseJavaLocalInspect
|
||||
final PsiCodeBlock body = method.getBody();
|
||||
LOG.assertTrue(body != null);
|
||||
|
||||
final Collection<PsiComment> comments = collectCommentsOutsideMethodBody(anonymousClass, body);
|
||||
final Collection<PsiComment> comments = collectCommentsOutsideMethodBody(anonymousClass.getParent(), body);
|
||||
final Project project = anonymousClass.getProject();
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
|
||||
|
||||
@@ -326,7 +326,7 @@ public class AnonymousCanBeLambdaInspection extends AbstractBaseJavaLocalInspect
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static Collection<PsiComment> collectCommentsOutsideMethodBody(PsiAnonymousClass anonymousClass, PsiCodeBlock body) {
|
||||
static Collection<PsiComment> collectCommentsOutsideMethodBody(PsiElement anonymousClass, PsiCodeBlock body) {
|
||||
final Collection<PsiComment> psiComments = PsiTreeUtil.findChildrenOfType(anonymousClass, PsiComment.class);
|
||||
psiComments.removeIf(comment -> PsiTreeUtil.isAncestor(body, comment, false));
|
||||
return ContainerUtil.map(psiComments, (comment) -> (PsiComment)comment.copy());
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
// "Replace with lambda" "true"
|
||||
|
||||
class Test {
|
||||
//my comment
|
||||
//comment inside new expression
|
||||
//my comment
|
||||
Runnable r = () -> {};
|
||||
}
|
||||
+2
-1
@@ -1,7 +1,8 @@
|
||||
// "Replace with lambda" "true"
|
||||
|
||||
class Test {
|
||||
Runnable r = new Ru<caret>nnable() {
|
||||
Runnable r = new //comment inside new expression
|
||||
Ru<caret>nnable() {
|
||||
//my comment
|
||||
public void run () {}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user