diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java index a152842b20de..ea51929510e1 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageFix.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.daemon.impl.quickfix; import com.intellij.codeInsight.FileModificationService; @@ -46,6 +46,8 @@ import org.jetbrains.annotations.Nullable; import java.util.*; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + /** * @author cdr */ @@ -420,7 +422,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction/*, Hig if (!PsiTypesUtil.allTypeParametersResolved(myTargetMethod, exprType)) return false; JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(expression.getProject()); String name = suggestUniqueParameterName(codeStyleManager, expression, exprType, existingNames); - final ParameterInfoImpl newParameterInfo = new ParameterInfoImpl(-1, name, exprType, expression.getText().replace('\n', ' ')); + final ParameterInfoImpl newParameterInfo = new ParameterInfoImpl(NEW_PARAMETER, name, exprType, expression.getText().replace('\n', ' ')); result.add(newParameterInfo); newParams.add(newParameterInfo); buf.append("").append(escapePresentableType(exprType)).append(""); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageReverseOrderFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageReverseOrderFix.java index 10d42bb69473..c6abd05d8a3e 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageReverseOrderFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/ChangeMethodSignatureFromUsageReverseOrderFix.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.daemon.impl.quickfix; import com.intellij.openapi.editor.Editor; @@ -30,6 +16,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + public class ChangeMethodSignatureFromUsageReverseOrderFix extends ChangeMethodSignatureFromUsageFix { public ChangeMethodSignatureFromUsageReverseOrderFix(@NotNull PsiMethod targetMethod, PsiExpression @NotNull [] expressions, @@ -106,7 +94,7 @@ public class ChangeMethodSignatureFromUsageReverseOrderFix extends ChangeMethodS if (exprType == null) return false; JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(expression.getProject()); String name = suggestUniqueParameterName(codeStyleManager, expression, exprType, existingNames); - final ParameterInfoImpl newParameterInfo = new ParameterInfoImpl(-1, name, exprType, expression.getText().replace('\n', ' ')); + final ParameterInfoImpl newParameterInfo = new ParameterInfoImpl(NEW_PARAMETER, name, exprType, expression.getText().replace('\n', ' ')); result.add(0, newParameterInfo); newParams.add(newParameterInfo); params.add(0, "" + escapePresentableType(exprType) + ""); diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java index 67e2ad79de98..7f0b2f779abc 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateConstructorParameterFromFieldFix.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.daemon.impl.quickfix; import com.intellij.codeInsight.FileModificationService; @@ -54,6 +40,8 @@ import org.jetbrains.annotations.Nullable; import java.util.*; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + public class CreateConstructorParameterFromFieldFix implements IntentionAction { private static final Key, Boolean>> FIELDS = Key.create("CONSTRUCTOR_PARAMS"); @@ -261,7 +249,7 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction { settings.PREFER_LONGER_NAMES = preferLongerNames || types.get(paramType).size() > 1; final String uniqueParameterName = getUniqueParameterName(parameters, param, usedFields); usedFields.put((PsiField)param, uniqueParameterName); - newParamInfos[i++] = new ParameterInfoImpl(-1, uniqueParameterName, paramType, uniqueParameterName); + newParamInfos[i++] = new ParameterInfoImpl(NEW_PARAMETER, uniqueParameterName, paramType, uniqueParameterName); } finally { settings.PREFER_LONGER_NAMES = preferLongerNames; diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateParameterFromUsageFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateParameterFromUsageFix.java index c52ab2d05be2..eb3f694221bd 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateParameterFromUsageFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/CreateParameterFromUsageFix.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2015 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.daemon.impl.quickfix; import com.intellij.codeInsight.daemon.QuickFixBundle; @@ -41,6 +27,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + /** * @author Mike */ @@ -97,7 +85,7 @@ public class CreateParameterFromUsageFix extends CreateVarFromUsageFix { final List parameterInfos = new ArrayList<>(Arrays.asList(ParameterInfoImpl.fromMethod(method))); - ParameterInfoImpl parameterInfo = new ParameterInfoImpl(-1, varName, type, varName, false); + ParameterInfoImpl parameterInfo = new ParameterInfoImpl(NEW_PARAMETER, varName, type, varName, false); if (!method.isVarArgs()) { parameterInfos.add(parameterInfo); } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MethodParameterFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MethodParameterFix.java index 8a0bac0d88ca..a79751b53028 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MethodParameterFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/quickfix/MethodParameterFix.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.daemon.impl.quickfix; import com.intellij.codeInsight.FileModificationService; @@ -39,6 +25,8 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + public class MethodParameterFix extends LocalQuickFixAndIntentionActionOnPsiElement { private static final Logger LOG = Logger.getInstance(MethodParameterFix.class); @@ -140,7 +128,7 @@ public class MethodParameterFix extends LocalQuickFixAndIntentionActionOnPsiElem result.add(new ParameterInfoImpl(i, parameter.getName(), parameter.getType())); } if (parameters.length == myIndex) { - result.add(new ParameterInfoImpl(-1, newParameter.getName(), newParameter.getType())); + result.add(new ParameterInfoImpl(NEW_PARAMETER, newParameter.getName(), newParameter.getType())); } return result.toArray(new ParameterInfoImpl[0]); } diff --git a/java/java-impl/src/com/intellij/refactoring/changeSignature/DetectedJavaChangeInfo.java b/java/java-impl/src/com/intellij/refactoring/changeSignature/DetectedJavaChangeInfo.java index 9864c6c8a705..c88facdc46a9 100644 --- a/java/java-impl/src/com/intellij/refactoring/changeSignature/DetectedJavaChangeInfo.java +++ b/java/java-impl/src/com/intellij/refactoring/changeSignature/DetectedJavaChangeInfo.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.refactoring.changeSignature; import com.intellij.codeInsight.daemon.impl.quickfix.DefineParamsDefaultValueAction; @@ -42,6 +28,8 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + class DetectedJavaChangeInfo extends JavaChangeInfoImpl { private PsiMethod mySuperMethod; private final String[] myModifiers; @@ -242,7 +230,7 @@ class DetectedJavaChangeInfo extends JavaChangeInfoImpl { } final CanonicalTypes.Type typeWrapper = parameterInfo.getTypeWrapper(); if (!typeWrapper.isValid()) return false; - parameterInfos[i] = new ParameterInfoImpl(oldParameter != null ? oldParameter.getOldIndex() : -1, + parameterInfos[i] = new ParameterInfoImpl(oldParameter != null ? oldParameter.getOldIndex() : NEW_PARAMETER, parameterInfo.getName(), typeWrapper, null); diff --git a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaParameterTableModel.java b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaParameterTableModel.java index 4348fbe9ab5c..0e556018b904 100644 --- a/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaParameterTableModel.java +++ b/java/java-impl/src/com/intellij/refactoring/changeSignature/JavaParameterTableModel.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.refactoring.changeSignature; import com.intellij.codeInsight.completion.JavaCompletionUtil; @@ -48,6 +34,8 @@ import java.awt.event.KeyEvent; import java.util.LinkedHashSet; import java.util.Set; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + public class JavaParameterTableModel extends ParameterTableModelBase> { private final Project myProject; @@ -80,7 +68,7 @@ public class JavaParameterTableModel extends ParameterTableModelBase createRowItem(@Nullable ParameterInfoImpl parameterInfo) { if (parameterInfo == null) { - parameterInfo = new ParameterInfoImpl(-1); + parameterInfo = new ParameterInfoImpl(NEW_PARAMETER); } JavaCodeFragmentFactory f = JavaCodeFragmentFactory.getInstance(myProject); final PsiTypeCodeFragment paramTypeCodeFragment = diff --git a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/JavaIntroduceParameterObjectDelegate.java b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/JavaIntroduceParameterObjectDelegate.java index 86e7d76035f8..b672debfd702 100644 --- a/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/JavaIntroduceParameterObjectDelegate.java +++ b/java/java-impl/src/com/intellij/refactoring/introduceparameterobject/JavaIntroduceParameterObjectDelegate.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.refactoring.introduceparameterobject; import com.intellij.codeInsight.highlighting.ReadWriteAccessDetector; @@ -49,6 +35,8 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + public class JavaIntroduceParameterObjectDelegate extends IntroduceParameterObjectDelegate { @@ -86,7 +74,7 @@ public class JavaIntroduceParameterObjectDelegate final String classTypeText = descriptor.createFakeClassTypeText(); final JavaPsiFacade facade = JavaPsiFacade.getInstance(project); - return new ParameterInfoImpl(-1, paramName, facade.getElementFactory().createTypeFromText(classTypeText, method), null) { + return new ParameterInfoImpl(NEW_PARAMETER, paramName, facade.getElementFactory().createTypeFromText(classTypeText, method), null) { @Nullable @Override public PsiElement getActualValue(PsiElement exp, Object substitutor) { diff --git a/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeMethodStaticProcessor.java b/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeMethodStaticProcessor.java index 34c2f10c7c88..5bb96b2b29fa 100644 --- a/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeMethodStaticProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/makeStatic/MakeMethodStaticProcessor.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.refactoring.makeStatic; import com.intellij.codeInsight.AnnotationUtil; @@ -46,6 +32,8 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + /** * @author dsl */ @@ -160,13 +148,13 @@ public class MakeMethodStaticProcessor extends MakeMethodOrClassStaticProcessor< PsiParameter[] parameters = myMember.getParameterList().getParameters(); if (mySettings.isMakeClassParameter()) { - params.add(new ParameterInfoImpl(-1, mySettings.getClassParameterName(), + params.add(new ParameterInfoImpl(NEW_PARAMETER, mySettings.getClassParameterName(), factory.createType(containingClass, PsiSubstitutor.EMPTY), "this")); } if (mySettings.isMakeFieldParameters()) { for (Settings.FieldParameter parameter : mySettings.getParameterOrderList()) { - params.add(new ParameterInfoImpl(-1, mySettings.getClassParameterName(), parameter.type, parameter.field.getName())); + params.add(new ParameterInfoImpl(NEW_PARAMETER, mySettings.getClassParameterName(), parameter.type, parameter.field.getName())); } } diff --git a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/ChangeSignatureTouchLambdaTest.java b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/ChangeSignatureTouchLambdaTest.java index b969469296fc..f3b4204417af 100644 --- a/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/ChangeSignatureTouchLambdaTest.java +++ b/java/java-tests/testSrc/com/intellij/java/codeInsight/daemon/lambda/ChangeSignatureTouchLambdaTest.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.codeInsight.daemon.lambda; import com.intellij.java.refactoring.ChangeSignatureBaseTest; @@ -20,22 +6,24 @@ import com.intellij.psi.PsiType; import com.intellij.refactoring.changeSignature.ParameterInfoImpl; import com.intellij.refactoring.changeSignature.ThrownExceptionInfo; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + public class ChangeSignatureTouchLambdaTest extends ChangeSignatureBaseTest { public void testVariableDeclaration() { - doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false); + doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false); } public void testMethodArgument() { - doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false); + doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false); } public void testDefaultMethodTouched() { - doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false); + doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false); } public void testDelegateInInterface() { - doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN, "false")}, new ThrownExceptionInfo[0], true); + doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN, "false")}, new ThrownExceptionInfo[0], true); } public void testAddExceptionToCatchInOneLineLambda() { diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/ChangeSignatureBaseTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/ChangeSignatureBaseTest.java index 4c26995bfa8e..5759a9acf35d 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/ChangeSignatureBaseTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/ChangeSignatureBaseTest.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.refactoring; import com.intellij.JavaTestUtil; @@ -29,6 +15,8 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + public abstract class ChangeSignatureBaseTest extends LightRefactoringTestCase { protected PsiElementFactory myFactory; @@ -58,7 +46,7 @@ public abstract class ChangeSignatureBaseTest extends LightRefactoringTestCase { ParameterInfoImpl[] parameterInfos = new ParameterInfoImpl[parameters.length]; for (int i = 0; i < parameters.length; i++) { PsiType type = myFactory.createTypeFromText(parameters[i], method); - parameterInfos[i] = new ParameterInfoImpl(-1, "p" + (i + 1), type); + parameterInfos[i] = new ParameterInfoImpl(NEW_PARAMETER, "p" + (i + 1), type); } return parameterInfos; }; diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/ChangeSignaturePropagationTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/ChangeSignaturePropagationTest.java index affa8b6ffb6f..521ef13c7a78 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/ChangeSignaturePropagationTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/ChangeSignaturePropagationTest.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.refactoring; import com.intellij.JavaTestUtil; @@ -36,6 +22,8 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + /** * @author ven */ @@ -74,7 +62,7 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase { } } PsiClassType stringType = PsiType.getJavaLangString(getPsiManager(), GlobalSearchScope.allScope(getProject())); - final ParameterInfoImpl[] newParameters = {new ParameterInfoImpl(-1, "param", stringType)}; + final ParameterInfoImpl[] newParameters = {new ParameterInfoImpl(NEW_PARAMETER, "param", stringType)}; BaseRefactoringProcessor.ConflictsInTestsException.withIgnoredConflicts(() -> doTest(newParameters, new ThrownExceptionInfo[0], methods, null, method)); } @@ -144,7 +132,7 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase { } private void parameterPropagationTest(final PsiMethod method, final HashSet psiMethods, final PsiType paramType) { - final ParameterInfoImpl[] newParameters = new ParameterInfoImpl[]{new ParameterInfoImpl(-1, "clazz", paramType, "null")}; + final ParameterInfoImpl[] newParameters = new ParameterInfoImpl[]{new ParameterInfoImpl(NEW_PARAMETER, "clazz", paramType, "null")}; doTest(newParameters, new ThrownExceptionInfo[0], psiMethods, null, method); } diff --git a/java/java-tests/testSrc/com/intellij/java/refactoring/ChangeSignatureTest.java b/java/java-tests/testSrc/com/intellij/java/refactoring/ChangeSignatureTest.java index cfda46affbbf..874bdb37ef59 100644 --- a/java/java-tests/testSrc/com/intellij/java/refactoring/ChangeSignatureTest.java +++ b/java/java-tests/testSrc/com/intellij/java/refactoring/ChangeSignatureTest.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.java.refactoring; import com.intellij.codeInsight.TargetElementUtil; @@ -28,6 +14,8 @@ import com.intellij.refactoring.util.CanonicalTypes; import java.util.HashSet; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + /** * @author dsl */ @@ -71,7 +59,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testDuplicatedSignatureInInheritor() { try { - doTest(null, new ParameterInfoImpl[] {new ParameterInfoImpl(-1, "i", PsiType.INT)}, true); + doTest(null, new ParameterInfoImpl[] {new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT)}, true); fail("Conflict expected"); } catch (BaseRefactoringProcessor.ConflictsInTestsException ignored) { } @@ -87,8 +75,8 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testGenericTypes() { doTest(null, null, "T", method -> new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "x", myFactory.createTypeFromText("T", method.getParameterList()), "null"), - new ParameterInfoImpl(-1, "y", myFactory.createTypeFromText("C", method.getParameterList()), "null") + new ParameterInfoImpl(NEW_PARAMETER, "x", myFactory.createTypeFromText("T", method.getParameterList()), "null"), + new ParameterInfoImpl(NEW_PARAMETER, "y", myFactory.createTypeFromText("C", method.getParameterList()), "null") }, false); } @@ -100,16 +88,16 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testTypeParametersInMethod() { doTest(null, null, null, method -> new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "t", myFactory.createTypeFromText("T", method.getParameterList()), "null"), - new ParameterInfoImpl(-1, "u", myFactory.createTypeFromText("U", method.getParameterList()), "null"), - new ParameterInfoImpl(-1, "cu", myFactory.createTypeFromText("C", method.getParameterList()), "null") + new ParameterInfoImpl(NEW_PARAMETER, "t", myFactory.createTypeFromText("T", method.getParameterList()), "null"), + new ParameterInfoImpl(NEW_PARAMETER, "u", myFactory.createTypeFromText("U", method.getParameterList()), "null"), + new ParameterInfoImpl(NEW_PARAMETER, "cu", myFactory.createTypeFromText("C", method.getParameterList()), "null") }, false); } public void testDefaultConstructor() { doTest(null, new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "j", PsiType.INT, "27") + new ParameterInfoImpl(NEW_PARAMETER, "j", PsiType.INT, "27") }, false ); } @@ -117,7 +105,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testGenerateDelegate() { doTest(null, new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "i", PsiType.INT, "27") + new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27") }, true ); } @@ -125,7 +113,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testGenerateDelegateForAbstract() { doTest(null, new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "i", PsiType.INT, "27") + new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27") }, true ); } @@ -133,7 +121,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testGenerateDelegateWithReturn() { doTest(null, new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "i", PsiType.INT, "27") + new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27") }, true ); } @@ -142,7 +130,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(1), - new ParameterInfoImpl(-1, "c", PsiType.CHAR, "'a'"), + new ParameterInfoImpl(NEW_PARAMETER, "c", PsiType.CHAR, "'a'"), new ParameterInfoImpl(0, "j", PsiType.INT) }, true ); @@ -154,7 +142,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testGenerateDelegateDefaultConstructor() { doTest(null, new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "i", PsiType.INT, "27") + new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27") }, true); } @@ -167,7 +155,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testJavadocGenericsLink() { doTest(null, new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "y", myFactory.createTypeFromText("java.util.List", null)), + new ParameterInfoImpl(NEW_PARAMETER, "y", myFactory.createTypeFromText("java.util.List", null)), new ParameterInfoImpl(0, "a", PsiType.BOOLEAN) }, false); } @@ -181,14 +169,14 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testParamNameNoConflict() { doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(0), - new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN) + new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN) }, false); } public void testVarargMethodToNonVarag() { doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(0, "i", PsiType.INT), - new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN) + new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN) }, false); } @@ -214,7 +202,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testParamJavadoc2() { doTest(null, new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "z", PsiType.BOOLEAN), + new ParameterInfoImpl(NEW_PARAMETER, "z", PsiType.BOOLEAN), new ParameterInfoImpl(0, "a", PsiType.BOOLEAN), }, false); } @@ -222,14 +210,14 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testParamJavadoc3() { doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(0, "a", PsiType.BOOLEAN), - new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN), + new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN), }, false); } public void testParamJavadocRenamedReordered() { doTest(null, new ParameterInfoImpl[]{ new ParameterInfoImpl(0, "a", PsiType.BOOLEAN), - new ParameterInfoImpl(-1, "c", PsiType.BOOLEAN), + new ParameterInfoImpl(NEW_PARAMETER, "c", PsiType.BOOLEAN), new ParameterInfoImpl(1, "b1", PsiType.BOOLEAN), }, false); } @@ -242,25 +230,25 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testSuperCallFromOtherMethod() { doTest(null, new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "nnn", PsiType.INT, "-222"), + new ParameterInfoImpl(NEW_PARAMETER, "nnn", PsiType.INT, "-222"), }, false); } public void testUseAnyVariable() { doTest(null, null, null, method -> new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "l", myFactory.createTypeFromText("List", method), "null", true) + new ParameterInfoImpl(NEW_PARAMETER, "l", myFactory.createTypeFromText("List", method), "null", true) }, false); } public void testUseThisAsAnyVariable() { doTest(null, null, null, method -> new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "l", myFactory.createTypeFromText("List", method), "null", true) + new ParameterInfoImpl(NEW_PARAMETER, "l", myFactory.createTypeFromText("List", method), "null", true) }, false); } public void testUseAnyVariableAndDefault() { doTest(null, null, null, method -> new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "c", myFactory.createTypeFromText("C", method), "null", true) + new ParameterInfoImpl(NEW_PARAMETER, "c", myFactory.createTypeFromText("C", method), "null", true) }, false); } @@ -272,13 +260,13 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testEnumConstructor() { doTest(null, new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "i", PsiType.INT, "10") + new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "10") }, false); } public void testVarargs1() { doTest(null, new ParameterInfoImpl[]{ - new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN, "true"), + new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN, "true"), new ParameterInfoImpl(0) }, false); } @@ -365,7 +353,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { } public void testIntroduceParameterWithDefaultValueInHierarchy() { - doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(-1, "i", PsiType.INT, "0")}, false); + doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "0")}, false); } public void testReorderMultilineMethodParameters() { @@ -406,7 +394,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { public void testAddParenthesisForLambdaParameterList() { GenParams genParams = method -> new ParameterInfoImpl[]{ new ParameterInfoImpl(0, "a", PsiType.INT), - new ParameterInfoImpl(-1, "b", PsiType.INT) + new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.INT) }; doTest(null, null, null, genParams, new SimpleExceptionsGen(), false, true); } @@ -481,7 +469,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { new ChangeSignatureProcessor(getProject(), method, false, null, method.getName(), CanonicalTypes.createTypeWrapper(PsiType.VOID), new ParameterInfoImpl[]{ new ParameterInfoImpl(0, parameters[0].getName(), parameters[0].getType()), - new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN)}, null, propagateParametersMethods, null + new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN)}, null, propagateParametersMethods, null ).run(); checkResultByFile(basePath + "_after.java"); } @@ -503,7 +491,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { new ChangeSignatureProcessor(getProject(), method, false, null, method.getName(), CanonicalTypes.createTypeWrapper(PsiType.VOID), new ParameterInfoImpl[]{ new ParameterInfoImpl(0, parameters[0].getName(), parameters[0].getType()), - new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN, "true")}, null, propagateParametersMethods, null + new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN, "true")}, null, propagateParametersMethods, null ).run(); checkResultByFile(basePath + "_after.java"); } @@ -523,7 +511,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest { return new ParameterInfoImpl[]{ new ParameterInfoImpl(2, "a", stringType), new ParameterInfoImpl(0, "b", stringType), - new ParameterInfoImpl(-1, "c", stringType) + new ParameterInfoImpl(NEW_PARAMETER, "c", stringType) }; }; doTest(null, null, null, genParams, new SimpleExceptionsGen(), false, false); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/CreateParameterFromUsageFix.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/CreateParameterFromUsageFix.java index 37d43f6b0893..051965edfba4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/CreateParameterFromUsageFix.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/intentions/CreateParameterFromUsageFix.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.annotator.intentions; import com.intellij.ide.util.SuperMethodWarningUtil; @@ -33,6 +33,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + /** * @author Max Medvedev */ @@ -130,7 +132,7 @@ public class CreateParameterFromUsageFix extends Intention implements MethodOrCl else { JavaChangeSignatureDialog dialog = new JavaChangeSignatureDialog(project, method, false, ref); final List parameterInfos = new ArrayList<>(Arrays.asList(ParameterInfoImpl.fromMethod(method))); - ParameterInfoImpl parameterInfo = new ParameterInfoImpl(-1, name, type, PsiTypesUtil.getDefaultValueOfType(type), false); + ParameterInfoImpl parameterInfo = new ParameterInfoImpl(NEW_PARAMETER, name, type, PsiTypesUtil.getDefaultValueOfType(type), false); if (!method.isVarArgs()) { parameterInfos.add(parameterInfo); } @@ -145,7 +147,7 @@ public class CreateParameterFromUsageFix extends Intention implements MethodOrCl private static GrParameterInfo createParameterInfo(String name, PsiType type) { String notNullName = name != null ? name : ""; String defaultValueText = GroovyToJavaGenerator.getDefaultValueText(type.getCanonicalText()); - return new GrParameterInfo(notNullName, defaultValueText, "", type, -1, false); + return new GrParameterInfo(notNullName, defaultValueText, "", type, NEW_PARAMETER, false); } @Override diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/CreateParameterForFieldIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/CreateParameterForFieldIntention.java index 91675b65af5a..28d79b90e3b1 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/CreateParameterForFieldIntention.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/CreateParameterForFieldIntention.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.intentions.control; import com.google.common.collect.Lists; @@ -48,6 +48,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + /** * @author Maxim.Medvedev */ @@ -135,7 +137,7 @@ public class CreateParameterForFieldIntention extends Intention { if (parameterName == null) { parameterName = nameValidator.validateName(suggestedNames[0], true); } - parameters.add(new GrParameterInfo(parameterName, "null", "", selectedValue.getTypeGroovy(), -1, false)); + parameters.add(new GrParameterInfo(parameterName, "null", "", selectedValue.getTypeGroovy(), NEW_PARAMETER, false)); PsiClassType[] exceptionTypes = constructor.getThrowsList().getReferencedTypes(); ThrownExceptionInfo[] thrownExceptionInfos = new ThrownExceptionInfo[exceptionTypes.length]; diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrParameterTableModelItem.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrParameterTableModelItem.java index d7969229abc5..a1f83a7a518e 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrParameterTableModelItem.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/refactoring/changeSignature/GrParameterTableModelItem.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2016 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.refactoring.changeSignature; import com.intellij.openapi.project.Project; @@ -22,6 +8,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.debugger.fragments.GroovyCodeFragment; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + /** * @author Max Medvedev */ @@ -40,7 +28,7 @@ public class GrParameterTableModelItem extends ParameterTableModelItemBase { @Override @@ -72,7 +60,7 @@ public class GroovyIntroduceParameterObjectDelegate final GroovyPsiElementFactory elementFactory = GroovyPsiElementFactory.getInstance(method.getProject()); PsiType classType = elementFactory.createTypeByFQClassName(StringUtil.getQualifiedName(descriptor.getPackageName(), descriptor.getClassName())); - return new GrParameterInfo(descriptor.getClassName(), null, null, classType, -1, false) { + return new GrParameterInfo(descriptor.getClassName(), null, null, classType, NEW_PARAMETER, false) { @Nullable @Override public PsiElement getActualValue(PsiElement callExpression, Object substitutor) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/changeSignature/ChangeSignatureForJavaTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/changeSignature/ChangeSignatureForJavaTest.groovy index eb8f83165363..4e65aaf9225c 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/changeSignature/ChangeSignatureForJavaTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/refactoring/changeSignature/ChangeSignatureForJavaTest.groovy @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.groovy.refactoring.changeSignature import com.intellij.codeInsight.TargetElementUtil @@ -28,6 +14,8 @@ import org.jetbrains.annotations.NonNls import org.jetbrains.annotations.Nullable import org.jetbrains.plugins.groovy.util.TestUtils +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER + /** * @author Maxim.Medvedev */ @@ -48,8 +36,8 @@ class ChangeSignatureForJavaTest extends LightJavaCodeInsightFixtureTestCase { doTest null, null, "T", { PsiMethod method -> final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory() return [ - new ParameterInfoImpl(-1, "x", factory.createTypeFromText("T", method.getParameterList()), "null"), - new ParameterInfoImpl(-1, "y", factory.createTypeFromText("C", method.getParameterList()), "null") + new ParameterInfoImpl(NEW_PARAMETER, "x", factory.createTypeFromText("T", method.getParameterList()), "null"), + new ParameterInfoImpl(NEW_PARAMETER, "y", factory.createTypeFromText("C", method.getParameterList()), "null") ] }, false } @@ -67,32 +55,32 @@ class ChangeSignatureForJavaTest extends LightJavaCodeInsightFixtureTestCase { doTest null, null, null, { PsiMethod method -> final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory() return [ - new ParameterInfoImpl(-1, "t", factory.createTypeFromText("T", method.getParameterList()), "null"), - new ParameterInfoImpl(-1, "u", factory.createTypeFromText("U", method.getParameterList()), "null"), - new ParameterInfoImpl(-1, "cu", factory.createTypeFromText("C", method.getParameterList()), "null") + new ParameterInfoImpl(NEW_PARAMETER, "t", factory.createTypeFromText("T", method.getParameterList()), "null"), + new ParameterInfoImpl(NEW_PARAMETER, "u", factory.createTypeFromText("U", method.getParameterList()), "null"), + new ParameterInfoImpl(NEW_PARAMETER, "cu", factory.createTypeFromText("C", method.getParameterList()), "null") ] }, false } void testDefaultConstructor() throws Exception { - doTest null, [new ParameterInfoImpl(-1, "j", PsiType.INT, "27")], false + doTest null, [new ParameterInfoImpl(NEW_PARAMETER, "j", PsiType.INT, "27")], false } void testGenerateDelegate() throws Exception { - doTest null, [new ParameterInfoImpl(-1, "i", PsiType.INT, "27")], true + doTest null, [new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27")], true } /*public void testGenerateDelegateForAbstract() throws Exception { doTest(null, new ParameterInfoImpl[] { - new ParameterInfoImpl(-1, "i", PsiType.INT, "27") + new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27") }, true); } public void testGenerateDelegateWithReturn() throws Exception { doTest(null, new ParameterInfoImpl[] { - new ParameterInfoImpl(-1, "i", PsiType.INT, "27") + new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27") }, true); } @@ -100,7 +88,7 @@ class ChangeSignatureForJavaTest extends LightJavaCodeInsightFixtureTestCase { doTest(null, new ParameterInfoImpl[] { new ParameterInfoImpl(1), - new ParameterInfoImpl(-1, "c", PsiType.CHAR, "'a'"), + new ParameterInfoImpl(NEW_PARAMETER, "c", PsiType.CHAR, "'a'"), new ParameterInfoImpl(0, "j", PsiType.INT) }, true); } @@ -111,7 +99,7 @@ class ChangeSignatureForJavaTest extends LightJavaCodeInsightFixtureTestCase { */ void testGenerateDelegateDefaultConstructor() throws Exception { - doTest null, [new ParameterInfoImpl(-1, "i", PsiType.INT, "27")], true + doTest null, [new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27")], true } /* @@ -125,7 +113,7 @@ class ChangeSignatureForJavaTest extends LightJavaCodeInsightFixtureTestCase { public void testSuperCallFromOtherMethod() throws Exception { doTest(null, new ParameterInfoImpl[] { - new ParameterInfoImpl(-1, "nnn", PsiType.INT, "-222"), + new ParameterInfoImpl(NEW_PARAMETER, "nnn", PsiType.INT, "-222"), }, false); } */ @@ -136,7 +124,7 @@ class ChangeSignatureForJavaTest extends LightJavaCodeInsightFixtureTestCase { public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException { final PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory(); return new ParameterInfoImpl[] { - new ParameterInfoImpl(-1, "l", factory.createTypeFromText("List", method), "null", true) + new ParameterInfoImpl(NEW_PARAMETER, "l", factory.createTypeFromText("List", method), "null", true) }; } }, false); @@ -150,14 +138,14 @@ class ChangeSignatureForJavaTest extends LightJavaCodeInsightFixtureTestCase { public void testEnumConstructor() throws Exception { doTest(null, new ParameterInfoImpl[] { - new ParameterInfoImpl(-1, "i", PsiType.INT, "10") + new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "10") }, false); } */ void testVarargs1() throws Exception { doTest null, [ - new ParameterInfoImpl(-1, "b", PsiType.BOOLEAN, "true"), + new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN, "true"), new ParameterInfoImpl(0) ], false } diff --git a/python/src/com/jetbrains/python/inspections/quickfix/PyChangeSignatureQuickFix.java b/python/src/com/jetbrains/python/inspections/quickfix/PyChangeSignatureQuickFix.java index 52562ab6a5ca..b5a62bfad031 100644 --- a/python/src/com/jetbrains/python/inspections/quickfix/PyChangeSignatureQuickFix.java +++ b/python/src/com/jetbrains/python/inspections/quickfix/PyChangeSignatureQuickFix.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains.python.inspections.quickfix; import com.google.common.collect.Iterators; @@ -35,6 +35,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; import static com.jetbrains.python.psi.PyUtil.as; public class PyChangeSignatureQuickFix extends LocalQuickFixOnPsiElement { @@ -65,11 +66,11 @@ public class PyChangeSignatureQuickFix extends LocalQuickFixOnPsiElement { final PyExpression value = ((PyKeywordArgument)arg).getValueExpression(); final String valueText = value != null ? value.getText() : ""; newParameters.add(Pair.create(parameters.length - 1, - new PyParameterInfo(-1, ((PyKeywordArgument)arg).getKeyword(), valueText, true))); + new PyParameterInfo(NEW_PARAMETER, ((PyKeywordArgument)arg).getKeyword(), valueText, true))); } else { final String paramName = generateParameterName(arg, function, usedParamNames, context); - newParameters.add(Pair.create(positionalParamAnchor, new PyParameterInfo(-1, paramName, arg.getText(), false))); + newParameters.add(Pair.create(positionalParamAnchor, new PyParameterInfo(NEW_PARAMETER, paramName, arg.getText(), false))); usedParamNames.add(paramName); } } @@ -82,7 +83,7 @@ public class PyChangeSignatureQuickFix extends LocalQuickFixOnPsiElement { final int complementaryParamLength = complementary.getParameterList().getParameters().length; final List> extraParams; if (complementaryParamLength > paramLength) { - extraParams = Collections.singletonList(Pair.create(paramLength - 1, new PyParameterInfo(-1, "**kwargs", "", false))); + extraParams = Collections.singletonList(Pair.create(paramLength - 1, new PyParameterInfo(NEW_PARAMETER, "**kwargs", "", false))); } else { extraParams = Collections.emptyList(); diff --git a/python/src/com/jetbrains/python/refactoring/changeSignature/PyParameterTableModel.java b/python/src/com/jetbrains/python/refactoring/changeSignature/PyParameterTableModel.java index 7dbb76378b6b..d1fd69072744 100644 --- a/python/src/com/jetbrains/python/refactoring/changeSignature/PyParameterTableModel.java +++ b/python/src/com/jetbrains/python/refactoring/changeSignature/PyParameterTableModel.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.jetbrains.python.refactoring.changeSignature; import com.intellij.openapi.editor.Document; @@ -30,6 +30,8 @@ import java.awt.*; import java.util.ArrayList; import java.util.Collection; +import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER; + /** * User : ktisha */ @@ -55,7 +57,7 @@ public class PyParameterTableModel extends ParameterTableModelBase