Add utility method for getting class from constructor parameter
This commit is contained in:
@@ -197,8 +197,9 @@ public class JetPsiUtil {
|
||||
firstPart = getFQName((JetNamedDeclaration) parent);
|
||||
}
|
||||
else if (namedDeclaration instanceof JetParameter) {
|
||||
if (((JetParameter) namedDeclaration).getValOrVarNode() != null && parent != null && parent.getParent() instanceof JetClassOrObject) {
|
||||
firstPart = getFQName((JetClassOrObject) parent.getParent());
|
||||
JetClass constructorClass = getClassIfParameterIsProperty((JetParameter) namedDeclaration);
|
||||
if (constructorClass != null) {
|
||||
firstPart = getFQName(constructorClass);
|
||||
}
|
||||
}
|
||||
else if (parent instanceof JetObjectDeclaration) {
|
||||
@@ -574,6 +575,18 @@ public class JetPsiUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetClass getClassIfParameterIsProperty(@NotNull JetParameter jetParameter) {
|
||||
if (jetParameter.getValOrVarNode() != null) {
|
||||
PsiElement parent = jetParameter.getParent();
|
||||
if (parent instanceof JetParameterList && parent.getParent() instanceof JetClass) {
|
||||
return (JetClass) parent.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static IElementType getOperation(@NotNull JetExpression expression) {
|
||||
if (expression instanceof JetQualifiedExpression) {
|
||||
|
||||
@@ -196,8 +196,11 @@ public class LightClassUtil {
|
||||
|
||||
@Nullable
|
||||
private static PsiClass getWrappingClass(@NotNull JetDeclaration declaration) {
|
||||
if (declaration instanceof JetParameter && declaration.getParent().getParent() instanceof JetClass) {
|
||||
return getPsiClass((JetClassOrObject) declaration.getParent().getParent());
|
||||
if (declaration instanceof JetParameter) {
|
||||
JetClass constructorClass = JetPsiUtil.getClassIfParameterIsProperty((JetParameter) declaration);
|
||||
if (constructorClass != null) {
|
||||
return getPsiClass(constructorClass);
|
||||
}
|
||||
}
|
||||
|
||||
if (declaration instanceof JetPropertyAccessor) {
|
||||
|
||||
@@ -143,12 +143,10 @@ public class JetIconProvider extends IconProvider {
|
||||
}
|
||||
if (psiElement instanceof JetParameter) {
|
||||
JetParameter parameter = (JetParameter) psiElement;
|
||||
if (parameter.getValOrVarNode() != null) {
|
||||
JetParameterList parameterList = PsiTreeUtil.getParentOfType(psiElement, JetParameterList.class);
|
||||
if (parameterList != null && parameterList.getParent() instanceof JetClass) {
|
||||
return parameter.isMutable() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
|
||||
}
|
||||
if (JetPsiUtil.getClassIfParameterIsProperty(parameter) != null) {
|
||||
return parameter.isMutable() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL;
|
||||
}
|
||||
|
||||
return JetIcons.PARAMETER;
|
||||
}
|
||||
if (psiElement instanceof JetProperty) {
|
||||
|
||||
@@ -48,7 +48,7 @@ public class KotlinDefinitionsSearcher extends QueryExecutorBase<PsiElement, Psi
|
||||
|
||||
if (queryParameters instanceof JetParameter) {
|
||||
JetParameter parameter = (JetParameter) queryParameters;
|
||||
if (parameter.getValOrVarNode() != null && queryParameters.getParent().getParent() instanceof JetClass) {
|
||||
if (JetPsiUtil.getClassIfParameterIsProperty(parameter) != null) {
|
||||
processPropertyImplementations(parameter, consumer);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user