<i18n dev> RFR: JDK-8285932 Implementation of JEP-430 String Templates (Preview) [v3]

Rémi Forax forax at openjdk.org
Fri Oct 28 19:11:30 UTC 2022

On Fri, 28 Oct 2022 17:57:30 GMT, Jim Laskey <jlaskey at openjdk.org> wrote:

>> Enhance the Java programming language with string templates, which are similar to string literals but contain embedded expressions. A string template is interpreted at run time by replacing each expression with the result of evaluating that expression, possibly after further validation and transformation. This is a [preview language feature and API](http://openjdk.java.net/jeps/12).
> Jim Laskey has updated the pull request incrementally with one additional commit since the last revision:
>   Update TemplateRuntime::combine

src/java.base/share/classes/java/lang/template/StringProcessor.java line 45:

> 43: @PreviewFeature(feature=PreviewFeature.Feature.STRING_TEMPLATES)
> 44: @FunctionalInterface
> 45: public interface StringProcessor extends TemplateProcessor<String> {}

The name should be `StringTemplateProcessor`.
And i'm not sure it's useful to have a specialized version for String, TemplateProcessor<String> is not an issue given that most of the time people will implement it, so writing `implements StringTemplateProcessor` instead of `implements TemplateProcessor<String>` does not seem to offer enough bangs for bucks.

src/java.base/share/classes/java/lang/template/StringTemplate.java line 29:

> 27: 
> 28: import java.lang.invoke.MethodHandle;
> 29: import java.util.*;

Please fix.

src/java.base/share/classes/java/lang/template/StringTemplate.java line 149:

> 147:      * {@return the interpolation of the StringTemplate}
> 148:      */
> 149:     default String interpolate() {

I wonder if all the default methods should not be better as static methods given that they are not the important part of the API but more side information that may be handy

src/java.base/share/classes/java/lang/template/StringTemplate.java line 175:

> 173:      * method {@code processor.process(this)}.
> 174:      */
> 175:     default <R, E extends Throwable> R process(ValidatingProcessor<R, E> processor) throws E {

signature should be `ValidatingProcessor<? extends R, ? extends E> processor`

src/java.base/share/classes/java/lang/template/StringTemplate.java line 204:

> 202:      * embedded expressions fields, otherwise this method returns getters for the values list.
> 203:      */
> 204:     default public List<MethodHandle> valueGetters() {

I think i prefer the term accessors instead of getters


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

More information about the i18n-dev mailing list