Don't ask user to choose method for renaming parameter when it is changed in overridden function.
This commit is contained in:
@@ -844,7 +844,7 @@ public class OverrideResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldReportParameterNameOverrideWarning(
|
||||
public static boolean shouldReportParameterNameOverrideWarning(
|
||||
@NotNull ValueParameterDescriptor parameterFromSubclass,
|
||||
@NotNull ValueParameterDescriptor parameterFromSuperclass
|
||||
) {
|
||||
|
||||
@@ -172,6 +172,11 @@ public class AddFunctionParametersFix extends ChangeFunctionSignatureFix {
|
||||
PsiElement onlyFunction = affectedFunctions.iterator().next();
|
||||
return !hasTypeMismatches && !isConstructor() && !hasOtherUsages(onlyFunction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forcePerformForSelectedFunctionOnly() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,11 @@ public class ChangeFunctionLiteralSignatureFix extends ChangeFunctionSignatureFi
|
||||
public boolean performSilently(@NotNull Collection<? extends PsiElement> elements) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forcePerformForSelectedFunctionOnly() {
|
||||
return false;
|
||||
}
|
||||
}, bindingContext, context, getText());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,11 @@ public class RemoveFunctionParametersFix extends ChangeFunctionSignatureFix {
|
||||
public boolean performSilently(@NotNull Collection<? extends PsiElement> elements) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forcePerformForSelectedFunctionOnly() {
|
||||
return false;
|
||||
}
|
||||
}, bindingContext, context, getText());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.psi.JetDeclarationWithBody
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetChangeSignature
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
|
||||
public abstract class CallableRefactoring<T: CallableDescriptor>(
|
||||
@@ -61,6 +62,10 @@ public abstract class CallableRefactoring<T: CallableDescriptor>(
|
||||
|
||||
private val kind = (callableDescriptor as? CallableMemberDescriptor)?.getKind() ?: CallableMemberDescriptor.Kind.DECLARATION
|
||||
|
||||
protected open fun forcePerformForSelectedFunctionOnly(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
private fun getClosestModifiableDescriptors(): Set<CallableDescriptor> {
|
||||
return when (kind) {
|
||||
DECLARATION -> {
|
||||
@@ -138,6 +143,11 @@ public abstract class CallableRefactoring<T: CallableDescriptor>(
|
||||
}
|
||||
|
||||
val closestModifiableDescriptors = getClosestModifiableDescriptors()
|
||||
if (forcePerformForSelectedFunctionOnly()) {
|
||||
performRefactoring(closestModifiableDescriptors)
|
||||
return true
|
||||
}
|
||||
|
||||
assert(!closestModifiableDescriptors.isEmpty(), "Should contain original declaration or some of its super declarations")
|
||||
val deepestSuperDeclarations =
|
||||
(callableDescriptor as? CallableMemberDescriptor)?.let { OverrideResolver.getDeepestSuperDeclarations(it) }
|
||||
|
||||
@@ -37,6 +37,10 @@ public trait JetChangeSignatureConfiguration {
|
||||
fun performSilently(affectedFunctions: Collection<PsiElement>): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
fun forcePerformForSelectedFunctionOnly(): Boolean {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
fun JetMethodDescriptor.modify(action: JetMutableMethodDescriptor.() -> Unit): JetMethodDescriptor {
|
||||
@@ -63,6 +67,8 @@ public class JetChangeSignature(project: Project,
|
||||
|
||||
private val LOG = Logger.getInstance(javaClass<JetChangeSignature>())
|
||||
|
||||
override fun forcePerformForSelectedFunctionOnly() = configuration.forcePerformForSelectedFunctionOnly()
|
||||
|
||||
override fun performRefactoring(descriptorsForChange: Collection<CallableDescriptor>) {
|
||||
assert (descriptorsForChange.all { it is FunctionDescriptor }) {
|
||||
"Function descriptors expected: " + descriptorsForChange.joinToString(separator = "\n")
|
||||
|
||||
+5
@@ -154,6 +154,11 @@ public class JetChangeSignatureHandler implements ChangeSignatureHandler {
|
||||
public boolean performSilently(@NotNull Collection<? extends PsiElement> elements) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forcePerformForSelectedFunctionOnly() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+10
-2
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.psi.JetNamedFunction
|
||||
import org.jetbrains.kotlin.psi.JetParameter
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.OverrideResolver
|
||||
|
||||
public class RenameKotlinParameterProcessor : RenameKotlinPsiProcessor() {
|
||||
override fun canProcessElement(element: PsiElement): Boolean {
|
||||
@@ -41,7 +42,12 @@ public class RenameKotlinParameterProcessor : RenameKotlinPsiProcessor() {
|
||||
assert(paramIndex != -1, { "couldn't find parameter in parent ${element.getElementTextWithContext()}" })
|
||||
|
||||
val context = function.analyze()
|
||||
val descriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, function] as? FunctionDescriptor ?: return
|
||||
val functionDescriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, function] as? FunctionDescriptor ?: return
|
||||
val parameterDescriptor = functionDescriptor.getValueParameters()[paramIndex]
|
||||
|
||||
val parameterNameChangedOnOverride = parameterDescriptor.getOverriddenDescriptors().any {
|
||||
overriddenParameter -> OverrideResolver.shouldReportParameterNameOverrideWarning(parameterDescriptor, overriddenParameter)
|
||||
}
|
||||
|
||||
val changeSignatureConfiguration = object : JetChangeSignatureConfiguration {
|
||||
override fun configure(originalDescriptor: JetMethodDescriptor, bindingContext: BindingContext): JetMethodDescriptor {
|
||||
@@ -49,8 +55,10 @@ public class RenameKotlinParameterProcessor : RenameKotlinPsiProcessor() {
|
||||
}
|
||||
|
||||
override fun performSilently(affectedFunctions: Collection<PsiElement>) = true
|
||||
|
||||
override fun forcePerformForSelectedFunctionOnly() = parameterNameChangedOnOverride
|
||||
}
|
||||
|
||||
runChangeSignature(element.getProject(), descriptor, changeSignatureConfiguration, context, element, "Rename parameter")
|
||||
runChangeSignature(element.getProject(), functionDescriptor, changeSignatureConfiguration, context, element, "Rename parameter")
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -243,6 +243,11 @@ public class JetChangeSignatureTest extends KotlinCodeInsightTestCase {
|
||||
public boolean performSilently(@NotNull Collection<? extends PsiElement> elements) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forcePerformForSelectedFunctionOnly() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
BindingContext context = ResolvePackage.analyze(method, BodyResolveMode.FULL);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user