From bf298ef66f4246beac1f768c529b3c407faefc87 Mon Sep 17 00:00:00 2001 From: "Anna.Kozlova" Date: Mon, 9 Jul 2018 13:26:09 +0200 Subject: [PATCH] to line end comment: trim lines --- .../ChangeToEndOfLineCommentIntention.java | 2 +- .../ipp/comment/to_end_of_line/TrimLines.java | 3 +++ .../to_end_of_line/TrimLines_after.java | 3 +++ ...ChangeToEndOfLineCommentIntentionTest.java | 20 +++++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 plugins/IntentionPowerPak/test/com/siyeh/ipp/comment/to_end_of_line/TrimLines.java create mode 100644 plugins/IntentionPowerPak/test/com/siyeh/ipp/comment/to_end_of_line/TrimLines_after.java create mode 100644 plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntentionTest.java diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntention.java index fbf1eda633a7..4cec4dcb3244 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntention.java @@ -53,7 +53,7 @@ public class ChangeToEndOfLineCommentIntention extends Intention { } } final PsiComment newComment = - factory.createCommentFromText("//" + lines[0], parent); + factory.createCommentFromText("//" + lines[0].trim(), parent); final PsiElement replacedComment = comment.replace(newComment); codeStyleManager.reformat(replacedComment); } diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/comment/to_end_of_line/TrimLines.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/comment/to_end_of_line/TrimLines.java new file mode 100644 index 000000000000..745f971d3fda --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/comment/to_end_of_line/TrimLines.java @@ -0,0 +1,3 @@ +class MyTest { + /* simple end comment */ +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/comment/to_end_of_line/TrimLines_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/comment/to_end_of_line/TrimLines_after.java new file mode 100644 index 000000000000..72bb69b90747 --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/comment/to_end_of_line/TrimLines_after.java @@ -0,0 +1,3 @@ +class MyTest { + //simple end comment +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntentionTest.java new file mode 100644 index 000000000000..d3fbcdf2a83a --- /dev/null +++ b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/comment/ChangeToEndOfLineCommentIntentionTest.java @@ -0,0 +1,20 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.siyeh.ipp.comment; + +import com.siyeh.IntentionPowerPackBundle; +import com.siyeh.ipp.IPPTestCase; + +public class ChangeToEndOfLineCommentIntentionTest extends IPPTestCase { + + public void testTrimLines() { doTest(); } + + @Override + protected String getIntentionName() { + return IntentionPowerPackBundle.message("change.to.end.of.line.comment.intention.name"); + } + + @Override + protected String getRelativePath() { + return "comment/to_end_of_line"; + } +} \ No newline at end of file