mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
change signature: warn if delete parameter and corresponding argument can have side effects
This commit is contained in:
+17
@@ -18,6 +18,7 @@ package com.intellij.refactoring.changeSignature;
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.ExceptionUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.RemoveUnusedVariableUtil;
|
||||
import com.intellij.codeInspection.dataFlow.ControlFlowAnalyzer;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
@@ -1034,6 +1035,22 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
|
||||
else if (element instanceof PsiMethodReferenceExpression && MethodReferenceUsageInfo.needToExpand(myChangeInfo)) {
|
||||
conflictDescriptions.putValue(element, RefactoringBundle.message("expand.method.reference.warning"));
|
||||
}
|
||||
else if (element instanceof PsiJavaCodeReferenceElement) {
|
||||
final PsiElement parent = element.getParent();
|
||||
if (parent instanceof PsiCallExpression) {
|
||||
final PsiExpressionList argumentList = ((PsiCallExpression)parent).getArgumentList();
|
||||
if (argumentList != null) {
|
||||
final PsiExpression[] args = argumentList.getExpressions();
|
||||
for (int i = 0; i < toRemove.length; i++) {
|
||||
if (toRemove[i] && i < args.length) {
|
||||
if (RemoveUnusedVariableUtil.checkSideEffects(args[i], null, new ArrayList<>())) {
|
||||
conflictDescriptions.putValue(args[i], "Parameter '" + myChangeInfo.getOldParameterNames()[i] + "' has usage that is not safe to delete");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return conflictDescriptions;
|
||||
|
||||
@@ -248,7 +248,13 @@ public class ChangeSignatureTest extends ChangeSignatureBaseTest {
|
||||
}
|
||||
|
||||
public void testRemoveVarargParameter() {
|
||||
doTest(null, null, null, new ParameterInfoImpl[]{new ParameterInfoImpl(0)}, new ThrownExceptionInfo[0], false);
|
||||
try {
|
||||
BaseRefactoringProcessor.ConflictsInTestsException.setTestIgnore(true);
|
||||
doTest(null, null, null, new ParameterInfoImpl[]{new ParameterInfoImpl(0)}, new ThrownExceptionInfo[0], false);
|
||||
}
|
||||
finally {
|
||||
BaseRefactoringProcessor.ConflictsInTestsException.setTestIgnore(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void testEnumConstructor() {
|
||||
|
||||
Reference in New Issue
Block a user