Search in sources :

Example 6 with GradleDslMethodCall

use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall 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)

Example 7 with GradleDslMethodCall

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

the class DependenciesModel method all.

/**
   * @return all the dependencies (artifact, module, etc.)
   * WIP: Do not use.
   */
@NotNull
public List<DependencyModel> all() {
    List<DependencyModel> dependencies = Lists.newArrayList();
    for (String configurationName : myDslElement.getProperties()) {
        GradleDslElementList list = myDslElement.getPropertyElement(configurationName, GradleDslElementList.class);
        if (list != null) {
            for (GradleDslElement element : list.getElements(GradleDslElement.class)) {
                dependencies.addAll(ArtifactDependencyModel.create(element));
                if (element instanceof GradleDslMethodCall) {
                    GradleDslMethodCall methodCall = (GradleDslMethodCall) element;
                    dependencies.addAll(ModuleDependencyModel.create(configurationName, methodCall));
                }
            }
        }
    }
    return dependencies;
}
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)

Example 8 with GradleDslMethodCall

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

the class LintOptionsModel method setFileValue.

private void setFileValue(@NotNull String property, @NotNull File file) {
    GradleDslMethodCall fileElement = myDslElement.getPropertyElement(property, GradleDslMethodCall.class);
    if (fileElement == null) {
        fileElement = new GradleDslMethodCall(myDslElement, "file", property);
        myDslElement.setNewElement(property, fileElement);
    }
    fileElement.setValue(file);
}
Also used : GradleDslMethodCall(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall)

Example 9 with GradleDslMethodCall

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

the class AbiModel method addReset.

@NotNull
public AbiModel addReset() {
    GradleDslMethodCall resetMethod = new GradleDslMethodCall(myDslElement, RESET, null);
    // TODO: reset include
    myDslElement.setNewElement(RESET, resetMethod);
    return this;
}
Also used : GradleDslMethodCall(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with GradleDslMethodCall

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

the class DensityModel method addReset.

@NotNull
public DensityModel addReset() {
    GradleDslMethodCall resetMethod = new GradleDslMethodCall(myDslElement, RESET, null);
    // TODO: reset include
    myDslElement.setNewElement(RESET, resetMethod);
    return this;
}
Also used : GradleDslMethodCall(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GradleDslMethodCall (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall)10 NotNull (org.jetbrains.annotations.NotNull)6 GradleDslElement (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement)5 GradleDslExpression (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression)5 GradleDslElementList (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList)2 GradleDslLiteral (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslLiteral)2 GradleNullableValue (com.android.tools.idea.gradle.dsl.model.values.GradleNullableValue)1 Nullable (org.jetbrains.annotations.Nullable)1