mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
change signature: restore explicit check for used parameters
This commit is contained in:
+9
-2
@@ -19,10 +19,14 @@ import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.refactoring.changeSignature.ChangeSignatureProcessor;
|
||||
import com.intellij.refactoring.changeSignature.JavaChangeInfo;
|
||||
import com.intellij.refactoring.changeSignature.JavaChangeInfoImpl;
|
||||
import com.intellij.refactoring.changeSignature.ParameterInfoImpl;
|
||||
import com.intellij.refactoring.util.CanonicalTypes;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.NotNullFunction;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -66,8 +70,11 @@ public class ParameterCanBeLocalInspection extends ParameterCanBeLocalInspection
|
||||
}
|
||||
final ParameterInfoImpl[] newParams = info.toArray(new ParameterInfoImpl[info.size()]);
|
||||
final String visibilityModifier = VisibilityUtil.getVisibilityModifier(method.getModifierList());
|
||||
final ChangeSignatureProcessor cp = new ChangeSignatureProcessor(project, method, false, visibilityModifier,
|
||||
method.getName(), method.getReturnType(), newParams) {
|
||||
final PsiType returnType = method.getReturnType();
|
||||
final JavaChangeInfo changeInfo = new JavaChangeInfoImpl(visibilityModifier, method, method.getName(),
|
||||
returnType != null ? CanonicalTypes.createTypeWrapper(returnType) : null,
|
||||
newParams, null, false, ContainerUtil.newHashSet(), ContainerUtil.newHashSet());
|
||||
final ChangeSignatureProcessor cp = new ChangeSignatureProcessor(project, changeInfo) {
|
||||
@Override
|
||||
protected void performRefactoring(@NotNull UsageInfo[] usages) {
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ public class ChangeSignatureProcessor extends ChangeSignatureProcessorBase {
|
||||
final JavaChangeInfoImpl javaChangeInfo =
|
||||
new JavaChangeInfoImpl(newVisibility, method, newName, newType, parameterInfo, thrownExceptions, generateDelegate,
|
||||
propagateParametersMethods, propagateExceptionsMethods);
|
||||
javaChangeInfo.setRefactoringId(REFACTORING_ID);
|
||||
javaChangeInfo.setCheckUnusedParameter();
|
||||
return javaChangeInfo;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,4 +68,9 @@ public interface JavaChangeInfo extends ChangeInfo {
|
||||
void updateMethod(PsiMethod psiMethod);
|
||||
|
||||
Collection<PsiMethod> getMethodsToPropagateParameters();
|
||||
|
||||
default boolean checkUnusedParameter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class JavaChangeInfoImpl extends UserDataHolderBase implements JavaChange
|
||||
final Set<PsiMethod> propagateParametersMethods;
|
||||
final Set<PsiMethod> propagateExceptionsMethods;
|
||||
|
||||
private String myRefactoringId = null;
|
||||
private boolean myCheckUnusedParameter = false;
|
||||
|
||||
/**
|
||||
* @param newExceptions null if not changed
|
||||
@@ -203,12 +203,13 @@ public class JavaChangeInfoImpl extends UserDataHolderBase implements JavaChange
|
||||
}
|
||||
}
|
||||
|
||||
public String getRefactoringId() {
|
||||
return myRefactoringId;
|
||||
@Override
|
||||
public boolean checkUnusedParameter() {
|
||||
return myCheckUnusedParameter;
|
||||
}
|
||||
|
||||
public void setRefactoringId(String refactoringId) {
|
||||
myRefactoringId = refactoringId;
|
||||
public void setCheckUnusedParameter() {
|
||||
myCheckUnusedParameter = true;
|
||||
}
|
||||
|
||||
protected void fillOldParams(PsiMethod method) {
|
||||
|
||||
+3
-4
@@ -1004,10 +1004,9 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
}
|
||||
|
||||
final boolean[] toRemove = myChangeInfo.toRemoveParm();
|
||||
//final String refactoringId = ((JavaChangeInfoImpl)myChangeInfo).getRefactoringId();
|
||||
//introduce parameter object deletes parameters but replaces their usages with generated code
|
||||
final boolean simpleChangeSignature = false;//ChangeSignatureProcessorBase.REFACTORING_ID.equals(refactoringId);
|
||||
if (simpleChangeSignature) {
|
||||
final boolean checkUnusedParameter = myChangeInfo.checkUnusedParameter();
|
||||
if (checkUnusedParameter) {
|
||||
checkParametersToDelete(myChangeInfo.getMethod(), toRemove, conflictDescriptions);
|
||||
}
|
||||
checkContract(conflictDescriptions, myChangeInfo.getMethod());
|
||||
@@ -1025,7 +1024,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
}
|
||||
else if (prototype != null && baseMethod == myChangeInfo.getMethod()) {
|
||||
ConflictsUtil.checkMethodConflicts(method.getContainingClass(), method, prototype, conflictDescriptions);
|
||||
if (simpleChangeSignature) {
|
||||
if (checkUnusedParameter) {
|
||||
checkParametersToDelete(method, toRemove, conflictDescriptions);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user