Search in sources :

Example 6 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.

the class CompilerUtil method addSourceCommandLineSwitch.

public static void addSourceCommandLineSwitch(final Sdk jdk, LanguageLevel chunkLanguageLevel, @NonNls final List<String> commandLine) {
    final String versionString = jdk.getVersionString();
    if (StringUtil.isEmpty(versionString)) {
        throw new IllegalArgumentException(CompilerBundle.message("javac.error.unknown.jdk.version", jdk.getName()));
    }
    final LanguageLevel applicableLanguageLevel = getApplicableLanguageLevel(versionString, chunkLanguageLevel);
    if (applicableLanguageLevel.equals(LanguageLevel.JDK_1_8)) {
        commandLine.add("-source");
        commandLine.add("8");
    } else if (applicableLanguageLevel.equals(LanguageLevel.JDK_1_7)) {
        commandLine.add("-source");
        commandLine.add("1.7");
    } else if (applicableLanguageLevel.equals(LanguageLevel.JDK_1_6)) {
        commandLine.add("-source");
        commandLine.add("1.6");
    } else if (applicableLanguageLevel.equals(LanguageLevel.JDK_1_5)) {
        commandLine.add("-source");
        commandLine.add("1.5");
    } else if (applicableLanguageLevel.equals(LanguageLevel.JDK_1_4)) {
        commandLine.add("-source");
        commandLine.add("1.4");
    } else if (applicableLanguageLevel.equals(LanguageLevel.JDK_1_3)) {
        if (!(isOfVersion(versionString, "1.3") || isOfVersion(versionString, "1.2") || isOfVersion(versionString, "1.1"))) {
            //noinspection HardCodedStringLiteral
            commandLine.add("-source");
            commandLine.add("1.3");
        }
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel)

Example 7 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project kotlin by JetBrains.

the class AbstractJavaAgainstKotlinCheckerTest method createMainModule.

@Override
protected Module createMainModule() throws IOException {
    Module module = super.createMainModule();
    String configFileText = getConfigFileText();
    if (configFileText == null) {
        return module;
    }
    if (InTextDirectivesUtils.isDirectiveDefined(configFileText, "// WITH_RUNTIME")) {
        ConfigLibraryUtil.configureKotlinRuntime(module);
    }
    List<String> languageLevelLines = InTextDirectivesUtils.findLinesWithPrefixesRemoved(configFileText, "// LANGUAGE_LEVEL");
    if (languageLevelLines.size() > 1) {
        throw new AssertionError("Language level specified multiple times: " + languageLevelLines);
    }
    if (languageLevelLines.size() == 1) {
        LanguageLevel level = LanguageLevel.parse(languageLevelLines.iterator().next());
        if (level != null) {
            IdeaTestUtil.setModuleLanguageLevel(module, level);
        }
    }
    return module;
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) Module(com.intellij.openapi.module.Module)

Example 8 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel 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 9 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel 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 10 with LanguageLevel

use of com.intellij.pom.java.LanguageLevel in project intellij-community by JetBrains.

the class CreateSwitchTest method doTestString.

private void doTestString() {
    final LanguageLevelProjectExtension languageLevelProjectExtension = LanguageLevelProjectExtension.getInstance(getProject());
    final LanguageLevel oldLanguageLevel = languageLevelProjectExtension.getLanguageLevel();
    languageLevelProjectExtension.setLanguageLevel(LanguageLevel.JDK_1_7);
    try {
        doTest();
    } finally {
        languageLevelProjectExtension.setLanguageLevel(oldLanguageLevel);
    }
}
Also used : LanguageLevel(com.intellij.pom.java.LanguageLevel) LanguageLevelProjectExtension(com.intellij.openapi.roots.LanguageLevelProjectExtension)

Aggregations

LanguageLevel (com.intellij.pom.java.LanguageLevel)98 LanguageLevelProjectExtension (com.intellij.openapi.roots.LanguageLevelProjectExtension)21 Nullable (org.jetbrains.annotations.Nullable)14 Module (com.intellij.openapi.module.Module)13 NotNull (org.jetbrains.annotations.NotNull)9 Sdk (com.intellij.openapi.projectRoots.Sdk)8 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)7 Project (com.intellij.openapi.project.Project)6 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 File (java.io.File)6 IOException (java.io.IOException)5 IncorrectOperationException (com.intellij.util.IncorrectOperationException)4 LocalInspectionToolWrapper (com.intellij.codeInspection.ex.LocalInspectionToolWrapper)3 Lexer (com.intellij.lexer.Lexer)3 LanguageLevelModuleExtension (com.intellij.openapi.roots.LanguageLevelModuleExtension)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 JavaProjectData (com.intellij.externalSystem.JavaProjectData)2 DisposeAwareProjectChange (com.intellij.openapi.externalSystem.util.DisposeAwareProjectChange)2 ConfigurationException (com.intellij.openapi.options.ConfigurationException)2