Skip to content

Support for text blocks in Escapers #7421

Open
@graememorgan

Description

@graememorgan

API(s)

`com.google.common.escape.SourceCodeEscapers`

How do you want it to be improved?

There are existing Escapers 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions