diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/types/ReplaceLambdaWithAnonymousIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/types/ReplaceLambdaWithAnonymousIntention.java index 78fc86da423a..5a5dc8258841 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/types/ReplaceLambdaWithAnonymousIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/types/ReplaceLambdaWithAnonymousIntention.java @@ -51,6 +51,7 @@ public class ReplaceLambdaWithAnonymousIntention extends Intention { protected void processIntention(Editor editor, @NotNull PsiElement element) throws IncorrectOperationException { final PsiLambdaExpression lambdaExpression = PsiTreeUtil.getParentOfType(element, PsiLambdaExpression.class); LOG.assertTrue(lambdaExpression != null); + final PsiParameter[] paramListCopy = ((PsiParameterList)lambdaExpression.getParameterList().copy()).getParameters(); PsiType functionalInterfaceType = lambdaExpression.getFunctionalInterfaceType(); LOG.assertTrue(functionalInterfaceType != null); functionalInterfaceType = GenericsUtil.eliminateWildcards(functionalInterfaceType); @@ -69,6 +70,14 @@ public class ReplaceLambdaWithAnonymousIntention extends Intention { final List> infos = OverrideImplementUtil.overrideOrImplement(anonymousClass, method); if (infos != null && infos.size() == 1) { final PsiMethod member = infos.get(0).getPsiMember(); + final PsiParameter[] parameters = member.getParameterList().getParameters(); + for (int i = 0; i < parameters.length; i++) { + final PsiParameter parameter = parameters[i]; + final String lambdaParamName = paramListCopy[i].getName(); + if (lambdaParamName != null) { + parameter.setName(lambdaParamName); + } + } PsiCodeBlock codeBlock = member.getBody(); LOG.assertTrue(codeBlock != null); codeBlock = (PsiCodeBlock)codeBlock.replace(psiElementFactory.createCodeBlockFromText(blockText, null)); diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/lambda2anonymous/RenameParams.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/lambda2anonymous/RenameParams.java new file mode 100644 index 000000000000..d3a7499d1450 --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/lambda2anonymous/RenameParams.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +class Test { + interface Some { + void test(int p1, int p2); + } + + { + Some some = (i1, i2) -> { + System.out.println(i1 + i2); + }; + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/lambda2anonymous/RenameParams_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/lambda2anonymous/RenameParams_after.java new file mode 100644 index 000000000000..4bdd78b9b874 --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/types/lambda2anonymous/RenameParams_after.java @@ -0,0 +1,29 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +class Test { + interface Some { + void test(int p1, int p2); + } + + { + Some some = new Some() { + @Override + public void test(int i1, int i2) { + System.out.println(i1 + i2); + } + }; + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/types/ReplaceLambdaWithAnonymousIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/types/ReplaceLambdaWithAnonymousIntentionTest.java index 6f77340da4b1..cbb85e819988 100644 --- a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/types/ReplaceLambdaWithAnonymousIntentionTest.java +++ b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/types/ReplaceLambdaWithAnonymousIntentionTest.java @@ -31,6 +31,10 @@ public class ReplaceLambdaWithAnonymousIntentionTest extends IPPTestCase { doTest(); } + public void testRenameParams() { + doTest(); + } + public void testInsertFinal() { doTest(); }