Change Signature: Fix detection of conflicts in generic classes

This commit is contained in:
Alexey Sedunov
2014-10-01 15:08:13 +04:00
parent 609caa8159
commit 73fc984c4c
6 changed files with 79 additions and 6 deletions
@@ -41,7 +41,6 @@ import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeProjection;
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
import org.jetbrains.jet.plugin.refactoring.changeSignature.usages.JetFunctionCallUsage;
import org.jetbrains.jet.plugin.refactoring.changeSignature.usages.JetFunctionDefinitionUsage;
@@ -49,7 +48,6 @@ import org.jetbrains.jet.plugin.refactoring.changeSignature.usages.JetParameterU
import org.jetbrains.jet.plugin.refactoring.changeSignature.usages.JetUsageInfo;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.Collections;
import java.util.List;
import java.util.Set;
@@ -136,8 +134,8 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
JetScope parametersScope = null;
DeclarationDescriptor containingDeclaration = oldDescriptor != null ? oldDescriptor.getContainingDeclaration() : null;
if (oldDescriptor instanceof ConstructorDescriptor && containingDeclaration instanceof ClassDescriptor)
parametersScope = ((ClassDescriptor) containingDeclaration).getMemberScope(Collections.<TypeProjection>emptyList());
if (oldDescriptor instanceof ConstructorDescriptor && containingDeclaration instanceof ClassDescriptorWithResolutionScopes)
parametersScope = ((ClassDescriptorWithResolutionScopes) containingDeclaration).getScopeForInitializerResolution();
else if (function instanceof JetFunction)
parametersScope = getFunctionBodyScope((JetFunction) function, bindingContext);
@@ -187,8 +185,8 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
@Nullable
private static JetScope getFunctionScope(BindingContext bindingContext, DeclarationDescriptor containingDeclaration) {
if (containingDeclaration instanceof ClassDescriptor)
return ((ClassDescriptor) containingDeclaration).getMemberScope(ContainerUtil.<TypeProjection>emptyList());
if (containingDeclaration instanceof ClassDescriptorWithResolutionScopes)
return ((ClassDescriptorWithResolutionScopes) containingDeclaration).getScopeForInitializerResolution();
else if (containingDeclaration instanceof FunctionDescriptorImpl) {
PsiElement container = DescriptorToSourceUtils.descriptorToDeclaration(containingDeclaration);
@@ -0,0 +1,14 @@
open class C0<X>(val x: X) {}
open class C1<T: Any> (var _x1: T? = null, _x2: Double?, val _x3: ((Int) -> Int)?) : C0<((Int) -> Int)?>(_x3){
fun bar() {
val y1 = _x1;
val y2 = _x2;
}
}
class C2 : C1<Int>(1, 2.5, null<caret>) {
fun foo() {
var c = C1(2, 3.5, null);
c = C1(_x1 = 2, _x2 = 3.5, _x3 = null);
}
}
@@ -0,0 +1,14 @@
open class C0<X>(val x: X) {}
open class C1<T: Any> protected (val x1: T? = null, var x2: Double, x3: ((Int) -> Int)?) : C0<((Int) -> Int)?>(x3){
fun bar() {
val y1 = x1;
val y2 = x2;
}
}
class C2 : C1<Int>(1, 2.5, null<caret>) {
fun foo() {
var c = C1(2, 3.5, null);
c = C1(x1 = 2, x2 = 3.5, x3 = null);
}
}
@@ -0,0 +1,12 @@
public fun foo<T: Any>(<caret>_x1: T? = null, _x2: Double?, _x3: ((T) -> T)?) {
foo(2, 3.5, null);
val y1 = _x1;
val y2 = _x2;
val y3 = _x3;
foo(_x3 = null, _x1 = 2, _x2 = 3.5);
}
fun bar() {
foo(_x1 = 2, _x2 = 3.5, _x3 = null);
foo(_x3 = null, _x1 = 2, _x2 = 3.5);
}
@@ -0,0 +1,12 @@
fun foo<T: Any>(<caret>x1: T? = null, x2: Double, x3: ((T) -> T)?) {
foo(2, 3.5, null);
val y1 = x1;
val y2 = x2;
val y3 = x3;
foo(x3 = null, x1 = 2, x2 = 3.5);
}
fun bar() {
foo(x1 = 2, x2 = 3.5, x3 = null);
foo(x3 = null, x1 = 2, x2 = 3.5);
}
@@ -122,6 +122,19 @@ public class JetChangeSignatureTest extends KotlinCodeInsightTestCase {
doTest(changeInfo);
}
public void testGenericConstructor() throws Exception {
JetChangeInfo changeInfo = getChangeInfo();
changeInfo.setNewVisibility(Visibilities.PUBLIC);
changeInfo.getNewParameters()[0].setValOrVar(JetValVar.Var);
changeInfo.getNewParameters()[1].setValOrVar(JetValVar.None);
changeInfo.getNewParameters()[2].setValOrVar(JetValVar.Val);
changeInfo.getNewParameters()[0].setName("_x1");
changeInfo.getNewParameters()[1].setName("_x2");
changeInfo.getNewParameters()[2].setName("_x3");
changeInfo.getNewParameters()[1].setTypeText("Double?");
doTest(changeInfo);
}
public void testConstructorSwapArguments() throws Exception {
JetChangeInfo changeInfo = getChangeInfo();
changeInfo.getNewParameters()[0].setName("_x1");
@@ -142,6 +155,16 @@ public class JetChangeSignatureTest extends KotlinCodeInsightTestCase {
doTest(changeInfo);
}
public void testGenericFunctions() throws Exception {
JetChangeInfo changeInfo = getChangeInfo();
changeInfo.setNewVisibility(Visibilities.PUBLIC);
changeInfo.getNewParameters()[0].setName("_x1");
changeInfo.getNewParameters()[1].setName("_x2");
changeInfo.getNewParameters()[2].setName("_x3");
changeInfo.getNewParameters()[1].setTypeText("Double?");
doTest(changeInfo);
}
public void testExpressionFunction() throws Exception {
JetChangeInfo changeInfo = getChangeInfo();
changeInfo.getNewParameters()[0].setName("x1");