Search in sources :

Example 6 with GradleDslExpression

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

the class RepositoryModel method name.

@NotNull
public GradleDefaultValue<String> name() {
    if (myDslElement == null) {
        return new GradleDefaultValue<>(null, myDefaultRepoName);
    }
    GradleDslExpression nameExpression = myDslElement.getPropertyElement(NAME, GradleDslExpression.class);
    String name = null;
    if (nameExpression != null) {
        name = nameExpression.getValue(String.class);
    }
    if (name == null) {
        name = myDefaultRepoName;
    }
    return new GradleDefaultValue<>(nameExpression, name);
}
Also used : GradleDslExpression(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression) GradleDefaultValue(com.android.tools.idea.gradle.dsl.model.values.GradleDefaultValue) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with GradleDslExpression

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

the class UrlBasedRepositoryModel method url.

@NotNull
public GradleDefaultValue<String> url() {
    if (myDslElement == null) {
        return new GradleDefaultValue<>(null, myDefaultRepoUrl);
    }
    GradleDslExpression nameExpression = myDslElement.getPropertyElement(URL, GradleDslExpression.class);
    String url = null;
    if (nameExpression != null) {
        url = nameExpression.getValue(String.class);
    }
    if (url == null) {
        url = myDefaultRepoUrl;
    }
    return new GradleDefaultValue<>(nameExpression, url);
}
Also used : GradleDslExpression(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression) GradleDefaultValue(com.android.tools.idea.gradle.dsl.model.values.GradleDefaultValue) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with GradleDslExpression

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

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

the class SigningConfigModel method getPasswordValue.

@NotNull
private GradleNullableValue<SigningConfigPassword> getPasswordValue(@NotNull String property) {
    GradleDslExpression passwordElement = getPasswordElement(property);
    if (passwordElement == null) {
        return new GradleNullableValue<>(myDslElement, null);
    }
    Type passwordType;
    switch(passwordElement.getName()) {
        case SYSTEM_GETENV:
            passwordType = ENVIRONMENT_VARIABLE;
            break;
        case SYSTEM_CONSOLE_READ_LINE:
            passwordType = CONSOLE_READ;
            break;
        default:
            passwordType = PLAIN_TEXT;
            break;
    }
    String passwordText = passwordElement.getValue(String.class);
    if (passwordText != null) {
        return new GradleNullableValue<>(passwordElement, new SigningConfigPassword(passwordType, passwordText));
    }
    return new GradleNullableValue<>(passwordElement, null);
}
Also used : GradleNullableValue(com.android.tools.idea.gradle.dsl.model.values.GradleNullableValue) Type(com.android.tools.idea.gradle.dsl.model.android.SigningConfigModel.SigningConfigPassword.Type) GradleDslExpression(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GradleDslExpression (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression)9 GradleDslMethodCall (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall)5 NotNull (org.jetbrains.annotations.NotNull)5 GradleDslElement (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement)4 GradleDefaultValue (com.android.tools.idea.gradle.dsl.model.values.GradleDefaultValue)2 GradleNullableValue (com.android.tools.idea.gradle.dsl.model.values.GradleNullableValue)2 GradleDslLiteral (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslLiteral)2 Type (com.android.tools.idea.gradle.dsl.model.android.SigningConfigModel.SigningConfigPassword.Type)1 GradleDslExpressionList (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionList)1 GradleDslExpressionMap (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpressionMap)1 Map (java.util.Map)1 Nullable (org.jetbrains.annotations.Nullable)1