diff --git a/plugins/IntentionPowerPak/src/com/siyeh/ipp/varargs/MakeMethodVarargsIntention.java b/plugins/IntentionPowerPak/src/com/siyeh/ipp/varargs/MakeMethodVarargsIntention.java index 016d4bd396f5..2b0617c673a6 100644 --- a/plugins/IntentionPowerPak/src/com/siyeh/ipp/varargs/MakeMethodVarargsIntention.java +++ b/plugins/IntentionPowerPak/src/com/siyeh/ipp/varargs/MakeMethodVarargsIntention.java @@ -15,6 +15,7 @@ */ package com.siyeh.ipp.varargs; +import com.intellij.openapi.diagnostic.Logger; import com.intellij.psi.*; import com.intellij.psi.search.searches.ReferencesSearch; import com.intellij.util.IncorrectOperationException; @@ -25,6 +26,8 @@ import org.jetbrains.annotations.NotNull; public class MakeMethodVarargsIntention extends Intention { + private static final Logger LOG = Logger.getInstance("#" + MakeMethodVarargsIntention.class.getName()); + @NotNull protected PsiElementPredicate getElementPredicate() { return new MakeMethodVarargsPredicate(); @@ -42,14 +45,11 @@ public class MakeMethodVarargsIntention extends Intention { final PsiParameter[] parameters = parameterList.getParameters(); final PsiParameter lastParameter = parameters[parameters.length - 1]; final PsiType type = lastParameter.getType(); - final PsiType componentType = type.getDeepComponentType(); - final String text = componentType.getCanonicalText(); - final PsiManager manager = element.getManager(); - final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(); - final PsiParameter newParameter = - factory.createParameterFromText(text + "... " + - lastParameter.getName(), element); - lastParameter.replace(newParameter); + final PsiElementFactory factory = JavaPsiFacade.getInstance(element.getProject()).getElementFactory(); + final PsiTypeElement typeElement = lastParameter.getTypeElement(); + LOG.assertTrue(typeElement != null); + final PsiType ellipsisType = PsiEllipsisType.createEllipsis(((PsiArrayType)type).getComponentType(), type.getAnnotations()); + typeElement.replace(factory.createTypeElement(ellipsisType)); } private static void makeMethodCallsVarargs(PsiElement element) diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/varargs/make_method_varargs/DeepArray.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/varargs/make_method_varargs/DeepArray.java new file mode 100644 index 000000000000..eb62e9ad9d91 --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/varargs/make_method_varargs/DeepArray.java @@ -0,0 +1,8 @@ +class Test { + public void foo(final String[][] arg) { + } + + { + foo(new String[][]{}); + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/varargs/make_method_varargs/DeepArray_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/varargs/make_method_varargs/DeepArray_after.java new file mode 100644 index 000000000000..971148ca2481 --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/varargs/make_method_varargs/DeepArray_after.java @@ -0,0 +1,8 @@ +class Test { + public void foo(final String[]... arg) { + } + + { + foo(); + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/varargs/make_method_varargs/Final.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/varargs/make_method_varargs/Final.java new file mode 100644 index 000000000000..1a36d0462efd --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/varargs/make_method_varargs/Final.java @@ -0,0 +1,8 @@ +class Test { + public void foo(final String[] arg) { + } + + { + foo(new String[]{}); + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/test/com/siyeh/ipp/varargs/make_method_varargs/Final_after.java b/plugins/IntentionPowerPak/test/com/siyeh/ipp/varargs/make_method_varargs/Final_after.java new file mode 100644 index 000000000000..412fd976d26d --- /dev/null +++ b/plugins/IntentionPowerPak/test/com/siyeh/ipp/varargs/make_method_varargs/Final_after.java @@ -0,0 +1,8 @@ +class Test { + public void foo(final String... arg) { + } + + { + foo(); + } +} \ No newline at end of file diff --git a/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/varargs/MakeMethodVarargsIntentionTest.java b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/varargs/MakeMethodVarargsIntentionTest.java new file mode 100644 index 000000000000..d034b2cc02f1 --- /dev/null +++ b/plugins/IntentionPowerPak/testSrc/com/siyeh/ipp/varargs/MakeMethodVarargsIntentionTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2000-2013 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. + */ +package com.siyeh.ipp.varargs; + +import com.siyeh.IntentionPowerPackBundle; +import com.siyeh.ipp.IPPTestCase; + +public class MakeMethodVarargsIntentionTest extends IPPTestCase { + + public void testFinal() { doTest(); } + public void testDeepArray() { doTest(); } + + @Override + protected String getRelativePath() { + return "varargs/make_method_varargs"; + } + + @Override + protected String getIntentionName() { + return IntentionPowerPackBundle.message("make.method.varargs.intention.name"); + } +} \ No newline at end of file