use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement 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;
}
use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement 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);
}
use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement 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;
}
use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement in project android by JetBrains.
the class GradleValue method getResolvedVariables.
@NotNull
public Map<String, GradleNotNullValue<Object>> getResolvedVariables() {
if (myDslElement == null) {
return ImmutableMap.of();
}
ImmutableMap.Builder<String, GradleNotNullValue<Object>> builder = ImmutableMap.builder();
for (GradleResolvedVariable variable : myDslElement.getResolvedVariables()) {
String variableName = variable.getVariableName();
Object resolvedValue = variable.getValue();
GradleDslElement element = variable.getElement();
builder.put(variableName, new GradleNotNullValue<>(element, resolvedValue));
}
return builder.build();
}
use of com.android.tools.idea.gradle.dsl.parser.elements.GradleDslElement in project android by JetBrains.
the class DependenciesModel method remove.
@NotNull
public DependenciesModel remove(@NotNull DependencyModel dependency) {
GradleDslElementList gradleDslElementList = myDslElement.getPropertyElement(dependency.configurationName(), GradleDslElementList.class);
if (gradleDslElementList != null) {
GradleDslElement dependencyElement = dependency.getDslElement();
GradleDslElement parent = dependencyElement.getParent();
if (parent instanceof GradleDslMethodCall) {
GradleDslMethodCall methodCall = (GradleDslMethodCall) parent;
List<GradleDslElement> arguments = methodCall.getArguments();
if (arguments.size() == 1 && arguments.get(0).equals(dependencyElement)) {
// If this is the last argument, remove the method call altogether.
gradleDslElementList.removeElement(methodCall);
} else {
methodCall.remove(dependencyElement);
}
} else {
gradleDslElementList.removeElement(dependencyElement);
}
}
return this;
}
Aggregations