mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
replace ParameterInfoImpl construct usages with builder
GitOrigin-RevId: 5108a8ef182d15cd9b9365e7b59e3e3bb74cd392
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0fa3376c43
commit
bc90b4f87b
+12
-9
@@ -46,8 +46,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER;
|
||||
|
||||
/**
|
||||
* @author cdr
|
||||
*/
|
||||
@@ -285,7 +283,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction/*, Hig
|
||||
if (buf.length() > 0) buf.append(", ");
|
||||
final PsiType parameterType = PsiUtil.convertAnonymousToBaseType(paramType);
|
||||
final String presentableText = escapePresentableType(parameterType);
|
||||
final ParameterInfoImpl parameterInfo = new ParameterInfoImpl(pi, parameter.getName(), parameter.getType());
|
||||
final ParameterInfoImpl parameterInfo = ParameterInfoImpl.create(pi).withName(parameter.getName()).withType(parameter.getType());
|
||||
if (TypeConversionUtil.areTypesAssignmentCompatible(paramType, expression)) {
|
||||
buf.append(presentableText);
|
||||
result.add(parameterInfo);
|
||||
@@ -302,7 +300,9 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction/*, Hig
|
||||
for(int i = pi; i < parameters.length; i++) {
|
||||
if (buf.length() > 0) buf.append(", ");
|
||||
buf.append("<s>").append(escapePresentableType(parameters[i].getType())).append("</s>");
|
||||
final ParameterInfoImpl parameterInfo = new ParameterInfoImpl(pi, parameters[i].getName(), parameters[i].getType());
|
||||
final ParameterInfoImpl parameterInfo = ParameterInfoImpl.create(pi)
|
||||
.withName(parameters[i].getName())
|
||||
.withType(parameters[i].getType());
|
||||
removedParams.add(parameterInfo);
|
||||
}
|
||||
}
|
||||
@@ -333,7 +333,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction/*, Hig
|
||||
PsiUtil.ensureValidType(paramType);
|
||||
final String presentableText = escapePresentableType(paramType);
|
||||
if (TypeConversionUtil.areTypesAssignmentCompatible(paramType, expression)) {
|
||||
result.add(new ParameterInfoImpl(i, parameter.getName(), paramType));
|
||||
result.add(ParameterInfoImpl.create(i).withName(parameter.getName()).withType(paramType));
|
||||
buf.append(presentableText);
|
||||
}
|
||||
else {
|
||||
@@ -344,7 +344,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction/*, Hig
|
||||
exprType = ((PsiDisjunctionType)exprType).getLeastUpperBound();
|
||||
}
|
||||
if (!PsiTypesUtil.allTypeParametersResolved(myTargetMethod, exprType)) return null;
|
||||
final ParameterInfoImpl changedParameterInfo = new ParameterInfoImpl(i, parameter.getName(), exprType);
|
||||
final ParameterInfoImpl changedParameterInfo = ParameterInfoImpl.create(i).withName(parameter.getName()).withType(exprType);
|
||||
result.add(changedParameterInfo);
|
||||
changedParams.add(changedParameterInfo);
|
||||
buf.append("<s>").append(presentableText).append("</s> <b>").append(escapePresentableType(exprType)).append("</b>");
|
||||
@@ -396,7 +396,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction/*, Hig
|
||||
.areTypesAssignmentCompatible(paramType, expression));
|
||||
if (parameterAssignable) {
|
||||
final PsiType type = parameter.getType();
|
||||
result.add(new ParameterInfoImpl(pi, parameter.getName(), type));
|
||||
result.add(ParameterInfoImpl.create(pi).withName(parameter.getName()).withType(type));
|
||||
buf.append(escapePresentableType(type));
|
||||
pi++;
|
||||
ei++;
|
||||
@@ -405,7 +405,7 @@ public class ChangeMethodSignatureFromUsageFix implements IntentionAction/*, Hig
|
||||
if (pi == parameters.length - 1) {
|
||||
assert varargParam != null;
|
||||
final PsiType type = varargParam.getType();
|
||||
result.add(new ParameterInfoImpl(pi, varargParam.getName(), type));
|
||||
result.add(ParameterInfoImpl.create(pi).withName(varargParam.getName()).withType(type));
|
||||
buf.append(escapePresentableType(type));
|
||||
}
|
||||
pi++;
|
||||
@@ -422,7 +422,10 @@ 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(NEW_PARAMETER, name, exprType, expression.getText().replace('\n', ' '));
|
||||
final ParameterInfoImpl newParameterInfo = ParameterInfoImpl.createNew()
|
||||
.withName(name)
|
||||
.withType(exprType)
|
||||
.withDefaultValue(expression.getText().replace('\n', ' '));
|
||||
result.add(newParameterInfo);
|
||||
newParams.add(newParameterInfo);
|
||||
buf.append("<b>").append(escapePresentableType(exprType)).append("</b>");
|
||||
|
||||
+6
-3
@@ -73,7 +73,7 @@ public class ChangeMethodSignatureFromUsageReverseOrderFix extends ChangeMethodS
|
||||
.areTypesAssignmentCompatible(paramType, expression));
|
||||
if (parameterAssignable) {
|
||||
final PsiType type = parameter.getType();
|
||||
result.add(0, new ParameterInfoImpl(pi, parameter.getName(), type));
|
||||
result.add(0, ParameterInfoImpl.create(pi).withName(parameter.getName()).withType(type));
|
||||
params.add(0, escapePresentableType(type));
|
||||
pi--;
|
||||
ei--;
|
||||
@@ -82,7 +82,7 @@ public class ChangeMethodSignatureFromUsageReverseOrderFix extends ChangeMethodS
|
||||
if (pi == parameters.length - 1) {
|
||||
assert varargParam != null;
|
||||
final PsiType type = varargParam.getType();
|
||||
result.add(0, new ParameterInfoImpl(pi, varargParam.getName(), type));
|
||||
result.add(0, ParameterInfoImpl.create(pi).withName(varargParam.getName()).withType(type));
|
||||
params.add(0, escapePresentableType(type));
|
||||
}
|
||||
pi--;
|
||||
@@ -94,7 +94,10 @@ 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(NEW_PARAMETER, name, exprType, expression.getText().replace('\n', ' '));
|
||||
final ParameterInfoImpl newParameterInfo = ParameterInfoImpl.createNew()
|
||||
.withName(name)
|
||||
.withType(exprType)
|
||||
.withDefaultValue(expression.getText().replace('\n', ' '));
|
||||
result.add(0, newParameterInfo);
|
||||
newParams.add(newParameterInfo);
|
||||
params.add(0, "<b>" + escapePresentableType(exprType) + "</b>");
|
||||
|
||||
+8
-4
@@ -40,8 +40,6 @@ 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");
|
||||
|
||||
@@ -243,13 +241,19 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
|
||||
for (PsiVariable param : params) {
|
||||
final PsiType paramType = param.getType();
|
||||
if (param instanceof PsiParameter) {
|
||||
newParamInfos[i++] = new ParameterInfoImpl(parameterList.getParameterIndex((PsiParameter)param), param.getName(), paramType, param.getName());
|
||||
newParamInfos[i++] = ParameterInfoImpl.create(parameterList.getParameterIndex((PsiParameter)param))
|
||||
.withName(param.getName())
|
||||
.withType(paramType)
|
||||
.withDefaultValue(param.getName());
|
||||
} else {
|
||||
try {
|
||||
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(NEW_PARAMETER, uniqueParameterName, paramType, uniqueParameterName);
|
||||
newParamInfos[i++] = ParameterInfoImpl.createNew()
|
||||
.withName(uniqueParameterName)
|
||||
.withType(paramType)
|
||||
.withDefaultValue(uniqueParameterName);
|
||||
}
|
||||
finally {
|
||||
settings.PREFER_LONGER_NAMES = preferLongerNames;
|
||||
|
||||
+1
-3
@@ -27,8 +27,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER;
|
||||
|
||||
/**
|
||||
* @author Mike
|
||||
*/
|
||||
@@ -85,7 +83,7 @@ public class CreateParameterFromUsageFix extends CreateVarFromUsageFix {
|
||||
|
||||
final List<ParameterInfoImpl> parameterInfos =
|
||||
new ArrayList<>(Arrays.asList(ParameterInfoImpl.fromMethod(method)));
|
||||
ParameterInfoImpl parameterInfo = new ParameterInfoImpl(NEW_PARAMETER, varName, type, varName, false);
|
||||
ParameterInfoImpl parameterInfo = ParameterInfoImpl.createNew().withName(varName).withType(type).withDefaultValue(varName);
|
||||
if (!method.isVarArgs()) {
|
||||
parameterInfos.add(parameterInfo);
|
||||
}
|
||||
|
||||
+2
-4
@@ -25,8 +25,6 @@ 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);
|
||||
|
||||
@@ -125,10 +123,10 @@ public class MethodParameterFix extends LocalQuickFixAndIntentionActionOnPsiElem
|
||||
newParameter.setName(parameter.getName());
|
||||
parameter = newParameter;
|
||||
}
|
||||
result.add(new ParameterInfoImpl(i, parameter.getName(), parameter.getType()));
|
||||
result.add(ParameterInfoImpl.create(i).withName(parameter.getName()).withType(parameter.getType()));
|
||||
}
|
||||
if (parameters.length == myIndex) {
|
||||
result.add(new ParameterInfoImpl(NEW_PARAMETER, newParameter.getName(), newParameter.getType()));
|
||||
result.add(ParameterInfoImpl.createNew().withName(newParameter.getName()).withType(newParameter.getType()));
|
||||
}
|
||||
return result.toArray(new ParameterInfoImpl[0]);
|
||||
}
|
||||
|
||||
+4
-16
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// 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;
|
||||
@@ -126,7 +112,9 @@ public class VariableTypeFix extends LocalQuickFixAndIntentionActionOnPsiElement
|
||||
int i = 0;
|
||||
for (PsiParameter parameter : psiMethod.getParameterList().getParameters()) {
|
||||
final boolean changeType = i == parameterIndex;
|
||||
infos.add(new ParameterInfoImpl(i++, parameter.getName(), changeType ? getReturnType() : parameter.getType()));
|
||||
infos.add(ParameterInfoImpl.create(i++)
|
||||
.withName(parameter.getName())
|
||||
.withType(changeType ? getReturnType() : parameter.getType()));
|
||||
}
|
||||
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
|
||||
+2
-2
@@ -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.intention.impl;
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFixAndIntentionActionOnPsiElement;
|
||||
@@ -48,7 +48,7 @@ public class SameErasureButDifferentMethodsFix extends LocalQuickFixAndIntention
|
||||
PsiParameter parameter = parameters[i];
|
||||
PsiParameter superParameter = superParameters[i];
|
||||
PsiType superParameterType = superSubstitutor.substitute(superParameter.getType());
|
||||
infos[i] = new ParameterInfoImpl(i, parameter.getName(), superParameterType);
|
||||
infos[i] = ParameterInfoImpl.create(i).withName(parameter.getName()).withType(superParameterType);
|
||||
}
|
||||
|
||||
ChangeSignatureProcessor processor =
|
||||
|
||||
+1
-1
@@ -342,7 +342,7 @@ public class SameParameterValueInspection extends GlobalJavaBatchInspectionTool
|
||||
final String paramName = parameter.getName();
|
||||
for (PsiParameter param : parameters) {
|
||||
if (!Comparing.strEqual(paramName, param.getName())) {
|
||||
psiParameters.add(new ParameterInfoImpl(paramIdx, param.getName(), param.getType()));
|
||||
psiParameters.add(ParameterInfoImpl.create(paramIdx).withName(param.getName()).withType(param.getType()));
|
||||
}
|
||||
paramIdx++;
|
||||
}
|
||||
|
||||
+2
-2
@@ -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 com.intellij.codeInspection.varScopeCanBeNarrowed;
|
||||
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
@@ -161,7 +161,7 @@ public class ParameterCanBeLocalInspection extends AbstractBaseJavaLocalInspecti
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiParameter psiParameter = parameters[i];
|
||||
if (psiParameter == parameter) continue;
|
||||
info.add(new ParameterInfoImpl(i, psiParameter.getName(), psiParameter.getType()));
|
||||
info.add(ParameterInfoImpl.create(i).withName(psiParameter.getName()).withType(psiParameter.getType()));
|
||||
}
|
||||
final ParameterInfoImpl[] newParams = info.toArray(new ParameterInfoImpl[0]);
|
||||
final String visibilityModifier = VisibilityUtil.getVisibilityModifier(method.getModifierList());
|
||||
|
||||
+8
-8
@@ -208,10 +208,10 @@ class DetectedJavaChangeInfo extends JavaChangeInfoImpl {
|
||||
}
|
||||
|
||||
if (oldParameter != null) {
|
||||
parameterInfos[i] = new ParameterInfoImpl(oldParameter.getOldIndex(),
|
||||
oldParameter.getName(),
|
||||
oldParameter.getTypeWrapper(),
|
||||
null);
|
||||
parameterInfos[i] = ParameterInfoImpl.create(oldParameter.getOldIndex())
|
||||
.withName(oldParameter.getName())
|
||||
.withType(oldParameter.getTypeWrapper())
|
||||
.withDefaultValue(null);
|
||||
untouchedParams.put(parameterInfos[i], oldParameter.getOldIndex());
|
||||
}
|
||||
}
|
||||
@@ -230,10 +230,10 @@ class DetectedJavaChangeInfo extends JavaChangeInfoImpl {
|
||||
}
|
||||
final CanonicalTypes.Type typeWrapper = parameterInfo.getTypeWrapper();
|
||||
if (!typeWrapper.isValid()) return false;
|
||||
parameterInfos[i] = new ParameterInfoImpl(oldParameter != null ? oldParameter.getOldIndex() : NEW_PARAMETER,
|
||||
parameterInfo.getName(),
|
||||
typeWrapper,
|
||||
null);
|
||||
parameterInfos[i] = ParameterInfoImpl.create(oldParameter != null ? oldParameter.getOldIndex() : NEW_PARAMETER)
|
||||
.withName(parameterInfo.getName())
|
||||
.withType(typeWrapper)
|
||||
.withDefaultValue(null);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
+2
-16
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.psi.PsiClass;
|
||||
@@ -44,7 +30,7 @@ public class JavaMethodDescriptor implements MethodDescriptor<ParameterInfoImpl,
|
||||
final PsiParameter[] parameters = myMethod.getParameterList().getParameters();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
ParameterInfoImpl info = new ParameterInfoImpl(i, parameter.getName(), parameter.getType());
|
||||
ParameterInfoImpl info = ParameterInfoImpl.create(i).withName(parameter.getName()).withType(parameter.getType());
|
||||
info.defaultValue = "";
|
||||
result.add(info);
|
||||
}
|
||||
|
||||
+1
-3
@@ -34,8 +34,6 @@ 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;
|
||||
|
||||
@@ -68,7 +66,7 @@ public class JavaParameterTableModel extends ParameterTableModelBase<ParameterIn
|
||||
@Override
|
||||
protected ParameterTableModelItemBase<ParameterInfoImpl> createRowItem(@Nullable ParameterInfoImpl parameterInfo) {
|
||||
if (parameterInfo == null) {
|
||||
parameterInfo = new ParameterInfoImpl(NEW_PARAMETER);
|
||||
parameterInfo = ParameterInfoImpl.createNew();
|
||||
}
|
||||
JavaCodeFragmentFactory f = JavaCodeFragmentFactory.getInstance(myProject);
|
||||
final PsiTypeCodeFragment paramTypeCodeFragment =
|
||||
|
||||
+83
-17
@@ -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;
|
||||
|
||||
@@ -22,6 +8,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.refactoring.util.CanonicalTypes;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -39,26 +26,58 @@ public class ParameterInfoImpl implements JavaParameterInfo {
|
||||
private CanonicalTypes.Type myType;
|
||||
String defaultValue = "";
|
||||
|
||||
/**
|
||||
* @see #create(int)
|
||||
* @see #createNew()
|
||||
*/
|
||||
public ParameterInfoImpl(int oldParameterIndex) {
|
||||
this.oldParameterIndex = oldParameterIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #create(int)
|
||||
* @see #createNew()
|
||||
* @see #withName(String)
|
||||
* @see #withType(PsiType)
|
||||
*/
|
||||
public ParameterInfoImpl(int oldParameterIndex, @NonNls String name, PsiType aType) {
|
||||
setName(name);
|
||||
this.oldParameterIndex = oldParameterIndex;
|
||||
setType(aType);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #create(int)
|
||||
* @see #createNew()
|
||||
* @see #withName(String)
|
||||
* @see #withType(PsiType)
|
||||
* @see #withDefaultValue(String)
|
||||
*/
|
||||
public ParameterInfoImpl(int oldParameterIndex, @NonNls String name, PsiType aType, @NonNls String defaultValue) {
|
||||
this(oldParameterIndex, name, aType, defaultValue, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #create(int)
|
||||
* @see #createNew()
|
||||
* @see #withName(String)
|
||||
* @see #withType(PsiType)
|
||||
* @see #withDefaultValue(String)
|
||||
* @see #useAnySingleVariable()
|
||||
*/
|
||||
public ParameterInfoImpl(int oldParameterIndex, @NonNls String name, PsiType aType, @NonNls String defaultValue, boolean useAnyVariable) {
|
||||
this(oldParameterIndex, name, aType);
|
||||
this.defaultValue = defaultValue;
|
||||
useAnySingleVariable = useAnyVariable;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #create(int)
|
||||
* @see #createNew()
|
||||
* @see #withName(String)
|
||||
* @see #withType(CanonicalTypes.Type)
|
||||
* @see #withDefaultValue(String)
|
||||
*/
|
||||
public ParameterInfoImpl(int oldParameterIndex, String name, CanonicalTypes.Type typeWrapper, String defaultValue) {
|
||||
setName(name);
|
||||
this.oldParameterIndex = oldParameterIndex;
|
||||
@@ -173,7 +192,7 @@ public class ParameterInfoImpl implements JavaParameterInfo {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
result.add(new ParameterInfoImpl(i, parameter.getName(), parameter.getType()));
|
||||
result.add(create(i).withName(parameter.getName()).withType(parameter.getType()));
|
||||
}
|
||||
return result.toArray(new ParameterInfoImpl[0]);
|
||||
}
|
||||
@@ -191,9 +210,56 @@ public class ParameterInfoImpl implements JavaParameterInfo {
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
if (!parameterToRemove.equals(parameter)) {
|
||||
result.add(new ParameterInfoImpl(i, parameter.getName(), parameter.getType()));
|
||||
result.add(create(i).withName(parameter.getName()).withType(parameter.getType()));
|
||||
}
|
||||
}
|
||||
return result.toArray(new ParameterInfoImpl[0]);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract(value = "-> new", pure = true)
|
||||
public static ParameterInfoImpl createNew() {
|
||||
return create(NEW_PARAMETER);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract(value = "_ -> new", pure = true)
|
||||
public static ParameterInfoImpl create(int oldParameterIndex) {
|
||||
return new ParameterInfoImpl(oldParameterIndex);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract(value = "_ -> this")
|
||||
public ParameterInfoImpl withName(@NonNls String name) {
|
||||
setName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract(value = "_ -> this")
|
||||
public ParameterInfoImpl withType(PsiType aType) {
|
||||
setType(aType);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract(value = "_ -> this")
|
||||
public ParameterInfoImpl withType(CanonicalTypes.Type typeWrapper) {
|
||||
myType = typeWrapper;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract(value = "_ -> this")
|
||||
public ParameterInfoImpl withDefaultValue(@NonNls String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Contract(value = "-> this")
|
||||
public ParameterInfoImpl useAnySingleVariable() {
|
||||
useAnySingleVariable = true;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-16
@@ -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.inline;
|
||||
|
||||
import com.intellij.codeInsight.ExceptionUtil;
|
||||
@@ -166,7 +152,7 @@ public class InlineParameterExpressionProcessor extends BaseRefactoringProcessor
|
||||
final String paramName = myParameter.getName();
|
||||
for (PsiParameter param : parameters) {
|
||||
if (!Comparing.strEqual(paramName, param.getName())) {
|
||||
psiParameters.add(new ParameterInfoImpl(paramIdx, param.getName(), param.getType()));
|
||||
psiParameters.add(ParameterInfoImpl.create(paramIdx).withName(param.getName()).withType(param.getType()));
|
||||
}
|
||||
paramIdx++;
|
||||
}
|
||||
|
||||
+3
-2
@@ -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.refactoring.introduceparameterobject;
|
||||
|
||||
import com.intellij.ide.util.TreeJavaClassChooserDialog;
|
||||
@@ -186,7 +186,8 @@ public class IntroduceParameterObjectDialog extends AbstractIntroduceParameterOb
|
||||
final List<ParameterInfoImpl> parameters = new ArrayList<>();
|
||||
for (VariableData data : myParameterTablePanel.getVariableData()) {
|
||||
if (data.passAsParameter) {
|
||||
parameters.add(new ParameterInfoImpl(parameterList.getParameterIndex((PsiParameter)data.variable), data.name, data.type));
|
||||
int oldParameterIndex = parameterList.getParameterIndex((PsiParameter)data.variable);
|
||||
parameters.add(ParameterInfoImpl.create(oldParameterIndex).withName(data.name).withType(data.type));
|
||||
}
|
||||
}
|
||||
final ParameterInfoImpl[] infos = parameters.toArray(new ParameterInfoImpl[0]);
|
||||
|
||||
+9
-6
@@ -32,8 +32,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
@@ -148,18 +146,23 @@ public class MakeMethodStaticProcessor extends MakeMethodOrClassStaticProcessor<
|
||||
PsiParameter[] parameters = myMember.getParameterList().getParameters();
|
||||
|
||||
if (mySettings.isMakeClassParameter()) {
|
||||
params.add(new ParameterInfoImpl(NEW_PARAMETER, mySettings.getClassParameterName(),
|
||||
factory.createType(containingClass, PsiSubstitutor.EMPTY), "this"));
|
||||
params.add(ParameterInfoImpl.createNew()
|
||||
.withName(mySettings.getClassParameterName())
|
||||
.withType(factory.createType(containingClass, PsiSubstitutor.EMPTY))
|
||||
.withDefaultValue("this"));
|
||||
}
|
||||
|
||||
if (mySettings.isMakeFieldParameters()) {
|
||||
for (Settings.FieldParameter parameter : mySettings.getParameterOrderList()) {
|
||||
params.add(new ParameterInfoImpl(NEW_PARAMETER, mySettings.getClassParameterName(), parameter.type, parameter.field.getName()));
|
||||
params.add(ParameterInfoImpl.createNew()
|
||||
.withName(mySettings.getClassParameterName())
|
||||
.withType(parameter.type)
|
||||
.withDefaultValue(parameter.field.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
params.add(new ParameterInfoImpl(i));
|
||||
params.add(ParameterInfoImpl.create(i));
|
||||
}
|
||||
|
||||
final PsiType returnType = myMember.getReturnType();
|
||||
|
||||
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// 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.util.duplicates;
|
||||
|
||||
import com.intellij.codeInsight.PsiEquivalenceUtil;
|
||||
@@ -109,7 +95,7 @@ public class MatchUtil {
|
||||
break;
|
||||
}
|
||||
}
|
||||
newParameters.add(new ParameterInfoImpl(i, oldParameter.getName(), type));
|
||||
newParameters.add(ParameterInfoImpl.create(i).withName(oldParameter.getName()).withType(type));
|
||||
}
|
||||
return newParameters;
|
||||
}
|
||||
|
||||
+4
-6
@@ -6,24 +6,22 @@ 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(NEW_PARAMETER, "b", PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false);
|
||||
doTest(null, null, null, new ParameterInfoImpl[] {ParameterInfoImpl.createNew().withName("b").withType(PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false);
|
||||
}
|
||||
|
||||
public void testMethodArgument() {
|
||||
doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false);
|
||||
doTest(null, null, null, new ParameterInfoImpl[] {ParameterInfoImpl.createNew().withName("b").withType(PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false);
|
||||
}
|
||||
|
||||
public void testDefaultMethodTouched() {
|
||||
doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false);
|
||||
doTest(null, null, null, new ParameterInfoImpl[] {ParameterInfoImpl.createNew().withName("b").withType(PsiType.BOOLEAN)}, new ThrownExceptionInfo[0], false);
|
||||
}
|
||||
|
||||
public void testDelegateInInterface() {
|
||||
doTest(null, null, null, new ParameterInfoImpl[] {new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN, "false")}, new ThrownExceptionInfo[0], true);
|
||||
doTest(null, null, null, new ParameterInfoImpl[] {ParameterInfoImpl.createNew().withName("b").withType(PsiType.BOOLEAN).withDefaultValue("false")}, new ThrownExceptionInfo[0], true);
|
||||
}
|
||||
|
||||
public void testAddExceptionToCatchInOneLineLambda() {
|
||||
|
||||
@@ -46,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(NEW_PARAMETER, "p" + (i + 1), type);
|
||||
parameterInfos[i] = ParameterInfoImpl.createNew().withName("p" + (i + 1)).withType(type);
|
||||
}
|
||||
return parameterInfos;
|
||||
};
|
||||
@@ -153,7 +153,7 @@ public abstract class ChangeSignatureBaseTest extends LightRefactoringTestCase {
|
||||
if (myInfos == null) {
|
||||
myInfos = new ParameterInfoImpl[method.getParameterList().getParametersCount()];
|
||||
for (int i = 0; i < myInfos.length; i++) {
|
||||
myInfos[i] = new ParameterInfoImpl(i);
|
||||
myInfos[i] = ParameterInfoImpl.create(i);
|
||||
}
|
||||
}
|
||||
for (ParameterInfoImpl info : myInfos) {
|
||||
|
||||
+3
-3
@@ -62,7 +62,7 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase {
|
||||
}
|
||||
}
|
||||
PsiClassType stringType = PsiType.getJavaLangString(getPsiManager(), GlobalSearchScope.allScope(getProject()));
|
||||
final ParameterInfoImpl[] newParameters = {new ParameterInfoImpl(NEW_PARAMETER, "param", stringType)};
|
||||
final ParameterInfoImpl[] newParameters = {ParameterInfoImpl.createNew().withName("param").withType(stringType)};
|
||||
BaseRefactoringProcessor.ConflictsInTestsException.withIgnoredConflicts(() -> doTest(newParameters, new ThrownExceptionInfo[0], methods, null, method));
|
||||
}
|
||||
|
||||
@@ -132,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(NEW_PARAMETER, "clazz", paramType, "null")};
|
||||
final ParameterInfoImpl[] newParameters = new ParameterInfoImpl[]{ParameterInfoImpl.createNew().withName("clazz").withType(paramType).withDefaultValue("null")};
|
||||
doTest(newParameters, new ThrownExceptionInfo[0], psiMethods, null, method);
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class ChangeSignaturePropagationTest extends LightRefactoringTestCase {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
ParameterInfoImpl[] result = new ParameterInfoImpl[parameters.length + newParameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
result[i] = new ParameterInfoImpl(i);
|
||||
result[i] = ParameterInfoImpl.create(i);
|
||||
}
|
||||
System.arraycopy(newParameters, 0, result, parameters.length, newParameters.length);
|
||||
return result;
|
||||
|
||||
@@ -14,8 +14,6 @@ import com.intellij.refactoring.util.CanonicalTypes;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
import static com.intellij.refactoring.changeSignature.ParameterInfo.NEW_PARAMETER;
|
||||
|
||||
/**
|
||||
* @author dsl
|
||||
*/
|
||||
@@ -30,12 +28,12 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
}
|
||||
|
||||
public void testParameterReorder() {
|
||||
doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1), new ParameterInfoImpl(0)}, false);
|
||||
doTest(null, new ParameterInfoImpl[]{ParameterInfoImpl.create(1), ParameterInfoImpl.create(0)}, false);
|
||||
}
|
||||
|
||||
public void testWarnAboutContract() {
|
||||
try {
|
||||
doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1)}, false);
|
||||
doTest(null, new ParameterInfoImpl[]{ParameterInfoImpl.create(1)}, false);
|
||||
fail("Conflict expected");
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException ignored) { }
|
||||
@@ -59,7 +57,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
|
||||
public void testDuplicatedSignatureInInheritor() {
|
||||
try {
|
||||
doTest(null, new ParameterInfoImpl[] {new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT)}, true);
|
||||
doTest(null, new ParameterInfoImpl[] {ParameterInfoImpl.createNew().withName("i").withType(PsiType.INT)}, true);
|
||||
fail("Conflict expected");
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException ignored) { }
|
||||
@@ -75,29 +73,29 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
|
||||
public void testGenericTypes() {
|
||||
doTest(null, null, "T", method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "x", myFactory.createTypeFromText("T", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "y", myFactory.createTypeFromText("C<T>", method.getParameterList()), "null")
|
||||
ParameterInfoImpl.createNew().withName("x").withType(myFactory.createTypeFromText("T", method.getParameterList())).withDefaultValue("null"),
|
||||
ParameterInfoImpl.createNew().withName("y").withType(myFactory.createTypeFromText("C<T>", method.getParameterList())).withDefaultValue("null")
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testGenericTypesInOldParameters() {
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "t", myFactory.createTypeFromText("T", method), null)
|
||||
ParameterInfoImpl.create(0).withName("t").withType(myFactory.createTypeFromText("T", method)).withDefaultValue(null)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testTypeParametersInMethod() {
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
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")
|
||||
ParameterInfoImpl.createNew().withName("t").withType(myFactory.createTypeFromText("T", method.getParameterList())).withDefaultValue("null"),
|
||||
ParameterInfoImpl.createNew().withName("u").withType(myFactory.createTypeFromText("U", method.getParameterList())).withDefaultValue("null"),
|
||||
ParameterInfoImpl.createNew().withName("cu").withType(myFactory.createTypeFromText("C<U>", method.getParameterList())).withDefaultValue("null")
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testDefaultConstructor() {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "j", PsiType.INT, "27")
|
||||
ParameterInfoImpl.createNew().withName("j").withType(PsiType.INT).withDefaultValue("27")
|
||||
}, false
|
||||
);
|
||||
}
|
||||
@@ -105,7 +103,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
public void testGenerateDelegate() {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27")
|
||||
ParameterInfoImpl.createNew().withName("i").withType(PsiType.INT).withDefaultValue("27")
|
||||
}, true
|
||||
);
|
||||
}
|
||||
@@ -113,7 +111,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
public void testGenerateDelegateForAbstract() {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27")
|
||||
ParameterInfoImpl.createNew().withName("i").withType(PsiType.INT).withDefaultValue("27")
|
||||
}, true
|
||||
);
|
||||
}
|
||||
@@ -121,7 +119,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
public void testGenerateDelegateWithReturn() {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27")
|
||||
ParameterInfoImpl.createNew().withName("i").withType(PsiType.INT).withDefaultValue("27")
|
||||
}, true
|
||||
);
|
||||
}
|
||||
@@ -129,9 +127,9 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
public void testGenerateDelegateWithParametersReordering() {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1),
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "c", PsiType.CHAR, "'a'"),
|
||||
new ParameterInfoImpl(0, "j", PsiType.INT)
|
||||
ParameterInfoImpl.create(1),
|
||||
ParameterInfoImpl.createNew().withName("c").withType(PsiType.CHAR).withDefaultValue("'a'"),
|
||||
ParameterInfoImpl.create(0).withName("j").withType(PsiType.INT)
|
||||
}, true
|
||||
);
|
||||
}
|
||||
@@ -142,145 +140,145 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
|
||||
public void testGenerateDelegateDefaultConstructor() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27")
|
||||
ParameterInfoImpl.createNew().withName("i").withType(PsiType.INT).withDefaultValue("27")
|
||||
}, true);
|
||||
}
|
||||
|
||||
public void testSCR40895() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "y", PsiType.INT),
|
||||
new ParameterInfoImpl(1, "b", PsiType.BOOLEAN)
|
||||
ParameterInfoImpl.create(0).withName("y").withType(PsiType.INT),
|
||||
ParameterInfoImpl.create(1).withName("b").withType(PsiType.BOOLEAN)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testJavadocGenericsLink() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "y", myFactory.createTypeFromText("java.util.List<java.lang.String>", null)),
|
||||
new ParameterInfoImpl(0, "a", PsiType.BOOLEAN)
|
||||
ParameterInfoImpl.createNew().withName("y").withType(myFactory.createTypeFromText("java.util.List<java.lang.String>", null)),
|
||||
ParameterInfoImpl.create(0).withName("a").withType(PsiType.BOOLEAN)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamNameSameAsFieldName() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "fieldName", PsiType.INT)
|
||||
ParameterInfoImpl.create(0).withName("fieldName").withType(PsiType.INT)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamNameNoConflict() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0),
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN)
|
||||
ParameterInfoImpl.create(0),
|
||||
ParameterInfoImpl.createNew().withName("b").withType(PsiType.BOOLEAN)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testVarargMethodToNonVarag() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "i", PsiType.INT),
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN)
|
||||
ParameterInfoImpl.create(0).withName("i").withType(PsiType.INT),
|
||||
ParameterInfoImpl.createNew().withName("b").withType(PsiType.BOOLEAN)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamJavadoc() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1, "z", PsiType.INT),
|
||||
new ParameterInfoImpl(0, "y", PsiType.INT)
|
||||
ParameterInfoImpl.create(1).withName("z").withType(PsiType.INT),
|
||||
ParameterInfoImpl.create(0).withName("y").withType(PsiType.INT)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamJavadoc0() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1, "z", PsiType.INT),
|
||||
new ParameterInfoImpl(0, "y", PsiType.INT)
|
||||
ParameterInfoImpl.create(1).withName("z").withType(PsiType.INT),
|
||||
ParameterInfoImpl.create(0).withName("y").withType(PsiType.INT)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamJavadoc1() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "z", PsiType.BOOLEAN)
|
||||
ParameterInfoImpl.create(0).withName("z").withType(PsiType.BOOLEAN)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamJavadoc2() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "z", PsiType.BOOLEAN),
|
||||
new ParameterInfoImpl(0, "a", PsiType.BOOLEAN),
|
||||
ParameterInfoImpl.createNew().withName("z").withType(PsiType.BOOLEAN),
|
||||
ParameterInfoImpl.create(0).withName("a").withType(PsiType.BOOLEAN),
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamJavadoc3() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "a", PsiType.BOOLEAN),
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN),
|
||||
ParameterInfoImpl.create(0).withName("a").withType(PsiType.BOOLEAN),
|
||||
ParameterInfoImpl.createNew().withName("b").withType(PsiType.BOOLEAN),
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testParamJavadocRenamedReordered() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "a", PsiType.BOOLEAN),
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "c", PsiType.BOOLEAN),
|
||||
new ParameterInfoImpl(1, "b1", PsiType.BOOLEAN),
|
||||
ParameterInfoImpl.create(0).withName("a").withType(PsiType.BOOLEAN),
|
||||
ParameterInfoImpl.createNew().withName("c").withType(PsiType.BOOLEAN),
|
||||
ParameterInfoImpl.create(1).withName("b1").withType(PsiType.BOOLEAN),
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testJavadocNoNewLineInserted() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "newArgs", PsiType.DOUBLE),
|
||||
ParameterInfoImpl.create(0).withName("newArgs").withType(PsiType.DOUBLE),
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testSuperCallFromOtherMethod() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "nnn", PsiType.INT, "-222"),
|
||||
ParameterInfoImpl.createNew().withName("nnn").withType(PsiType.INT).withDefaultValue("-222"),
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testUseAnyVariable() {
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "l", myFactory.createTypeFromText("List", method), "null", true)
|
||||
ParameterInfoImpl.createNew().withName("l").withType(myFactory.createTypeFromText("List", method)).withDefaultValue("null").useAnySingleVariable()
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testUseThisAsAnyVariable() {
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "l", myFactory.createTypeFromText("List", method), "null", true)
|
||||
ParameterInfoImpl.createNew().withName("l").withType(myFactory.createTypeFromText("List", method)).withDefaultValue("null").useAnySingleVariable()
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testUseAnyVariableAndDefault() {
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "c", myFactory.createTypeFromText("C", method), "null", true)
|
||||
ParameterInfoImpl.createNew().withName("c").withType(myFactory.createTypeFromText("C", method)).withDefaultValue("null").useAnySingleVariable()
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testRemoveVarargParameter() {
|
||||
BaseRefactoringProcessor.ConflictsInTestsException.withIgnoredConflicts(()->
|
||||
doTest(null, null, null, new ParameterInfoImpl[]{new ParameterInfoImpl(0)}, new ThrownExceptionInfo[0], false)
|
||||
doTest(null, null, null, new ParameterInfoImpl[]{ParameterInfoImpl.create(0)}, new ThrownExceptionInfo[0], false)
|
||||
);
|
||||
}
|
||||
|
||||
public void testEnumConstructor() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "10")
|
||||
ParameterInfoImpl.createNew().withName("i").withType(PsiType.INT).withDefaultValue("10")
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testVarargs1() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN, "true"),
|
||||
new ParameterInfoImpl(0)
|
||||
ParameterInfoImpl.createNew().withName("b").withType(PsiType.BOOLEAN).withDefaultValue("true"),
|
||||
ParameterInfoImpl.create(0)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testVarargs2() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1, "i", PsiType.INT),
|
||||
new ParameterInfoImpl(0, "b", new PsiEllipsisType(PsiType.BOOLEAN))
|
||||
ParameterInfoImpl.create(1).withName("i").withType(PsiType.INT),
|
||||
ParameterInfoImpl.create(0).withName("b").withType(new PsiEllipsisType(PsiType.BOOLEAN))
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testJavadocOfDeleted() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "role", PsiType.INT),
|
||||
ParameterInfoImpl.create(0).withName("role").withType(PsiType.INT),
|
||||
}, false);
|
||||
}
|
||||
|
||||
@@ -340,61 +338,61 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
|
||||
public void testReorderWithVarargs() { // IDEADEV-26977
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1),
|
||||
new ParameterInfoImpl(0, "s", myFactory.createTypeFromText("java.lang.String...", getFile()))
|
||||
ParameterInfoImpl.create(1),
|
||||
ParameterInfoImpl.create(0).withName("s").withType(myFactory.createTypeFromText("java.lang.String...", getFile()))
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testReorderWithVarargsFromSimpleType() {
|
||||
doTest(null, new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1),
|
||||
new ParameterInfoImpl(0, "s", myFactory.createTypeFromText("java.lang.String...", getFile()))
|
||||
ParameterInfoImpl.create(1),
|
||||
ParameterInfoImpl.create(0).withName("s").withType(myFactory.createTypeFromText("java.lang.String...", getFile()))
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testIntroduceParameterWithDefaultValueInHierarchy() {
|
||||
doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "0")}, false);
|
||||
doTest(null, new ParameterInfoImpl[]{ParameterInfoImpl.createNew().withName("i").withType(PsiType.INT).withDefaultValue("0")}, false);
|
||||
}
|
||||
|
||||
public void testReorderMultilineMethodParameters() {
|
||||
// Inspired by IDEA-54902
|
||||
doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1), new ParameterInfoImpl(0)}, false);
|
||||
doTest(null, new ParameterInfoImpl[]{ParameterInfoImpl.create(1), ParameterInfoImpl.create(0)}, false);
|
||||
}
|
||||
|
||||
public void testRemoveFirstParameter() {
|
||||
doTest(null, new ParameterInfoImpl[]{new ParameterInfoImpl(1)}, false);
|
||||
doTest(null, new ParameterInfoImpl[]{ParameterInfoImpl.create(1)}, false);
|
||||
}
|
||||
|
||||
public void testReplaceVarargWithArray() {
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1, "l", myFactory.createTypeFromText("List<T>[]", method.getParameterList()), "null", false),
|
||||
new ParameterInfoImpl(0, "s", myFactory.createTypeFromText("String", method.getParameterList()))
|
||||
ParameterInfoImpl.create(1).withName("l").withType(myFactory.createTypeFromText("List<T>[]", method.getParameterList())).withDefaultValue("null"),
|
||||
ParameterInfoImpl.create(0).withName("s").withType(myFactory.createTypeFromText("String", method.getParameterList()))
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testReplaceOldStyleArrayWithVarargs() {
|
||||
doTest(null, new ParameterInfoImpl[] {new ParameterInfoImpl(0, "a", new PsiEllipsisType(PsiType.INT))}, false);
|
||||
doTest(null, new ParameterInfoImpl[] {ParameterInfoImpl.create(0).withName("a").withType(new PsiEllipsisType(PsiType.INT))}, false);
|
||||
}
|
||||
|
||||
public void testReorderParamsOfFunctionalInterface() {
|
||||
doTest(null, null, null, method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1, "b", PsiType.INT),
|
||||
new ParameterInfoImpl(0, "a", PsiType.BOOLEAN)
|
||||
ParameterInfoImpl.create(1).withName("b").withType(PsiType.INT),
|
||||
ParameterInfoImpl.create(0).withName("a").withType(PsiType.BOOLEAN)
|
||||
}, false);
|
||||
}
|
||||
|
||||
public void testReorderParamsOfFunctionalInterfaceExpandMethodReference() {
|
||||
GenParams genParams = method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(1, "b", PsiType.INT),
|
||||
new ParameterInfoImpl(0, "a", PsiType.INT)
|
||||
ParameterInfoImpl.create(1).withName("b").withType(PsiType.INT),
|
||||
ParameterInfoImpl.create(0).withName("a").withType(PsiType.INT)
|
||||
};
|
||||
doTest(null, null, null, genParams, new SimpleExceptionsGen(), false, true);
|
||||
}
|
||||
|
||||
public void testAddParenthesisForLambdaParameterList() {
|
||||
GenParams genParams = method -> new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(0, "a", PsiType.INT),
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.INT)
|
||||
ParameterInfoImpl.create(0).withName("a").withType(PsiType.INT),
|
||||
ParameterInfoImpl.createNew().withName("b").withType(PsiType.INT)
|
||||
};
|
||||
doTest(null, null, null, genParams, new SimpleExceptionsGen(), false, true);
|
||||
}
|
||||
@@ -410,7 +408,7 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
}
|
||||
|
||||
public void testRenameMethodUsedInMethodReference() {
|
||||
GenParams genParams = method -> new ParameterInfoImpl[] {new ParameterInfoImpl(0, "a", PsiType.INT)};
|
||||
GenParams genParams = method -> new ParameterInfoImpl[] {ParameterInfoImpl.create(0).withName("a").withType(PsiType.INT)};
|
||||
doTest(PsiModifier.PRIVATE, "alwaysFalse", null, genParams, new SimpleExceptionsGen(), false, false);
|
||||
}
|
||||
|
||||
@@ -468,8 +466,8 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
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(NEW_PARAMETER, "b", PsiType.BOOLEAN)}, null, propagateParametersMethods, null
|
||||
ParameterInfoImpl.create(0).withName(parameters[0].getName()).withType(parameters[0].getType()),
|
||||
ParameterInfoImpl.createNew().withName("b").withType(PsiType.BOOLEAN)}, null, propagateParametersMethods, null
|
||||
).run();
|
||||
checkResultByFile(basePath + "_after.java");
|
||||
}
|
||||
@@ -490,8 +488,8 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
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(NEW_PARAMETER, "b", PsiType.BOOLEAN, "true")}, null, propagateParametersMethods, null
|
||||
ParameterInfoImpl.create(0).withName(parameters[0].getName()).withType(parameters[0].getType()),
|
||||
ParameterInfoImpl.createNew().withName("b").withType(PsiType.BOOLEAN).withDefaultValue("true")}, null, propagateParametersMethods, null
|
||||
).run();
|
||||
checkResultByFile(basePath + "_after.java");
|
||||
}
|
||||
@@ -509,9 +507,9 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
GenParams genParams = method -> {
|
||||
PsiClassType stringType = PsiType.getJavaLangString(method.getManager(), method.getResolveScope());
|
||||
return new ParameterInfoImpl[]{
|
||||
new ParameterInfoImpl(2, "a", stringType),
|
||||
new ParameterInfoImpl(0, "b", stringType),
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "c", stringType)
|
||||
ParameterInfoImpl.create(2).withName("a").withType(stringType),
|
||||
ParameterInfoImpl.create(0).withName("b").withType(stringType),
|
||||
ParameterInfoImpl.createNew().withName("c").withType(stringType)
|
||||
};
|
||||
};
|
||||
doTest(null, null, null, genParams, new SimpleExceptionsGen(), false, false);
|
||||
|
||||
+8
-21
@@ -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;
|
||||
|
||||
@@ -76,7 +62,7 @@ public class IntroduceParameterObjectTest extends LightMultiFileTestCase {
|
||||
final ParameterInfoImpl[] datas = new ParameterInfoImpl[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
datas[i] = new ParameterInfoImpl(i, parameter.getName(), parameter.getType());
|
||||
datas[i] = ParameterInfoImpl.create(i).withName(parameter.getName()).withType(parameter.getType());
|
||||
}
|
||||
return datas;
|
||||
}
|
||||
@@ -144,7 +130,7 @@ public class IntroduceParameterObjectTest extends LightMultiFileTestCase {
|
||||
final ParameterInfoImpl[] datas = new ParameterInfoImpl[parameters.length - 1];
|
||||
for (int i = 0; i < parameters.length - 1; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
datas[i] = new ParameterInfoImpl(i, parameter.getName(), parameter.getType());
|
||||
datas[i] = ParameterInfoImpl.create(i).withName(parameter.getName()).withType(parameter.getType());
|
||||
}
|
||||
return datas;
|
||||
});
|
||||
@@ -157,7 +143,7 @@ public class IntroduceParameterObjectTest extends LightMultiFileTestCase {
|
||||
final ParameterInfoImpl[] datas = new ParameterInfoImpl[parameters.length - 1];
|
||||
for (int i = 0; i < parameters.length - 1; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
datas[i] = new ParameterInfoImpl(i, parameter.getName(), parameter.getType());
|
||||
datas[i] = ParameterInfoImpl.create(i).withName(parameter.getName()).withType(parameter.getType());
|
||||
}
|
||||
return datas;
|
||||
});
|
||||
@@ -167,7 +153,7 @@ public class IntroduceParameterObjectTest extends LightMultiFileTestCase {
|
||||
doTestExistingClass("Param", "", false, "public", method -> {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
PsiParameter parameter = parameters[1];
|
||||
return new ParameterInfoImpl[]{new ParameterInfoImpl(1, parameter.getName(), parameter.getType())};
|
||||
return new ParameterInfoImpl[]{ParameterInfoImpl.create(1).withName(parameter.getName()).withType(parameter.getType())};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -175,8 +161,9 @@ public class IntroduceParameterObjectTest extends LightMultiFileTestCase {
|
||||
doTest(false, true, psiMethod -> {
|
||||
final PsiParameter parameter = psiMethod.getParameterList().getParameters()[0];
|
||||
final PsiClass collectionClass = myFixture.findClass(CommonClassNames.JAVA_UTIL_COLLECTION);
|
||||
final ParameterInfoImpl variableData =
|
||||
new ParameterInfoImpl(0, parameter.getName(), JavaPsiFacade.getElementFactory(getProject()).createType(collectionClass));
|
||||
final ParameterInfoImpl variableData = ParameterInfoImpl.create(0)
|
||||
.withName(parameter.getName())
|
||||
.withType(JavaPsiFacade.getElementFactory(getProject()).createType(collectionClass));
|
||||
return new ParameterInfoImpl[]{variableData};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -131,7 +131,10 @@ public class BoundedWildcardInspection extends AbstractBaseJavaLocalInspectionTo
|
||||
}
|
||||
|
||||
int[] i = {0};
|
||||
List<ParameterInfoImpl> parameterInfos = ContainerUtil.map(method.getParameterList().getParameters(), p -> new ParameterInfoImpl(i[0]++, p.getName(), p.getType()));
|
||||
List<ParameterInfoImpl> parameterInfos = ContainerUtil.map(method.getParameterList().getParameters(),
|
||||
p -> ParameterInfoImpl.create(i[0]++)
|
||||
.withName(p.getName())
|
||||
.withType(p.getType()));
|
||||
int index = method.getParameterList().getParameterIndex(candidate.methodParameter);
|
||||
if (index == -1) return;
|
||||
|
||||
@@ -142,9 +145,10 @@ public class BoundedWildcardInspection extends AbstractBaseJavaLocalInspectionTo
|
||||
candidate = candidate.getSuperMethodVarianceCandidate(superMethod);
|
||||
clone = suggestMethodParameterType(candidate, isExtends);
|
||||
i[0] = 0;
|
||||
parameterInfos = ContainerUtil.map(superMethod.getParameterList().getParameters(), p -> new ParameterInfoImpl(i[0]++, p.getName(), p.getType()));
|
||||
parameterInfos = ContainerUtil.map(superMethod.getParameterList().getParameters(),
|
||||
p -> ParameterInfoImpl.create(i[0]++).withName(p.getName()).withType(p.getType()));
|
||||
}
|
||||
parameterInfos.set(index, new ParameterInfoImpl(index, candidate.methodParameter.getName(), clone));
|
||||
parameterInfos.set(index, ParameterInfoImpl.create(index).withName(candidate.methodParameter.getName()).withType(clone));
|
||||
|
||||
JavaChangeSignatureDialog
|
||||
dialog = JavaChangeSignatureDialog.createAndPreselectNew(project, method, parameterInfos, false, null/*todo?*/);
|
||||
|
||||
+4
-1
@@ -132,7 +132,10 @@ 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(NEW_PARAMETER, name, type, PsiTypesUtil.getDefaultValueOfType(type), false);
|
||||
ParameterInfoImpl parameterInfo = ParameterInfoImpl.createNew()
|
||||
.withName(name)
|
||||
.withType(type)
|
||||
.withDefaultValue(PsiTypesUtil.getDefaultValueOfType(type));
|
||||
if (!method.isVarArgs()) {
|
||||
parameterInfos.add(parameterInfo);
|
||||
}
|
||||
|
||||
+69
-78
@@ -14,8 +14,6 @@ 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
|
||||
*/
|
||||
@@ -29,15 +27,15 @@ class ChangeSignatureForJavaTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
void testParameterReorder() throws Exception {
|
||||
doTest null, [new ParameterInfoImpl(1), new ParameterInfoImpl(0)], false
|
||||
doTest null, [ParameterInfoImpl.create(1), ParameterInfoImpl.create(0)], false
|
||||
}
|
||||
|
||||
void testGenericTypes() throws Exception {
|
||||
doTest null, null, "T", { PsiMethod method ->
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory()
|
||||
return [
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "x", factory.createTypeFromText("T", method.getParameterList()), "null"),
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "y", factory.createTypeFromText("C<T>", method.getParameterList()), "null")
|
||||
ParameterInfoImpl.createNew().withName("x").withType(factory.createTypeFromText("T", method.getParameterList())).withDefaultValue("null"),
|
||||
ParameterInfoImpl.createNew().withName("y").withType(factory.createTypeFromText("C<T>", method.getParameterList())).withDefaultValue("null")
|
||||
]
|
||||
}, false
|
||||
}
|
||||
@@ -46,7 +44,7 @@ class ChangeSignatureForJavaTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
doTest null, null, null, { PsiMethod method ->
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory()
|
||||
return [
|
||||
new ParameterInfoImpl(0, "t", factory.createTypeFromText("T", method), null)
|
||||
ParameterInfoImpl.create(0).withName("t").withType(factory.createTypeFromText("T", method)).withDefaultValue(null)
|
||||
]
|
||||
}, false
|
||||
}
|
||||
@@ -55,98 +53,93 @@ class ChangeSignatureForJavaTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
doTest null, null, null, { PsiMethod method ->
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory()
|
||||
return [
|
||||
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")
|
||||
ParameterInfoImpl.createNew().withName("t").withType(factory.createTypeFromText("T", method.getParameterList())).withDefaultValue("null"),
|
||||
ParameterInfoImpl.createNew().withName("u").withType(factory.createTypeFromText("U", method.getParameterList())).withDefaultValue("null"),
|
||||
ParameterInfoImpl.createNew().withName("cu").withType(factory.createTypeFromText("C<U>", method.getParameterList())).withDefaultValue("null")
|
||||
]
|
||||
}, false
|
||||
}
|
||||
|
||||
void testDefaultConstructor() throws Exception {
|
||||
doTest null, [new ParameterInfoImpl(NEW_PARAMETER, "j", PsiType.INT, "27")], false
|
||||
doTest null, [ParameterInfoImpl.createNew().withName("j").withType(PsiType.INT).withDefaultValue("27")], false
|
||||
}
|
||||
|
||||
void testGenerateDelegate() throws Exception {
|
||||
doTest null, [new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27")], true
|
||||
doTest null, [ParameterInfoImpl.createNew().withName("i").withType(PsiType.INT).withDefaultValue("27")], true
|
||||
}
|
||||
|
||||
/*public void testGenerateDelegateForAbstract() throws Exception {
|
||||
/*void testGenerateDelegateForAbstract() throws Exception {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27")
|
||||
}, true);
|
||||
[
|
||||
ParameterInfoImpl.createNew().withName("i").withType(PsiType.INT).withDefaultValue("27")
|
||||
], true)
|
||||
}
|
||||
|
||||
public void testGenerateDelegateWithReturn() throws Exception {
|
||||
void testGenerateDelegateWithReturn() throws Exception {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27")
|
||||
}, true);
|
||||
[
|
||||
ParameterInfoImpl.createNew().withName("i").withType(PsiType.INT).withDefaultValue("27")
|
||||
], true)
|
||||
}
|
||||
|
||||
public void testGenerateDelegateWithParametersReordering() throws Exception {
|
||||
void testGenerateDelegateWithParametersReordering() throws Exception {
|
||||
doTest(null,
|
||||
new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(1),
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "c", PsiType.CHAR, "'a'"),
|
||||
new ParameterInfoImpl(0, "j", PsiType.INT)
|
||||
}, true);
|
||||
[
|
||||
ParameterInfoImpl.create(1),
|
||||
ParameterInfoImpl.createNew().withName("c").withType(PsiType.CHAR).withDefaultValue("'a'"),
|
||||
ParameterInfoImpl.create(0).withName("j").withType(PsiType.INT)
|
||||
], true)
|
||||
}
|
||||
|
||||
public void testGenerateDelegateConstructor() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[0], true);
|
||||
}
|
||||
*/
|
||||
void testGenerateDelegateConstructor() throws Exception {
|
||||
doTest(null, [], true)
|
||||
}*/
|
||||
|
||||
void testGenerateDelegateDefaultConstructor() throws Exception {
|
||||
doTest null, [new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "27")], true
|
||||
doTest null, [ParameterInfoImpl.createNew().withName("i").withType(PsiType.INT).withDefaultValue("27")], true
|
||||
}
|
||||
|
||||
/*
|
||||
public void testSCR40895() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(0, "y", PsiType.INT),
|
||||
new ParameterInfoImpl(1, "b", PsiType.BOOLEAN)
|
||||
}, false);
|
||||
/*void testSCR40895() throws Exception {
|
||||
doTest(null, [
|
||||
ParameterInfoImpl.create(0).withName("y").withType(PsiType.INT),
|
||||
ParameterInfoImpl.create(1).withName("b").withType(PsiType.BOOLEAN)
|
||||
], false)
|
||||
}
|
||||
|
||||
|
||||
public void testSuperCallFromOtherMethod() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "nnn", PsiType.INT, "-222"),
|
||||
}, false);
|
||||
}
|
||||
*/
|
||||
void testSuperCallFromOtherMethod() throws Exception {
|
||||
doTest(null, [
|
||||
ParameterInfoImpl.createNew().withName("nnn").withType(PsiType.INT).withDefaultValue("-222"),
|
||||
], false)
|
||||
}*/
|
||||
|
||||
/*//todo?
|
||||
public void testUseAnyVariable() throws Exception {
|
||||
doTest(null, null, null, new GenParams() {
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
|
||||
return new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "l", factory.createTypeFromText("List", method), "null", true)
|
||||
};
|
||||
}
|
||||
}, false);
|
||||
//todo?
|
||||
/*void testUseAnyVariable() throws Exception {
|
||||
doTest(null, null, null, { PsiMethod method ->
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory()
|
||||
return [
|
||||
ParameterInfoImpl.createNew().withName("l").withType(factory.createTypeFromText("List", method)).withDefaultValue("null").useAnySingleVariable()
|
||||
]
|
||||
}, false)
|
||||
}*/
|
||||
|
||||
/*
|
||||
public void testRemoveVarargParameter() throws Exception {
|
||||
doTest(null, null, null, new ParameterInfoImpl[]{new ParameterInfoImpl(0)}, new ThrownExceptionInfo[0], false);
|
||||
void testRemoveVarargParameter() throws Exception {
|
||||
doTest(null, null, null, [ParameterInfoImpl.create(0)], [], false)
|
||||
}
|
||||
|
||||
|
||||
public void testEnumConstructor() throws Exception {
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "i", PsiType.INT, "10")
|
||||
}, false);
|
||||
void testEnumConstructor() throws Exception {
|
||||
doTest(null, [
|
||||
ParameterInfoImpl.createNew().withName("i").withType(PsiType.INT).withDefaultValue("10")
|
||||
], false)
|
||||
}
|
||||
*/
|
||||
|
||||
void testVarargs1() throws Exception {
|
||||
doTest null, [
|
||||
new ParameterInfoImpl(NEW_PARAMETER, "b", PsiType.BOOLEAN, "true"),
|
||||
new ParameterInfoImpl(0)
|
||||
ParameterInfoImpl.createNew().withName("b").withType(PsiType.BOOLEAN).withDefaultValue("true"),
|
||||
ParameterInfoImpl.create(0)
|
||||
], false
|
||||
}
|
||||
|
||||
@@ -165,23 +158,21 @@ class ChangeSignatureForJavaTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
public ThrownExceptionInfo[] genExceptions(PsiMethod method) {
|
||||
return new ThrownExceptionInfo[] {
|
||||
new JavaThrownExceptionInfo(-1, JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createTypeByFQClassName("java.lang.Exception", method.getResolveScope()))
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
false);
|
||||
false)
|
||||
}*/
|
||||
|
||||
/*
|
||||
public void testAddRuntimeException() throws Exception {
|
||||
doTest(null, null, null, new SimpleParameterGen(new ParameterInfoImpl[0]),
|
||||
new GenExceptions() {
|
||||
public ThrownExceptionInfo[] genExceptions(PsiMethod method) {
|
||||
return new ThrownExceptionInfo[] {
|
||||
new JavaThrownExceptionInfo(-1, JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createTypeByFQClassName("java.lang.RuntimeException", method.getResolveScope()))
|
||||
};
|
||||
}
|
||||
},
|
||||
false);
|
||||
void testAddRuntimeException() throws Exception {
|
||||
doTest(null, null, null, new SimpleParameterGen(), { PsiMethod method ->
|
||||
return [
|
||||
new JavaThrownExceptionInfo(-1, JavaPsiFacade.getInstance(method.getProject()).getElementFactory().createTypeByFQClassName(
|
||||
"java.lang.RuntimeException", method.getResolveScope()))
|
||||
]
|
||||
},
|
||||
false)
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -196,12 +187,12 @@ class ChangeSignatureForJavaTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
|
||||
/*
|
||||
//todo
|
||||
public void testReorderWithVarargs() throws Exception { // IDEADEV-26977
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
doTest(null, new ParameterInfoImpl[] {
|
||||
new ParameterInfoImpl(1),
|
||||
new ParameterInfoImpl(0, "s", factory.createTypeFromText("java.lang.String...", myFixture.getFile()))
|
||||
}, false);
|
||||
void testReorderWithVarargs() throws Exception { // IDEADEV-26977
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory()
|
||||
doTest(null, [
|
||||
ParameterInfoImpl.create(1),
|
||||
ParameterInfoImpl.create(0).withName("s").withType(factory.createTypeFromText("java.lang.String...", myFixture.getFile()))
|
||||
], false)
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
+2
-2
@@ -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.javaFX.fxml.codeInsight.inspections;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
@@ -219,7 +219,7 @@ public class JavaFxEventHandlerInspection extends XmlSuppressableInspectionTool
|
||||
final PsiClassType declaredType = JavaFxPsiUtil.getDeclaredEventType(attribute);
|
||||
if (declaredType == null) return;
|
||||
|
||||
final ParameterInfoImpl parameterInfo = new ParameterInfoImpl(0, parameterName, declaredType);
|
||||
final ParameterInfoImpl parameterInfo = ParameterInfoImpl.create(0).withName(parameterName).withType(declaredType);
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
final ChangeSignatureProcessor processor =
|
||||
new ChangeSignatureProcessor(project, method, false, null, method.getName(), method.getReturnType(),
|
||||
|
||||
Reference in New Issue
Block a user