mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simplify extract method object processing: instead of change signature just replace return value for newly created inner class (ensure that fqn won't be inserted)
This commit is contained in:
+15
-13
@@ -86,7 +86,7 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
private boolean myMadeStatic = false;
|
||||
private final Set<MethodToMoveUsageInfo> myUsages = new LinkedHashSet<MethodToMoveUsageInfo>();
|
||||
private PsiClass myInnerClass;
|
||||
private ChangeSignatureProcessor myChangeSignatureProcessor;
|
||||
private boolean myChangeReturnType;
|
||||
private Runnable myCopyMethodToInner;
|
||||
|
||||
public ExtractMethodObjectProcessor(Project project, Editor editor, PsiElement[] elements, final String innerClassName) {
|
||||
@@ -266,12 +266,6 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
myInnerClass.add(GenerateMembersUtil.generateGetterPrototype(field));
|
||||
}
|
||||
|
||||
PsiParameter[] params = getMethod().getParameterList().getParameters();
|
||||
ParameterInfoImpl[] infos = new ParameterInfoImpl[params.length];
|
||||
for (int i = 0; i < params.length; i++) {
|
||||
PsiParameter param = params[i];
|
||||
infos[i] = new ParameterInfoImpl(i, param.getName(), param.getType());
|
||||
}
|
||||
final PsiCodeBlock body = getMethod().getBody();
|
||||
LOG.assertTrue(body != null);
|
||||
final LinkedHashSet<PsiLocalVariable> vars = new LinkedHashSet<PsiLocalVariable>();
|
||||
@@ -393,17 +387,25 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
myChangeSignatureProcessor = new ChangeSignatureProcessor(myProject, getMethod(), false, null, getMethod().getName(),
|
||||
new PsiImmediateClassType(myInnerClass, PsiSubstitutor.EMPTY), infos);
|
||||
myChangeReturnType = true;
|
||||
}
|
||||
|
||||
void runChangeSignature() {
|
||||
if (myChangeSignatureProcessor != null) {
|
||||
myChangeSignatureProcessor.run();
|
||||
}
|
||||
if (myCopyMethodToInner != null) {
|
||||
ApplicationManager.getApplication().runWriteAction(myCopyMethodToInner);
|
||||
}
|
||||
if (myChangeReturnType) {
|
||||
final Runnable runnable = new Runnable() {
|
||||
public void run() {
|
||||
final PsiTypeElement typeElement = ((PsiLocalVariable)((PsiDeclarationStatement)JavaPsiFacade.getElementFactory(myProject)
|
||||
.createStatementFromText(myInnerClassName + " l =null;", myInnerClass)).getDeclaredElements()[0]).getTypeElement();
|
||||
final PsiTypeElement innerMethodReturnTypeElement = myInnerMethod.getReturnTypeElement();
|
||||
LOG.assertTrue(innerMethodReturnTypeElement != null);
|
||||
innerMethodReturnTypeElement.replace(typeElement);
|
||||
}
|
||||
};
|
||||
ApplicationManager.getApplication().runWriteAction(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
private String getPureName(PsiVariable var) {
|
||||
@@ -524,7 +526,7 @@ public class ExtractMethodObjectProcessor extends BaseRefactoringProcessor {
|
||||
LOG.assertTrue(methodBody != null);
|
||||
replacedMethodBody.replace(methodBody);
|
||||
PsiUtil.setModifierProperty(newMethod, PsiModifier.STATIC, myInnerClass.hasModifierProperty(PsiModifier.STATIC) && notHasGeneratedFields());
|
||||
myInnerMethod = (PsiMethod)JavaCodeStyleManager.getInstance(myProject).shortenClassReferences(myInnerClass.add(newMethod));
|
||||
myInnerMethod = (PsiMethod)myInnerClass.add(newMethod);
|
||||
}
|
||||
|
||||
private boolean notHasGeneratedFields() {
|
||||
|
||||
@@ -77,7 +77,6 @@ public class ExtractMethodObject4DebuggerTest extends LightRefactoringTestCase {
|
||||
" }");
|
||||
}
|
||||
|
||||
@Bombed(month = Calendar.SEPTEMBER, day = 20)
|
||||
public void testInvokeReturnType() throws Exception {
|
||||
doTest("x = 6; y = 6;", "Test test = new Test().invoke();\n" +
|
||||
" x = test.getX();\n" +
|
||||
|
||||
Reference in New Issue
Block a user