Search in sources :

Example 1 with GradleNullableValue

use of com.android.tools.idea.gradle.dsl.model.values.GradleNullableValue 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 2 with GradleNullableValue

use of com.android.tools.idea.gradle.dsl.model.values.GradleNullableValue in project android by JetBrains.

the class AbstractBuildModel method path.

@NotNull
public GradleNullableValue<File> path() {
    GradleDslElement pathElement = myDslElement.getPropertyElement(PATH);
    if (pathElement == null) {
        return new GradleNullableValue<>(myDslElement, null);
    }
    File value = null;
    if (pathElement instanceof GradleDslMethodCall || pathElement instanceof GradleDslNewExpression) {
        value = ((GradleDslExpression) pathElement).getValue(File.class);
    } else if (pathElement instanceof GradleDslExpression) {
        String path = ((GradleDslExpression) pathElement).getValue(String.class);
        if (path != null) {
            value = new File(path);
        }
    }
    return new GradleNullableValue<>(pathElement, value);
}
Also used : GradleNullableValue(com.android.tools.idea.gradle.dsl.model.values.GradleNullableValue) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GradleNullableValue

use of com.android.tools.idea.gradle.dsl.model.values.GradleNullableValue 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

GradleNullableValue (com.android.tools.idea.gradle.dsl.model.values.GradleNullableValue)3 NotNull (org.jetbrains.annotations.NotNull)3 GradleDslExpression (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslExpression)2 Type (com.android.tools.idea.gradle.dsl.model.android.SigningConfigModel.SigningConfigPassword.Type)1 GradleDslElement (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement)1 GradleDslMethodCall (com.android.tools.idea.gradle.dsl.parser.elements.GradleDslMethodCall)1 File (java.io.File)1