Search in sources :

Example 6 with GradleDslElement

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

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

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

the class GradleBuildModel method populateWithParentModuleSubProjectsProperties.

private static void populateWithParentModuleSubProjectsProperties(@NotNull GradleBuildDslFile buildDslFile) {
    GradleSettingsModel gradleSettingsModel = GradleSettingsModel.get(buildDslFile.getProject());
    if (gradleSettingsModel == null) {
        return;
    }
    String modulePath = gradleSettingsModel.moduleWithDirectory(buildDslFile.getDirectoryPath());
    if (modulePath == null) {
        return;
    }
    GradleBuildModel parentModuleModel = gradleSettingsModel.getParentModuleModel(modulePath);
    if (parentModuleModel == null) {
        return;
    }
    GradleDslFile parentModuleDslFile = parentModuleModel.myGradleDslFile;
    buildDslFile.setParentModuleDslFile(parentModuleDslFile);
    SubProjectsDslElement subProjectsDslElement = parentModuleDslFile.getPropertyElement(SUBPROJECTS_BLOCK_NAME, SubProjectsDslElement.class);
    if (subProjectsDslElement == null) {
        return;
    }
    buildDslFile.setParsedElement(SUBPROJECTS_BLOCK_NAME, subProjectsDslElement);
    for (Map.Entry<String, GradleDslElement> entry : subProjectsDslElement.getPropertyElements().entrySet()) {
        buildDslFile.setParsedElement(entry.getKey(), entry.getValue());
    }
}
Also used : SubProjectsDslElement(com.android.tools.idea.gradle.dsl.parser.build.SubProjectsDslElement) GradleDslFile(com.android.tools.idea.gradle.dsl.parser.GradleDslFile) Map(java.util.Map) GradleDslExpressionMap(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap) GradleDslElement(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement)

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