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
;
15 public class InlineParameterTest
extends LightCodeInsightTestCase
{
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
{
29 public void testNullValue() throws Exception
{
33 public void testConstructorCall() throws Exception
{
37 public void testStaticFinalField() throws Exception
{
41 public void testRefIdentical() throws Exception
{
45 public void testRefIdenticalNoLocal() throws Exception
{
49 public void testRefLocalConstantInitializer() throws Exception
{
53 public void testRefLocalWithLocal() throws Exception
{
57 public void testRefMethod() throws Exception
{
61 public void testRefMethodOnLocal() throws Exception
{
65 public void testRefFinalLocal() throws Exception
{
69 public void testRefStaticField() throws Exception
{
73 public void testRefFinalLocalInitializedWithMethod() throws Exception
{
77 public void testRefSelfField() throws Exception
{
81 public void testRefOuterThis() throws Exception
{
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
{
94 public void testRefQualifiedThis() throws Exception
{
98 public void testRefSameNonFinalField() throws Exception
{
102 public void testRefSameNonFinalFieldOtherObject() throws Exception
{
106 catch (CommonRefactoringUtil
.RefactoringErrorHintException e
) {
107 assertEquals("Cannot find constant initializer for parameter", e
.getMessage());
111 public void testRef2ConstantsWithTheSameValue() throws Exception
{
115 public void testRefConstantAndField() throws Exception
{
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
);
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
);