From 81cad6fdb3c39dba50b59556503fadb21b03dd90 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" <anna.kozlova@jetbrains.com> Date: Mon, 8 Jan 2018 12:45:34 +0100 Subject: [PATCH] preserve comments: temp skip comments in imports --- .../intellij/java/propertyBased/JavaIntentionPolicy.java | 8 ++++++++ .../testFramework/propertyBased/IntentionPolicy.java | 5 +++++ .../testFramework/propertyBased/InvokeIntention.java | 5 +++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaIntentionPolicy.java b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaIntentionPolicy.java index 7b1d36907f0d..c895016a3150 100644 --- a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaIntentionPolicy.java +++ b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaIntentionPolicy.java @@ -18,7 +18,10 @@ package com.intellij.java.propertyBased; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; import com.intellij.psi.JavaPsiFacade; +import com.intellij.psi.PsiComment; import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiImportList; +import com.intellij.psi.util.PsiTreeUtil; import com.intellij.testFramework.propertyBased.IntentionPolicy; import org.jetbrains.annotations.NotNull; @@ -91,6 +94,11 @@ class JavaCommentingStrategy extends JavaIntentionPolicy { return !commentChangingActions; } + @Override + public boolean trackComment(PsiComment comment) { + return PsiTreeUtil.getParentOfType(comment, PsiImportList.class) == null; + } + @Override public boolean mayBreakCode(@NotNull IntentionAction action, @NotNull Editor editor, @NotNull PsiFile file) { return true; diff --git a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/IntentionPolicy.java b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/IntentionPolicy.java index 7b357cb9d918..0f0b82fdf33b 100644 --- a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/IntentionPolicy.java +++ b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/IntentionPolicy.java @@ -17,6 +17,7 @@ package com.intellij.testFramework.propertyBased; import com.intellij.codeInsight.intention.IntentionAction; import com.intellij.openapi.editor.Editor; +import com.intellij.psi.PsiComment; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NotNull; @@ -57,4 +58,8 @@ public class IntentionPolicy { public boolean checkComments(IntentionAction intention) { return false; } + + public boolean trackComment(PsiComment comment) { + return true; + } } diff --git a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/InvokeIntention.java b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/InvokeIntention.java index c42876d2323a..52687905484f 100644 --- a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/InvokeIntention.java +++ b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/InvokeIntention.java @@ -34,9 +34,9 @@ import com.intellij.psi.util.PsiUtilBase; import com.intellij.testFramework.PsiTestUtil; import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; import com.intellij.util.containers.ContainerUtil; -import org.jetbrains.jetCheck.Generator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jetCheck.Generator; import java.util.Collection; import java.util.Collections; @@ -144,7 +144,8 @@ public class InvokeIntention extends ActionOnRange { protected List<String> extractCommentsReformattedToSingleWhitespace(PsiFile file) { return PsiTreeUtil.findChildrenOfType(file, PsiComment.class) - .stream().map(comment -> comment.getText().replaceAll("[\\s*]+", " ")).collect(Collectors.toList()); + .stream() + .filter(comment -> myPolicy.trackComment(comment)).map(comment -> comment.getText().replaceAll("[\\s*]+", " ")).collect(Collectors.toList()); } private static void checkNoNewErrors(Project project, Editor editor, String intentionString) { -- GitLab