Search in sources :

Example 1 with CompileOptionsModel

use of com.android.tools.idea.gradle.dsl.model.android.CompileOptionsModel 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

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 JavaModel (com.android.tools.idea.gradle.dsl.model.java.JavaModel)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 Nullable (org.jetbrains.annotations.Nullable)1