diff --git a/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java b/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java index da54774d9540..c88f448f3cfe 100644 --- a/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java +++ b/java/execution/openapi/src/com/intellij/execution/configurations/JavaParameters.java @@ -53,9 +53,9 @@ public class JavaParameters extends SimpleJavaParameters { public static final int CLASSES_AND_TESTS = CLASSES_ONLY | TESTS_ONLY; public static final int JDK_AND_CLASSES_AND_PROVIDED = JDK_ONLY | CLASSES_ONLY | INCLUDE_PROVIDED; - public void configureByModule(final Module module, - @MagicConstant(valuesFromClass = JavaParameters.class) final int classPathType, - final Sdk jdk) throws CantRunException { + public void configureByModule(Module module, + @MagicConstant(valuesFromClass = JavaParameters.class) int classPathType, + Sdk jdk) throws CantRunException { if ((classPathType & JDK_ONLY) != 0) { if (jdk == null) { throw CantRunException.noJdkConfigured(); @@ -74,27 +74,21 @@ public class JavaParameters extends SimpleJavaParameters { } private void configureJavaEnablePreviewProperty(OrderEnumerator orderEnumerator, Sdk jdk) { - if (getVMParametersList().hasParameter(JAVA_ENABLE_PREVIEW_PROPERTY)) { + ParametersList vmParameters = getVMParametersList(); + if (vmParameters.hasParameter(JAVA_ENABLE_PREVIEW_PROPERTY) || !JavaSdkVersionUtil.isAtLeast(jdk, JavaSdkVersion.JDK_11)) { return; } - if (jdk != null) { - JavaSdkVersion javaSdkVersion = JavaSdkVersionUtil.getJavaSdkVersion(jdk); - if (javaSdkVersion == null || !javaSdkVersion.isAtLeast(JavaSdkVersion.JDK_11)) { - return; - } - } - List modules = new ArrayList<>(); - orderEnumerator.forEachModule(modules::add); - for (Module m : modules) { - LanguageLevelModuleExtensionImpl moduleExtension = LanguageLevelModuleExtensionImpl.getInstance(m); + orderEnumerator.forEachModule(module -> { + LanguageLevelModuleExtension moduleExtension = LanguageLevelModuleExtensionImpl.getInstance(module); if (moduleExtension != null) { LanguageLevel languageLevel = moduleExtension.getLanguageLevel(); if (languageLevel != null && languageLevel.isPreview()) { - getVMParametersList().add(JAVA_ENABLE_PREVIEW_PROPERTY); - break; + vmParameters.add(JAVA_ENABLE_PREVIEW_PROPERTY); + return false; } } - } + return true; + }); } private void configureJavaLibraryPath(OrderEnumerator enumerator) { diff --git a/java/java-impl/src/com/intellij/openapi/projectRoots/ex/JavaSdkUtil.java b/java/java-impl/src/com/intellij/openapi/projectRoots/ex/JavaSdkUtil.java index a45316af373b..d20d69f940fc 100644 --- a/java/java-impl/src/com/intellij/openapi/projectRoots/ex/JavaSdkUtil.java +++ b/java/java-impl/src/com/intellij/openapi/projectRoots/ex/JavaSdkUtil.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.projectRoots.ex; import com.intellij.openapi.module.Module; @@ -45,7 +31,6 @@ public class JavaSdkUtil { } } - public static String getJunit4JarPath() { return PathUtil.getJarPathForClass(ReflectionUtil.forName("org.junit.Test")); } @@ -83,16 +68,6 @@ public class JavaSdkUtil { @Contract("null, _ -> false") public static boolean isJdkAtLeast(@Nullable Sdk jdk, @NotNull JavaSdkVersion expected) { - if (jdk != null) { - SdkTypeId type = jdk.getSdkType(); - if (type instanceof JavaSdk) { - JavaSdkVersion actual = ((JavaSdk)type).getVersion(jdk); - if (actual != null) { - return actual.isAtLeast(expected); - } - } - } - - return false; + return JavaSdkVersionUtil.isAtLeast(jdk, expected); } -} +} \ No newline at end of file diff --git a/java/openapi/src/com/intellij/openapi/projectRoots/JavaSdkVersionUtil.java b/java/openapi/src/com/intellij/openapi/projectRoots/JavaSdkVersionUtil.java index 9ee57ae62f15..761cd0146485 100644 --- a/java/openapi/src/com/intellij/openapi/projectRoots/JavaSdkVersionUtil.java +++ b/java/openapi/src/com/intellij/openapi/projectRoots/JavaSdkVersionUtil.java @@ -1,19 +1,24 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.projectRoots; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtilCore; import com.intellij.openapi.roots.ModuleRootManager; import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class JavaSdkVersionUtil { - public static boolean isAtLeast(@NotNull PsiElement element, @NotNull JavaSdkVersion minVersion) { + public static boolean isAtLeast(@NotNull PsiElement element, @NotNull JavaSdkVersion expected) { JavaSdkVersion version = getJavaSdkVersion(element); - return version == null || version.isAtLeast(minVersion); + return version == null || version.isAtLeast(expected); + } + + @Contract("null, _ -> false") + public static boolean isAtLeast(@Nullable Sdk jdk, @NotNull JavaSdkVersion expected) { + JavaSdkVersion actual = getJavaSdkVersion(jdk); + return actual != null && actual.isAtLeast(expected); } public static JavaSdkVersion getJavaSdkVersion(@NotNull PsiElement element) { @@ -27,7 +32,6 @@ public class JavaSdkVersionUtil { if (!(sdkType instanceof JavaSdk) && sdkType instanceof SdkType) { sdkType = ((SdkType)sdkType).getDependencyType(); } - if (sdkType instanceof JavaSdk) { return ((JavaSdk)sdkType).getVersion(sdk); }