mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
initialize in setup: add field initialization instead of variable declaration (IDEA-62451)
This commit is contained in:
@@ -26,6 +26,7 @@ import com.intellij.psi.*;
|
|||||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
import com.intellij.psi.search.GlobalSearchScope;
|
||||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||||
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import com.intellij.refactoring.HelpID;
|
import com.intellij.refactoring.HelpID;
|
||||||
import com.intellij.refactoring.RefactoringBundle;
|
import com.intellij.refactoring.RefactoringBundle;
|
||||||
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||||
@@ -231,7 +232,11 @@ public abstract class LocalToFieldHandler {
|
|||||||
PsiStatement assignment = createAssignment(local, field.getName(), factory);
|
PsiStatement assignment = createAssignment(local, field.getName(), factory);
|
||||||
final PsiCodeBlock body = inClass.getBody();
|
final PsiCodeBlock body = inClass.getBody();
|
||||||
assert body != null;
|
assert body != null;
|
||||||
body.add(assignment);
|
if (PsiTreeUtil.isAncestor(body, local, false)) {
|
||||||
|
body.addBefore(assignment, PsiTreeUtil.getParentOfType(local, PsiStatement.class));
|
||||||
|
} else {
|
||||||
|
body.add(assignment);
|
||||||
|
}
|
||||||
local.delete();
|
local.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import junit.framework.TestCase;
|
||||||
|
public class T extends TestCase {
|
||||||
|
private String i;
|
||||||
|
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
i = getName();
|
||||||
|
myName = " second " + i;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import junit.framework.TestCase;
|
||||||
|
public class T extends TestCase {
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
String na<caret>me = getName();
|
||||||
|
myName = " second " + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void test() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getName() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -78,6 +78,10 @@ public class IntroduceFieldWitSetUpInitializationTest extends CodeInsightTestCas
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testOrderInSetup() throws Exception {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void doTest() throws Exception {
|
private void doTest() throws Exception {
|
||||||
configureByFile("/refactoring/introduceField/before" + getTestName(false) + ".java");
|
configureByFile("/refactoring/introduceField/before" + getTestName(false) + ".java");
|
||||||
|
|||||||
Reference in New Issue
Block a user