code generation - Equivalent of comma operator in Java? -


i trying source transformation on java code results in code every expression, method called if expression evaluated.

(the use case simplistic line coverage measure. i've done sort of thing before in javascript: <my-expression> becomes (covered("path/to/file.js", 12), <my-expression>) or something, 12 line number of expression).

java doesn't have comma operator. thought wrapping expressions in method call, e.g. covered function declared public static <t> t covered(string file, int line, t expr) , return third argument, write covered("path/to/file.java", 12, myexpression()) doesn't work expressions have type void.

is there easy way accomplish this? evil code okay; generated code.

(i see problem, now.)

the context in java void expression can legally occur when statement expression, or 1st or 3rd part in classic for statement. so:

  • if expression used expression statement:

    covered(...); <my-expression>; 
  • if expression used 1st or 3rd part of for,

    covered(...), <my-expression> 
  • otherwise

    covered(..., <my-expression>) 

    or such. (this requires overload of covered each primitive type, , overload signature <t> overload(..., <t>).)

i think can determined purely based on syntax. no type analysis or method overload resolution required figure out whether void method being called.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -