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);
}
Aggregations