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

fix: correctly sniper-print type member comments after removal of all modifiers #3747

Conversation

slarse
Copy link
Collaborator

@slarse slarse commented Jan 8, 2021

Fix #3732

This PR fixes the bug described in #3732 by keeping track of the last printed element, and allowing the backwards search for previous whitespace to bypass modifier lists that have not been printed. To illustrate the effect of the fix, here's the initial test case file:

public class TypeMemberComments {
    // field comment
    public static int NON_FINAL_FIELD = 42;

    // method comment
    public void nonStaticMethod() {

    }

    // nested type comment
    private class NonStaticInnerClass {

    }
}

The test case removes all of the modifiers from all of the type members. Before the fix, the sniper-printed result was the following:

public class TypeMemberComments {
     int NON_FINAL_FIELD = 42;

     void nonStaticMethod() {

    }

     class NonStaticInnerClass {

    }
}

Note that the comments have disappeared and that the indentation of the type members is a bit off. After the fix, the result is like so:

public class TypeMemberComments {
    // field comment
    int NON_FINAL_FIELD = 42;

    // method comment
    void nonStaticMethod() {

    }

    // nested type comment
    class NonStaticInnerClass {

    }
}

As it should!

@slarse slarse changed the title wip: fix: Fix comment disappearing on removing all modifiers from variable declaration wip: fix: Fix comment disappearing on removing all modifiers from field Jan 8, 2021
@slarse slarse changed the title wip: fix: Fix comment disappearing on removing all modifiers from field review: fix: Fix comment disappearing on removing all modifiers from field Jan 11, 2021
@slarse slarse changed the title review: fix: Fix comment disappearing on removing all modifiers from field wip: fix: Fix comment disappearing on removing all modifiers from field Jan 11, 2021
@slarse slarse changed the title wip: fix: Fix comment disappearing on removing all modifiers from field review: fix: Fix comment disappearing on removing all modifiers from field Jan 11, 2021
@slarse slarse changed the title review: fix: Fix comment disappearing on removing all modifiers from field wip: fix: Fix comment disappearing on removing all modifiers from field Jan 11, 2021
@slarse slarse changed the title wip: fix: Fix comment disappearing on removing all modifiers from field review: fix: Fix comment disappearing on removing all modifiers from field Jan 13, 2021
@slarse slarse changed the title review: fix: Fix comment disappearing on removing all modifiers from field review: fix: Fix comment disappearing on removing all modifiers from type member Jan 13, 2021
@slarse slarse changed the title review: fix: Fix comment disappearing on removing all modifiers from type member review: fix: Correctly sniper print type member comments after removal of all modifiers Jan 13, 2021
@monperrus monperrus changed the title review: fix: Correctly sniper print type member comments after removal of all modifiers fix: correctly sniper-print type member comments after removal of all modifiers Jan 13, 2021
@monperrus monperrus merged commit 498d122 into INRIA:master Jan 13, 2021
@monperrus
Copy link
Collaborator

Thanks!

@slarse slarse deleted the issue/3732-fix-disappearing-comment-on-removal-of-modifiers branch May 28, 2021 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants