mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
convert to instance: remove target class parameter javadoc (IDEA-78892 )
This commit is contained in:
@@ -23,6 +23,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.javadoc.PsiDocParamRef;
|
||||
import com.intellij.psi.impl.source.resolve.JavaResolveUtil;
|
||||
import com.intellij.psi.javadoc.PsiDocTagValue;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
@@ -114,8 +115,9 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
for (final PsiReference ref : ReferencesSearch.search(myTargetParameter, new LocalSearchScope(myMethod), false)) {
|
||||
if (ref.getElement() instanceof PsiReferenceExpression) {
|
||||
result.add(new ParameterUsageInfo((PsiReferenceExpression)ref));
|
||||
final PsiElement element = ref.getElement();
|
||||
if (element instanceof PsiReferenceExpression || element instanceof PsiDocParamRef) {
|
||||
result.add(new ParameterUsageInfo(ref));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,15 +346,23 @@ public class ConvertToInstanceMethodProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
|
||||
private void processParameterUsage(ParameterUsageInfo usage) throws IncorrectOperationException {
|
||||
final PsiJavaCodeReferenceElement referenceExpression = usage.getReferenceExpression();
|
||||
if (referenceExpression.getParent() instanceof PsiReferenceExpression) {
|
||||
// todo: check for correctness
|
||||
referenceExpression.delete();
|
||||
}
|
||||
else {
|
||||
final PsiExpression expression =
|
||||
JavaPsiFacade.getInstance(myMethod.getProject()).getElementFactory().createExpressionFromText("this", null);
|
||||
referenceExpression.replace(expression);
|
||||
final PsiReference reference = usage.getReferenceExpression();
|
||||
if (reference instanceof PsiReferenceExpression) {
|
||||
final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)reference;
|
||||
if (referenceExpression.getParent() instanceof PsiReferenceExpression) {
|
||||
// todo: check for correctness
|
||||
referenceExpression.delete();
|
||||
}
|
||||
else {
|
||||
final PsiExpression expression =
|
||||
JavaPsiFacade.getInstance(myMethod.getProject()).getElementFactory().createExpressionFromText("this", null);
|
||||
referenceExpression.replace(expression);
|
||||
}
|
||||
} else {
|
||||
final PsiElement element = reference.getElement();
|
||||
if (element instanceof PsiDocParamRef) {
|
||||
element.getParent().delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,22 +15,21 @@
|
||||
*/
|
||||
package com.intellij.refactoring.convertToInstanceMethod;
|
||||
|
||||
import com.intellij.psi.PsiJavaCodeReferenceElement;
|
||||
import com.intellij.psi.PsiReferenceExpression;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
class ParameterUsageInfo extends UsageInfo {
|
||||
private final PsiReferenceExpression myReferenceExpression;
|
||||
private final PsiReference myReferenceExpression;
|
||||
|
||||
public ParameterUsageInfo(PsiReferenceExpression refereneceElement) {
|
||||
super(refereneceElement);
|
||||
myReferenceExpression = refereneceElement;
|
||||
public ParameterUsageInfo(PsiReference referenceElement) {
|
||||
super(referenceElement);
|
||||
myReferenceExpression = referenceElement;
|
||||
}
|
||||
|
||||
public PsiJavaCodeReferenceElement getReferenceExpression() {
|
||||
public PsiReference getReferenceExpression() {
|
||||
return myReferenceExpression;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
/**
|
||||
* method description
|
||||
* @param a description
|
||||
*/
|
||||
public static void ma<caret>in(A a) {
|
||||
}
|
||||
}
|
||||
|
||||
class A {}
|
||||
@@ -0,0 +1,10 @@
|
||||
class Test {
|
||||
}
|
||||
|
||||
class A {
|
||||
/**
|
||||
* method description
|
||||
*/
|
||||
public void main() {
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,8 @@ public class ConvertToInstanceMethodTest extends LightRefactoringTestCase {
|
||||
|
||||
public void testInterfaceTypeParameter() throws Exception { doTest(0); }
|
||||
|
||||
public void testJavadocParameter() throws Exception { doTest(0); }
|
||||
|
||||
private void doTest(final int targetParameter) throws Exception {
|
||||
final String filePath = "/refactoring/convertToInstanceMethod/" + getTestName(false) + ".java";
|
||||
configureByFile(filePath);
|
||||
|
||||
Reference in New Issue
Block a user