Search in sources :

Example 96 with GroovyPsiElement

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project android by JetBrains.

the class GradleDslMethodCall method apply.

@Override
protected void apply() {
    for (GradleDslElement argument : myToBeRemovedArguments) {
        if (myArguments.remove(argument)) {
            argument.delete();
        }
    }
    GroovyPsiElement psiElement = getPsiElement();
    if (psiElement instanceof GrMethodCallExpression) {
        GrMethodCallExpression methodCall = (GrMethodCallExpression) psiElement;
        if (myToBeAddedArgument != null) {
            myToBeAddedArgument.setPsiElement(methodCall.getArgumentList());
            myToBeAddedArgument.applyChanges();
            myArguments.add(myToBeAddedArgument);
        }
    }
    for (GradleDslElement argument : myArguments) {
        if (argument.isModified()) {
            argument.applyChanges();
        }
    }
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrMethodCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)

Example 97 with GroovyPsiElement

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project android by JetBrains.

the class GradlePropertiesDslElement method addAsParsedDslExpressionList.

protected void addAsParsedDslExpressionList(@NotNull String property, GradleDslExpression dslLiteral) {
    GroovyPsiElement psiElement = dslLiteral.getPsiElement();
    if (psiElement == null) {
        return;
    }
    // Only elements which are added as expression list are the ones which supports both single argument and multiple arguments
    // (ex: flavorDimensions in android block). To support that, we create an expression list where appending to the arguments list is
    // supported even when there is only one element in it. This does not work in many other places like proguardFile elements where
    // only one argument is supported and for this cases we use addToParsedExpressionList method.
    GradleDslExpressionList literalList = new GradleDslExpressionList(this, psiElement, property, true);
    literalList.addParsedExpression(dslLiteral);
    myProperties.put(property, literalList);
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 98 with GroovyPsiElement

use of org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement in project android by JetBrains.

the class GradlePropertiesDslElement method addToParsedExpressionList.

public void addToParsedExpressionList(@NotNull String property, @NotNull GradleDslElement element) {
    GroovyPsiElement psiElement = element.getPsiElement();
    if (psiElement == null) {
        return;
    }
    GradleDslExpressionList gradleDslExpressionList = getPropertyElement(property, GradleDslExpressionList.class);
    if (gradleDslExpressionList == null) {
        gradleDslExpressionList = new GradleDslExpressionList(this, psiElement, property);
        myProperties.put(property, gradleDslExpressionList);
    } else {
        gradleDslExpressionList.setPsiElement(psiElement);
    }
    if (element instanceof GradleDslExpression) {
        gradleDslExpressionList.addParsedExpression((GradleDslExpression) element);
    } else if (element instanceof GradleDslExpressionList) {
        List<GradleDslExpression> gradleExpressions = ((GradleDslExpressionList) element).getExpressions();
        for (GradleDslExpression expression : gradleExpressions) {
            gradleDslExpressionList.addParsedExpression(expression);
        }
    }
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) List(java.util.List)

Aggregations

GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)98 PsiElement (com.intellij.psi.PsiElement)34 Nullable (org.jetbrains.annotations.Nullable)17 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)17 GroovyPsiElementFactory (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory)16 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)13 GrArgumentList (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrArgumentList)12 GrClosableBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock)11 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)9 GrListOrMap (org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.GrListOrMap)8 GrNamedArgument (org.jetbrains.plugins.groovy.lang.psi.api.statements.arguments.GrNamedArgument)8 GrApplicationStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrApplicationStatement)8 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)8 GrTypeDefinition (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition)8 Project (com.intellij.openapi.project.Project)7 TextRange (com.intellij.openapi.util.TextRange)7 NotNull (org.jetbrains.annotations.NotNull)7 GroovyRecursiveElementVisitor (org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor)7 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)7 GroovyResolveResult (org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult)6