Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use @formatter:off and @formatter:on with google-java-format #295

Closed
kryczaatos opened this issue Jul 18, 2018 · 3 comments
Closed

Use @formatter:off and @formatter:on with google-java-format #295

kryczaatos opened this issue Jul 18, 2018 · 3 comments

Comments

@kryczaatos
Copy link

I would like to exclude some of the code blocks from default formatting approach. I used to use @Formatter:on and off for that, but it seems that it doesn't work with google-java-format.
Is there is any way to use it?

@jbduncan
Copy link
Contributor

Hi @kryczaatos. Sadly, I believe that it's both unsupported and an explicit non-goal of google-java-format to allow users to exclude code blocks from formatting, but I'm sure that someone on the google-java-format team can either correct me or clarify.

@jbduncan
Copy link
Contributor

jbduncan commented Jul 18, 2018

@kryczaatos I don't know what your situation is or why you want to exclude certain code blocks, but if you want to format some code just a bit differently, e.g. if google-java-format gives you a long-ish line like this, but you want it split into multiple lines:

List<String> strings = numbers.stream().map(Object::toString).collect(toList());

then if you simply insert a blank comment like so:

List<String> strings = numbers //
.stream().map(Object::toString).collect(toList());

then when you next run google-java-format, it will format the code like this:

List<String> strings = 
    numbers //
        .stream()
        .map(Object::toString)
        .collect(toList());

It's a weird workaround, but I've found it to be quite useful, personally.

I hope this helps!

@cushon
Copy link
Collaborator

cushon commented Jul 23, 2018

This is a duplicate of #137.

@cushon cushon closed this as completed Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants