diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LanguageLevelCombo.kt b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LanguageLevelCombo.kt index 7ffb8683bcf3..ed0c374ade3a 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LanguageLevelCombo.kt +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/LanguageLevelCombo.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.roots.ui.configuration import com.intellij.ide.JavaUiBundle @@ -29,7 +29,7 @@ abstract class LanguageLevelCombo @JvmOverloads constructor( val items = mutableListOf() items.add(defaultItem ?: "") - val highestPreviewLevel = LanguageLevel.HIGHEST.previewLevel + val highestPreviewLevel = LanguageLevel.HIGHEST.getPreviewLevel() val highestWithPreview = highestPreviewLevel ?: LanguageLevel.HIGHEST fun MutableList.filterAndAdd(levels: Collection) = levels.filter(levelFilter).also { addAll(it) } diff --git a/java/java-syntax/src/com/intellij/pom/java/LanguageLevel.kt b/java/java-syntax/src/com/intellij/pom/java/LanguageLevel.kt index bb359eba0802..114077be90a3 100644 --- a/java/java-syntax/src/com/intellij/pom/java/LanguageLevel.kt +++ b/java/java-syntax/src/com/intellij/pom/java/LanguageLevel.kt @@ -106,25 +106,23 @@ enum class LanguageLevel { /** * @return corresponding preview level, or `null` if level has no paired preview level */ - val previewLevel: LanguageLevel? - get() { - if (this.isPreview) return this - try { - return valueOf(name + "_PREVIEW") - } - catch (_: IllegalArgumentException) { - return null - } + fun getPreviewLevel(): LanguageLevel? { + if (isPreview) return this + try { + return valueOf(name + "_PREVIEW") } + catch (_: IllegalArgumentException) { + return null + } + } /** * @return corresponding non-preview level; this if this level is non-preview already */ - val nonPreviewLevel: LanguageLevel - get() { - if (!this.isPreview) return this - return requireNotNull(ourStandardVersions[myVersion.feature]) - } + fun getNonPreviewLevel(): LanguageLevel { + if (!isPreview) return this + return requireNotNull(ourStandardVersions[myVersion.feature]) + } val presentableText: @Nls String get() = myPresentableText() diff --git a/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/JavaApiUsageInspection.kt b/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/JavaApiUsageInspection.kt index 13f00cfce141..94276dd3d3e9 100644 --- a/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/JavaApiUsageInspection.kt +++ b/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/JavaApiUsageInspection.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.codeInspection import com.intellij.analysis.JvmAnalysisBundle @@ -170,7 +170,7 @@ class JavaApiUsageInspection : AbstractBaseUastLocalInspectionTool() { if (module != null) { languageLevel = getEffectiveLanguageLevel(module) if (languageLevel.isUnsupported) { - languageLevel = languageLevel.nonPreviewLevel + languageLevel = languageLevel.getNonPreviewLevel() } } else if (sourcePsi.containingFile.virtualFile is LightVirtualFile) { diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenImportUtil.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenImportUtil.kt index def4d9d2cd7f..928063a36221 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenImportUtil.kt +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenImportUtil.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.idea.maven.importing import com.intellij.build.events.MessageEvent @@ -310,14 +310,14 @@ object MavenImportUtil { private fun adjustPreviewLanguageLevel(mavenProject: MavenProject, level: LanguageLevel): LanguageLevel { val enablePreviewProperty = mavenProject.properties.getProperty("maven.compiler.enablePreview") if (enablePreviewProperty.toBoolean()) { - return level.previewLevel ?: level + return level.getPreviewLevel() ?: level } val compilerConfiguration = mavenProject.getPluginConfiguration(COMPILER_PLUGIN_GROUP_ID, COMPILER_PLUGIN_ARTIFACT_ID) if (compilerConfiguration != null) { val enablePreviewParameter = compilerConfiguration.getChildTextTrim("enablePreview") if (enablePreviewParameter.toBoolean()) { - return level.previewLevel ?: level + return level.getPreviewLevel() ?: level } val compilerArgs = compilerConfiguration.getChild("compilerArgs") @@ -326,7 +326,7 @@ object MavenImportUtil { compilerArgs.getChildren("arg").any { isPreviewText(it) } || compilerArgs.getChildren("compilerArg").any{ isPreviewText(it) } ) { - return level.previewLevel ?: level + return level.getPreviewLevel() ?: level } } }