Search in sources :

Example 36 with GrStatementOwner

use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.

the class GradleBuildFileTest method testCreateIntegerValue.

@SuppressWarnings("unchecked")
public void testCreateIntegerValue() throws Exception {
    final GradleBuildFile file = getTestFile(getSimpleTestFile());
    final GrStatementOwner closure = file.getClosure("android/productFlavors/flavor1");
    WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {

        @Override
        public void run() {
            file.setValue(closure, BuildFileKey.VERSION_CODE, 199);
        }
    });
    StringBuilder expected = new StringBuilder(getSimpleTestFile());
    int position = expected.indexOf("\n", expected.indexOf("proguard-flavor1.txt")) + 1;
    expected.insert(position, "            versionCode 199\n");
    assertContents(expected.toString());
    Object value = file.getValue(BuildFileKey.FLAVORS);
    assertNotNull("flavors should be parsed", value);
    final List<NamedObject> flavors = (List<NamedObject>) value;
    assertEquals(2, flavors.size());
    assertEquals(199, flavors.get(0).getValue(BuildFileKey.VERSION_CODE));
}
Also used : GrStatementOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 37 with GrStatementOwner

use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.

the class GradleBuildFileTest method testSetFileValue.

public void testSetFileValue() throws Exception {
    final GradleBuildFile file = getTestFile(getSimpleTestFile());
    final GrStatementOwner closure = file.getClosure("android/signingConfigs/debug");
    final File replacementFile = new File("abc/def/foo.keystore");
    WriteCommandAction.runWriteCommandAction(getProject(), new Runnable() {

        @Override
        public void run() {
            file.setValue(closure, BuildFileKey.STORE_FILE, replacementFile);
        }
    });
    // We always expect system independent paths in build.gradle files.
    String expected = getSimpleTestFile().replaceAll("debug.keystore", "abc/def/foo.keystore");
    assertContents(expected);
    assertEquals(replacementFile, file.getValue(closure, BuildFileKey.STORE_FILE));
}
Also used : GrStatementOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 38 with GrStatementOwner

use of org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner in project android by JetBrains.

the class GradleBuildFileTest method testSetIntegerOrStringAsString.

public void testSetIntegerOrStringAsString() 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, "foo");
        }
    });
    String expected = "android {\n" + "    defaultConfig {\n" + "        targetSdkVersion 'foo'\n" + "    }\n" + "}\n";
    assertContents(expected);
}
Also used : GrStatementOwner(org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner)

Aggregations

GrStatementOwner (org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner)38 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)11 PsiElement (com.intellij.psi.PsiElement)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 File (java.io.File)4 List (java.util.List)4 GrOpenBlock (org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock)4 GrMethod (org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod)4 ImmutableList (com.google.common.collect.ImmutableList)3 GrControlStatement (org.jetbrains.plugins.groovy.lang.psi.api.formatter.GrControlStatement)3 GrBlockStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrBlockStatement)3 BuildFileKey (com.android.tools.idea.gradle.parser.BuildFileKey)2 NamedObject (com.android.tools.idea.gradle.parser.NamedObject)2 ValueFactory (com.android.tools.idea.gradle.parser.ValueFactory)2 ASTNode (com.intellij.lang.ASTNode)2 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 IElementType (com.intellij.psi.tree.IElementType)2 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 NotNull (org.jetbrains.annotations.NotNull)2