RFR: JDK-8285932 Implementation of JEP-430 String Templates (Preview) [v7]

Jim Laskey jlaskey at openjdk.org
Wed Nov 2 18:55:41 UTC 2022


On Tue, 1 Nov 2022 17:33:30 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> Jim Laskey has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Add @SafeVarargs declarations
>
> src/java.base/share/classes/java/util/FormatProcessor.java line 118:
> 
>> 116: 
>> 117:     // %[argument_index$][flags][width][.precision][t]conversion
>> 118:     private static final String formatSpecifier
> 
> Should this be all upper case?

Changing

> src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavaTokenizer.java line 355:
> 
>> 353:         // If first embedded expression.
>> 354:         if (!isStringTemplate) {
>> 355:             checkSourceLevel(pos, Feature.STRING_TEMPLATES);
> 
> If we check source level inside the `if`, we would only issue a preview error/warning once, which seems to be against JEP 12?

The error is collated to the opening quote so one is sufficient. Embedded Expressions are not the feature. String templates is. The parser bails at that point.


>> cat Main.java
public class Main {
    public static void main(String... args) {
        int x = 10, y = 20;
        String s = STR."Adding {x} and {y} equals {x + y}";
        String t = STR."Adding {x} and {y} equals {x + y}";
    }
}
>> javac Main.java
Main.java:4: error: string templates are a preview feature and are disabled by default.
        String s = STR."Adding {x} and {y} equals {x + y}";
                       ^
  (use --enable-preview to enable string templates)
1 error

-------------

PR: https://git.openjdk.org/jdk/pull/10889


More information about the compiler-dev mailing list