mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
safe delete method parameter: change method signature in javadoc accordingly (IDEA-57032)
This commit is contained in:
+11
-7
@@ -172,7 +172,7 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo
|
||||
}
|
||||
|
||||
|
||||
private String[] getSignature() {
|
||||
public String[] getSignature() {
|
||||
PsiElement element = getNameElement().getNextSibling();
|
||||
|
||||
while (element != null && !(element instanceof PsiDocTagValue)) {
|
||||
@@ -223,7 +223,7 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo
|
||||
return JavaResolveUtil.getContextClass(this);
|
||||
}
|
||||
|
||||
private class MyReference implements PsiJavaReference {
|
||||
public class MyReference implements PsiJavaReference {
|
||||
private final PsiElement myReferencee;
|
||||
|
||||
public MyReference(PsiElement referencee) {
|
||||
@@ -345,16 +345,20 @@ public class PsiDocMethodOrFieldRef extends CompositePsiElement implements PsiDo
|
||||
}
|
||||
newText.append("*/");
|
||||
|
||||
PsiComment comment =
|
||||
JavaPsiFacade.getInstance(containingClass.getProject()).getElementFactory().createCommentFromText(newText.toString(), null);
|
||||
PsiElement tag = PsiTreeUtil.getChildOfType(comment, PsiDocTag.class);
|
||||
PsiElement ref = PsiTreeUtil.getChildOfType(tag, PsiDocMethodOrFieldRef.class);
|
||||
return replace(ref);
|
||||
return bindToText(containingClass, newText);
|
||||
}
|
||||
|
||||
return PsiDocMethodOrFieldRef.this;
|
||||
}
|
||||
|
||||
public PsiElement bindToText(PsiClass containingClass, StringBuffer newText) {
|
||||
PsiComment comment =
|
||||
JavaPsiFacade.getInstance(containingClass.getProject()).getElementFactory().createCommentFromText(newText.toString(), null);
|
||||
PsiElement tag = PsiTreeUtil.getChildOfType(comment, PsiDocTag.class);
|
||||
PsiElement ref = PsiTreeUtil.getChildOfType(tag, PsiDocMethodOrFieldRef.class);
|
||||
return replace(ref);
|
||||
}
|
||||
|
||||
public boolean isReferenceTo(PsiElement element) {
|
||||
return getManager().areElementsEquivalent(resolve(), element);
|
||||
}
|
||||
|
||||
@@ -24,9 +24,11 @@ import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.impl.source.javadoc.PsiDocMethodOrFieldRef;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
@@ -39,9 +41,11 @@ import com.intellij.refactoring.util.RefactoringUIUtil;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.usageView.UsageViewUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
@@ -583,6 +587,30 @@ public class JavaSafeDeleteProcessor implements SafeDeleteProcessorDelegate {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (element instanceof PsiDocMethodOrFieldRef) {
|
||||
if (((PsiDocMethodOrFieldRef)element).getSignature() != null) {
|
||||
@NonNls final StringBuffer newText = new StringBuffer();
|
||||
newText.append("/** @see #").append(method.getName()).append('(');
|
||||
final List<PsiParameter> parameters = new ArrayList<PsiParameter>(Arrays.asList(method.getParameterList().getParameters()));
|
||||
parameters.remove(parameter);
|
||||
newText.append(StringUtil.join(parameters, new Function<PsiParameter, String>() {
|
||||
@Override
|
||||
public String fun(PsiParameter psiParameter) {
|
||||
return parameter.getType().getCanonicalText();
|
||||
}
|
||||
}, ","));
|
||||
newText.append(")*/");
|
||||
usages.add(new SafeDeleteReferenceJavaDeleteUsageInfo(element, parameter, true) {
|
||||
public void deleteElement() throws IncorrectOperationException {
|
||||
final PsiDocMethodOrFieldRef.MyReference javadocMethodReference =
|
||||
(PsiDocMethodOrFieldRef.MyReference)element.getReference();
|
||||
if (javadocMethodReference != null) {
|
||||
javadocMethodReference.bindToText(method.getContainingClass(), newText);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class Super {
|
||||
void m1(String p2) {}
|
||||
|
||||
/**
|
||||
* @see #m1( String)
|
||||
*/
|
||||
void m2() {}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class Super {
|
||||
void m1(String p<caret>1, String p2) {}
|
||||
|
||||
/**
|
||||
* @see #m1(String, String)
|
||||
*/
|
||||
void m2() {}
|
||||
}
|
||||
@@ -61,6 +61,11 @@ public class SafeDeleteTest extends MultiFileTestCase {
|
||||
doTest("B");
|
||||
}
|
||||
|
||||
public void testJavadocParamRef() throws Exception {
|
||||
myDoCompare = false;
|
||||
doTest("Super");
|
||||
}
|
||||
|
||||
public void testEnumConstructorParameter() throws Exception {
|
||||
myDoCompare = false;
|
||||
doTest("UserFlags");
|
||||
|
||||
Reference in New Issue
Block a user