use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class PsiUtil method getArgumentTypes.
@Nullable
public static PsiType[] getArgumentTypes(@Nullable PsiElement place, boolean nullAsBottom, @Nullable GrExpression stopAt) {
PsiElement parent = place instanceof GrEnumConstant ? place : place != null ? place.getParent() : null;
if (parent instanceof GrIndexProperty) {
GrIndexProperty index = (GrIndexProperty) parent;
PsiType[] argTypes = getArgumentTypes(index.getNamedArguments(), index.getExpressionArguments(), index.getClosureArguments(), nullAsBottom, stopAt);
if (isLValue(index) && argTypes != null) {
PsiType rawInitializer = TypeInferenceHelper.getInitializerTypeFor(index);
PsiType initializer = notNullizeType(rawInitializer, nullAsBottom, index);
return ArrayUtil.append(argTypes, initializer);
} else {
return argTypes;
}
}
if (parent instanceof GrCall) {
GrCall call = (GrCall) parent;
GrNamedArgument[] namedArgs = call.getNamedArguments();
GrExpression[] expressions = call.getExpressionArguments();
GrClosableBlock[] closures = call.getClosureArguments();
return getArgumentTypes(namedArgs, expressions, closures, nullAsBottom, stopAt);
} else if (parent instanceof GrAnonymousClassDefinition) {
final GrArgumentList argList = ((GrAnonymousClassDefinition) parent).getArgumentListGroovy();
if (argList == null) {
return getArgumentTypes(GrNamedArgument.EMPTY_ARRAY, GrExpression.EMPTY_ARRAY, GrClosableBlock.EMPTY_ARRAY, nullAsBottom, stopAt);
} else {
return getArgumentTypes(argList.getNamedArguments(), argList.getExpressionArguments(), GrClosableBlock.EMPTY_ARRAY, nullAsBottom, stopAt);
}
} else if (parent instanceof GrBinaryExpression) {
GrExpression right = ((GrBinaryExpression) parent).getRightOperand();
PsiType type = right != null ? right.getType() : null;
return new PsiType[] { notNullizeType(type, nullAsBottom, parent) };
} else if (parent instanceof GrAssignmentExpression) {
PsiType type = ((GrAssignmentExpression) parent).getType();
return new PsiType[] { notNullizeType(type, nullAsBottom, parent) };
}
return null;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class PsiUtil method getAllArguments.
/**
* Returns all arguments passed to method. First argument is null if Named Arguments is present.
*/
public static GrExpression[] getAllArguments(@NotNull GrCall call) {
GrArgumentList argumentList = call.getArgumentList();
if (argumentList == null)
return GrExpression.EMPTY_ARRAY;
GrClosableBlock[] closureArguments = call.getClosureArguments();
GrExpression[] expressionArguments = argumentList.getExpressionArguments();
GrNamedArgument[] namedArguments = argumentList.getNamedArguments();
int length = expressionArguments.length + closureArguments.length;
int k = 0;
if (namedArguments.length > 0) {
length++;
k = 1;
}
GrExpression[] res = new GrExpression[length];
for (GrExpression expressionArgument : expressionArguments) {
res[k++] = expressionArgument;
}
for (GrClosableBlock closureArgument : closureArguments) {
res[k++] = closureArgument;
}
return res;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument 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