Search in sources :

Example 1 with LanguageLevelModuleExtension

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);
    }
}
Also used : AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension) Module(com.intellij.openapi.module.Module) LanguageLevelModuleExtension(com.intellij.openapi.roots.LanguageLevelModuleExtension) Test(org.junit.Test)

Example 2 with LanguageLevelModuleExtension

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);
}
Also used : Project(com.intellij.openapi.project.Project) RenderingContext(com.android.tools.idea.templates.recipe.RenderingContext) LanguageLevel(com.intellij.pom.java.LanguageLevel) Module(com.intellij.openapi.module.Module) LanguageLevelModuleExtension(com.intellij.openapi.roots.LanguageLevelModuleExtension) File(java.io.File)

Example 3 with LanguageLevelModuleExtension

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);
            }
        }
    };
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ContentEntry(com.intellij.openapi.roots.ContentEntry) DefaultLightProjectDescriptor(com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor) Module(com.intellij.openapi.module.Module) LanguageLevelModuleExtension(com.intellij.openapi.roots.LanguageLevelModuleExtension) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with LanguageLevelModuleExtension

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();
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) LanguageLevelModuleExtension(com.intellij.openapi.roots.LanguageLevelModuleExtension) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with LanguageLevelModuleExtension

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));
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) Module(com.intellij.openapi.module.Module) LanguageLevelModuleExtension(com.intellij.openapi.roots.LanguageLevelModuleExtension) UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LanguageLevelModuleExtension (com.intellij.openapi.roots.LanguageLevelModuleExtension)5 Module (com.intellij.openapi.module.Module)4 LanguageLevel (com.intellij.pom.java.LanguageLevel)3 NotNull (org.jetbrains.annotations.NotNull)3 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 RenderingContext (com.android.tools.idea.templates.recipe.RenderingContext)1 UsageDescriptor (com.intellij.internal.statistic.beans.UsageDescriptor)1 Project (com.intellij.openapi.project.Project)1 ContentEntry (com.intellij.openapi.roots.ContentEntry)1 LanguageLevelProjectExtension (com.intellij.openapi.roots.LanguageLevelProjectExtension)1 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 DefaultLightProjectDescriptor (com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor)1 HashSet (com.intellij.util.containers.HashSet)1 File (java.io.File)1 Test (org.junit.Test)1