use of org.jetbrains.plugins.groovy.lang.psi.impl.GrLiteralClassType in project intellij-community by JetBrains.
the class DefaultCallExpressionTypeCalculator method calculateReturnType.
@Override
public PsiType calculateReturnType(@NotNull GrMethodCall callExpression, GroovyResolveResult[] resolveResults) {
GrExpression invoked = callExpression.getInvokedExpression();
if (invoked instanceof GrReferenceExpression) {
GrReferenceExpression refExpr = (GrReferenceExpression) invoked;
PsiManager manager = callExpression.getManager();
PsiType result = null;
for (GroovyResolveResult resolveResult : resolveResults) {
PsiType returnType = calculateReturnTypeInner(callExpression, refExpr, resolveResult);
if (returnType == null)
return null;
PsiType nonVoid = PsiType.VOID.equals(returnType) && !isCompileStatic(callExpression) ? PsiType.NULL : returnType;
PsiType normalized = nonVoid instanceof GrLiteralClassType ? nonVoid : TypesUtil.substituteAndNormalizeType(nonVoid, resolveResult.getSubstitutor(), resolveResult.getSpreadState(), callExpression);
LOG.assertTrue(normalized != null, "return type: " + returnType + "; substitutor: " + resolveResult.getSubstitutor());
if (result == null || normalized.isAssignableFrom(result)) {
result = normalized;
} else if (!result.isAssignableFrom(normalized)) {
result = TypesUtil.getLeastUpperBound(result, normalized, manager);
}
}
return result;
} else {
return extractReturnTypeFromType(invoked.getType(), false, callExpression);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.impl.GrLiteralClassType in project intellij-community by JetBrains.
the class ExpressionGenerator method visitListOrMap.
@Override
public void visitListOrMap(@NotNull GrListOrMap listOrMap) {
final PsiType type = listOrMap.getType();
//can be PsiArrayType or GrLiteralClassType
LOG.assertTrue(type instanceof GrLiteralClassType || type instanceof PsiArrayType || type instanceof PsiClassType);
if (listOrMap.isMap()) {
if (listOrMap.getNamedArguments().length == 0) {
builder.append("new ");
TypeWriter.writeTypeForNew(builder, type, listOrMap);
builder.append("()");
} else {
String varName = generateMapVariableDeclaration(listOrMap, type);
generateMapElementInsertions(listOrMap, varName);
builder.append(varName);
}
} else {
builder.append("new ");
PsiType typeToUse = getTypeToUseByList(listOrMap, type);
TypeWriter.writeTypeForNew(builder, typeToUse, listOrMap);
if (typeToUse instanceof PsiArrayType) {
if (listOrMap.getInitializers().length == 0) {
builder.replace(builder.length() - 2, builder.length(), "[0]");
} else {
builder.append('{');
genInitializers(listOrMap);
builder.append('}');
}
} else if (listOrMap.getInitializers().length == 0) {
builder.append("()");
} else {
builder.append("(java.util.Arrays.asList(");
genInitializers(listOrMap);
builder.append("))");
}
}
}
Aggregations