use of org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty in project intellij-community by JetBrains.
the class GenerationUtil method getDeclaredType.
@Nullable
public static PsiType getDeclaredType(@Nullable GrExpression expression, ExpressionContext context) {
if (expression instanceof GrReferenceExpression) {
final GroovyResolveResult resolveResult = ((GrReferenceExpression) expression).advancedResolve();
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
PsiElement resolved = resolveResult.getElement();
if (resolved instanceof PsiVariable) {
return substitutor.substitute(context.typeProvider.getVarType((PsiVariable) resolved));
} else if (resolved instanceof PsiMethod) {
return getDeclaredType((PsiMethod) resolved, substitutor, context);
}
} else if (expression instanceof GrMethodCall) {
final GrExpression invokedExpression = ((GrMethodCall) expression).getInvokedExpression();
return getDeclaredType(invokedExpression, context);
} else if (expression instanceof GrBinaryExpression) {
final GroovyResolveResult result = PsiImplUtil.extractUniqueResult(((GrBinaryExpression) expression).multiResolve(false));
if (result.getElement() instanceof PsiMethod) {
return getDeclaredType((PsiMethod) result.getElement(), result.getSubstitutor(), context);
}
} else if (expression instanceof GrIndexProperty) {
final GroovyResolveResult result = ((GrIndexProperty) expression).advancedResolve();
if (result.getElement() instanceof PsiMethod) {
return getDeclaredType((PsiMethod) result.getElement(), result.getSubstitutor(), context);
}
} else if (expression instanceof GrAssignmentExpression) {
return getDeclaredType(((GrAssignmentExpression) expression).getRValue(), context);
} else if (expression instanceof GrConditionalExpression) {
return TypesUtil.getLeastUpperBoundNullable(getDeclaredType(((GrConditionalExpression) expression).getThenBranch(), context), getDeclaredType(((GrConditionalExpression) expression).getElseBranch(), context), expression.getManager());
} else if (expression instanceof GrParenthesizedExpression) {
return getDeclaredType(((GrParenthesizedExpression) expression).getOperand(), context);
} else if (expression == null) {
return null;
}
return expression.getType();
}
Aggregations