Search in sources :

Example 1 with JavaModel

use of com.android.tools.idea.gradle.dsl.model.java.JavaModel in project android by JetBrains.

the class AllProjectsTest method testAllProjectsSection.

public void testAllProjectsSection() throws Exception {
    String settingsText = "include ':" + SUB_MODULE_NAME + "'";
    String mainModuleText = "allprojects { \n" + "  sourceCompatibility = 1.5\n" + "  targetCompatibility = 1.6\n" + "}";
    String subModuleText = "";
    writeToSettingsFile(settingsText);
    writeToBuildFile(mainModuleText);
    writeToSubModuleBuildFile(subModuleText);
    JavaModel java = getGradleBuildModel().java();
    assertEquals(LanguageLevel.JDK_1_5, java.sourceCompatibility());
    assertEquals(LanguageLevel.JDK_1_6, java.targetCompatibility());
    JavaModel subModuleJavaModel = getSubModuleGradleBuildModel().java();
    assertEquals(LanguageLevel.JDK_1_5, subModuleJavaModel.sourceCompatibility());
    assertEquals(LanguageLevel.JDK_1_6, subModuleJavaModel.targetCompatibility());
}
Also used : JavaModel(com.android.tools.idea.gradle.dsl.model.java.JavaModel)

Example 2 with JavaModel

use of com.android.tools.idea.gradle.dsl.model.java.JavaModel in project android by JetBrains.

the class AllProjectsTest method testOverrideAllProjectsSectionInSubproject.

public void testOverrideAllProjectsSectionInSubproject() throws Exception {
    String settingsText = "include ':" + SUB_MODULE_NAME + "'";
    String mainModuleText = "allprojects { \n" + "  sourceCompatibility = 1.4\n" + "  targetCompatibility = 1.5\n" + "}\n" + "sourceCompatibility = 1.5 \n" + "targetCompatibility = 1.6";
    String subModuleText = "sourceCompatibility = 1.6\n" + "targetCompatibility = 1.7";
    writeToSettingsFile(settingsText);
    writeToBuildFile(mainModuleText);
    writeToSubModuleBuildFile(subModuleText);
    JavaModel java = getGradleBuildModel().java();
    // 1_4 is overridden with 1_5
    assertEquals(LanguageLevel.JDK_1_5, java.sourceCompatibility());
    // 1_5 is overridden with 1_6
    assertEquals(LanguageLevel.JDK_1_6, java.targetCompatibility());
    JavaModel subModuleJavaModel = getSubModuleGradleBuildModel().java();
    // 1_4 is overridden with 1_6
    assertEquals(LanguageLevel.JDK_1_6, subModuleJavaModel.sourceCompatibility());
    // 1_5 is overridden with 1_7
    assertEquals(LanguageLevel.JDK_1_7, subModuleJavaModel.targetCompatibility());
}
Also used : JavaModel(com.android.tools.idea.gradle.dsl.model.java.JavaModel)

Example 3 with JavaModel

use of com.android.tools.idea.gradle.dsl.model.java.JavaModel in project android by JetBrains.

the class AllProjectsTest method testOverrideWithAllProjectsSection.

public void testOverrideWithAllProjectsSection() throws Exception {
    String settingsText = "include ':" + SUB_MODULE_NAME + "'";
    String mainModuleText = "sourceCompatibility = 1.4 \n" + "targetCompatibility = 1.5 \n" + "allprojects { \n" + "  sourceCompatibility = 1.5\n" + "  targetCompatibility = 1.6\n" + "}";
    String subModuleText = "";
    writeToSettingsFile(settingsText);
    writeToBuildFile(mainModuleText);
    writeToSubModuleBuildFile(subModuleText);
    JavaModel java = getGradleBuildModel().java();
    // 1_4 is overridden with 1_5
    assertEquals(LanguageLevel.JDK_1_5, java.sourceCompatibility());
    // 1_5 is overridden with 1_6
    assertEquals(LanguageLevel.JDK_1_6, java.targetCompatibility());
    JavaModel subModuleJavaModel = getSubModuleGradleBuildModel().java();
    // Subproject got 1_5 from allprojects section
    assertEquals(LanguageLevel.JDK_1_5, subModuleJavaModel.sourceCompatibility());
    // Subproject got 1_5 from allprojects section
    assertEquals(LanguageLevel.JDK_1_6, subModuleJavaModel.targetCompatibility());
}
Also used : JavaModel(com.android.tools.idea.gradle.dsl.model.java.JavaModel)

Example 4 with JavaModel

use of com.android.tools.idea.gradle.dsl.model.java.JavaModel in project android by JetBrains.

the class AllProjectsTest method testOverrideAllProjectsSection.

public void testOverrideAllProjectsSection() throws Exception {
    String settingsText = "include ':" + SUB_MODULE_NAME + "'";
    String mainModuleText = "allprojects { \n" + "  sourceCompatibility = 1.4\n" + "  targetCompatibility = 1.5\n" + "}\n" + "sourceCompatibility = 1.5 \n" + "targetCompatibility = 1.6";
    String subModuleText = "";
    writeToSettingsFile(settingsText);
    writeToBuildFile(mainModuleText);
    writeToSubModuleBuildFile(subModuleText);
    JavaModel java = getGradleBuildModel().java();
    // 1_4 is overridden with 1_5
    assertEquals(LanguageLevel.JDK_1_5, java.sourceCompatibility());
    // 1_5 is overridden with 1_6
    assertEquals(LanguageLevel.JDK_1_6, java.targetCompatibility());
    JavaModel subModuleJavaModel = getSubModuleGradleBuildModel().java();
    // Subproject got 1_4 from allprojects section
    assertEquals(LanguageLevel.JDK_1_4, subModuleJavaModel.sourceCompatibility());
    // Subproject got 1_5 from allprojects section
    assertEquals(LanguageLevel.JDK_1_5, subModuleJavaModel.targetCompatibility());
}
Also used : JavaModel(com.android.tools.idea.gradle.dsl.model.java.JavaModel)

Example 5 with JavaModel

use of com.android.tools.idea.gradle.dsl.model.java.JavaModel in project android by JetBrains.

the class AndroidGradleJavaProjectModelModifier method changeLanguageLevel.

@Nullable
@Override
public Promise<Void> changeLanguageLevel(@NotNull Module module, @NotNull LanguageLevel level) {
    Project project = module.getProject();
    if (!isBuildWithGradle(module)) {
        return null;
    }
    GradleBuildModel buildModel = GradleBuildModel.get(module);
    if (buildModel == null) {
        return null;
    }
    if (getAndroidModel(module) != null) {
        AndroidModel android = buildModel.android();
        if (android == null) {
            return null;
        }
        CompileOptionsModel compileOptions = android.compileOptions();
        compileOptions.setSourceCompatibility(level);
        compileOptions.setTargetCompatibility(level);
    } else {
        JavaFacet javaFacet = JavaFacet.getInstance(module);
        if (javaFacet == null || javaFacet.getJavaModuleModel() == null) {
            return null;
        }
        JavaModel javaModel = buildModel.java();
        javaModel.setSourceCompatibility(level);
        javaModel.setTargetCompatibility(level);
    }
    new WriteCommandAction(project, "Change Gradle Language Level") {

        @Override
        protected void run(@NotNull Result result) throws Throwable {
            buildModel.applyChanges();
            registerUndoAction(project);
        }
    }.execute();
    return requestProjectSync(project);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Project(com.intellij.openapi.project.Project) JavaFacet(com.android.tools.idea.gradle.project.facet.java.JavaFacet) GradleBuildModel(com.android.tools.idea.gradle.dsl.model.GradleBuildModel) Projects.getAndroidModel(com.android.tools.idea.gradle.util.Projects.getAndroidModel) AndroidModel(com.android.tools.idea.gradle.dsl.model.android.AndroidModel) JavaModel(com.android.tools.idea.gradle.dsl.model.java.JavaModel) CompileOptionsModel(com.android.tools.idea.gradle.dsl.model.android.CompileOptionsModel) Result(com.intellij.openapi.application.Result) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

JavaModel (com.android.tools.idea.gradle.dsl.model.java.JavaModel)9 GradleBuildModel (com.android.tools.idea.gradle.dsl.model.GradleBuildModel)1 AndroidModel (com.android.tools.idea.gradle.dsl.model.android.AndroidModel)1 CompileOptionsModel (com.android.tools.idea.gradle.dsl.model.android.CompileOptionsModel)1 JavaDslElement (com.android.tools.idea.gradle.dsl.parser.java.JavaDslElement)1 JavaFacet (com.android.tools.idea.gradle.project.facet.java.JavaFacet)1 Projects.getAndroidModel (com.android.tools.idea.gradle.util.Projects.getAndroidModel)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Project (com.intellij.openapi.project.Project)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1