Search in sources :

Example 11 with GrNamedArgument

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;
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) PsiMethod(com.intellij.psi.PsiMethod) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) GrLiteral(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with GrNamedArgument

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;
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)

Example 13 with GrNamedArgument

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)));
        }
    }
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrArgumentLabel(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel)

Example 14 with GrNamedArgument

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() + "'");
        }
    }
}
Also used : NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrString(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString)

Example 15 with GrNamedArgument

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;
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrMethodCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression) GrIndexProperty(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrIndexProperty) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) GrListOrMap(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrSpreadArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrSpreadArgument) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)48 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)17 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)16 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)13 GrListOrMap (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap)12 PsiElement (com.intellij.psi.PsiElement)11 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)11 Nullable (org.jetbrains.annotations.Nullable)10 GrArgumentLabel (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentLabel)8 NotNull (org.jetbrains.annotations.NotNull)5 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)5 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)5 GrString (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrString)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 NamedArgumentDescriptor (org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor)4 GrClosureSignature (org.jetbrains.plugins.groovy.lang.psi.api.signatures.GrClosureSignature)4 GrCall (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall)4 ASTNode (com.intellij.lang.ASTNode)3 LeafPsiElement (com.intellij.psi.impl.source.tree.LeafPsiElement)3 ArrayList (java.util.ArrayList)3