Commit 81cad6fd authored by Anna.Kozlova's avatar Anna.Kozlova
Browse files

preserve comments: temp skip comments in imports

parent aa517015
Branches unavailable Tags unavailable
No related merge requests found
Showing with 16 additions and 2 deletions
+16 -2
......@@ -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;
......
......@@ -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;
}
}
......@@ -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) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment