Search in sources :

Example 1 with GradleDslElement

use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement in project android by JetBrains.

the class SigningConfigModel method getStoreFileExpression.

@Nullable
private GradleDslExpression getStoreFileExpression() {
    GradleDslMethodCall methodCall = myDslElement.getPropertyElement(STORE_FILE, GradleDslMethodCall.class);
    if (methodCall == null || methodCall.getArguments().size() == 0) {
        return null;
    }
    GradleDslElement argument = methodCall.getArguments().get(0);
    if (argument instanceof GradleDslExpression) {
        return (GradleDslExpression) argument;
    }
    return null;
}
Also used : GradleDslExpression(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression) GradleDslMethodCall(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall) GradleDslElement(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GradleDslElement

use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement in project android by JetBrains.

the class SourceSetModel method root.

@NotNull
public GradleNullableValue<String> root() {
    GradleDslExpression rootElement = myDslElement.getPropertyElement(ROOT, GradleDslExpression.class);
    if (rootElement == null) {
        return new GradleNullableValue<>(myDslElement, null);
    }
    String value = null;
    if (rootElement instanceof GradleDslMethodCall) {
        List<GradleDslElement> arguments = ((GradleDslMethodCall) rootElement).getArguments();
        if (!arguments.isEmpty()) {
            GradleDslElement pathArgument = arguments.get(0);
            if (pathArgument instanceof GradleDslExpression) {
                value = ((GradleDslExpression) pathArgument).getValue(String.class);
            }
        }
    } else {
        value = rootElement.getValue(String.class);
    }
    return new GradleNullableValue<>(rootElement, value);
}
Also used : GradleNullableValue(com.android.tools.idea.gradle.dsl.model.values.GradleNullableValue) GradleDslExpression(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression) GradleDslMethodCall(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall) GradleDslElement(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GradleDslElement

use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement in project android by JetBrains.

the class SourceSetModel method setRoot.

@NotNull
public SourceSetModel setRoot(@NotNull String root) {
    GradleDslExpression rootElement = myDslElement.getPropertyElement(ROOT, GradleDslExpression.class);
    if (rootElement == null) {
        myDslElement.setNewLiteral(ROOT, root);
        return this;
    }
    if (rootElement instanceof GradleDslMethodCall) {
        List<GradleDslElement> arguments = ((GradleDslMethodCall) rootElement).getArguments();
        if (!arguments.isEmpty()) {
            GradleDslElement pathArgument = arguments.get(0);
            if (pathArgument instanceof GradleDslExpression) {
                ((GradleDslExpression) pathArgument).setValue(root);
                return this;
            }
        }
    }
    rootElement.setValue(root);
    return this;
}
Also used : GradleDslExpression(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression) GradleDslMethodCall(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall) GradleDslElement(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GradleDslElement

use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement in project android by JetBrains.

the class GradleValue method getResolvedVariables.

@NotNull
public Map<String, GradleNotNullValue<Object>> getResolvedVariables() {
    if (myDslElement == null) {
        return ImmutableMap.of();
    }
    ImmutableMap.Builder<String, GradleNotNullValue<Object>> builder = ImmutableMap.builder();
    for (GradleResolvedVariable variable : myDslElement.getResolvedVariables()) {
        String variableName = variable.getVariableName();
        Object resolvedValue = variable.getValue();
        GradleDslElement element = variable.getElement();
        builder.put(variableName, new GradleNotNullValue<>(element, resolvedValue));
    }
    return builder.build();
}
Also used : GradleResolvedVariable(com.android.tools.idea.gradle.dsl.parser.GradleResolvedVariable) ImmutableMap(com.google.common.collect.ImmutableMap) GradleDslElement(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GradleDslElement

use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement in project android by JetBrains.

the class DependenciesModel method remove.

@NotNull
public DependenciesModel remove(@NotNull DependencyModel dependency) {
    GradleDslElementList gradleDslElementList = myDslElement.getPropertyElement(dependency.configurationName(), GradleDslElementList.class);
    if (gradleDslElementList != null) {
        GradleDslElement dependencyElement = dependency.getDslElement();
        GradleDslElement parent = dependencyElement.getParent();
        if (parent instanceof GradleDslMethodCall) {
            GradleDslMethodCall methodCall = (GradleDslMethodCall) parent;
            List<GradleDslElement> arguments = methodCall.getArguments();
            if (arguments.size() == 1 && arguments.get(0).equals(dependencyElement)) {
                // If this is the last argument, remove the method call altogether.
                gradleDslElementList.removeElement(methodCall);
            } else {
                methodCall.remove(dependencyElement);
            }
        } else {
            gradleDslElementList.removeElement(dependencyElement);
        }
    }
    return this;
}
Also used : GradleDslElementList(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList) GradleDslMethodCall(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall) GradleDslElement(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GradleDslElement (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement)8 GradleDslMethodCall (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall)5 NotNull (org.jetbrains.annotations.NotNull)5 GradleDslExpression (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression)4 GradleDslElementList (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList)2 GradleDslExpressionMap (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap)2 Map (java.util.Map)2 GradleNullableValue (com.android.tools.idea.gradle.dsl.model.values.GradleNullableValue)1 GradleDslFile (com.android.tools.idea.gradle.dsl.parser.GradleDslFile)1 GradleResolvedVariable (com.android.tools.idea.gradle.dsl.parser.GradleResolvedVariable)1 SubProjectsDslElement (com.android.tools.idea.gradle.dsl.parser.build.SubProjectsDslElement)1 GradleDslExpressionList (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Nullable (org.jetbrains.annotations.Nullable)1