preserve comments: anonym -> for comments inside parent new expression

This commit is contained in:
Anna.Kozlova
2017-11-24 18:41:43 +01:00
parent 8b287c2f4b
commit 679013c7ae
3 changed files with 6 additions and 4 deletions
@@ -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());
@@ -1,6 +1,7 @@
// "Replace with lambda" "true"
class Test {
//my comment
//comment inside new expression
//my comment
Runnable r = () -> {};
}
@@ -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 () {}
};