Light Classes: Primary constructor fixes
This commit is contained in:
+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]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user