Light Classes: Primary constructor fixes
This commit is contained in:
@@ -1046,7 +1046,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
|
||||
ConstructorContext constructorContext = context.intoConstructor(constructorDescriptor);
|
||||
|
||||
functionCodegen.generateMethod(OtherOrigin(myClass, constructorDescriptor), constructorDescriptor, constructorContext,
|
||||
JetPrimaryConstructor primaryConstructor = myClass.getPrimaryConstructor();
|
||||
JvmDeclarationOrigin origin = OtherOrigin(primaryConstructor != null ? primaryConstructor : myClass, constructorDescriptor);
|
||||
functionCodegen.generateMethod(origin, constructorDescriptor, constructorContext,
|
||||
new FunctionGenerationStrategy.CodegenBased<ConstructorDescriptor>(state, constructorDescriptor) {
|
||||
@Override
|
||||
public void doGenerateBody(@NotNull ExpressionCodegen codegen, @NotNull JvmMethodSignature signature) {
|
||||
|
||||
+3
-3
@@ -100,15 +100,15 @@ public class KotlinLightClassForExplicitDeclaration extends KotlinWrappingLightC
|
||||
//noinspection unchecked
|
||||
PsiElement declaration = JetPsiUtil.getTopmostParentOfTypes(
|
||||
classOrObject,
|
||||
JetNamedFunction.class, JetProperty.class, JetClassInitializer.class, JetParameter.class
|
||||
JetNamedFunction.class, JetConstructor.class, JetProperty.class, JetClassInitializer.class, JetParameter.class
|
||||
);
|
||||
|
||||
if (declaration instanceof JetParameter) {
|
||||
declaration = PsiTreeUtil.getParentOfType(declaration, JetNamedDeclaration.class);
|
||||
}
|
||||
|
||||
if (declaration instanceof JetNamedFunction) {
|
||||
JetNamedFunction function = (JetNamedFunction) declaration;
|
||||
if (declaration instanceof JetFunction) {
|
||||
JetFunction function = (JetFunction) declaration;
|
||||
return getParentByPsiMethod(LightClassUtil.getLightClassMethod(function), function.getName(), false);
|
||||
}
|
||||
|
||||
|
||||
@@ -78,13 +78,8 @@ public class KotlinLightParameter extends LightParameter implements KotlinLightE
|
||||
int jetIndex = PsiUtilPackage.isExtensionDeclaration(declaration) ? index - 1 : index;
|
||||
if (jetIndex < 0) return null;
|
||||
|
||||
if (declaration instanceof JetNamedFunction) {
|
||||
List<JetParameter> paramList = ((JetNamedFunction) declaration).getValueParameters();
|
||||
return jetIndex < paramList.size() ? paramList.get(jetIndex) : null;
|
||||
}
|
||||
|
||||
if (declaration instanceof JetClass) {
|
||||
List<JetParameter> paramList = ((JetClass) declaration).getPrimaryConstructorParameters();
|
||||
if (declaration instanceof JetFunction) {
|
||||
List<JetParameter> paramList = ((JetFunction) declaration).getValueParameters();
|
||||
return jetIndex < paramList.size() ? paramList.get(jetIndex) : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -247,6 +247,10 @@ public class LightClassUtil {
|
||||
declaration = (JetProperty) propertyParent;
|
||||
}
|
||||
|
||||
if (declaration instanceof JetConstructor) {
|
||||
return getPsiClass(((JetConstructor) declaration).getClassOrObject());
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
if (PsiTreeUtil.getParentOfType(declaration, JetFunction.class, JetProperty.class) != null) {
|
||||
// Can't get wrappers for internal declarations. Their classes are not generated during calcStub
|
||||
|
||||
@@ -67,22 +67,18 @@ public fun PsiElement.getRepresentativeLightMethod(): PsiMethod? =
|
||||
}
|
||||
|
||||
public fun JetParameter.toPsiParameter(): PsiParameter? {
|
||||
val paramList = getNonStrictParentOfType<JetParameterList>()
|
||||
if (paramList == null) return null
|
||||
val paramList = getNonStrictParentOfType<JetParameterList>() ?: return null
|
||||
|
||||
val paramIndex = paramList.getParameters().indexOf(this)
|
||||
val owner = paramList.getParent()
|
||||
val lightParamIndex = if (owner is JetDeclaration && owner.isExtensionDeclaration()) paramIndex + 1 else paramIndex
|
||||
|
||||
val method: PsiMethod? = when (owner) {
|
||||
is JetFunction -> LightClassUtil.getLightClassMethod(owner)
|
||||
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(owner)
|
||||
is JetPrimaryConstructor -> LightClassUtil.getPsiClass(owner.getContainingClassOrObject())?.getConstructors()?.let { constructors ->
|
||||
if (constructors.isNotEmpty()) constructors[0] else null
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
if (method == null) return null
|
||||
val method: PsiMethod =
|
||||
when (owner) {
|
||||
is JetFunction -> LightClassUtil.getLightClassMethod(owner)
|
||||
is JetPropertyAccessor -> LightClassUtil.getLightClassAccessorMethod(owner)
|
||||
else -> null
|
||||
} ?: return null
|
||||
|
||||
return method.getParameterList().getParameters()[lightParamIndex]
|
||||
}
|
||||
|
||||
@@ -2,21 +2,21 @@
|
||||
|
||||
package constructorVsFun
|
||||
|
||||
class <!CONFLICTING_OVERLOADS!>a()<!> { }
|
||||
class a<!CONFLICTING_OVERLOADS!>()<!> { }
|
||||
|
||||
<!CONFLICTING_OVERLOADS!>fun a()<!> = 1
|
||||
|
||||
class Tram {
|
||||
<!CONFLICTING_OVERLOADS!>fun f()<!> { }
|
||||
|
||||
class <!CONFLICTING_OVERLOADS!>f()<!> { }
|
||||
class f<!CONFLICTING_OVERLOADS!>()<!> { }
|
||||
}
|
||||
|
||||
class Yvayva {
|
||||
companion object {
|
||||
<!CONFLICTING_OVERLOADS!>fun fghj()<!> { }
|
||||
|
||||
class <!CONFLICTING_OVERLOADS!>fghj()<!> { }
|
||||
class fghj<!CONFLICTING_OVERLOADS!>()<!> { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,5 +26,4 @@ class Rtyu {
|
||||
companion object {
|
||||
class ololo() { }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-2
@@ -31,5 +31,4 @@ fun z(<!UNUSED_PARAMETER!>view<!>: () -> Unit) {}
|
||||
<!CONFLICTING_OVERLOADS!>fun x()<!> = z { z { z { z { z { z { z { z { } } } } } } } }
|
||||
<!CONFLICTING_OVERLOADS!>fun x()<!> = z { z { z { z { z { z { z { z { } } } } } } } }
|
||||
|
||||
class <!CONFLICTING_OVERLOADS!>x()<!> {}
|
||||
|
||||
class x<!CONFLICTING_OVERLOADS!>()<!> {}
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class <!CONFLICTING_OVERLOADS!>A(x: String = "", y: String = "")<!> {
|
||||
class A<!CONFLICTING_OVERLOADS!>(x: String = "", y: String = "")<!> {
|
||||
<!CONFLICTING_OVERLOADS!>constructor(x: String, y: String)<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>(x, y)
|
||||
<!CONFLICTING_OVERLOADS!>constructor()<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>("", "")
|
||||
<!CONFLICTING_OVERLOADS!>constructor()<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>("", "")
|
||||
@@ -13,7 +13,7 @@ class B {
|
||||
<!CONFLICTING_OVERLOADS!>fun B(x: Int)<!> {}
|
||||
|
||||
class Outer {
|
||||
class <!CONFLICTING_OVERLOADS!>A(x: String = "", y: String = "")<!> {
|
||||
class A<!CONFLICTING_OVERLOADS!>(x: String = "", y: String = "")<!> {
|
||||
<!CONFLICTING_OVERLOADS!>constructor(x: String, y: String)<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>(x, y)
|
||||
<!CONFLICTING_OVERLOADS!>constructor()<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>("", "")
|
||||
<!CONFLICTING_OVERLOADS!>constructor()<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>("", "")
|
||||
@@ -24,4 +24,4 @@ class Outer {
|
||||
}
|
||||
|
||||
<!CONFLICTING_OVERLOADS!>fun B(x: Int)<!> {}
|
||||
}
|
||||
}
|
||||
@@ -340,11 +340,8 @@ public class JetRefactoringUtil {
|
||||
|
||||
if (method instanceof KotlinLightMethod) {
|
||||
JetDeclaration declaration = ((KotlinLightMethod) method).getOrigin();
|
||||
if (declaration instanceof JetNamedFunction) {
|
||||
result.add(((JetNamedFunction) declaration).getValueParameters().get(parameterIndex));
|
||||
}
|
||||
else if (declaration instanceof JetClass) {
|
||||
result.add(((JetClass) declaration).getPrimaryConstructorParameters().get(parameterIndex));
|
||||
if (declaration instanceof JetFunction) {
|
||||
result.add(((JetFunction) declaration).getValueParameters().get(parameterIndex));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
+4
-2
@@ -1,12 +1,14 @@
|
||||
<node text="A ()" base="true">
|
||||
<node text="B ()"/>
|
||||
<node text="X in MyClass ()"/>
|
||||
<node text="Anonymous in MyClass ()"/>
|
||||
<node text="X in MyClass() in MyClass ()"/>
|
||||
<node text="Anonymous in MyClass() in MyClass ()"/>
|
||||
<node text="G in MyClass ()"/>
|
||||
<node text="C in MyClass ()"/>
|
||||
<node text="X in foo() in MyClass ()"/>
|
||||
<node text="Anonymous in foo() in MyClass ()"/>
|
||||
<node text="F in foo() in MyClass ()"/>
|
||||
<node text="D in foo() in MyClass ()"/>
|
||||
<node text="X in MyClass2() in MyClass2 ()"/>
|
||||
<node text="Anonymous in MyClass2() in MyClass2 ()"/>
|
||||
<node text="E in bar() in main.kt ()"/>
|
||||
</node>
|
||||
|
||||
@@ -18,6 +18,10 @@ class MyClass(a: A = run { class X: A(); object: A() {} }) {
|
||||
}
|
||||
}
|
||||
|
||||
class MyClass2 {
|
||||
constructor(a: A = run { class X: A(); object: A() {} })
|
||||
}
|
||||
|
||||
val bar: Int
|
||||
get() {
|
||||
class E: A()
|
||||
|
||||
+7
-7
@@ -1,12 +1,12 @@
|
||||
<node text="A ()" base="true">
|
||||
<node text="B ()"/>
|
||||
<node text="X in MyClass ()"/>
|
||||
<node text="Anonymous in MyClass ()"/>
|
||||
<node text="G in MyClass ()"/>
|
||||
<node text="C in MyClass ()"/>
|
||||
<node text="X in foo() in MyClass ()"/>
|
||||
<node text="Anonymous in MyClass() in MyClass ()"/>
|
||||
<node text="Anonymous in foo() in MyClass ()"/>
|
||||
<node text="F in foo() in MyClass ()"/>
|
||||
<node text="B ()"/>
|
||||
<node text="C in MyClass ()"/>
|
||||
<node text="D in foo() in MyClass ()"/>
|
||||
<node text="E in bar() in main.kt ()"/>
|
||||
<node text="F in foo() in MyClass ()"/>
|
||||
<node text="G in MyClass ()"/>
|
||||
<node text="X in MyClass() in MyClass ()"/>
|
||||
<node text="X in foo() in MyClass ()"/>
|
||||
</node>
|
||||
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
<node text="A ()" base="true">
|
||||
<node text="B ()"/>
|
||||
<node text="Anonymous in MyClass ()"/>
|
||||
<node text="C in MyClass ()"/>
|
||||
<node text="Anonymous in MyClass() in MyClass ()"/>
|
||||
<node text="Anonymous in foo() in MyClass ()"/>
|
||||
<node text="D in foo() in MyClass ()"/>
|
||||
<node text="F in t() in MyClass ()"/>
|
||||
<node text="E in bar() in main.kt ()"/>
|
||||
<node text="Anonymous in x() in main.kt ()"/>
|
||||
<node text="B ()"/>
|
||||
<node text="C in MyClass ()"/>
|
||||
<node text="D in foo() in MyClass ()"/>
|
||||
<node text="E in bar() in main.kt ()"/>
|
||||
<node text="F in t() in MyClass ()"/>
|
||||
</node>
|
||||
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
<node text="A ()" base="true">
|
||||
<node text="B ()"/>
|
||||
<node text="Anonymous in MyClass ()"/>
|
||||
<node text="C in MyClass ()"/>
|
||||
<node text="Anonymous in MyClass() in MyClass ()"/>
|
||||
<node text="Anonymous in foo() in MyClass ()"/>
|
||||
<node text="D in foo() in MyClass ()"/>
|
||||
<node text="F in t() in MyClass ()"/>
|
||||
<node text="E in bar() in main.kt ()"/>
|
||||
<node text="Anonymous in x() in main.kt ()"/>
|
||||
<node text="B ()"/>
|
||||
<node text="C in MyClass ()"/>
|
||||
<node text="D in foo() in MyClass ()"/>
|
||||
<node text="E in bar() in main.kt ()"/>
|
||||
<node text="F in t() in MyClass ()"/>
|
||||
</node>
|
||||
|
||||
+7
-7
@@ -1,12 +1,12 @@
|
||||
<node text="A ()" base="true">
|
||||
<node text="B ()"/>
|
||||
<node text="X in MyClass ()"/>
|
||||
<node text="Anonymous in MyClass ()"/>
|
||||
<node text="G in MyClass ()"/>
|
||||
<node text="C in MyClass ()"/>
|
||||
<node text="X in foo() in MyClass ()"/>
|
||||
<node text="Anonymous in MyClass() in MyClass ()"/>
|
||||
<node text="Anonymous in foo() in MyClass ()"/>
|
||||
<node text="B ()"/>
|
||||
<node text="C in MyClass ()"/>
|
||||
<node text="D in foo() in MyClass ()"/>
|
||||
<node text="F in foo() in MyClass ()"/>
|
||||
<node text="E in bar() in main.kt ()"/>
|
||||
<node text="F in foo() in MyClass ()"/>
|
||||
<node text="G in MyClass ()"/>
|
||||
<node text="X in MyClass() in MyClass ()"/>
|
||||
<node text="X in foo() in MyClass ()"/>
|
||||
</node>
|
||||
|
||||
+7
-7
@@ -1,12 +1,12 @@
|
||||
<node text="A ()" base="true">
|
||||
<node text="B ()"/>
|
||||
<node text="X in MyClass ()"/>
|
||||
<node text="Anonymous in MyClass ()"/>
|
||||
<node text="G in MyClass ()"/>
|
||||
<node text="C in MyClass ()"/>
|
||||
<node text="X in foo() in MyClass ()"/>
|
||||
<node text="Anonymous in MyClass() in MyClass ()"/>
|
||||
<node text="Anonymous in foo() in MyClass ()"/>
|
||||
<node text="B ()"/>
|
||||
<node text="C in MyClass ()"/>
|
||||
<node text="D in foo() in MyClass ()"/>
|
||||
<node text="F in foo() in MyClass ()"/>
|
||||
<node text="E in bar() in main.kt ()"/>
|
||||
<node text="F in foo() in MyClass ()"/>
|
||||
<node text="G in MyClass ()"/>
|
||||
<node text="X in MyClass() in MyClass ()"/>
|
||||
<node text="X in foo() in MyClass ()"/>
|
||||
</node>
|
||||
|
||||
Reference in New Issue
Block a user