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
;
17 public class InlineParameterTest
extends LightCodeInsightTestCase
{
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
{
31 public void testNullValue() throws Exception
{
35 public void testConstructorCall() throws Exception
{
39 public void testStaticFinalField() throws Exception
{
43 public void testRefIdentical() throws Exception
{
47 public void testRefIdenticalNoLocal() throws Exception
{
51 public void testRefLocalConstantInitializer() throws Exception
{
55 public void testRefLocalWithLocal() throws Exception
{
59 public void testRefMethod() throws Exception
{
63 public void testRefMethodOnLocal() throws Exception
{
67 public void testRefFinalLocal() throws Exception
{
71 public void testRefStaticField() throws Exception
{
75 public void testRefFinalLocalInitializedWithMethod() throws Exception
{
79 public void testRefSelfField() throws Exception
{
83 public void testRefStaticMethod() throws Exception
{
87 public void testRefOuterThis() throws Exception
{
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
{
100 public void testRefQualifiedThis() throws Exception
{
104 public void testRefSameNonFinalField() throws Exception
{
108 public void testRefSameNonFinalFieldOtherObject() throws Exception
{
109 doTestCannotFindInitializer();
112 public void testRef2ConstantsWithTheSameValue() throws Exception
{
116 public void testRefConstantAndField() throws Exception
{
117 doTestCannotFindInitializer();
120 public void testRefNewInner() throws Exception
{
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
{
133 public void testRefNewInnerAvailable() throws Exception
{
137 public void testRefNewInnerFromMethod() throws Exception
{
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
{
150 public void testRefNewTopLevel() throws Exception
{
154 public void testRefNewLocal() throws Exception
{
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
{
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
{
176 catch (BaseRefactoringProcessor
.ConflictsInTestsException e
) {
177 assertEquals("Parameter initializer depends on callers parameter", e
.getMessage());
182 public void testHandleExceptions() throws Exception
{
186 private void doTestCannotFindInitializer() throws Exception
{
190 catch (CommonRefactoringUtil
.RefactoringErrorHintException e
) {
191 assertEquals("Cannot find constant initializer for parameter", e
.getMessage());
195 public void testRefNonStatic() throws Exception
{
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
{
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
{
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
{
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
{
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
);
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
);