From 57081fdd4edffdcbc2530f9f6abcd73faf7c949c Mon Sep 17 00:00:00 2001 From: anna Date: Wed, 3 Apr 2013 16:09:39 +0200 Subject: [PATCH] introduce parameter: ignore parts of qualified name (IDEA-104485) --- .../IntroduceVariableBase.java | 18 ++++++++++++++---- .../afterPackageReferenceShouldBeIgnored.java | 8 ++++++++ .../beforePackageReferenceShouldBeIgnored.java | 6 ++++++ .../refactoring/IntroduceParameterTest.java | 4 ++++ 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 java/java-tests/testData/refactoring/introduceParameter/afterPackageReferenceShouldBeIgnored.java create mode 100644 java/java-tests/testData/refactoring/introduceParameter/beforePackageReferenceShouldBeIgnored.java diff --git a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java index 3423cca5bd30..b2aa15916b26 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceVariable/IntroduceVariableBase.java @@ -197,12 +197,22 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase { PsiExpression expression = PsiTreeUtil.getParentOfType(elementAtCaret, PsiExpression.class); while (expression != null) { if (!expressions.contains(expression) && !(expression instanceof PsiParenthesizedExpression) && !(expression instanceof PsiSuperExpression) && expression.getType() != PsiType.VOID) { - if (expression instanceof PsiMethodReferenceExpression || - !(expression instanceof PsiReferenceExpression && - (expression.getParent() instanceof PsiMethodCallExpression || ((PsiReferenceExpression)expression).resolve() instanceof PsiClass)) && - !(expression instanceof PsiAssignmentExpression)) { + if (expression instanceof PsiMethodReferenceExpression) { expressions.add(expression); } + else if (!(expression instanceof PsiAssignmentExpression)) { + if (!(expression instanceof PsiReferenceExpression)) { + expressions.add(expression); + } + else { + if (!(expression.getParent() instanceof PsiMethodCallExpression)) { + final PsiElement resolve = ((PsiReferenceExpression)expression).resolve(); + if (!(resolve instanceof PsiClass) && !(resolve instanceof PsiPackage)) { + expressions.add(expression); + } + } + } + } } expression = PsiTreeUtil.getParentOfType(expression, PsiExpression.class); } diff --git a/java/java-tests/testData/refactoring/introduceParameter/afterPackageReferenceShouldBeIgnored.java b/java/java-tests/testData/refactoring/introduceParameter/afterPackageReferenceShouldBeIgnored.java new file mode 100644 index 000000000000..b889350d504c --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameter/afterPackageReferenceShouldBeIgnored.java @@ -0,0 +1,8 @@ +import java.io.File; + +class Test { + public void foo(final File anObject) { + bar(anObject); + } + void bar(java.io.File f){} +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/introduceParameter/beforePackageReferenceShouldBeIgnored.java b/java/java-tests/testData/refactoring/introduceParameter/beforePackageReferenceShouldBeIgnored.java new file mode 100644 index 000000000000..d52aef3cede7 --- /dev/null +++ b/java/java-tests/testData/refactoring/introduceParameter/beforePackageReferenceShouldBeIgnored.java @@ -0,0 +1,6 @@ +class Test { + public void foo() { + bar(java.io.File.createTempFile("a", "b")); + } + void bar(java.io.File f){} +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java index 59d5ca1ad847..5fff2193ee83 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/IntroduceParameterTest.java @@ -316,6 +316,10 @@ public class IntroduceParameterTest extends LightRefactoringTestCase { doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, false, true, false); } + public void testPackageReferenceShouldBeIgnored() throws Exception { + doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, false, true, false); + } + private void doTestThroughHandler() throws Exception { configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java"); boolean enabled = true;