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

Poor formatting of generic parameters on methods when class names are long #1074

Open
christophercolumbusdog opened this issue Apr 16, 2024 · 0 comments

Comments

@christophercolumbusdog
Copy link

christophercolumbusdog commented Apr 16, 2024

What happened?

We encountered a class in our codebase with a generic parameter T on one of its methods. T has bounds that involve classes with long names, and when we format this class with Palantir format, we get the following:

public class CrazyGenerics {

    public <
                    T extends
                            FantasticVeryLongNamedContainerWithLongName<?, ?, ?, ?>
                                    & OtherLongNamedTypeWithOnlyOneGenericType<?>>
            void computeInfo() {}

    public interface FantasticVeryLongNamedContainerWithLongName<FirstType, SecondType, ThirdType, FourthType> {
        FirstType getFirst();

        SecondType getSecond();

        ThirdType getThird();

        FourthType getFourth();
    }

    public interface OtherLongNamedTypeWithOnlyOneGenericType<FirstType> {
        FirstType getFirst();
    }
}

What did you want to happen?

I could see a few better alternatives.

Be consistent with the indentation after methods:

    public <
            T extends
                    FantasticVeryLongNamedContainerWithLongName<?, ?, ?, ?>
                            & OtherLongNamedTypeWithOnlyOneGenericType<?>>
            void computeInfo() {}

Or perhaps leave the generic type on the original line:

    public <T extends
            FantasticVeryLongNamedContainerWithLongName<?, ?, ?, ?>
                    & OtherLongNamedTypeWithOnlyOneGenericType<?>>
            void computeInfo() {}

Other suggestions welcome, but I hope it's clear why the original is not ideal.

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

1 participant