Search in sources :

Example 1 with GradleDslMethodCall

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

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

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

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

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

GradleDslMethodCall (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall)10 NotNull (org.jetbrains.annotations.NotNull)6 GradleDslElement (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement)5 GradleDslExpression (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression)5 GradleDslElementList (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElementList)2 GradleDslLiteral (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslLiteral)2 GradleNullableValue (com.android.tools.idea.gradle.dsl.model.values.GradleNullableValue)1 Nullable (org.jetbrains.annotations.Nullable)1