use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.
the class GradleBuildFile method removeValue.
/**
* If the given key has a value at the given root, removes it and returns true. Returns false if there is no value for that key.
*/
public boolean removeValue(@Nullable GrStatementOwner root, @NotNull BuildFileKey key) {
checkInitialized();
commitDocumentChanges();
if (root == null) {
root = myGroovyFile;
}
GrMethodCall method = getMethodCallByPath(root, key.getPath());
if (method != null) {
GrStatementOwner parent = (GrStatementOwner) method.getParent();
parent.removeElements(new PsiElement[] { method });
reformatClosure(parent);
return true;
}
return false;
}
use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.
the class NamedObjectPanel method init.
@Override
public void init() {
super.init();
myPanelGroup.myPanes.add(myDetailsPane);
if (myGradleBuildFile == null) {
return;
}
List<NamedObject> namedObjects = (List<NamedObject>) myGradleBuildFile.getValue(myBuildFileKey);
if (namedObjects != null) {
for (NamedObject object : namedObjects) {
// consistent between the case where you've customized it and you haven't.
if (myBuildFileKey == BuildFileKey.BUILD_TYPES && HARDCODED_BUILD_TYPES.contains(object.getName())) {
object = new UndeletableNamedObject(object);
}
addElement(object);
}
}
// If this is a flavor panel, add a synthetic flavor entry for defaultConfig.
if (myBuildFileKey == BuildFileKey.FLAVORS) {
GrStatementOwner defaultConfig = myGradleBuildFile.getClosure(BuildFileKey.DEFAULT_CONFIG.getPath());
NamedObject obj = new UndeletableNamedObject(DEFAULT_CONFIG);
if (defaultConfig != null) {
for (BuildFileKey key : DEFAULT_CONFIG_KEYS) {
Object value = myGradleBuildFile.getValue(defaultConfig, key);
obj.setValue(key, value);
}
}
addElement(obj);
}
NamedObject.Factory objectFactory = (NamedObject.Factory) myBuildFileKey.getValueFactory();
if (objectFactory == null) {
throw new IllegalArgumentException("Can't instantiate a NamedObjectPanel for BuildFileKey " + myBuildFileKey.toString());
}
Collection<BuildFileKey> properties = objectFactory.getProperties();
// Query the model for its view of the world, and merge it with the build file-based view.
for (NamedObject obj : getObjectsFromModel(properties)) {
boolean found = false;
for (NamedObject o : myListModel) {
if (o.getName().equals(obj.getName())) {
found = true;
}
}
if (!found) {
NamedObject namedObject = new UndeletableNamedObject(obj.getName());
addElement(namedObject);
// Keep track of objects that are only in the model and not in the build file. We want to avoid creating them in the build file
// unless some value in them is changed to non-default.
myModelOnlyObjects.add(namedObject);
}
myModelObjects.put(obj.getName(), obj.getValues());
}
myList.updateUI();
myDetailsPane.init(myGradleBuildFile, properties);
if (myListModel.getSize() > 0) {
myList.setSelectedIndex(0);
}
updateUiFromCurrentObject();
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
updatePanelGroup();
}
}, ModalityState.any());
}
use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.
the class GradleBuildFileTest method testSetBooleanValue.
public void testSetBooleanValue() throws Exception {
final GradleBuildFile file = getTestFile(getSimpleTestFile());
final GrStatementOwner closure = file.getClosure("android/buildTypes/debug");
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
file.setValue(closure, BuildFileKey.DEBUGGABLE, false);
}
});
String expected = getSimpleTestFile().replaceAll("debuggable true", "debuggable false");
assertContents(expected);
assertEquals(false, file.getValue(closure, BuildFileKey.DEBUGGABLE));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.
the class GradleBuildFileTest method testSetIntegerOrStringAsIntegerValuedString.
public void testSetIntegerOrStringAsIntegerValuedString() throws Exception {
final GradleBuildFile file = getTestFile("android {\n" + " defaultConfig {\n" + " }\n" + "}\n");
final GrStatementOwner closure = file.getClosure("android/defaultConfig");
assertNotNull(closure);
WriteCommandAction.runWriteCommandAction(myProject, new Runnable() {
@Override
public void run() {
file.setValue(closure, BuildFileKey.TARGET_SDK_VERSION, "5");
}
});
String expected = "android {\n" + " defaultConfig {\n" + " targetSdkVersion 5\n" + " }\n" + "}\n";
assertContents(expected);
}
use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.
the class GradleBuildFileTest method testGetIntegerOrStringAsString.
public void testGetIntegerOrStringAsString() throws Exception {
final GradleBuildFile file = getTestFile("android {\n" + " defaultConfig {\n" + " targetSdkVersion 'foo'\n" + " }\n" + "}\n");
GrStatementOwner closure = file.getClosure("android/defaultConfig");
assertNotNull(closure);
assertEquals("foo", file.getValue(closure, BuildFileKey.TARGET_SDK_VERSION));
}
Aggregations