mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract method: show conflict for same parameter names (IDEA-174452)
This commit is contained in:
@@ -54,6 +54,8 @@ import javax.swing.border.Border;
|
||||
import java.awt.*;
|
||||
import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
@@ -607,11 +609,13 @@ public class ExtractMethodDialog extends DialogWrapper implements AbstractExtrac
|
||||
}
|
||||
|
||||
protected void checkMethodConflicts(MultiMap<PsiElement, String> conflicts) {
|
||||
checkParametersConflicts(conflicts);
|
||||
PsiMethod prototype;
|
||||
try {
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(myProject).getElementFactory();
|
||||
prototype = factory.createMethod(myNameField.getEnteredName().trim(), myReturnType);
|
||||
if (myTypeParameterList != null) prototype.getTypeParameterList().replace(myTypeParameterList);
|
||||
Set<String> usedNames = new HashSet<>();
|
||||
for (VariableData data : myInputVariables) {
|
||||
if (data.passAsParameter) {
|
||||
prototype.getParameterList().add(factory.createParameter(data.name, data.type));
|
||||
@@ -626,6 +630,17 @@ public class ExtractMethodDialog extends DialogWrapper implements AbstractExtrac
|
||||
ConflictsUtil.checkMethodConflicts(myTargetClass, null, prototype, conflicts);
|
||||
}
|
||||
|
||||
protected void checkParametersConflicts(MultiMap<PsiElement, String> conflicts) {
|
||||
Set<String> usedNames = new HashSet<>();
|
||||
for (VariableData data : myInputVariables) {
|
||||
if (data.passAsParameter) {
|
||||
if (!usedNames.add(data.name)) {
|
||||
conflicts.putValue(null, "Conflicting parameter name: " + data.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiType getReturnType() {
|
||||
return mySelector != null ? mySelector.getSelectedType() : myReturnType;
|
||||
|
||||
+6
@@ -43,6 +43,7 @@ import com.intellij.refactoring.util.RefactoringChangeUtil;
|
||||
import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import com.intellij.refactoring.util.VariableData;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -274,6 +275,11 @@ public class IntroduceFunctionalVariableHandler extends IntroduceVariableHandler
|
||||
return "(" + parametersList + ") -> " + returnTypeString;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkMethodConflicts(MultiMap<PsiElement, String> conflicts) {
|
||||
checkParametersConflicts(conflicts);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getVisibility() {
|
||||
|
||||
Reference in New Issue
Block a user