[java] IDEA-390261 Support JEP 532: Primitive Types in Patterns, instanceof, and switch (Fifth Preview)

(cherry picked from commit d6c0f396582c7a1c1f466887a0358793851d58bc)

GitOrigin-RevId: 447bb655fd409d5838f96896a4dec3a5b0703d1f
This commit is contained in:
Mikhail Pyltsin
2026-07-23 10:59:41 +00:00
committed by intellij-monorepo-bot
parent 71b5d5a192
commit bbdd2f0f1a
5 changed files with 52 additions and 7 deletions
@@ -1,14 +1,14 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.pom.java
import com.intellij.java.syntax.JavaSyntaxBundle
import com.intellij.java.syntax.JavaSyntaxBundle.message
import com.intellij.util.ThreadLocalKmp
import org.jetbrains.annotations.ApiStatus
import org.jetbrains.annotations.Contract
import org.jetbrains.annotations.Nls
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.PropertyKey
import com.intellij.util.ThreadLocalKmp
import org.jetbrains.annotations.ApiStatus
import kotlin.jvm.JvmStatic
/**
@@ -268,7 +268,7 @@ enum class JavaFeature {
override fun isSufficient(useSiteLevel: LanguageLevel): Boolean {
return super.isSufficient(useSiteLevel) ||
useSiteLevel.isAtLeast(LanguageLevel.JDK_25) ||
LanguageLevel.JDK_24_PREVIEW == useSiteLevel; //jep 494
LanguageLevel.JDK_24_PREVIEW == useSiteLevel //jep 494
}
override val standardLevel: LanguageLevel = LanguageLevel.JDK_25
@@ -306,6 +306,7 @@ enum class JavaFeature {
/**
* JEP 530
* JEP 532 (without any changes)
* @see PRIMITIVE_TYPES_IN_PATTERNS
*/
PATTERNS_WITH_TIGHTENED_DOMINANCE(LanguageLevel.JDK_26_PREVIEW, "feature.patterns.with.tightened.dominance"),
@@ -0,0 +1,28 @@
package dfa;
public class MixFloatingPointWithIntegralLiterals {
private static float aaa = 2;
static void main(String[] args) {
switch (1.0) {
case <error descr="Incompatible types. Found: 'int', required: 'double'">1</error> -> System.out.println(1);
default -> System.out.println(2);
}
switch (1.0) {
case 1.0 -> System.out.println(1);
default -> System.out.println(2);
}
switch (1.0) {
case <error descr="Incompatible types. Found: 'char', required: 'double'">'c'</error> -> System.out.println(1);
default -> System.out.println(2);
}
switch (1.0f) {
case <error descr="Incompatible types. Found: 'int', required: 'float'">1</error> -> System.out.println(1);
default -> System.out.println(2);
}
switch (1.0f) {
case <error descr="Constant expression required">aaa</error> -> System.out.println(1);
default -> System.out.println(2);
}
}
}
@@ -0,0 +1,15 @@
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.codeInsight.daemon;
import com.intellij.testFramework.LightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
//JEP 532 for java 27 is the same as JEP 520 for java 26 (without any changes)
public class LightPrimitivePatternsHighlightingWithTightenedDominance27Test extends LightPrimitivePatternsHighlightingWithTightenedDominanceTest {
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JAVA_27;
}
}
@@ -1,9 +1,7 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2026 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.codeInsight.daemon;
import com.intellij.JavaTestUtil;
import com.intellij.pom.java.JavaFeature;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
@@ -68,4 +66,6 @@ public class LightPrimitivePatternsHighlightingWithTightenedDominanceTest extend
public void testSwitchPrimitivePatternDominatedTightened() { doTest(); }
public void testSwitchPrimitivePatternListTightened() { doTest(); }
public void testMixFloatingPointWithIntegralLiterals() { doTest(); }
}
@@ -147,6 +147,7 @@ public abstract class LightJavaCodeInsightFixtureTestCase extends UsefulTestCase
public static final @NotNull LightProjectDescriptor JAVA_24 = new ProjectDescriptor(LanguageLevel.JDK_24);
public static final @NotNull LightProjectDescriptor JAVA_25 = new ProjectDescriptor(LanguageLevel.JDK_25);
public static final @NotNull LightProjectDescriptor JAVA_26 = new ProjectDescriptor(LanguageLevel.JDK_26_PREVIEW);
public static final @NotNull LightProjectDescriptor JAVA_27 = new ProjectDescriptor(LanguageLevel.JDK_27_PREVIEW);
public static final @NotNull LightProjectDescriptor JAVA_X = new ProjectDescriptor(LanguageLevel.JDK_X);
/**