diff --git a/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java b/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java index 080a74e6dc7a..dd5d6aa995f7 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceParameter/AbstractJavaInplaceIntroducer.java @@ -132,8 +132,16 @@ public abstract class AbstractJavaInplaceIntroducer extends AbstractInplaceIntro if (expression == null) { expression = PsiTreeUtil.getParentOfType(refVariableElement, PsiExpression.class); } - if (expression instanceof PsiReferenceExpression && expression.getParent() instanceof PsiMethodCallExpression) { - expression = (PsiExpression)expression.getParent(); + while (expression instanceof PsiReferenceExpression) { + final PsiElement parent = expression.getParent(); + if (parent instanceof PsiMethodCallExpression) { + if (parent.getText().equals(exprText)) return (PsiExpression)parent; + } + if (parent instanceof PsiExpression) { + expression = (PsiExpression)parent; + } else { + return null; + } } return expression != null && expression.isValid() && expression.getText().equals(exprText) ? expression : null; } diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceParameter/replaceAll1.java b/java/java-tests/testData/refactoring/inplaceIntroduceParameter/replaceAll1.java new file mode 100644 index 000000000000..663a918624d3 --- /dev/null +++ b/java/java-tests/testData/refactoring/inplaceIntroduceParameter/replaceAll1.java @@ -0,0 +1,59 @@ +public abstract class PartnerAuthenticationInterceptor { + + + protected boolean validateProtection(PartnerAuthentication partnerAuthentication) { + tryPartnerAuthenticationTypes(partnerAuthentication, validated, ip, partner, "serviceGroup"); + + return false; + } + + + private boolean tryPartnerAuthenticationTypes(PartnerAuthentication partnerAuthentication, boolean validated, String ip, String partner, String serviceGroup) { + if (partnerAuthentication.type() == PartnerAuthenticationType.IP_PARTNER_ID) { + + } else if (partnerAuthentication.type() == PartnerAuthenticationType.IP) { + } + return validated; + } + + + private class PartnerAuthentication { + public String serviceGroup() { + return null; //To change body of created methods use File | Settings | File Templates. + } + + public String type() { + return null; + } + } + + private static class PartnerIdHolder { + private static PartnerIP partnerIP; + + public static PartnerIP getPartnerIP() { + return partnerIP; + } + } + + private class PartnerIP { + private String ip; + private String partner; + private boolean valid; + + public String getIp() { + return ip; + } + + public String getPartner() { + return partner; + } + + public boolean isValid() { + return valid; + } + } + + private class PartnerAuthenticationType { + public static final String IP_PARTNER_ID = "id"; + } +} diff --git a/java/java-tests/testData/refactoring/inplaceIntroduceParameter/replaceAll1_after.java b/java/java-tests/testData/refactoring/inplaceIntroduceParameter/replaceAll1_after.java new file mode 100644 index 000000000000..b40cea1f0bd8 --- /dev/null +++ b/java/java-tests/testData/refactoring/inplaceIntroduceParameter/replaceAll1_after.java @@ -0,0 +1,59 @@ +public abstract class PartnerAuthenticationInterceptor { + + + protected boolean validateProtection(PartnerAuthentication partnerAuthentication) { + tryPartnerAuthenticationTypes(validated, ip, partner, "serviceGroup", partnerAuthentication.type()); + + return false; + } + + + private boolean tryPartnerAuthenticationTypes(boolean validated, String ip, String partner, String serviceGroup, String type) { + if (type == PartnerAuthenticationType.IP_PARTNER_ID) { + + } else if (type == PartnerAuthenticationType.IP) { + } + return validated; + } + + + private class PartnerAuthentication { + public String serviceGroup() { + return null; //To change body of created methods use File | Settings | File Templates. + } + + public String type() { + return null; + } + } + + private static class PartnerIdHolder { + private static PartnerIP partnerIP; + + public static PartnerIP getPartnerIP() { + return partnerIP; + } + } + + private class PartnerIP { + private String ip; + private String partner; + private boolean valid; + + public String getIp() { + return ip; + } + + public String getPartner() { + return partner; + } + + public boolean isValid() { + return valid; + } + } + + private class PartnerAuthenticationType { + public static final String IP_PARTNER_ID = "id"; + } +} diff --git a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceParameterTest.java b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceParameterTest.java index 92c9234a9470..4ee036833c0c 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceParameterTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/InplaceIntroduceParameterTest.java @@ -41,6 +41,15 @@ public class InplaceIntroduceParameterTest extends AbstractJavaInplaceIntroduceT }); } + public void testReplaceAll1() throws Exception { + doTest(new Pass() { + @Override + public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) { + inplaceIntroduceFieldPopup.setReplaceAllOccurrences(true); + } + }); + } + public void testReplaceAllMethodCalls() throws Exception { doTest(new Pass() { @Override