mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Remove continuation indent on typing '@' in JavaDoc
See IDEA-179426 Javadoc @param/@return tag after @param tag with description should not be indented
This commit is contained in:
@@ -49,10 +49,29 @@ public class JavadocTypedHandler extends TypedHandlerDelegate {
|
||||
@NotNull
|
||||
@Override
|
||||
public Result charTyped(char c, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
|
||||
insertClosingTagIfNecessary(c, project, editor, file);
|
||||
if (file instanceof PsiJavaFile &&
|
||||
(insertClosingTagIfNecessary(c, project, editor, file) ||
|
||||
adjustStartTagIndent(c, editor, file))) {
|
||||
return Result.CONTINUE;
|
||||
}
|
||||
return Result.CONTINUE;
|
||||
}
|
||||
|
||||
private static boolean adjustStartTagIndent(char c, @NotNull Editor editor, @NotNull PsiFile file) {
|
||||
if (c == '@') {
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
PsiElement currElement = file.findElementAt(offset);
|
||||
if (currElement instanceof PsiWhiteSpace) {
|
||||
PsiElement prev = currElement.getPrevSibling();
|
||||
if (prev != null && prev.getNode().getElementType() == JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS) {
|
||||
editor.getDocument().replaceString(currElement.getTextRange().getStartOffset(), offset - 1, " ");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if it's necessary to insert closing tag on typed character.
|
||||
*
|
||||
@@ -63,7 +82,7 @@ public class JavadocTypedHandler extends TypedHandlerDelegate {
|
||||
* @return {@code true} if closing tag is inserted; {@code false} otherwise
|
||||
*/
|
||||
private static boolean insertClosingTagIfNecessary(char c, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
|
||||
if (c != CLOSE_TAG_SYMBOL || !CodeInsightSettings.getInstance().JAVADOC_GENERATE_CLOSING_TAG || !(file instanceof PsiJavaFile)) {
|
||||
if (c != CLOSE_TAG_SYMBOL || !CodeInsightSettings.getInstance().JAVADOC_GENERATE_CLOSING_TAG) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.company;
|
||||
|
||||
public class Test {
|
||||
/**
|
||||
* @param a Description A
|
||||
* @param b Description B
|
||||
* <caret>
|
||||
*/
|
||||
void foo(int a, int b, int c) {}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.company;
|
||||
|
||||
public class Test {
|
||||
/**
|
||||
* @param a Description A
|
||||
* @param b Description B
|
||||
* @<caret>
|
||||
*/
|
||||
void foo(int a, int b, int c) {}
|
||||
}
|
||||
+10
-6
@@ -21,25 +21,29 @@ public class JavadocTypedHandlerFunctionalTest extends LightPlatformCodeInsightT
|
||||
private static final String BASE_PATH = "/codeInsight/editorActions/javadocTypedHandler/";
|
||||
|
||||
public void testEmptyTag() {
|
||||
doTest();
|
||||
doTest('>');
|
||||
}
|
||||
|
||||
public void testComment() {
|
||||
doTest();
|
||||
doTest('>');
|
||||
}
|
||||
|
||||
public void testCodeTag() {
|
||||
doTest();
|
||||
doTest('>');
|
||||
}
|
||||
|
||||
public void testTypeParam() {
|
||||
doTest();
|
||||
doTest('>');
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
public void testDocTagStart() {
|
||||
doTest('@');
|
||||
}
|
||||
|
||||
private void doTest(char typedChar) {
|
||||
String testName = getTestName(true);
|
||||
configureByFile(BASE_PATH + testName + ".java");
|
||||
type('>');
|
||||
type(typedChar);
|
||||
checkResultByFile(BASE_PATH + testName + "_after.java");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user