mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
[java] IDEA-352189 Support JEP 455. Implement increase language level check and fix
GitOrigin-RevId: d69e01d624fcfc4ddb3af7292693ed056efc88a4
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ab46a9f54a
commit
ff1ce5a0bd
@@ -189,6 +189,9 @@ public class PatternsInSwitchBlockHighlightingModel extends SwitchBlockHighlight
|
||||
info.registerFix(fix, null, null, null, null);
|
||||
}
|
||||
}
|
||||
if (patternType instanceof PsiPrimitiveType) {
|
||||
HighlightUtil.registerIncreaseLanguageLevelFixes(mySelector, JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, info);
|
||||
}
|
||||
errorSink.accept(info);
|
||||
return true;
|
||||
}
|
||||
@@ -206,6 +209,9 @@ public class PatternsInSwitchBlockHighlightingModel extends SwitchBlockHighlight
|
||||
(!IncompleteModelUtil.isPotentiallyConvertible(mySelectorType, patternType, label))) {
|
||||
HighlightInfo.Builder error =
|
||||
HighlightUtil.createIncompatibleTypeHighlightInfo(mySelectorType, patternType, elementToReport.getTextRange(), 0);
|
||||
if (mySelectorType instanceof PsiPrimitiveType) {
|
||||
HighlightUtil.registerIncreaseLanguageLevelFixes(mySelector, JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS, error);
|
||||
}
|
||||
errorSink.accept(error);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class X {
|
||||
record A(long l){}
|
||||
void test(Object obj) {
|
||||
if(obj instanceof A(i<caret>nt i)) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class X {
|
||||
void test(int i) {
|
||||
if(i instanceo<caret>f short s){}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class X {
|
||||
void test(int i) {
|
||||
switch (i) {
|
||||
case lon<caret>g l-> System.out.println("1");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class X {
|
||||
void test(long i) {
|
||||
switch(i<caret>){
|
||||
default -> System.out.println("1");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
class X {
|
||||
void test(int i) {
|
||||
switch (i) {
|
||||
case Int<caret>eger l-> System.out.println("1");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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-2024 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;
|
||||
@@ -7,6 +7,7 @@ import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.impl.preview.IntentionPreviewPopupUpdateProcessor;
|
||||
import com.intellij.java.JavaBundle;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
@@ -25,7 +26,7 @@ public class IncreaseLanguageLevelFixTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk(JavaVersion.compose(17));
|
||||
return IdeaTestUtil.getMockJdk(JavaVersion.compose(23));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,6 +58,26 @@ public class IncreaseLanguageLevelFixTest extends LightDaemonAnalyzerTestCase {
|
||||
doTest(LanguageLevel.JDK_17);
|
||||
}
|
||||
|
||||
public void testInstanceofWithPrimitives() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, () -> doTest(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.getMinimumLevel()));
|
||||
}
|
||||
|
||||
public void testSwitchWithPrimitiveSelector() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, () -> doTest(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.getMinimumLevel()));
|
||||
}
|
||||
|
||||
public void testDeconstructionWithPrimitives() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, () -> doTest(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.getMinimumLevel()));
|
||||
}
|
||||
|
||||
public void testSwitchWithPrimitivePattern() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, () -> doTest(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.getMinimumLevel()));
|
||||
}
|
||||
|
||||
public void testSwitchWithPrimitiveSelectorAndPattern() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_21, () -> doTest(JavaFeature.PRIMITIVE_TYPES_IN_PATTERNS.getMinimumLevel()));
|
||||
}
|
||||
|
||||
private void doTest(LanguageLevel level) {
|
||||
configureByFile(getTestName(false) + ".java");
|
||||
doHighlighting();
|
||||
|
||||
Reference in New Issue
Block a user