add ParameterInfo#NEW, replace usages of obscure -1 constant

GitOrigin-RevId: 6df4beac5ce422af1fa0b4dc1c86d0bd6ec5498d
This commit is contained in:
Artem Khvastunov
2020-01-21 14:15:25 +01:00
committed by intellij-monorepo-bot
parent a35e9fb6a3
commit 0fa3376c43
21 changed files with 149 additions and 318 deletions

View File

@@ -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("<b>").append(escapePresentableType(exprType)).append("</b>");

View File

@@ -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, "<b>" + escapePresentableType(exprType) + "</b>");

View File

@@ -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<Map<SmartPsiElementPointer<PsiField>, 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;

View File

@@ -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<ParameterInfoImpl> 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);
}

View File

@@ -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]);
}

View File

@@ -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);

View File

@@ -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<ParameterInfoImpl, ParameterTableModelItemBase<ParameterInfoImpl>> {
private final Project myProject;
@@ -80,7 +68,7 @@ public class JavaParameterTableModel extends ParameterTableModelBase<ParameterIn
@Override
protected ParameterTableModelItemBase<ParameterInfoImpl> createRowItem(@Nullable ParameterInfoImpl parameterInfo) {
if (parameterInfo == null) {
parameterInfo = new ParameterInfoImpl(-1);
parameterInfo = new ParameterInfoImpl(NEW_PARAMETER);
}
JavaCodeFragmentFactory f = JavaCodeFragmentFactory.getInstance(myProject);
final PsiTypeCodeFragment paramTypeCodeFragment =

View File

@@ -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<PsiMethod, ParameterInfoImpl, JavaIntroduceParameterObjectClassDescriptor> {
@@ -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) {

View File

@@ -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()));
}
}

View File

@@ -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() {

View File

@@ -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;
};

View File

@@ -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<PsiMethod> 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);
}

View File

@@ -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<T>", method.getParameterList()), "null")
new ParameterInfoImpl(NEW_PARAMETER, "x", myFactory.createTypeFromText("T", method.getParameterList()), "null"),
new ParameterInfoImpl(NEW_PARAMETER, "y", myFactory.createTypeFromText("C<T>", 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<U>", 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<U>", 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<java.lang.String>", null)),
new ParameterInfoImpl(NEW_PARAMETER, "y", myFactory.createTypeFromText("java.util.List<java.lang.String>", 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);

View File

@@ -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<ParameterInfoImpl> 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

View File

@@ -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];

View File

@@ -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<GrPar
@NotNull final Project project,
@Nullable final PsiElement context) {
if (parameterInfo == null) {
parameterInfo = new GrParameterInfo("", "", "", null, -1, false);
parameterInfo = new GrParameterInfo("", "", "", null, NEW_PARAMETER, false);
}
PsiTypeCodeFragment typeCodeFragment =

View File

@@ -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.introduceParameterObject;
import com.intellij.codeInsight.highlighting.ReadWriteAccessDetector;
@@ -48,6 +34,8 @@ import org.jetbrains.plugins.groovy.refactoring.changeSignature.GrParameterInfo;
import java.util.Collection;
import java.util.List;
import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER;
public class GroovyIntroduceParameterObjectDelegate
extends IntroduceParameterObjectDelegate<GrMethod, GrParameterInfo, GroovyIntroduceObjectClassDescriptor> {
@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) {

View File

@@ -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<T>", method.getParameterList()), "null")
new ParameterInfoImpl(NEW_PARAMETER, "x", factory.createTypeFromText("T", method.getParameterList()), "null"),
new ParameterInfoImpl(NEW_PARAMETER, "y", factory.createTypeFromText("C<T>", 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<U>", 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<U>", 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
}

View File

@@ -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<Pair<Integer, PyParameterInfo>> 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();

View File

@@ -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<PyParameterIn
@Override
protected PyParameterTableModelItem createRowItem(@Nullable PyParameterInfo parameterInfo) {
if (parameterInfo == null) {
parameterInfo = new PyParameterInfo(-1);
parameterInfo = new PyParameterInfo(NEW_PARAMETER);
}
final String defaultValue = parameterInfo.getDefaultValue();
final PsiCodeFragment defaultValueFragment = new PyExpressionCodeFragment(myProject, StringUtil.notNullize(defaultValue),

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2017 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.project.Project;
@@ -19,6 +19,8 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER;
/**
* User : ktisha
*/
@@ -56,17 +58,17 @@ public class PyChangeSignatureTest extends PyTestCase {
public void testAddPositionalParam() {
doChangeSignatureTest(null, Arrays.asList(new PyParameterInfo(0, "a", null, false), new PyParameterInfo(1, "b", null, false),
new PyParameterInfo(-1, "c", "3", false)));
new PyParameterInfo(NEW_PARAMETER, "c", "3", false)));
}
public void testAddDefaultParamAtEnd() {
doChangeSignatureTest(null, Arrays.asList(new PyParameterInfo(0, "a", null, false), new PyParameterInfo(1, "b", null, false),
new PyParameterInfo(-1, "c", "3", true)));
new PyParameterInfo(NEW_PARAMETER, "c", "3", true)));
}
// PY-24607
public void testAddDefaultParamBeforeAnotherDefault() {
doChangeSignatureTest(null, Arrays.asList(new PyParameterInfo(0, "a", null, false), new PyParameterInfo(-1, "d", "1", true),
doChangeSignatureTest(null, Arrays.asList(new PyParameterInfo(0, "a", null, false), new PyParameterInfo(NEW_PARAMETER, "d", "1", true),
new PyParameterInfo(1, "b", "None", true)));
}
@@ -77,7 +79,7 @@ public class PyChangeSignatureTest extends PyTestCase {
// PY-15143
public void testRemoveDefaultFromParamWithoutReplacement() {
final PyParameterInfo first = new PyParameterInfo(0, "arg", null, false);
final PyParameterInfo second = new PyParameterInfo(-1, "vvv", "xxx", false);
final PyParameterInfo second = new PyParameterInfo(NEW_PARAMETER, "vvv", "xxx", false);
doValidationTest(null, Arrays.asList(first, second), PyBundle.message("refactoring.change.signature.dialog.validation.default.missing"));
}
@@ -114,12 +116,12 @@ public class PyChangeSignatureTest extends PyTestCase {
public void testClassMethod() {
doChangeSignatureTest(null, Arrays.asList(new PyParameterInfo(0, "self", null, false), new PyParameterInfo(1, "a", null, true),
new PyParameterInfo(-1, "b", "2", false)));
new PyParameterInfo(NEW_PARAMETER, "b", "2", false)));
}
public void testKeywordParam() {
doChangeSignatureTest(null, Arrays.asList(new PyParameterInfo(0, "a", null, false),
new PyParameterInfo(-1, "b", "2", false)));
new PyParameterInfo(NEW_PARAMETER, "b", "2", false)));
}
public void testParamAnnotation() {
@@ -133,8 +135,8 @@ public class PyChangeSignatureTest extends PyTestCase {
public void testKeywordOnlyParams() {
doChangeSignatureTest(null, Arrays.asList(new PyParameterInfo(0, "param", null, false),
new PyParameterInfo(-1, "*", null, false),
new PyParameterInfo(-1, "a", "2", false)), LanguageLevel.PYTHON34);
new PyParameterInfo(NEW_PARAMETER, "*", null, false),
new PyParameterInfo(NEW_PARAMETER, "a", "2", false)), LanguageLevel.PYTHON34);
}
public void testKeywordOnlyParamRemoveDefaultValue() {
@@ -170,7 +172,7 @@ public class PyChangeSignatureTest extends PyTestCase {
}
public void testMoveRenameParam() {
final PyParameterInfo b = new PyParameterInfo(-1, "b", "1", false);
final PyParameterInfo b = new PyParameterInfo(NEW_PARAMETER, "b", "1", false);
final PyParameterInfo a = new PyParameterInfo(0, "a", "2", true);
a.setName("a2");
doChangeSignatureTest("foo", Arrays.asList(b,
@@ -201,7 +203,7 @@ public class PyChangeSignatureTest extends PyTestCase {
}
public void testEmptyParameterName() {
doValidationTest(null, Arrays.asList(new PyParameterInfo(-1, "", "2", true)),
doValidationTest(null, Arrays.asList(new PyParameterInfo(NEW_PARAMETER, "", "2", true)),
PyBundle.message("refactoring.change.signature.dialog.validation.parameter.name"));
}
@@ -210,11 +212,11 @@ public class PyChangeSignatureTest extends PyTestCase {
}
public void testNonDefaultAfterDefault() {
doValidationTest(null, Arrays.asList(new PyParameterInfo(-1, "a", "2", false), new PyParameterInfo(0, "b", "2", false)), null);
doValidationTest(null, Arrays.asList(new PyParameterInfo(NEW_PARAMETER, "a", "2", false), new PyParameterInfo(0, "b", "2", false)), null);
}
public void testNonDefaultAfterDefault1() {
doValidationTest(null, Arrays.asList(new PyParameterInfo(0, "b", "1", true), new PyParameterInfo(-1, "a", "2", false)),
doValidationTest(null, Arrays.asList(new PyParameterInfo(0, "b", "1", true), new PyParameterInfo(NEW_PARAMETER, "a", "2", false)),
PyPsiBundle.message("ANN.non.default.param.after.default"));
}
@@ -295,13 +297,13 @@ public class PyChangeSignatureTest extends PyTestCase {
// PY-24288
public void testKeywordParameterAlreadyExists() {
doChangeSignatureTest(null, Arrays.asList(new PyParameterInfo(0, "x", null, false),
new PyParameterInfo(-1, "foo", "None", true),
new PyParameterInfo(NEW_PARAMETER, "foo", "None", true),
new PyParameterInfo(1, "**kwargs", null, false)));
}
// PY-24480
public void testAddParameterBeforeVararg() {
doChangeSignatureTest(null, Arrays.asList(new PyParameterInfo(-1, "x", "42", false),
doChangeSignatureTest(null, Arrays.asList(new PyParameterInfo(NEW_PARAMETER, "x", "42", false),
new PyParameterInfo(0, "*args", null, false)));
}
@@ -320,7 +322,7 @@ public class PyChangeSignatureTest extends PyTestCase {
Arrays.asList(
new PyParameterInfo(0, "x", null, false),
new PyParameterInfo(1, "*args", null, false),
new PyParameterInfo(-1, "foo", "None", false)
new PyParameterInfo(NEW_PARAMETER, "foo", "None", false)
)
)
);
@@ -349,7 +351,7 @@ public class PyChangeSignatureTest extends PyTestCase {
public void testScatteredKwargsArgsAddParamAfter() {
doChangeSignatureTest("f", Arrays.asList(new PyParameterInfo(0, "x", null, false),
new PyParameterInfo(1, "foo", null, false),
new PyParameterInfo(-1, "y", "None", false),
new PyParameterInfo(NEW_PARAMETER, "y", "None", false),
new PyParameterInfo(2, "**kwargs", null, false)));
}
@@ -357,7 +359,7 @@ public class PyChangeSignatureTest extends PyTestCase {
public void testScatteredKwargsArgsAddParamAfterWithDefault() {
doChangeSignatureTest("f", Arrays.asList(new PyParameterInfo(0, "x", null, false),
new PyParameterInfo(1, "foo", null, false),
new PyParameterInfo(-1, "y", "None", true),
new PyParameterInfo(NEW_PARAMETER, "y", "None", true),
new PyParameterInfo(2, "**kwargs", null, false)));
}