Description
API(s)
`com.google.common.escape.SourceCodeEscapers`
How do you want it to be improved?
There are existing Escaper
s that support escaping a String
to include in Java source code as a quoted string literal.
What I'd really like is an Escaper
which escapes appropriately for Java 15 text blocks.
Why do we need it to be improved?
"Need" is a strong word! We have a string literal escaper; I think an escaper for text block literals is a natural (if low-priority) extension given the new feature.
Example
The existing escapers turn `"` into `\"`.
A text block escaper would leave `"` unchanged unless it's a _triple_ `"""`. It also wouldn't need to escape newlines, but _would_ need to worry about trailing spaces at the end of lines.
Current Behavior
I could use javaCharEscaper()
and put that in a text block.
Desired Behavior
I'd like an escaper that makes better use of the functionality of text blocks to produce more readable source.
Concrete Use Cases
I was writing an ErrorProne check that google-java-formats code written in text blocks.
Checklist
-
I agree to follow the code of conduct.
-
I have read and understood the contribution guidelines.
-
I have read and understood Guava's philosophy, and I strongly believe that this proposal aligns with it.