mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] format javadoc after change signature
fixes IDEA-281568, IDEA-139879, IDEA-55288 GitOrigin-RevId: c0a83cf3288ee5c78ed8c53dd7bae73fc3de59dd
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fd1ca7caae
commit
d6f3b1ec85
+3
@@ -23,6 +23,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.impl.source.codeStyle.javadoc.CommentFormatter;
|
||||
import com.intellij.psi.impl.source.resolve.JavaResolveUtil;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
@@ -1078,6 +1079,8 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
methodDocComment.add(JavaPsiFacade.getElementFactory(method.getProject()).createDocTagFromText("@return"));
|
||||
}
|
||||
}
|
||||
CommentFormatter formatter = new CommentFormatter(method.getContainingFile());
|
||||
formatter.processComment(methodDocComment.getNode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.intellij.codeInsight.highlighting.HighlightManager;
|
||||
import com.intellij.java.refactoring.JavaRefactoringBundle;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.editor.colors.EditorColors;
|
||||
@@ -24,6 +25,7 @@ import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.impl.PsiImplUtil;
|
||||
import com.intellij.psi.impl.source.codeStyle.javadoc.CommentFormatter;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
import com.intellij.psi.javadoc.PsiDocTagValue;
|
||||
@@ -1177,8 +1179,12 @@ public final class RefactoringUtil {
|
||||
paramTag.delete();
|
||||
}
|
||||
for (PsiDocTag psiDocTag : newTags) {
|
||||
anchor = anchor != null && anchor.isValid() ? docComment.addAfter(psiDocTag, anchor) : docComment.add(psiDocTag);
|
||||
anchor = anchor != null && anchor.isValid()
|
||||
? docComment.addAfter(psiDocTag, anchor)
|
||||
: docComment.add(psiDocTag);
|
||||
}
|
||||
CommentFormatter formatter = new CommentFormatter(method.getContainingFile());
|
||||
formatter.processComment(docComment.getNode());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.intellij.psi.impl.source.SourceTreeToPsiMap;
|
||||
import com.intellij.psi.impl.source.tree.*;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
import com.intellij.psi.javadoc.PsiDocToken;
|
||||
import com.intellij.psi.tree.ChildRoleBase;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
@@ -195,16 +196,19 @@ public class PsiDocCommentImpl extends LazyParseablePsiElement implements PsiDoc
|
||||
addNewLineToTag((CompositeElement)first, getContainingFile(), getManager());
|
||||
}
|
||||
else {
|
||||
removeEndingAsterisksFromTag((CompositeElement)first);
|
||||
removeEndingAsterisksFromTagIfNeeded((CompositeElement)first);
|
||||
}
|
||||
}
|
||||
|
||||
return first;
|
||||
}
|
||||
|
||||
private static void removeEndingAsterisksFromTag(CompositeElement tag) {
|
||||
private static void removeEndingAsterisksFromTagIfNeeded(CompositeElement tag) {
|
||||
ASTNode current = tag.getLastChildNode();
|
||||
while (current != null && current.getElementType() == DOC_COMMENT_DATA) {
|
||||
if (current instanceof PsiDocToken) {
|
||||
return;
|
||||
}
|
||||
current = current.getTreePrev();
|
||||
}
|
||||
if (current != null && current.getElementType() == DOC_COMMENT_LEADING_ASTERISKS) {
|
||||
@@ -219,6 +223,7 @@ public class PsiDocCommentImpl extends LazyParseablePsiElement implements PsiDoc
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static boolean nodeIsNextAfterAsterisks(@NotNull ASTNode node) {
|
||||
ASTNode current = TreeUtil.findSiblingBackward(node, DOC_COMMENT_LEADING_ASTERISKS);
|
||||
if (current == null || current == node) return false;
|
||||
|
||||
@@ -18,7 +18,7 @@ final class R {
|
||||
* @param b b value
|
||||
* @param c c value
|
||||
* @param d d value
|
||||
* @param s s value
|
||||
* @param s s value
|
||||
*/
|
||||
R(int a, boolean b, float c, double d, String s) {
|
||||
this.a = a;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
class A {
|
||||
/**
|
||||
* Foo
|
||||
*
|
||||
* @param i1 an int
|
||||
* @param i2 another int
|
||||
*/
|
||||
void <caret>foo(int i1, int i2) {
|
||||
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
class A {
|
||||
/**
|
||||
* Foo
|
||||
*
|
||||
* @param i1 an int
|
||||
*/
|
||||
void foo(int i1) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
class C {
|
||||
/**
|
||||
* This is the role -
|
||||
*
|
||||
* @param role another desc
|
||||
* @return return description
|
||||
*/
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
public class Test {
|
||||
/**
|
||||
* @param i
|
||||
* @param i
|
||||
* @param j
|
||||
* @return
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
class A {
|
||||
/**
|
||||
* Demo.
|
||||
*
|
||||
* @param a
|
||||
* a.
|
||||
* @param b
|
||||
* b.
|
||||
* @param c
|
||||
* c.
|
||||
*/
|
||||
public void <caret>demo(int a, int b, int c) {
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
class A {
|
||||
/**
|
||||
* Demo.
|
||||
*
|
||||
* @param a
|
||||
* a.
|
||||
* @param b
|
||||
* b.
|
||||
* @param c
|
||||
* c.
|
||||
*/
|
||||
public void <caret>demo(int a, int b, int c) {
|
||||
}
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
class A {
|
||||
/**
|
||||
* Demo.
|
||||
* @param b
|
||||
* b.
|
||||
* @param a
|
||||
* a.
|
||||
* @param c
|
||||
* c.
|
||||
*/
|
||||
public void demo(int b, int a, int c) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class A {
|
||||
/**
|
||||
* Demo.
|
||||
*
|
||||
* @param b b.
|
||||
* @param a a.
|
||||
* @param c c.
|
||||
*/
|
||||
public void demo(int b, int a, int c) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
public class MyClass3
|
||||
{
|
||||
/**
|
||||
* This method does amazing things.
|
||||
*
|
||||
* @param a First parameter.
|
||||
* @param b Second parameter.
|
||||
* @param c Third parameter.
|
||||
*
|
||||
* @return A magic string.
|
||||
*
|
||||
* @since Blabla 1.2.
|
||||
*/
|
||||
public String <caret>myMethod(int a, long b, boolean c)
|
||||
{
|
||||
return "Hi there!";
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println(new MyClass3().myMethod(1, "2", true));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
public class MyClass3
|
||||
{
|
||||
/**
|
||||
* This method does amazing things.
|
||||
*
|
||||
* @param b Second parameter.
|
||||
* @param a First parameter.
|
||||
* @param c Third parameter.
|
||||
* @param d
|
||||
* @return A magic string.
|
||||
* @since Blabla 1.2.
|
||||
*/
|
||||
public String myMethod(int b, long a, boolean c, short d)
|
||||
{
|
||||
return "Hi there!";
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println(new MyClass3().myMethod(1, "2", true, ));
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ class X {
|
||||
*/
|
||||
public class TestRefactorLink {
|
||||
/**
|
||||
@return nothing
|
||||
* @param z zparam
|
||||
* @param z zparam
|
||||
* @param y yparam
|
||||
* @return nothing
|
||||
*/
|
||||
public void mymethod(int z, int y) { }
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ class X {
|
||||
*/
|
||||
public class TestRefactorLink {
|
||||
/**
|
||||
* @return nothing
|
||||
* @param z yparam
|
||||
* @return nothing
|
||||
*/
|
||||
public void mymethod(boolean z) { }
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
class X {
|
||||
|
||||
/**
|
||||
* @param a aparam
|
||||
* @param a aparam
|
||||
* @param c
|
||||
* @param b1 bparam
|
||||
*/
|
||||
|
||||
@@ -5,9 +5,9 @@ class X {
|
||||
*/
|
||||
public class TestRefactorLink {
|
||||
/**
|
||||
* @return nothing
|
||||
* @param z zparam
|
||||
* @param y yparam
|
||||
* @return nothing
|
||||
*/
|
||||
public void mymethod(int z, int y) { }
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
/**
|
||||
* Record javadoc
|
||||
* Record javadoc
|
||||
*
|
||||
* @param x x
|
||||
* @param y
|
||||
*/
|
||||
|
||||
+4
-2
@@ -1,12 +1,14 @@
|
||||
/**
|
||||
* Record javadoc
|
||||
* Record javadoc
|
||||
*
|
||||
* @param y y
|
||||
* @param z z
|
||||
* @param x x
|
||||
*/
|
||||
record Rec(int y, int z, int x) {
|
||||
/**
|
||||
* Constructor javadoc
|
||||
* Constructor javadoc
|
||||
*
|
||||
* @param y y
|
||||
* @param z z
|
||||
* @param x x
|
||||
|
||||
-1
@@ -1,6 +1,5 @@
|
||||
/**
|
||||
* @param yyy y
|
||||
*
|
||||
*/
|
||||
record Rec(long yyy) {
|
||||
public long yyy() {
|
||||
|
||||
@@ -2,7 +2,8 @@ class X {
|
||||
|
||||
/**
|
||||
* documentation
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public int <caret>mymethod() { }
|
||||
public int mymethod() { }
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.intellij.codeInsight.TargetElementUtil;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.changeSignature.ChangeSignatureProcessor;
|
||||
import com.intellij.refactoring.changeSignature.JavaThrownExceptionInfo;
|
||||
@@ -589,5 +590,37 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
doTest(null, null, "@org.jetbrains.annotations.NotNull java.lang.String", method -> new ParameterInfoImpl[0], false);
|
||||
}
|
||||
|
||||
public void testMultilineJavadoc() { // IDEA-281568
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
ParameterInfoImpl.create(1).withType(PsiType.INT).withName("b"),
|
||||
ParameterInfoImpl.create(0).withType(PsiType.INT).withName("a"),
|
||||
ParameterInfoImpl.create(2).withType(PsiType.INT).withName("c"),
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testMultilineJavadocWithoutFormatting() { // IDEA-281568
|
||||
JavaCodeStyleSettings.getInstance(getProject()).ENABLE_JAVADOC_FORMATTING = false;
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
ParameterInfoImpl.create(1).withType(PsiType.INT).withName("b"),
|
||||
ParameterInfoImpl.create(0).withType(PsiType.INT).withName("a"),
|
||||
ParameterInfoImpl.create(2).withType(PsiType.INT).withName("c"),
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testJavadocNotBrokenAfterDelete() { // IDEA-139879
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
ParameterInfoImpl.create(0).withType(PsiType.INT).withName("i1")
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testNoGapsInParameterTags() { // IDEA-139879
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
ParameterInfoImpl.create(0).withType(PsiType.INT).withName("b"),
|
||||
ParameterInfoImpl.create(1).withType(PsiType.LONG).withName("a"),
|
||||
ParameterInfoImpl.create(2).withType(PsiType.BOOLEAN).withName("c"),
|
||||
ParameterInfoImpl.createNew().withType(PsiType.SHORT).withName("d"),
|
||||
}, false);
|
||||
}
|
||||
|
||||
/* workers */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user