mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 10:20:15 +07:00
JoinLinesHandler: Only skip conversion to block comment if next line starts with line comment
GitOrigin-RevId: 895b8631127d321f7db8f5e25871a2dca5777760
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a01edaba49
commit
818325442d
@@ -0,0 +1,4 @@
|
||||
class A{
|
||||
// comment <caret>1
|
||||
/* comment 2 */ /* comment 3 */
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
class A{
|
||||
// comment <caret>1
|
||||
/* comment 2 */ /* comment 3 */void test() {}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class A{
|
||||
/* comment 1 */<caret>/* comment 2 */ /* comment 3 */void test() {}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class A{
|
||||
/* comment 1 */<caret>/* comment 2 */ /* comment 3 */
|
||||
}
|
||||
@@ -154,6 +154,8 @@ public class JoinLinesTest extends LightJavaCodeInsightTestCase {
|
||||
public void testLocalVarImplicit() { doTest(); }
|
||||
|
||||
public void testSlashComment() { doTest(); }
|
||||
public void testSlashCommentFollowedByBlockComment() { doTest(); }
|
||||
public void testSlashCommentFollowedByBlockCommentAndCode() { doTest(); }
|
||||
public void testDocComment() { doTest(); }
|
||||
|
||||
public void testOnEmptyLine() { doTest(); }
|
||||
|
||||
@@ -39,6 +39,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.codeInsight.editorActions.JoinLinesHandlerDelegate.CANNOT_JOIN;
|
||||
import static com.intellij.psi.util.PsiUtilCore.getElementType;
|
||||
|
||||
public class JoinLinesHandler extends EditorActionHandler.ForEachCaret {
|
||||
private static final Logger LOG = Logger.getInstance(JoinLinesHandler.class);
|
||||
@@ -149,7 +150,7 @@ public class JoinLinesHandler extends EditorActionHandler.ForEachCaret {
|
||||
int nextStart = CharArrayUtil.shiftForward(text, myDoc.getLineStartOffset(line + 1), " \t\n");
|
||||
if (nextStart < text.length() &&
|
||||
myDoc.getLineNumber(nextStart) <= myLine + lineCount &&
|
||||
getCommentElement(myFile.findElementAt(nextStart)) == null) {
|
||||
!isLineComment(getCommentElement(myFile.findElementAt(nextStart)))) {
|
||||
endComments.add(comment);
|
||||
}
|
||||
}
|
||||
@@ -167,6 +168,13 @@ public class JoinLinesHandler extends EditorActionHandler.ForEachCaret {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isLineComment(@Nullable PsiComment element) {
|
||||
if (element == null) return false;
|
||||
Commenter commenter = LanguageCommenters.INSTANCE.forLanguage(element.getLanguage());
|
||||
return commenter instanceof CodeDocumentationAwareCommenter &&
|
||||
((CodeDocumentationAwareCommenter)commenter).getLineCommentTokenType() == getElementType(element);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param lineCount number of lines to process
|
||||
* @return number of unprocessed lines
|
||||
|
||||
Reference in New Issue
Block a user