use of com.intellij.openapi.roots.LanguageLevelModuleExtension in project android by JetBrains.
the class NewProjectTest method testLanguageLevelForApi21.
@Test
public void testLanguageLevelForApi21() {
newProject("Test Application").withBriefNames().withMinSdk("21").create();
AndroidModuleModel appAndroidModel = guiTest.ideFrame().getAndroidProjectForModule("app");
assertThat(appAndroidModel.getAndroidProject().getDefaultConfig().getProductFlavor().getMinSdkVersion().getApiString()).named("minSdkVersion API").isEqualTo("21");
assertThat(appAndroidModel.getJavaLanguageLevel()).named("Gradle Java language level").isSameAs(LanguageLevel.JDK_1_7);
LanguageLevelProjectExtension projectExt = LanguageLevelProjectExtension.getInstance(guiTest.ideFrame().getProject());
assertThat(projectExt.getLanguageLevel()).named("Project Java language level").isSameAs(LanguageLevel.JDK_1_7);
for (Module module : ModuleManager.getInstance(guiTest.ideFrame().getProject()).getModules()) {
LanguageLevelModuleExtension moduleExt = LanguageLevelModuleExtensionImpl.getInstance(module);
assertThat(moduleExt.getLanguageLevel()).named("Gradle Java language level in module " + module.getName()).isSameAs(LanguageLevel.JDK_1_7);
}
}
use of com.intellij.openapi.roots.LanguageLevelModuleExtension in project android by JetBrains.
the class JavaModuleDynamicPath method performFinishingOperation.
private boolean performFinishingOperation(boolean dryRun) {
Project project = getProject();
assert project != null;
Map<String, Object> parameterValueMap = Maps.newHashMap();
// Grab our parameters from the state
parameterValueMap.putAll(myState.flatten());
// Compute the module directory
String projectName = (String) parameterValueMap.get(FormFactorUtils.ATTR_MODULE_NAME);
String moduleName = WizardUtils.computeModuleName(projectName, getProject());
String modulePath = FileUtil.toSystemIndependentName(FileUtil.join(project.getBasePath(), moduleName));
parameterValueMap.put(TemplateMetadata.ATTR_PROJECT_OUT, modulePath);
parameterValueMap.put(FormFactorUtils.ATTR_MODULE_NAME, moduleName);
// Compute the output directory
String packageName = myState.get(PACKAGE_NAME);
assert packageName != null;
String packagePath = FileUtil.join(myState.getNotNull(SRC_DIR, "src/main/java/"), packageName.replace('.', '/'));
String srcOut = FileUtil.toSystemIndependentName(FileUtil.join(modulePath, packagePath));
parameterValueMap.put(TemplateMetadata.ATTR_SRC_OUT, srcOut);
parameterValueMap.put(TemplateMetadata.ATTR_IS_NEW_PROJECT, true);
parameterValueMap.put(ATTR_IS_LIBRARY_MODULE, true);
// Set Java version, if not already done
if (!parameterValueMap.containsKey(ATTR_JAVA_VERSION)) {
// We can't JUST look at the overall project level language level, since
// Gradle sync appears not to sync the overall project level; instead we
// have to take the min of all the modules
LanguageLevel min = ApplicationManager.getApplication().runReadAction(new Computable<LanguageLevel>() {
@Override
public LanguageLevel compute() {
LanguageLevel min = null;
for (Module module : ModuleManager.getInstance(project).getModules()) {
LanguageLevelModuleExtension moduleLevelExt = LanguageLevelModuleExtensionImpl.getInstance(module);
if (moduleLevelExt != null) {
LanguageLevel moduleLevel = moduleLevelExt.getLanguageLevel();
if (moduleLevel != null) {
if (min == null) {
min = moduleLevel;
} else if (moduleLevel.compareTo(min) < 0) {
min = moduleLevel;
}
}
}
}
if (min == null) {
min = LanguageLevelProjectExtension.getInstance(project).getLanguageLevel();
}
return min;
}
});
parameterValueMap.put(ATTR_JAVA_VERSION, min.getCompilerComplianceDefaultOption());
}
// @formatter:off
RenderingContext context = RenderingContext.Builder.newContext(myTemplate, project).withCommandName("New Java Library").withDryRun(dryRun).withShowErrors(true).withModuleRoot(new File(FileUtil.toSystemDependentName(modulePath))).withParams(parameterValueMap).withGradleSync(false).build();
// @formatter:on
return myTemplate.render(context);
}
use of com.intellij.openapi.roots.LanguageLevelModuleExtension in project intellij-plugins by JetBrains.
the class CucumberJavaTestUtil method createCucumberJava8ProjectDescriptor.
public static DefaultLightProjectDescriptor createCucumberJava8ProjectDescriptor() {
return new DefaultLightProjectDescriptor() {
@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
attachCucumberLibraries(module, model);
LanguageLevelModuleExtension extension = model.getModuleExtension(LanguageLevelModuleExtension.class);
if (extension != null) {
extension.setLanguageLevel(LanguageLevel.JDK_1_8);
}
VirtualFile sourceRoot = VirtualFileManager.getInstance().refreshAndFindFileByUrl("temp:///src");
if (sourceRoot != null) {
contentEntry.removeSourceFolder(contentEntry.getSourceFolders()[0]);
contentEntry.addSourceFolder(sourceRoot, true);
}
}
};
}
use of com.intellij.openapi.roots.LanguageLevelModuleExtension in project intellij-community by JetBrains.
the class EffectiveLanguageLevelUtil method getEffectiveLanguageLevel.
@NotNull
public static LanguageLevel getEffectiveLanguageLevel(@NotNull final Module module) {
ApplicationManager.getApplication().assertReadAccessAllowed();
LanguageLevelModuleExtension moduleLevel = LanguageLevelModuleExtensionImpl.getInstance(module);
LanguageLevel level = moduleLevel == null ? null : moduleLevel.getLanguageLevel();
if (level != null)
return level;
return LanguageLevelProjectExtension.getInstance(module.getProject()).getLanguageLevel();
}
use of com.intellij.openapi.roots.LanguageLevelModuleExtension in project intellij-community by JetBrains.
the class LanguageLevelUsagesCollector method getProjectUsages.
@NotNull
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
final Set<String> languageLevels = new HashSet<>();
for (Module module : ModuleManager.getInstance(project).getModules()) {
final LanguageLevelModuleExtension instance = LanguageLevelModuleExtensionImpl.getInstance(module);
final LanguageLevel languageLevel = instance.getLanguageLevel();
if (languageLevel != null) {
languageLevels.add(languageLevel.toString());
} else {
languageLevels.add(LanguageLevelProjectExtension.getInstance(project).getLanguageLevel().toString());
}
}
return ContainerUtil.map2Set(languageLevels, languageLevel -> new UsageDescriptor(languageLevel, 1));
}
Aggregations