inline parameter: make it public; allow to inline refs to the same non final fields...
[fedora-idea.git] / java / java-tests / testSrc / com / intellij / refactoring / inline / InlineParameterTest.java
blob4c12817ee32d4899b41cf801dfcc3ae67966f426
1 package com.intellij.refactoring.inline;
3 import com.intellij.JavaTestUtil;
4 import com.intellij.codeInsight.TargetElementUtilBase;
5 import com.intellij.openapi.projectRoots.Sdk;
6 import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
7 import com.intellij.psi.PsiElement;
8 import com.intellij.refactoring.util.CommonRefactoringUtil;
9 import com.intellij.testFramework.LightCodeInsightTestCase;
10 import org.jetbrains.annotations.NonNls;
12 /**
13 * @author yole
15 public class InlineParameterTest extends LightCodeInsightTestCase {
16 @Override
17 protected String getTestDataPath() {
18 return JavaTestUtil.getJavaTestDataPath();
21 protected Sdk getProjectJDK() {
22 return JavaSdkImpl.getMockJdk15("java 1.5");
25 public void testSameValue() throws Exception {
26 doTest(true);
29 public void testNullValue() throws Exception {
30 doTest(true);
33 public void testConstructorCall() throws Exception {
34 doTest(true);
37 public void testStaticFinalField() throws Exception {
38 doTest(true);
41 public void testRefIdentical() throws Exception {
42 doTest(true);
45 public void testRefIdenticalNoLocal() throws Exception {
46 doTest(false);
49 public void testRefLocalConstantInitializer() throws Exception {
50 doTest(false);
53 public void testRefLocalWithLocal() throws Exception {
54 doTest(false);
57 public void testRefMethod() throws Exception {
58 doTest(true);
61 public void testRefMethodOnLocal() throws Exception {
62 doTest(false);
65 public void testRefFinalLocal() throws Exception {
66 doTest(true);
69 public void testRefStaticField() throws Exception {
70 doTest(true);
73 public void testRefFinalLocalInitializedWithMethod() throws Exception {
74 doTest(false);
77 public void testRefSelfField() throws Exception {
78 doTest(false);
81 public void testRefOuterThis() throws Exception {
82 try {
83 doTest(false);
85 catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
86 assertEquals("Parameter initializer depends on values which are not available inside the method and cannot be inlined", e.getMessage());
90 public void testRefThis() throws Exception {
91 doTest(false);
94 public void testRefQualifiedThis() throws Exception {
95 doTest(false);
98 public void testRefSameNonFinalField() throws Exception {
99 doTest(false);
102 public void testRefSameNonFinalFieldOtherObject() throws Exception {
103 try {
104 doTest(false);
106 catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
107 assertEquals("Cannot find constant initializer for parameter", e.getMessage());
111 public void testRef2ConstantsWithTheSameValue() throws Exception {
112 doTest(false);
115 public void testRefConstantAndField() throws Exception {
116 try {
117 doTest(false);
119 catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
120 assertEquals("Cannot find constant initializer for parameter", e.getMessage());
124 private void doTest(final boolean createLocal) throws Exception {
125 getProject().putUserData(InlineParameterExpressionProcessor.CREATE_LOCAL_FOR_TESTS,createLocal);
127 String name = getTestName(false);
128 @NonNls String fileName = "/refactoring/inlineParameter/" + name + ".java";
129 configureByFile(fileName);
130 performAction();
131 checkResultByFile(null, fileName + ".after", true);
134 private static void performAction() {
135 final PsiElement element = TargetElementUtilBase.findTargetElement(myEditor, TargetElementUtilBase
136 .REFERENCED_ELEMENT_ACCEPTED | TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
137 new InlineParameterHandler().inlineElement(getProject(), myEditor, element);