Search in sources :

Example 1 with GradleDslExpression

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

the class SigningConfigModel method getStoreFileExpression.

@Nullable
private GradleDslExpression getStoreFileExpression() {
    GradleDslMethodCall methodCall = myDslElement.getPropertyElement(STORE_FILE, GradleDslMethodCall.class);
    if (methodCall == null || methodCall.getArguments().size() == 0) {
        return null;
    }
    GradleDslElement argument = methodCall.getArguments().get(0);
    if (argument instanceof GradleDslExpression) {
        return (GradleDslExpression) argument;
    }
    return null;
}
Also used : GradleDslExpression(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression) GradleDslMethodCall(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall) GradleDslElement(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GradleDslExpression

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

the class SigningConfigModel method setStoreFile.

public SigningConfigModel setStoreFile(@NotNull String storeFile) {
    if (myDslElement.getPropertyElement(STORE_FILE) == null) {
        GradleDslMethodCall methodCall = new GradleDslMethodCall(myDslElement, "file", STORE_FILE);
        GradleDslLiteral literal = new GradleDslLiteral(methodCall, "");
        literal.setValue(storeFile);
        methodCall.addNewArgument(literal);
        myDslElement.setNewElement(STORE_FILE, methodCall);
    } else {
        GradleDslExpression expression = getStoreFileExpression();
        if (expression != null) {
            expression.setValue(storeFile);
        }
    }
    return this;
}
Also used : GradleDslExpression(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression) GradleDslMethodCall(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall) GradleDslLiteral(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslLiteral)

Example 3 with GradleDslExpression

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

the class SigningConfigModel method setPasswordValue.

private void setPasswordValue(@NotNull String property, @NotNull Type type, @NotNull String text) {
    if (type == PLAIN_TEXT) {
        myDslElement.setNewLiteral(property, text);
        return;
    }
    GradleNullableValue<SigningConfigPassword> passwordValue = getPasswordValue(property);
    SigningConfigPassword password = passwordValue.value();
    if (password != null && password.getType() == type) {
        GradleDslExpression element = getPasswordElement(property);
        if (element != null) {
            element.setValue(text);
            return;
        }
    }
    GradleDslMethodCall methodCall = null;
    if (type == ENVIRONMENT_VARIABLE) {
        methodCall = new GradleDslMethodCall(myDslElement, SYSTEM_GETENV, property);
    } else if (type == CONSOLE_READ) {
        methodCall = new GradleDslMethodCall(myDslElement, SYSTEM_CONSOLE_READ_LINE, property);
    }
    if (methodCall != null) {
        GradleDslLiteral argumentElement = new GradleDslLiteral(methodCall, methodCall.getName());
        argumentElement.setValue(text);
        methodCall.addNewArgument(argumentElement);
        myDslElement.setNewElement(property, methodCall);
    }
}
Also used : GradleDslExpression(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression) GradleDslMethodCall(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall) GradleDslLiteral(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslLiteral)

Example 4 with GradleDslExpression

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

the class SourceSetModel method root.

@NotNull
public GradleNullableValue<String> root() {
    GradleDslExpression rootElement = myDslElement.getPropertyElement(ROOT, GradleDslExpression.class);
    if (rootElement == null) {
        return new GradleNullableValue<>(myDslElement, null);
    }
    String value = null;
    if (rootElement instanceof GradleDslMethodCall) {
        List<GradleDslElement> arguments = ((GradleDslMethodCall) rootElement).getArguments();
        if (!arguments.isEmpty()) {
            GradleDslElement pathArgument = arguments.get(0);
            if (pathArgument instanceof GradleDslExpression) {
                value = ((GradleDslExpression) pathArgument).getValue(String.class);
            }
        }
    } else {
        value = rootElement.getValue(String.class);
    }
    return new GradleNullableValue<>(rootElement, value);
}
Also used : GradleNullableValue(com.android.tools.idea.gradle.dsl.model.values.GradleNullableValue) GradleDslExpression(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression) 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 GradleDslExpression

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

the class SourceSetModel method setRoot.

@NotNull
public SourceSetModel setRoot(@NotNull String root) {
    GradleDslExpression rootElement = myDslElement.getPropertyElement(ROOT, GradleDslExpression.class);
    if (rootElement == null) {
        myDslElement.setNewLiteral(ROOT, root);
        return this;
    }
    if (rootElement instanceof GradleDslMethodCall) {
        List<GradleDslElement> arguments = ((GradleDslMethodCall) rootElement).getArguments();
        if (!arguments.isEmpty()) {
            GradleDslElement pathArgument = arguments.get(0);
            if (pathArgument instanceof GradleDslExpression) {
                ((GradleDslExpression) pathArgument).setValue(root);
                return this;
            }
        }
    }
    rootElement.setValue(root);
    return this;
}
Also used : GradleDslExpression(com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression) 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)

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