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