Search in sources :

Example 11 with LanguageLevelProjectExtension

use of com.intellij.openapi.roots.LanguageLevelProjectExtension in project intellij-community by JetBrains.

the class TypeCookTest method testConvertToDiamond.

public void testConvertToDiamond() throws Exception {
    final LanguageLevelProjectExtension levelProjectExtension = LanguageLevelProjectExtension.getInstance(getProject());
    final LanguageLevel oldLevel = levelProjectExtension.getLanguageLevel();
    try {
        levelProjectExtension.setLanguageLevel(LanguageLevel.JDK_1_8);
        start();
    } finally {
        levelProjectExtension.setLanguageLevel(oldLevel);
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 12 with LanguageLevelProjectExtension

use of com.intellij.openapi.roots.LanguageLevelProjectExtension in project intellij-community by JetBrains.

the class KeywordCompletionTest method testPrivateInJava9Interface.

public void testPrivateInJava9Interface() throws Exception {
    LanguageLevelProjectExtension levelProjectExtension = LanguageLevelProjectExtension.getInstance(getProject());
    LanguageLevel oldLevel = levelProjectExtension.getLanguageLevel();
    try {
        levelProjectExtension.setLanguageLevel(LanguageLevel.JDK_1_9);
        doTest(false);
    } finally {
        levelProjectExtension.setLanguageLevel(oldLevel);
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 13 with LanguageLevelProjectExtension

use of com.intellij.openapi.roots.LanguageLevelProjectExtension in project intellij-community by JetBrains.

the class NewProjectUtil method applyJdkToProject.

public static void applyJdkToProject(@NotNull Project project, @NotNull Sdk jdk) {
    ProjectRootManagerEx rootManager = ProjectRootManagerEx.getInstanceEx(project);
    rootManager.setProjectSdk(jdk);
    JavaSdkVersion version = JavaSdk.getInstance().getVersion(jdk);
    if (version != null) {
        LanguageLevel maxLevel = version.getMaxLanguageLevel();
        LanguageLevelProjectExtension extension = LanguageLevelProjectExtension.getInstance(ProjectManager.getInstance().getDefaultProject());
        LanguageLevelProjectExtension ext = LanguageLevelProjectExtension.getInstance(project);
        if (extension.isDefault() || maxLevel.compareTo(ext.getLanguageLevel()) < 0) {
            ext.setLanguageLevel(maxLevel);
        }
    }
}
Also used : ProjectRootManagerEx(com.intellij.openapi.roots.ex.ProjectRootManagerEx) JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) LanguageLevel(com.intellij.pom.java.LanguageLevel) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 14 with LanguageLevelProjectExtension

use of com.intellij.openapi.roots.LanguageLevelProjectExtension in project intellij-community by JetBrains.

the class JavaProjectDataService method updateSdk.

private static void updateSdk(@NotNull final Project project, @NotNull final JavaSdkVersion version) {
    final Sdk sdk = findJdk(version);
    if (sdk == null)
        return;
    ExternalSystemApiUtil.executeProjectChangeAction(new DisposeAwareProjectChange(project) {

        @Override
        public void execute() {
            ProjectRootManager.getInstance(project).setProjectSdk(sdk);
            LanguageLevel level = version.getMaxLanguageLevel();
            LanguageLevelProjectExtension languageLevelExtension = LanguageLevelProjectExtension.getInstance(project);
            if (level.compareTo(languageLevelExtension.getLanguageLevel()) < 0) {
                languageLevelExtension.setLanguageLevel(level);
            }
        }
    });
}
Also used : DisposeAwareProjectChange(com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange) LanguageLevel(com.intellij.pom.java.LanguageLevel) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Example 15 with LanguageLevelProjectExtension

use of com.intellij.openapi.roots.LanguageLevelProjectExtension in project intellij-community by JetBrains.

the class JavaProjectDataService method setLanguageLevel.

@SuppressWarnings("MethodMayBeStatic")
public void setLanguageLevel(@NotNull final LanguageLevel languageLevel, @NotNull Project project) {
    final LanguageLevelProjectExtension languageLevelExtension = LanguageLevelProjectExtension.getInstance(project);
    if (languageLevelExtension.getLanguageLevel().isAtLeast(languageLevel)) {
        return;
    }
    ExternalSystemApiUtil.executeProjectChangeAction(new DisposeAwareProjectChange(project) {

        @Override
        public void execute() {
            languageLevelExtension.setLanguageLevel(languageLevel);
        }
    });
}
Also used : DisposeAwareProjectChange(com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Aggregations

LanguageLevelProjectExtension (com.intellij.openapi.roots.LanguageLevelProjectExtension)31 LanguageLevel (com.intellij.pom.java.LanguageLevel)23 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)3 DisposeAwareProjectChange (com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange)3 ProjectRootManagerEx (com.intellij.openapi.roots.ex.ProjectRootManagerEx)3 JavaProjectData (com.intellij.externalSystem.JavaProjectData)2 Module (com.intellij.openapi.module.Module)2 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 ProjectEx (com.intellij.openapi.project.ex.ProjectEx)1 JavaSdkVersion (com.intellij.openapi.projectRoots.JavaSdkVersion)1 CompilerProjectExtension (com.intellij.openapi.roots.CompilerProjectExtension)1 LanguageLevelModuleExtension (com.intellij.openapi.roots.LanguageLevelModuleExtension)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 JavaModuleFixtureBuilder (com.intellij.testFramework.builders.JavaModuleFixtureBuilder)1 IdeaProjectTestFixture (com.intellij.testFramework.fixtures.IdeaProjectTestFixture)1 File (java.io.File)1 IOException (java.io.IOException)1