From 09df3b6400bbc01e7248ac145e621266c4e38537 Mon Sep 17 00:00:00 2001 From: "Denis.Zhdanov" Date: Mon, 11 Feb 2013 13:19:34 +0400 Subject: [PATCH] IDEA-100722 Commenting block of Java code with EOL comments unfolds imports and top comment Use bulk processing only when number of lines to be commented is relatively big. 'Relatively big' might be tweaked via 'idea.bulk.comment.lines.trigger' property. Default value is 100. We need that change because the whole bulk processing is implemented in a way 'drop all cached info on bulk change start; re-calculate all necessary info on bulk update end'. I.e. there is no point in recalculating everything when, for example, one line is commented --- .../CommentByLineCommentHandler.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java index 5da9aa487a91..db00b690b06a 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/generation/CommentByLineCommentHandler.java @@ -46,6 +46,7 @@ import com.intellij.psi.codeStyle.Indent; import com.intellij.psi.util.PsiUtilBase; import com.intellij.util.DocumentUtil; import com.intellij.util.StringBuilderSpinAllocator; +import com.intellij.util.SystemProperties; import com.intellij.util.containers.IntArrayList; import com.intellij.util.text.CharArrayUtil; import gnu.trove.THashMap; @@ -55,19 +56,23 @@ import org.jetbrains.annotations.Nullable; import java.util.Map; public class CommentByLineCommentHandler implements CodeInsightActionHandler { - private Project myProject; - private PsiFile myFile; - private Document myDocument; - private Editor myEditor; - private int myStartOffset; - private int myEndOffset; - private int myStartLine; - private int myEndLine; - private int[] myStartOffsets; - private int[] myEndOffsets; - private Commenter[] myCommenters; + + private static final int MIN_LINES_TO_COMMENT_TO_USE_BULK_PROCESSING + = SystemProperties.getIntProperty("idea.bulk.comment.lines.trigger", 100); + + private Project myProject; + private PsiFile myFile; + private Document myDocument; + private Editor myEditor; + private int myStartOffset; + private int myEndOffset; + private int myStartLine; + private int myEndLine; + private int[] myStartOffsets; + private int[] myEndOffsets; + private Commenter[] myCommenters; private Map myCommenterStateMap; - private CodeStyleManager myCodeStyleManager; + private CodeStyleManager myCodeStyleManager; @Override public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { @@ -419,7 +424,7 @@ public class CommentByLineCommentHandler implements CodeInsightActionHandler { } public void doDefaultCommenting(final Commenter commenter) { - DocumentUtil.executeInBulk(myDocument, true, new Runnable() { + DocumentUtil.executeInBulk(myDocument, myEndLine - myStartLine >= MIN_LINES_TO_COMMENT_TO_USE_BULK_PROCESSING, new Runnable() { @Override public void run() { for (int line = myEndLine; line >= myStartLine; line--) { @@ -435,7 +440,7 @@ public class CommentByLineCommentHandler implements CodeInsightActionHandler { final FileType fileType = myFile.getFileType(); final Indent minIndent = computeMinIndent(myStartLine, myEndLine, chars, myCodeStyleManager, fileType); - DocumentUtil.executeInBulk(myDocument, true, new Runnable() { + DocumentUtil.executeInBulk(myDocument, myEndLine - myStartLine > MIN_LINES_TO_COMMENT_TO_USE_BULK_PROCESSING, new Runnable() { @Override public void run() { for (int line = myEndLine; line >= myStartLine; line--) {