Vineflower / vineflower

Modern Java decompiler aiming to be as accurate as possible, with an emphasis on output quality. Fork of the Fernflower decompiler.
https://vineflower.org/
Apache License 2.0
1.13k stars 83 forks source link

Resugar `makeConcatWithConstants` into string templates when supported #377

Open Gaming32 opened 2 months ago

Gaming32 commented 2 months ago

Is your feature request related to a problem? Please describe.

String templates currently will decompile into the string concats they're desugared into.

Describe the solution you'd like

If the class file supports string templates (currently Java 21+ preview class files), these string concats could be sugared into string templates. It's not guaranteed they were originally string templates, but it's impossible to tell if they were (the desugaring happens on the AST, so javac literally compiles them as if they were standard string concats).

Additional context

Original source ```java public class Bar { void foo(int x) { System.out.println(STR."foo: \{x}"); } void bar(int x) { System.out.println(STR."bar: \{x}"); } } ```
Decompiled source (Vineflower 1.10.1) ```java public class Bar { void foo(int x) { System.out.println("foo: " + x); } void bar(int x) { System.out.println("bar: " + x); } } ```
jaskarth commented 2 months ago

I think the idea was to take a look at this after the preview phase is done, as the design of string templates is still being iterated on.