Backblaze / b2-sdk-java

The official Java SDK for using Backblaze's B2 Storage APIs
Other
93 stars 26 forks source link

Inference for `B2Json.constructor#params` #177

Closed clamothebb closed 2 years ago

clamothebb commented 2 years ago

Adds support for Java 8's -parameters option, so constructor parameters do not need to be reiterated in B2Json.constructor#params. This enables DRYer B2Json usage and allows developers to generate complete constructors for POJOs using IDE tools.

Previous syntax (still supported):

        @B2Json.constructor(params = "omitNullString, regularString, omitNullInteger, regularInteger")
        public OmitNullTestClass(String omitNullString, String regularString, Integer omitNullInteger, Integer regularInteger) {
            this.omitNullString = omitNullString;
            this.regularString = regularString;
            this.omitNullInteger = omitNullInteger;
            this.regularInteger = regularInteger;
        }

New syntax supported:

        @B2Json.constructor
        public OmitNullTestClass(String omitNullString, String regularString, Integer omitNullInteger, Integer regularInteger) {
            this.omitNullString = omitNullString;
            this.regularString = regularString;
            this.omitNullInteger = omitNullInteger;
            this.regularInteger = regularInteger;
        }

This doesn't introduce any dependencies. It continues to support classes not compiled with javac's -parameters argument. This doesn't have any effect on existing classes, since inference is only used when params are not provided.

Locally, I modified and ran the entire B2JsonTest suite with inferred parameters, with the exception of testParamListedTwice since it's impossible to list a param twice in an actual constructor. All tests passed. This PR includes focused tests for this new functionality.

eding-backblaze commented 2 years ago

Oh! also, our current practice is to update copyright date on all files that you've updated. So you should probably do that in the files you've touched (not just created) in this PR.

brianb-backblaze commented 2 years ago

I check the box for "update copyright" in the IDEA commit dialog and have it update automatically.

clamothebb commented 2 years ago

Thanks for the reviews. I updated the copyrights. Do the reviewers or the PR author typically perform the merge in this project? I'd love to have a version of this released soon so I can use it when building new POJOs in bzmono.

eding-backblaze commented 2 years ago

It's typically the PR author that performs the merge. Please choose "Squash and merge" so that all your changes are merged as a single commit into master.