1e3a7529b21dc82339fb7ea217ba2e78063deed5
[fedora-idea.git] / java / java-tests / testSrc / com / intellij / refactoring / inline / InlineParameterTest.java
blob1e3a7529b21dc82339fb7ea217ba2e78063deed5
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.BaseRefactoringProcessor;
9 import com.intellij.refactoring.util.CommonRefactoringUtil;
10 import com.intellij.testFramework.LightCodeInsightTestCase;
11 import org.jetbrains.annotations.NonNls;
13 /**
14 * @author yole
17 public class InlineParameterTest extends LightCodeInsightTestCase {
18 @Override
19 protected String getTestDataPath() {
20 return JavaTestUtil.getJavaTestDataPath();
23 protected Sdk getProjectJDK() {
24 return JavaSdkImpl.getMockJdk15("java 1.5");
27 public void testSameValue() throws Exception {
28 doTest(true);
31 public void testNullValue() throws Exception {
32 doTest(true);
35 public void testConstructorCall() throws Exception {
36 doTest(true);
39 public void testStaticFinalField() throws Exception {
40 doTest(true);
43 public void testRefIdentical() throws Exception {
44 doTest(true);
47 public void testRefIdenticalNoLocal() throws Exception {
48 doTest(false);
51 public void testRefLocalConstantInitializer() throws Exception {
52 doTest(false);
55 public void testRefLocalWithLocal() throws Exception {
56 doTest(false);
59 public void testRefMethod() throws Exception {
60 doTest(true);
63 public void testRefMethodOnLocal() throws Exception {
64 doTest(false);
67 public void testRefFinalLocal() throws Exception {
68 doTest(true);
71 public void testRefStaticField() throws Exception {
72 doTest(true);
75 public void testRefFinalLocalInitializedWithMethod() throws Exception {
76 doTest(false);
79 public void testRefSelfField() throws Exception {
80 doTest(false);
83 public void testRefStaticMethod() throws Exception {
84 doTest(true);
87 public void testRefOuterThis() throws Exception {
88 try {
89 doTest(false);
91 catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
92 assertEquals("Parameter initializer depends on this which is not available inside the method and cannot be inlined", e.getMessage());
96 public void testRefThis() throws Exception {
97 doTest(false);
100 public void testRefQualifiedThis() throws Exception {
101 doTest(false);
104 public void testRefSameNonFinalField() throws Exception {
105 doTest(false);
108 public void testRefSameNonFinalFieldOtherObject() throws Exception {
109 doTestCannotFindInitializer();
112 public void testRef2ConstantsWithTheSameValue() throws Exception {
113 doTest(false);
116 public void testRefConstantAndField() throws Exception {
117 doTestCannotFindInitializer();
120 public void testRefNewInner() throws Exception {
121 try {
122 doTest(false);
124 catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
125 assertEquals("Parameter initializer depends on class <b><code>User.Local</code></b> which is not available inside method and cannot be inlined", e.getMessage());
129 public void testRefNewInnerForMethod() throws Exception {
130 doTest(false);
133 public void testRefNewInnerAvailable() throws Exception {
134 doTest(false);
137 public void testRefNewInnerFromMethod() throws Exception {
138 try {
139 doTest(false);
141 catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
142 assertEquals("Parameter initializer depends on class <b><code>Local</code></b> which is not available inside method and cannot be inlined", e.getMessage());
146 public void testRefNewInnerInHierarchyAvailable() throws Exception {
147 doTest(false);
150 public void testRefNewTopLevel() throws Exception {
151 doTest(false);
154 public void testRefNewLocal() throws Exception {
155 try {
156 doTest(false);
158 catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
159 assertEquals("Parameter initializer depends on class <b><code>Local</code></b> which is not available inside method and cannot be inlined", e.getMessage());
163 public void testRefArrayAccess() throws Exception {
164 try {
165 doTest(false);
167 catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
168 assertEquals("Parameter initializer depends on value which is not available inside method and cannot be inlined", e.getMessage());
172 public void testRefCallerParameter() throws Exception {
173 try {
174 doTest(false);
176 catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
177 assertEquals("Parameter initializer depends on callers parameter", e.getMessage());
182 public void testHandleExceptions() throws Exception {
183 doTest(false);
186 private void doTestCannotFindInitializer() throws Exception {
187 try {
188 doTest(false);
190 catch (CommonRefactoringUtil.RefactoringErrorHintException e) {
191 assertEquals("Cannot find constant initializer for parameter", e.getMessage());
195 public void testRefNonStatic() throws Exception {
196 try {
197 doTest(false);
199 catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
200 assertEquals("Parameter initializer depends on method <b><code>provideObject()</code></b> which is not available inside the static method", e.getMessage());
204 public void testRefNonStaticClass() throws Exception {
205 try {
206 doTest(false);
208 catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
209 assertEquals("Parameter initializer depends on non static class which is not available inside static method", e.getMessage());
213 public void testRefThisFromStatic() throws Exception {
214 try {
215 doTest(false);
217 catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
218 assertEquals("Parameter initializer depends on this which is not available inside the static method", e.getMessage());
222 public void testVisibility() throws Exception {
223 try {
224 doTest(false);
226 catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
227 assertEquals("Parameter initializer depends on value which is not available inside method", e.getMessage());
231 public void testWriteAccess() throws Exception {
232 try {
233 doTest(false);
235 catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
236 assertEquals("Parameter initializer depends on value which is not available inside method and cannot be inlined", e.getMessage());
240 private void doTest(final boolean createLocal) throws Exception {
241 getProject().putUserData(InlineParameterExpressionProcessor.CREATE_LOCAL_FOR_TESTS,createLocal);
243 String name = getTestName(false);
244 @NonNls String fileName = "/refactoring/inlineParameter/" + name + ".java";
245 configureByFile(fileName);
246 performAction();
247 checkResultByFile(null, fileName + ".after", true);
250 private static void performAction() {
251 final PsiElement element = TargetElementUtilBase.findTargetElement(myEditor, TargetElementUtilBase
252 .REFERENCED_ELEMENT_ACCEPTED | TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
253 new InlineParameterHandler().inlineElement(getProject(), myEditor, element);