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 intellij-community by JetBrains.
the class GroovyFix method replaceStatement.
/**
* unwraps surrounding blocks from newStatement.
*/
protected static void replaceStatement(GrStatement oldStatement, GrStatement newStatement) throws IncorrectOperationException {
if (newStatement instanceof GrBlockStatement) {
GrBlockStatement blockStatement = (GrBlockStatement) newStatement;
final GrOpenBlock openBlock = blockStatement.getBlock();
final GrStatement[] statements = openBlock.getStatements();
if (statements.length == 0) {
oldStatement.removeStatement();
} else {
final PsiElement parent = oldStatement.getParent();
if (parent instanceof GrStatementOwner) {
GrStatementOwner statementOwner = (GrStatementOwner) parent;
for (GrStatement statement : statements) {
statementOwner.addStatementBefore(statement, oldStatement);
}
oldStatement.removeStatement();
} else if (parent instanceof GrControlStatement) {
oldStatement.replace(newStatement);
}
}
} else {
oldStatement.replaceWithStatement(newStatement);
}
}
use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.
the class GradleBuildFileTest method testSetIntegerOrStringAsInteger.
public void testSetIntegerOrStringAsInteger() 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 testSetFileStringValue.
public void testSetFileStringValue() throws Exception {
final GradleBuildFile file = getTestFile(getSimpleTestFile());
final GrStatementOwner closure = file.getClosure("android/productFlavors/flavor1");
final File replacementFile = new File("abc/def/foo.txt");
WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {
@Override
public void run() {
file.setValue(closure, BuildFileKey.PROGUARD_FILE, replacementFile);
}
});
// We always expect system independent paths in build.gradle files.
String expected = getSimpleTestFile().replaceAll("proguard-flavor1\\.txt", "abc/def/foo.txt");
assertContents(expected);
assertEquals(replacementFile, file.getValue(closure, BuildFileKey.PROGUARD_FILE));
}
use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.
the class GradleBuildFileTest method testGetIntegerOrStringAsInteger.
public void testGetIntegerOrStringAsInteger() throws Exception {
final GradleBuildFile file = getTestFile("android {\n" + " defaultConfig {\n" + " targetSdkVersion 5\n" + " }\n" + "}\n");
GrStatementOwner closure = file.getClosure("android/defaultConfig");
assertNotNull(closure);
assertEquals("5", file.getValue(closure, BuildFileKey.TARGET_SDK_VERSION));
}
Aggregations