String literals in Java 7: version 1.2

rssh at gradsoft.com.ua rssh at gradsoft.com.ua
Wed Mar 18 12:54:56 PDT 2009


> Hi All,
>
> 2009/3/18  <rssh at gradsoft.com.ua>:
>
> [snip]
>
>> Complex case:
>> Create special syntax for template processing inside strings - I guess
>> this can be a library issue.
>> We have jsr223. May be good ideaa is adding helper methods, which
>> process
>> string via choosed language interptreter, i.e.
>> ═s.scriptEval("velocity",binding);
>> ═.... but - from other side ═we can't receive binding between names and
>> values automatically for now.
>
> Not sure that a library would work, can you give an example of the
> call you propose?
>

Example of such call can be:

binding = new Binding();
binding.put("x",x);
binding.put("y",y);

"""
 <?if ($x==$y) {?>
   A
 <? } else { ?>
   B
 <? } ?>
""".evalScript("PHP",binding);

If PHP is avaible via JSR223 API, then string will be evaluated to A or B.
Or, if you does not like PHP, you can use velocity or java.

But creating binding by hands (first 3 strings of test) kill all :(

>From other side, in principle compiler can generate binding for local
variables automatically, so in principle it is possible to create 'magic
annotation', to write code like:


int someMethod();
{
int x=1;
int y=2;
@GenerateVariableBinding
Binding binding;

String s = """
 <?if ($x==$y) {?>
   A
 <? } else { ?>
   B
 <? } ?>
""".evalScript("PHP",binding);

System.out.println();

}


(I think about formalizing and submitting such proposal, but not sure that
it is possible correct define one in short terms.)







More information about the coin-dev mailing list