Search in sources :

Example 21 with GrNamedArgument

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.

the class GrArgumentLabelImpl method getReferenceFromNamedArgumentProviders.

@Nullable
private PsiPolyVariantReference getReferenceFromNamedArgumentProviders() {
    PsiElement namedArgument = getParent();
    if (!(namedArgument instanceof GrNamedArgument))
        return null;
    PsiElement nameElement = getNameElement();
    if (!(nameElement instanceof LeafPsiElement))
        return null;
    IElementType elementType = ((LeafPsiElement) nameElement).getElementType();
    if (elementType != GroovyTokenTypes.mIDENT && !CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getBoxedTypeName(elementType))) {
        return null;
    }
    GrCall call = PsiUtil.getCallByNamedParameter((GrNamedArgument) namedArgument);
    if (call == null)
        return NamedArgumentUtilKt.getReferenceFromDescriptor(this);
    String labelName = getName();
    Map<String, NamedArgumentDescriptor> providers = GroovyNamedArgumentProvider.getNamedArgumentsFromAllProviders(call, labelName, false);
    if (providers != null) {
        NamedArgumentDescriptor descr = providers.get(labelName);
        if (descr != null) {
            PsiPolyVariantReference res = descr.createReference(this);
            if (res != null) {
                return res;
            }
        }
    }
    return null;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) NamedArgumentDescriptor(org.jetbrains.plugins.groovy.extensions.NamedArgumentDescriptor) GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) GrCall(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCall) LeafPsiElement(com.intellij.psi.impl.source.tree.LeafPsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with GrNamedArgument

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.

the class GrArgumentListImpl method addAfter.

@Override
public PsiElement addAfter(@NotNull PsiElement element, @Nullable PsiElement anchor) throws IncorrectOperationException {
    if (element instanceof GrExpression || element instanceof GrNamedArgument) {
        final boolean insertComma = getAllArguments().length != 0;
        if (anchor == null)
            anchor = getLeftParen();
        PsiElement result;
        result = super.addAfter(element, anchor);
        if (insertComma) {
            final ASTNode astNode = getNode();
            if (anchor == getLeftParen()) {
                astNode.addLeaf(GroovyTokenTypes.mCOMMA, ",", result.getNextSibling().getNode());
            } else {
                astNode.addLeaf(GroovyTokenTypes.mCOMMA, ",", result.getNode());
            }
            CodeStyleManager.getInstance(getManager().getProject()).reformat(this);
        }
        return result;
    }
    return super.addAfter(element, anchor);
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) ASTNode(com.intellij.lang.ASTNode) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 23 with GrNamedArgument

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project intellij-community by JetBrains.

the class PsiUtil method getNamedArgumentValue.

@Nullable
public static PsiElement getNamedArgumentValue(GrNamedArgument otherNamedArgument, String argumentName) {
    PsiElement parent = otherNamedArgument.getParent();
    if (!(parent instanceof GrNamedArgumentsOwner))
        return null;
    GrNamedArgument namedArgument = ((GrNamedArgumentsOwner) parent).findNamedArgument(argumentName);
    if (namedArgument == null)
        return null;
    return namedArgument.getExpression();
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrNamedArgumentsOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrNamedArgumentsOwner) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with GrNamedArgument

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project android by JetBrains.

the class GradleDslParser method getMethodCall.

@NotNull
static GradleDslMethodCall getMethodCall(@NotNull GradleDslElement parentElement, @NotNull GrMethodCallExpression psiElement, @NotNull String propertyName, @NotNull GrArgumentList argumentList) {
    GradleDslMethodCall methodCall = new GradleDslMethodCall(parentElement, psiElement, propertyName);
    for (GrExpression expression : argumentList.getExpressionArguments()) {
        if (expression instanceof GrListOrMap) {
            GrListOrMap listOrMap = (GrListOrMap) expression;
            if (listOrMap.isMap()) {
                methodCall.addParsedExpressionMap(getExpressionMap(methodCall, expression, propertyName, listOrMap.getNamedArguments()));
            } else {
                for (GrExpression grExpression : listOrMap.getInitializers()) {
                    GradleDslExpression dslExpression = getExpressionElement(methodCall, expression, propertyName, grExpression);
                    if (dslExpression != null) {
                        methodCall.addParsedExpression(dslExpression);
                    }
                }
            }
        } else if (expression instanceof GrClosableBlock) {
            methodCall.setParsedClosureElement(getClosureElement(methodCall, (GrClosableBlock) expression, propertyName));
        } else {
            GradleDslExpression dslExpression = getExpressionElement(methodCall, expression, propertyName, expression);
            if (dslExpression != null) {
                methodCall.addParsedExpression(dslExpression);
            }
        }
    }
    GrNamedArgument[] namedArguments = argumentList.getNamedArguments();
    if (namedArguments.length > 0) {
        methodCall.addParsedExpressionMap(getExpressionMap(methodCall, argumentList, propertyName, namedArguments));
    }
    return methodCall;
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrClosableBlock(org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock) GrListOrMap(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with GrNamedArgument

use of org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument in project android by JetBrains.

the class GradleDslParser method getExpressionMap.

@NotNull
private static GradleDslExpressionMap getExpressionMap(@NotNull GradleDslElement parentElement, // GrArgumentList or GrListOrMap
@NotNull GroovyPsiElement mapPsiElement, @NotNull String propertyName, @NotNull GrNamedArgument... namedArguments) {
    GradleDslExpressionMap expressionMap = new GradleDslExpressionMap(parentElement, mapPsiElement, propertyName);
    for (GrNamedArgument namedArgument : namedArguments) {
        String argName = namedArgument.getLabelName();
        if (isEmpty(argName)) {
            continue;
        }
        GrExpression valueExpression = namedArgument.getExpression();
        if (valueExpression == null) {
            continue;
        }
        GradleDslElement valueElement = getExpressionElement(expressionMap, mapPsiElement, argName, valueExpression);
        if (valueElement == null && valueExpression instanceof GrListOrMap) {
            GrListOrMap listOrMap = (GrListOrMap) valueExpression;
            if (listOrMap.isMap()) {
                valueElement = getExpressionMap(expressionMap, listOrMap, argName, listOrMap.getNamedArguments());
            } else {
                // ex: flatDir name: "libs", dirs: ["libs1", "libs2"]
                valueElement = getExpressionList(expressionMap, listOrMap, argName, listOrMap.getInitializers());
            }
        }
        if (valueElement != null) {
            expressionMap.setParsedElement(argName, valueElement);
        }
    }
    return expressionMap;
}
Also used : GrNamedArgument(org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument) GrListOrMap(org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap) NotNull(org.jetbrains.annotations.NotNull)

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