use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrSpreadArgument in project intellij-community by JetBrains.
the class GroovyTypeCheckVisitorHelper method getExpressionArgumentsOfCall.
@Nullable
public static List<GrExpression> getExpressionArgumentsOfCall(@NotNull GrArgumentList argumentList) {
final ArrayList<GrExpression> args = ContainerUtil.newArrayList();
for (GroovyPsiElement arg : argumentList.getAllArguments()) {
if (arg instanceof GrSpreadArgument) {
GrExpression spreaded = ((GrSpreadArgument) arg).getArgument();
if (spreaded instanceof GrListOrMap && !((GrListOrMap) spreaded).isMap()) {
Collections.addAll(args, ((GrListOrMap) spreaded).getInitializers());
} else {
return null;
}
} else if (arg instanceof GrExpression) {
args.add((GrExpression) arg);
} else if (arg instanceof GrNamedArgument) {
args.add(((GrNamedArgument) arg).getExpression());
}
}
final PsiElement parent = argumentList.getParent();
if (parent instanceof GrIndexProperty && PsiUtil.isLValue((GroovyPsiElement) parent)) {
args.add(TypeInferenceHelper.getInitializerFor((GrExpression) parent));
} else if (parent instanceof GrMethodCallExpression) {
ContainerUtil.addAll(args, ((GrMethodCallExpression) parent).getClosureArguments());
}
return args;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrSpreadArgument in project intellij-community by JetBrains.
the class PsiUtil method getArgumentTypes.
@Nullable
public static PsiType[] getArgumentTypes(@NotNull GrNamedArgument[] namedArgs, @NotNull GrExpression[] expressions, @NotNull GrClosableBlock[] closures, boolean nullAsBottom, @Nullable GrExpression stopAt) {
List<PsiType> result = new ArrayList<>();
if (namedArgs.length > 0) {
GrNamedArgument context = namedArgs[0];
result.add(GrMapType.createFromNamedArgs(context, namedArgs));
}
for (GrExpression expression : expressions) {
PsiType type = expression.getType();
if (expression instanceof GrSpreadArgument) {
if (type instanceof GrTupleType) {
result.addAll(Arrays.asList(((GrTupleType) type).getComponentTypes()));
} else {
return null;
}
} else {
if (type == null) {
result.add(nullAsBottom ? null : TypesUtil.getJavaLangObject(expression));
} else {
if (stopAt == expression) {
type = TypeConversionUtil.erasure(type);
}
result.add(type);
}
}
if (stopAt == expression) {
return result.toArray(PsiType.createArray(result.size()));
}
}
for (GrClosableBlock closure : closures) {
PsiType closureType = closure.getType();
if (closureType != null) {
if (stopAt == closure) {
closureType = TypeConversionUtil.erasure(closureType);
}
result.add(notNullizeType(closureType, nullAsBottom, closure));
}
if (stopAt == closure) {
break;
}
}
return result.toArray(PsiType.createArray(result.size()));
}
Aggregations