mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-06 05:10:22 +07:00
[java] disable String Templates for Java 23 (IDEA-355055)
GitOrigin-RevId: cc2b3dfffd4fe0ba34a91b0d9f342e32304bfd2c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c88d2ccbcc
commit
a01eb76a76
@@ -78,7 +78,17 @@ public enum JavaFeature {
|
||||
LanguageLevel.JDK_19_PREVIEW, LanguageLevel.JDK_20_PREVIEW),
|
||||
ENUM_QUALIFIED_NAME_IN_SWITCH(LanguageLevel.JDK_21, "feature.enum.qualified.name.in.switch"),
|
||||
SEQUENCED_COLLECTIONS(LanguageLevel.JDK_21, "feature.sequenced.collections"),
|
||||
STRING_TEMPLATES(LanguageLevel.JDK_21_PREVIEW, "feature.string.templates"),
|
||||
STRING_TEMPLATES(LanguageLevel.JDK_21_PREVIEW, "feature.string.templates") {
|
||||
@Override
|
||||
public boolean isSufficient(@NotNull LanguageLevel useSiteLevel) {
|
||||
return super.isSufficient(useSiteLevel) && !useSiteLevel.isAtLeast(LanguageLevel.JDK_23);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLimited() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
UNNAMED_PATTERNS_AND_VARIABLES(LanguageLevel.JDK_22, "feature.unnamed.vars") {
|
||||
@Override
|
||||
public boolean isSufficient(@NotNull LanguageLevel useSiteLevel) {
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
import java.io.*;
|
||||
|
||||
class X {
|
||||
|
||||
void processorMissing() {
|
||||
System.out.println(<error descr="String templates are not supported at language level '23'">"""
|
||||
\{1}
|
||||
"""</error>);
|
||||
<error descr="String templates are not supported at language level '23'">"\{}"</error>;
|
||||
System.out.println(<error descr="Cannot resolve symbol 'NOPE'">NOPE</error>.<error descr="String templates are not supported at language level '23'">"\{false}"</error>);
|
||||
System.out.println(<error descr="Cannot resolve symbol 'RAW'">RAW</error>.<error descr="String templates are not supported at language level '23'">"\{false}"</error>);
|
||||
}
|
||||
|
||||
void correct(int i) {
|
||||
System.out.println(<error descr="Cannot resolve symbol 'STR'">STR</error>.<error descr="String templates are not supported at language level '23'">"the value is \{i}"</error>);
|
||||
String s = <error descr="Cannot resolve symbol 'STR'">STR</error>."";
|
||||
StringTemplate st = <error descr="String templates are not supported at language level '23'">StringTemplate.RAW."""
|
||||
"""</error>;
|
||||
}
|
||||
|
||||
void wrongType(String foo) {
|
||||
String s = StringTemplate.RAW.<error descr="String templates are not supported at language level '23'">"""
|
||||
this: \{foo}
|
||||
"""</error>;
|
||||
|
||||
var x = (java.io.Serializable & StringTemplate.Processor<String, RuntimeException>)null;
|
||||
java.util.ArrayList v = <error descr="String templates are not supported at language level '23'">x."asdf"</error>;
|
||||
String t = <error descr="String templates are not supported at language level '23'">x."reticulation"</error>;
|
||||
}
|
||||
|
||||
String unresolvedValues() {
|
||||
return <error descr="Cannot resolve symbol 'STR'">STR</error>."\{<error descr="Cannot resolve symbol 'logic'">logic</error>} \{<error descr="Cannot resolve symbol 'proportion'">proportion</error>}";
|
||||
}
|
||||
|
||||
interface MyProcessor extends StringTemplate.Processor {}
|
||||
|
||||
String raw(StringTemplate.Processor processor, MyProcessor myProcessor) {
|
||||
System.out.println(<error descr="String templates are not supported at language level '23'">myProcessor.""</error>);
|
||||
return processor.<error descr="String templates are not supported at language level '23'">"\{}\{}\{}\{}\{}\{}"</error>;
|
||||
var z = (java.io.Serializable & StringTemplate.Processor)myProcessor;
|
||||
System.out.println(<error descr="String templates are not supported at language level '23'">z.""</error>);
|
||||
}
|
||||
|
||||
void nested() {
|
||||
System.out.println(<error descr="Cannot resolve symbol 'STR'">STR</error>."\{<error descr="Cannot resolve symbol 'STR'">STR</error>."\{<error descr="Cannot resolve symbol 'STR'">STR</error>."\{<error descr="Cannot resolve symbol 'STR'">STR</error>."\{<error descr="Cannot resolve symbol 'STR'">STR</error>."\{<error descr="Cannot resolve symbol 'STR'">STR</error>."\{<error descr="Cannot resolve symbol 'STR'">STR</error>.""}"}"}"}"}"}");
|
||||
}
|
||||
|
||||
String badEscape() {
|
||||
System.out.println(<error descr="Cannot resolve symbol 'STR'">STR</error>."b<error descr="Illegal escape character in string literal">\a</error>d \{} esc<error descr="Illegal escape character in string literal">\a</error>pe 1");
|
||||
System.out.println(<error descr="Cannot resolve symbol 'STR'">STR</error>. """
|
||||
b<error descr="Illegal escape character in string literal">\a</error>d \{} esc<error descr="Illegal escape character in string literal">\a</error>pe 2
|
||||
""");
|
||||
System.out.println(<error descr="Cannot resolve symbol 'STR'">STR</error>."\{<error descr="Line end not allowed in string literals">}unclosed);</error>
|
||||
return <error descr="Cannot resolve symbol 'STR'">STR</error>."\{} <error descr="Illegal Unicode escape sequence">\u</error>X";
|
||||
}
|
||||
|
||||
static class Covariant implements StringTemplate.Processor<Object, RuntimeException> {
|
||||
@Override
|
||||
public Integer process(StringTemplate stringTemplate) {
|
||||
return 123;
|
||||
}
|
||||
}
|
||||
|
||||
public static void testCovariant() {
|
||||
Covariant proc = new Covariant();
|
||||
// In Java 22, covariant processors are supported
|
||||
Integer i = <error descr="String templates are not supported at language level '23'">proc."hello"</error>;
|
||||
}
|
||||
|
||||
static class CovariantException implements StringTemplate.Processor<Integer, Exception> {
|
||||
@Override
|
||||
public Integer process(StringTemplate stringTemplate) throws Ex {
|
||||
return 123;
|
||||
}
|
||||
}
|
||||
|
||||
class Ex extends Exception {}
|
||||
class Ex2 extends Exception {}
|
||||
|
||||
public static void testHandle(StringTemplate.Processor<Integer, Ex> proc) {
|
||||
try {
|
||||
Object x = <error descr="String templates are not supported at language level '23'">proc."hello"</error>;
|
||||
}
|
||||
catch (Ex ex) {}
|
||||
}
|
||||
|
||||
public static void testExceptionInFragments(StringTemplate.Processor<Integer, Ex> proc,
|
||||
StringTemplate.Processor<Integer, Ex2> proc2) {
|
||||
try {
|
||||
proc."hell\{<error descr="String templates are not supported at language level '23'">proc2."xyz"</error>}o";
|
||||
}
|
||||
catch (Ex ex) {}
|
||||
}
|
||||
|
||||
public static void testCovariantException() {
|
||||
CovariantException proc = new CovariantException();
|
||||
// As of Java 21, covariant processors are not supported
|
||||
Integer i = <error descr="String templates are not supported at language level '23'">proc."hello"</error>;
|
||||
|
||||
try {
|
||||
Integer i2 = <error descr="String templates are not supported at language level '23'">proc."hello"</error>;
|
||||
}
|
||||
catch (Ex ex) {}
|
||||
}
|
||||
|
||||
public static void testCapturedWilcard(StringTemplate.Processor<?, ?> str) {
|
||||
Object s = <error descr="String templates are not supported at language level '23'">str.""</error>;
|
||||
}
|
||||
|
||||
void testCapturedWildcard2() {
|
||||
StringTemplate.Processor<StringTemplate.Processor<?, ? extends Exception>, RuntimeException> processor = null;
|
||||
Object o = <error descr="String templates are not supported at language level '23'">processor."""
|
||||
"""</error>."""
|
||||
""";
|
||||
}
|
||||
|
||||
public static void noNewlineAfterTextBlockOpeningQuotes() {
|
||||
System.out.println(<error descr="Cannot resolve symbol 'STR'">STR</error>.<error descr="Illegal text block start: missing new line after opening quotes">"""</error>\{}""");
|
||||
}
|
||||
|
||||
public static void voidExpression() {
|
||||
String a = <error descr="Cannot resolve symbol 'STR'">STR</error>.<error descr="String templates are not supported at language level '23'">"\{voidExpression()}"</error>;
|
||||
System.out.println(a);
|
||||
}
|
||||
|
||||
interface AnyProcessor extends StringTemplate.Processor<Object, Throwable> {}
|
||||
|
||||
interface FooProcessor extends AnyProcessor {
|
||||
@Override
|
||||
Object process(StringTemplate stringTemplate) throws Ex, IOException;
|
||||
}
|
||||
|
||||
interface BarProcessor extends AnyProcessor {
|
||||
@Override
|
||||
Object process(StringTemplate stringTemplate) throws Ex2, EOFException, FileNotFoundException;
|
||||
}
|
||||
|
||||
interface FooBarProcessor extends FooProcessor, BarProcessor {}
|
||||
|
||||
static void test(FooBarProcessor fooBarProcessor) {
|
||||
System.out.println(<error descr="String templates are not supported at language level '23'">fooBarProcessor.""</error>);
|
||||
}
|
||||
|
||||
static class IntegerProcessor implements StringTemplate.Processor<Object, RuntimeException> {
|
||||
@Override
|
||||
public Integer process(StringTemplate template) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void myTest() {
|
||||
Integer x = <error descr="String templates are not supported at language level '23'">new IntegerProcessor()."hello"</error>;
|
||||
System.out.println(x);
|
||||
}
|
||||
}
|
||||
@@ -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-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;
|
||||
@@ -23,6 +23,7 @@ public class LightStringTemplatesHighlightingTest extends LightJavaCodeInsightFi
|
||||
public void testStringTemplates() { doTest(); }
|
||||
|
||||
public void testStringTemplatesJava22() { IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_22_PREVIEW, () -> doTest()); }
|
||||
public void testStringTemplatesJava23() { IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_23_PREVIEW, () -> doTest()); }
|
||||
|
||||
private void doTest() {
|
||||
myFixture.configureByFile(getTestName(false) + ".java");
|
||||
|
||||
Reference in New Issue
Block a user