Eliminate redundant descriptorToDeclaration call from factory for "Change signature" quick fixes
This commit is contained in:
@@ -44,12 +44,11 @@ public class AddFunctionParametersFix extends ChangeFunctionSignatureFix {
|
||||
private final boolean hasTypeMismatches;
|
||||
|
||||
public AddFunctionParametersFix(
|
||||
@NotNull PsiElement declaration,
|
||||
@NotNull JetCallElement callElement,
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
boolean hasTypeMismatches
|
||||
) {
|
||||
super(declaration, callElement, functionDescriptor);
|
||||
super(callElement, functionDescriptor);
|
||||
this.callElement = callElement;
|
||||
this.hasTypeMismatches = hasTypeMismatches;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ChangeFunctionLiteralSignatureFix extends ChangeFunctionSignatureFi
|
||||
@NotNull JetFunctionLiteral functionLiteral,
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
@NotNull List<JetType> parameterTypes) {
|
||||
super(functionLiteral, functionLiteral, functionDescriptor);
|
||||
super(functionLiteral, functionDescriptor);
|
||||
this.parameterTypes = parameterTypes;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters1;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
@@ -47,11 +46,10 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
||||
protected final FunctionDescriptor functionDescriptor;
|
||||
|
||||
public ChangeFunctionSignatureFix(
|
||||
@NotNull PsiElement element,
|
||||
@NotNull PsiElement context,
|
||||
@NotNull FunctionDescriptor functionDescriptor
|
||||
) {
|
||||
super(element);
|
||||
super(context);
|
||||
this.context = context;
|
||||
this.functionDescriptor = functionDescriptor;
|
||||
}
|
||||
@@ -99,9 +97,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
||||
BindingContext bindingContext
|
||||
) {
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
assert i <
|
||||
arguments
|
||||
.size(); // number of parameters must not be greater than the number of arguments (it's called only for TOO_MANY_ARGUMENTS error)
|
||||
assert i < arguments .size(); // number of parameters must not be greater than the number of arguments (it's called only for TOO_MANY_ARGUMENTS error)
|
||||
JetExpression argumentExpression = arguments.get(i).getArgumentExpression();
|
||||
JetType argumentType =
|
||||
argumentExpression != null ? bindingContext.get(BindingContext.EXPRESSION_TYPE, argumentExpression) : null;
|
||||
@@ -192,13 +188,8 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
||||
}
|
||||
BindingContext bindingContext =
|
||||
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) context.getContainingFile()).getBindingContext();
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bindingContext, functionDescriptor);
|
||||
|
||||
if (declaration == null) {
|
||||
return null;
|
||||
}
|
||||
if (descriptor instanceof ValueParameterDescriptor) {
|
||||
return new RemoveFunctionParametersFix(declaration, context, functionDescriptor, (ValueParameterDescriptor) descriptor);
|
||||
return new RemoveFunctionParametersFix(context, functionDescriptor, (ValueParameterDescriptor) descriptor);
|
||||
}
|
||||
else {
|
||||
List<ValueParameterDescriptor> parameters = functionDescriptor.getValueParameters();
|
||||
@@ -206,7 +197,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
||||
|
||||
if (arguments.size() > parameters.size()) {
|
||||
boolean hasTypeMismatches = hasTypeMismatches(parameters, arguments, bindingContext);
|
||||
return new AddFunctionParametersFix(declaration, callElement, functionDescriptor, hasTypeMismatches);
|
||||
return new AddFunctionParametersFix(callElement, functionDescriptor, hasTypeMismatches);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,12 +37,11 @@ public class RemoveFunctionParametersFix extends ChangeFunctionSignatureFix {
|
||||
private final ValueParameterDescriptor parameterToRemove;
|
||||
|
||||
public RemoveFunctionParametersFix(
|
||||
@NotNull PsiElement element,
|
||||
@NotNull PsiElement context,
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
@NotNull ValueParameterDescriptor parameterToRemove
|
||||
) {
|
||||
super(element, context, functionDescriptor);
|
||||
super(context, functionDescriptor);
|
||||
this.parameterToRemove = parameterToRemove;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// "Add parameter to function 'f'" "true"
|
||||
trait Z {
|
||||
fun f(i: Int)
|
||||
}
|
||||
|
||||
trait ZZ {
|
||||
fun f(i: Int)
|
||||
}
|
||||
|
||||
trait ZZZ: Z, ZZ {
|
||||
}
|
||||
|
||||
trait ZZZZ : ZZZ {
|
||||
override fun f(i: Int)
|
||||
}
|
||||
|
||||
fun usage(z: ZZZ) {
|
||||
z.f(3)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// "Remove parameter 'i'" "true"
|
||||
trait Z {
|
||||
fun f()
|
||||
}
|
||||
|
||||
trait ZZ {
|
||||
fun f()
|
||||
}
|
||||
|
||||
trait ZZZ: Z, ZZ {
|
||||
}
|
||||
|
||||
trait ZZZZ : ZZZ {
|
||||
override fun f()
|
||||
}
|
||||
|
||||
fun usage(z: ZZZ) {
|
||||
z.f()
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// "Add parameter to function 'f'" "true"
|
||||
trait Z {
|
||||
fun f()
|
||||
}
|
||||
|
||||
trait ZZ {
|
||||
fun f()
|
||||
}
|
||||
|
||||
trait ZZZ: Z, ZZ {
|
||||
}
|
||||
|
||||
trait ZZZZ : ZZZ {
|
||||
override fun f()
|
||||
}
|
||||
|
||||
fun usage(z: ZZZ) {
|
||||
z.f(<caret>3)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// "Remove parameter 'i'" "true"
|
||||
trait Z {
|
||||
fun f(i: Int)
|
||||
}
|
||||
|
||||
trait ZZ {
|
||||
fun f(i: Int)
|
||||
}
|
||||
|
||||
trait ZZZ: Z, ZZ {
|
||||
}
|
||||
|
||||
trait ZZZZ : ZZZ {
|
||||
override fun f(i: Int)
|
||||
}
|
||||
|
||||
fun usage(z: ZZZ) {
|
||||
z.f(<caret>)
|
||||
}
|
||||
@@ -375,6 +375,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest("idea/testData/quickfix/changeSignature/beforeAddFunctionParameterAndChangeTypes.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeAddParameterToFakeOverride.kt")
|
||||
public void testAddParameterToFakeOverride() throws Exception {
|
||||
doTest("idea/testData/quickfix/changeSignature/beforeAddParameterToFakeOverride.kt");
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInChangeSignature() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/changeSignature"), Pattern.compile("^before(\\w+)\\.kt$"), true);
|
||||
}
|
||||
@@ -434,6 +439,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest("idea/testData/quickfix/changeSignature/beforeRemoveNamedParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeRemoveParameterFromFakeOverride.kt")
|
||||
public void testRemoveParameterFromFakeOverride() throws Exception {
|
||||
doTest("idea/testData/quickfix/changeSignature/beforeRemoveParameterFromFakeOverride.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("beforeRemoveUnusedParameter.kt")
|
||||
public void testRemoveUnusedParameter() throws Exception {
|
||||
doTest("idea/testData/quickfix/changeSignature/beforeRemoveUnusedParameter.kt");
|
||||
|
||||
Reference in New Issue
Block a user