mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
IDEA-70492 Javadoc Smart Complete Statement: Improve processing in case of the last parameter
This commit is contained in:
@@ -2,6 +2,7 @@ package com.intellij.codeInsight.editorActions.smartEnter;
|
||||
|
||||
import com.intellij.javadoc.JavadocHelper;
|
||||
import com.intellij.openapi.editor.CaretModel;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.LogicalPosition;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
@@ -44,7 +45,33 @@ public class JavadocFixer {
|
||||
|
||||
final JavadocHelper.JavadocParameterInfo next = findNext(pair.second, pair.first);
|
||||
if (next == null) {
|
||||
return false;
|
||||
final int line = pair.first.lastLine + 1;
|
||||
final Document document = editor.getDocument();
|
||||
if (line < document.getLineCount()) {
|
||||
StringBuilder indent = new StringBuilder();
|
||||
boolean insertIndent = true;
|
||||
final CharSequence text = document.getCharsSequence();
|
||||
for (int i = document.getLineStartOffset(line), max = document.getLineEndOffset(line); i < max; i++) {
|
||||
final char c = text.charAt(i);
|
||||
if (c == ' ' || c == '\t') {
|
||||
indent.append(c);
|
||||
continue;
|
||||
}
|
||||
else if (c == '*') {
|
||||
indent.append("* ");
|
||||
if (i < max - 1 && text.charAt(i + 1) != '/') {
|
||||
insertIndent = false;
|
||||
}
|
||||
}
|
||||
indent.append("\n");
|
||||
break;
|
||||
}
|
||||
if (insertIndent) {
|
||||
document.insertString(document.getLineStartOffset(line), indent);
|
||||
}
|
||||
}
|
||||
moveCaretToTheLineEndIfPossible(editor, line);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (next.parameterDescriptionStartPosition != null) {
|
||||
@@ -57,6 +84,19 @@ public class JavadocFixer {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void moveCaretToTheLineEndIfPossible(@NotNull Editor editor, int line) {
|
||||
final Document document = editor.getDocument();
|
||||
final CaretModel caretModel = editor.getCaretModel();
|
||||
int offset;
|
||||
if (line >= document.getLineCount()) {
|
||||
offset = document.getTextLength();
|
||||
}
|
||||
else {
|
||||
offset = document.getLineEndOffset(line);
|
||||
}
|
||||
caretModel.moveToOffset(offset);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static JavadocHelper.JavadocParameterInfo findNext(@NotNull Collection<JavadocHelper.JavadocParameterInfo> data,
|
||||
@NotNull JavadocHelper.JavadocParameterInfo anchor)
|
||||
|
||||
@@ -205,14 +205,19 @@ public class JavadocHelper {
|
||||
if (elementType == JavaDocTokenType.DOC_COMMENT_DATA) {
|
||||
return new JavadocParameterInfo(
|
||||
editor.offsetToLogicalPosition(paramRef.getTextRange().getEndOffset()),
|
||||
editor.offsetToLogicalPosition(e.getTextRange().getStartOffset())
|
||||
editor.offsetToLogicalPosition(e.getTextRange().getStartOffset()),
|
||||
editor.getDocument().getLineNumber(e.getTextRange().getEndOffset())
|
||||
);
|
||||
}
|
||||
else if (elementType == JavaDocTokenType.DOC_COMMENT_LEADING_ASTERISKS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return new JavadocParameterInfo(editor.offsetToLogicalPosition(paramRef.getTextRange().getEndOffset()), null);
|
||||
return new JavadocParameterInfo(
|
||||
editor.offsetToLogicalPosition(paramRef.getTextRange().getEndOffset()),
|
||||
null,
|
||||
editor.getDocument().getLineNumber(paramRef.getTextRange().getEndOffset())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -232,10 +237,16 @@ public class JavadocHelper {
|
||||
*/
|
||||
@NotNull public final LogicalPosition parameterNameEndPosition;
|
||||
@Nullable public final LogicalPosition parameterDescriptionStartPosition;
|
||||
/** Last logical line occupied by the current javadoc parameter. */
|
||||
public final int lastLine;
|
||||
|
||||
public JavadocParameterInfo(@NotNull LogicalPosition parameterNameEndPosition, LogicalPosition parameterDescriptionStartPosition) {
|
||||
public JavadocParameterInfo(@NotNull LogicalPosition parameterNameEndPosition,
|
||||
LogicalPosition parameterDescriptionStartPosition,
|
||||
int lastLine)
|
||||
{
|
||||
this.parameterNameEndPosition = parameterNameEndPosition;
|
||||
this.parameterDescriptionStartPosition = parameterDescriptionStartPosition;
|
||||
this.lastLine = lastLine;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class Foo {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param i desc
|
||||
* @param j desc<caret>
|
||||
*/
|
||||
void test(int i, int j) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param i desc
|
||||
* @param j desc<caret>
|
||||
* @return
|
||||
*/
|
||||
int test(int i, int j) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param i desc
|
||||
* @param j desc
|
||||
* @return<caret>
|
||||
*/
|
||||
int test(int i, int j) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param i desc
|
||||
* @param j desc
|
||||
* <caret>
|
||||
*/
|
||||
void test(int i, int j) {
|
||||
}
|
||||
}
|
||||
@@ -223,6 +223,10 @@ public class CompleteStatementTest extends EditorActionTestCase {
|
||||
public void testFromJavadocParameterDescriptionEndToNextParameter() throws Exception { doTest(); }
|
||||
|
||||
public void testFromJavadocParameterDescriptionMiddleToNextParameter() throws Exception { doTest(); }
|
||||
|
||||
public void testLastJavadocParameterDescription() throws Exception { doTest(); }
|
||||
|
||||
public void testLastJavadocParameterDescriptionToReturn() throws Exception { doTest(); }
|
||||
|
||||
private void doTestBracesNextLineStyle() throws Exception {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
|
||||
Reference in New Issue
Block a user