Search in sources :

Example 1 with GradleDslExpressionList

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

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

the class ExtModelTest method testListReferenceInListProperty.

public void testListReferenceInListProperty() throws IOException {
    String text = "ext.TEST_STRINGS = [\"test1\", \"test2\"]\n" + "android.defaultConfig {\n" + "    proguardFiles TEST_STRINGS\n" + "}";
    writeToBuildFile(text);
    GradleBuildModel buildModel = getGradleBuildModel();
    ExtModel extModel = buildModel.ext();
    GradleDslExpressionList testStringsList = extModel.getPropertyElement("TEST_STRINGS", GradleDslExpressionList.class);
    assertNotNull(testStringsList);
    assertEquals(ImmutableList.of("test1", "test2"), testStringsList.getValues(String.class));
    AndroidModel androidModel = buildModel.android();
    assertNotNull(androidModel);
    ProductFlavorModel defaultConfig = androidModel.defaultConfig();
    assertEquals("proguardFiles", ImmutableList.of("test1", "test2"), defaultConfig.proguardFiles());
}
Also used : GradleDslExpressionList(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionList) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel) ProductFlavorModel(com.android.tools.idea.gradle.dsl.model.android.ProductFlavorModel)

Example 3 with GradleDslExpressionList

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

the class ProductFlavorDslElement method addParsedElement.

@Override
public void addParsedElement(@NotNull String property, @NotNull GradleDslElement element) {
    if (property.equals("resConfigs") || property.equals("resConfig")) {
        addToParsedExpressionList("resConfigs", element);
        return;
    }
    if (property.equals("testInstrumentationRunnerArguments")) {
        if (!(element instanceof GradleDslExpressionMap)) {
            return;
        }
        GradleDslExpressionMap testInstrumentationRunnerArgumentsElement = getPropertyElement("testInstrumentationRunnerArguments", GradleDslExpressionMap.class);
        if (testInstrumentationRunnerArgumentsElement == null) {
            setParsedElement("testInstrumentationRunnerArguments", element);
        } else {
            testInstrumentationRunnerArgumentsElement.setPsiElement(element.getPsiElement());
            GradleDslExpressionMap elementsToAdd = (GradleDslExpressionMap) element;
            for (Map.Entry<String, GradleDslElement> entry : elementsToAdd.getPropertyElements().entrySet()) {
                testInstrumentationRunnerArgumentsElement.setParsedElement(entry.getKey(), entry.getValue());
            }
        }
        return;
    }
    if (property.equals("testInstrumentationRunnerArgument")) {
        if (!(element instanceof GradleDslExpressionList)) {
            return;
        }
        GradleDslExpressionList gradleDslExpressionList = (GradleDslExpressionList) element;
        List<GradleDslExpression> elements = gradleDslExpressionList.getExpressions();
        if (elements.size() != 2) {
            return;
        }
        String key = elements.get(0).getValue(String.class);
        if (key == null) {
            return;
        }
        GradleDslExpression value = elements.get(1);
        GradleDslExpressionMap testInstrumentationRunnerArgumentsElement = getPropertyElement("testInstrumentationRunnerArguments", GradleDslExpressionMap.class);
        if (testInstrumentationRunnerArgumentsElement == null) {
            testInstrumentationRunnerArgumentsElement = new GradleDslExpressionMap(this, "testInstrumentationRunnerArguments");
        }
        testInstrumentationRunnerArgumentsElement.setParsedElement(key, value);
        return;
    }
    super.addParsedElement(property, element);
}
Also used : GradleDslExpressionList(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionList) GradleDslExpressionMap(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap) GradleDslExpression(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression) GradleDslExpressionMap(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap) Map(java.util.Map) GradleDslElement(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement)

Example 4 with GradleDslExpressionList

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

the class BuildTypeModel method buildConfigFields.

@Nullable
public List<GradleNotNullValue<BuildConfigField>> buildConfigFields() {
    List<Pair<GradleDslExpressionList, TypeNameValueElement>> typeNameValueElements = getTypeNameValueElements(BUILD_CONFIG_FIELD);
    if (typeNameValueElements == null) {
        return null;
    }
    List<GradleNotNullValue<BuildConfigField>> buildConfigFields = Lists.newArrayListWithCapacity(typeNameValueElements.size());
    for (Pair<GradleDslExpressionList, TypeNameValueElement> pair : typeNameValueElements) {
        GradleDslExpressionList listElement = pair.getFirst();
        TypeNameValueElement typeNameValueElement = pair.getSecond();
        buildConfigFields.add(new GradleNotNullValue<>(listElement, new BuildConfigField(typeNameValueElement.type(), typeNameValueElement.name(), typeNameValueElement.value())));
    }
    return buildConfigFields;
}
Also used : GradleDslExpressionList(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionList) GradleNotNullValue(com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue) Pair(com.android.utils.Pair) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GradleDslExpressionList (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionList)4 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)1 AndroidModel (com.android.tools.idea.gradle.dsl.model.android.AndroidModel)1 ProductFlavorModel (com.android.tools.idea.gradle.dsl.model.android.ProductFlavorModel)1 GradleNotNullValue (com.android.tools.idea.gradle.dsl.model.values.GradleNotNullValue)1 GradleDslElement (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement)1 GradleDslElementList (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList)1 GradleDslExpression (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression)1 GradleDslExpressionMap (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap)1 Pair (com.android.utils.Pair)1 Map (java.util.Map)1 Nullable (org.jetbrains.annotations.Nullable)1