use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class GradleDocumentationProvider method findDoc.
@Nullable
private static String findDoc(@Nullable PsiElement element, Object argValue) {
String result = null;
if (element instanceof GrLiteral) {
GrLiteral grLiteral = (GrLiteral) element;
PsiElement stmt = PsiTreeUtil.findFirstParent(grLiteral, psiElement -> psiElement instanceof GrCall);
if (stmt instanceof GrCall) {
GrCall grCall = (GrCall) stmt;
PsiMethod psiMethod = grCall.resolveMethod();
if (psiMethod != null && psiMethod.getContainingClass() != null) {
//noinspection ConstantConditions
String qualifiedName = psiMethod.getContainingClass().getQualifiedName();
if (grLiteral.getParent() instanceof GrNamedArgument) {
GrNamedArgument namedArgument = (GrNamedArgument) grLiteral.getParent();
String key = StringUtil.join(new String[] { "gradle.documentation", qualifiedName, psiMethod.getName(), namedArgument.getLabelName(), String.valueOf(argValue) }, ".");
result = GradleDocumentationBundle.messageOrDefault(key, "");
}
}
}
}
return result;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class GradleResolverUtil method getGrMethodArumentsCount.
public static int getGrMethodArumentsCount(@NotNull GrArgumentList args) {
int argsCount = 0;
boolean namedArgProcessed = false;
for (GroovyPsiElement arg : args.getAllArguments()) {
if (arg instanceof GrNamedArgument) {
if (!namedArgProcessed) {
namedArgProcessed = true;
argsCount++;
}
} else {
argsCount++;
}
}
return argsCount;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class GroovyAnnotator method checkNamedArgs.
private void checkNamedArgs(GrNamedArgument[] namedArguments, boolean forArgList) {
highlightNamedArgs(namedArguments);
Set<Object> existingKeys = ContainerUtil.newHashSet();
for (GrNamedArgument namedArgument : namedArguments) {
GrArgumentLabel label = namedArgument.getLabel();
Object value = PsiUtil.getLabelValue(label);
if (value == null)
continue;
if (value == ObjectUtils.NULL)
value = null;
if (existingKeys.add(value))
continue;
if (forArgList) {
myHolder.createErrorAnnotation(label, GroovyBundle.message("duplicated.named.parameter", String.valueOf(value)));
} else {
myHolder.createWarningAnnotation(label, GroovyBundle.message("duplicate.element.in.the.map", String.valueOf(value)));
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.
the class GroovyTypeCheckVisitor method checkNamedArguments.
private void checkNamedArguments(GroovyPsiElement context, GrNamedArgument[] namedArguments, Map<String, NamedArgumentDescriptor> map) {
for (GrNamedArgument namedArgument : namedArguments) {
String labelName = namedArgument.getLabelName();
NamedArgumentDescriptor descriptor = map.get(labelName);
if (descriptor == null)
continue;
GrExpression namedArgumentExpression = namedArgument.getExpression();
if (namedArgumentExpression == null)
continue;
if (getTupleInitializer(namedArgumentExpression) != null)
continue;
if (PsiUtil.isRawClassMemberAccess(namedArgumentExpression))
continue;
PsiType expressionType = TypesUtil.boxPrimitiveType(namedArgumentExpression.getType(), context.getManager(), context.getResolveScope());
if (expressionType == null)
continue;
if (!descriptor.checkType(expressionType, context)) {
registerError(namedArgumentExpression, ProblemHighlightType.GENERIC_ERROR, "Type of argument '" + labelName + "' can not be '" + expressionType.getPresentableText() + "'");
}
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument 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;
}
Aggregations