Search in sources :

Example 1 with GradleDslElementList

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

the class RepositoriesDslElement method setParsedElement.

@Override
public void setParsedElement(@NotNull String name, @NotNull GradleDslElement repository) {
    // Because we need to preserve the the order of the repositories defined, storing all the repository elements in a dummy element list.
    // TODO: Consider extending RepositoriesDslElement directly from GradleDslElementList instead of GradlePropertiesDslElement.
    GradleDslElementList repositoriesListElement = getOrCreateRepositoriesElement();
    repositoriesListElement.addParsedElement(repository);
}
Also used : GradleDslElementList(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList)

Example 2 with GradleDslElementList

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

the class BuildTypeDslElement method addParsedElement.

@Override
public void addParsedElement(@NotNull String property, @NotNull GradleDslElement element) {
    if (property.equals("buildConfigField")) {
        if (!(element instanceof GradleDslExpressionList)) {
            return;
        }
        GradleDslExpressionList listElement = (GradleDslExpressionList) element;
        if (listElement.getExpressions().size() != 3 || listElement.getValues(String.class).size() != 3) {
            return;
        }
        GradleDslElementList elementList = getPropertyElement("buildConfigField", GradleDslElementList.class);
        if (elementList == null) {
            elementList = new GradleDslElementList(this, "buildConfigField");
            setParsedElement("buildConfigField", elementList);
        }
        elementList.addParsedElement(element);
        return;
    }
    super.addParsedElement(property, element);
}
Also used : GradleDslExpressionList(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionList) GradleDslElementList(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList)

Example 3 with GradleDslElementList

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

the class DependenciesModel method addArtifact.

@NotNull
public DependenciesModel addArtifact(@NotNull String configurationName, @NotNull ArtifactDependencySpec dependency, @NotNull List<ArtifactDependencySpec> excludes) {
    GradleDslElementList list = getOrCreateGradleDslElementList(configurationName);
    ArtifactDependencyModel.createAndAddToList(list, configurationName, dependency, excludes);
    return this;
}
Also used : GradleDslElementList(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GradleDslElementList

use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList 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 5 with GradleDslElementList

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

the class DependenciesModel method getOrCreateGradleDslElementList.

@NotNull
private GradleDslElementList getOrCreateGradleDslElementList(@NotNull String configurationName) {
    GradleDslElementList list = myDslElement.getPropertyElement(configurationName, GradleDslElementList.class);
    if (list == null) {
        list = new GradleDslElementList(myDslElement, configurationName);
        myDslElement.setNewElement(configurationName, list);
    }
    return list;
}
Also used : GradleDslElementList(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GradleDslElementList (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList)13 NotNull (org.jetbrains.annotations.NotNull)9 GradleDslElement (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement)2 GradleDslMethodCall (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall)2 GradleDslExpressionList (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionList)1 GradleDslExpressionMap (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap)1 ArrayList (java.util.ArrayList)1