RFR: 8344942: Template-Based Testing Framework [v61]

Emanuel Peter epeter at openjdk.org
Sun Jun 1 05:37:08 UTC 2025


On Fri, 30 May 2025 07:54:53 GMT, Christian Hagedorn <chagedorn at openjdk.org> wrote:

>> Emanuel Peter has updated the pull request incrementally with two additional commits since the last revision:
>> 
>>  - Merge branch 'JDK-8344942-TemplateFramework-v3' of https://github.com/eme64/jdk into JDK-8344942-TemplateFramework-v3
>>  - move verification
>
> test/hotspot/jtreg/testlibrary_tests/template_framework/examples/TestTutorial.java line 151:
> 
>> 149:             "System.out.println(", arg, ");\n",  // capture arg via lambda argument
>> 150:             "System.out.println(#arg);\n",       // capture arg via hashtag replacement
>> 151:             "System.out.println(#{arg});\n",     // capture arg via hashtag replacement with brackets
> 
> It's not clear here why one should use brackets. If there is an argument for those further down, then you can cross reference. Otherwise, it might need some explanation here.

I rewrote the whole section a little:

   155             // It would have been optimal to use Java String Templates to format                                                                                                                                                                                                                                                                                                                                                     
   156             // argument values into Strings. However, since these are not (yet)                                                                                                                                                                                                                                                                                                                                                      
   157             // available, the Template Framework provides two alternative ways of                                                                                                                                                                                                                                                                                                                                                    
   158             // formatting Strings:                                                                                                                                                                                                                                                                                                                                                                                                   
   159             // 1) By appending to the comma-separated list of Tokens passed to body().                                                                                                                                                                                                                                                                                                                                               
   160             //    Appending as a Token works whenever one has a reference to the Object                                                                                                                                                                                                                                                                                                                                              
   161             //    in Java code. But often, this is rather cumbersome and looks awkward,                                                                                                                                                                                                                                                                                                                                              
   162             //    given all the additional quotes and commands required. Hence, it                                                                                                                                                                                                                                                                                                                                                   
   163             //    is encouraged to only use this method when necessary.                                                                                                                                                                                                                                                                                                                                                              
   164             // 2) By hashtag replacements inside a single string. One can either                                                                                                                                                                                                                                                                                                                                                     
   165             //    use "#arg" directly, or use brackets "#{arg}". When possible, one                                                                                                                                                                                                                                                                                                                                                  
   166             //    should prefer avoiding the brackets, as they create additional                                                                                                                                                                                                                                                                                                                                                     
   167             //    noise. However, there are cases where they are useful, for                                                                                                                                                                                                                                                                                                                                                         
   168             //    example "#TYPE_CON" would be parsed as a hashtag replacement                                                                                                                                                                                                                                                                                                                                                       
   169             //    for the hashtag name "TYPE_CON", whereas "#{TYPE}_CON" is                                                                                                                                                                                                                                                                                                                                                          
   170             //    parsed as hashtag name "TYPE", followed by literal string "_CON".                                                                                                                                                                                                                                                                                                                                                  
   171             //    See also: generateWithHashtagAndDollarReplacements2                                                                                                                                                                                                                                                                                                                                                                
   172             //    There are two ways to define the value of a hashtag replacement:                                                                                                                                                                                                                                                                                                                                                   
   173             //    a) Capturing Template arguments as Strings.                                                                                                                                                                                                                                                                                                                                                                        
   174             //    b) Using a "let" definition (see examples further down).                                                                                                                                                                                                                                                                                                                                                           
   175             // Which one should be preferred is a code style question. Generally, we                                                                                                                                                                                                                                                                                                                                                 
   176             // prefer the use of hashtag replacements because that allows easy use of                                                                                                                                                                                                                                                                                                                                                
_  177             // multiline strings (i.e. text blocks).

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24217#discussion_r2118746980


More information about the hotspot-compiler-dev mailing list