mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
copy javadoc to the generated constructor (IDEADEV-41681)
This commit is contained in:
@@ -25,6 +25,8 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.javadoc.PsiDocComment;
|
||||
import com.intellij.psi.javadoc.PsiDocTag;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
@@ -221,6 +223,7 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP
|
||||
protected void performRefactoring(UsageInfo[] usageInfos) {
|
||||
final PsiClass psiClass = buildClass();
|
||||
if (psiClass != null) {
|
||||
fixJavadocForConstructor(psiClass);
|
||||
super.performRefactoring(usageInfos);
|
||||
if (!myUseExistingClass) {
|
||||
for (PsiReference reference : ReferencesSearch.search(method)) {
|
||||
@@ -281,6 +284,37 @@ public class IntroduceParameterObjectProcessor extends FixableUsagesRefactoringP
|
||||
return null;
|
||||
}
|
||||
|
||||
private void fixJavadocForConstructor(PsiClass psiClass) {
|
||||
final PsiDocComment docComment = method.getDocComment();
|
||||
if (docComment != null) {
|
||||
final List<PsiDocTag> mergedTags = new ArrayList<PsiDocTag>();
|
||||
final PsiDocTag[] paramTags = docComment.findTagsByName("param");
|
||||
for (PsiDocTag paramTag : paramTags) {
|
||||
final PsiElement[] dataElements = paramTag.getDataElements();
|
||||
if (dataElements.length > 0) {
|
||||
mergedTags.add((PsiDocTag)paramTag.copy());
|
||||
}
|
||||
}
|
||||
|
||||
PsiMethod compatibleParamObjectConstructor = null;
|
||||
if (myExistingClassCompatibleConstructor != null && myExistingClassCompatibleConstructor.getDocComment() == null) {
|
||||
compatibleParamObjectConstructor = myExistingClassCompatibleConstructor;
|
||||
} else if (!myUseExistingClass){
|
||||
compatibleParamObjectConstructor = psiClass.getConstructors()[0];
|
||||
}
|
||||
|
||||
if (compatibleParamObjectConstructor != null) {
|
||||
PsiDocComment psiDocComment =
|
||||
JavaPsiFacade.getElementFactory(myProject).createDocCommentFromText("/**\n*/", compatibleParamObjectConstructor);
|
||||
psiDocComment = (PsiDocComment)compatibleParamObjectConstructor.addBefore(psiDocComment, compatibleParamObjectConstructor.getFirstChild());
|
||||
|
||||
for (PsiDocTag tag : mergedTags) {
|
||||
psiDocComment.add(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected String getCommandName() {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
return RefactorJBundle.message("introduced.parameter.class.command.name", className, containingClass.getName(), method.getName());
|
||||
|
||||
@@ -29,9 +29,7 @@ import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
@SuppressWarnings({"MethodWithTooManyParameters"})
|
||||
public class MergeMethodArguments extends FixableUsageInfo {
|
||||
@@ -74,10 +72,10 @@ public class MergeMethodArguments extends FixableUsageInfo {
|
||||
else {
|
||||
psiClass = psiFacade.findClass(StringUtil.getQualifiedName(packageName, className), GlobalSearchScope.allScope(getProject()));
|
||||
}
|
||||
assert psiClass != null;
|
||||
PsiSubstitutor subst = PsiSubstitutor.EMPTY;
|
||||
if (deepestSuperMethod != null) {
|
||||
final PsiClass parentClass = deepestSuperMethod.getContainingClass();
|
||||
assert psiClass != null;
|
||||
final PsiSubstitutor parentSubstitutor =
|
||||
TypeConversionUtil.getSuperClassSubstitutor(parentClass, method.getContainingClass(), PsiSubstitutor.EMPTY);
|
||||
for (int i1 = 0; i1 < psiClass.getTypeParameters().length; i1++) {
|
||||
@@ -92,7 +90,8 @@ public class MergeMethodArguments extends FixableUsageInfo {
|
||||
}
|
||||
}
|
||||
final List<ParameterInfoImpl> parametersInfo = new ArrayList<ParameterInfoImpl>();
|
||||
parametersInfo.add(new ParameterInfoImpl(-1, parameterName, new PsiImmediateClassType(psiClass, subst), null) {
|
||||
final PsiClassType classType = JavaPsiFacade.getElementFactory(getProject()).createType(psiClass, subst);
|
||||
parametersInfo.add(new ParameterInfoImpl(-1, parameterName, classType, null) {
|
||||
@Override
|
||||
public PsiExpression getValue(final PsiCallExpression expr) throws IncorrectOperationException {
|
||||
return (PsiExpression)JavaCodeStyleManager.getInstance(getProject()).shortenClassReferences(psiFacade.getElementFactory().createExpressionFromText(getMergedParam(expr), expr));
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
class Test {
|
||||
/**
|
||||
* foo comment
|
||||
* @param param
|
||||
*/
|
||||
void foo(Param param) {
|
||||
bar(param.getS());
|
||||
}
|
||||
|
||||
void bar(String s){}
|
||||
|
||||
private static class Param {
|
||||
private final String s;
|
||||
|
||||
/**
|
||||
* @param s long description
|
||||
*/
|
||||
private Param(String s) {
|
||||
this.s = s;
|
||||
}
|
||||
|
||||
public String getS() {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
class Test {
|
||||
/**
|
||||
* foo comment
|
||||
* @param s long description
|
||||
*/
|
||||
void foo(String s) {
|
||||
bar(s);
|
||||
}
|
||||
|
||||
void bar(String s){}
|
||||
}
|
||||
@@ -68,6 +68,10 @@ public class IntroduceParameterObjectTest extends MultiFileTestCase{
|
||||
doTest(false, true);
|
||||
}
|
||||
|
||||
public void testCopyJavadoc() throws Exception {
|
||||
doTest(false, true);
|
||||
}
|
||||
|
||||
public void testUsedInnerClass() throws Exception {
|
||||
doTest(false, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user