Skip to content

Extra newlines on type annotations #1

Description

@swankjesse

Input: one group of fields:

    private DbIncomingEmail incomingEmail;
    private CreationMechanism creationMechanism;
    private @Nullable String creationUserAgent;
    private ClientId clientId;
    private Token externalId;

Output: three groups of fields, because the 3rd field has @Nullable.

    private DbIncomingEmail incomingEmail;
    private CreationMechanism creationMechanism;

    private @Nullable String creationUserAgent;

    private ClientId clientId;
    private Token externalId;

Is this a bug?

Activity

  1. kevinb9n commented on May 15, 2015

    @kevinb9n
    Contributor

    I think it is a bug. Part of the point of in-line mode annotations (vs.
    vertical mode annotations) is supposed to be no longer forcing extra line
    breaks.

    On Fri, May 15, 2015 at 7:00 AM, Jesse Wilson [email protected]
    wrote:

    Input: one group of fields:

    private DbIncomingEmail incomingEmail;
    private CreationMechanism creationMechanism;
    private @Nullable String creationUserAgent;
    private ClientId clientId;
    private Token externalId;
    

    Output: three groups of fields, because the 3rd field has @nullable.

    private DbIncomingEmail incomingEmail;
    private CreationMechanism creationMechanism;
    
    private @Nullable String creationUserAgent;
    
    private ClientId clientId;
    private Token externalId;
    

    Is this a bug?

    —
    Reply to this email directly or view it on GitHub
    #1.

    Kevin Bourrillion | Java Librarian | Google, Inc. | [email protected]

  2. kevinb9n commented on May 15, 2015

    @kevinb9n
    Contributor

    Note there is a slight wrinkle, though.

    The formatter cannot always tell whether an annotation is a type annotation
    or not. It will have to use a pretty gross heuristic. But for now, Google
    isn't on Java 8 yet, so it's going to always assume they are not type
    annotations (because they can't be), but of course it won't go so far as to
    physically move them before the modifiers, so that people in your situation
    won't get annoyed. At some point we will have to turn that on and, well,
    Liam could show you the proposal for how to guess at whether something is a
    type annotation or not...

    On Fri, May 15, 2015 at 7:06 AM, Kevin Bourrillion [email protected]
    wrote:

    I think it is a bug. Part of the point of in-line mode annotations (vs.
    vertical mode annotations) is supposed to be no longer forcing extra line
    breaks.

    On Fri, May 15, 2015 at 7:00 AM, Jesse Wilson [email protected]
    wrote:

    Input: one group of fields:

    private DbIncomingEmail incomingEmail;
    private CreationMechanism creationMechanism;
    private @Nullable String creationUserAgent;
    private ClientId clientId;
    private Token externalId;
    

    Output: three groups of fields, because the 3rd field has @nullable.

    private DbIncomingEmail incomingEmail;
    private CreationMechanism creationMechanism;
    
    private @Nullable String creationUserAgent;
    
    private ClientId clientId;
    private Token externalId;
    

    Is this a bug?

    —
    Reply to this email directly or view it on GitHub
    #1.

    Kevin Bourrillion | Java Librarian | Google, Inc. | [email protected]

    Kevin Bourrillion | Java Librarian | Google, Inc. | [email protected]

  3. cushon commented on May 16, 2015

    @cushon
    Collaborator

    I created #5 to track possible heuristics for type annotations.

    I'm working on a fix for this issue that will suppress the blank lines unless the annotations end up being formatted vertically.

  4. cushon commented on Aug 26, 2015

    @cushon
    Collaborator

    a7cd9c5 was buggy, and would do things like format:

    class Test {
    
      @Nullable int x = 1;
      @Nullable int y = 2;
      @Nullable int z = 2;
    }

    into:

    class Test {
    
      @Nullable int x = 1;
    
      @Nullable int y = 2;
      @Nullable int z = 2;
    }

    All known badness with blank lines around annotated field declarations has been fixed by fb109b9, so please file bugs if you see other issues with that.

  5. added a commit that references this issue on Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions