From 8f8f57fc5b12248a8c2e1b134eb5eede1f28d55f Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 9 Oct 2022 10:03:55 +0200 Subject: [PATCH 001/601] Upgrade AutoValue 1.9 -> 1.10 (#283) See: - https://github.com/google/auto/releases/tag/auto-value-1.10 - https://github.com/google/auto/compare/auto-value-1.9...auto-value-1.10 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 85afe299a2..0d28d1784c 100644 --- a/pom.xml +++ b/pom.xml @@ -146,7 +146,7 @@ one place. We use these to keep dependencies in sync. Version numbers that need to be referenced only once should *not* be listed here. --> 1.0.1 - 1.9 + 1.10 ${version.error-prone-orig} v${version.error-prone-orig}-picnic-3 2.15.0 From 45cac6105e930fc98ec1622779ae68d1cbae020c Mon Sep 17 00:00:00 2001 From: Jelmer Borst Date: Sun, 9 Oct 2022 19:41:32 +0200 Subject: [PATCH 002/601] Have website use theme variables instead of custom SASS overrides (#285) --- website/_includes/head_custom.html | 4 ++-- website/_sass/color_schemes/_common.scss | 5 +++++ website/_sass/color_schemes/_variables.scss | 1 + website/_sass/color_schemes/eps-dark.scss | 3 +++ website/_sass/color_schemes/eps-light.scss | 3 +++ website/_sass/custom/custom.scss | 21 ------------------- .../assets/css/just-the-docs-eps-dark.scss | 3 +++ .../assets/css/just-the-docs-eps-light.scss | 3 +++ 8 files changed, 20 insertions(+), 23 deletions(-) create mode 100644 website/_sass/color_schemes/_common.scss create mode 100644 website/_sass/color_schemes/_variables.scss create mode 100644 website/_sass/color_schemes/eps-dark.scss create mode 100644 website/_sass/color_schemes/eps-light.scss delete mode 100644 website/_sass/custom/custom.scss create mode 100644 website/assets/css/just-the-docs-eps-dark.scss create mode 100644 website/assets/css/just-the-docs-eps-light.scss diff --git a/website/_includes/head_custom.html b/website/_includes/head_custom.html index 598920041f..74b77b7772 100644 --- a/website/_includes/head_custom.html +++ b/website/_includes/head_custom.html @@ -12,7 +12,7 @@ - - diff --git a/website/_sass/color_schemes/_common.scss b/website/_sass/color_schemes/_common.scss new file mode 100644 index 0000000000..477b57bec3 --- /dev/null +++ b/website/_sass/color_schemes/_common.scss @@ -0,0 +1,5 @@ +footer > img#logo { + width: 2rem; + margin: 0 auto; + display: block; +} diff --git a/website/_sass/color_schemes/_variables.scss b/website/_sass/color_schemes/_variables.scss new file mode 100644 index 0000000000..fb0a8addf8 --- /dev/null +++ b/website/_sass/color_schemes/_variables.scss @@ -0,0 +1 @@ +$nav-width: 400px; diff --git a/website/_sass/color_schemes/eps-dark.scss b/website/_sass/color_schemes/eps-dark.scss new file mode 100644 index 0000000000..67cf318f23 --- /dev/null +++ b/website/_sass/color_schemes/eps-dark.scss @@ -0,0 +1,3 @@ +@import "./color_schemes/dark"; +@import "_variables"; +@import "_common"; diff --git a/website/_sass/color_schemes/eps-light.scss b/website/_sass/color_schemes/eps-light.scss new file mode 100644 index 0000000000..9b8dfede4f --- /dev/null +++ b/website/_sass/color_schemes/eps-light.scss @@ -0,0 +1,3 @@ +@import "./color_schemes/light"; +@import "_variables"; +@import "_common"; diff --git a/website/_sass/custom/custom.scss b/website/_sass/custom/custom.scss deleted file mode 100644 index cff65e8ac6..0000000000 --- a/website/_sass/custom/custom.scss +++ /dev/null @@ -1,21 +0,0 @@ -// XXX: We should override `$nav-width(-md)`, but this breaks code highlighting -// and other styles. See -// https://github.com/just-the-docs/just-the-docs/issues/982. -// Once the fix for the above issue is released, replace this section with the -// approach recommended at -// https://just-the-docs.github.io/just-the-docs/docs/customization/#custom-schemes. -@include mq(lg) { - .side-bar { - min-width: 400px; - } - - .site-nav, .site-header { - width: 400px; - } -} - -footer > img#logo { - width: 2rem; - margin: 0 auto; - display: block; -} diff --git a/website/assets/css/just-the-docs-eps-dark.scss b/website/assets/css/just-the-docs-eps-dark.scss new file mode 100644 index 0000000000..2d7902cda4 --- /dev/null +++ b/website/assets/css/just-the-docs-eps-dark.scss @@ -0,0 +1,3 @@ +--- +--- +{% include css/just-the-docs.scss.liquid color_scheme="eps-dark" %} diff --git a/website/assets/css/just-the-docs-eps-light.scss b/website/assets/css/just-the-docs-eps-light.scss new file mode 100644 index 0000000000..90a89fd0f0 --- /dev/null +++ b/website/assets/css/just-the-docs-eps-light.scss @@ -0,0 +1,3 @@ +--- +--- +{% include css/just-the-docs.scss.liquid color_scheme="eps-light" %} From 757d5b1d70718ea6d2791a6abdce7e974979b94c Mon Sep 17 00:00:00 2001 From: Jelmer Borst Date: Sun, 9 Oct 2022 19:43:01 +0200 Subject: [PATCH 003/601] Unify local and GitHub Actions website generation flow (#274) --- .github/workflows/deploy-website.yaml | 18 ++++++++++-------- generate-docs.sh | 6 +++--- website/.ruby-version | 1 + website/Gemfile | 9 ++++++--- website/README.md | 26 ++++++++++++++++++++++++-- website/_config.yml | 7 +------ 6 files changed, 45 insertions(+), 22 deletions(-) create mode 100644 website/.ruby-version diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index 4577fbdaac..0ea6e7dac5 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -16,22 +16,24 @@ jobs: steps: - name: Check out code uses: actions/checkout@v3.1.0 + - uses: ruby/setup-ruby@v1.117.0 + with: + working-directory: ./website + bundler-cache: true - name: Configure Github Pages uses: actions/configure-pages@v2.1.1 - name: Generate documentation run: ./generate-docs.sh - name: Build website with Jekyll - uses: actions/jekyll-build-pages@v1.0.5 - with: - source: website/ - destination: ./_site + working-directory: ./website + run: bundle exec jekyll build - name: Validate HTML output - uses: anishathalye/proof-html@v1.4.1 - with: - directory: ./_site - check_external_hash: false + working-directory: ./website + run: bundle exec htmlproofer --check-external-hash false ./_site - name: Upload website as artifact uses: actions/upload-pages-artifact@v1.0.4 + with: + path: ./website/_site deploy: if: github.ref == 'refs/heads/master' needs: build diff --git a/generate-docs.sh b/generate-docs.sh index 0eaa911ee2..1caf0f3d64 100755 --- a/generate-docs.sh +++ b/generate-docs.sh @@ -2,14 +2,14 @@ set -e -u -o pipefail -REPOSIORY_ROOT="$(git rev-parse --show-toplevel)" -WEBSITE_ROOT="${REPOSIORY_ROOT}/website" +REPOSITORY_ROOT="$(git rev-parse --show-toplevel)" +WEBSITE_ROOT="${REPOSITORY_ROOT}/website" generate_homepage() { local homepage="${WEBSITE_ROOT}/index.md" echo "Generating ${homepage}..." - cat - "${REPOSIORY_ROOT}/README.md" > "${homepage}" << EOF + cat - "${REPOSITORY_ROOT}/README.md" > "${homepage}" << EOF --- layout: default title: Home diff --git a/website/.ruby-version b/website/.ruby-version new file mode 100644 index 0000000000..ef538c2810 --- /dev/null +++ b/website/.ruby-version @@ -0,0 +1 @@ +3.1.2 diff --git a/website/Gemfile b/website/Gemfile index cdeed141c6..734e7a144a 100644 --- a/website/Gemfile +++ b/website/Gemfile @@ -1,5 +1,8 @@ +ruby File.read(".ruby-version").strip + source "https://rubygems.org" -gem "github-pages", "227" gem "html-proofer", "4.4.1" -gem "jekyll-remote-theme", "0.4.3" -gem "rake", "13.0.6" +gem "jekyll", "4.2.2" +gem "jekyll-sitemap", "1.4" +gem "just-the-docs", "0.4.0.rc2" +gem "webrick", "1.7" diff --git a/website/README.md b/website/README.md index b1d8674559..b9d0f9833a 100644 --- a/website/README.md +++ b/website/README.md @@ -24,6 +24,27 @@ If you are not familiar with Jekyll, be sure to check out its [documentation][jekyll-docs]. It is recommended to follow the provided step-by-step tutorial. +###### Switch Ruby versions + +The required Ruby version is set in `.ruby-version`. To switch, you can use +[rvm][rvm] to manage your Ruby version. + +###### Resolve Bundler issues + +On macOS, you may get an error such as the following when running `bundle +install`: + +```sh +fatal error: 'openssl/ssl.h' file not found +``` + +In that case, run: + +```sh +bundle config build.eventmachine --with-cppflags="-I$(brew --prefix openssl)/include" +bundle install +``` + # Deployment The website is regenerated and deployed using the @@ -33,6 +54,7 @@ Actions workflow any time a change is merged to `master`. [error-prone-support-website]: https://error-prone.picnic.tech [error-prone-support-website-deploy-workflow]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/deploy-website.yaml [jekyll]: https://jekyllrb.com -[jekyll-docs]: https://jekyllrb.com/docs/ -[jekyll-docs-installation]: https://jekyllrb.com/docs/installation/ +[jekyll-docs]: https://jekyllrb.com/docs +[jekyll-docs-installation]: https://jekyllrb.com/docs/installation [localhost-port-4000]: http://127.0.0.1:4000 +[rvm]: https://rvm.io diff --git a/website/_config.yml b/website/_config.yml index 002a30563d..4c5f1303e1 100644 --- a/website/_config.yml +++ b/website/_config.yml @@ -6,13 +6,8 @@ description: >- Error Prone extensions: extra bug checkers and a large battery of Refaster templates. -# XXX: Investigate dropping the remote theme by instead managing just-the-docs -# using Bundler. This requires changes to the build setup. The upshot is that -# local and CI build environments would then be in sync. -# https://github.com/PicnicSupermarket/error-prone-support/pull/253#discussion_r982709523 -remote_theme: just-the-docs/just-the-docs@v0.4.0.rc2 +theme: just-the-docs plugins: - - jekyll-remote-theme - jekyll-sitemap # Files and directories not to be deployed through GitHub pages. From 3f1399c13937398ce6f6c9d56143049650d73cdb Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Tue, 11 Oct 2022 14:43:34 +0200 Subject: [PATCH 004/601] Accommodate rapid website development on the `website` branch (#287) By (a) deploying from that branch and (b) temporarily disabling external link checking. --- .github/workflows/deploy-website.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index 0ea6e7dac5..52060459f2 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -2,7 +2,7 @@ name: Update `error-prone.picnic.tech` website content on: pull_request: push: - branches: [ master ] + branches: [ master, website ] permissions: contents: read id-token: write @@ -29,13 +29,15 @@ jobs: run: bundle exec jekyll build - name: Validate HTML output working-directory: ./website - run: bundle exec htmlproofer --check-external-hash false ./_site + # XXX: Drop `--disable_external true` once we fully adopted the + # "Refaster rules" terminology on our website and in the code. + run: bundle exec htmlproofer --disable_external true --check-external-hash false ./_site - name: Upload website as artifact uses: actions/upload-pages-artifact@v1.0.4 with: path: ./website/_site deploy: - if: github.ref == 'refs/heads/master' + if: github.ref == 'refs/heads/website' needs: build runs-on: ubuntu-22.04 environment: From 5cec0dd5085bb6a0ccccd79c86ddf2090bcb21b9 Mon Sep 17 00:00:00 2001 From: Pieter Dirk Soels Date: Tue, 11 Oct 2022 14:57:19 +0200 Subject: [PATCH 005/601] Rename `Slf4JLogStatementTest` to `Slf4jLogStatementTest` (#289) --- .../{Slf4JLogStatementTest.java => Slf4jLogStatementTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/{Slf4JLogStatementTest.java => Slf4jLogStatementTest.java} (99%) diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4JLogStatementTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogStatementTest.java similarity index 99% rename from error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4JLogStatementTest.java rename to error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogStatementTest.java index 6375c76cd2..5900a45071 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4JLogStatementTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogStatementTest.java @@ -5,7 +5,7 @@ import com.google.errorprone.CompilationTestHelper; import org.junit.jupiter.api.Test; -final class Slf4JLogStatementTest { +final class Slf4jLogStatementTest { private final CompilationTestHelper compilationTestHelper = CompilationTestHelper.newInstance(Slf4jLogStatement.class, getClass()); private final BugCheckerRefactoringTestHelper refactoringTestHelper = From 7aef2cfe51aeec5f428d36835e2799cd3a34023c Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 11 Oct 2022 15:43:05 +0200 Subject: [PATCH 006/601] Upgrade pitest-maven-plugin 1.9.7 -> 1.9.8 (#290) See https://github.com/hcoles/pitest/compare/1.9.7...1.9.8 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0d28d1784c..a456f64279 100644 --- a/pom.xml +++ b/pom.xml @@ -1255,7 +1255,7 @@ org.pitest pitest-maven - 1.9.7 + 1.9.8 + tech.picnic.error-prone-support refaster-runner @@ -122,7 +122,7 @@ $ mvn clean install [INFO] ------------------------------------------------------------- [WARNING] COMPILATION WARNING : [INFO] ------------------------------------------------------------- -[WARNING] Example.java:[9,34] [tech.picnic.errorprone.refastertemplates.BigDecimalTemplates.BigDecimalZero] +[WARNING] Example.java:[9,34] [tech.picnic.errorprone.refasterrules.BigDecimalRules.BigDecimalZero] Did you mean 'return BigDecimal.ZERO;'? [WARNING] Example.java:[13,35] [IdentityConversion] This method invocation appears redundant; remove it or suppress this warning and add a comment explaining its purpose (see https://error-prone.picnic.tech/bugpatterns/IdentityConversion) @@ -136,12 +136,12 @@ Two things are kicking in here: 1. An Error Prone [`BugChecker`][error-prone-bugchecker] that flags unnecessary [identity conversions][bug-checks-identity-conversion]. -2. A [Refaster][refaster] template capable of - [rewriting][refaster-templates-bigdecimal] expressions of the form +2. A [Refaster][refaster] rule capable of + [rewriting][refaster-rules-bigdecimal] expressions of the form `BigDecimal.valueOf(0)` and `new BigDecimal(0)` to `BigDecimal.ZERO`. Be sure to check out all [bug checks][bug-checks] and [refaster -templates][refaster-templates]. +rules][refaster-rules]. ## 👷 Developing Error Prone Support @@ -227,5 +227,5 @@ guidelines][contributing]. [pitest-maven]: https://pitest.org/quickstart/maven [pr-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg [refaster]: https://errorprone.info/docs/refaster -[refaster-templates-bigdecimal]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/BigDecimalTemplates.java -[refaster-templates]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ +[refaster-rules-bigdecimal]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java +[refaster-rules]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ diff --git a/error-prone-contrib/README.md b/error-prone-contrib/README.md index ace42e7da4..77ee5c6f85 100644 --- a/error-prone-contrib/README.md +++ b/error-prone-contrib/README.md @@ -267,7 +267,7 @@ Refaster's expressiveness: motivating example, see the two subtly different loop definitions in `CollectionRemoveAllFromCollectionExpression`. - Figure out why Refaster sometimes doesn't match the correct generic overload. - See the `AssertThatIterableHasOneComparableElementEqualTo` template for an + See the `AssertThatIterableHasOneComparableElementEqualTo` rule for an example. [autorefactor]: https://autorefactor.org diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/AssertJIsNull.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/AssertJIsNull.java index 3859e9333d..bce994e816 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/AssertJIsNull.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/AssertJIsNull.java @@ -24,7 +24,7 @@ /** * A {@link BugChecker} that flags AssertJ {@code isEqualTo(null)} checks for simplification. * - *

This bug checker cannot be replaced with a simple Refaster template, as the Refaster approach + *

This bug checker cannot be replaced with a simple Refaster rule, as the Refaster approach * would require that all overloads of {@link org.assertj.core.api.Assert#isEqualTo(Object)} (such * as {@link org.assertj.core.api.AbstractStringAssert#isEqualTo(String)}) are explicitly * enumerated. This bug checker generically matches all such current and future overloads. diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotation.java index efc8e9c009..74e92d95a2 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotation.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotation.java @@ -25,7 +25,7 @@ /** A {@link BugChecker} that flags likely missing Refaster annotations. */ @AutoService(BugChecker.class) @BugPattern( - summary = "The Refaster template contains a method without any Refaster annotations", + summary = "The Refaster rule contains a method without any Refaster annotations", link = BUG_PATTERNS_BASE_URL + "MissingRefasterAnnotation", linkType = CUSTOM, severity = WARNING, diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterAnyOfUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterAnyOfUsage.java index e9e4948674..0e636b02e5 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterAnyOfUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterAnyOfUsage.java @@ -22,8 +22,8 @@ /** * A {@link BugChecker} that flags unnecessary {@link Refaster#anyOf(Object[])} usages. * - *

Note that this logic can't be implemented as a Refaster template, as the {@link Refaster} - * class is treated specially. + *

Note that this logic can't be implemented as a Refaster rule, as the {@link Refaster} class is + * treated specially. */ @AutoService(BugChecker.class) @BugPattern( diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterTemplateModifiers.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiers.java similarity index 93% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterTemplateModifiers.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiers.java index 930baee235..fd016da91a 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterTemplateModifiers.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiers.java @@ -35,11 +35,11 @@ @AutoService(BugChecker.class) @BugPattern( summary = "Refaster class and method definitions should specify a canonical set of modifiers", - link = BUG_PATTERNS_BASE_URL + "RefasterTemplateModifiers", + link = BUG_PATTERNS_BASE_URL + "RefasterRuleModifiers", linkType = CUSTOM, severity = SUGGESTION, tags = STYLE) -public final class RefasterTemplateModifiers extends BugChecker +public final class RefasterRuleModifiers extends BugChecker implements ClassTreeMatcher, MethodTreeMatcher { private static final long serialVersionUID = 1L; private static final Matcher BEFORE_TEMPLATE_METHOD = hasAnnotation(BeforeTemplate.class); @@ -85,8 +85,8 @@ private static SuggestedFix suggestCanonicalModifiers(ClassTree tree, VisitorSta if (!hasMatchingMember(tree, PLACEHOLDER_METHOD, state)) { /* - * Templates without a `@Placeholder` method should be `final`. Note that Refaster enforces - * that `@Placeholder` methods are `abstract`, so templates _with_ such a method will + * Rules without a `@Placeholder` method should be `final`. Note that Refaster enforces + * that `@Placeholder` methods are `abstract`, so rules _with_ such a method will * naturally be `abstract` and non-`final`. */ modifiersToAdd.add(Modifier.FINAL); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJBigDecimalRules.java similarity index 82% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJBigDecimalRules.java index aea7797008..272b3ab194 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJBigDecimalRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.data.Offset.offset; import static org.assertj.core.data.Percentage.withPercentage; @@ -11,17 +11,17 @@ import org.assertj.core.api.BigDecimalAssert; /** - * Refaster templates related to AssertJ assertions over {@link BigDecimal}s. + * Refaster rules related to AssertJ assertions over {@link BigDecimal}s. * - *

Note that, contrary to collections of Refaster templates for other {@link - * org.assertj.core.api.NumberAssert} subtypes, these templates do not rewrite to/from {@link + *

Note that, contrary to collections of Refaster rules for other {@link + * org.assertj.core.api.NumberAssert} subtypes, these rules do not rewrite to/from {@link * BigDecimalAssert#isEqualTo(Object)} and {@link BigDecimalAssert#isNotEqualTo(Object)}. This is * because {@link BigDecimal#equals(Object)} considers not only the numeric value of compared * instances, but also their scale. As a result various seemingly straightforward transformations * would actually subtly change the assertion's semantics. */ -final class AssertJBigDecimalTemplates { - private AssertJBigDecimalTemplates() {} +final class AssertJBigDecimalRules { + private AssertJBigDecimalRules() {} static final class AbstractBigDecimalAssertIsEqualByComparingTo { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJBigIntegerRules.java similarity index 95% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJBigIntegerRules.java index 6394d1cda0..7b3ad736ca 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJBigIntegerRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.data.Offset.offset; import static org.assertj.core.data.Percentage.withPercentage; @@ -11,8 +11,8 @@ // XXX: If we add a rule that drops unnecessary `L` suffixes from literal longs, then the `0L`/`1L` // cases below can go. -final class AssertJBigIntegerTemplates { - private AssertJBigIntegerTemplates() {} +final class AssertJBigIntegerRules { + private AssertJBigIntegerRules() {} static final class AbstractBigIntegerAssertIsEqualTo { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJBooleanRules.java similarity index 95% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJBooleanRules.java index 6f56835c3f..9c28353c63 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJBooleanRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.assertj.core.api.Assertions.assertThat; @@ -9,8 +9,8 @@ import com.google.errorprone.refaster.annotation.UseImportPolicy; import org.assertj.core.api.AbstractBooleanAssert; -final class AssertJBooleanTemplates { - private AssertJBooleanTemplates() {} +final class AssertJBooleanRules { + private AssertJBooleanRules() {} static final class AbstractBooleanAssertIsEqualTo { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJByteTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJByteRules.java similarity index 94% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJByteTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJByteRules.java index 220e3001e7..1c1134c387 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJByteTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJByteRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.data.Offset.offset; import static org.assertj.core.data.Percentage.withPercentage; @@ -8,8 +8,8 @@ import com.google.errorprone.refaster.annotation.BeforeTemplate; import org.assertj.core.api.AbstractByteAssert; -final class AssertJByteTemplates { - private AssertJByteTemplates() {} +final class AssertJByteRules { + private AssertJByteRules() {} static final class AbstractByteAssertIsEqualTo { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJCharSequenceRules.java similarity index 92% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJCharSequenceRules.java index f528b7d285..545b7fec08 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJCharSequenceRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.assertj.core.api.Assertions.assertThat; @@ -9,8 +9,8 @@ import com.google.errorprone.refaster.annotation.UseImportPolicy; import org.assertj.core.api.AbstractAssert; -final class AssertJCharSequenceTemplates { - private AssertJCharSequenceTemplates() {} +final class AssertJCharSequenceRules { + private AssertJCharSequenceRules() {} static final class AssertThatCharSequenceIsEmpty { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJComparableRules.java similarity index 95% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJComparableRules.java index 2d63f665da..ea92d58fb6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJComparableRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.assertj.core.api.Assertions.assertThat; @@ -9,8 +9,8 @@ import org.assertj.core.api.AbstractComparableAssert; import org.assertj.core.api.AbstractIntegerAssert; -final class AssertJComparableTemplates { - private AssertJComparableTemplates() {} +final class AssertJComparableRules { + private AssertJComparableRules() {} static final class AssertThatIsEqualByComparingTo> { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJDoubleRules.java similarity index 95% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJDoubleRules.java index 44dc57b014..624018ffd9 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJDoubleRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.data.Offset.offset; import static org.assertj.core.data.Percentage.withPercentage; @@ -9,8 +9,8 @@ import org.assertj.core.api.AbstractDoubleAssert; import org.assertj.core.data.Offset; -final class AssertJDoubleTemplates { - private AssertJDoubleTemplates() {} +final class AssertJDoubleRules { + private AssertJDoubleRules() {} static final class AbstractDoubleAssertIsCloseToWithOffset { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJEnumerableRules.java similarity index 93% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJEnumerableRules.java index 7f20919951..a891bfbc06 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJEnumerableRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.Iterables; import com.google.errorprone.refaster.Refaster; @@ -7,8 +7,8 @@ import java.util.Collection; import org.assertj.core.api.EnumerableAssert; -final class AssertJEnumerableTemplates { - private AssertJEnumerableTemplates() {} +final class AssertJEnumerableRules { + private AssertJEnumerableRules() {} static final class EnumerableAssertIsEmpty { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJFloatRules.java similarity index 95% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJFloatRules.java index 6de54b99cb..8952ca4f2b 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJFloatRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.data.Offset.offset; import static org.assertj.core.data.Percentage.withPercentage; @@ -9,8 +9,8 @@ import org.assertj.core.api.AbstractFloatAssert; import org.assertj.core.data.Offset; -final class AssertJFloatTemplates { - private AssertJFloatTemplates() {} +final class AssertJFloatRules { + private AssertJFloatRules() {} static final class AbstractFloatAssertIsCloseToWithOffset { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJIntegerRules.java similarity index 94% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJIntegerRules.java index f46ac40564..d134bfe6c8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJIntegerRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.data.Offset.offset; import static org.assertj.core.data.Percentage.withPercentage; @@ -8,8 +8,8 @@ import com.google.errorprone.refaster.annotation.BeforeTemplate; import org.assertj.core.api.AbstractIntegerAssert; -final class AssertJIntegerTemplates { - private AssertJIntegerTemplates() {} +final class AssertJIntegerRules { + private AssertJIntegerRules() {} static final class AbstractIntegerAssertIsEqualTo { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJLongTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJLongRules.java similarity index 94% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJLongTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJLongRules.java index e992886dff..3ac9275fc2 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJLongTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJLongRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.data.Offset.offset; import static org.assertj.core.data.Percentage.withPercentage; @@ -8,8 +8,8 @@ import com.google.errorprone.refaster.annotation.BeforeTemplate; import org.assertj.core.api.AbstractLongAssert; -final class AssertJLongTemplates { - private AssertJLongTemplates() {} +final class AssertJLongRules { + private AssertJLongRules() {} static final class AbstractLongAssertIsEqualTo { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJMapTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJMapRules.java similarity index 90% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJMapTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJMapRules.java index 566caa3265..dfbd303ea3 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJMapTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJMapRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableMap; import com.google.errorprone.refaster.annotation.AfterTemplate; @@ -6,8 +6,8 @@ import java.util.Map; import org.assertj.core.api.AbstractMapAssert; -final class AssertJMapTemplates { - private AssertJMapTemplates() {} +final class AssertJMapRules { + private AssertJMapRules() {} static final class AbstractMapAssertContainsExactlyInAnyOrderEntriesOf { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJNumberRules.java similarity index 98% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJNumberRules.java index 0c7f08b6aa..fac67d6068 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJNumberRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.assertj.core.api.Assertions.assertThat; @@ -21,8 +21,8 @@ import org.assertj.core.api.NumberAssert; import tech.picnic.errorprone.refaster.matchers.IsCharacter; -final class AssertJNumberTemplates { - private AssertJNumberTemplates() {} +final class AssertJNumberRules { + private AssertJNumberRules() {} static final class NumberAssertIsPositive { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJObjectRules.java similarity index 95% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJObjectRules.java index 458a4c2c66..b5122b7296 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJObjectRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.assertj.core.api.Assertions.assertThat; @@ -11,8 +11,8 @@ import org.assertj.core.api.AbstractStringAssert; import org.assertj.core.api.ObjectAssert; -final class AssertJObjectTemplates { - private AssertJObjectTemplates() {} +final class AssertJObjectRules { + private AssertJObjectRules() {} static final class AssertThatIsInstanceOf { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJOptionalRules.java similarity index 97% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJOptionalRules.java index 6769749cf5..f14bef43ad 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJOptionalRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.assertj.core.api.Assertions.assertThat; @@ -15,8 +15,8 @@ import org.assertj.core.api.ObjectAssert; import org.assertj.core.api.OptionalAssert; -final class AssertJOptionalTemplates { - private AssertJOptionalTemplates() {} +final class AssertJOptionalRules { + private AssertJOptionalRules() {} static final class AssertThatOptional { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJPrimitiveTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJPrimitiveRules.java similarity index 96% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJPrimitiveTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJPrimitiveRules.java index b58a703c71..7635e37037 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJPrimitiveTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJPrimitiveRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.assertj.core.api.Assertions.assertThat; @@ -10,8 +10,8 @@ import org.assertj.core.api.AbstractBooleanAssert; import org.assertj.core.api.AbstractDoubleAssert; -final class AssertJPrimitiveTemplates { - private AssertJPrimitiveTemplates() {} +final class AssertJPrimitiveRules { + private AssertJPrimitiveRules() {} static final class AssertThatIsEqualTo { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJRules.java similarity index 99% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJRules.java index e941254bb1..4da5ba9c92 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.assertj.core.api.Assertions.assertThat; @@ -55,7 +55,7 @@ import org.assertj.core.api.OptionalLongAssert; import tech.picnic.errorprone.refaster.matchers.IsArray; -/** Refaster templates related to AssertJ expressions and statements. */ +/** Refaster rules related to AssertJ expressions and statements. */ // XXX: Most `AbstractIntegerAssert` rules can also be applied for other primitive types. Generate // these in separate files. // XXX: Also do for BigInteger/BigDecimal? @@ -63,7 +63,7 @@ // ^ And variants. // XXX: Consider splitting this class into multiple classes. // XXX: Some of these rules may not apply given the updated TestNG rewrite rules. Review. -// XXX: For the templates that "unwrap" explicitly enumerated collections, also introduce variants +// XXX: For the rules that "unwrap" explicitly enumerated collections, also introduce variants // with explicitly enumerated sorted collections. (Requires that the type bound is Comparable.) // XXX: Handle `.isEqualTo(explicitlyEnumeratedCollection)`. Can be considered equivalent to // `.containsOnly(elements)`. (This does mean the auto-generated code needs to be more advanced. @@ -101,7 +101,7 @@ // (etc.) // XXX: Look into using Assertions#contentOf(URL url, Charset charset) instead of our own test // method. -// XXX: Write Optional templates also for `OptionalInt` and variants. +// XXX: Write `Optional` rules also for `OptionalInt` and variants. // XXX: Write plugin to flag `assertThat(compileTimeConstant)` occurrences. Also other likely // candidates, such as `assertThat(ImmutableSet(foo, bar)).XXX` // XXX: Write generic plugin to replace explicit array parameters with varargs (`new int[] {1, 2}` @@ -118,10 +118,10 @@ // XXX: `assertThat(ImmutableList.sortedCopyOf(cmp, values)).somethingExactOrder` -> just compare // "in any order". // XXX: Turns out a lot of this is also covered by https://github.com/palantir/assertj-automation. -// See how we can combine these things. Do note that (at present) their Refaster templates don't -// show up as Error Prone checks. So we'd have to build an integration for that. -final class AssertJTemplates { - private AssertJTemplates() {} +// See how we can combine these things. Do note that (at present) their Refaster rules don't show up +// as Error Prone checks. So we'd have to build an integration for that. +final class AssertJRules { + private AssertJRules() {} // // OptionalDouble @@ -491,7 +491,7 @@ IterableAssert after(Iterable iterable, T element) { } // XXX: This overload is here because `assertThat` has an overload for `Comparable` types. - // Unfortunately this still doesn't convince Refaster to match this template in the context of + // Unfortunately this still doesn't convince Refaster to match this rule in the context of // Comparable types. Figure out why! Note that this also affects the `AssertThatOptional` rule. static final class AssertThatIterableHasOneComparableElementEqualTo< S extends Comparable, T extends S> { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJShortTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJShortRules.java similarity index 94% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJShortTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJShortRules.java index 017f897b93..a09e34ca2b 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJShortTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJShortRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.data.Offset.offset; import static org.assertj.core.data.Percentage.withPercentage; @@ -8,8 +8,8 @@ import com.google.errorprone.refaster.annotation.BeforeTemplate; import org.assertj.core.api.AbstractShortAssert; -final class AssertJShortTemplates { - private AssertJShortTemplates() {} +final class AssertJShortRules { + private AssertJShortRules() {} static final class AbstractShortAssertIsEqualTo { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJStringTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJStringRules.java similarity index 95% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJStringTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJStringRules.java index c217193bf5..d149d3b1ff 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJStringTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJStringRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.assertj.core.api.Assertions.assertThat; @@ -9,8 +9,8 @@ import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractStringAssert; -final class AssertJStringTemplates { - private AssertJStringTemplates() {} +final class AssertJStringRules { + private AssertJStringRules() {} static final class AbstractStringAssertStringIsEmpty { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRules.java similarity index 97% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRules.java index 14ebac29d5..f221f66425 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -18,16 +18,16 @@ import org.assertj.core.api.ThrowableAssert.ThrowingCallable; /** - * Refaster templates related to AssertJ assertions over expressions that may throw a {@link - * Throwable} subtype. + * Refaster rules related to AssertJ assertions over expressions that may throw a {@link Throwable} + * subtype. * *

For reasons of consistency we prefer {@link * org.assertj.core.api.Assertions#assertThatThrownBy} over static methods for specific exception * types. Note that only the most common assertion expressions are rewritten here; covering all * cases would require the implementation of an Error Prone check instead. */ -final class AssertJThrowingCallableTemplates { - private AssertJThrowingCallableTemplates() {} +final class AssertJThrowingCallableRules { + private AssertJThrowingCallableRules() {} static final class AssertThatThrownByIllegalArgumentException { @BeforeTemplate @@ -429,8 +429,8 @@ static final class AssertThatThrownByHasMessageParameters { } } - // XXX: Drop this template in favour of a generic Error Prone check that flags - // `String.format(...)` arguments to a wide range of format methods. + // XXX: Drop this rule in favour of a generic Error Prone check that flags `String.format(...)` + // arguments to a wide range of format methods. static final class AbstractThrowableAssertHasMessage { @BeforeTemplate AbstractThrowableAssert before( @@ -449,8 +449,8 @@ static final class AbstractThrowableAssertHasMessage { } } - // XXX: Drop this template in favour of a generic Error Prone check that flags - // `String.format(...)` arguments to a wide range of format methods. + // XXX: Drop this rule in favour of a generic Error Prone check that flags `String.format(...)` + // arguments to a wide range of format methods. static final class AbstractThrowableAssertWithFailMessage { @BeforeTemplate AbstractThrowableAssert before( diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssortedTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssortedRules.java similarity index 94% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssortedTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssortedRules.java index 62ec075c2a..872f9eced8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/AssortedTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssortedRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.base.Preconditions.checkElementIndex; import static com.google.common.collect.ImmutableSet.toImmutableSet; @@ -30,11 +30,11 @@ import javax.annotation.Nullable; /** - * Assorted Refaster templates that do not (yet) belong in one of the other classes with more - * topical Refaster templates. + * Assorted Refaster rules that do not (yet) belong in one of the other classes with more topical + * Refaster rules. */ -final class AssortedTemplates { - private AssortedTemplates() {} +final class AssortedRules { + private AssortedRules() {} /** Prefer {@link Objects#checkIndex(int, int)} over the Guava alternative. */ static final class CheckIndex { @@ -117,7 +117,7 @@ T after(Iterator iterator, T defaultValue) { } /** Don't unnecessarily repeat boolean expressions. */ - // XXX: This template captures only the simplest case. `@AlsoNegation` doesn't help. Consider + // XXX: This rule captures only the simplest case. `@AlsoNegation` doesn't help. Consider // contributing a Refaster patch, which handles the negation in the `@BeforeTemplate` more // intelligently. static final class LogicalImplication { @@ -172,8 +172,8 @@ boolean after(Set set1, Set set2) { * Collections#disjoint(Collection, Collection)}. */ // XXX: Other copy operations could be elided too, but these are most common after application of - // the `DisjointSets` template defined above. If we ever introduce a generic "makes a copy" - // stand-in, use it here. + // the `DisjointSets` rule defined above. If we ever introduce a generic "makes a copy" stand-in, + // use it here. static final class DisjointCollections { @BeforeTemplate boolean before(Collection collection1, Collection collection2) { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/BigDecimalTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java similarity index 89% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/BigDecimalTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java index e6169e9b46..7f27917660 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/BigDecimalTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java @@ -1,13 +1,13 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.errorprone.refaster.Refaster; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import java.math.BigDecimal; -/** Refaster templates related to expressions dealing with {@link BigDecimal}s. */ -final class BigDecimalTemplates { - private BigDecimalTemplates() {} +/** Refaster rules related to expressions dealing with {@link BigDecimal}s. */ +final class BigDecimalRules { + private BigDecimalRules() {} /** Prefer using the constant {@link BigDecimal#ZERO} when possible. */ static final class BigDecimalZero { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/CollectionTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java similarity index 98% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/CollectionTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java index 55f8a100a0..e02c12c2a2 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/CollectionTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; @@ -20,11 +20,11 @@ import java.util.function.IntFunction; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with (arbitrary) collections. */ +/** Refaster rules related to expressions dealing with (arbitrary) collections. */ // XXX: There are other Guava `Iterables` methods that should not be called if the input is known to // be a `Collection`. Add those here. -final class CollectionTemplates { - private CollectionTemplates() {} +final class CollectionRules { + private CollectionRules() {} /** * Prefer {@link Collection#isEmpty()} over alternatives that consult the collection's size or are diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ComparatorTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java similarity index 97% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ComparatorTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java index c088b8fa82..3a1e94d32b 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ComparatorTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static java.util.Comparator.comparing; @@ -25,9 +25,9 @@ import java.util.function.ToIntFunction; import java.util.function.ToLongFunction; -/** Refaster templates related to expressions dealing with {@link Comparator}s. */ -final class ComparatorTemplates { - private ComparatorTemplates() {} +/** Refaster rules related to expressions dealing with {@link Comparator}s. */ +final class ComparatorRules { + private ComparatorRules() {} /** Prefer {@link Comparator#naturalOrder()} over more complicated constructs. */ static final class NaturalOrder> { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java similarity index 97% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java index 32ab0fbeaa..7e8e007b19 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.Streams; import com.google.errorprone.refaster.Refaster; @@ -13,9 +13,9 @@ import java.util.stream.DoubleStream; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link DoubleStream}s. */ -final class DoubleStreamTemplates { - private DoubleStreamTemplates() {} +/** Refaster rules related to expressions dealing with {@link DoubleStream}s. */ +final class DoubleStreamRules { + private DoubleStreamRules() {} /** Don't unnecessarily call {@link Streams#concat(DoubleStream...)}. */ static final class ConcatOneDoubleStream { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/EqualityTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/EqualityRules.java similarity index 94% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/EqualityTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/EqualityRules.java index 3cb561b11a..6aaccd1d4d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/EqualityTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/EqualityRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.errorprone.refaster.Refaster; import com.google.errorprone.refaster.annotation.AfterTemplate; @@ -7,9 +7,9 @@ import java.util.Objects; import java.util.function.Predicate; -/** Refaster templates related to expressions dealing with (in)equalities. */ -final class EqualityTemplates { - private EqualityTemplates() {} +/** Refaster rules related to expressions dealing with (in)equalities. */ +final class EqualityRules { + private EqualityRules() {} /** Prefer reference-based quality for enums. */ // Primitive value comparisons are not listed, because Error Prone flags those out of the box. diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableListMultimapRules.java similarity index 97% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableListMultimapRules.java index e1da7db817..87fc03db95 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableListMultimapRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableListMultimap.flatteningToImmutableListMultimap; import static com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap; @@ -25,9 +25,9 @@ import java.util.function.Function; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link ImmutableListMultimap}s. */ -final class ImmutableListMultimapTemplates { - private ImmutableListMultimapTemplates() {} +/** Refaster rules related to expressions dealing with {@link ImmutableListMultimap}s. */ +final class ImmutableListMultimapRules { + private ImmutableListMultimapRules() {} /** * Prefer {@link ImmutableListMultimap#builder()} over the associated constructor on constructions @@ -70,7 +70,7 @@ ImmutableListMultimap after() { * alternatives. */ // XXX: One can define variants for more than one key-value pair, but at some point the builder - // actually produces nicer code. So it's not clear we should add Refaster templates for those + // actually produces nicer code. So it's not clear we should add Refaster rules for those // variants. static final class PairToImmutableListMultimap { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableListRules.java similarity index 96% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableListRules.java index 082fadf231..de9aca4deb 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableListTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableListRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableSet.toImmutableSet; @@ -21,9 +21,9 @@ import java.util.List; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link ImmutableList}s. */ -final class ImmutableListTemplates { - private ImmutableListTemplates() {} +/** Refaster rules related to expressions dealing with {@link ImmutableList}s. */ +final class ImmutableListRules { + private ImmutableListRules() {} /** Prefer {@link ImmutableList#builder()} over the associated constructor. */ // XXX: This drops generic type information, sometimes leading to non-compilable code. See @@ -154,7 +154,7 @@ ImmutableList after(Stream stream) { * communicate the immutability of the resulting list at the type level. */ // XXX: The `Stream` variant may be too contrived to warrant inclusion. Review its usage if/when - // this and similar Refaster templates are replaced with an Error Prone check. + // this and similar Refaster rules are replaced with an Error Prone check. static final class ImmutableListOf { @BeforeTemplate List before() { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMapRules.java similarity index 98% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMapRules.java index ad9a4e3a70..2d1906983f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMapRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableMap.toImmutableMap; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; @@ -22,9 +22,9 @@ import java.util.function.Function; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link ImmutableMap}s. */ -final class ImmutableMapTemplates { - private ImmutableMapTemplates() {} +/** Refaster rules related to expressions dealing with {@link ImmutableMap}s. */ +final class ImmutableMapRules { + private ImmutableMapRules() {} /** Prefer {@link ImmutableMap#builder()} over the associated constructor. */ // XXX: This drops generic type information, sometimes leading to non-compilable code. See @@ -313,7 +313,7 @@ ImmutableMap after(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V } } - // XXX: Add a template for this: + // XXX: Add a rule for this: // Maps.transformValues(streamOfEntries.collect(groupBy(fun)), ImmutableMap::copyOf) // -> // streamOfEntries.collect(groupBy(fun, toImmutableMap(Map.Entry::getKey, Map.Entry::getValue))) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMultisetRules.java similarity index 93% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMultisetRules.java index d60264965f..07802c7741 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMultisetRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableMultiset.toImmutableMultiset; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; @@ -14,9 +14,9 @@ import java.util.Iterator; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link ImmutableMultiset}s. */ -final class ImmutableMultisetTemplates { - private ImmutableMultisetTemplates() {} +/** Refaster rules related to expressions dealing with {@link ImmutableMultiset}s. */ +final class ImmutableMultisetRules { + private ImmutableMultisetRules() {} /** Prefer {@link ImmutableMultiset#builder()} over the associated constructor. */ // XXX: This drops generic type information, sometimes leading to non-compilable code. See diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetMultimapRules.java similarity index 97% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetMultimapRules.java index ed991be8ef..8272c05b57 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetMultimapRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSetMultimap.flatteningToImmutableSetMultimap; import static com.google.common.collect.ImmutableSetMultimap.toImmutableSetMultimap; @@ -22,9 +22,9 @@ import java.util.function.Function; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link ImmutableSetMultimap}s. */ -final class ImmutableSetMultimapTemplates { - private ImmutableSetMultimapTemplates() {} +/** Refaster rules related to expressions dealing with {@link ImmutableSetMultimap}s. */ +final class ImmutableSetMultimapRules { + private ImmutableSetMultimapRules() {} /** Prefer {@link ImmutableSetMultimap#builder()} over the associated constructor. */ // XXX: This drops generic type information, sometimes leading to non-compilable code. See @@ -56,7 +56,7 @@ ImmutableSetMultimap after() { /** Prefer {@link ImmutableSetMultimap#of(Object, Object)} over more contrived alternatives. */ // XXX: One can define variants for more than one key-value pair, but at some point the builder - // actually produces nicer code. So it's not clear we should add Refaster templates for those + // actually produces nicer code. So it's not clear we should add Refaster rules for those // variants. static final class PairToImmutableSetMultimap { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetRules.java similarity index 95% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetRules.java index b710f4e7a1..b7159b886a 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; @@ -18,9 +18,9 @@ import java.util.Set; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link ImmutableSet}s. */ -final class ImmutableSetTemplates { - private ImmutableSetTemplates() {} +/** Refaster rules related to expressions dealing with {@link ImmutableSet}s. */ +final class ImmutableSetRules { + private ImmutableSetRules() {} /** Prefer {@link ImmutableSet#builder()} over the associated constructor. */ // XXX: This drops generic type information, sometimes leading to non-compilable code. See @@ -104,7 +104,7 @@ ImmutableSet after(SetView set) { * communicate the immutability of the resulting set at the type level. */ // XXX: The `Stream` variant may be too contrived to warrant inclusion. Review its usage if/when - // this and similar Refaster templates are replaced with an Error Prone check. + // this and similar Refaster rules are replaced with an Error Prone check. static final class ImmutableSetOf { @BeforeTemplate Set before() { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRules.java similarity index 95% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRules.java index e5e265d684..ff03163cad 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSortedMap.toImmutableSortedMap; import static java.util.Comparator.naturalOrder; @@ -14,9 +14,9 @@ import java.util.Map; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link ImmutableSortedMap}s. */ -final class ImmutableSortedMapTemplates { - private ImmutableSortedMapTemplates() {} +/** Refaster rules related to expressions dealing with {@link ImmutableSortedMap}s. */ +final class ImmutableSortedMapRules { + private ImmutableSortedMapRules() {} /** Prefer {@link ImmutableSortedMap#orderedBy(Comparator)} over the associated constructor. */ static final class ImmutableSortedMapBuilder { @@ -82,7 +82,7 @@ ImmutableSortedMap after() { /** Prefer {@link ImmutableSortedMap#of(Object, Object)} over more contrived alternatives. */ // XXX: One can define variants for more than one key-value pair, but at some point the builder - // actually produces nicer code. So it's not clear we should add Refaster templates for those + // actually produces nicer code. So it's not clear we should add Refaster rules for those // variants. // XXX: We could also rewrite builders with non-natural orders, but that would affect // `ImmutableSortedMap#comparator()`. diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedMultisetRules.java similarity index 95% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedMultisetRules.java index 68252ae21d..0e8a252223 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedMultisetRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSortedMultiset.toImmutableSortedMultiset; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; @@ -16,9 +16,9 @@ import java.util.Iterator; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link ImmutableSortedMultiset}s. */ -final class ImmutableSortedMultisetTemplates { - private ImmutableSortedMultisetTemplates() {} +/** Refaster rules related to expressions dealing with {@link ImmutableSortedMultiset}s. */ +final class ImmutableSortedMultisetRules { + private ImmutableSortedMultisetRules() {} /** * Prefer {@link ImmutableSortedMultiset#orderedBy(Comparator)} over the associated constructor. diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedSetRules.java similarity index 95% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedSetRules.java index bac035d3b0..627fdf7c0f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedSetRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; @@ -16,9 +16,9 @@ import java.util.Iterator; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link ImmutableSortedSet}s. */ -final class ImmutableSortedSetTemplates { - private ImmutableSortedSetTemplates() {} +/** Refaster rules related to expressions dealing with {@link ImmutableSortedSet}s. */ +final class ImmutableSortedSetRules { + private ImmutableSortedSetRules() {} /** Prefer {@link ImmutableSortedSet#orderedBy(Comparator)} over the associated constructor. */ static final class ImmutableSortedSetBuilder { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/IntStreamTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java similarity index 97% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/IntStreamTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java index 52d8bb2d66..382f5d332b 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/IntStreamTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.Streams; import com.google.errorprone.refaster.Refaster; @@ -13,9 +13,9 @@ import java.util.stream.IntStream; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link IntStream}s. */ -final class IntStreamTemplates { - private IntStreamTemplates() {} +/** Refaster rules related to expressions dealing with {@link IntStream}s. */ +final class IntStreamRules { + private IntStreamRules() {} /** Prefer {@link IntStream#range(int, int)} over the more contrived alternative. */ static final class IntStreamClosedOpenRange { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/JUnitTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JUnitRules.java similarity index 82% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/JUnitTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JUnitRules.java index 3386787e95..b2c5942856 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/JUnitTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JUnitRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.junit.jupiter.params.provider.Arguments.arguments; @@ -9,9 +9,9 @@ import com.google.errorprone.refaster.annotation.UseImportPolicy; import org.junit.jupiter.params.provider.Arguments; -/** Refaster templates related to JUnit expressions and statements. */ -final class JUnitTemplates { - private JUnitTemplates() {} +/** Refaster rules related to JUnit expressions and statements. */ +final class JUnitRules { + private JUnitRules() {} /** Prefer statically imported {@link Arguments#arguments} over {@link Arguments#of} calls. */ static final class ArgumentsEnumeration { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/LongStreamTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java similarity index 97% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/LongStreamTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java index 2cefe257f3..45b4c0da30 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/LongStreamTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.Streams; import com.google.errorprone.refaster.Refaster; @@ -13,9 +13,9 @@ import java.util.stream.LongStream; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link LongStream}s. */ -final class LongStreamTemplates { - private LongStreamTemplates() {} +/** Refaster rules related to expressions dealing with {@link LongStream}s. */ +final class LongStreamRules { + private LongStreamRules() {} /** Prefer {@link LongStream#range(long, long)} over the more contrived alternative. */ static final class LongStreamClosedOpenRange { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MapEntryTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapEntryRules.java similarity index 94% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MapEntryTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapEntryRules.java index d01d621563..27d3af80c3 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MapEntryTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapEntryRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static java.util.Comparator.comparing; @@ -15,9 +15,9 @@ import java.util.Comparator; import java.util.Map; -/** Refaster templates related to expressions dealing with {@link Map.Entry} instances. */ -final class MapEntryTemplates { - private MapEntryTemplates() {} +/** Refaster rules related to expressions dealing with {@link Map.Entry} instances. */ +final class MapEntryRules { + private MapEntryRules() {} /** * Prefer {@link Map#entry(Object, Object)} over alternative ways to create an immutable map diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MockitoTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MockitoRules.java similarity index 87% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MockitoTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MockitoRules.java index 3b67c27046..b17af9b514 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MockitoTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MockitoRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.mockito.Mockito.never; @@ -11,9 +11,9 @@ import org.mockito.Mockito; import org.mockito.verification.VerificationMode; -/** Refaster templates related to Mockito expressions and statements. */ -final class MockitoTemplates { - private MockitoTemplates() {} +/** Refaster rules related to Mockito expressions and statements. */ +final class MockitoRules { + private MockitoRules() {} /** * Prefer {@link Mockito#never()}} over explicitly specifying that the associated invocation must diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MultimapTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MultimapRules.java similarity index 89% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MultimapTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MultimapRules.java index 9e0f45e31a..ff64ad784c 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/MultimapTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MultimapRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; @@ -9,9 +9,9 @@ import java.util.Set; import javax.annotation.Nullable; -/** Refaster templates related to expressions dealing with {@link Multimap}s. */ -final class MultimapTemplates { - private MultimapTemplates() {} +/** Refaster rules related to expressions dealing with {@link Multimap}s. */ +final class MultimapRules { + private MultimapRules() {} /** Prefer {@link Multimap#keySet()} over more contrived alternatives. */ static final class MultimapKeySet { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/NullTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/NullRules.java similarity index 92% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/NullTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/NullRules.java index d5b8c22d23..770843886c 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/NullTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/NullRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static java.util.Objects.requireNonNullElse; @@ -11,9 +11,9 @@ import java.util.function.Predicate; import javax.annotation.Nullable; -/** Refaster templates related to expressions dealing with (possibly) null values. */ -final class NullTemplates { - private NullTemplates() {} +/** Refaster rules related to expressions dealing with (possibly) null values. */ +final class NullRules { + private NullRules() {} /** Prefer the {@code ==} operator over {@link Objects#isNull(Object)}. */ static final class IsNull { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java similarity index 97% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java index 113159d98c..7c990060a5 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/OptionalTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; @@ -18,9 +18,9 @@ import java.util.stream.Stream; import javax.annotation.Nullable; -/** Refaster templates related to expressions dealing with {@link Optional}s. */ -final class OptionalTemplates { - private OptionalTemplates() {} +/** Refaster rules related to expressions dealing with {@link Optional}s. */ +final class OptionalRules { + private OptionalRules() {} static final class OptionalOfNullable { // XXX: Refaster should be smart enough to also rewrite occurrences in which there are @@ -78,8 +78,8 @@ T after(Optional optional) { } /** Prefer {@link Optional#orElseThrow()} over the less explicit {@link Optional#get()}. */ - // XXX: This template is analogous to `OptionalOrElseThrow` above. Arguably this is its - // generalization. If/when Refaster is extended to understand this, delete the template above. + // XXX: This rule is analogous to `OptionalOrElseThrow` above. Arguably this is its + // generalization. If/when Refaster is extended to understand this, delete the rule above. static final class OptionalOrElseThrowMethodReference { @BeforeTemplate Function, T> before() { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/PrimitiveTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/PrimitiveRules.java similarity index 89% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/PrimitiveTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/PrimitiveRules.java index 622d2538c8..041abec002 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/PrimitiveTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/PrimitiveRules.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.primitives.Ints; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; -/** Refaster templates related to expressions dealing with primitives. */ -final class PrimitiveTemplates { - private PrimitiveTemplates() {} +/** Refaster rules related to expressions dealing with primitives. */ +final class PrimitiveRules { + private PrimitiveRules() {} /** Avoid contrived ways of expressing the "less than" relationship. */ static final class LessThan { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java similarity index 97% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 68391d463e..e03b521533 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/ReactorTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.MoreCollectors.toOptional; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; @@ -27,9 +27,9 @@ import reactor.test.publisher.PublisherProbe; import tech.picnic.errorprone.refaster.matchers.ThrowsCheckedException; -/** Refaster templates related to Reactor expressions and statements. */ -final class ReactorTemplates { - private ReactorTemplates() {} +/** Refaster rules related to Reactor expressions and statements. */ +final class ReactorRules { + private ReactorRules() {} /** * Prefer {@link Mono#fromSupplier(Supplier)} over {@link Mono#fromCallable(Callable)} where @@ -95,7 +95,7 @@ Flux after(Throwable throwable) { /** * Don't unnecessarily pass {@link Mono#error(Supplier)} a method reference or lambda expression. */ - // XXX: Drop this rule once the more general rule `AssortedTemplates#SupplierAsSupplier` works + // XXX: Drop this rule once the more general rule `AssortedRules#SupplierAsSupplier` works // reliably. static final class MonoErrorSupplier { @BeforeTemplate @@ -112,7 +112,7 @@ Mono after(Supplier supplier) { /** * Don't unnecessarily pass {@link Flux#error(Supplier)} a method reference or lambda expression. */ - // XXX: Drop this rule once the more general rule `AssortedTemplates#SupplierAsSupplier` works + // XXX: Drop this rule once the more general rule `AssortedRules#SupplierAsSupplier` works // reliably. static final class FluxErrorSupplier { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/RxJava2AdapterRules.java similarity index 96% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/RxJava2AdapterRules.java index 5384b9fbf7..b03245c7b1 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/RxJava2AdapterRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.errorprone.refaster.Refaster; import com.google.errorprone.refaster.annotation.AfterTemplate; @@ -14,9 +14,9 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -/** Refaster templates related to expressions dealing with {@link RxJava2Adapter}. */ -final class RxJava2AdapterTemplates { - private RxJava2AdapterTemplates() {} +/** Refaster rules related to expressions dealing with {@link RxJava2Adapter}. */ +final class RxJava2AdapterRules { + private RxJava2AdapterRules() {} /** Use the fluent API style when using {@link RxJava2Adapter#completableToMono}. */ static final class CompletableToMono { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/StreamTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java similarity index 98% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/StreamTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java index 375d67f622..336393e151 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/StreamTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static java.util.Comparator.naturalOrder; @@ -23,9 +23,9 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -/** Refaster templates related to expressions dealing with {@link Stream}s. */ -final class StreamTemplates { - private StreamTemplates() {} +/** Refaster rules related to expressions dealing with {@link Stream}s. */ +final class StreamRules { + private StreamRules() {} /** * Prefer {@link Collectors#joining()} over {@link Collectors#joining(CharSequence)} with an empty diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/StringTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java similarity index 94% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/StringTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java index 7b7707bfed..3e01463f68 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/StringTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.joining; @@ -18,10 +18,10 @@ import java.util.function.Function; import javax.annotation.Nullable; -/** Refaster templates related to expressions dealing with {@link String}s. */ +/** Refaster rules related to expressions dealing with {@link String}s. */ // XXX: Should we prefer `s -> !s.isEmpty()` or `not(String::isEmpty)`? -final class StringTemplates { - private StringTemplates() {} +final class StringRules { + private StringRules() {} /** Prefer {@link String#isEmpty()} over alternatives that consult the string's length. */ static final class StringIsEmpty { @@ -128,8 +128,8 @@ String after(Object object) { * Prefer direct delegation to {@link String#valueOf(Object)} over the indirection introduced by * {@link Objects#toString(Object)}. */ - // XXX: This template is analogous to `StringValueOf` above. Arguably this is its generalization. - // If/when Refaster is extended to understand this, delete the template above. + // XXX: This rule is analogous to `StringValueOf` above. Arguably this is its generalization. + // If/when Refaster is extended to understand this, delete the rule above. static final class StringValueOfMethodReference { @BeforeTemplate Function before() { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TestNGToAssertJRules.java similarity index 98% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TestNGToAssertJRules.java index 23f36f7865..e49014fb0f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TestNGToAssertJRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static org.assertj.core.api.Assertions.assertThat; @@ -30,7 +30,7 @@ import org.testng.Assert.ThrowingRunnable; /** - * Refaster templates that replace TestNG assertions with equivalent AssertJ assertions. + * Refaster rules that replace TestNG assertions with equivalent AssertJ assertions. * *

Some of the classes below have TestNG {@code @BeforeTemplate}s that reference wildcard type * bounds ({@code }), while the associated AssertJ {@code @AfterTemplate}s reference stricter @@ -69,11 +69,11 @@ * * */ -// XXX: As-is these templates do not result in a complete migration: +// XXX: As-is these rules do not result in a complete migration: // - Expressions containing comments are skipped due to a limitation of Refaster. // - Assertions inside lambda expressions are also skipped. Unclear why. -final class TestNGToAssertJTemplates { - private TestNGToAssertJTemplates() {} +final class TestNGToAssertJRules { + private TestNGToAssertJRules() {} static final class Fail { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/TimeTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TimeRules.java similarity index 98% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/TimeTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TimeRules.java index d7e9fa8432..6b33428dc6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/TimeTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TimeRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static java.time.ZoneOffset.UTC; @@ -22,9 +22,9 @@ import java.time.temporal.ChronoUnit; import java.time.temporal.TemporalUnit; -/** Refaster templates related to expressions dealing with time. */ -final class TimeTemplates { - private TimeTemplates() {} +/** Refaster rules related to expressions dealing with time. */ +final class TimeRules { + private TimeRules() {} /** * Prefer {@link Clock#instant()} over {@link Instant#now(Clock)}, as it is more concise and more diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/WebClientTemplates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/WebClientRules.java similarity index 97% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/WebClientTemplates.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/WebClientRules.java index 57b5cb850b..8452f00d17 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/WebClientTemplates.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/WebClientRules.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.HEAD; @@ -22,11 +22,11 @@ import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec; /** - * Refaster templates related to expressions dealing with {@link + * Refaster rules related to expressions dealing with {@link * org.springframework.web.reactive.function.client.WebClient} and related types. */ -final class WebClientTemplates { - private WebClientTemplates() {} +final class WebClientRules { + private WebClientRules() {} /** Prefer {@link RequestBodySpec#bodyValue(Object)} over more contrived alternatives. */ static final class BodyValue { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/package-info.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/package-info.java similarity index 54% rename from error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/package-info.java rename to error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/package-info.java index 42b5bc948b..d3da8852c7 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refastertemplates/package-info.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/package-info.java @@ -1,4 +1,4 @@ -/** Picnic Refaster templates. */ +/** Picnic Refaster rules. */ @com.google.errorprone.annotations.CheckReturnValue @javax.annotation.ParametersAreNonnullByDefault -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotationTest.java index 3611a2f6f8..74b2fcbfa0 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotationTest.java @@ -11,7 +11,7 @@ final class MissingRefasterAnnotationTest { .expectErrorMessage( "X", containsPattern( - "The Refaster template contains a method without any Refaster annotations")); + "The Refaster rule contains a method without any Refaster annotations")); @Test void identification() { @@ -74,17 +74,17 @@ void identification() { " }", " }", "", - " static final class ValidRefasterTemplate {", + " static final class ValidRefasterRule {", " @BeforeTemplate", " void unusedPureFunctionCall(Object o) {", " o.toString();", " }", " }", "", - " static final class NotARefasterTemplate {", + " static final class NotARefasterRule {", " @Override", " public String toString() {", - " return \"This is not a Refaster template\";", + " return \"This is not a Refaster rule\";", " }", " }", "}") diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterTemplateModifiersTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiersTest.java similarity index 96% rename from error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterTemplateModifiersTest.java rename to error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiersTest.java index 574f4081b8..c21a784925 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterTemplateModifiersTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiersTest.java @@ -5,11 +5,11 @@ import com.google.errorprone.CompilationTestHelper; import org.junit.jupiter.api.Test; -final class RefasterTemplateModifiersTest { +final class RefasterRuleModifiersTest { private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(RefasterTemplateModifiers.class, getClass()); + CompilationTestHelper.newInstance(RefasterRuleModifiers.class, getClass()); private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(RefasterTemplateModifiers.class, getClass()); + BugCheckerRefactoringTestHelper.newInstance(RefasterRuleModifiers.class, getClass()); @Test void identification() { diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java new file mode 100644 index 0000000000..be11145750 --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java @@ -0,0 +1,83 @@ +package tech.picnic.errorprone.refasterrules; + +import static java.util.function.Predicate.not; + +import com.google.common.collect.ImmutableSet; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollection; + +final class RefasterRulesTest { + /** The names of all Refaster rule groups defined in this module. */ + private static final ImmutableSet> RULE_COLLECTIONS = + ImmutableSet.of( + AssertJRules.class, + AssertJBigDecimalRules.class, + AssertJBigIntegerRules.class, + AssertJBooleanRules.class, + AssertJByteRules.class, + AssertJCharSequenceRules.class, + AssertJComparableRules.class, + AssertJDoubleRules.class, + AssertJEnumerableRules.class, + AssertJFloatRules.class, + AssertJIntegerRules.class, + AssertJLongRules.class, + AssertJNumberRules.class, + AssertJMapRules.class, + AssertJObjectRules.class, + AssertJOptionalRules.class, + AssertJPrimitiveRules.class, + AssertJShortRules.class, + AssertJStringRules.class, + AssertJThrowingCallableRules.class, + AssortedRules.class, + BigDecimalRules.class, + CollectionRules.class, + ComparatorRules.class, + DoubleStreamRules.class, + EqualityRules.class, + ImmutableListRules.class, + ImmutableListMultimapRules.class, + ImmutableMapRules.class, + ImmutableMultisetRules.class, + ImmutableSetRules.class, + ImmutableSetMultimapRules.class, + ImmutableSortedMapRules.class, + ImmutableSortedMultisetRules.class, + ImmutableSortedSetRules.class, + IntStreamRules.class, + JUnitRules.class, + LongStreamRules.class, + MapEntryRules.class, + MockitoRules.class, + MultimapRules.class, + NullRules.class, + OptionalRules.class, + PrimitiveRules.class, + ReactorRules.class, + RxJava2AdapterRules.class, + StreamRules.class, + StringRules.class, + TestNGToAssertJRules.class, + TimeRules.class, + WebClientRules.class); + + // XXX: Create a JUnit extension to automatically discover the rule collections in a given context + // to make sure the list is exhaustive. + private static Stream validateRuleCollectionTestCases() { + // XXX: Drop the filter once we have added tests for AssertJ! We can then also replace this + // method with `@ValueSource(classes = {...})`. + return RULE_COLLECTIONS.stream() + .filter(not(AssertJRules.class::equals)) + .map(Arguments::arguments); + } + + @MethodSource("validateRuleCollectionTestCases") + @ParameterizedTest + void validateRuleCollection(Class clazz) { + RefasterRuleCollection.validate(clazz); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplatesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplatesTest.java deleted file mode 100644 index b739216bcd..0000000000 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refastertemplates/RefasterTemplatesTest.java +++ /dev/null @@ -1,83 +0,0 @@ -package tech.picnic.errorprone.refastertemplates; - -import static java.util.function.Predicate.not; - -import com.google.common.collect.ImmutableSet; -import java.util.stream.Stream; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import tech.picnic.errorprone.refaster.test.RefasterTemplateCollection; - -final class RefasterTemplatesTest { - /** The names of all Refaster template groups defined in this module. */ - private static final ImmutableSet> TEMPLATE_COLLECTIONS = - ImmutableSet.of( - AssertJTemplates.class, - AssertJBigDecimalTemplates.class, - AssertJBigIntegerTemplates.class, - AssertJBooleanTemplates.class, - AssertJByteTemplates.class, - AssertJCharSequenceTemplates.class, - AssertJComparableTemplates.class, - AssertJDoubleTemplates.class, - AssertJEnumerableTemplates.class, - AssertJFloatTemplates.class, - AssertJIntegerTemplates.class, - AssertJLongTemplates.class, - AssertJNumberTemplates.class, - AssertJMapTemplates.class, - AssertJObjectTemplates.class, - AssertJOptionalTemplates.class, - AssertJPrimitiveTemplates.class, - AssertJShortTemplates.class, - AssertJStringTemplates.class, - AssertJThrowingCallableTemplates.class, - AssortedTemplates.class, - BigDecimalTemplates.class, - CollectionTemplates.class, - ComparatorTemplates.class, - DoubleStreamTemplates.class, - EqualityTemplates.class, - ImmutableListTemplates.class, - ImmutableListMultimapTemplates.class, - ImmutableMapTemplates.class, - ImmutableMultisetTemplates.class, - ImmutableSetTemplates.class, - ImmutableSetMultimapTemplates.class, - ImmutableSortedMapTemplates.class, - ImmutableSortedMultisetTemplates.class, - ImmutableSortedSetTemplates.class, - IntStreamTemplates.class, - JUnitTemplates.class, - LongStreamTemplates.class, - MapEntryTemplates.class, - MockitoTemplates.class, - MultimapTemplates.class, - NullTemplates.class, - OptionalTemplates.class, - PrimitiveTemplates.class, - ReactorTemplates.class, - RxJava2AdapterTemplates.class, - StreamTemplates.class, - StringTemplates.class, - TestNGToAssertJTemplates.class, - TimeTemplates.class, - WebClientTemplates.class); - - // XXX: Create a JUnit extension to automatically discover the template collections in a given - // context to make sure the list is exhaustive. - private static Stream validateTemplateCollectionTestCases() { - // XXX: Drop the filter once we have added tests for AssertJ! We can then also replace this - // method with `@ValueSource(classes = {...})`. - return TEMPLATE_COLLECTIONS.stream() - .filter(not(AssertJTemplates.class::equals)) - .map(Arguments::arguments); - } - - @MethodSource("validateTemplateCollectionTestCases") - @ParameterizedTest - void validateTemplateCollection(Class clazz) { - RefasterTemplateCollection.validate(clazz); - } -} diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigDecimalRulesTestInput.java similarity index 83% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigDecimalRulesTestInput.java index c8ecc2ecb8..6f33a5c231 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigDecimalRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -7,9 +7,9 @@ import com.google.common.collect.ImmutableSet; import java.math.BigDecimal; import org.assertj.core.api.AbstractBigDecimalAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJBigDecimalTemplatesTest implements RefasterTemplateTestCase { +final class AssertJBigDecimalRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(offset(0), withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigDecimalRulesTestOutput.java similarity index 83% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigDecimalRulesTestOutput.java index 9807aa5488..9fc72e7b8d 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigDecimalTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigDecimalRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -7,9 +7,9 @@ import com.google.common.collect.ImmutableSet; import java.math.BigDecimal; import org.assertj.core.api.AbstractBigDecimalAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJBigDecimalTemplatesTest implements RefasterTemplateTestCase { +final class AssertJBigDecimalRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(offset(0), withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigIntegerRulesTestInput.java similarity index 90% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigIntegerRulesTestInput.java index 3bbbcf0380..b3feb861e5 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigIntegerRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -7,9 +7,9 @@ import com.google.common.collect.ImmutableSet; import java.math.BigInteger; import org.assertj.core.api.AbstractBigIntegerAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJBigIntegerTemplatesTest implements RefasterTemplateTestCase { +final class AssertJBigIntegerRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(offset(0), withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigIntegerRulesTestOutput.java similarity index 89% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigIntegerRulesTestOutput.java index 9674b649dd..ea2fa45766 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBigIntegerTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBigIntegerRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -7,9 +7,9 @@ import com.google.common.collect.ImmutableSet; import java.math.BigInteger; import org.assertj.core.api.AbstractBigIntegerAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJBigIntegerTemplatesTest implements RefasterTemplateTestCase { +final class AssertJBigIntegerRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(offset(0), withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBooleanRulesTestInput.java similarity index 86% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBooleanRulesTestInput.java index 9181a58247..4993f7c707 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBooleanRulesTestInput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractBooleanAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJBooleanTemplatesTest implements RefasterTemplateTestCase { +final class AssertJBooleanRulesTest implements RefasterRuleCollectionTestCase { AbstractBooleanAssert testAbstractBooleanAssertIsEqualTo() { return assertThat(true).isNotEqualTo(!Boolean.FALSE); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBooleanRulesTestOutput.java similarity index 85% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBooleanRulesTestOutput.java index da458b13b9..e7d11d1e78 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJBooleanTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJBooleanRulesTestOutput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractBooleanAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJBooleanTemplatesTest implements RefasterTemplateTestCase { +final class AssertJBooleanRulesTest implements RefasterRuleCollectionTestCase { AbstractBooleanAssert testAbstractBooleanAssertIsEqualTo() { return assertThat(true).isEqualTo(Boolean.FALSE); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJByteRulesTestInput.java similarity index 85% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJByteRulesTestInput.java index f9a7b2607e..2db99cbb37 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJByteRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractByteAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJByteTemplatesTest implements RefasterTemplateTestCase { +final class AssertJByteRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(offset(0), withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJByteRulesTestOutput.java similarity index 85% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJByteRulesTestOutput.java index ea274127a4..5f740bde41 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJByteTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJByteRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractByteAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJByteTemplatesTest implements RefasterTemplateTestCase { +final class AssertJByteRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(offset(0), withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJCharSequenceRulesTestInput.java similarity index 74% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJCharSequenceRulesTestInput.java index 3cad90b1a0..e45d056c69 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJCharSequenceRulesTestInput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJCharSequenceTemplatesTest implements RefasterTemplateTestCase { +final class AssertJCharSequenceRulesTest implements RefasterRuleCollectionTestCase { void testAssertThatCharSequenceIsEmpty() { assertThat("foo".length()).isEqualTo(0L); assertThat("foo".length()).isNotPositive(); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJCharSequenceRulesTestOutput.java similarity index 72% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJCharSequenceRulesTestOutput.java index 9d0fc29bb3..50f906a537 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJCharSequenceTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJCharSequenceRulesTestOutput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJCharSequenceTemplatesTest implements RefasterTemplateTestCase { +final class AssertJCharSequenceRulesTest implements RefasterRuleCollectionTestCase { void testAssertThatCharSequenceIsEmpty() { assertThat("foo").isEmpty(); assertThat("foo").isEmpty(); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJComparableRulesTestInput.java similarity index 84% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJComparableRulesTestInput.java index 9d3793f23d..6863c8b828 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJComparableRulesTestInput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import java.math.BigDecimal; import org.assertj.core.api.AbstractComparableAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJComparableTemplatesTest implements RefasterTemplateTestCase { +final class AssertJComparableRulesTest implements RefasterRuleCollectionTestCase { AbstractComparableAssert testAssertThatIsEqualByComparingTo() { return assertThat(BigDecimal.ZERO.compareTo(BigDecimal.ONE)).isEqualTo(0); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJComparableRulesTestOutput.java similarity index 83% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJComparableRulesTestOutput.java index 8ff2093d8d..a7378f5212 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJComparableTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJComparableRulesTestOutput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import java.math.BigDecimal; import org.assertj.core.api.AbstractComparableAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJComparableTemplatesTest implements RefasterTemplateTestCase { +final class AssertJComparableRulesTest implements RefasterRuleCollectionTestCase { AbstractComparableAssert testAssertThatIsEqualByComparingTo() { return assertThat(BigDecimal.ZERO).isEqualByComparingTo(BigDecimal.ONE); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJDoubleRulesTestInput.java similarity index 87% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJDoubleRulesTestInput.java index 04eb0c7206..232265e98b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJDoubleRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractDoubleAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJDoubleTemplatesTest implements RefasterTemplateTestCase { +final class AssertJDoubleRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJDoubleRulesTestOutput.java similarity index 86% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJDoubleRulesTestOutput.java index 12ec9c93be..62acf54d33 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJDoubleTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJDoubleRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractDoubleAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJDoubleTemplatesTest implements RefasterTemplateTestCase { +final class AssertJDoubleRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJEnumerableRulesTestInput.java similarity index 84% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJEnumerableRulesTestInput.java index 2ef8511104..7157710f77 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJEnumerableRulesTestInput.java @@ -1,13 +1,13 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import org.assertj.core.api.EnumerableAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJEnumerableTemplatesTest implements RefasterTemplateTestCase { +final class AssertJEnumerableRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Iterables.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJEnumerableRulesTestOutput.java similarity index 83% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJEnumerableRulesTestOutput.java index 5c46789db9..2f676a8eb7 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJEnumerableTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJEnumerableRulesTestOutput.java @@ -1,13 +1,13 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import org.assertj.core.api.EnumerableAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJEnumerableTemplatesTest implements RefasterTemplateTestCase { +final class AssertJEnumerableRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Iterables.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJFloatRulesTestInput.java similarity index 87% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJFloatRulesTestInput.java index 54b4fac623..caaa12de81 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJFloatRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractFloatAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJFloatTemplatesTest implements RefasterTemplateTestCase { +final class AssertJFloatRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJFloatRulesTestOutput.java similarity index 86% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJFloatRulesTestOutput.java index 40b9626372..e2c4fd0fdb 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJFloatTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJFloatRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractFloatAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJFloatTemplatesTest implements RefasterTemplateTestCase { +final class AssertJFloatRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJIntegerRulesTestInput.java similarity index 84% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJIntegerRulesTestInput.java index 6b4b7a38c3..9c69c87c3d 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJIntegerRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractIntegerAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJIntegerTemplatesTest implements RefasterTemplateTestCase { +final class AssertJIntegerRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(offset(0), withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJIntegerRulesTestOutput.java similarity index 84% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJIntegerRulesTestOutput.java index 87613912ff..495cf18588 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJIntegerTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJIntegerRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractIntegerAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJIntegerTemplatesTest implements RefasterTemplateTestCase { +final class AssertJIntegerRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(offset(0), withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJLongRulesTestInput.java similarity index 85% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJLongRulesTestInput.java index b55a52774f..7c3bcc4e28 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJLongRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractLongAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJLongTemplatesTest implements RefasterTemplateTestCase { +final class AssertJLongRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(offset(0), withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJLongRulesTestOutput.java similarity index 84% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJLongRulesTestOutput.java index 1c7a851983..81692bf1d1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJLongTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJLongRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractLongAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJLongTemplatesTest implements RefasterTemplateTestCase { +final class AssertJLongRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(offset(0), withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestInput.java similarity index 74% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestInput.java index 84d9fb02d3..064430f62a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestInput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableMap; import org.assertj.core.api.AbstractMapAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJMapTemplatesTest implements RefasterTemplateTestCase { +final class AssertJMapRulesTest implements RefasterRuleCollectionTestCase { AbstractMapAssert testAbstractMapAssertContainsExactlyInAnyOrderEntriesOf() { return assertThat(ImmutableMap.of(1, 2, 3, 4)).isEqualTo(ImmutableMap.of(1, 2, 3, 4)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestOutput.java similarity index 74% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestOutput.java index 65d1a3b4cb..a5e58f23b0 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJMapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestOutput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableMap; import org.assertj.core.api.AbstractMapAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJMapTemplatesTest implements RefasterTemplateTestCase { +final class AssertJMapRulesTest implements RefasterRuleCollectionTestCase { AbstractMapAssert testAbstractMapAssertContainsExactlyInAnyOrderEntriesOf() { return assertThat(ImmutableMap.of(1, 2, 3, 4)) diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJNumberRulesTestInput.java similarity index 95% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJNumberRulesTestInput.java index ce5773aabe..7b3d027d97 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJNumberRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; @@ -6,9 +6,9 @@ import java.math.BigDecimal; import java.math.BigInteger; import org.assertj.core.api.NumberAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJNumberTemplatesTest implements RefasterTemplateTestCase { +final class AssertJNumberRulesTest implements RefasterRuleCollectionTestCase { ImmutableSet> testNumberAssertIsPositive() { return ImmutableSet.of( assertThat((byte) 0).isGreaterThan((byte) 0), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJNumberRulesTestOutput.java similarity index 95% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJNumberRulesTestOutput.java index 227fedf57e..e141a90742 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJNumberTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJNumberRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; @@ -6,9 +6,9 @@ import java.math.BigDecimal; import java.math.BigInteger; import org.assertj.core.api.NumberAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJNumberTemplatesTest implements RefasterTemplateTestCase { +final class AssertJNumberRulesTest implements RefasterRuleCollectionTestCase { ImmutableSet> testNumberAssertIsPositive() { return ImmutableSet.of( assertThat((byte) 0).isPositive(), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJObjectRulesTestInput.java similarity index 77% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJObjectRulesTestInput.java index 391c6b1228..ce37306575 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJObjectRulesTestInput.java @@ -1,11 +1,11 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import org.assertj.core.api.AbstractAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJObjectTemplatesTest implements RefasterTemplateTestCase { +final class AssertJObjectRulesTest implements RefasterRuleCollectionTestCase { AbstractAssert testAssertThatIsInstanceOf() { return assertThat("foo" instanceof String).isTrue(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJObjectRulesTestOutput.java similarity index 77% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJObjectRulesTestOutput.java index 3e68603b4a..0af2474fe8 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJObjectTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJObjectRulesTestOutput.java @@ -1,11 +1,11 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import org.assertj.core.api.AbstractAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJObjectTemplatesTest implements RefasterTemplateTestCase { +final class AssertJObjectRulesTest implements RefasterRuleCollectionTestCase { AbstractAssert testAssertThatIsInstanceOf() { return assertThat("foo").isInstanceOf(String.class); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJOptionalRulesTestInput.java similarity index 90% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJOptionalRulesTestInput.java index ca6be8ec0b..e337bfb108 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJOptionalRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; @@ -6,9 +6,9 @@ import java.util.Optional; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.OptionalAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJOptionalTemplatesTest implements RefasterTemplateTestCase { +final class AssertJOptionalRulesTest implements RefasterRuleCollectionTestCase { AbstractAssert testAssertThatOptional() { return assertThat(Optional.of(new Object()).orElseThrow()); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJOptionalRulesTestOutput.java similarity index 89% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJOptionalRulesTestOutput.java index df5f706c31..e0ec85491b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJOptionalTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJOptionalRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; @@ -6,9 +6,9 @@ import java.util.Optional; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.OptionalAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJOptionalTemplatesTest implements RefasterTemplateTestCase { +final class AssertJOptionalRulesTest implements RefasterRuleCollectionTestCase { AbstractAssert testAssertThatOptional() { return assertThat(Optional.of(new Object())).get(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitiveTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJPrimitiveRulesTestInput.java similarity index 95% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitiveTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJPrimitiveRulesTestInput.java index ace0e0e6c3..d4740aae59 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitiveTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJPrimitiveRulesTestInput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJPrimitiveTemplatesTest implements RefasterTemplateTestCase { +final class AssertJPrimitiveRulesTest implements RefasterRuleCollectionTestCase { @SuppressWarnings("SimplifyBooleanExpression") ImmutableSet> testAssertThatIsEqualTo() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitiveTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJPrimitiveRulesTestOutput.java similarity index 96% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitiveTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJPrimitiveRulesTestOutput.java index 7215bbfb8c..e556908b27 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJPrimitiveTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJPrimitiveRulesTestOutput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJPrimitiveTemplatesTest implements RefasterTemplateTestCase { +final class AssertJPrimitiveRulesTest implements RefasterRuleCollectionTestCase { @SuppressWarnings("SimplifyBooleanExpression") ImmutableSet> testAssertThatIsEqualTo() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJShortRulesTestInput.java similarity index 86% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJShortRulesTestInput.java index e4fc739373..6114d86177 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJShortRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractShortAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJShortTemplatesTest implements RefasterTemplateTestCase { +final class AssertJShortRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(offset(0), withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJShortRulesTestOutput.java similarity index 85% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJShortRulesTestOutput.java index 58beb71e24..463bea8e37 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJShortTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJShortRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.data.Offset.offset; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractShortAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJShortTemplatesTest implements RefasterTemplateTestCase { +final class AssertJShortRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(offset(0), withPercentage(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestInput.java similarity index 79% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestInput.java index e699740a83..7efb588db8 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestInput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractStringAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJStringTemplatesTest implements RefasterTemplateTestCase { +final class AssertJStringRulesTest implements RefasterRuleCollectionTestCase { void testAbstractStringAssertStringIsEmpty() { assertThat("foo").isEqualTo(""); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestOutput.java similarity index 78% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestOutput.java index 1e048f94a2..f0d8293bd9 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJStringTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestOutput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractStringAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJStringTemplatesTest implements RefasterTemplateTestCase { +final class AssertJStringRulesTest implements RefasterRuleCollectionTestCase { void testAbstractStringAssertStringIsEmpty() { assertThat("foo").isEmpty(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestInput.java similarity index 96% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestInput.java index 4f43569189..3dc64aeaad 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIOException; @@ -10,9 +10,9 @@ import com.google.common.collect.ImmutableSet; import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.AbstractThrowableAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJThrowingCallableTemplatesTest implements RefasterTemplateTestCase { +final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestOutput.java similarity index 96% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestOutput.java index 3e2fb68076..c00ed335e7 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssertJThrowingCallableTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatIOException; @@ -11,9 +11,9 @@ import java.io.IOException; import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.AbstractThrowableAssert; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssertJThrowingCallableTemplatesTest implements RefasterTemplateTestCase { +final class AssertJThrowingCallableRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssortedRulesTestInput.java similarity index 94% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssortedRulesTestInput.java index d4023e4546..6c1398a39c 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssortedRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSet.toImmutableSet; @@ -17,9 +17,9 @@ import java.util.HashSet; import java.util.Map; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssortedTemplatesTest implements RefasterTemplateTestCase { +final class AssortedRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssortedRulesTestOutput.java similarity index 94% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssortedRulesTestOutput.java index 10809a7134..7a9a91cb73 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/AssortedTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssortedRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.Sets.toImmutableEnumSet; @@ -21,9 +21,9 @@ import java.util.Map; import java.util.Objects; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class AssortedTemplatesTest implements RefasterTemplateTestCase { +final class AssortedRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java similarity index 77% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java index 878b1bac28..37db5459ce 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java @@ -1,10 +1,10 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import java.math.BigDecimal; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class BigDecimalTemplatesTest implements RefasterTemplateTestCase { +final class BigDecimalRulesTest implements RefasterRuleCollectionTestCase { ImmutableSet testBigDecimalZero() { return ImmutableSet.of(BigDecimal.valueOf(0), BigDecimal.valueOf(0L), new BigDecimal("0")); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java similarity index 75% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java index 1a379ce9f7..8be65ad520 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/BigDecimalTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java @@ -1,10 +1,10 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import java.math.BigDecimal; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class BigDecimalTemplatesTest implements RefasterTemplateTestCase { +final class BigDecimalRulesTest implements RefasterRuleCollectionTestCase { ImmutableSet testBigDecimalZero() { return ImmutableSet.of(BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java similarity index 97% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java index b2509efd1b..c5c3f686d5 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -12,9 +12,9 @@ import java.util.Optional; import java.util.TreeSet; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class CollectionTemplatesTest implements RefasterTemplateTestCase { +final class CollectionRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Iterables.class, Lists.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java similarity index 96% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java index cbbf3dbdae..7d580729cc 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/CollectionTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -12,9 +12,9 @@ import java.util.Optional; import java.util.TreeSet; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class CollectionTemplatesTest implements RefasterTemplateTestCase { +final class CollectionRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Iterables.class, Lists.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestInput.java similarity index 95% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestInput.java index dee75ddac8..961a5f21c0 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static java.util.Comparator.naturalOrder; import static java.util.Comparator.reverseOrder; @@ -10,9 +10,9 @@ import java.util.Collections; import java.util.Comparator; import java.util.function.BinaryOperator; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ComparatorTemplatesTest implements RefasterTemplateTestCase { +final class ComparatorRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java similarity index 94% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java index e6cd9d1aa8..b2a54f06a1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ComparatorTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static java.util.Comparator.naturalOrder; import static java.util.Comparator.reverseOrder; @@ -11,9 +11,9 @@ import java.util.Collections; import java.util.Comparator; import java.util.function.BinaryOperator; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ComparatorTemplatesTest implements RefasterTemplateTestCase { +final class ComparatorRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java similarity index 93% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java index 37bd64f8f7..9c35f9c651 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; @@ -6,9 +6,9 @@ import java.util.function.DoublePredicate; import java.util.stream.DoubleStream; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class DoubleStreamTemplatesTest implements RefasterTemplateTestCase { +final class DoubleStreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java similarity index 93% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java index de39e49000..0f5c7db8eb 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/DoubleStreamTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; @@ -6,9 +6,9 @@ import java.util.function.DoublePredicate; import java.util.stream.DoubleStream; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class DoubleStreamTemplatesTest implements RefasterTemplateTestCase { +final class DoubleStreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestInput.java similarity index 89% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestInput.java index 129fe4eaf1..e887e5a0ca 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestInput.java @@ -1,13 +1,13 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.BoundType; import com.google.common.collect.ImmutableSet; import java.math.RoundingMode; import java.util.Objects; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class EqualityTemplatesTest implements RefasterTemplateTestCase { +final class EqualityRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Objects.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestOutput.java similarity index 89% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestOutput.java index 907e4768ce..b3aa30245a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/EqualityTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/EqualityRulesTestOutput.java @@ -1,13 +1,13 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.BoundType; import com.google.common.collect.ImmutableSet; import java.math.RoundingMode; import java.util.Objects; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class EqualityTemplatesTest implements RefasterTemplateTestCase { +final class EqualityRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Objects.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableListMultimapRulesTestInput.java similarity index 96% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableListMultimapRulesTestInput.java index f840b67d17..287e550a99 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableListMultimapRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableListMultimap.flatteningToImmutableListMultimap; import static com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap; @@ -16,9 +16,9 @@ import com.google.common.collect.TreeMultimap; import java.util.Map; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableListMultimapTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableListMultimapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableListMultimapRulesTestOutput.java similarity index 95% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableListMultimapRulesTestOutput.java index 7f7e7888b0..cfed18e6fa 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListMultimapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableListMultimapRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableListMultimap.flatteningToImmutableListMultimap; import static com.google.common.collect.ImmutableListMultimap.toImmutableListMultimap; @@ -16,9 +16,9 @@ import com.google.common.collect.TreeMultimap; import java.util.Map; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableListMultimapTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableListMultimapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableListRulesTestInput.java similarity index 94% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableListRulesTestInput.java index 0afd20b0e1..8a8623f0bf 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableListRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableList.toImmutableList; import static java.util.Comparator.naturalOrder; @@ -11,9 +11,9 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableListTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableListRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableListRulesTestOutput.java similarity index 93% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableListRulesTestOutput.java index 915ab1e1df..6a026f8c45 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableListTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableListRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableSet.toImmutableSet; @@ -12,9 +12,9 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableListTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableListRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestInput.java similarity index 95% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestInput.java index b2667b9f58..b4cd5f950e 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableMap.toImmutableMap; import static java.util.function.Function.identity; @@ -12,9 +12,9 @@ import java.util.Collections; import java.util.Map; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableMapTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableMapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Collections.class, Streams.class, identity()); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestOutput.java similarity index 94% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestOutput.java index 77153c7466..4c1ddf948f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableMap.toImmutableMap; import static java.util.function.Function.identity; @@ -12,9 +12,9 @@ import java.util.Collections; import java.util.Map; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableMapTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableMapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Collections.class, Streams.class, identity()); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMultisetRulesTestInput.java similarity index 89% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMultisetRulesTestInput.java index 92f4ed84f1..efeeb2db39 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMultisetRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableMultiset.toImmutableMultiset; @@ -8,9 +8,9 @@ import com.google.common.collect.Streams; import java.util.Arrays; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableMultisetTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableMultisetRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Arrays.class, Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMultisetRulesTestOutput.java similarity index 87% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMultisetRulesTestOutput.java index 84f5122d84..297b316717 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableMultisetTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMultisetRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableMultiset.toImmutableMultiset; @@ -8,9 +8,9 @@ import com.google.common.collect.Streams; import java.util.Arrays; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableMultisetTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableMultisetRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Arrays.class, Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetMultimapRulesTestInput.java similarity index 95% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetMultimapRulesTestInput.java index 2f2cd08f0c..8ac6542589 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetMultimapRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSetMultimap.flatteningToImmutableSetMultimap; import static com.google.common.collect.ImmutableSetMultimap.toImmutableSetMultimap; @@ -13,9 +13,9 @@ import com.google.common.collect.TreeMultimap; import java.util.Map; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableSetMultimapTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableSetMultimapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Streams.class, flatteningToImmutableSetMultimap(null, null)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetMultimapRulesTestOutput.java similarity index 94% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetMultimapRulesTestOutput.java index f887977a8b..5f358443ef 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetMultimapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetMultimapRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSetMultimap.flatteningToImmutableSetMultimap; import static com.google.common.collect.ImmutableSetMultimap.toImmutableSetMultimap; @@ -13,9 +13,9 @@ import com.google.common.collect.TreeMultimap; import java.util.Map; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableSetMultimapTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableSetMultimapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Streams.class, flatteningToImmutableSetMultimap(null, null)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestInput.java similarity index 92% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestInput.java index d2b38ad2ac..9a457ff05b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSet.toImmutableSet; @@ -10,9 +10,9 @@ import java.util.Collections; import java.util.Set; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableSetTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableSetRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Arrays.class, Collections.class, Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestOutput.java similarity index 91% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestOutput.java index e6ad2e44ad..21e612a36f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSetTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSet.toImmutableSet; @@ -10,9 +10,9 @@ import java.util.Collections; import java.util.Set; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableSetTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableSetRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Arrays.class, Collections.class, Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRulesTestInput.java similarity index 92% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRulesTestInput.java index a2df4ae2b0..45fef73d29 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSortedMap.toImmutableSortedMap; import static java.util.Comparator.naturalOrder; @@ -10,9 +10,9 @@ import java.util.Comparator; import java.util.Map; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableSortedMapTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableSortedMapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRulesTestOutput.java similarity index 91% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRulesTestOutput.java index 7f394fa1f1..9955c0c540 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSortedMap.toImmutableSortedMap; import static java.util.Comparator.naturalOrder; @@ -10,9 +10,9 @@ import java.util.Comparator; import java.util.Map; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableSortedMapTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableSortedMapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMultisetRulesTestInput.java similarity index 92% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMultisetRulesTestInput.java index 085fb1e8c6..0906733c3b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMultisetRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSortedMultiset.toImmutableSortedMultiset; import static java.util.Comparator.naturalOrder; @@ -11,9 +11,9 @@ import java.util.Arrays; import java.util.Comparator; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableSortedMultisetTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableSortedMultisetRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Arrays.class, Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMultisetRulesTestOutput.java similarity index 91% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMultisetRulesTestOutput.java index 843c2922e6..ffcba2930a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedMultisetTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMultisetRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSortedMultiset.toImmutableSortedMultiset; import static java.util.Comparator.naturalOrder; @@ -11,9 +11,9 @@ import java.util.Arrays; import java.util.Comparator; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableSortedMultisetTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableSortedMultisetRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Arrays.class, Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedSetRulesTestInput.java similarity index 92% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedSetRulesTestInput.java index 4a90a87457..a1d8f80f4c 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedSetRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet; import static java.util.Comparator.naturalOrder; @@ -10,9 +10,9 @@ import java.util.Arrays; import java.util.Comparator; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableSortedSetTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableSortedSetRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Arrays.class, Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedSetRulesTestOutput.java similarity index 91% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedSetRulesTestOutput.java index b944a2ef31..5fa58dbbfe 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ImmutableSortedSetTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedSetRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSortedSet.toImmutableSortedSet; import static java.util.Comparator.naturalOrder; @@ -10,9 +10,9 @@ import java.util.Arrays; import java.util.Comparator; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ImmutableSortedSetTemplatesTest implements RefasterTemplateTestCase { +final class ImmutableSortedSetRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Arrays.class, Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java similarity index 93% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java index 03cf380352..32458e2bbb 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; @@ -6,9 +6,9 @@ import java.util.function.IntPredicate; import java.util.stream.IntStream; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class IntStreamTemplatesTest implements RefasterTemplateTestCase { +final class IntStreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java similarity index 93% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java index c40930f27a..c75ce7bb7f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/IntStreamTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; @@ -6,9 +6,9 @@ import java.util.function.IntPredicate; import java.util.stream.IntStream; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class IntStreamTemplatesTest implements RefasterTemplateTestCase { +final class IntStreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitRulesTestInput.java similarity index 59% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitRulesTestInput.java index 77c83e8916..25ebb0d566 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitRulesTestInput.java @@ -1,10 +1,10 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import org.junit.jupiter.params.provider.Arguments; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class JUnitTemplatesTest implements RefasterTemplateTestCase { +final class JUnitRulesTest implements RefasterRuleCollectionTestCase { ImmutableSet testArgumentsEnumeration() { return ImmutableSet.of( Arguments.of("foo"), Arguments.of(1, "foo", 2, "bar"), Arguments.of(new Object())); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitRulesTestOutput.java similarity index 63% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitRulesTestOutput.java index 13151144b2..45dba93b76 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/JUnitTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitRulesTestOutput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.junit.jupiter.params.provider.Arguments.arguments; import com.google.common.collect.ImmutableSet; import org.junit.jupiter.params.provider.Arguments; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class JUnitTemplatesTest implements RefasterTemplateTestCase { +final class JUnitRulesTest implements RefasterRuleCollectionTestCase { ImmutableSet testArgumentsEnumeration() { return ImmutableSet.of( arguments("foo"), arguments(1, "foo", 2, "bar"), arguments(new Object())); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java similarity index 93% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java index 51a32a1d3a..3909ce3df7 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; @@ -6,9 +6,9 @@ import java.util.function.LongPredicate; import java.util.stream.LongStream; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class LongStreamTemplatesTest implements RefasterTemplateTestCase { +final class LongStreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java similarity index 93% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java index c87219b7fd..b585534a33 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/LongStreamTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; @@ -6,9 +6,9 @@ import java.util.function.LongPredicate; import java.util.stream.LongStream; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class LongStreamTemplatesTest implements RefasterTemplateTestCase { +final class LongStreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapEntryRulesTestInput.java similarity index 87% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapEntryRulesTestInput.java index e829d26833..99b40dd7e2 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapEntryRulesTestInput.java @@ -1,13 +1,13 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import java.util.AbstractMap; import java.util.Comparator; import java.util.Map; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class MapEntryTemplatesTest implements RefasterTemplateTestCase { +final class MapEntryRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(AbstractMap.class, Maps.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapEntryRulesTestOutput.java similarity index 85% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapEntryRulesTestOutput.java index 056bb169ee..39cfa9c280 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MapEntryTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapEntryRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static java.util.Map.Entry.comparingByKey; import static java.util.Map.Entry.comparingByValue; @@ -8,9 +8,9 @@ import java.util.AbstractMap; import java.util.Comparator; import java.util.Map; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class MapEntryTemplatesTest implements RefasterTemplateTestCase { +final class MapEntryRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(AbstractMap.class, Maps.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MockitoRulesTestInput.java similarity index 70% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MockitoRulesTestInput.java index f48eec9c48..667bd22081 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MockitoRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import org.mockito.verification.VerificationMode; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class MockitoTemplatesTest implements RefasterTemplateTestCase { +final class MockitoRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(times(1)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MockitoRulesTestOutput.java similarity index 72% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MockitoRulesTestOutput.java index 367ffba744..292faf3524 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MockitoTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MockitoRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -7,9 +7,9 @@ import com.google.common.collect.ImmutableSet; import org.mockito.verification.VerificationMode; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class MockitoTemplatesTest implements RefasterTemplateTestCase { +final class MockitoRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(times(1)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MultimapRulesTestInput.java similarity index 80% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MultimapRulesTestInput.java index 3348249ba7..d11347fa16 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MultimapRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; @@ -6,9 +6,9 @@ import com.google.common.collect.Multimaps; import java.util.Collection; import java.util.Set; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class MultimapTemplatesTest implements RefasterTemplateTestCase { +final class MultimapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Multimaps.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MultimapRulesTestOutput.java similarity index 79% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MultimapRulesTestOutput.java index 0aeab3fc01..417de18ab1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/MultimapTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MultimapRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; @@ -6,9 +6,9 @@ import com.google.common.collect.Multimaps; import java.util.Collection; import java.util.Set; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class MultimapTemplatesTest implements RefasterTemplateTestCase { +final class MultimapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Multimaps.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/NullRulesTestInput.java similarity index 78% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/NullRulesTestInput.java index 971c3324ee..9163673a5f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/NullRulesTestInput.java @@ -1,12 +1,12 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableSet; import java.util.Objects; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class NullTemplatesTest implements RefasterTemplateTestCase { +final class NullRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(MoreObjects.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/NullRulesTestOutput.java similarity index 78% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/NullRulesTestOutput.java index ed066a5599..4867d0089d 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/NullTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/NullRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static java.util.Objects.requireNonNullElse; @@ -6,9 +6,9 @@ import com.google.common.collect.ImmutableSet; import java.util.Objects; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class NullTemplatesTest implements RefasterTemplateTestCase { +final class NullRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(MoreObjects.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestInput.java similarity index 95% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestInput.java index 02c027c3d9..d06d9da7d9 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestInput.java @@ -1,13 +1,13 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; import java.util.Optional; import java.util.function.Function; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class OptionalTemplatesTest implements RefasterTemplateTestCase { +final class OptionalRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestOutput.java similarity index 94% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestOutput.java index 3c2d94dab9..e20f6b4a6f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/OptionalTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.Streams.stream; @@ -7,9 +7,9 @@ import java.util.Optional; import java.util.function.Function; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class OptionalTemplatesTest implements RefasterTemplateTestCase { +final class OptionalRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Streams.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestInput.java similarity index 87% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestInput.java index c94bdc65a2..c3b5d3d5c9 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestInput.java @@ -1,10 +1,10 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import com.google.common.primitives.Ints; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class PrimitiveTemplatesTest implements RefasterTemplateTestCase { +final class PrimitiveRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Ints.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestOutput.java similarity index 86% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestOutput.java index 0c7e1034c8..a9d675f0a5 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/PrimitiveTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestOutput.java @@ -1,10 +1,10 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import com.google.common.primitives.Ints; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class PrimitiveTemplatesTest implements RefasterTemplateTestCase { +final class PrimitiveRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Ints.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java similarity index 96% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index aef41daaca..cbf5cc888f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.assertj.core.api.Assertions.assertThat; @@ -12,9 +12,9 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.test.publisher.PublisherProbe; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ReactorTemplatesTest implements RefasterTemplateTestCase { +final class ReactorRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(assertThat(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java similarity index 96% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index a57a3c561a..94daf79ec9 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/ReactorTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.MoreCollectors.toOptional; import static java.util.function.Function.identity; @@ -14,9 +14,9 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.test.publisher.PublisherProbe; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class ReactorTemplatesTest implements RefasterTemplateTestCase { +final class ReactorRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(assertThat(0)); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/RxJava2AdapterRulesTestInput.java similarity index 93% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/RxJava2AdapterRulesTestInput.java index 415a6954a1..5562a671b2 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/RxJava2AdapterRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import io.reactivex.BackpressureStrategy; @@ -10,9 +10,9 @@ import reactor.adapter.rxjava.RxJava2Adapter; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class RxJava2AdapterTemplatesTest implements RefasterTemplateTestCase { +final class RxJava2AdapterRulesTest implements RefasterRuleCollectionTestCase { ImmutableSet> testCompletableToMono() { return ImmutableSet.of( RxJava2Adapter.completableToMono(Completable.complete()), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/RxJava2AdapterRulesTestOutput.java similarity index 94% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/RxJava2AdapterRulesTestOutput.java index ab093b0c0b..6a088d1435 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/RxJava2AdapterTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/RxJava2AdapterRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import io.reactivex.BackpressureStrategy; @@ -10,9 +10,9 @@ import reactor.adapter.rxjava.RxJava2Adapter; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class RxJava2AdapterTemplatesTest implements RefasterTemplateTestCase { +final class RxJava2AdapterRulesTest implements RefasterRuleCollectionTestCase { ImmutableSet> testCompletableToMono() { return ImmutableSet.of( Completable.complete().as(RxJava2Adapter::completableToMono), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java similarity index 95% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java index f59538c6b0..67911c452f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static java.util.Comparator.comparingInt; import static java.util.Comparator.reverseOrder; @@ -11,9 +11,9 @@ import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class StreamTemplatesTest implements RefasterTemplateTestCase { +final class StreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Objects.class, Streams.class, not(null), reverseOrder()); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java similarity index 95% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java index c41746138d..87e7619539 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StreamTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static java.util.Comparator.comparingInt; import static java.util.Comparator.naturalOrder; @@ -13,9 +13,9 @@ import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class StreamTemplatesTest implements RefasterTemplateTestCase { +final class StreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Objects.class, Streams.class, not(null), reverseOrder()); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestInput.java similarity index 93% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestInput.java index af94e0a546..f70407c02b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.joining; @@ -14,9 +14,9 @@ import java.util.Optional; import java.util.function.Function; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class StringTemplatesTest implements RefasterTemplateTestCase { +final class StringRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestOutput.java similarity index 92% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestOutput.java index 9e85aa5782..723cfe3ce3 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/StringTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.stream.Collectors.joining; @@ -15,9 +15,9 @@ import java.util.Optional; import java.util.function.Function; import java.util.stream.Stream; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class StringTemplatesTest implements RefasterTemplateTestCase { +final class StringRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TestNGToAssertJRulesTestInput.java similarity index 97% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TestNGToAssertJRulesTestInput.java index 34d0a9fd48..91e7999b5f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TestNGToAssertJRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEqualsNoOrder; @@ -17,9 +17,9 @@ import com.google.common.collect.Iterators; import java.util.ArrayList; import java.util.Collections; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class TestNGToAssertJTemplatesTest implements RefasterTemplateTestCase { +final class TestNGToAssertJRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TestNGToAssertJRulesTestOutput.java similarity index 98% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TestNGToAssertJRulesTestOutput.java index 496620306b..ba9ad9a409 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TestNGToAssertJTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TestNGToAssertJRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableList.copyOf; import static org.assertj.core.api.Assertions.assertThat; @@ -22,9 +22,9 @@ import com.google.common.collect.Iterators; import java.util.ArrayList; import java.util.Collections; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class TestNGToAssertJTemplatesTest implements RefasterTemplateTestCase { +final class TestNGToAssertJRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TimeRulesTestInput.java similarity index 96% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TimeRulesTestInput.java index 09060a69b1..b813403c0d 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TimeRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import java.time.Clock; @@ -13,9 +13,9 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class TimeTemplatesTest implements RefasterTemplateTestCase { +final class TimeRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(ChronoUnit.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TimeRulesTestOutput.java similarity index 95% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TimeRulesTestOutput.java index 215c93fe8c..2e411bcc19 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/TimeTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/TimeRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; import java.time.Clock; @@ -13,9 +13,9 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class TimeTemplatesTest implements RefasterTemplateTestCase { +final class TimeRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(ChronoUnit.class); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/WebClientRulesTestInput.java similarity index 92% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestInput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/WebClientRulesTestInput.java index 323899bb31..61a0cd2dfb 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/WebClientRulesTestInput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.HEAD; @@ -11,9 +11,9 @@ import com.google.common.collect.ImmutableSet; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.function.client.WebClient; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class WebClientTemplatesTest implements RefasterTemplateTestCase { +final class WebClientRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(fromValue(""), GET, HEAD, OPTIONS, PATCH, POST, PUT); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/WebClientRulesTestOutput.java similarity index 91% rename from error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestOutput.java rename to error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/WebClientRulesTestOutput.java index 9e0d57831d..fcdbf4c269 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refastertemplates/WebClientTemplatesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/WebClientRulesTestOutput.java @@ -1,4 +1,4 @@ -package tech.picnic.errorprone.refastertemplates; +package tech.picnic.errorprone.refasterrules; import static org.springframework.http.HttpMethod.GET; import static org.springframework.http.HttpMethod.HEAD; @@ -11,9 +11,9 @@ import com.google.common.collect.ImmutableSet; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.web.reactive.function.client.WebClient; -import tech.picnic.errorprone.refaster.test.RefasterTemplateTestCase; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; -final class WebClientTemplatesTest implements RefasterTemplateTestCase { +final class WebClientRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(fromValue(""), GET, HEAD, OPTIONS, PATCH, POST, PUT); diff --git a/pom.xml b/pom.xml index a456f64279..67001d1494 100644 --- a/pom.xml +++ b/pom.xml @@ -1230,10 +1230,9 @@ false - - tech.picnic.errorprone.refastertemplates + + tech.picnic.errorprone.refasterrules ${version.jdk} @@ -1368,7 +1367,7 @@ + check/rule under test. Ideally all test cases are realistic. --> -XepAllSuggestionsAsWarnings -Xep:MethodReferenceUsage:OFF diff --git a/refaster-compiler/pom.xml b/refaster-compiler/pom.xml index 049521617d..c494ab1dc0 100644 --- a/refaster-compiler/pom.xml +++ b/refaster-compiler/pom.xml @@ -11,7 +11,7 @@ refaster-compiler Picnic :: Error Prone Support :: Refaster Compiler - A Java compiler plugin that identifies and compiles Refaster templates, storing them as resource files on the classpath. + A Java compiler plugin that identifies and compiles Refaster rules, storing them as resource files on the classpath. diff --git a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompiler.java b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompiler.java index c78593e4bc..47dcdff99d 100644 --- a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompiler.java +++ b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompiler.java @@ -8,7 +8,7 @@ /** * A variant of {@code com.google.errorprone.refaster.RefasterRuleCompiler} that outputs a {@code * fully/qualified/Class.refaster} file for each compiled {@code fully.qualified.Class} that - * contains a Refaster template. + * contains a Refaster rule. */ @AutoService(Plugin.class) public final class RefasterRuleCompiler implements Plugin { diff --git a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java index e2940b1422..7731ee0810 100644 --- a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java +++ b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java @@ -54,21 +54,21 @@ public void finished(TaskEvent taskEvent) { } ClassTree tree = JavacTrees.instance(context).getTree(taskEvent.getTypeElement()); - if (tree == null || !containsRefasterTemplates(tree)) { + if (tree == null || !containsRefasterRules(tree)) { return; } - ImmutableListMultimap rules = compileRefasterTemplates(tree); + ImmutableListMultimap rules = compileRefasterRules(tree); for (Map.Entry> rule : Multimaps.asMap(rules).entrySet()) { try { outputCodeTransformers(rule.getValue(), getOutputFile(taskEvent, rule.getKey())); } catch (IOException e) { - throw new UncheckedIOException("Failed to persist compiled Refaster templates", e); + throw new UncheckedIOException("Failed to persist compiled Refaster rules", e); } } } - private boolean containsRefasterTemplates(ClassTree tree) { + private boolean containsRefasterRules(ClassTree tree) { return Boolean.TRUE.equals( new TreeScanner() { @Override @@ -87,8 +87,7 @@ public Boolean reduce(Boolean r1, Boolean r2) { }.scan(tree, null)); } - private ImmutableListMultimap compileRefasterTemplates( - ClassTree tree) { + private ImmutableListMultimap compileRefasterRules(ClassTree tree) { ListMultimap rules = ArrayListMultimap.create(); new TreeScanner() { @Nullable diff --git a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/package-info.java b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/package-info.java index 7a5be8d1f6..78b0583712 100644 --- a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/package-info.java +++ b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/package-info.java @@ -1,5 +1,5 @@ /** - * A Java compiler plugin that identifies and compiles Refaster templates, storing them as resource + * A Java compiler plugin that identifies and compiles Refaster rules, storing them as resource * files on the classpath. */ @com.google.errorprone.annotations.CheckReturnValue diff --git a/refaster-runner/pom.xml b/refaster-runner/pom.xml index 7bccf546c5..c0265fc3a7 100644 --- a/refaster-runner/pom.xml +++ b/refaster-runner/pom.xml @@ -11,7 +11,7 @@ refaster-runner Picnic :: Error Prone Support :: Refaster Runner - Exposes Refaster templates found on the classpath through a regular Error Prone check. + Exposes Refaster rules found on the classpath through a regular Error Prone check. diff --git a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/CodeTransformers.java b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/CodeTransformers.java index f3bde9fd0c..cda3004c0e 100644 --- a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/CodeTransformers.java +++ b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/CodeTransformers.java @@ -15,11 +15,11 @@ import java.util.function.Supplier; /** - * Scans the classpath for {@value #REFASTER_TEMPLATE_SUFFIX} files and loads them as {@link + * Scans the classpath for {@value #REFASTER_RULE_SUFFIX} files and loads them as {@link * CodeTransformer}s. */ public final class CodeTransformers { - private static final String REFASTER_TEMPLATE_SUFFIX = ".refaster"; + private static final String REFASTER_RULE_SUFFIX = ".refaster"; private static final Supplier> ALL_CODE_TRANSFORMERS = Suppliers.memoize(CodeTransformers::loadAllCodeTransformers); @@ -30,28 +30,28 @@ private CodeTransformers() {} * *

This method returns a cached view; all invocations except the first are very cheap. * - * @return A mapping from Refaster template names to associated {@link CodeTransformer}s. + * @return A mapping from Refaster rule names to associated {@link CodeTransformer}s. */ public static ImmutableListMultimap getAllCodeTransformers() { return ALL_CODE_TRANSFORMERS.get(); } /** - * Scans the classpath for compiled Refaster templates and returns the associated deserialized - * {@link CodeTransformer}s, indexed by their name. + * Scans the classpath for compiled Refaster rules and returns the associated deserialized {@link + * CodeTransformer}s, indexed by their name. * - * @return A mapping from Refaster template names to associated {@link CodeTransformer}s. + * @return A mapping from Refaster rule names to associated {@link CodeTransformer}s. */ private static ImmutableListMultimap loadAllCodeTransformers() { ImmutableListMultimap.Builder transformers = ImmutableListMultimap.builder(); for (ResourceInfo resource : getClassPathResources()) { - getRefasterTemplateName(resource) + getRefasterRuleName(resource) .ifPresent( - templateName -> + ruleName -> loadCodeTransformer(resource) - .ifPresent(transformer -> transformers.put(templateName, transformer))); + .ifPresent(transformer -> transformers.put(ruleName, transformer))); } return transformers.build(); @@ -65,15 +65,15 @@ private static ImmutableSet getClassPathResources() { } } - private static Optional getRefasterTemplateName(ResourceInfo resource) { + private static Optional getRefasterRuleName(ResourceInfo resource) { String resourceName = resource.getResourceName(); - if (!resourceName.endsWith(REFASTER_TEMPLATE_SUFFIX)) { + if (!resourceName.endsWith(REFASTER_RULE_SUFFIX)) { return Optional.empty(); } int lastPathSeparator = resourceName.lastIndexOf('/'); int beginIndex = lastPathSeparator < 0 ? 0 : lastPathSeparator + 1; - int endIndex = resourceName.length() - REFASTER_TEMPLATE_SUFFIX.length(); + int endIndex = resourceName.length() - REFASTER_RULE_SUFFIX.length(); return Optional.of(resourceName.substring(beginIndex, endIndex)); } diff --git a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java index 118475dbea..203e2fe25b 100644 --- a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java +++ b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java @@ -37,11 +37,11 @@ import java.util.stream.Stream; /** - * A {@link BugChecker} that flags code that can be simplified using Refaster templates located on - * the classpath. + * A {@link BugChecker} that flags code that can be simplified using Refaster rules located on the + * classpath. * *

This checker locates all {@code *.refaster} classpath resources and assumes they contain a - * {@link CodeTransformer}. The set of loaded Refaster templates can be restricted by passing {@code + * {@link CodeTransformer}. The set of loaded Refaster rules can be restricted by passing {@code * -XepOpt:Refaster:NamePattern=}. */ @AutoService(BugChecker.class) @@ -51,8 +51,8 @@ severity = SUGGESTION, tags = SIMPLIFICATION) public final class Refaster extends BugChecker implements CompilationUnitTreeMatcher { - /** Flag to pass a pattern that restricts which Refaster templates are loaded. */ - public static final String INCLUDED_TEMPLATES_PATTERN_FLAG = "Refaster:NamePattern"; + /** Flag to pass a pattern that restricts which Refaster rules are loaded. */ + public static final String INCLUDED_RULES_PATTERN_FLAG = "Refaster:NamePattern"; private static final long serialVersionUID = 1L; @@ -151,7 +151,7 @@ private static CodeTransformer createCompositeCodeTransformer(ErrorProneFlags fl CodeTransformers.getAllCodeTransformers(); return CompositeCodeTransformer.compose( flags - .get(INCLUDED_TEMPLATES_PATTERN_FLAG) + .get(INCLUDED_RULES_PATTERN_FLAG) .map(Pattern::compile) .>map( nameFilter -> filterCodeTransformers(allTransformers, nameFilter)) diff --git a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java index dc08a789c6..c10739493d 100644 --- a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java +++ b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java @@ -1,4 +1,4 @@ -/** Exposes Refaster templates found on the classpath through a regular Error Prone check. */ +/** Exposes Refaster rules found on the classpath through a regular Error Prone check. */ @com.google.errorprone.annotations.CheckReturnValue @javax.annotation.ParametersAreNonnullByDefault package tech.picnic.errorprone.refaster.runner; diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java index b4a2732102..5888f03422 100644 --- a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java @@ -7,11 +7,11 @@ final class CodeTransformersTest { /** * Verifies that {@link CodeTransformers#getAllCodeTransformers()} finds the code transformer - * compiled from {@link FooTemplates} on the classpath. + * compiled from {@link FooRules} on the classpath. */ @Test void getAllCodeTransformers() { assertThat(CodeTransformers.getAllCodeTransformers().keySet()) - .containsExactly("FooTemplates$SimpleTemplate"); + .containsExactly("FooRules$SimpleRule"); } } diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooTemplates.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooRules.java similarity index 64% rename from refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooTemplates.java rename to refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooRules.java index 0625275d9f..be79875a47 100644 --- a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooTemplates.java +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooRules.java @@ -3,12 +3,12 @@ import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; -/** An example template collection used to test {@link CodeTransformers}. */ -final class FooTemplates { - private FooTemplates() {} +/** An example rule collection used to test {@link CodeTransformers}. */ +final class FooRules { + private FooRules() {} - /** Simple template for testing purposes. */ - static final class SimpleTemplate { + /** Simple rule for testing purposes. */ + static final class SimpleRule { @BeforeTemplate boolean before(String string) { return string.toCharArray().length == 0; diff --git a/refaster-support/pom.xml b/refaster-support/pom.xml index a4e65ea140..51680fc3f4 100644 --- a/refaster-support/pom.xml +++ b/refaster-support/pom.xml @@ -11,7 +11,7 @@ refaster-support Picnic :: Error Prone Support :: Refaster Support - Helper utilities for use with Refaster templates. + Helper utilities for use with Refaster rules. + @@ -821,6 +825,11 @@ error_prone_core ${version.error-prone} + + com.google.auto.value + auto-value + ${version.auto-value} + com.google.auto.service auto-service @@ -1256,6 +1265,9 @@ pitest-maven 1.9.8 + + *.AutoValue_* + @@ -1318,6 +1330,23 @@ + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + true + + + + + + -XepAllErrorsAsWarnings + + -XepDisableWarningsInGeneratedCode diff --git a/refaster-compiler/pom.xml b/refaster-compiler/pom.xml index c494ab1dc0..dc43b58dfa 100644 --- a/refaster-compiler/pom.xml +++ b/refaster-compiler/pom.xml @@ -27,6 +27,10 @@ ${groupId.error-prone} error_prone_core + + ${project.groupId} + refaster-support + com.google.auto.service auto-service-annotations diff --git a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java index 7731ee0810..3c13b74d67 100644 --- a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java +++ b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java @@ -1,12 +1,12 @@ package tech.picnic.errorprone.refaster.plugin; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ImmutableListMultimap; -import com.google.common.collect.ListMultimap; -import com.google.common.collect.Multimaps; +import com.google.common.collect.ImmutableClassToInstanceMap; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; import com.google.errorprone.CodeTransformer; -import com.google.errorprone.CompositeCodeTransformer; import com.google.errorprone.refaster.RefasterRuleBuilderScanner; +import com.google.errorprone.refaster.UTemplater; import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.AnnotationTree; @@ -26,12 +26,13 @@ import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.UncheckedIOException; -import java.util.List; +import java.lang.annotation.Annotation; import java.util.Map; import javax.annotation.Nullable; import javax.tools.FileObject; import javax.tools.JavaFileManager; import javax.tools.StandardLocation; +import tech.picnic.errorprone.refaster.AnnotatedCompositeCodeTransformer; /** * A variant of {@code com.google.errorprone.refaster.RefasterRuleCompilerAnalyzer} that stores @@ -58,26 +59,60 @@ public void finished(TaskEvent taskEvent) { return; } - ImmutableListMultimap rules = compileRefasterRules(tree); - for (Map.Entry> rule : Multimaps.asMap(rules).entrySet()) { + ImmutableMap rules = compileRefasterRules(tree); + for (Map.Entry rule : rules.entrySet()) { try { - outputCodeTransformers(rule.getValue(), getOutputFile(taskEvent, rule.getKey())); + outputCodeTransformer(rule.getValue(), getOutputFile(taskEvent, rule.getKey())); } catch (IOException e) { throw new UncheckedIOException("Failed to persist compiled Refaster rules", e); } } } - private boolean containsRefasterRules(ClassTree tree) { + private ImmutableMap compileRefasterRules(ClassTree tree) { + ImmutableMap.Builder rules = ImmutableMap.builder(); + new TreeScanner>() { + @Nullable + @Override + public Void visitClass(ClassTree node, ImmutableClassToInstanceMap annotations) { + ClassSymbol symbol = ASTHelpers.getSymbol(node); + + ImmutableList transformers = + ImmutableList.copyOf(RefasterRuleBuilderScanner.extractRules(node, context)); + if (!transformers.isEmpty()) { + rules.put( + node, + AnnotatedCompositeCodeTransformer.create( + toPackageName(symbol), transformers, annotations)); + } + + return super.visitClass(node, merge(annotations, UTemplater.annotationMap(symbol))); + } + }.scan(tree, ImmutableClassToInstanceMap.of()); + return rules.buildOrThrow(); + } + + private FileObject getOutputFile(TaskEvent taskEvent, ClassTree tree) throws IOException { + ClassSymbol symbol = ASTHelpers.getSymbol(tree); + + JavaFileManager fileManager = context.get(JavaFileManager.class); + return fileManager.getFileForOutput( + StandardLocation.CLASS_OUTPUT, + toPackageName(symbol), + toSimpleFlatName(symbol) + ".refaster", + taskEvent.getSourceFile()); + } + + private static boolean containsRefasterRules(ClassTree tree) { return Boolean.TRUE.equals( new TreeScanner() { @Override - public Boolean visitAnnotation(AnnotationTree node, @Nullable Void v) { + public Boolean visitAnnotation(AnnotationTree node, @Nullable Void unused) { Symbol sym = ASTHelpers.getSymbol(node); return (sym != null && sym.getQualifiedName() .contentEquals(BeforeTemplate.class.getCanonicalName())) - || super.visitAnnotation(node, v); + || super.visitAnnotation(node, unused); } @Override @@ -87,40 +122,31 @@ public Boolean reduce(Boolean r1, Boolean r2) { }.scan(tree, null)); } - private ImmutableListMultimap compileRefasterRules(ClassTree tree) { - ListMultimap rules = ArrayListMultimap.create(); - new TreeScanner() { - @Nullable - @Override - public Void visitClass(ClassTree node, @Nullable Void v) { - rules.putAll(node, RefasterRuleBuilderScanner.extractRules(node, context)); - return super.visitClass(node, null); - } - }.scan(tree, null); - return ImmutableListMultimap.copyOf(rules); + /** Merges two annotation mappings, preferring the second over the first in case of conflicts. */ + private static ImmutableClassToInstanceMap merge( + ImmutableClassToInstanceMap first, + ImmutableClassToInstanceMap second) { + return ImmutableClassToInstanceMap.builder() + .putAll(Maps.filterKeys(first, k -> !second.containsKey(k))) + .putAll(second) + .build(); } - private FileObject getOutputFile(TaskEvent taskEvent, ClassTree tree) throws IOException { - ClassSymbol symbol = ASTHelpers.getSymbol(tree); + private static String toPackageName(ClassSymbol symbol) { PackageSymbol enclosingPackage = ASTHelpers.enclosingPackage(symbol); - String packageName = enclosingPackage == null ? "" : enclosingPackage.toString(); - String relativeName = toSimpleFlatName(symbol) + ".refaster"; - - JavaFileManager fileManager = context.get(JavaFileManager.class); - return fileManager.getFileForOutput( - StandardLocation.CLASS_OUTPUT, packageName, relativeName, taskEvent.getSourceFile()); + return enclosingPackage == null ? "" : enclosingPackage.toString(); } - private static CharSequence toSimpleFlatName(ClassSymbol classSymbol) { - Name flatName = classSymbol.flatName(); + private static CharSequence toSimpleFlatName(ClassSymbol symbol) { + Name flatName = symbol.flatName(); int lastDot = flatName.lastIndexOf((byte) '.'); return lastDot < 0 ? flatName : flatName.subSequence(lastDot + 1, flatName.length()); } - private static void outputCodeTransformers(List rules, FileObject target) + private static void outputCodeTransformer(CodeTransformer codeTransformer, FileObject target) throws IOException { try (ObjectOutput output = new ObjectOutputStream(target.openOutputStream())) { - output.writeObject(CompositeCodeTransformer.compose(rules)); + output.writeObject(codeTransformer); } } } diff --git a/refaster-runner/pom.xml b/refaster-runner/pom.xml index c0265fc3a7..9bdd3a65ed 100644 --- a/refaster-runner/pom.xml +++ b/refaster-runner/pom.xml @@ -29,6 +29,11 @@ error_prone_check_api provided + + ${groupId.error-prone} + error_prone_test_helpers + test + ${project.groupId} refaster-compiler @@ -37,6 +42,10 @@ `annotationProcessorPaths` configuration below. --> provided + + ${project.groupId} + refaster-support + com.google.auto.service auto-service-annotations @@ -67,6 +76,11 @@ junit-jupiter-engine test + + org.junit.jupiter + junit-jupiter-params + test + diff --git a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java index 203e2fe25b..ef3b70161f 100644 --- a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java +++ b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java @@ -3,7 +3,9 @@ import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.ImmutableRangeSet.toImmutableRangeSet; import static com.google.errorprone.BugPattern.LinkType.NONE; +import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; +import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; import static com.google.errorprone.BugPattern.StandardTags.SIMPLIFICATION; import static java.util.function.Predicate.not; @@ -16,9 +18,11 @@ import com.google.common.collect.RangeSet; import com.google.common.collect.TreeRangeSet; import com.google.errorprone.BugPattern; +import com.google.errorprone.BugPattern.SeverityLevel; import com.google.errorprone.CodeTransformer; import com.google.errorprone.CompositeCodeTransformer; import com.google.errorprone.ErrorProneFlags; +import com.google.errorprone.ErrorProneOptions.Severity; import com.google.errorprone.SubContext; import com.google.errorprone.VisitorState; import com.google.errorprone.annotations.CanIgnoreReturnValue; @@ -33,6 +37,7 @@ import java.util.Comparator; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -40,8 +45,8 @@ * A {@link BugChecker} that flags code that can be simplified using Refaster rules located on the * classpath. * - *

This checker locates all {@code *.refaster} classpath resources and assumes they contain a - * {@link CodeTransformer}. The set of loaded Refaster rules can be restricted by passing {@code + *

This checker locates all {@code *.refaster} classpath resources and assumes that they contain + * a {@link CodeTransformer}. The set of loaded Refaster rules can be restricted by passing {@code * -XepOpt:Refaster:NamePattern=}. */ @AutoService(BugChecker.class) @@ -104,7 +109,7 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s */ // XXX: This selection logic solves an issue described in // https://github.com/google/error-prone/issues/559. Consider contributing it back upstream. - private static void applyMatches( + private void applyMatches( Iterable allMatches, EndPosTable endPositions, VisitorState state) { ImmutableList byReplacementSize = ImmutableList.sortedCopyOf( @@ -118,12 +123,55 @@ private static void applyMatches( ImmutableRangeSet ranges = getReplacementRanges(description, endPositions); if (ranges.asRanges().stream().noneMatch(replacedSections::intersects)) { /* This suggested fix does not overlap with any ("larger") replacement seen until now. Apply it. */ - state.reportMatch(description); + state.reportMatch(augmentDescription(description, getSeverityOverride(state))); replacedSections.addAll(ranges); } } } + private Optional getSeverityOverride(VisitorState state) { + return Optional.ofNullable(state.errorProneOptions().getSeverityMap().get(canonicalName())) + .flatMap(Refaster::toSeverityLevel); + } + + private static Optional toSeverityLevel(Severity severity) { + switch (severity) { + case DEFAULT: + return Optional.empty(); + case WARN: + return Optional.of(WARNING); + case ERROR: + return Optional.of(ERROR); + default: + throw new IllegalStateException(String.format("Unsupported severity='%s'", severity)); + } + } + + /** + * Updates the given {@link Description}'s details by standardizing the reported check name, + * updating the associated message, and optionally overriding its severity. + * + *

The assigned severity is overridden only if this bug checker's severity was explicitly + * configured. + * + *

The original check name (i.e. the Refaster rule name) is prepended to the {@link + * Description}'s message. The replacement check name ("Refaster Rule", a name which includes a + * space) is chosen such that it is guaranteed not to match any canonical bug checker name (as + * that could cause {@link VisitorState#reportMatch(Description)}} to override the reported + * severity). + */ + private static Description augmentDescription( + Description description, Optional severityOverride) { + return Description.builder( + description.position, + "Refaster Rule", + description.getLink(), + severityOverride.orElse(description.severity), + String.join(": ", description.checkName, description.getRawMessage())) + .addAllFixes(description.fixes) + .build(); + } + private static int getReplacedCodeSize(Description description, EndPosTable endPositions) { return getReplacements(description, endPositions).mapToInt(Replacement::length).sum(); } diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java index 5888f03422..5a2a71980d 100644 --- a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/CodeTransformersTest.java @@ -6,12 +6,17 @@ final class CodeTransformersTest { /** - * Verifies that {@link CodeTransformers#getAllCodeTransformers()} finds the code transformer + * Verifies that {@link CodeTransformers#getAllCodeTransformers()} finds the code transformers * compiled from {@link FooRules} on the classpath. */ @Test void getAllCodeTransformers() { assertThat(CodeTransformers.getAllCodeTransformers().keySet()) - .containsExactly("FooRules$SimpleRule"); + .containsExactlyInAnyOrder( + "FooRules$StringOfSizeZeroRule", + "FooRules$StringOfSizeZeroVerboseRule", + "FooRules$StringOfSizeOneRule", + "FooRules$ExtraGrouping$StringOfSizeTwoRule", + "FooRules$ExtraGrouping$StringOfSizeThreeRule"); } } diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooRules.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooRules.java index be79875a47..df20e66eb7 100644 --- a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooRules.java +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/FooRules.java @@ -1,14 +1,21 @@ package tech.picnic.errorprone.refaster.runner; +import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; +import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; +import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; + import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; +import tech.picnic.errorprone.refaster.annotation.Description; +import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; +import tech.picnic.errorprone.refaster.annotation.Severity; -/** An example rule collection used to test {@link CodeTransformers}. */ +/** An example rule collection used to test {@link CodeTransformers} and {@link Refaster}. */ final class FooRules { private FooRules() {} - /** Simple rule for testing purposes. */ - static final class SimpleRule { + /** A simple rule for testing purposes, lacking any custom annotations. */ + static final class StringOfSizeZeroRule { @BeforeTemplate boolean before(String string) { return string.toCharArray().length == 0; @@ -19,4 +26,73 @@ boolean after(String string) { return string.isEmpty(); } } + + /** + * A simple rule for testing purposes, matching the same set of expressions as {@link + * StringOfSizeZeroRule}, but producing a larger replacement string. + */ + static final class StringOfSizeZeroVerboseRule { + @BeforeTemplate + boolean before(String string) { + return string.toCharArray().length == 0; + } + + @AfterTemplate + boolean after(String string) { + return string.length() + 1 == 1; + } + } + + /** A simple rule for testing purposes, having several custom annotations. */ + @Description("A custom description about matching single-char strings") + @OnlineDocumentation + @Severity(WARNING) + static final class StringOfSizeOneRule { + @BeforeTemplate + boolean before(String string) { + return string.toCharArray().length == 1; + } + + @AfterTemplate + boolean after(String string) { + return string.length() == 1; + } + } + + /** A nested class with annotations that are inherited by the Refaster rules contained in it. */ + @Description("A custom subgroup description") + @OnlineDocumentation("https://example.com/rule/${topLevelClassName}#${nestedClassName}") + @Severity(ERROR) + static final class ExtraGrouping { + private ExtraGrouping() {} + + /** A simple rule for testing purposes, inheriting custom annotations. */ + static final class StringOfSizeTwoRule { + @BeforeTemplate + boolean before(String string) { + return string.toCharArray().length == 2; + } + + @AfterTemplate + boolean after(String string) { + return string.length() == 2; + } + } + + /** A simple rule for testing purposes, overriding custom annotations. */ + @Description("A custom description about matching three-char strings") + @OnlineDocumentation("https://example.com/custom") + @Severity(SUGGESTION) + static final class StringOfSizeThreeRule { + @BeforeTemplate + boolean before(String string) { + return string.toCharArray().length == 3; + } + + @AfterTemplate + boolean after(String string) { + return string.length() == 3; + } + } + } } diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java new file mode 100644 index 0000000000..8ec4e5122c --- /dev/null +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java @@ -0,0 +1,272 @@ +package tech.picnic.errorprone.refaster.runner; + +import static com.google.common.base.Predicates.containsPattern; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; +import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; +import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; +import static java.util.Comparator.comparingInt; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.params.provider.Arguments.arguments; + +import com.google.common.collect.ImmutableList; +import com.google.errorprone.BugCheckerInfo; +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; +import com.google.errorprone.BugPattern.SeverityLevel; +import com.google.errorprone.CompilationTestHelper; +import java.util.regex.Pattern; +import java.util.stream.Stream; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import tech.picnic.errorprone.refaster.ErrorProneFork; + +final class RefasterTest { + private final CompilationTestHelper compilationHelper = + CompilationTestHelper.newInstance(Refaster.class, getClass()) + .matchAllDiagnostics() + .expectErrorMessage( + "StringOfSizeZeroRule", + containsPattern( + "\\[Refaster Rule\\] FooRules\\.StringOfSizeZeroRule: Refactoring opportunity\\s+.+\\s+")) + .expectErrorMessage( + "StringOfSizeOneRule", + containsPattern( + "\\[Refaster Rule\\] FooRules\\.StringOfSizeOneRule: " + + "A custom description about matching single-char strings\\s+.+\\s+" + + "\\(see https://error-prone.picnic.tech/refasterrules/FooRules#StringOfSizeOneRule\\)")) + .expectErrorMessage( + "StringOfSizeTwoRule", + containsPattern( + "\\[Refaster Rule\\] FooRules\\.ExtraGrouping\\.StringOfSizeTwoRule: " + + "A custom subgroup description\\s+.+\\s+" + + "\\(see https://example.com/rule/FooRules#ExtraGrouping.StringOfSizeTwoRule\\)")) + .expectErrorMessage( + "StringOfSizeThreeRule", + containsPattern( + "\\[Refaster Rule\\] FooRules\\.ExtraGrouping\\.StringOfSizeThreeRule: " + + "A custom description about matching three-char strings\\s+.+\\s+" + + "\\(see https://example.com/custom\\)")); + private final BugCheckerRefactoringTestHelper refactoringTestHelper = + BugCheckerRefactoringTestHelper.newInstance(Refaster.class, getClass()); + private final BugCheckerRefactoringTestHelper restrictedRefactoringTestHelper = + BugCheckerRefactoringTestHelper.newInstance(Refaster.class, getClass()) + .setArgs( + "-XepOpt:Refaster:NamePattern=.*\\$(StringOfSizeZeroVerboseRule|StringOfSizeTwoRule)$"); + + @Test + void identification() { + compilationHelper + .addSourceLines( + "A.java", + "class A {", + " void m() {", + " // BUG: Diagnostic matches: StringOfSizeZeroRule", + " boolean b1 = \"foo\".toCharArray().length == 0;", + " // BUG: Diagnostic matches: StringOfSizeOneRule", + " boolean b2 = \"bar\".toCharArray().length == 1;", + " // BUG: Diagnostic matches: StringOfSizeTwoRule", + " boolean b3 = \"baz\".toCharArray().length == 2;", + " // BUG: Diagnostic matches: StringOfSizeThreeRule", + " boolean b4 = \"qux\".toCharArray().length == 3;", + " }", + "}") + .doTest(); + } + + private static Stream severityAssignmentTestCases() { + /* + * The _actual_ default severity is assigned by the `CodeTransformer`s to which the `Refaster` + * bug checker delegates. Here we verify that the absence of an `@Severity` annotation yields + * the same severity as the bug checker's declared severity. + */ + SeverityLevel defaultSeverity = BugCheckerInfo.create(Refaster.class).defaultSeverity(); + + /* { arguments, expectedSeverities } */ + return Stream.concat( + Stream.of( + arguments( + ImmutableList.of(), ImmutableList.of(defaultSeverity, WARNING, ERROR, SUGGESTION)), + arguments(ImmutableList.of("-Xep:Refaster:OFF"), ImmutableList.of()), + arguments( + ImmutableList.of("-Xep:Refaster:DEFAULT"), + ImmutableList.of(defaultSeverity, WARNING, ERROR, SUGGESTION)), + arguments( + ImmutableList.of("-Xep:Refaster:WARN"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), + arguments( + ImmutableList.of("-Xep:Refaster:ERROR"), + ImmutableList.of(ERROR, ERROR, ERROR, ERROR)), + arguments( + ImmutableList.of("-XepAllErrorsAsWarnings"), + ImmutableList.of(defaultSeverity, WARNING, WARNING, SUGGESTION)), + arguments( + ImmutableList.of("-Xep:Refaster:OFF", "-XepAllErrorsAsWarnings"), + ImmutableList.of()), + arguments( + ImmutableList.of("-Xep:Refaster:DEFAULT", "-XepAllErrorsAsWarnings"), + ImmutableList.of(defaultSeverity, WARNING, WARNING, SUGGESTION)), + arguments( + ImmutableList.of("-Xep:Refaster:WARN", "-XepAllErrorsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), + arguments( + ImmutableList.of("-Xep:Refaster:ERROR", "-XepAllErrorsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING))), + ErrorProneFork.isErrorProneForkAvailable() + ? Stream.of( + arguments( + ImmutableList.of("-Xep:Refaster:OFF", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of()), + arguments( + ImmutableList.of("-Xep:Refaster:DEFAULT", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(WARNING, WARNING, ERROR, WARNING)), + arguments( + ImmutableList.of("-Xep:Refaster:WARN", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), + arguments( + ImmutableList.of("-Xep:Refaster:ERROR", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(ERROR, ERROR, ERROR, ERROR)), + arguments( + ImmutableList.of( + "-Xep:Refaster:OFF", + "-XepAllErrorsAsWarnings", + "-XepAllSuggestionsAsWarnings"), + ImmutableList.of()), + arguments( + ImmutableList.of( + "-Xep:Refaster:DEFAULT", + "-XepAllErrorsAsWarnings", + "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), + arguments( + ImmutableList.of( + "-Xep:Refaster:WARN", + "-XepAllErrorsAsWarnings", + "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), + arguments( + ImmutableList.of( + "-Xep:Refaster:ERROR", + "-XepAllErrorsAsWarnings", + "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING))) + : Stream.empty()); + } + + /** + * Verifies that the bug checker flags refactoring opportunities with the appropriate severity + * level. + * + * @implNote This test setup is rather cumbersome, because {@link CompilationTestHelper} does not + * enable direct assertions against the severity of collected diagnostics output. + */ + @MethodSource("severityAssignmentTestCases") + @ParameterizedTest + void severityAssignment( + ImmutableList arguments, ImmutableList expectedSeverities) { + assertThatThrownBy( + () -> + compilationHelper + .setArgs(arguments) + .addSourceLines( + "A.java", + "class A {", + " void m() {", + " boolean[] bs = {", + " \"foo\".toCharArray().length == 0,", + " \"bar\".toCharArray().length == 1,", + " \"baz\".toCharArray().length == 2,", + " \"qux\".toCharArray().length == 3", + " };", + " }", + "}") + .doTest()) + .isInstanceOf(AssertionError.class) + .message() + .satisfies( + message -> + assertThat(extractRefasterSeverities("A.java", message)) + .containsExactlyElementsOf(expectedSeverities)); + } + + private static ImmutableList extractRefasterSeverities( + String fileName, String message) { + return Pattern.compile( + String.format( + "/%s:(\\d+): (Note|warning|error): \\[Refaster Rule\\]", Pattern.quote(fileName))) + .matcher(message) + .results() + .sorted(comparingInt(r -> Integer.parseInt(r.group(1)))) + .map(r -> toSeverityLevel(r.group(2))) + .collect(toImmutableList()); + } + + private static SeverityLevel toSeverityLevel(String compilerDiagnosticsPrefix) { + switch (compilerDiagnosticsPrefix) { + case "Note": + return SUGGESTION; + case "warning": + return WARNING; + case "error": + return ERROR; + default: + throw new IllegalStateException( + String.format("Unrecognized diagnostics prefix '%s'", compilerDiagnosticsPrefix)); + } + } + + @Test + void replacement() { + refactoringTestHelper + .addInputLines( + "A.java", + "class A {", + " void m() {", + " boolean b1 = \"foo\".toCharArray().length == 0;", + " boolean b2 = \"bar\".toCharArray().length == 1;", + " boolean b3 = \"baz\".toCharArray().length == 2;", + " boolean b4 = \"qux\".toCharArray().length == 3;", + " }", + "}") + .addOutputLines( + "A.java", + "class A {", + " void m() {", + " boolean b1 = \"foo\".isEmpty();", + " boolean b2 = \"bar\".length() == 1;", + " boolean b3 = \"baz\".length() == 2;", + " boolean b4 = \"qux\".length() == 3;", + " }", + "}") + .doTest(TestMode.TEXT_MATCH); + } + + @Test + void restrictedReplacement() { + restrictedRefactoringTestHelper + .addInputLines( + "A.java", + "class A {", + " void m() {", + " boolean b1 = \"foo\".toCharArray().length == 0;", + " boolean b2 = \"bar\".toCharArray().length == 1;", + " boolean b3 = \"baz\".toCharArray().length == 2;", + " boolean b4 = \"qux\".toCharArray().length == 3;", + " }", + "}") + .addOutputLines( + "A.java", + "class A {", + " void m() {", + " boolean b1 = \"foo\".length() + 1 == 1;", + " boolean b2 = \"bar\".toCharArray().length == 1;", + " boolean b3 = \"baz\".length() == 2;", + " boolean b4 = \"qux\".toCharArray().length == 3;", + " }", + "}") + .doTest(TestMode.TEXT_MATCH); + } +} diff --git a/refaster-support/pom.xml b/refaster-support/pom.xml index 51680fc3f4..b8a1835630 100644 --- a/refaster-support/pom.xml +++ b/refaster-support/pom.xml @@ -46,6 +46,11 @@ error_prone_test_helpers test + + com.google.auto.value + auto-value-annotations + provided + com.google.code.findbugs jsr305 @@ -56,6 +61,11 @@ guava provided + + org.assertj + assertj-core + test + org.junit.jupiter junit-jupiter-api @@ -66,5 +76,15 @@ junit-jupiter-engine test + + org.junit.jupiter + junit-jupiter-params + test + + + org.mockito + mockito-core + test + diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java new file mode 100644 index 0000000000..e43f0ea4c5 --- /dev/null +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java @@ -0,0 +1,152 @@ +package tech.picnic.errorprone.refaster; + +import static com.google.common.base.Preconditions.checkState; +import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; +import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; +import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; +import static tech.picnic.errorprone.refaster.annotation.OnlineDocumentation.NESTED_CLASS_URL_PLACEHOLDER; +import static tech.picnic.errorprone.refaster.annotation.OnlineDocumentation.TOP_LEVEL_CLASS_URL_PLACEHOLDER; + +import com.google.auto.value.AutoValue; +import com.google.common.base.Splitter; +import com.google.common.collect.Comparators; +import com.google.common.collect.ImmutableClassToInstanceMap; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterators; +import com.google.errorprone.BugPattern.SeverityLevel; +import com.google.errorprone.CodeTransformer; +import com.google.errorprone.CompositeCodeTransformer; +import com.google.errorprone.DescriptionListener; +import com.google.errorprone.ErrorProneOptions; +import com.google.errorprone.matchers.Description; +import com.sun.source.util.TreePath; +import com.sun.tools.javac.util.Context; +import java.io.Serializable; +import java.lang.annotation.Annotation; +import java.util.Iterator; +import java.util.Optional; +import java.util.function.Function; +import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; +import tech.picnic.errorprone.refaster.annotation.Severity; + +/** + * A {@link CompositeCodeTransformer} that augments the {@link Description} of Refaster rule + * matches. + * + *

The content is augmented based on custom {@link tech.picnic.errorprone.refaster.annotation + * annotations} available on the matching {@link CodeTransformer} or on this {@link + * CompositeCodeTransformer} as a fallback, if any. + */ +@AutoValue +public abstract class AnnotatedCompositeCodeTransformer implements CodeTransformer, Serializable { + private static final long serialVersionUID = 1L; + private static final Splitter CLASS_NAME_SPLITTER = Splitter.on('.').limit(2); + + abstract String packageName(); + + abstract ImmutableList transformers(); + + @Override + public abstract ImmutableClassToInstanceMap annotations(); + + /** + * Creates an instance of an {@link AnnotatedCompositeCodeTransformer}. + * + * @param packageName The package in which the wrapped {@link CodeTransformer}s reside. + * @param transformers The {@link CodeTransformer}s to which to delegate. + * @param annotations The annotations that are applicable to this {@link CodeTransformer}. + * @return A non-{@code null} {@link AnnotatedCompositeCodeTransformer}. + */ + public static AnnotatedCompositeCodeTransformer create( + String packageName, + ImmutableList transformers, + ImmutableClassToInstanceMap annotations) { + return new AutoValue_AnnotatedCompositeCodeTransformer(packageName, transformers, annotations); + } + + @Override + public final void apply(TreePath path, Context context, DescriptionListener listener) { + for (CodeTransformer transformer : transformers()) { + transformer.apply( + path, + context, + description -> + listener.onDescribed(augmentDescription(description, transformer, context))); + } + } + + private Description augmentDescription( + Description description, CodeTransformer delegate, Context context) { + String shortCheckName = getShortCheckName(description.checkName); + return Description.builder( + description.position, + shortCheckName, + getLinkPattern(delegate, shortCheckName).orElse(null), + overrideSeverity(getSeverity(delegate), context), + getDescription(delegate)) + .addAllFixes(description.fixes) + .build(); + } + + private String getShortCheckName(String fullCheckName) { + if (packageName().isEmpty()) { + return fullCheckName; + } + + String prefix = packageName() + '.'; + checkState( + fullCheckName.startsWith(prefix), + "Refaster rule class '%s' is not located in package '%s'", + fullCheckName, + packageName()); + + return fullCheckName.substring(prefix.length()); + } + + private Optional getLinkPattern(CodeTransformer delegate, String checkName) { + Iterator nameComponents = CLASS_NAME_SPLITTER.splitToStream(checkName).iterator(); + return getAnnotationValue(OnlineDocumentation.class, OnlineDocumentation::value, delegate) + .map(url -> url.replace(TOP_LEVEL_CLASS_URL_PLACEHOLDER, nameComponents.next())) + .map( + url -> + url.replace(NESTED_CLASS_URL_PLACEHOLDER, Iterators.getNext(nameComponents, ""))); + } + + private SeverityLevel getSeverity(CodeTransformer delegate) { + /* + * The default severity should be kept in sync with the default severity of the + * `tech.picnic.errorprone.refaster.runner.Refaster` bug checker. (The associated + * `RefasterTest#severityAssignment` test verifies this invariant.) + */ + return getAnnotationValue(Severity.class, Severity::value, delegate).orElse(SUGGESTION); + } + + private String getDescription(CodeTransformer delegate) { + return getAnnotationValue( + tech.picnic.errorprone.refaster.annotation.Description.class, + tech.picnic.errorprone.refaster.annotation.Description::value, + delegate) + .orElse("Refactoring opportunity"); + } + + private Optional getAnnotationValue( + Class annotation, Function extractor, CodeTransformer delegate) { + return getAnnotationValue(delegate, annotation) + .or(() -> getAnnotationValue(this, annotation)) + .map(extractor); + } + + private static Optional getAnnotationValue( + CodeTransformer codeTransformer, Class annotation) { + return Optional.ofNullable(codeTransformer.annotations().getInstance(annotation)); + } + + private static SeverityLevel overrideSeverity(SeverityLevel severity, Context context) { + ErrorProneOptions options = context.get(ErrorProneOptions.class); + SeverityLevel minSeverity = + ErrorProneFork.isSuggestionsAsWarningsEnabled(options) ? WARNING : SUGGESTION; + SeverityLevel maxSeverity = options.isDropErrorsToWarnings() ? WARNING : ERROR; + + return Comparators.max(Comparators.min(severity, minSeverity), maxSeverity); + } +} diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/ErrorProneFork.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/ErrorProneFork.java new file mode 100644 index 0000000000..38d29c403c --- /dev/null +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/ErrorProneFork.java @@ -0,0 +1,56 @@ +package tech.picnic.errorprone.refaster; + +import com.google.errorprone.ErrorProneOptions; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Arrays; +import java.util.Optional; + +/** + * Utility class that enables the runtime to determine whether Picnic's fork of Error Prone is on + * the classpath. + * + * @see Picnic's Error Prone fork + */ +public final class ErrorProneFork { + private static final Optional ERROR_PRONE_OPTIONS_IS_SUGGESTIONS_AS_WARNINGS_METHOD = + Arrays.stream(ErrorProneOptions.class.getDeclaredMethods()) + .filter(m -> Modifier.isPublic(m.getModifiers())) + .filter(m -> "isSuggestionsAsWarnings".equals(m.getName())) + .findFirst(); + + private ErrorProneFork() {} + + /** + * Tells whether Picnic's fork of Error Prone is available. + * + * @return {@code true} iff classpath introspection indicates the presence of Error Prone + * modifications that are assumed to be present only in Picnic's fork. + */ + public static boolean isErrorProneForkAvailable() { + return ERROR_PRONE_OPTIONS_IS_SUGGESTIONS_AS_WARNINGS_METHOD.isPresent(); + } + + /** + * Tells whether the custom {@code -XepAllSuggestionsAsWarnings} flag is set. + * + * @param options The currently active Error Prone options. + * @return {@code true} iff {@link #isErrorProneForkAvailable() the Error Prone fork is available} + * and the aforementioned flag is set. + * @see google/error-prone#3301 + */ + public static boolean isSuggestionsAsWarningsEnabled(ErrorProneOptions options) { + return ERROR_PRONE_OPTIONS_IS_SUGGESTIONS_AS_WARNINGS_METHOD + .filter(m -> Boolean.TRUE.equals(invoke(m, options))) + .isPresent(); + } + + private static Object invoke(Method method, Object obj, Object... args) { + try { + return method.invoke(obj, args); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new IllegalStateException(String.format("Failed to invoke method '%s'", method), e); + } + } +} diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Description.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Description.java new file mode 100644 index 0000000000..84af8a5727 --- /dev/null +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Description.java @@ -0,0 +1,22 @@ +package tech.picnic.errorprone.refaster.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Describes the intent of a Refaster rule or group of Refaster rules. + * + *

Annotations on nested classes override the description associated with any enclosing class. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface Description { + /** + * A description of the annotated Refaster rule(s). + * + * @return A non-{@code null} string. + */ + String value(); +} diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/OnlineDocumentation.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/OnlineDocumentation.java new file mode 100644 index 0000000000..f41a2f1b67 --- /dev/null +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/OnlineDocumentation.java @@ -0,0 +1,48 @@ +package tech.picnic.errorprone.refaster.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Signals that a Refaster rule or group of Refaster rules comes with online documentation. + * + *

The provided value may be a full URL, or a URL pattern containing either or both of the + * {@value TOP_LEVEL_CLASS_URL_PLACEHOLDER} and {@value NESTED_CLASS_URL_PLACEHOLDER} placeholders. + * + *

By default it is assumed that the Refaster rule(s) are documented on the Error Prone Support + * website. Annotations on nested classes override the documentation URL associated with any + * enclosing class. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface OnlineDocumentation { + /** + * The URL placeholder value that will be replaced with the name of the top-level class in which + * the annotated Refaster rule is located. + */ + String TOP_LEVEL_CLASS_URL_PLACEHOLDER = "${topLevelClassName}"; + /** + * The URL placeholder value that will be replaced with the name of the nested class in which the + * annotated Refaster rule is located, if applicable. + * + *

If the Refaster rule is not defined in a nested class then this placeholder will be replaced + * with the empty string. In case the Refaster rule is syntactically nested inside a deeper + * hierarchy of classes, then this placeholder will be replaced with concatenation of the names of + * all these classes (except the top-level class name), separated by dots. + */ + String NESTED_CLASS_URL_PLACEHOLDER = "${nestedClassName}"; + + /** + * The URL or URL pattern of the website at which the annotated Refaster rule(s) are documented. + * + * @return A non-{@code null} string, optionally containing the {@value + * TOP_LEVEL_CLASS_URL_PLACEHOLDER} and {@value NESTED_CLASS_URL_PLACEHOLDER} placeholders. + */ + String value() default + "https://error-prone.picnic.tech/refasterrules/" + + TOP_LEVEL_CLASS_URL_PLACEHOLDER + + '#' + + NESTED_CLASS_URL_PLACEHOLDER; +} diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Severity.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Severity.java new file mode 100644 index 0000000000..afa5a6c6e1 --- /dev/null +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/Severity.java @@ -0,0 +1,25 @@ +package tech.picnic.errorprone.refaster.annotation; + +import com.google.errorprone.BugPattern.SeverityLevel; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Describes the severity of a Refaster rule or group of Refaster rules. + * + *

The default severity is the severity assigned to the {@code Refaster} bug checker, which may + * be controlled explicitly by running Error Prone with e.g. {@code -Xep:Refaster:WARN}. Annotations + * on nested classes override the severity associated with any enclosing class. + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.SOURCE) +public @interface Severity { + /** + * The expected severity of any match of the annotated Refaster rule(s). + * + * @return An Error Prone severity level. + */ + SeverityLevel value(); +} diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java new file mode 100644 index 0000000000..53e8e88739 --- /dev/null +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java @@ -0,0 +1,8 @@ +/** + * A collection of annotations that can be placed on Refaster rule classes and Refaster rule + * collection classes, thus influencing the way in which associated rule matches are reported in + * non-patch mode. + */ +@com.google.errorprone.annotations.CheckReturnValue +@javax.annotation.ParametersAreNonnullByDefault +package tech.picnic.errorprone.refaster.annotation; diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/package-info.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/package-info.java new file mode 100644 index 0000000000..4955569986 --- /dev/null +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/package-info.java @@ -0,0 +1,4 @@ +/** Assorted classes that aid the compilation or evaluation of Refaster rules. */ +@com.google.errorprone.annotations.CheckReturnValue +@javax.annotation.ParametersAreNonnullByDefault +package tech.picnic.errorprone.refaster; diff --git a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformerTest.java b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformerTest.java new file mode 100644 index 0000000000..d49dcf3006 --- /dev/null +++ b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformerTest.java @@ -0,0 +1,204 @@ +package tech.picnic.errorprone.refaster; + +import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; +import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; +import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.notNull; +import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import com.google.auto.value.AutoAnnotation; +import com.google.common.collect.ImmutableClassToInstanceMap; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; +import com.google.errorprone.BugPattern.SeverityLevel; +import com.google.errorprone.CodeTransformer; +import com.google.errorprone.DescriptionListener; +import com.google.errorprone.ErrorProneOptions; +import com.google.errorprone.fixes.Fix; +import com.google.errorprone.matchers.Description; +import com.sun.source.util.TreePath; +import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; +import tech.picnic.errorprone.refaster.annotation.Severity; + +// XXX: Test the `ErrorProneOptions`-based severity override logic. (Right now that logic is tested +// through `RefasterTest`, but ideally it is covered by tests in this class, closer to the code that +// implements the relevant logic.) See the comment in `#context()` below. +final class AnnotatedCompositeCodeTransformerTest { + private static final DiagnosticPosition DUMMY_POSITION = mock(DiagnosticPosition.class); + private static final Fix DUMMY_FIX = mock(Fix.class); + private static final TreePath DUMMY_PATH = mock(TreePath.class); + private static final String DEFAULT_PACKAGE = ""; + private static final String CUSTOM_PACKAGE = "com.example"; + private static final String SIMPLE_CLASS_NAME = "MyRefasterRule"; + + private static Stream applyTestCases() { + /* { context, packageName, ruleName, compositeAnnotations, delegateAnnotations, expectedDescription } */ + return Stream.of( + arguments( + context(), + DEFAULT_PACKAGE, + SIMPLE_CLASS_NAME, + ImmutableSet.of(), + ImmutableSet.of(), + description( + SIMPLE_CLASS_NAME, Optional.empty(), SUGGESTION, "Refactoring opportunity")), + arguments( + context(), + CUSTOM_PACKAGE, + CUSTOM_PACKAGE + '.' + SIMPLE_CLASS_NAME, + ImmutableSet.of( + descriptionAnnotation("Composite description"), + documentationAnnotation("https://example.com"), + severityAnnotation(ERROR)), + ImmutableSet.of(), + description( + SIMPLE_CLASS_NAME, + Optional.of("https://example.com"), + ERROR, + "Composite description")), + arguments( + context(), + DEFAULT_PACKAGE, + SIMPLE_CLASS_NAME, + ImmutableSet.of(), + ImmutableSet.of( + descriptionAnnotation("Rule description"), + documentationAnnotation("https://example.com/rule/${topLevelClassName}"), + severityAnnotation(WARNING)), + description( + SIMPLE_CLASS_NAME, + Optional.of("https://example.com/rule/" + SIMPLE_CLASS_NAME), + WARNING, + "Rule description")), + arguments( + context(), + CUSTOM_PACKAGE, + CUSTOM_PACKAGE + '.' + SIMPLE_CLASS_NAME + ".SomeInnerClass.NestedEvenDeeper", + ImmutableSet.of( + descriptionAnnotation("Some description"), + documentationAnnotation("https://example.com"), + severityAnnotation(ERROR)), + ImmutableSet.of( + descriptionAnnotation("Overriding description"), + documentationAnnotation( + "https://example.com/rule/${topLevelClassName}/${nestedClassName}"), + severityAnnotation(SUGGESTION)), + description( + SIMPLE_CLASS_NAME + ".SomeInnerClass.NestedEvenDeeper", + Optional.of( + "https://example.com/rule/" + + SIMPLE_CLASS_NAME + + "/SomeInnerClass.NestedEvenDeeper"), + SUGGESTION, + "Overriding description"))); + } + + @MethodSource("applyTestCases") + @ParameterizedTest + void apply( + Context context, + String packageName, + String ruleName, + ImmutableSet compositeAnnotations, + ImmutableSet delegateAnnotations, + Description expectedDescription) { + CodeTransformer codeTransformer = + AnnotatedCompositeCodeTransformer.create( + packageName, + ImmutableList.of( + delegateCodeTransformer( + delegateAnnotations, context, refasterDescription(ruleName))), + indexAnnotations(compositeAnnotations)); + + List collected = new ArrayList<>(); + codeTransformer.apply(DUMMY_PATH, context, collected::add); + assertThat(collected) + .satisfiesExactly( + actual -> { + assertThat(actual.position).isEqualTo(expectedDescription.position); + assertThat(actual.checkName).isEqualTo(expectedDescription.checkName); + assertThat(actual.fixes).containsExactlyElementsOf(expectedDescription.fixes); + assertThat(actual.getLink()).isEqualTo(expectedDescription.getLink()); + assertThat(actual.getRawMessage()).isEqualTo(expectedDescription.getRawMessage()); + }); + } + + private static ImmutableClassToInstanceMap indexAnnotations( + ImmutableSet annotations) { + return ImmutableClassToInstanceMap.copyOf( + Maps.uniqueIndex(annotations, Annotation::annotationType)); + } + + private static CodeTransformer delegateCodeTransformer( + ImmutableSet annotations, + Context expectedContext, + Description returnedDescription) { + CodeTransformer codeTransformer = mock(CodeTransformer.class); + + when(codeTransformer.annotations()).thenReturn(indexAnnotations(annotations)); + doAnswer( + inv -> { + inv.getArgument(2).onDescribed(returnedDescription); + return null; + }) + .when(codeTransformer) + .apply(eq(DUMMY_PATH), eq(expectedContext), notNull()); + + return codeTransformer; + } + + /** + * Returns a {@link Description} with some default values as produced by {@link + * com.google.errorprone.refaster.RefasterScanner}. + */ + private static Description refasterDescription(String name) { + return description(name, Optional.of(""), WARNING, ""); + } + + private static Description description( + String name, Optional link, SeverityLevel severityLevel, String message) { + return Description.builder(DUMMY_POSITION, name, link.orElse(null), severityLevel, message) + .addFix(DUMMY_FIX) + .build(); + } + + private static Context context() { + // XXX: Use `ErrorProneOptions#processArgs` to test the + // `AnnotatedCompositeCodeTransformer#overrideSeverity` logic. + Context context = mock(Context.class); + when(context.get(ErrorProneOptions.class)).thenReturn(ErrorProneOptions.empty()); + return context; + } + + @AutoAnnotation + private static tech.picnic.errorprone.refaster.annotation.Description descriptionAnnotation( + String value) { + return new AutoAnnotation_AnnotatedCompositeCodeTransformerTest_descriptionAnnotation(value); + } + + @AutoAnnotation + private static OnlineDocumentation documentationAnnotation(String value) { + return new AutoAnnotation_AnnotatedCompositeCodeTransformerTest_documentationAnnotation(value); + } + + @AutoAnnotation + private static Severity severityAnnotation(SeverityLevel value) { + return new AutoAnnotation_AnnotatedCompositeCodeTransformerTest_severityAnnotation(value); + } +} diff --git a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/ErrorProneForkTest.java b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/ErrorProneForkTest.java new file mode 100644 index 0000000000..06b11b8501 --- /dev/null +++ b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/ErrorProneForkTest.java @@ -0,0 +1,67 @@ +package tech.picnic.errorprone.refaster; + +import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +import com.google.errorprone.BugPattern; +import com.google.errorprone.CompilationTestHelper; +import com.google.errorprone.ErrorProneOptions; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher; +import com.google.errorprone.matchers.Description; +import com.sun.source.tree.ClassTree; +import org.junit.jupiter.api.Test; + +final class ErrorProneForkTest { + @Test + void isErrorProneForkAvailable() { + assertThat(ErrorProneFork.isErrorProneForkAvailable()) + .isEqualTo(Boolean.TRUE.toString().equals(System.getProperty("error-prone-fork-in-use"))); + } + + @Test + void isSuggestionsAsWarningsEnabledWithoutFlag() { + CompilationTestHelper.newInstance(TestChecker.class, getClass()) + .addSourceLines( + "A.java", + "// BUG: Diagnostic contains: Suggestions as warnings enabled: false", + "class A {}") + .doTest(); + } + + @Test + void isSuggestionsAsWarningsEnabledWithFlag() { + assumeTrue( + ErrorProneFork.isErrorProneForkAvailable(), + "Picnic's Error Prone fork is not on the classpath"); + + CompilationTestHelper.newInstance(TestChecker.class, getClass()) + .setArgs("-XepAllSuggestionsAsWarnings") + .addSourceLines( + "A.java", + "// BUG: Diagnostic contains: Suggestions as warnings enabled: true", + "class A {}") + .doTest(); + } + + /** + * A {@link BugChecker} that reports the result of {@link + * ErrorProneFork#isSuggestionsAsWarningsEnabled(ErrorProneOptions)}. + */ + @BugPattern(summary = "Flags classes with a custom error message", severity = ERROR) + public static final class TestChecker extends BugChecker implements ClassTreeMatcher { + private static final long serialVersionUID = 1L; + + @Override + public Description matchClass(ClassTree tree, VisitorState state) { + return buildDescription(tree) + .setMessage( + String.format( + "Suggestions as warnings enabled: %s", + ErrorProneFork.isSuggestionsAsWarningsEnabled(state.errorProneOptions()))) + .build(); + } + } +} diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java index ce01ec9919..daf2d52513 100644 --- a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java @@ -175,11 +175,11 @@ private static ImmutableRangeMap indexRuleMatches( ImmutableRangeMap.Builder ruleMatches = ImmutableRangeMap.builder(); for (Description description : matches) { + String ruleName = extractRefasterRuleName(description); Set replacements = Iterables.getOnlyElement(description.fixes).getReplacements(endPositions); for (Replacement replacement : replacements) { - ruleMatches.put( - replacement.range(), getSubstringAfterFinalDelimiter('.', description.checkName)); + ruleMatches.put(replacement.range(), ruleName); } } @@ -226,6 +226,13 @@ private void reportViolations( state.reportMatch(describeMatch(tree, fixWithComment)); } + private static String extractRefasterRuleName(Description description) { + String message = description.getRawMessage(); + int index = message.indexOf(':'); + checkState(index >= 0, "Failed to extract Refaster rule name from string '%s'", message); + return getSubstringAfterFinalDelimiter('.', message.substring(0, index)); + } + private static String getSubstringAfterFinalDelimiter(char delimiter, String value) { int index = value.lastIndexOf(delimiter); checkState(index >= 0, "String '%s' does not contain character '%s'", value, delimiter); From 85cb997f1b89031cc54aea2d172ecfd5d6307445 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Thu, 13 Oct 2022 09:20:46 +0200 Subject: [PATCH 009/601] [maven-release-plugin] prepare release v0.4.0 --- error-prone-contrib/pom.xml | 2 +- pom.xml | 4 ++-- refaster-compiler/pom.xml | 2 +- refaster-runner/pom.xml | 2 +- refaster-support/pom.xml | 2 +- refaster-test-support/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index e8681ecd37..efc598a812 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.3.1-SNAPSHOT + 0.4.0 error-prone-contrib diff --git a/pom.xml b/pom.xml index 84a6a5572a..837b59a85d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ tech.picnic.error-prone-support error-prone-support - 0.3.1-SNAPSHOT + 0.4.0 pom Picnic :: Error Prone Support @@ -48,7 +48,7 @@ scm:git:git@github.com:PicnicSupermarket/error-prone-support.git - HEAD + v0.4.0 https://github.com/PicnicSupermarket/error-prone-support diff --git a/refaster-compiler/pom.xml b/refaster-compiler/pom.xml index dc43b58dfa..8fb347b493 100644 --- a/refaster-compiler/pom.xml +++ b/refaster-compiler/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.3.1-SNAPSHOT + 0.4.0 refaster-compiler diff --git a/refaster-runner/pom.xml b/refaster-runner/pom.xml index 9bdd3a65ed..bc2ea69922 100644 --- a/refaster-runner/pom.xml +++ b/refaster-runner/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.3.1-SNAPSHOT + 0.4.0 refaster-runner diff --git a/refaster-support/pom.xml b/refaster-support/pom.xml index b8a1835630..3e7ede5d52 100644 --- a/refaster-support/pom.xml +++ b/refaster-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.3.1-SNAPSHOT + 0.4.0 refaster-support diff --git a/refaster-test-support/pom.xml b/refaster-test-support/pom.xml index 92a3b9bd3f..34feb0dc1e 100644 --- a/refaster-test-support/pom.xml +++ b/refaster-test-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.3.1-SNAPSHOT + 0.4.0 refaster-test-support From 7de9bede198a241c479bc55c74a5aea88f7018cd Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Thu, 13 Oct 2022 09:20:46 +0200 Subject: [PATCH 010/601] [maven-release-plugin] prepare for next development iteration --- error-prone-contrib/pom.xml | 2 +- pom.xml | 4 ++-- refaster-compiler/pom.xml | 2 +- refaster-runner/pom.xml | 2 +- refaster-support/pom.xml | 2 +- refaster-test-support/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index efc598a812..ec76a6b891 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.4.0 + 0.4.1-SNAPSHOT error-prone-contrib diff --git a/pom.xml b/pom.xml index 837b59a85d..2e0f4aecd4 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ tech.picnic.error-prone-support error-prone-support - 0.4.0 + 0.4.1-SNAPSHOT pom Picnic :: Error Prone Support @@ -48,7 +48,7 @@ scm:git:git@github.com:PicnicSupermarket/error-prone-support.git - v0.4.0 + HEAD https://github.com/PicnicSupermarket/error-prone-support diff --git a/refaster-compiler/pom.xml b/refaster-compiler/pom.xml index 8fb347b493..85afa6a44c 100644 --- a/refaster-compiler/pom.xml +++ b/refaster-compiler/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.4.0 + 0.4.1-SNAPSHOT refaster-compiler diff --git a/refaster-runner/pom.xml b/refaster-runner/pom.xml index bc2ea69922..6403d266a4 100644 --- a/refaster-runner/pom.xml +++ b/refaster-runner/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.4.0 + 0.4.1-SNAPSHOT refaster-runner diff --git a/refaster-support/pom.xml b/refaster-support/pom.xml index 3e7ede5d52..093d037b82 100644 --- a/refaster-support/pom.xml +++ b/refaster-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.4.0 + 0.4.1-SNAPSHOT refaster-support diff --git a/refaster-test-support/pom.xml b/refaster-test-support/pom.xml index 34feb0dc1e..e121a1f678 100644 --- a/refaster-test-support/pom.xml +++ b/refaster-test-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.4.0 + 0.4.1-SNAPSHOT refaster-test-support From a2559bddda0bbaea3757b7dd2e6f99e150a23888 Mon Sep 17 00:00:00 2001 From: Jelmer Borst Date: Thu, 13 Oct 2022 10:12:37 +0200 Subject: [PATCH 011/601] Fix and simplify documented example compiler output (#297) --- README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ccd1ab3029..a26f915a49 100644 --- a/README.md +++ b/README.md @@ -119,16 +119,13 @@ code with Maven should yield two compiler warnings: ```sh $ mvn clean install ... -[INFO] ------------------------------------------------------------- -[WARNING] COMPILATION WARNING : -[INFO] ------------------------------------------------------------- -[WARNING] Example.java:[9,34] [tech.picnic.errorprone.refasterrules.BigDecimalRules.BigDecimalZero] +[INFO] Example.java:[9,34] [Refaster Rule] BigDecimalRules.BigDecimalZero: Refactoring opportunity + (see https://error-prone.picnic.tech/refasterrules/BigDecimalRules#BigDecimalZero) Did you mean 'return BigDecimal.ZERO;'? +... [WARNING] Example.java:[13,35] [IdentityConversion] This method invocation appears redundant; remove it or suppress this warning and add a comment explaining its purpose (see https://error-prone.picnic.tech/bugpatterns/IdentityConversion) Did you mean 'return set;' or '@SuppressWarnings("IdentityConversion") public ImmutableSet getSet() {'? -[INFO] 2 warnings -[INFO] ------------------------------------------------------------- ... ``` From 4fd8f574303194f7d64eff849db06c62d132f605 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 15 Oct 2022 11:03:17 +0200 Subject: [PATCH 012/601] Upgrade ruby/setup-ruby v1.117.0 -> v1.118.0 (#298) See: - https://github.com/ruby/setup-ruby/releases/tag/v1.118.0 - https://github.com/ruby/setup-ruby/compare/v1.117.0...v1.118.0 --- .github/workflows/deploy-website.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index 52060459f2..bb0e985c0e 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -16,7 +16,7 @@ jobs: steps: - name: Check out code uses: actions/checkout@v3.1.0 - - uses: ruby/setup-ruby@v1.117.0 + - uses: ruby/setup-ruby@v1.118.0 with: working-directory: ./website bundler-cache: true From b9884fa6d6430db98c632a1a90b150fff5f7563f Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 15 Oct 2022 13:22:02 +0200 Subject: [PATCH 013/601] Upgrade Error Prone 2.15.0 -> 2.16 (#291) See: - https://github.com/google/error-prone/releases/tag/v2.16 - https://github.com/google/error-prone/compare/v2.15.0...v2.16 - https://github.com/PicnicSupermarket/error-prone/compare/v2.15.0-picnic-3...v2.16-picnic-1 --- .../picnic/errorprone/bugpatterns/MethodReferenceUsage.java | 4 ++-- pom.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MethodReferenceUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MethodReferenceUsage.java index 437fb6db1f..ea1f6c9faf 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MethodReferenceUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MethodReferenceUsage.java @@ -122,7 +122,7 @@ private static Optional constructMethodRef( return Optional.empty(); } Symbol sym = ASTHelpers.getSymbol(methodSelect); - if (!sym.isStatic()) { + if (!ASTHelpers.isStatic(sym)) { return constructFix(lambdaExpr, "this", methodSelect); } return constructFix(lambdaExpr, sym.owner, methodSelect); @@ -192,7 +192,7 @@ private static Optional constructFix( Name sName = target.getSimpleName(); Optional fix = constructFix(lambdaExpr, sName, methodName); - if (!"java.lang".equals(target.packge().toString())) { + if (!"java.lang".equals(ASTHelpers.enclosingPackage(target).toString())) { Name fqName = target.getQualifiedName(); if (!sName.equals(fqName)) { return fix.map(b -> b.addImport(fqName.toString())); diff --git a/pom.xml b/pom.xml index 2e0f4aecd4..70ac6d51b0 100644 --- a/pom.xml +++ b/pom.xml @@ -148,8 +148,8 @@ 1.0.1 1.10 ${version.error-prone-orig} - v${version.error-prone-orig}-picnic-3 - 2.15.0 + v${version.error-prone-orig}-picnic-1 + 2.16 0.1.15 1.0 11 From d6b28733f6c2d6ed1e84baaccbbc6f3031917ddc Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 15 Oct 2022 17:01:00 +0200 Subject: [PATCH 014/601] Upgrade Jackson 2.13.4 -> 2.13.4.20221013 (#294) See: - https://github.com/FasterXML/jackson-databind/compare/jackson-databind-2.13.4...jackson-databind-2.13.4.2 - https://github.com/FasterXML/jackson-bom/compare/jackson-bom-2.13.4...jackson-bom-2.13.4.20221013 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 70ac6d51b0..1042094a0d 100644 --- a/pom.xml +++ b/pom.xml @@ -219,7 +219,7 @@ com.fasterxml.jackson jackson-bom - 2.13.4 + 2.13.4.20221013 pom import From 4efd79bfa65838ad77f1216d8a399c90e37a76d7 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 17 Oct 2022 10:25:01 +0200 Subject: [PATCH 015/601] Upgrade Project Reactor 2020.0.23 -> 2020.0.24 (#295) See: - https://github.com/reactor/reactor/releases/tag/2020.0.24 - https://github.com/reactor/reactor/compare/2020.0.23...2020.0.24 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1042094a0d..0da6790bc7 100644 --- a/pom.xml +++ b/pom.xml @@ -308,7 +308,7 @@ io.projectreactor reactor-bom - 2020.0.23 + 2020.0.24 pom import From 1d28512f09e82a988666e9da0da5f1e3cacd0f0c Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 17 Oct 2022 10:44:11 +0200 Subject: [PATCH 016/601] Upgrade swagger-annotations 1.6.7 -> 1.6.8 (#300) See: - https://github.com/swagger-api/swagger-core/releases/tag/v1.6.8 - https://github.com/swagger-api/swagger-core/compare/v1.6.7...v1.6.8 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0da6790bc7..58089f098d 100644 --- a/pom.xml +++ b/pom.xml @@ -320,7 +320,7 @@ io.swagger swagger-annotations - 1.6.7 + 1.6.8 io.swagger.core.v3 From 2578857a375c99e04dd17ccec2c788083ac56fd0 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 17 Oct 2022 11:10:20 +0200 Subject: [PATCH 017/601] Upgrade errorprone-slf4j 0.1.15 -> 0.1.16 (#296) See: - https://github.com/KengoTODA/errorprone-slf4j/releases/tag/v0.1.16 - https://github.com/KengoTODA/errorprone-slf4j/compare/v0.1.15...v0.1.16 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 58089f098d..33bf1fe3c8 100644 --- a/pom.xml +++ b/pom.xml @@ -150,7 +150,7 @@ ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 2.16 - 0.1.15 + 0.1.16 1.0 11 3.8.6 From 759e7ea2ff6783843c3c6c9157b9fbd599362b39 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 17 Oct 2022 14:54:27 +0200 Subject: [PATCH 018/601] Upgrade swagger-annotations 2.2.3 -> 2.2.4 (#299) See: - https://github.com/swagger-api/swagger-core/releases/tag/v2.2.4 - https://github.com/swagger-api/swagger-core/compare/v2.2.3...v2.2.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 33bf1fe3c8..75fddbfb27 100644 --- a/pom.xml +++ b/pom.xml @@ -325,7 +325,7 @@ io.swagger.core.v3 swagger-annotations - 2.2.3 + 2.2.4 jakarta.servlet From d0533f71904dc5cb5a3a7d69b7394a84122efba2 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 20 Oct 2022 08:12:58 +0200 Subject: [PATCH 019/601] Upgrade actions/deploy-pages v1.2.1 -> v1.2.2 (#302) See: - https://github.com/actions/deploy-pages/releases/tag/v1.2.2 - https://github.com/actions/deploy-pages/compare/v1.2.1...v1.2.2 --- .github/workflows/deploy-website.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index bb0e985c0e..0436f10828 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -46,4 +46,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v1.2.1 + uses: actions/deploy-pages@v1.2.2 From e6ccb523fdf5cc932254e009465a8ddfcdc8c351 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 20 Oct 2022 08:46:03 +0200 Subject: [PATCH 020/601] Upgrade Mockito 4.8.0 -> 4.8.1 (#303) See: - https://github.com/mockito/mockito/releases/tag/v4.8.1 - https://github.com/mockito/mockito/compare/v4.8.0...v4.8.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 75fddbfb27..1ef83431f4 100644 --- a/pom.xml +++ b/pom.xml @@ -154,7 +154,7 @@ 1.0 11 3.8.6 - 4.8.0 + 4.8.1 1.0.1 0.10.2 + `org.jspecify.nullness.Nullable`. --> + `org.jspecify.nullness.Nullable`. --> + + + + `org.jspecify.nullness.Nullable`. --> diff --git a/refaster-compiler/pom.xml b/refaster-compiler/pom.xml index 85afa6a44c..6cab978a48 100644 --- a/refaster-compiler/pom.xml +++ b/refaster-compiler/pom.xml @@ -36,14 +36,14 @@ auto-service-annotations provided - - com.google.code.findbugs - jsr305 - provided - com.google.guava guava + + org.jspecify + jspecify + provided + diff --git a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java index 3c13b74d67..f7bd2c2908 100644 --- a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java +++ b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java @@ -28,10 +28,10 @@ import java.io.UncheckedIOException; import java.lang.annotation.Annotation; import java.util.Map; -import javax.annotation.Nullable; import javax.tools.FileObject; import javax.tools.JavaFileManager; import javax.tools.StandardLocation; +import org.jspecify.nullness.Nullable; import tech.picnic.errorprone.refaster.AnnotatedCompositeCodeTransformer; /** @@ -71,10 +71,10 @@ public void finished(TaskEvent taskEvent) { private ImmutableMap compileRefasterRules(ClassTree tree) { ImmutableMap.Builder rules = ImmutableMap.builder(); - new TreeScanner>() { - @Nullable + new TreeScanner<@Nullable Void, ImmutableClassToInstanceMap>() { @Override - public Void visitClass(ClassTree node, ImmutableClassToInstanceMap annotations) { + public @Nullable Void visitClass( + ClassTree node, ImmutableClassToInstanceMap annotations) { ClassSymbol symbol = ASTHelpers.getSymbol(node); ImmutableList transformers = @@ -105,7 +105,7 @@ private FileObject getOutputFile(TaskEvent taskEvent, ClassTree tree) throws IOE private static boolean containsRefasterRules(ClassTree tree) { return Boolean.TRUE.equals( - new TreeScanner() { + new TreeScanner() { @Override public Boolean visitAnnotation(AnnotationTree node, @Nullable Void unused) { Symbol sym = ASTHelpers.getSymbol(node); diff --git a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/package-info.java b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/package-info.java index 78b0583712..4217cb239c 100644 --- a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/package-info.java +++ b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/package-info.java @@ -3,5 +3,5 @@ * files on the classpath. */ @com.google.errorprone.annotations.CheckReturnValue -@javax.annotation.ParametersAreNonnullByDefault +@org.jspecify.nullness.NullMarked package tech.picnic.errorprone.refaster.plugin; diff --git a/refaster-runner/pom.xml b/refaster-runner/pom.xml index 6403d266a4..25ad73e192 100644 --- a/refaster-runner/pom.xml +++ b/refaster-runner/pom.xml @@ -51,11 +51,6 @@ auto-service-annotations provided - - com.google.code.findbugs - jsr305 - provided - com.google.guava guava @@ -66,6 +61,11 @@ assertj-core test + + org.jspecify + jspecify + provided + org.junit.jupiter junit-jupiter-api diff --git a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java index c10739493d..f71089d3e1 100644 --- a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java +++ b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java @@ -1,4 +1,4 @@ /** Exposes Refaster rules found on the classpath through a regular Error Prone check. */ @com.google.errorprone.annotations.CheckReturnValue -@javax.annotation.ParametersAreNonnullByDefault +@org.jspecify.nullness.NullMarked package tech.picnic.errorprone.refaster.runner; diff --git a/refaster-support/pom.xml b/refaster-support/pom.xml index 093d037b82..944b622967 100644 --- a/refaster-support/pom.xml +++ b/refaster-support/pom.xml @@ -51,21 +51,20 @@ auto-value-annotations provided - - com.google.code.findbugs - jsr305 - provided - com.google.guava guava - provided org.assertj assertj-core test + + org.jspecify + jspecify + provided + org.junit.jupiter junit-jupiter-api diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java index 53e8e88739..99339a5c9f 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java @@ -4,5 +4,5 @@ * non-patch mode. */ @com.google.errorprone.annotations.CheckReturnValue -@javax.annotation.ParametersAreNonnullByDefault +@org.jspecify.nullness.NullMarked package tech.picnic.errorprone.refaster.annotation; diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/package-info.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/package-info.java index 714c3224e2..7a68fc5e30 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/package-info.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/package-info.java @@ -5,5 +5,5 @@ * com.google.errorprone.refaster.annotation.NotMatches @NotMatches} annotations. */ @com.google.errorprone.annotations.CheckReturnValue -@javax.annotation.ParametersAreNonnullByDefault +@org.jspecify.nullness.NullMarked package tech.picnic.errorprone.refaster.matchers; diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/package-info.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/package-info.java index 4955569986..99bd0885b7 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/package-info.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/package-info.java @@ -1,4 +1,4 @@ /** Assorted classes that aid the compilation or evaluation of Refaster rules. */ @com.google.errorprone.annotations.CheckReturnValue -@javax.annotation.ParametersAreNonnullByDefault +@org.jspecify.nullness.NullMarked package tech.picnic.errorprone.refaster; diff --git a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java index adc2d1f965..b1370b519d 100644 --- a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java +++ b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java @@ -11,7 +11,7 @@ import com.sun.source.tree.MethodTree; import com.sun.source.tree.Tree; import com.sun.source.util.TreeScanner; -import javax.annotation.Nullable; +import org.jspecify.nullness.Nullable; /** * An abstract {@link BugChecker} that reports a match for each expression matched by the given @@ -31,10 +31,9 @@ abstract class AbstractMatcherTestChecker extends BugChecker implements Compilat @Override public Description matchCompilationUnit(CompilationUnitTree compilationUnit, VisitorState state) { - new TreeScanner() { - @Nullable + new TreeScanner<@Nullable Void, @Nullable Void>() { @Override - public Void scan(Tree tree, @Nullable Void unused) { + public @Nullable Void scan(Tree tree, @Nullable Void unused) { if (tree instanceof ExpressionTree && delegate.matches((ExpressionTree) tree, state)) { state.reportMatch( Description.builder(tree, canonicalName(), null, defaultSeverity(), message()) @@ -44,9 +43,8 @@ public Void scan(Tree tree, @Nullable Void unused) { return super.scan(tree, unused); } - @Nullable @Override - public Void visitImport(ImportTree node, @Nullable Void unused) { + public @Nullable Void visitImport(ImportTree node, @Nullable Void unused) { /* * We're not interested in matching import statements. While components of these * can be `ExpressionTree`s, they will never be matched by Refaster. @@ -54,9 +52,8 @@ public Void visitImport(ImportTree node, @Nullable Void unused) { return null; } - @Nullable @Override - public Void visitMethod(MethodTree node, @Nullable Void unused) { + public @Nullable Void visitMethod(MethodTree node, @Nullable Void unused) { /* * We're not interested in matching e.g. parameter and return type declarations. While these * can be `ExpressionTree`s, they will never be matched by Refaster. diff --git a/refaster-test-support/pom.xml b/refaster-test-support/pom.xml index e121a1f678..064a1529a9 100644 --- a/refaster-test-support/pom.xml +++ b/refaster-test-support/pom.xml @@ -45,15 +45,15 @@ auto-service-annotations provided - - com.google.code.findbugs - jsr305 - provided - com.google.guava guava + + org.jspecify + jspecify + provided + org.junit.jupiter junit-jupiter-engine diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java index daf2d52513..45a734cea6 100644 --- a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java @@ -44,7 +44,7 @@ import java.util.Optional; import java.util.Set; import java.util.regex.Pattern; -import javax.annotation.Nullable; +import org.jspecify.nullness.Nullable; import tech.picnic.errorprone.refaster.runner.CodeTransformers; import tech.picnic.errorprone.refaster.runner.Refaster; @@ -239,16 +239,15 @@ private static String getSubstringAfterFinalDelimiter(char delimiter, String val return value.substring(index + 1); } - private class UnexpectedMatchReporter extends TreeScanner { + private class UnexpectedMatchReporter extends TreeScanner<@Nullable Void, VisitorState> { private final ImmutableRangeMap indexedMatches; UnexpectedMatchReporter(ImmutableRangeMap indexedMatches) { this.indexedMatches = indexedMatches; } - @Nullable @Override - public Void visitMethod(MethodTree tree, VisitorState state) { + public @Nullable Void visitMethod(MethodTree tree, VisitorState state) { if (!ASTHelpers.isGeneratedConstructor(tree)) { getRuleUnderTest(tree, state) .ifPresent(ruleUnderTest -> reportUnexpectedMatches(tree, ruleUnderTest, state)); diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/package-info.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/package-info.java index 93cfccf4ab..cce5279378 100644 --- a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/package-info.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/package-info.java @@ -1,4 +1,4 @@ /** Opinionated utilities for the testing of Refaster rules. */ @com.google.errorprone.annotations.CheckReturnValue -@javax.annotation.ParametersAreNonnullByDefault +@org.jspecify.nullness.NullMarked package tech.picnic.errorprone.refaster.test; diff --git a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/ValidRules.java b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/ValidRules.java index 99c1007070..1d6c2359c9 100644 --- a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/ValidRules.java +++ b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/ValidRules.java @@ -8,7 +8,7 @@ import com.google.errorprone.refaster.annotation.Placeholder; import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Set; -import javax.annotation.Nullable; +import org.jspecify.nullness.Nullable; /** Refaster rule collection to validate that having no violations works as expected. */ final class ValidRules { From 21388273c5fcb867a5370fa8dc8db231e40ef7fe Mon Sep 17 00:00:00 2001 From: chamil-prabodha Date: Tue, 25 Oct 2022 16:54:28 +0200 Subject: [PATCH 031/601] Have `TimeZoneUsage` check flag `{OffsetDate,Offset,ZonedDate}Time#now` (#311) --- .../errorprone/bugpatterns/TimeZoneUsage.java | 8 ++- .../bugpatterns/TimeZoneUsageTest.java | 68 ++++++++++++------- 2 files changed, 50 insertions(+), 26 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsage.java index 1bda1d207b..c4426261ff 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsage.java @@ -26,6 +26,9 @@ import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.time.OffsetTime; +import java.time.ZonedDateTime; /** A {@link BugChecker} that flags illegal time-zone related operations. */ @AutoService(BugChecker.class) @@ -58,7 +61,10 @@ public final class TimeZoneUsage extends BugChecker implements MethodInvocationT .onClassAny( LocalDate.class.getName(), LocalDateTime.class.getName(), - LocalTime.class.getName()) + LocalTime.class.getName(), + OffsetDateTime.class.getName(), + OffsetTime.class.getName(), + ZonedDateTime.class.getName()) .named("now"), staticMethod().onClassAny(Instant.class.getName()).named("now").withNoParameters()); diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsageTest.java index b675225b92..ad4e8a8b07 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsageTest.java @@ -1,17 +1,11 @@ package tech.picnic.errorprone.bugpatterns; -import static com.google.common.base.Predicates.containsPattern; - import com.google.errorprone.CompilationTestHelper; import org.junit.jupiter.api.Test; final class TimeZoneUsageTest { private final CompilationTestHelper compilationHelper = - CompilationTestHelper.newInstance(TimeZoneUsage.class, getClass()) - .expectErrorMessage( - "X", - containsPattern( - "Derive the current time from an existing `Clock` Spring bean, and don't rely on a `Clock`'s time zone")); + CompilationTestHelper.newInstance(TimeZoneUsage.class, getClass()); @Test void identification() { @@ -26,7 +20,10 @@ void identification() { "import java.time.LocalDate;", "import java.time.LocalDateTime;", "import java.time.LocalTime;", + "import java.time.OffsetDateTime;", + "import java.time.OffsetTime;", "import java.time.ZoneId;", + "import java.time.ZonedDateTime;", "", "class A {", " void m() {", @@ -36,48 +33,69 @@ void identification() { " Clock.offset(clock, Duration.ZERO);", " Clock.tick(clock, Duration.ZERO);", "", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " Clock.systemUTC();", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " Clock.systemDefaultZone();", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " Clock.system(UTC);", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " Clock.tickMillis(UTC);", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " Clock.tickMinutes(UTC);", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " Clock.tickSeconds(UTC);", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " clock.getZone();", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " clock.withZone(UTC);", "", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " Instant.now();", " // This is equivalent to `clock.instant()`, which is fine.", " Instant.now(clock);", "", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " LocalDate.now();", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " LocalDate.now(clock);", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " LocalDate.now(UTC);", "", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " LocalDateTime.now();", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " LocalDateTime.now(clock);", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " LocalDateTime.now(UTC);", "", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " LocalTime.now();", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " LocalTime.now(clock);", - " // BUG: Diagnostic matches: X", + " // BUG: Diagnostic contains:", " LocalTime.now(UTC);", + "", + " // BUG: Diagnostic contains:", + " OffsetDateTime.now();", + " // BUG: Diagnostic contains:", + " OffsetDateTime.now(clock);", + " // BUG: Diagnostic contains:", + " OffsetDateTime.now(UTC);", + "", + " // BUG: Diagnostic contains:", + " OffsetTime.now();", + " // BUG: Diagnostic contains:", + " OffsetTime.now(clock);", + " // BUG: Diagnostic contains:", + " OffsetTime.now(UTC);", + "", + " // BUG: Diagnostic contains:", + " ZonedDateTime.now();", + " // BUG: Diagnostic contains:", + " ZonedDateTime.now(clock);", + " // BUG: Diagnostic contains:", + " ZonedDateTime.now(UTC);", " }", "", " abstract class ForwardingClock extends Clock {", From 92f2b0ab0f83649aff1bc2a7b56bff821fd70929 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Tue, 25 Oct 2022 17:13:43 +0200 Subject: [PATCH 032/601] Introduce `MoreTypes` utility class (#234) The static methods of this class allow one to construct complex types, against which expression types can subsequently be matched. --- .../bugpatterns/NestedOptionals.java | 24 +-- .../bugpatterns/RefasterRuleModifiers.java | 2 +- .../errorprone/bugpatterns/StaticImport.java | 3 +- .../errorprone/bugpatterns/StringJoin.java | 4 +- .../bugpatterns/util/MoreTypes.java | 132 ++++++++++++ .../bugpatterns/util/MoreTypesTest.java | 188 ++++++++++++++++++ 6 files changed, 333 insertions(+), 20 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreTypes.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreTypesTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedOptionals.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedOptionals.java index 1c6228e29e..b736d5a050 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedOptionals.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedOptionals.java @@ -4,9 +4,11 @@ import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; import static com.google.errorprone.BugPattern.StandardTags.FRAGILE_CODE; import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.generic; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.raw; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.subOf; import com.google.auto.service.AutoService; -import com.google.common.collect.Iterables; import com.google.errorprone.BugPattern; import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.BugChecker; @@ -16,9 +18,7 @@ import com.google.errorprone.suppliers.Suppliers; import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.MethodInvocationTree; -import com.sun.source.tree.Tree; import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.util.List; import java.util.Optional; /** A {@link BugChecker} that flags nesting of {@link Optional Optionals}. */ @@ -33,24 +33,16 @@ public final class NestedOptionals extends BugChecker implements MethodInvocationTreeMatcher { private static final long serialVersionUID = 1L; private static final Supplier OPTIONAL = Suppliers.typeFromClass(Optional.class); + private static final Supplier OPTIONAL_OF_OPTIONAL = + VisitorState.memoize(generic(OPTIONAL, subOf(raw(OPTIONAL)))); /** Instantiates a new {@link NestedOptionals} instance. */ public NestedOptionals() {} @Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { - return isOptionalOfOptional(tree, state) ? describeMatch(tree) : Description.NO_MATCH; - } - - private static boolean isOptionalOfOptional(Tree tree, VisitorState state) { - Type optionalType = OPTIONAL.get(state); - Type type = ASTHelpers.getType(tree); - if (!ASTHelpers.isSubtype(type, optionalType, state)) { - return false; - } - - List typeArguments = type.getTypeArguments(); - return !typeArguments.isEmpty() - && ASTHelpers.isSubtype(Iterables.getOnlyElement(typeArguments), optionalType, state); + return state.getTypes().isSubtype(ASTHelpers.getType(tree), OPTIONAL_OF_OPTIONAL.get(state)) + ? describeMatch(tree) + : Description.NO_MATCH; } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiers.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiers.java index 5cd6a5db49..88fbb22fc8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiers.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiers.java @@ -29,7 +29,7 @@ import javax.lang.model.element.Modifier; /** - * A {@link BugChecker} which suggests a canonical set of modifiers for Refaster class and method + * A {@link BugChecker} that suggests a canonical set of modifiers for Refaster class and method * definitions. */ @AutoService(BugChecker.class) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java index d5bc39c5ec..6063562002 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java @@ -101,7 +101,8 @@ public final class StaticImport extends BugChecker implements MemberSelectTreeMa "org.springframework.http.HttpMethod", "org.springframework.http.MediaType", "org.testng.Assert", - "reactor.function.TupleUtils"); + "reactor.function.TupleUtils", + "tech.picnic.errorprone.bugpatterns.util.MoreTypes"); /** Type members that should be statically imported. */ @VisibleForTesting diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java index 5941f541b5..e590037268 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java @@ -30,8 +30,8 @@ import tech.picnic.errorprone.bugpatterns.util.SourceCode; /** - * A {@link BugChecker} which flags {@link String#format(String, Object...)} invocations which can - * be replaced with a {@link String#join(CharSequence, CharSequence...)} or even a {@link + * A {@link BugChecker} that flags {@link String#format(String, Object...)} invocations which can be + * replaced with a {@link String#join(CharSequence, CharSequence...)} or even a {@link * String#valueOf} invocation. */ // XXX: What about `v1 + "sep" + v2` and similar expressions? Do we want to rewrite those to diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreTypes.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreTypes.java new file mode 100644 index 0000000000..7f8c2f3706 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreTypes.java @@ -0,0 +1,132 @@ +package tech.picnic.errorprone.bugpatterns.util; + +import static java.util.stream.Collectors.toCollection; + +import com.google.errorprone.VisitorState; +import com.google.errorprone.suppliers.Supplier; +import com.google.errorprone.suppliers.Suppliers; +import com.sun.tools.javac.code.BoundKind; +import com.sun.tools.javac.code.Type; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.function.BiFunction; + +/** + * A set of helper methods which together define a DSL for defining {@link Type types}. + * + *

These methods are meant to be statically imported. Example usage: + * + *

{@code
+ * Supplier type =
+ *     VisitorState.memoize(
+ *         generic(
+ *             type("reactor.core.publisher.Flux"),
+ *             subOf(generic(type("org.reactivestreams.Publisher"), unbound()))));
+ * }
+ * + * This statement produces a memoized supplier of the type {@code Flux>}. + */ +public final class MoreTypes { + private MoreTypes() {} + + /** + * Creates a supplier of the type with the given fully qualified name. + * + *

This method should only be used when building more complex types in combination with other + * {@link MoreTypes} methods. In other cases prefer directly calling {@link + * Suppliers#typeFromString(String)}. + * + * @param typeName The type of interest. + * @return A supplier which returns the described type if available in the given state, and {@code + * null} otherwise. + */ + public static Supplier type(String typeName) { + return Suppliers.typeFromString(typeName); + } + + /** + * Creates a supplier of the described generic type. + * + * @param type The base type of interest. + * @param typeArgs The desired type arguments. + * @return A supplier which returns the described type if available in the given state, and {@code + * null} otherwise. + */ + // XXX: The given `type` should be a generic type, so perhaps `withParams` would be a better + // method name. But the DSL wouldn't look as nice that way. + @SafeVarargs + @SuppressWarnings("varargs") + public static Supplier generic(Supplier type, Supplier... typeArgs) { + return propagateNull( + type, + (state, baseType) -> { + List params = + Arrays.stream(typeArgs).map(s -> s.get(state)).collect(toCollection(ArrayList::new)); + if (params.stream().anyMatch(Objects::isNull)) { + return null; + } + + return state.getType(baseType, /* isArray= */ false, params); + }); + } + + /** + * Creates a raw (erased, non-generic) variant of the given type. + * + * @param type The base type of interest. + * @return A supplier which returns the described type if available in the given state, and {@code + * null} otherwise. + */ + public static Supplier raw(Supplier type) { + return propagateNull(type, (state, baseType) -> baseType.tsym.erasure(state.getTypes())); + } + + /** + * Creates a {@code ? super T} wildcard type, with {@code T} bound to the given type. + * + * @param type The base type of interest. + * @return A supplier which returns the described type if available in the given state, and {@code + * null} otherwise. + */ + public static Supplier superOf(Supplier type) { + return propagateNull( + type, + (state, baseType) -> + new Type.WildcardType(baseType, BoundKind.SUPER, state.getSymtab().boundClass)); + } + + /** + * Creates a {@code ? extends T} wildcard type, with {@code T} bound to the given type. + * + * @param type The base type of interest. + * @return A supplier which returns the described type if available in the given state, and {@code + * null} otherwise. + */ + public static Supplier subOf(Supplier type) { + return propagateNull( + type, + (state, baseType) -> + new Type.WildcardType( + type.get(state), BoundKind.EXTENDS, state.getSymtab().boundClass)); + } + + /** + * Creates an unbound wildcard type ({@code ?}). + * + * @return A supplier which returns the described type. + */ + public static Supplier unbound() { + return state -> + new Type.WildcardType( + state.getSymtab().objectType, BoundKind.UNBOUND, state.getSymtab().boundClass); + } + + private static Supplier propagateNull( + Supplier type, BiFunction transformer) { + return state -> + Optional.ofNullable(type.get(state)).map(t -> transformer.apply(state, t)).orElse(null); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreTypesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreTypesTest.java new file mode 100644 index 0000000000..48d003fa20 --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreTypesTest.java @@ -0,0 +1,188 @@ +package tech.picnic.errorprone.bugpatterns.util; + +import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.generic; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.raw; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.subOf; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.superOf; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.type; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.unbound; + +import com.google.common.collect.ImmutableSet; +import com.google.errorprone.BugPattern; +import com.google.errorprone.CompilationTestHelper; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.suppliers.Supplier; +import com.google.errorprone.util.ASTHelpers; +import com.google.errorprone.util.Signatures; +import com.sun.source.tree.MethodInvocationTree; +import com.sun.tools.javac.code.Type; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Test; + +final class MoreTypesTest { + private static final ImmutableSet> TYPES = + ImmutableSet.of( + // Invalid types. + type("java.lang.Nonexistent"), + generic(type("java.util.Integer"), unbound()), + // Valid types. + type("java.lang.String"), + type("java.lang.Number"), + superOf(type("java.lang.Number")), + subOf(type("java.lang.Number")), + type("java.lang.Integer"), + superOf(type("java.lang.Integer")), + subOf(type("java.lang.Integer")), + type("java.util.Optional"), + raw(type("java.util.Optional")), + generic(type("java.util.Optional"), unbound()), + generic(type("java.util.Optional"), type("java.lang.Number")), + type("java.util.Collection"), + raw(type("java.util.Collection")), + generic(type("java.util.Collection"), unbound()), + generic(type("java.util.Collection"), type("java.lang.Number")), + generic(type("java.util.Collection"), superOf(type("java.lang.Number"))), + generic(type("java.util.Collection"), subOf(type("java.lang.Number"))), + generic(type("java.util.Collection"), type("java.lang.Integer")), + generic(type("java.util.Collection"), superOf(type("java.lang.Integer"))), + generic(type("java.util.Collection"), subOf(type("java.lang.Integer"))), + type("java.util.List"), + raw(type("java.util.List")), + generic(type("java.util.List"), unbound()), + generic(type("java.util.List"), type("java.lang.Number")), + generic(type("java.util.List"), superOf(type("java.lang.Number"))), + generic(type("java.util.List"), subOf(type("java.lang.Number"))), + generic(type("java.util.List"), type("java.lang.Integer")), + generic(type("java.util.List"), superOf(type("java.lang.Integer"))), + generic(type("java.util.List"), subOf(type("java.lang.Integer"))), + generic( + type("java.util.Map"), + type("java.lang.String"), + subOf(generic(type("java.util.Collection"), superOf(type("java.lang.Short")))))); + + @Test + void matcher() { + CompilationTestHelper.newInstance(SubtypeFlagger.class, getClass()) + .addSourceLines( + "/A.java", + "import java.util.Collection;", + "import java.util.List;", + "import java.util.Map;", + "import java.util.Optional;", + "import java.util.Set;", + "", + "class A {", + " void m() {", + " Object object = factory();", + " A a = factory();", + "", + " // BUG: Diagnostic contains: [Number, ? super Number, Integer, ? super Integer]", + " int integer = factory();", + "", + " // BUG: Diagnostic contains: [String]", + " String string = factory();", + "", + " // BUG: Diagnostic contains: [Optional]", + " Optional rawOptional = factory();", + " // BUG: Diagnostic contains: [Optional, Optional]", + " Optional optionalOfS = factory();", + " // BUG: Diagnostic contains: [Optional, Optional]", + " Optional optionalOfT = factory();", + " // BUG: Diagnostic contains: [Optional, Optional, Optional]", + " Optional optionalOfNumber = factory();", + " // BUG: Diagnostic contains: [Optional, Optional]", + " Optional optionalOfInteger = factory();", + "", + " // BUG: Diagnostic contains: [Collection]", + " Collection rawCollection = factory();", + " // BUG: Diagnostic contains: [Collection, Collection, Collection, Collection, Collection, Collection]", + " Collection collectionOfNumber = factory();", + " // BUG: Diagnostic contains: [Collection, Collection, Collection,", + " // Collection, Collection, Collection]", + " Collection collectionOfInteger = factory();", + " // BUG: Diagnostic contains: [Collection, Collection, Collection]", + " Collection collectionOfShort = factory();", + "", + " // BUG: Diagnostic contains: [Collection, List]", + " List rawList = factory();", + " // BUG: Diagnostic contains: [Collection, Collection, Collection, Collection, Collection, Collection, List, List,", + " // List, List, List, List]", + " List listOfNumber = factory();", + " // BUG: Diagnostic contains: [Collection, Collection, Collection,", + " // Collection, Collection, Collection, List,", + " // List, List, List, List, List]", + " List listOfInteger = factory();", + " // BUG: Diagnostic contains: [Collection, Collection, Collection, List,", + " // List, List]", + " List listOfShort = factory();", + "", + " // BUG: Diagnostic contains: [Collection]", + " Set rawSet = factory();", + " // BUG: Diagnostic contains: [Collection, Collection, Collection, Collection, Collection, Collection]", + " Set setOfNumber = factory();", + " // BUG: Diagnostic contains: [Collection, Collection, Collection,", + " // Collection, Collection, Collection]", + " Set setOfInteger = factory();", + " // BUG: Diagnostic contains: [Collection, Collection, Collection]", + " Set setOfShort = factory();", + "", + " Map rawMap = factory();", + " Map> mapFromNumberToCollectionOfNumber = factory();", + " Map> mapFromNumberToCollectionOfShort = factory();", + " Map> mapFromNumberToCollectionOfInteger = factory();", + " // BUG: Diagnostic contains: [Map>]", + " Map> mapFromStringToCollectionOfNumber = factory();", + " // BUG: Diagnostic contains: [Map>]", + " Map> mapFromStringToCollectionOfShort = factory();", + " Map> mapFromStringToCollectionOfInteger = factory();", + " // BUG: Diagnostic contains: [Map>]", + " Map> mapFromStringToListOfNumber = factory();", + " // BUG: Diagnostic contains: [Map>]", + " Map> mapFromStringToListOfShort = factory();", + " Map> mapFromStringToListOfInteger = factory();", + " }", + "", + " private T factory() {", + " return null;", + " }", + "}") + .doTest(); + } + + /** + * A {@link BugChecker} that flags method invocations that are a subtype of any type contained in + * {@link #TYPES}. + */ + @BugPattern(summary = "Flags invocations of methods with select return types", severity = ERROR) + public static final class SubtypeFlagger extends BugChecker + implements MethodInvocationTreeMatcher { + private static final long serialVersionUID = 1L; + + @Override + public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { + Type treeType = ASTHelpers.getType(tree); + + List matches = new ArrayList<>(); + + for (Supplier type : TYPES) { + Type testType = type.get(state); + if (testType != null && state.getTypes().isSubtype(treeType, testType)) { + matches.add(Signatures.prettyType(testType)); + } + } + + return matches.isEmpty() + ? Description.NO_MATCH + : buildDescription(tree).setMessage(matches.toString()).build(); + } + } +} From 6cb10ffe2f32d644ff33afea6f0ae9c7cdcdc4be Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Tue, 25 Oct 2022 17:51:24 +0200 Subject: [PATCH 033/601] Build and test on additional platforms and against additional JDKs (#301) --- .github/workflows/build.yaml | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5c93ff91ac..4979e59dc0 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -7,10 +7,27 @@ permissions: contents: read jobs: build: - runs-on: ubuntu-22.04 strategy: matrix: - jdk: [ 11.0.16, 17.0.4 ] + os: [ ubuntu-22.04 ] + jdk: [ 11.0.16, 17.0.4, 19 ] + distribution: [ temurin ] + experimental: [ false ] + include: + - os: macos-12 + jdk: 17.0.4 + distribution: temurin + experimental: false + - os: windows-2022 + jdk: 17.0.4 + distribution: temurin + experimental: false + - os: ubuntu-22.04 + jdk: 20-ea + distribution: zulu + experimental: true + runs-on: ${{ matrix.os }} + continue-on-error: ${{ matrix.experimental }} steps: # We run the build twice for each supported JDK: once against the # original Error Prone release, using only Error Prone checks available @@ -23,7 +40,7 @@ jobs: uses: actions/setup-java@v3.6.0 with: java-version: ${{ matrix.jdk }} - distribution: temurin + distribution: ${{ matrix.distribution }} cache: maven - name: Display build environment details run: mvn --version From 45dfc53d402480fa1bef779a329ba014ca6f40a4 Mon Sep 17 00:00:00 2001 From: Eric Staffas <114935344+eric-picnic@users.noreply.github.com> Date: Wed, 26 Oct 2022 08:28:35 +0200 Subject: [PATCH 034/601] Prefer `Flux#take(long, boolean)` over `Flux#take(long)` to limit upstream generation (#314) --- .../refasterrules/ReactorRules.java | 31 +++++++++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 4 +++ .../refasterrules/ReactorRulesTestOutput.java | 4 +++ 3 files changed, 39 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 1b3bf9c3e9..d2eb81d06d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1,6 +1,7 @@ package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.MoreCollectors.toOptional; +import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static java.util.function.Function.identity; import static org.assertj.core.api.Assertions.assertThat; @@ -28,7 +29,9 @@ import reactor.test.StepVerifier; import reactor.test.publisher.PublisherProbe; import reactor.util.context.Context; +import tech.picnic.errorprone.refaster.annotation.Description; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; +import tech.picnic.errorprone.refaster.annotation.Severity; import tech.picnic.errorprone.refaster.matchers.ThrowsCheckedException; /** Refaster rules related to Reactor expressions and statements. */ @@ -144,6 +147,34 @@ Mono after(Mono mono, S object) { } } + /** + * Prefer {@link Flux#take(long, boolean)} over {@link Flux#take(long)}. + * + *

In Reactor versions prior to 3.5.0, {@code Flux#take(long)} makes an unbounded request + * upstream, and is equivalent to {@code Flux#take(long, false)}. In 3.5.0, the behavior of {@code + * Flux#take(long)} will change to that of {@code Flux#take(long, true)}. + * + *

The intent with this Refaster rule is to get the new behavior before upgrading to Reactor + * 3.5.0. + */ + // XXX: Drop this rule some time after upgrading to Reactor 3.6.0, or introduce a way to apply + // this rule only when an older version of Reactor is on the classpath. + // XXX: Once Reactor 3.6.0 is out, introduce a rule that rewrites code in the opposite direction. + @Description( + "Prior to Reactor 3.5.0, `take(n)` requests and unbounded number of elements upstream.") + @Severity(WARNING) + static final class FluxTake { + @BeforeTemplate + Flux before(Flux flux, long n) { + return flux.take(n); + } + + @AfterTemplate + Flux after(Flux flux, long n) { + return flux.take(n, /* limitRequest= */ true); + } + } + /** Don't unnecessarily pass an empty publisher to {@link Mono#switchIfEmpty(Mono)}. */ static final class MonoSwitchIfEmptyOfEmptyPublisher { @BeforeTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 270dce8306..60c0902de4 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -58,6 +58,10 @@ Mono testMonoThenReturn() { return Mono.empty().then(Mono.just("foo")); } + Flux testFluxTake() { + return Flux.just(1, 2, 3).take(1); + } + Mono testMonoSwitchIfEmptyOfEmptyPublisher() { return Mono.just(1).switchIfEmpty(Mono.empty()); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index 2c790c959b..e24d8157fe 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -60,6 +60,10 @@ Mono testMonoThenReturn() { return Mono.empty().thenReturn("foo"); } + Flux testFluxTake() { + return Flux.just(1, 2, 3).take(1, true); + } + Mono testMonoSwitchIfEmptyOfEmptyPublisher() { return Mono.just(1); } From b0d374040ab1f94e986c4628d76effc12505cf49 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 26 Oct 2022 09:19:33 +0200 Subject: [PATCH 035/601] Upgrade ruby/setup-ruby v1.118.0 -> v1.120.0 (#317) See: - https://github.com/ruby/setup-ruby/releases/tag/v1.119.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.120.0 - https://github.com/ruby/setup-ruby/compare/v1.118.0...v1.120.0 --- .github/workflows/deploy-website.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index 88f7c61009..65ce85b27c 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -16,7 +16,7 @@ jobs: steps: - name: Check out code uses: actions/checkout@v3.1.0 - - uses: ruby/setup-ruby@v1.118.0 + - uses: ruby/setup-ruby@v1.120.0 with: working-directory: ./website bundler-cache: true From f3b81304b967e5391fd9b7e60a20b02df88cd355 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 26 Oct 2022 10:00:34 +0200 Subject: [PATCH 036/601] Upgrade pitest-maven-plugin 1.9.8 -> 1.9.9 (#136) See https://github.com/hcoles/pitest/compare/1.9.8...1.9.9 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b961fc894a..b116241e28 100644 --- a/pom.xml +++ b/pom.xml @@ -1265,7 +1265,7 @@ org.pitest pitest-maven - 1.9.8 + 1.9.9 *.AutoValue_* From 2196bbd8f9ba5b71675d9c75f93e5280fed2afb3 Mon Sep 17 00:00:00 2001 From: Elena Liashenko Date: Wed, 26 Oct 2022 10:40:09 +0200 Subject: [PATCH 037/601] Have `FluxFlatMapUsage` better handle nested `Publisher`s (#224) --- .../bugpatterns/FluxFlatMapUsage.java | 54 ++++++++++++++----- .../bugpatterns/FluxFlatMapUsageTest.java | 25 ++++++++- 2 files changed, 63 insertions(+), 16 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsage.java index a449084b84..4485527e17 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsage.java @@ -5,6 +5,10 @@ import static com.google.errorprone.BugPattern.StandardTags.LIKELY_ERROR; import static com.google.errorprone.matchers.method.MethodMatchers.instanceMethod; import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.generic; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.subOf; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.type; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.unbound; import com.google.auto.service.AutoService; import com.google.common.collect.Iterables; @@ -17,11 +21,14 @@ import com.google.errorprone.fixes.SuggestedFixes; import com.google.errorprone.matchers.Description; import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.suppliers.Supplier; +import com.google.errorprone.suppliers.Suppliers; +import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.MemberReferenceTree; import com.sun.source.tree.MethodInvocationTree; +import com.sun.tools.javac.code.Type; import java.util.function.Function; -import java.util.function.Supplier; import reactor.core.publisher.Flux; /** @@ -33,11 +40,12 @@ * former interleaves values as they are emitted, yielding nondeterministic results. In most cases * {@link Flux#concatMap(Function)} should be preferred, as it produces consistent results and * avoids potentially saturating the thread pool on which subscription happens. If {@code - * concatMap}'s single-subscription semantics are undesirable one should invoke a {@code flatMap} or - * {@code flatMapSequential} overload with an explicit concurrency level. + * concatMap}'s sequential-subscription semantics are undesirable one should invoke a {@code + * flatMap} or {@code flatMapSequential} overload with an explicit concurrency level. * - *

NB: The rarely-used overload {@link Flux#flatMap(Function, Function, Supplier)} is not flagged - * by this check because there is no clear alternative to point to. + *

NB: The rarely-used overload {@link Flux#flatMap(Function, Function, + * java.util.function.Supplier)} is not flagged by this check because there is no clear alternative + * to point to. */ @AutoService(BugChecker.class) @BugPattern( @@ -52,11 +60,16 @@ public final class FluxFlatMapUsage extends BugChecker implements MethodInvocationTreeMatcher, MemberReferenceTreeMatcher { private static final long serialVersionUID = 1L; private static final String MAX_CONCURRENCY_ARG_NAME = "MAX_CONCURRENCY"; + private static final Supplier FLUX = + Suppliers.typeFromString("reactor.core.publisher.Flux"); private static final Matcher FLUX_FLATMAP = instanceMethod() - .onDescendantOf("reactor.core.publisher.Flux") + .onDescendantOf(FLUX) .namedAnyOf("flatMap", "flatMapSequential") .withParameters(Function.class.getName()); + private static final Supplier FLUX_OF_PUBLISHERS = + VisitorState.memoize( + generic(FLUX, subOf(generic(type("org.reactivestreams.Publisher"), unbound())))); /** Instantiates a new {@link FluxFlatMapUsage} instance. */ public FluxFlatMapUsage() {} @@ -67,14 +80,27 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState return Description.NO_MATCH; } - return buildDescription(tree) - .addFix(SuggestedFixes.renameMethodInvocation(tree, "concatMap", state)) - .addFix( - SuggestedFix.builder() - .postfixWith( - Iterables.getOnlyElement(tree.getArguments()), ", " + MAX_CONCURRENCY_ARG_NAME) - .build()) - .build(); + SuggestedFix serializationFix = SuggestedFixes.renameMethodInvocation(tree, "concatMap", state); + SuggestedFix concurrencyCapFix = + SuggestedFix.builder() + .postfixWith( + Iterables.getOnlyElement(tree.getArguments()), ", " + MAX_CONCURRENCY_ARG_NAME) + .build(); + + Description.Builder description = buildDescription(tree); + + if (state.getTypes().isSubtype(ASTHelpers.getType(tree), FLUX_OF_PUBLISHERS.get(state))) { + /* + * Nested publishers may need to be subscribed to eagerly in order to avoid a deadlock, e.g. + * if they are produced by `Flux#groupBy`. In this case we suggest specifying an explicit + * concurrently bound, in favour of sequential subscriptions using `Flux#concatMap`. + */ + description.addFix(concurrencyCapFix).addFix(serializationFix); + } else { + description.addFix(serializationFix).addFix(concurrencyCapFix); + } + + return description.build(); } @Override diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsageTest.java index 7cfd295b56..a80414e18b 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsageTest.java @@ -4,6 +4,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; +import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.CompilationTestHelper; import org.junit.jupiter.api.Test; @@ -33,6 +34,14 @@ void identification() { " Flux.just(1).flatMapSequential(Flux::just);", " // BUG: Diagnostic contains:", " Flux.just(1).flatMapSequential(i -> Flux.just(String.valueOf(i)));", + " // BUG: Diagnostic contains:", + " Flux.just(1, 2).groupBy(i -> i).flatMap(Flux::just);", + " // BUG: Diagnostic contains:", + " Flux.just(1, 2).groupBy(i -> i).flatMap(i -> Flux.just(String.valueOf(i)));", + " // BUG: Diagnostic contains:", + " Flux.just(1, 2).groupBy(i -> i).flatMapSequential(Flux::just);", + " // BUG: Diagnostic contains:", + " Flux.just(1, 2).groupBy(i -> i).flatMapSequential(i -> Flux.just(String.valueOf(i)));", "", " Mono.just(1).flatMap(Mono::just);", " Flux.just(1).concatMap(Flux::just);", @@ -71,9 +80,13 @@ void replacementFirstSuggestedFix() { "import reactor.core.publisher.Flux;", "", "class A {", + " private static final int MAX_CONCURRENCY = 8;", + "", " void m() {", " Flux.just(1).flatMap(Flux::just);", " Flux.just(1).flatMapSequential(Flux::just);", + " Flux.just(1, 2).groupBy(i -> i).flatMap(Flux::just);", + " Flux.just(1, 2).groupBy(i -> i).flatMapSequential(Flux::just);", " }", "}") .addOutputLines( @@ -81,12 +94,16 @@ void replacementFirstSuggestedFix() { "import reactor.core.publisher.Flux;", "", "class A {", + " private static final int MAX_CONCURRENCY = 8;", + "", " void m() {", " Flux.just(1).concatMap(Flux::just);", " Flux.just(1).concatMap(Flux::just);", + " Flux.just(1, 2).groupBy(i -> i).flatMap(Flux::just, MAX_CONCURRENCY);", + " Flux.just(1, 2).groupBy(i -> i).flatMapSequential(Flux::just, MAX_CONCURRENCY);", " }", "}") - .doTest(); + .doTest(TestMode.TEXT_MATCH); } @Test @@ -103,6 +120,8 @@ void replacementSecondSuggestedFix() { " void m() {", " Flux.just(1).flatMap(Flux::just);", " Flux.just(1).flatMapSequential(Flux::just);", + " Flux.just(1, 2).groupBy(i -> i).flatMap(Flux::just);", + " Flux.just(1, 2).groupBy(i -> i).flatMapSequential(Flux::just);", " }", "}") .addOutputLines( @@ -115,8 +134,10 @@ void replacementSecondSuggestedFix() { " void m() {", " Flux.just(1).flatMap(Flux::just, MAX_CONCURRENCY);", " Flux.just(1).flatMapSequential(Flux::just, MAX_CONCURRENCY);", + " Flux.just(1, 2).groupBy(i -> i).concatMap(Flux::just);", + " Flux.just(1, 2).groupBy(i -> i).concatMap(Flux::just);", " }", "}") - .doTest(); + .doTest(TestMode.TEXT_MATCH); } } From dc0f90e9814d0a25c0e48d272c97cba6ad4d2639 Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Wed, 26 Oct 2022 10:53:27 +0200 Subject: [PATCH 038/601] Introduce `{Mono,Flux}#zipWith{,Iterable}` Refaster rules (#293) --- error-prone-contrib/pom.xml | 5 ++ .../refasterrules/ReactorRules.java | 88 +++++++++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 21 +++++ .../refasterrules/ReactorRulesTestOutput.java | 26 ++++++ 4 files changed, 140 insertions(+) diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index 2696e612d2..3e7d97d6a6 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -93,6 +93,11 @@ reactor-adapter provided + + io.projectreactor.addons + reactor-extra + provided + io.reactivex.rxjava2 rxjava diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index d2eb81d06d..f669dbe3df 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -5,6 +5,7 @@ import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static java.util.function.Function.identity; import static org.assertj.core.api.Assertions.assertThat; +import static reactor.function.TupleUtils.function; import com.google.common.collect.ImmutableMap; import com.google.common.collect.MoreCollectors; @@ -19,6 +20,7 @@ import java.util.HashMap; import java.util.Optional; import java.util.concurrent.Callable; +import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; @@ -29,6 +31,7 @@ import reactor.test.StepVerifier; import reactor.test.publisher.PublisherProbe; import reactor.util.context.Context; +import reactor.util.function.Tuple2; import tech.picnic.errorprone.refaster.annotation.Description; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; import tech.picnic.errorprone.refaster.annotation.Severity; @@ -74,6 +77,91 @@ Mono after(Optional optional) { } } + /** + * Prefer {@link Mono#zip(Mono, Mono)} over a chained {@link Mono#zipWith(Mono)}, as the former + * better conveys that the {@link Mono}s may be subscribed to concurrently, and generalizes to + * combining three or more reactive streams. + */ + static final class MonoZip { + @BeforeTemplate + Mono> before(Mono mono, Mono other) { + return mono.zipWith(other); + } + + @AfterTemplate + Mono> after(Mono mono, Mono other) { + return Mono.zip(mono, other); + } + } + + /** + * Prefer {@link Mono#zip(Mono, Mono)} with a chained combinator over a chained {@link + * Mono#zipWith(Mono, BiFunction)}, as the former better conveys that the {@link Mono}s may be + * subscribed to concurrently, and generalizes to combining three or more reactive streams. + */ + static final class MonoZipWithCombinator { + @BeforeTemplate + Mono before(Mono mono, Mono other, BiFunction combinator) { + return mono.zipWith(other, combinator); + } + + @AfterTemplate + Mono after(Mono mono, Mono other, BiFunction combinator) { + return Mono.zip(mono, other).map(function(combinator)); + } + } + + /** + * Prefer {@link Flux#zip(Publisher, Publisher)} over a chained {@link Flux#zipWith(Publisher)}, + * as the former better conveys that the {@link Publisher}s may be subscribed to concurrently, and + * generalizes to combining three or more reactive streams. + */ + static final class FluxZip { + @BeforeTemplate + Flux> before(Flux flux, Publisher other) { + return flux.zipWith(other); + } + + @AfterTemplate + Flux> after(Flux flux, Publisher other) { + return Flux.zip(flux, other); + } + } + + /** + * Prefer {@link Flux#zip(Publisher, Publisher)} with a chained combinator over a chained {@link + * Flux#zipWith(Publisher, BiFunction)}, as the former better conveys that the {@link Publisher}s + * may be subscribed to concurrently, and generalizes to combining three or more reactive streams. + */ + static final class FluxZipWithCombinator { + @BeforeTemplate + Flux before(Flux flux, Publisher other, BiFunction combinator) { + return flux.zipWith(other, combinator); + } + + @AfterTemplate + Flux after(Flux flux, Publisher other, BiFunction combinator) { + return Flux.zip(flux, other).map(function(combinator)); + } + } + + /** + * Prefer {@link Flux#zipWithIterable(Iterable)} with a chained combinator over {@link + * Flux#zipWithIterable(Iterable, BiFunction)}, as the former generally yields more readable code. + */ + static final class FluxZipWithIterable { + @BeforeTemplate + Flux before(Flux flux, Iterable iterable, BiFunction combinator) { + return flux.zipWithIterable(iterable, combinator); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + Flux after(Flux flux, Iterable iterable, BiFunction combinator) { + return flux.zipWithIterable(iterable).map(function(combinator)); + } + } + /** Don't unnecessarily defer {@link Mono#error(Throwable)}. */ static final class MonoDeferredError { @BeforeTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 60c0902de4..291e2a1698 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -15,6 +15,7 @@ import reactor.test.StepVerifier; import reactor.test.publisher.PublisherProbe; import reactor.util.context.Context; +import reactor.util.function.Tuple2; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class ReactorRulesTest implements RefasterRuleCollectionTestCase { @@ -38,6 +39,26 @@ ImmutableSet> testMonoFromOptional() { Mono.fromSupplier(() -> Optional.of(2).orElse(null))); } + Mono> testMonoZip() { + return Mono.just("foo").zipWith(Mono.just(1)); + } + + Mono testMonoZipWithCombinator() { + return Mono.just("foo").zipWith(Mono.just(1), String::repeat); + } + + Flux> testFluxZip() { + return Flux.just("foo", "bar").zipWith(Flux.just(1, 2)); + } + + Flux testFluxZipWithCombinator() { + return Flux.just("foo", "bar").zipWith(Flux.just(1, 2), String::repeat); + } + + Flux testFluxZipWithIterable() { + return Flux.just("foo", "bar").zipWithIterable(ImmutableSet.of(1, 2), String::repeat); + } + Mono testMonoDeferredError() { return Mono.defer(() -> Mono.error(new IllegalStateException())); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index e24d8157fe..a43d3e78f9 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -3,6 +3,7 @@ import static com.google.common.collect.MoreCollectors.toOptional; import static java.util.function.Function.identity; import static org.assertj.core.api.Assertions.assertThat; +import static reactor.function.TupleUtils.function; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -14,9 +15,11 @@ import java.util.function.Supplier; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +import reactor.function.TupleUtils; import reactor.test.StepVerifier; import reactor.test.publisher.PublisherProbe; import reactor.util.context.Context; +import reactor.util.function.Tuple2; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class ReactorRulesTest implements RefasterRuleCollectionTestCase { @@ -40,6 +43,29 @@ ImmutableSet> testMonoFromOptional() { Mono.defer(() -> Mono.justOrEmpty(Optional.of(2)))); } + Mono> testMonoZip() { + return Mono.zip(Mono.just("foo"), Mono.just(1)); + } + + Mono testMonoZipWithCombinator() { + return Mono.zip(Mono.just("foo"), Mono.just(1)).map(TupleUtils.function(String::repeat)); + } + + Flux> testFluxZip() { + return Flux.zip(Flux.just("foo", "bar"), Flux.just(1, 2)); + } + + Flux testFluxZipWithCombinator() { + return Flux.zip(Flux.just("foo", "bar"), Flux.just(1, 2)) + .map(TupleUtils.function(String::repeat)); + } + + Flux testFluxZipWithIterable() { + return Flux.just("foo", "bar") + .zipWithIterable(ImmutableSet.of(1, 2)) + .map(function(String::repeat)); + } + Mono testMonoDeferredError() { return Mono.error(() -> new IllegalStateException()); } From afb2a28dcfc7fdb0b2834e78e84aad99d4d191f0 Mon Sep 17 00:00:00 2001 From: Cernat Catalin Stefan Date: Wed, 26 Oct 2022 17:11:16 +0200 Subject: [PATCH 039/601] Introduce `{Mono,Flux}Map{,NotNull}` Refaster rules (#142) --- .../refasterrules/ReactorRules.java | 185 +++++++++++++++++- .../refasterrules/ReactorRulesTestInput.java | 66 ++++++- .../refasterrules/ReactorRulesTestOutput.java | 63 +++++- 3 files changed, 309 insertions(+), 5 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index f669dbe3df..5f2f44045e 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -362,16 +362,195 @@ Flux after( */ abstract static class MonoFlatMapToFlux { @Placeholder(allowsIdentity = true) - abstract Mono valueTransformation(@MayOptionallyUse T value); + abstract Mono transformation(@MayOptionallyUse T value); @BeforeTemplate Flux before(Mono mono) { - return mono.flatMapMany(v -> valueTransformation(v)); + return mono.flatMapMany(v -> transformation(v)); } @AfterTemplate Flux after(Mono mono) { - return mono.flatMap(v -> valueTransformation(v)).flux(); + return mono.flatMap(v -> transformation(v)).flux(); + } + } + + /** + * Prefer {@link Mono#map(Function)} over alternatives that unnecessarily require an inner + * subscription. + */ + abstract static class MonoMap { + @Placeholder(allowsIdentity = true) + abstract S transformation(@MayOptionallyUse T value); + + @BeforeTemplate + Mono before(Mono mono) { + return mono.flatMap(x -> Mono.just(transformation(x))); + } + + @AfterTemplate + Mono after(Mono mono) { + return mono.map(x -> transformation(x)); + } + } + + /** + * Prefer {@link Flux#map(Function)} over alternatives that unnecessarily require an inner + * subscription. + */ + abstract static class FluxMap { + @Placeholder(allowsIdentity = true) + abstract S transformation(@MayOptionallyUse T value); + + @BeforeTemplate + Flux before(Flux flux, boolean delayUntilEnd, int maxConcurrency, int prefetch) { + return Refaster.anyOf( + flux.concatMap(x -> Mono.just(transformation(x))), + flux.concatMap(x -> Flux.just(transformation(x))), + flux.concatMap(x -> Mono.just(transformation(x)), prefetch), + flux.concatMap(x -> Flux.just(transformation(x)), prefetch), + flux.concatMapDelayError(x -> Mono.just(transformation(x))), + flux.concatMapDelayError(x -> Flux.just(transformation(x))), + flux.concatMapDelayError(x -> Mono.just(transformation(x)), prefetch), + flux.concatMapDelayError(x -> Flux.just(transformation(x)), prefetch), + flux.concatMapDelayError(x -> Mono.just(transformation(x)), delayUntilEnd, prefetch), + flux.concatMapDelayError(x -> Flux.just(transformation(x)), delayUntilEnd, prefetch), + flux.flatMap(x -> Mono.just(transformation(x)), maxConcurrency), + flux.flatMap(x -> Flux.just(transformation(x)), maxConcurrency), + flux.flatMap(x -> Mono.just(transformation(x)), maxConcurrency, prefetch), + flux.flatMap(x -> Flux.just(transformation(x)), maxConcurrency, prefetch), + flux.flatMapDelayError(x -> Mono.just(transformation(x)), maxConcurrency, prefetch), + flux.flatMapDelayError(x -> Flux.just(transformation(x)), maxConcurrency, prefetch), + flux.flatMapSequential(x -> Mono.just(transformation(x)), maxConcurrency), + flux.flatMapSequential(x -> Flux.just(transformation(x)), maxConcurrency), + flux.flatMapSequential(x -> Mono.just(transformation(x)), maxConcurrency, prefetch), + flux.flatMapSequential(x -> Flux.just(transformation(x)), maxConcurrency, prefetch), + flux.flatMapSequentialDelayError( + x -> Mono.just(transformation(x)), maxConcurrency, prefetch), + flux.flatMapSequentialDelayError( + x -> Flux.just(transformation(x)), maxConcurrency, prefetch), + flux.switchMap(x -> Mono.just(transformation(x))), + flux.switchMap(x -> Flux.just(transformation(x)))); + } + + @AfterTemplate + Flux after(Flux flux) { + return flux.map(x -> transformation(x)); + } + } + + /** + * Prefer {@link Mono#mapNotNull(Function)} over alternatives that unnecessarily require an inner + * subscription. + */ + abstract static class MonoMapNotNull { + @Placeholder(allowsIdentity = true) + abstract S transformation(@MayOptionallyUse T value); + + @BeforeTemplate + Mono before(Mono mono) { + return mono.flatMap( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), Mono.fromSupplier(() -> transformation(x)))); + } + + @AfterTemplate + Mono after(Mono mono) { + return mono.mapNotNull(x -> transformation(x)); + } + } + + /** + * Prefer {@link Flux#mapNotNull(Function)} over alternatives that unnecessarily require an inner + * subscription. + */ + abstract static class FluxMapNotNull { + @Placeholder(allowsIdentity = true) + abstract S transformation(@MayOptionallyUse T value); + + @BeforeTemplate + Publisher before(Flux flux, boolean delayUntilEnd, int maxConcurrency, int prefetch) { + return Refaster.anyOf( + flux.concatMap( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), + Mono.fromSupplier(() -> transformation(x)))), + flux.concatMap( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), + Mono.fromSupplier(() -> transformation(x))), + prefetch), + flux.concatMapDelayError( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), + Mono.fromSupplier(() -> transformation(x)))), + flux.concatMapDelayError( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), + Mono.fromSupplier(() -> transformation(x))), + prefetch), + flux.concatMapDelayError( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), + Mono.fromSupplier(() -> transformation(x))), + delayUntilEnd, + prefetch), + flux.flatMap( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), + Mono.fromSupplier(() -> transformation(x))), + maxConcurrency), + flux.flatMap( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), + Mono.fromSupplier(() -> transformation(x))), + maxConcurrency, + prefetch), + flux.flatMapDelayError( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), + Mono.fromSupplier(() -> transformation(x))), + maxConcurrency, + prefetch), + flux.flatMapSequential( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), + Mono.fromSupplier(() -> transformation(x))), + maxConcurrency), + flux.flatMapSequential( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), + Mono.fromSupplier(() -> transformation(x))), + maxConcurrency, + prefetch), + flux.flatMapSequentialDelayError( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), + Mono.fromSupplier(() -> transformation(x))), + maxConcurrency, + prefetch), + flux.switchMap( + x -> + Refaster.anyOf( + Mono.justOrEmpty(transformation(x)), + Mono.fromSupplier(() -> transformation(x))))); + } + + @AfterTemplate + Flux after(Flux flux) { + return flux.mapNotNull(x -> transformation(x)); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 291e2a1698..8c33d36b80 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -111,7 +111,71 @@ Flux testFluxConcatMapIterableWithPrefetch() { } Flux testMonoFlatMapToFlux() { - return Mono.just("foo").flatMapMany(s -> Mono.just(s + s)); + return Mono.just("foo").flatMapMany(s -> Mono.fromSupplier(() -> s + s)); + } + + ImmutableSet> testMonoMap() { + return ImmutableSet.of( + Mono.just("foo").flatMap(s -> Mono.just(s)), + Mono.just("bar").flatMap(s -> Mono.just(s.substring(1)))); + } + + ImmutableSet> testFluxMap() { + return ImmutableSet.of( + Flux.just(1).concatMap(n -> Mono.just(n)), + Flux.just(1).concatMap(n -> Flux.just(n * 2)), + Flux.just(1).concatMap(n -> Mono.just(n), 3), + Flux.just(1).concatMap(n -> Flux.just(n * 2), 3), + Flux.just(1).concatMapDelayError(n -> Mono.just(n)), + Flux.just(1).concatMapDelayError(n -> Flux.just(n * 2)), + Flux.just(1).concatMapDelayError(n -> Mono.just(n), 3), + Flux.just(1).concatMapDelayError(n -> Flux.just(n * 2), 3), + Flux.just(1).flatMap(n -> Mono.just(n), 3), + Flux.just(1).flatMap(n -> Flux.just(n * 2), 3), + Flux.just(1).flatMap(n -> Mono.just(n), 3, 4), + Flux.just(1).flatMap(n -> Flux.just(n * 2), 3, 4), + Flux.just(1).flatMapDelayError(n -> Mono.just(n), 3, 4), + Flux.just(1).flatMapDelayError(n -> Flux.just(n * 2), 3, 4), + Flux.just(1).flatMapSequential(n -> Mono.just(n), 3), + Flux.just(1).flatMapSequential(n -> Flux.just(n * 2), 3), + Flux.just(1).flatMapSequential(n -> Mono.just(n), 3, 4), + Flux.just(1).flatMapSequential(n -> Flux.just(n * 2), 3, 4), + Flux.just(1).flatMapSequentialDelayError(n -> Mono.just(n), 3, 4), + Flux.just(1).flatMapSequentialDelayError(n -> Flux.just(n * 2), 3, 4), + Flux.just(1).switchMap(n -> Mono.just(n)), + Flux.just(1).switchMap(n -> Flux.just(n * 2))); + } + + ImmutableSet> testMonoMapNotNull() { + return ImmutableSet.of( + Mono.just("foo").flatMap(s -> Mono.justOrEmpty(s)), + Mono.just("bar").flatMap(s -> Mono.fromSupplier(() -> s.substring(1)))); + } + + ImmutableSet> testFluxMapNotNull() { + return ImmutableSet.of( + Flux.just(1).concatMap(n -> Mono.justOrEmpty(n)), + Flux.just(1).concatMap(n -> Mono.fromSupplier(() -> n * 2)), + Flux.just(1).concatMap(n -> Mono.justOrEmpty(n), 3), + Flux.just(1).concatMap(n -> Mono.fromSupplier(() -> n * 2), 3), + Flux.just(1).concatMapDelayError(n -> Mono.justOrEmpty(n)), + Flux.just(1).concatMapDelayError(n -> Mono.fromSupplier(() -> n * 2)), + Flux.just(1).concatMapDelayError(n -> Mono.justOrEmpty(n), 3), + Flux.just(1).concatMapDelayError(n -> Mono.fromSupplier(() -> n * 2), 3), + Flux.just(1).flatMap(n -> Mono.justOrEmpty(n), 3), + Flux.just(1).flatMap(n -> Mono.fromSupplier(() -> n * 2), 3), + Flux.just(1).flatMap(n -> Mono.justOrEmpty(n), 3, 4), + Flux.just(1).flatMap(n -> Mono.fromSupplier(() -> n * 2), 3, 4), + Flux.just(1).flatMapDelayError(n -> Mono.justOrEmpty(n), 3, 4), + Flux.just(1).flatMapDelayError(n -> Mono.fromSupplier(() -> n * 2), 3, 4), + Flux.just(1).flatMapSequential(n -> Mono.justOrEmpty(n), 3), + Flux.just(1).flatMapSequential(n -> Mono.fromSupplier(() -> n * 2), 3), + Flux.just(1).flatMapSequential(n -> Mono.justOrEmpty(n), 3, 4), + Flux.just(1).flatMapSequential(n -> Mono.fromSupplier(() -> n * 2), 3, 4), + Flux.just(1).flatMapSequentialDelayError(n -> Mono.justOrEmpty(n), 3, 4), + Flux.just(1).flatMapSequentialDelayError(n -> Mono.fromSupplier(() -> n * 2), 3, 4), + Flux.just(1).switchMap(n -> Mono.justOrEmpty(n)), + Flux.just(1).switchMap(n -> Mono.fromSupplier(() -> n * 2))); } Flux testMonoFlux() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index a43d3e78f9..b943f50ea4 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -116,7 +116,68 @@ Flux testFluxConcatMapIterableWithPrefetch() { } Flux testMonoFlatMapToFlux() { - return Mono.just("foo").flatMap(s -> Mono.just(s + s)).flux(); + return Mono.just("foo").flatMap(s -> Mono.fromSupplier(() -> s + s)).flux(); + } + + ImmutableSet> testMonoMap() { + return ImmutableSet.of(Mono.just("foo").map(s -> s), Mono.just("bar").map(s -> s.substring(1))); + } + + ImmutableSet> testFluxMap() { + return ImmutableSet.of( + Flux.just(1).map(n -> n), + Flux.just(1).map(n -> n * 2), + Flux.just(1).map(n -> n), + Flux.just(1).map(n -> n * 2), + Flux.just(1).map(n -> n), + Flux.just(1).map(n -> n * 2), + Flux.just(1).map(n -> n), + Flux.just(1).map(n -> n * 2), + Flux.just(1).map(n -> n), + Flux.just(1).map(n -> n * 2), + Flux.just(1).map(n -> n), + Flux.just(1).map(n -> n * 2), + Flux.just(1).map(n -> n), + Flux.just(1).map(n -> n * 2), + Flux.just(1).map(n -> n), + Flux.just(1).map(n -> n * 2), + Flux.just(1).map(n -> n), + Flux.just(1).map(n -> n * 2), + Flux.just(1).map(n -> n), + Flux.just(1).map(n -> n * 2), + Flux.just(1).map(n -> n), + Flux.just(1).map(n -> n * 2)); + } + + ImmutableSet> testMonoMapNotNull() { + return ImmutableSet.of( + Mono.just("foo").mapNotNull(s -> s), Mono.just("bar").mapNotNull(s -> s.substring(1))); + } + + ImmutableSet> testFluxMapNotNull() { + return ImmutableSet.of( + Flux.just(1).mapNotNull(n -> n), + Flux.just(1).mapNotNull(n -> n * 2), + Flux.just(1).mapNotNull(n -> n), + Flux.just(1).mapNotNull(n -> n * 2), + Flux.just(1).mapNotNull(n -> n), + Flux.just(1).mapNotNull(n -> n * 2), + Flux.just(1).mapNotNull(n -> n), + Flux.just(1).mapNotNull(n -> n * 2), + Flux.just(1).mapNotNull(n -> n), + Flux.just(1).mapNotNull(n -> n * 2), + Flux.just(1).mapNotNull(n -> n), + Flux.just(1).mapNotNull(n -> n * 2), + Flux.just(1).mapNotNull(n -> n), + Flux.just(1).mapNotNull(n -> n * 2), + Flux.just(1).mapNotNull(n -> n), + Flux.just(1).mapNotNull(n -> n * 2), + Flux.just(1).mapNotNull(n -> n), + Flux.just(1).mapNotNull(n -> n * 2), + Flux.just(1).mapNotNull(n -> n), + Flux.just(1).mapNotNull(n -> n * 2), + Flux.just(1).mapNotNull(n -> n), + Flux.just(1).mapNotNull(n -> n * 2)); } Flux testMonoFlux() { From 04d886c03106d177b94d4e4cb73a9a6bcfa23dab Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Thu, 27 Oct 2022 10:31:06 +0200 Subject: [PATCH 040/601] Improve build and deployment concurrency handling (#284) Builds for the same branch are now serialized. Among other things this prevents concurrent deployments. While there, reduce the permission assigned to each of the two jobs. --- .github/workflows/deploy-website.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index 65ce85b27c..c0b664d9a5 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -3,15 +3,12 @@ on: pull_request: push: branches: [ master, website ] -permissions: - contents: read - id-token: write - pages: write concurrency: - group: pages - cancel-in-progress: true + group: ${{ github.workflow }}-${{ github.ref }} jobs: build: + permissions: + contents: read runs-on: ubuntu-22.04 steps: - name: Check out code @@ -39,6 +36,9 @@ jobs: deploy: if: github.ref == 'refs/heads/website' needs: build + permissions: + id-token: write + pages: write runs-on: ubuntu-22.04 environment: name: github-pages From 81227cdd94eb2bf2e5c4ac661214091e3eba25ee Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 27 Oct 2022 16:28:43 +0200 Subject: [PATCH 041/601] Upgrade tidy-maven-plugin 1.1.0 -> 1.2.0 (#271) See: - https://github.com/mojohaus/tidy-maven-plugin/releases/tag/tidy-maven-plugin-1.2.0 - https://github.com/mojohaus/tidy-maven-plugin/compare/tidy-maven-plugin-1.1.0...tidy-maven-plugin-1.2.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b116241e28..42f8958d83 100644 --- a/pom.xml +++ b/pom.xml @@ -1216,7 +1216,7 @@ org.codehaus.mojo tidy-maven-plugin - 1.1.0 + 1.2.0 org.codehaus.mojo From 022a3d293ed3b7044cebf2f0a3a3e3da2081a00b Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 28 Oct 2022 08:56:32 +0200 Subject: [PATCH 042/601] Upgrade New Relic Java Agent 7.10.0 -> 7.11.0 (#320) See: - https://github.com/newrelic/newrelic-java-agent/releases/tag/v7.11.0 - https://github.com/newrelic/newrelic-java-agent/compare/v7.10.0...v7.11.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 42f8958d83..29b86845fa 100644 --- a/pom.xml +++ b/pom.xml @@ -277,7 +277,7 @@ com.newrelic.agent.java newrelic-api - 7.10.0 + 7.11.0 From 8fa3ff3702f48d77a23bb12401d1ac4a4993f71a Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sat, 29 Oct 2022 13:42:51 +0200 Subject: [PATCH 043/601] By default, prevent `BugChecker`s from introducing new dependencies (#308) --- error-prone-contrib/pom.xml | 5 + .../bugpatterns/CollectorMutability.java | 4 +- .../ScheduledTransactionTrace.java | 4 +- .../bugpatterns/util/ThirdPartyLibrary.java | 105 ++++++++++++++++ .../bugpatterns/CollectorMutabilityTest.java | 17 +++ .../ScheduledTransactionTraceTest.java | 16 +++ .../util/ThirdPartyLibraryTest.java | 115 ++++++++++++++++++ 7 files changed, 264 insertions(+), 2 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibraryTest.java diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index 3e7d97d6a6..a27da56f31 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -173,6 +173,11 @@ slf4j-api test + + org.springframework + spring-context + test + org.springframework spring-test diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java index a715b613a2..e2baa3c10f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java @@ -18,6 +18,7 @@ import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.MethodInvocationTree; import java.util.stream.Collector; +import tech.picnic.errorprone.bugpatterns.util.ThirdPartyLibrary; /** * A {@link BugChecker} that flags {@link Collector Collectors} that don't clearly express @@ -50,7 +51,8 @@ public CollectorMutability() {} @Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { - if (!COLLECTOR_METHOD.matches(tree, state)) { + if (!ThirdPartyLibrary.GUAVA.isIntroductionAllowed(state) + || !COLLECTOR_METHOD.matches(tree, state)) { return Description.NO_MATCH; } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTrace.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTrace.java index a23a6ceeb6..73a9ec5f50 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTrace.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTrace.java @@ -26,6 +26,7 @@ import com.sun.source.tree.AnnotationTree; import com.sun.source.tree.MethodTree; import com.sun.source.tree.Tree; +import tech.picnic.errorprone.bugpatterns.util.ThirdPartyLibrary; /** * A {@link BugChecker} that flags methods with Spring's {@code @Scheduled} annotation that lack New @@ -51,7 +52,8 @@ public ScheduledTransactionTrace() {} @Override public Description matchMethod(MethodTree tree, VisitorState state) { - if (!IS_SCHEDULED.matches(tree, state)) { + if (!ThirdPartyLibrary.NEW_RELIC_AGENT_API.isIntroductionAllowed(state) + || !IS_SCHEDULED.matches(tree, state)) { return Description.NO_MATCH; } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java new file mode 100644 index 0000000000..9b8cbd9ebe --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java @@ -0,0 +1,105 @@ +package tech.picnic.errorprone.bugpatterns.util; + +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.suppliers.Supplier; +import com.sun.tools.javac.code.ClassFinder; +import com.sun.tools.javac.code.Symbol.CompletionFailure; +import com.sun.tools.javac.util.Name; + +/** + * Utility class that helps decide whether it is appropriate to introduce references to (well-known) + * third-party libraries. + * + *

This class should be used by {@link BugChecker}s that may otherwise suggest the introduction + * of code that depends on possibly-not-present third-party libraries. + */ +// XXX: Consider giving users more fine-grained control. This would be beneficial in cases where a +// dependency is on the classpath, but new usages are undesirable. +public enum ThirdPartyLibrary { + /** + * AssertJ. + * + * @see AssertJ documentation + */ + ASSERTJ("org.assertj.core.api.Assertions"), + /** + * Google's Guava. + * + * @see Guava on GitHub + */ + GUAVA("com.google.common.collect.ImmutableList"), + /** + * New Relic's Java agent API. + * + * @see New Relic + * Java agent API on GitHub + */ + NEW_RELIC_AGENT_API("com.newrelic.api.agent.Agent"), + /** + * VMWare's Project Reactor. + * + * @see Home page + */ + REACTOR("reactor.core.publisher.Flux"); + + private static final String IGNORE_CLASSPATH_COMPAT_FLAG = + "ErrorProneSupport:IgnoreClasspathCompat"; + + @SuppressWarnings("ImmutableEnumChecker" /* Supplier is deterministic. */) + private final Supplier canUse; + + /** + * Instantiates a {@link ThirdPartyLibrary} enum value. + * + * @param witnessFqcn The fully-qualified class name of a type that is expected to be on the + * classpath iff the associated third-party library is on the classpath. + */ + ThirdPartyLibrary(String witnessFqcn) { + this.canUse = VisitorState.memoize(state -> canIntroduceUsage(witnessFqcn, state)); + } + + /** + * Tells whether it is okay to introduce a dependency on this well-known third party library in + * the given context. + * + * @param state The context under consideration. + * @return {@code true} iff it is okay to assume or create a dependency on this library. + */ + public boolean isIntroductionAllowed(VisitorState state) { + return canUse.get(state); + } + + private static boolean canIntroduceUsage(String className, VisitorState state) { + return shouldIgnoreClasspath(state) || isKnownClass(className, state); + } + + /** + * Attempts to determine whether a class with the given FQCN is on the classpath. + * + *

The {@link VisitorState}'s symbol table is consulted first. If the type has not yet been + * loaded, then an attempt is made to do so. + */ + private static boolean isKnownClass(String className, VisitorState state) { + return state.getTypeFromString(className) != null || canLoadClass(className, state); + } + + private static boolean canLoadClass(String className, VisitorState state) { + ClassFinder classFinder = ClassFinder.instance(state.context); + Name binaryName = state.binaryNameFromClassname(className); + try { + classFinder.loadClass(state.getSymtab().unnamedModule, binaryName); + return true; + } catch (CompletionFailure e) { + return false; + } + } + + private static boolean shouldIgnoreClasspath(VisitorState state) { + return state + .errorProneOptions() + .getFlags() + .getBoolean(IGNORE_CLASSPATH_COMPAT_FLAG) + .orElse(Boolean.FALSE); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CollectorMutabilityTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CollectorMutabilityTest.java index 48509379e5..1b837e61b5 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CollectorMutabilityTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CollectorMutabilityTest.java @@ -65,6 +65,23 @@ void identification() { .doTest(); } + @Test + void identificationWithoutGuavaOnClasspath() { + compilationTestHelper + .withClasspath() + .addSourceLines( + "A.java", + "import java.util.stream.Collectors;", + "import java.util.stream.Stream;", + "", + "class A {", + " void m() {", + " Stream.empty().collect(Collectors.toList());", + " }", + "}") + .doTest(); + } + @Test void replacementFirstSuggestedFix() { refactoringTestHelper diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTraceTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTraceTest.java index 4753f141b7..95478fe712 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTraceTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTraceTest.java @@ -4,6 +4,7 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.CompilationTestHelper; import org.junit.jupiter.api.Test; +import org.springframework.scheduling.annotation.Scheduled; final class ScheduledTransactionTraceTest { private final CompilationTestHelper compilationTestHelper = @@ -43,6 +44,21 @@ void identification() { .doTest(); } + @Test + void identificationWithoutNewRelicAgentApiOnClasspath() { + compilationTestHelper + .withClasspath(Scheduled.class) + .addSourceLines( + "A.java", + "import org.springframework.scheduling.annotation.Scheduled;", + "", + "class A {", + " @Scheduled(fixedDelay = 1)", + " void scheduledButNotTraced() {}", + "}") + .doTest(); + } + @Test void replacement() { refactoringTestHelper diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibraryTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibraryTest.java new file mode 100644 index 0000000000..8d88885128 --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibraryTest.java @@ -0,0 +1,115 @@ +package tech.picnic.errorprone.bugpatterns.util; + +import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; +import static java.util.stream.Collectors.joining; + +import com.google.common.collect.ImmutableList; +import com.google.errorprone.BugPattern; +import com.google.errorprone.CompilationTestHelper; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher; +import com.google.errorprone.matchers.Description; +import com.sun.source.tree.ClassTree; +import java.util.Arrays; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import reactor.core.publisher.Flux; + +final class ThirdPartyLibraryTest { + private final CompilationTestHelper compilationTestHelper = + CompilationTestHelper.newInstance(TestChecker.class, getClass()); + + @Test + void isIntroductionAllowed() { + compilationTestHelper + .addSourceLines( + "A.java", + "// BUG: Diagnostic contains: ASSERTJ: true, GUAVA: true, NEW_RELIC_AGENT_API: true, REACTOR: true", + "class A {}") + .doTest(); + } + + @Test + void isIntroductionAllowedWitnessClassesInSymtab() { + compilationTestHelper + .addSourceLines( + "A.java", + "import com.google.common.collect.ImmutableList;", + "import com.newrelic.api.agent.Agent;", + "import org.assertj.core.api.Assertions;", + "import reactor.core.publisher.Flux;", + "", + "// BUG: Diagnostic contains: ASSERTJ: true, GUAVA: true, NEW_RELIC_AGENT_API: true, REACTOR: true", + "class A {", + " void m(Class clazz) {", + " m(Assertions.class);", + " m(ImmutableList.class);", + " m(Agent.class);", + " m(Flux.class);", + " }", + "}") + .doTest(); + } + + @Test + void isIntroductionAllowedWitnessClassesPartiallyOnClassPath() { + compilationTestHelper + .withClasspath(ImmutableList.class, Flux.class) + .addSourceLines( + "A.java", + "// BUG: Diagnostic contains: ASSERTJ: false, GUAVA: true, NEW_RELIC_AGENT_API: false, REACTOR: true", + "class A {}") + .doTest(); + } + + @Test + void isIntroductionAllowedWitnessClassesNotOnClassPath() { + compilationTestHelper + .withClasspath() + .addSourceLines( + "A.java", + "// BUG: Diagnostic contains: ASSERTJ: false, GUAVA: false, NEW_RELIC_AGENT_API: false, REACTOR:", + "// false", + "class A {}") + .doTest(); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void isIntroductionAllowedIgnoreClasspathCompat(boolean ignoreClassPath) { + compilationTestHelper + .setArgs("-XepOpt:ErrorProneSupport:IgnoreClasspathCompat=" + ignoreClassPath) + .withClasspath(ImmutableList.class, Flux.class) + .addSourceLines( + "A.java", + String.format( + "// BUG: Diagnostic contains: ASSERTJ: %s, GUAVA: true, NEW_RELIC_AGENT_API: %s, REACTOR: true", + ignoreClassPath, ignoreClassPath), + "class A {}") + .doTest(); + } + + /** + * Flags classes with a diagnostics message that indicates, for each {@link ThirdPartyLibrary} + * element, whether they can be used. + */ + @BugPattern(severity = ERROR, summary = "Interacts with `ThirdPartyLibrary` for testing purposes") + public static final class TestChecker extends BugChecker implements ClassTreeMatcher { + private static final long serialVersionUID = 1L; + + @Override + public Description matchClass(ClassTree tree, VisitorState state) { + return buildDescription(tree) + .setMessage( + Arrays.stream(ThirdPartyLibrary.values()) + .map( + lib -> + String.join( + ": ", lib.name(), String.valueOf(lib.isIntroductionAllowed(state)))) + .collect(joining(", "))) + .build(); + } + } +} From 16955a9cfaa523d4eb843564fd9951f7c34ab129 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 30 Oct 2022 16:34:31 +0100 Subject: [PATCH 044/601] Upgrade NullAway 0.10.2 -> 0.10.3 (#324) See: - https://github.com/uber/NullAway/blob/master/CHANGELOG.md - https://github.com/uber/NullAway/compare/v0.10.2...v0.10.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 29b86845fa..7f0dc2896c 100644 --- a/pom.xml +++ b/pom.xml @@ -156,7 +156,7 @@ 3.8.6 4.8.1 1.0.1 - 0.10.2 + 0.10.3 From 0f05d15dd2365f38d498aa18a160fb20e236fd55 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Fri, 18 Nov 2022 14:16:20 +0100 Subject: [PATCH 072/601] Have Renovate file `ruby/setup-ruby` upgrade PRs at most once a month (#357) --- .renovaterc.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.renovaterc.json b/.renovaterc.json index f3a8083474..1215190705 100644 --- a/.renovaterc.json +++ b/.renovaterc.json @@ -10,7 +10,8 @@ }, { "matchPackagePatterns": [ - "^com\\.palantir\\.baseline:baseline-error-prone$" + "^com\\.palantir\\.baseline:baseline-error-prone$", + "^ruby\/setup-ruby$" ], "schedule": "* * 1 * *" } From 3967542edf0dc3406d1328465fe603ea32a20485 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 19 Nov 2022 10:30:34 +0100 Subject: [PATCH 073/601] Upgrade Spring 5.3.23 -> 5.3.24 (#355) See: - https://github.com/spring-projects/spring-framework/releases/tag/v5.3.24 - https://github.com/spring-projects/spring-framework/compare/v5.3.23...v5.3.24 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index af35df3c76..b46559a68b 100644 --- a/pom.xml +++ b/pom.xml @@ -404,7 +404,7 @@ org.springframework spring-framework-bom - 5.3.23 + 5.3.24 pom import From 79b0123f4133a3d3fb8b478e9d8ea9b0da49b483 Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Sat, 19 Nov 2022 11:56:44 +0100 Subject: [PATCH 074/601] Extend `MonoFlux` Refaster rule (#358) --- .../tech/picnic/errorprone/refasterrules/ReactorRules.java | 3 ++- .../errorprone/refasterrules/ReactorRulesTestInput.java | 7 +++++-- .../errorprone/refasterrules/ReactorRulesTestOutput.java | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 382f1b1cde..c7715d6e3f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -559,7 +559,8 @@ Flux after(Flux flux) { static final class MonoFlux { @BeforeTemplate Flux before(Mono mono) { - return Flux.concat(mono); + return Refaster.anyOf( + mono.flatMapMany(Mono::just), mono.flatMapMany(Flux::just), Flux.concat(mono)); } @AfterTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index b56708a238..f8218770f7 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -178,8 +178,11 @@ ImmutableSet> testFluxMapNotNull() { Flux.just(1).switchMap(n -> Mono.fromSupplier(() -> n * 2))); } - Flux testMonoFlux() { - return Flux.concat(Mono.just("foo")); + ImmutableSet> testMonoFlux() { + return ImmutableSet.of( + Mono.just("foo").flatMapMany(Mono::just), + Mono.just("bar").flatMapMany(Flux::just), + Flux.concat(Mono.just("baz"))); } ImmutableSet>> testMonoCollectToOptional() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index 03a6788e54..7b91b7701f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -180,8 +180,9 @@ ImmutableSet> testFluxMapNotNull() { Flux.just(1).mapNotNull(n -> n * 2)); } - Flux testMonoFlux() { - return Mono.just("foo").flux(); + ImmutableSet> testMonoFlux() { + return ImmutableSet.of( + Mono.just("foo").flux(), Mono.just("bar").flux(), Mono.just("baz").flux()); } ImmutableSet>> testMonoCollectToOptional() { From 919a7c7ebef32904996246db54e5f3d6f07a138b Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 19 Nov 2022 13:16:30 +0100 Subject: [PATCH 075/601] Upgrade AutoValue 1.10 -> 1.10.1 (#361) See: - https://github.com/google/auto/releases/tag/auto-value-1.10.1 - https://github.com/google/auto/compare/auto-value-1.10...auto-value-1.10.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b46559a68b..1face219ff 100644 --- a/pom.xml +++ b/pom.xml @@ -146,7 +146,7 @@ one place. We use these to keep dependencies in sync. Version numbers that need to be referenced only once should *not* be listed here. --> 1.0.1 - 1.10 + 1.10.1 ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 2.16 From 1b6356a8762ae19da6841eb360c33ea8dcd2b1b8 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 19 Nov 2022 13:31:29 +0100 Subject: [PATCH 076/601] Upgrade NullAway 0.10.4 -> 0.10.5 (#359) See: - https://github.com/uber/NullAway/blob/master/CHANGELOG.md - https://github.com/uber/NullAway/compare/v0.10.4...v0.10.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1face219ff..1d641d50e6 100644 --- a/pom.xml +++ b/pom.xml @@ -156,7 +156,7 @@ 3.8.6 4.9.0 1.0.1 - 0.10.4 + 0.10.5 - 0.6.0 - 4.145.0 2.22.2 @@ -281,20 +272,6 @@ - - com.palantir.assertj-automation - assertj-error-prone - ${version.palantir-assertj-automation} - - - - com.palantir.baseline - baseline-error-prone - ${version.palantir-baseline} - - com.uber.nullaway nullaway @@ -844,20 +821,6 @@ nopen-checker ${version.nopen-checker} - com.uber.nullaway nullaway From 16c8bb0b27b0979df416e615ada3f3bd3188ae01 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 24 Nov 2022 08:37:02 +0100 Subject: [PATCH 084/601] Upgrade actions/configure-pages v2.1.2 -> v2.1.3 (#316) See: - https://github.com/actions/configure-pages/releases/tag/v2.1.3 - https://github.com/actions/configure-pages/compare/v2.1.2...v2.1.3 --- .github/workflows/deploy-website.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index 7ab44cea79..dfe87df1d4 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -18,7 +18,7 @@ jobs: working-directory: ./website bundler-cache: true - name: Configure Github Pages - uses: actions/configure-pages@v2.1.2 + uses: actions/configure-pages@v2.1.3 - name: Generate documentation run: ./generate-docs.sh - name: Build website with Jekyll From 7cc8abc3deccd76f26c0fd5aa4094138a404ead7 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 28 Nov 2022 09:04:31 +0100 Subject: [PATCH 085/601] Upgrade Checkstyle 10.4 -> 10.5.0 (#375) See: - https://checkstyle.sourceforge.io/releasenotes.html - https://github.com/checkstyle/checkstyle/releases/tag/checkstyle-10.5.0 - https://github.com/checkstyle/checkstyle/compare/checkstyle-10.4...checkstyle-10.5.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ff1bd3216e..b765b90543 100644 --- a/pom.xml +++ b/pom.xml @@ -760,7 +760,7 @@ com.puppycrawl.tools checkstyle - 10.4 + 10.5.0 io.spring.nohttp From 415ae35906f976119c4a5ca3c91a7ec649bff620 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 28 Nov 2022 12:46:35 +0100 Subject: [PATCH 086/601] Upgrade SLF4J API 2.0.4 -> 2.0.5 (#371) See: - https://www.slf4j.org/news.html - https://github.com/qos-ch/slf4j/compare/v_2.0.4...v_2.0.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b765b90543..80c22924d6 100644 --- a/pom.xml +++ b/pom.xml @@ -376,7 +376,7 @@ org.slf4j slf4j-api - 2.0.4 + 2.0.5 org.springframework From fa1bb8aa94b5c6f53f6e4f971bf150cd82cbfdc4 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 28 Nov 2022 13:01:20 +0100 Subject: [PATCH 087/601] Upgrade Spring Boot 2.7.5 -> 2.7.6 (#372) See: - https://github.com/spring-projects/spring-boot/releases/tag/v2.7.6 - https://github.com/spring-projects/spring-boot/compare/v2.7.5...v2.7.6 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 80c22924d6..0edb68f1b6 100644 --- a/pom.xml +++ b/pom.xml @@ -388,7 +388,7 @@ org.springframework.boot spring-boot-test - 2.7.5 + 2.7.6 org.testng From 6d15cfe7ffe0b39b65ce186e35261d7b35e14aea Mon Sep 17 00:00:00 2001 From: Christos Giallouros Date: Mon, 28 Nov 2022 13:15:25 +0100 Subject: [PATCH 088/601] Introduce `{Mono,Flux}DefaultIfEmpty` Refaster rules (#370) Resolves #363. --- .../refasterrules/ReactorRules.java | 30 +++++++++++++++++-- .../refasterrules/ReactorRulesTestInput.java | 16 +++++++--- .../refasterrules/ReactorRulesTestOutput.java | 15 +++++++--- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index c7715d6e3f..2d9cd67bf9 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -264,6 +264,32 @@ Flux after(Flux flux, long n) { } } + /** Prefer {@link Mono#defaultIfEmpty(Object)} over more contrived alternatives. */ + static final class MonoDefaultIfEmpty { + @BeforeTemplate + Mono before(Mono mono, T object) { + return mono.switchIfEmpty(Mono.just(object)); + } + + @AfterTemplate + Mono after(Mono mono, T object) { + return mono.defaultIfEmpty(object); + } + } + + /** Prefer {@link Flux#defaultIfEmpty(Object)} over more contrived alternatives. */ + static final class FluxDefaultIfEmpty { + @BeforeTemplate + Flux before(Flux flux, T object) { + return flux.switchIfEmpty(Refaster.anyOf(Mono.just(object), Flux.just(object))); + } + + @AfterTemplate + Flux after(Flux flux, T object) { + return flux.defaultIfEmpty(object); + } + } + /** Don't unnecessarily pass an empty publisher to {@link Mono#switchIfEmpty(Mono)}. */ static final class MonoSwitchIfEmptyOfEmptyPublisher { @BeforeTemplate @@ -577,9 +603,7 @@ Flux after(Mono mono) { static final class MonoCollectToOptional { @BeforeTemplate Mono> before(Mono mono) { - return Refaster.anyOf( - mono.map(Optional::of).defaultIfEmpty(Optional.empty()), - mono.map(Optional::of).switchIfEmpty(Mono.just(Optional.empty()))); + return mono.map(Optional::of).defaultIfEmpty(Optional.empty()); } @AfterTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index f8218770f7..61b258003b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -83,6 +83,16 @@ Flux testFluxTake() { return Flux.just(1, 2, 3).take(1); } + Mono testMonoDefaultIfEmpty() { + return Mono.just("foo").switchIfEmpty(Mono.just("bar")); + } + + ImmutableSet> testFluxDefaultIfEmpty() { + return ImmutableSet.of( + Flux.just("foo").switchIfEmpty(Mono.just("bar")), + Flux.just("baz").switchIfEmpty(Flux.just("qux"))); + } + Mono testMonoSwitchIfEmptyOfEmptyPublisher() { return Mono.just(1).switchIfEmpty(Mono.empty()); } @@ -185,10 +195,8 @@ ImmutableSet> testMonoFlux() { Flux.concat(Mono.just("baz"))); } - ImmutableSet>> testMonoCollectToOptional() { - return ImmutableSet.of( - Mono.just("foo").map(Optional::of).defaultIfEmpty(Optional.empty()), - Mono.just("bar").map(Optional::of).switchIfEmpty(Mono.just(Optional.empty()))); + Mono> testMonoCollectToOptional() { + return Mono.just("foo").map(Optional::of).defaultIfEmpty(Optional.empty()); } Mono testMonoCast() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index 7b91b7701f..55092ba2d5 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -90,6 +90,15 @@ Flux testFluxTake() { return Flux.just(1, 2, 3).take(1, true); } + Mono testMonoDefaultIfEmpty() { + return Mono.just("foo").defaultIfEmpty("bar"); + } + + ImmutableSet> testFluxDefaultIfEmpty() { + return ImmutableSet.of( + Flux.just("foo").defaultIfEmpty("bar"), Flux.just("baz").defaultIfEmpty("qux")); + } + Mono testMonoSwitchIfEmptyOfEmptyPublisher() { return Mono.just(1); } @@ -185,10 +194,8 @@ ImmutableSet> testMonoFlux() { Mono.just("foo").flux(), Mono.just("bar").flux(), Mono.just("baz").flux()); } - ImmutableSet>> testMonoCollectToOptional() { - return ImmutableSet.of( - Mono.just("foo").flux().collect(toOptional()), - Mono.just("bar").flux().collect(toOptional())); + Mono> testMonoCollectToOptional() { + return Mono.just("foo").flux().collect(toOptional()); } Mono testMonoCast() { From f46859ae3a7634d489d3f5dd937efcf5cfc233b9 Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Mon, 28 Nov 2022 16:24:55 +0100 Subject: [PATCH 089/601] Introduce some Refaster rules that avoid nested `Publisher`s (#374) --- .../refasterrules/ReactorRules.java | 35 +++++++++++++++++-- .../refasterrules/ReactorRulesTestInput.java | 17 +++++++-- .../refasterrules/ReactorRulesTestOutput.java | 17 +++++++-- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 2d9cd67bf9..d3695bec7f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -320,7 +320,10 @@ Flux after(Flux flux) { static final class FluxConcatMap { @BeforeTemplate Flux before(Flux flux, Function> function) { - return Refaster.anyOf(flux.flatMap(function, 1), flux.flatMapSequential(function, 1)); + return Refaster.anyOf( + flux.flatMap(function, 1), + flux.flatMapSequential(function, 1), + flux.map(function).concatMap(identity())); } @AfterTemplate @@ -337,7 +340,9 @@ Flux before( Function> function, int prefetch) { return Refaster.anyOf( - flux.flatMap(function, 1, prefetch), flux.flatMapSequential(function, 1, prefetch)); + flux.flatMap(function, 1, prefetch), + flux.flatMapSequential(function, 1, prefetch), + flux.map(function).concatMap(identity(), prefetch)); } @AfterTemplate @@ -639,6 +644,32 @@ Flux after(Flux flux) { } } + /** Prefer {@link Mono#flatMap(Function)} over more contrived alternatives. */ + static final class MonoFlatMap { + @BeforeTemplate + Mono before(Mono mono, Function> function) { + return mono.map(function).flatMap(identity()); + } + + @AfterTemplate + Mono after(Mono mono, Function> function) { + return mono.flatMap(function); + } + } + + /** Prefer {@link Mono#flatMapMany(Function)} over more contrived alternatives. */ + static final class MonoFlatMapMany { + @BeforeTemplate + Flux before(Mono mono, Function> function) { + return mono.map(function).flatMapMany(identity()); + } + + @AfterTemplate + Flux after(Mono mono, Function> function) { + return mono.flatMapMany(function); + } + } + /** * Prefer {@link Flux#concatMapIterable(Function)} over alternatives that require an additional * subscription. diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 61b258003b..daf40d369f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -1,5 +1,6 @@ package tech.picnic.errorprone.refasterrules; +import static java.util.function.Function.identity; import static org.assertj.core.api.Assertions.assertThat; import com.google.common.collect.ImmutableList; @@ -104,12 +105,16 @@ ImmutableSet> testFluxSwitchIfEmptyOfEmptyPublisher() { ImmutableSet> testFluxConcatMap() { return ImmutableSet.of( - Flux.just(1).flatMap(Mono::just, 1), Flux.just(2).flatMapSequential(Mono::just, 1)); + Flux.just(1).flatMap(Mono::just, 1), + Flux.just(2).flatMapSequential(Mono::just, 1), + Flux.just(3).map(Mono::just).concatMap(identity())); } ImmutableSet> testFluxConcatMapWithPrefetch() { return ImmutableSet.of( - Flux.just(1).flatMap(Mono::just, 1, 3), Flux.just(2).flatMapSequential(Mono::just, 1, 4)); + Flux.just(1).flatMap(Mono::just, 1, 3), + Flux.just(2).flatMapSequential(Mono::just, 1, 4), + Flux.just(3).map(Mono::just).concatMap(identity(), 5)); } Flux testFluxConcatMapIterable() { @@ -207,6 +212,14 @@ Flux testFluxCast() { return Flux.just(1).map(Number.class::cast); } + Mono testMonoFlatMap() { + return Mono.just("foo").map(Mono::just).flatMap(identity()); + } + + Flux testMonoFlatMapMany() { + return Mono.just("foo").map(Mono::just).flatMapMany(identity()); + } + ImmutableSet> testConcatMapIterableIdentity() { return ImmutableSet.of( Flux.just(ImmutableList.of("foo")).concatMap(list -> Flux.fromIterable(list)), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index 55092ba2d5..df6fb70af4 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -108,12 +108,17 @@ ImmutableSet> testFluxSwitchIfEmptyOfEmptyPublisher() { } ImmutableSet> testFluxConcatMap() { - return ImmutableSet.of(Flux.just(1).concatMap(Mono::just), Flux.just(2).concatMap(Mono::just)); + return ImmutableSet.of( + Flux.just(1).concatMap(Mono::just), + Flux.just(2).concatMap(Mono::just), + Flux.just(3).concatMap(Mono::just)); } ImmutableSet> testFluxConcatMapWithPrefetch() { return ImmutableSet.of( - Flux.just(1).concatMap(Mono::just, 3), Flux.just(2).concatMap(Mono::just, 4)); + Flux.just(1).concatMap(Mono::just, 3), + Flux.just(2).concatMap(Mono::just, 4), + Flux.just(3).concatMap(Mono::just, 5)); } Flux testFluxConcatMapIterable() { @@ -206,6 +211,14 @@ Flux testFluxCast() { return Flux.just(1).cast(Number.class); } + Mono testMonoFlatMap() { + return Mono.just("foo").flatMap(Mono::just); + } + + Flux testMonoFlatMapMany() { + return Mono.just("foo").flatMapMany(Mono::just); + } + ImmutableSet> testConcatMapIterableIdentity() { return ImmutableSet.of( Flux.just(ImmutableList.of("foo")).concatMapIterable(identity()), From 330328329f6eee9754515c13eee8ef97e969c9ad Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 30 Nov 2022 09:14:58 +0100 Subject: [PATCH 090/601] Report mutation test coverage of proposed changes (#346) Thanks to a free Arcmutate OSS license, GitHub Actions now runs Pitest against files changed in the context of a PR. While there, update Pitest's configuration to ignore Refaster rule collection classes, as mutations of those classes will not impact the associated unit tests. See: - https://www.arcmutate.com - https://pitest.org --- .github/workflows/pitest-analyze-pr.yml | 37 +++++++++++++++++++++++++ .github/workflows/pitest-update-pr.yml | 35 +++++++++++++++++++++++ README.md | 2 +- cdg-pitest-licence.txt | 7 +++++ pom.xml | 20 +++++++++++++ 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/pitest-analyze-pr.yml create mode 100644 .github/workflows/pitest-update-pr.yml create mode 100644 cdg-pitest-licence.txt diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml new file mode 100644 index 0000000000..8d1bf61330 --- /dev/null +++ b/.github/workflows/pitest-analyze-pr.yml @@ -0,0 +1,37 @@ +# Performs mutation testing analysis on the files changed by a pull request and +# uploads the results. The associated PR is subsequently updated by the +# `pitest-update-pr.yml` workflow. See https://blog.pitest.org/oss-pitest-pr/ +# for details. +name: "Mutation testing" +on: + pull_request: +permissions: + contents: read +jobs: + analyze-pr: + runs-on: ubuntu-22.04 + steps: + - name: Check out code + uses: actions/checkout@v3.1.0 + with: + fetch-depth: 2 + - name: Set up JDK + uses: actions/setup-java@v3.6.0 + with: + java-version: 17.0.4 + distribution: temurin + cache: maven + - name: Run Pitest + # By running with features `+GIT(from[HEAD~1]), +gitci`, Pitest only + # analyzes lines changed in the associated pull request, as GitHub + # exposes the changes unique to the PR as a single commit on top of the + # target branch. See https://blog.pitest.org/pitest-pr-setup for + # details. + run: mvn test pitest:mutationCoverage -DargLine.xmx=2048m -Dverification.skip -Dfeatures="+GIT(from[HEAD~1]), +gitci" + - name: Aggregate Pitest reports + run: mvn pitest-git:aggregate -DkilledEmoji=":tada:" -DmutantEmoji=":zombie:" -DtrailingText="Mutation testing report by [Pitest](https://pitest.org/). Review any surviving mutants by inspecting the line comments under [_Files changed_](${{ github.event.number }}/files)." + - name: Upload Pitest reports as artifact + uses: actions/upload-artifact@v3.1.1 + with: + name: pitest-reports + path: ./target/pit-reports-ci diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml new file mode 100644 index 0000000000..2acaf65398 --- /dev/null +++ b/.github/workflows/pitest-update-pr.yml @@ -0,0 +1,35 @@ +# Updates a pull request based on the corresponding mutation testing analysis +# performed by the `pitest-analyze-pr.yml` workflow. See +# https://blog.pitest.org/oss-pitest-pr/ for details. +name: "Mutation testing: post results" +on: + workflow_run: + workflows: ["Mutation testing"] + types: + - completed +permissions: + actions: read + checks: write + contents: read + pull-requests: write +jobs: + update-pr: + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-22.04 + steps: + - name: Check out code + uses: actions/checkout@v3.1.0 + - name: Set up JDK + uses: actions/setup-java@v3.6.0 + with: + java-version: 17.0.4 + distribution: temurin + cache: maven + - name: Download Pitest analysis artifact + uses: dawidd6/action-download-artifact@v2.24.2 + with: + workflow: ${{ github.event.workflow_run.workflow_id }} + name: pitest-reports + path: ./target/pit-reports-ci + - name: Update PR + run: mvn -DrepoToken="${{ secrets.GITHUB_TOKEN }}" pitest-github:updatePR diff --git a/README.md b/README.md index 090ba532dd..8008995960 100644 --- a/README.md +++ b/README.md @@ -166,7 +166,7 @@ Some other commands one may find relevant: - `mvn fmt:format` formats the code using [`google-java-format`][google-java-format]. -- `./run-mutation-tests.sh` runs mutation tests using [PIT][pitest]. The +- `./run-mutation-tests.sh` runs mutation tests using [Pitest][pitest]. The results can be reviewed by opening the respective `target/pit-reports/index.html` files. For more information check the [PIT Maven plugin][pitest-maven]. diff --git a/cdg-pitest-licence.txt b/cdg-pitest-licence.txt new file mode 100644 index 0000000000..1c803d4f49 --- /dev/null +++ b/cdg-pitest-licence.txt @@ -0,0 +1,7 @@ +# Arcmutate license for Error Prone Support, requested by sending an email to +# support@arcmutate.com. +expires=07/11/2023 +keyVersion=1 +signature=MhZxMbnO6UovNfllM0JuVWkZyvRT3/G5o/uT0Mm36c7200VpZNVu03gTAGivnl9W5RzvZhfpIHccuQ5ctjQkrqhsFSrl4fyqPqu3y5V2fsHIdFXP/G72EGj6Kay9ndLpaEHalqE0bEwxdnHMzEYq5y3O9vUPv8MhUl57xk+rvBo\= +packages=tech.picnic.errorprone.* +type=OSSS diff --git a/pom.xml b/pom.xml index 0edb68f1b6..fae22c204e 100644 --- a/pom.xml +++ b/pom.xml @@ -157,6 +157,7 @@ 4.9.0 1.0.1 0.10.5 + 1.0.1 2.22.2 @@ -428,6 +429,16 @@ + + com.groupcdg + pitest-git-maven-plugin + ${version.pitest-git} + + + com.groupcdg + pitest-github-maven-plugin + ${version.pitest-git} + com.spotify.fmt fmt-maven-plugin @@ -1231,8 +1242,12 @@ 1.9.11 + *.AutoValue_* + + *.refaster*.*Rules* + false @@ -1241,6 +1256,11 @@ false + + com.groupcdg + pitest-git-plugin + ${version.pitest-git} + org.pitest pitest-junit5-plugin From 96ab66cdcf2c688e9bb3abdc580d3ca87257af56 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 30 Nov 2022 16:44:09 +0100 Subject: [PATCH 091/601] Upgrade maven-dependency-plugin 3.3.0 -> 3.4.0 (#377) See: - https://issues.apache.org/jira/issues/?jql=project%20%3D%20MDEP%20AND%20fixVersion%20%3E%203.3.0%20AND%20fixVersion%20%3C%3D%203.4.0%20AND%20statusCategory%20%3D%20Done%20 - https://github.com/apache/maven-dependency-plugin/compare/maven-dependency-plugin-3.3.0...maven-dependency-plugin-3.4.0 --- pom.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index fae22c204e..0ecbe92c79 100644 --- a/pom.xml +++ b/pom.xml @@ -870,16 +870,16 @@ org.apache.maven.plugins maven-dependency-plugin - 3.3.0 + 3.4.0 + + true false true - - - * - From 8e3beb9d5c33ee0d6f531664f559c2ab501e2910 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 1 Dec 2022 09:01:08 +0100 Subject: [PATCH 092/601] Upgrade ruby/setup-ruby v1.123.0 -> v1.126.0 (#379) See: - https://github.com/ruby/setup-ruby/releases/tag/v1.124.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.125.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.126.0 - https://github.com/ruby/setup-ruby/compare/v1.123.0...v1.126.0 --- .github/workflows/deploy-website.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index dfe87df1d4..2f2e7ad54a 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -13,7 +13,7 @@ jobs: steps: - name: Check out code uses: actions/checkout@v3.1.0 - - uses: ruby/setup-ruby@v1.123.0 + - uses: ruby/setup-ruby@v1.126.0 with: working-directory: ./website bundler-cache: true From 5afa7e1878453f97996ed73c36847844e07074cb Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 2 Dec 2022 09:49:13 +0100 Subject: [PATCH 093/601] Upgrade actions/setup-java v3.6.0 -> v3.7.0 (#381) See: - https://github.com/actions/setup-java/releases/tag/v3.7.0 - https://github.com/actions/setup-java/compare/v3.6.0...v3.7.0 --- .github/workflows/build.yaml | 2 +- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/pitest-update-pr.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4979e59dc0..8018d049ef 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -37,7 +37,7 @@ jobs: - name: Check out code uses: actions/checkout@v3.1.0 - name: Set up JDK - uses: actions/setup-java@v3.6.0 + uses: actions/setup-java@v3.7.0 with: java-version: ${{ matrix.jdk }} distribution: ${{ matrix.distribution }} diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index 8d1bf61330..c1ffe16c91 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -16,7 +16,7 @@ jobs: with: fetch-depth: 2 - name: Set up JDK - uses: actions/setup-java@v3.6.0 + uses: actions/setup-java@v3.7.0 with: java-version: 17.0.4 distribution: temurin diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index 2acaf65398..753f6bea98 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -20,7 +20,7 @@ jobs: - name: Check out code uses: actions/checkout@v3.1.0 - name: Set up JDK - uses: actions/setup-java@v3.6.0 + uses: actions/setup-java@v3.7.0 with: java-version: 17.0.4 distribution: temurin From 8803d23a8e1fccd9678961b3dbdad09835c9b919 Mon Sep 17 00:00:00 2001 From: Gijs de Jong <14833076+oxkitsune@users.noreply.github.com> Date: Sun, 4 Dec 2022 16:49:01 +0100 Subject: [PATCH 094/601] Introduce `JUnitClassModifiers` check (#214) --- .../bugpatterns/JUnitClassModifiers.java | 82 +++++++++++ .../bugpatterns/JUnitClassModifiersTest.java | 134 ++++++++++++++++++ 2 files changed, 216 insertions(+) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiers.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiersTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiers.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiers.java new file mode 100644 index 0000000000..866b712572 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiers.java @@ -0,0 +1,82 @@ +package tech.picnic.errorprone.bugpatterns; + +import static com.google.errorprone.BugPattern.LinkType.CUSTOM; +import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; +import static com.google.errorprone.BugPattern.StandardTags.STYLE; +import static com.google.errorprone.matchers.ChildMultiMatcher.MatchType.AT_LEAST_ONE; +import static com.google.errorprone.matchers.Matchers.allOf; +import static com.google.errorprone.matchers.Matchers.annotations; +import static com.google.errorprone.matchers.Matchers.anyOf; +import static com.google.errorprone.matchers.Matchers.hasMethod; +import static com.google.errorprone.matchers.Matchers.hasModifier; +import static com.google.errorprone.matchers.Matchers.isType; +import static com.google.errorprone.matchers.Matchers.not; +import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; +import static tech.picnic.errorprone.bugpatterns.util.MoreJUnitMatchers.TEST_METHOD; +import static tech.picnic.errorprone.bugpatterns.util.MoreMatchers.hasMetaAnnotation; + +import com.google.auto.service.AutoService; +import com.google.common.collect.ImmutableSet; +import com.google.errorprone.BugPattern; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher; +import com.google.errorprone.fixes.SuggestedFix; +import com.google.errorprone.fixes.SuggestedFixes; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.matchers.Matcher; +import com.sun.source.tree.ClassTree; +import javax.lang.model.element.Modifier; + +/** + * A {@link BugChecker} that flags non-final and non package-private JUnit test class declarations, + * unless abstract. + */ +@AutoService(BugChecker.class) +@BugPattern( + summary = "Non-abstract JUnit test classes should be declared package-private and final", + linkType = CUSTOM, + link = BUG_PATTERNS_BASE_URL + "JUnitClassModifiers", + severity = SUGGESTION, + tags = STYLE) +public final class JUnitClassModifiers extends BugChecker implements ClassTreeMatcher { + private static final long serialVersionUID = 1L; + private static final Matcher HAS_SPRING_CONFIGURATION_ANNOTATION = + annotations( + AT_LEAST_ONE, + anyOf( + isType("org.springframework.context.annotation.Configuration"), + hasMetaAnnotation("org.springframework.context.annotation.Configuration"))); + private static final Matcher TEST_CLASS_WITH_INCORRECT_MODIFIERS = + allOf( + hasMethod(TEST_METHOD), + not(hasModifier(Modifier.ABSTRACT)), + anyOf( + hasModifier(Modifier.PRIVATE), + hasModifier(Modifier.PROTECTED), + hasModifier(Modifier.PUBLIC), + allOf(not(hasModifier(Modifier.FINAL)), not(HAS_SPRING_CONFIGURATION_ANNOTATION)))); + + /** Instantiates a new {@link JUnitClassModifiers} instance. */ + public JUnitClassModifiers() {} + + @Override + public Description matchClass(ClassTree tree, VisitorState state) { + if (!TEST_CLASS_WITH_INCORRECT_MODIFIERS.matches(tree, state)) { + return Description.NO_MATCH; + } + + SuggestedFix.Builder fixBuilder = SuggestedFix.builder(); + SuggestedFixes.removeModifiers( + tree.getModifiers(), + state, + ImmutableSet.of(Modifier.PRIVATE, Modifier.PROTECTED, Modifier.PUBLIC)) + .ifPresent(fixBuilder::merge); + + if (!HAS_SPRING_CONFIGURATION_ANNOTATION.matches(tree, state)) { + SuggestedFixes.addModifiers(tree, state, Modifier.FINAL).ifPresent(fixBuilder::merge); + } + + return describeMatch(tree, fixBuilder.build()); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiersTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiersTest.java new file mode 100644 index 0000000000..042a4e9d60 --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiersTest.java @@ -0,0 +1,134 @@ +package tech.picnic.errorprone.bugpatterns; + +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; +import com.google.errorprone.CompilationTestHelper; +import org.junit.jupiter.api.Test; + +final class JUnitClassModifiersTest { + private final CompilationTestHelper compilationTestHelper = + CompilationTestHelper.newInstance(JUnitClassModifiers.class, getClass()); + private final BugCheckerRefactoringTestHelper refactoringTestHelper = + BugCheckerRefactoringTestHelper.newInstance(JUnitClassModifiers.class, getClass()); + + @Test + void identification() { + compilationTestHelper + .addSourceLines( + "Container.java", + "import org.junit.jupiter.api.Test;", + "import org.junit.jupiter.params.ParameterizedTest;", + "import org.springframework.boot.test.context.TestConfiguration;", + "import org.springframework.context.annotation.Configuration;", + "", + "class Container {", + " final class FinalAndPackagePrivate {", + " @Test", + " void foo() {}", + " }", + "", + " final class FinalAndPackagePrivateWithCustomTestMethod {", + " @ParameterizedTest", + " void foo() {}", + " }", + "", + " public abstract class Abstract {", + " @Test", + " void foo() {}", + " }", + "", + " @Configuration", + " class WithConfigurationAnnotation {", + " @Test", + " void foo() {}", + " }", + "", + " @TestConfiguration", + " class WithConfigurationMetaAnnotation {", + " @Test", + " void foo() {}", + " }", + "", + " // BUG: Diagnostic contains:", + " private final class Private {", + " @Test", + " void foo() {}", + " }", + "", + " // BUG: Diagnostic contains:", + " protected final class Protected {", + " @Test", + " void foo() {}", + " }", + "", + " // BUG: Diagnostic contains:", + " public final class Public {", + " @Test", + " void foo() {}", + " }", + "", + " // BUG: Diagnostic contains:", + " class NonFinal {", + " @Test", + " void foo() {}", + " }", + "", + " // BUG: Diagnostic contains:", + " class NonFinalWithCustomTestMethod {", + " @ParameterizedTest", + " void foo() {}", + " }", + "", + " @Configuration", + " // BUG: Diagnostic contains:", + " public class PublicWithConfigurationAnnotation {", + " @Test", + " void foo() {}", + " }", + "", + " @TestConfiguration", + " // BUG: Diagnostic contains:", + " protected class ProtectedWithConfigurationMetaAnnotation {", + " @Test", + " void foo() {}", + " }", + "}") + .doTest(); + } + + @Test + void replacement() { + refactoringTestHelper + .addInputLines( + "A.java", + "import org.junit.jupiter.api.Test;", + "import org.springframework.context.annotation.Configuration;", + "", + "public class A {", + " @Test", + " void foo() {}", + "", + " @Configuration", + " private static class B {", + " @Test", + " void bar() {}", + " }", + "}") + .addOutputLines( + "A.java", + "import org.junit.jupiter.api.Test;", + "import org.springframework.context.annotation.Configuration;", + "", + "final class A {", + " @Test", + " void foo() {}", + "", + " @Configuration", + " static class B {", + " @Test", + " void bar() {}", + " }", + "}") + .doTest(TestMode.TEXT_MATCH); + } +} From 0ccebcc9c440276ddd13b74ac84332a4fb834910 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 4 Dec 2022 19:57:42 +0100 Subject: [PATCH 095/601] Upgrade Checker Framework Annotations 3.27.0 -> 3.28.0 (#382) See: - https://github.com/typetools/checker-framework/releases/tag/checker-framework-3.28.0 - https://github.com/typetools/checker-framework/compare/checker-framework-3.27.0...checker-framework-3.28.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0ecbe92c79..4e0d1d1665 100644 --- a/pom.xml +++ b/pom.xml @@ -343,7 +343,7 @@ org.checkerframework checker-qual - 3.27.0 + 3.28.0 org.hamcrest From 789f8c86f20d4d00404f5b641d8a59f8d5f11907 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 5 Dec 2022 09:01:20 +0100 Subject: [PATCH 096/601] Upgrade Pitest Git plugins 1.0.1 -> 1.0.2 (#380) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4e0d1d1665..392fe02065 100644 --- a/pom.xml +++ b/pom.xml @@ -157,7 +157,7 @@ 4.9.0 1.0.1 0.10.5 - 1.0.1 + 1.0.2 2.22.2 From 066591c3791d45fea82496d924c05fe6bf1622f6 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 5 Dec 2022 09:11:51 +0100 Subject: [PATCH 097/601] Improve mutation testing setup (#383) Summary of changes: - Enable Pitest's built-in `STRONGER` mutator group. - Enable Arcmutate's `EXTENDED` mutator group. - Enable Arcmutate's JUnit 5 Accelerator Plugin. - Modify `MoreTypesTest` such that it is impacted by mutations of the `MoreTypes` class. See: - https://pitest.org/quickstart/mutators/ - https://docs.arcmutate.com/docs/extended-operators.html - https://docs.arcmutate.com/docs/accelerator.html --- .../bugpatterns/util/MoreTypesTest.java | 93 ++++++++++--------- pom.xml | 14 +++ 2 files changed, 64 insertions(+), 43 deletions(-) diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreTypesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreTypesTest.java index 48d003fa20..29b6fed550 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreTypesTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreTypesTest.java @@ -25,46 +25,6 @@ import org.junit.jupiter.api.Test; final class MoreTypesTest { - private static final ImmutableSet> TYPES = - ImmutableSet.of( - // Invalid types. - type("java.lang.Nonexistent"), - generic(type("java.util.Integer"), unbound()), - // Valid types. - type("java.lang.String"), - type("java.lang.Number"), - superOf(type("java.lang.Number")), - subOf(type("java.lang.Number")), - type("java.lang.Integer"), - superOf(type("java.lang.Integer")), - subOf(type("java.lang.Integer")), - type("java.util.Optional"), - raw(type("java.util.Optional")), - generic(type("java.util.Optional"), unbound()), - generic(type("java.util.Optional"), type("java.lang.Number")), - type("java.util.Collection"), - raw(type("java.util.Collection")), - generic(type("java.util.Collection"), unbound()), - generic(type("java.util.Collection"), type("java.lang.Number")), - generic(type("java.util.Collection"), superOf(type("java.lang.Number"))), - generic(type("java.util.Collection"), subOf(type("java.lang.Number"))), - generic(type("java.util.Collection"), type("java.lang.Integer")), - generic(type("java.util.Collection"), superOf(type("java.lang.Integer"))), - generic(type("java.util.Collection"), subOf(type("java.lang.Integer"))), - type("java.util.List"), - raw(type("java.util.List")), - generic(type("java.util.List"), unbound()), - generic(type("java.util.List"), type("java.lang.Number")), - generic(type("java.util.List"), superOf(type("java.lang.Number"))), - generic(type("java.util.List"), subOf(type("java.lang.Number"))), - generic(type("java.util.List"), type("java.lang.Integer")), - generic(type("java.util.List"), superOf(type("java.lang.Integer"))), - generic(type("java.util.List"), subOf(type("java.lang.Integer"))), - generic( - type("java.util.Map"), - type("java.lang.String"), - subOf(generic(type("java.util.Collection"), superOf(type("java.lang.Short")))))); - @Test void matcher() { CompilationTestHelper.newInstance(SubtypeFlagger.class, getClass()) @@ -159,8 +119,8 @@ void matcher() { } /** - * A {@link BugChecker} that flags method invocations that are a subtype of any type contained in - * {@link #TYPES}. + * A {@link BugChecker} that flags method invocations that are a subtype of any type defined by + * {@link #getTestTypes()}. */ @BugPattern(summary = "Flags invocations of methods with select return types", severity = ERROR) public static final class SubtypeFlagger extends BugChecker @@ -173,7 +133,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState List matches = new ArrayList<>(); - for (Supplier type : TYPES) { + for (Supplier type : getTestTypes()) { Type testType = type.get(state); if (testType != null && state.getTypes().isSubtype(treeType, testType)) { matches.add(Signatures.prettyType(testType)); @@ -184,5 +144,52 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState ? Description.NO_MATCH : buildDescription(tree).setMessage(matches.toString()).build(); } + + /** + * Returns the type suppliers under test. + * + * @implNote The return value of this method should not be assigned to a field, as that would + * prevent mutations introduced by Pitest from being killed. + */ + private static ImmutableSet> getTestTypes() { + return ImmutableSet.of( + // Invalid types. + type("java.lang.Nonexistent"), + generic(type("java.util.Integer"), unbound()), + // Valid types. + type("java.lang.String"), + type("java.lang.Number"), + superOf(type("java.lang.Number")), + subOf(type("java.lang.Number")), + type("java.lang.Integer"), + superOf(type("java.lang.Integer")), + subOf(type("java.lang.Integer")), + type("java.util.Optional"), + raw(type("java.util.Optional")), + generic(type("java.util.Optional"), unbound()), + generic(type("java.util.Optional"), type("java.lang.Number")), + type("java.util.Collection"), + raw(type("java.util.Collection")), + generic(type("java.util.Collection"), unbound()), + generic(type("java.util.Collection"), type("java.lang.Number")), + generic(type("java.util.Collection"), superOf(type("java.lang.Number"))), + generic(type("java.util.Collection"), subOf(type("java.lang.Number"))), + generic(type("java.util.Collection"), type("java.lang.Integer")), + generic(type("java.util.Collection"), superOf(type("java.lang.Integer"))), + generic(type("java.util.Collection"), subOf(type("java.lang.Integer"))), + type("java.util.List"), + raw(type("java.util.List")), + generic(type("java.util.List"), unbound()), + generic(type("java.util.List"), type("java.lang.Number")), + generic(type("java.util.List"), superOf(type("java.lang.Number"))), + generic(type("java.util.List"), subOf(type("java.lang.Number"))), + generic(type("java.util.List"), type("java.lang.Integer")), + generic(type("java.util.List"), superOf(type("java.lang.Integer"))), + generic(type("java.util.List"), subOf(type("java.lang.Integer"))), + generic( + type("java.util.Map"), + type("java.lang.String"), + subOf(generic(type("java.util.Collection"), superOf(type("java.lang.Short")))))); + } } } diff --git a/pom.xml b/pom.xml index 392fe02065..bfda0bd0d7 100644 --- a/pom.xml +++ b/pom.xml @@ -1248,6 +1248,10 @@ *.refaster*.*Rules* false + + EXTENDED + STRONGER + @@ -1261,6 +1265,16 @@ pitest-git-plugin ${version.pitest-git} + + com.groupcdg.arcmutate + base + 1.0.1 + + + com.groupcdg.pitest + pitest-accelerator-junit5 + 1.0.4 + org.pitest pitest-junit5-plugin From 4f9aba83ec2d877f1f7265fa0c103a21e71fc04d Mon Sep 17 00:00:00 2001 From: Luke Prananta Date: Mon, 5 Dec 2022 13:49:20 +0100 Subject: [PATCH 098/601] Introduce `StringCaseLocaleUsage` check (#376) --- .../bugpatterns/StringCaseLocaleUsage.java | 70 ++++++++++++ .../StringCaseLocaleUsageTest.java | 104 ++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsage.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsage.java new file mode 100644 index 0000000000..11b441229c --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsage.java @@ -0,0 +1,70 @@ +package tech.picnic.errorprone.bugpatterns; + +import static com.google.errorprone.BugPattern.LinkType.CUSTOM; +import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; +import static com.google.errorprone.BugPattern.StandardTags.FRAGILE_CODE; +import static com.google.errorprone.matchers.method.MethodMatchers.instanceMethod; +import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; + +import com.google.auto.service.AutoService; +import com.google.errorprone.BugPattern; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; +import com.google.errorprone.fixes.Fix; +import com.google.errorprone.fixes.SuggestedFix; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.matchers.Matcher; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.MethodInvocationTree; +import tech.picnic.errorprone.bugpatterns.util.SourceCode; + +/** + * A {@link BugChecker} that flags calls to {@link String#toLowerCase()} and {@link + * String#toUpperCase()}, as these methods implicitly rely on the environment's default locale. + */ +// XXX: Also flag `String::toLowerCase` and `String::toUpperCase` method references. For these cases +// the suggested fix should introduce a lambda expression with a parameter of which the name does +// not coincide with the name of an existing variable name. Such functionality should likely be +// introduced in a utility class. +@AutoService(BugChecker.class) +@BugPattern( + summary = "Specify a `Locale` when calling `String#to{Lower,Upper}Case`", + link = BUG_PATTERNS_BASE_URL + "StringCaseLocaleUsage", + linkType = CUSTOM, + severity = WARNING, + tags = FRAGILE_CODE) +public final class StringCaseLocaleUsage extends BugChecker implements MethodInvocationTreeMatcher { + private static final long serialVersionUID = 1L; + private static final Matcher DEFAULT_LOCALE_CASE_CONVERSION = + instanceMethod() + .onExactClass(String.class.getName()) + .namedAnyOf("toLowerCase", "toUpperCase") + .withNoParameters(); + + /** Instantiates a new {@link StringCaseLocaleUsage} instance. */ + public StringCaseLocaleUsage() {} + + @Override + public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { + if (!DEFAULT_LOCALE_CASE_CONVERSION.matches(tree, state)) { + return Description.NO_MATCH; + } + + return buildDescription(tree) + .addFix(suggestLocale(tree, "Locale.ROOT", state)) + .addFix(suggestLocale(tree, "Locale.getDefault()", state)) + .build(); + } + + private static Fix suggestLocale(MethodInvocationTree tree, String locale, VisitorState state) { + // XXX: The logic that replaces the first parenthesis assumes that `tree` does not have a source + // code representation such as `str.toLowerCase/* Some comment with parens (). */()`. In such a + // case the comment, rather than the method invocation arguments, will be modified. Implement a + // generic solution for this. + return SuggestedFix.builder() + .addImport("java.util.Locale") + .replace(tree, SourceCode.treeToString(tree, state).replaceFirst("\\(", '(' + locale)) + .build(); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java new file mode 100644 index 0000000000..f47b0c434c --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java @@ -0,0 +1,104 @@ +package tech.picnic.errorprone.bugpatterns; + +import static com.google.errorprone.BugCheckerRefactoringTestHelper.newInstance; + +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; +import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; +import com.google.errorprone.CompilationTestHelper; +import org.junit.jupiter.api.Test; + +final class StringCaseLocaleUsageTest { + private final CompilationTestHelper compilationTestHelper = + CompilationTestHelper.newInstance(StringCaseLocaleUsage.class, getClass()); + private final BugCheckerRefactoringTestHelper refactoringTestHelper = + newInstance(StringCaseLocaleUsage.class, getClass()); + + @Test + void identification() { + compilationTestHelper + .addSourceLines( + "A.java", + "import static java.util.Locale.ROOT;", + "", + "import java.util.Locale;", + "", + "class A {", + " void m() {", + " \"a\".toLowerCase(Locale.ROOT);", + " \"a\".toUpperCase(Locale.ROOT);", + " \"b\".toLowerCase(ROOT);", + " \"b\".toUpperCase(ROOT);", + " \"c\".toLowerCase(Locale.getDefault());", + " \"c\".toUpperCase(Locale.getDefault());", + " \"d\".toLowerCase(Locale.ENGLISH);", + " \"d\".toUpperCase(Locale.ENGLISH);", + " \"e\".toLowerCase(new Locale(\"foo\"));", + " \"e\".toUpperCase(new Locale(\"foo\"));", + "", + " // BUG: Diagnostic contains:", + " \"f\".toLowerCase();", + " // BUG: Diagnostic contains:", + " \"g\".toUpperCase();", + "", + " String h = \"h\";", + " // BUG: Diagnostic contains:", + " h.toLowerCase();", + " String i = \"i\";", + " // BUG: Diagnostic contains:", + " i.toUpperCase();", + " }", + "}") + .doTest(); + } + + @Test + void replacementFirstSuggestedFix() { + refactoringTestHelper + .setFixChooser(FixChoosers.FIRST) + .addInputLines( + "A.java", + "class A {", + " void m() {", + " \"a\".toLowerCase(/* Comment with parens: (). */ );", + " \"b\".toUpperCase();", + " }", + "}") + .addOutputLines( + "A.java", + "import java.util.Locale;", + "", + "class A {", + " void m() {", + " \"a\".toLowerCase(Locale.ROOT /* Comment with parens: (). */);", + " \"b\".toUpperCase(Locale.ROOT);", + " }", + "}") + .doTest(TestMode.TEXT_MATCH); + } + + @Test + void replacementSecondSuggestedFix() { + refactoringTestHelper + .setFixChooser(FixChoosers.SECOND) + .addInputLines( + "A.java", + "class A {", + " void m() {", + " \"a\".toLowerCase();", + " \"b\".toUpperCase(/* Comment with parens: (). */ );", + " }", + "}") + .addOutputLines( + "A.java", + "import java.util.Locale;", + "", + "class A {", + " void m() {", + " \"a\".toLowerCase(Locale.getDefault());", + " \"b\".toUpperCase(Locale.getDefault() /* Comment with parens: (). */);", + " }", + "}") + .doTest(TestMode.TEXT_MATCH); + } +} From f585306a1f3b86a40144de047a2aa77ee2b098a0 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Tue, 6 Dec 2022 08:06:58 +0100 Subject: [PATCH 099/601] Downgrade actions/setup-java v3.7.0 -> v3.6.0 (#392) This reverts commit 5afa7e1878453f97996ed73c36847844e07074cb. Tag v3.7.0 was deleted; see actions/setup-java#422 for details. --- .github/workflows/build.yaml | 2 +- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/pitest-update-pr.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8018d049ef..4979e59dc0 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -37,7 +37,7 @@ jobs: - name: Check out code uses: actions/checkout@v3.1.0 - name: Set up JDK - uses: actions/setup-java@v3.7.0 + uses: actions/setup-java@v3.6.0 with: java-version: ${{ matrix.jdk }} distribution: ${{ matrix.distribution }} diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index c1ffe16c91..8d1bf61330 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -16,7 +16,7 @@ jobs: with: fetch-depth: 2 - name: Set up JDK - uses: actions/setup-java@v3.7.0 + uses: actions/setup-java@v3.6.0 with: java-version: 17.0.4 distribution: temurin diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index 753f6bea98..2acaf65398 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -20,7 +20,7 @@ jobs: - name: Check out code uses: actions/checkout@v3.1.0 - name: Set up JDK - uses: actions/setup-java@v3.7.0 + uses: actions/setup-java@v3.6.0 with: java-version: 17.0.4 distribution: temurin From 1afce12b5286103c9c5574c2304144500291b520 Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Tue, 6 Dec 2022 08:15:39 +0100 Subject: [PATCH 100/601] Introduce `Mono{Empty,Just,JustOrEmpty}` Refaster rules (#385) --- .../refasterrules/ReactorRules.java | 40 +++++++++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 12 ++++++ .../refasterrules/ReactorRulesTestOutput.java | 12 ++++++ 3 files changed, 64 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index d3695bec7f..06b2d97f40 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -26,6 +26,7 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; +import org.jspecify.nullness.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -59,6 +60,45 @@ Mono after(Supplier supplier) { } } + /** Prefer {@link Mono#empty()} over more contrived alternatives. */ + static final class MonoEmpty { + @BeforeTemplate + Mono before() { + return Refaster.anyOf(Mono.justOrEmpty(null), Mono.justOrEmpty(Optional.empty())); + } + + @AfterTemplate + Mono after() { + return Mono.empty(); + } + } + + /** Prefer {@link Mono#just(Object)} over more contrived alternatives. */ + static final class MonoJust { + @BeforeTemplate + Mono before(T value) { + return Mono.justOrEmpty(Optional.of(value)); + } + + @AfterTemplate + Mono after(T value) { + return Mono.just(value); + } + } + + /** Prefer {@link Mono#justOrEmpty(Object)} over more contrived alternatives. */ + static final class MonoJustOrEmpty<@Nullable T> { + @BeforeTemplate + Mono before(T value) { + return Mono.justOrEmpty(Optional.ofNullable(value)); + } + + @AfterTemplate + Mono after(T value) { + return Mono.justOrEmpty(value); + } + } + /** Prefer {@link Mono#justOrEmpty(Optional)} over more verbose alternatives. */ // XXX: If `optional` is a constant and effectively-final expression then the `Mono.defer` can be // dropped. Should look into Refaster support for identifying this. diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index daf40d369f..ab1abfc97c 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -34,6 +34,18 @@ ImmutableSet> testMonoFromSupplier() { Mono.fromCallable(this::toString)); } + ImmutableSet> testMonoEmpty() { + return ImmutableSet.of(Mono.justOrEmpty(null), Mono.justOrEmpty(Optional.empty())); + } + + Mono testMonoJust() { + return Mono.justOrEmpty(Optional.of(1)); + } + + Mono testMonoJustOrEmpty() { + return Mono.justOrEmpty(Optional.ofNullable(1)); + } + ImmutableSet> testMonoFromOptional() { return ImmutableSet.of( Mono.fromCallable(() -> Optional.of(1).orElse(null)), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index df6fb70af4..33edca43a6 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -37,6 +37,18 @@ ImmutableSet> testMonoFromSupplier() { Mono.fromSupplier(this::toString)); } + ImmutableSet> testMonoEmpty() { + return ImmutableSet.of(Mono.empty(), Mono.empty()); + } + + Mono testMonoJust() { + return Mono.just(1); + } + + Mono testMonoJustOrEmpty() { + return Mono.justOrEmpty(1); + } + ImmutableSet> testMonoFromOptional() { return ImmutableSet.of( Mono.defer(() -> Mono.justOrEmpty(Optional.of(1))), From ee62af4a8639cef97099a05b638b5b96f45cbb46 Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Tue, 6 Dec 2022 08:26:34 +0100 Subject: [PATCH 101/601] Introduce `MonoFromOptionalSwitchIfEmpty` and `OptionalMapMonoJust` Refaster rules (#384) --- .../refasterrules/ReactorRules.java | 34 +++++++++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 8 +++++ .../refasterrules/ReactorRulesTestOutput.java | 8 +++++ 3 files changed, 50 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 06b2d97f40..6b6997a5ed 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -118,6 +118,40 @@ Mono after(Optional optional) { } } + /** + * Try to avoid expressions of type {@code Optional>}, but if you must map an {@link + * Optional} to this type, prefer using {@link Mono#just(Object)}. + */ + static final class OptionalMapMonoJust { + @BeforeTemplate + Optional> before(Optional optional) { + return optional.map(Mono::justOrEmpty); + } + + @AfterTemplate + Optional> after(Optional optional) { + return optional.map(Mono::just); + } + } + + /** + * Prefer a {@link Mono#justOrEmpty(Optional)} and {@link Mono#switchIfEmpty(Mono)} chain over + * more contrived alternatives. + * + *

In particular, avoid mixing of the {@link Optional} and {@link Mono} APIs. + */ + static final class MonoFromOptionalSwitchIfEmpty { + @BeforeTemplate + Mono before(Optional optional, Mono mono) { + return optional.map(Mono::just).orElse(mono); + } + + @AfterTemplate + Mono after(Optional optional, Mono mono) { + return Mono.justOrEmpty(optional).switchIfEmpty(mono); + } + } + /** * Prefer {@link Mono#zip(Mono, Mono)} over a chained {@link Mono#zipWith(Mono)}, as the former * better conveys that the {@link Mono}s may be subscribed to concurrently, and generalizes to diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index ab1abfc97c..e256522c08 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -52,6 +52,14 @@ ImmutableSet> testMonoFromOptional() { Mono.fromSupplier(() -> Optional.of(2).orElse(null))); } + Optional> testOptionalMapMonoJust() { + return Optional.of("foo").map(Mono::justOrEmpty); + } + + Mono testMonoFromOptionalSwitchIfEmpty() { + return Optional.of(1).map(Mono::just).orElse(Mono.just(2)); + } + Mono> testMonoZip() { return Mono.just("foo").zipWith(Mono.just(1)); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index 33edca43a6..3c247811e4 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -55,6 +55,14 @@ ImmutableSet> testMonoFromOptional() { Mono.defer(() -> Mono.justOrEmpty(Optional.of(2)))); } + Optional> testOptionalMapMonoJust() { + return Optional.of("foo").map(Mono::just); + } + + Mono testMonoFromOptionalSwitchIfEmpty() { + return Mono.justOrEmpty(Optional.of(1)).switchIfEmpty(Mono.just(2)); + } + Mono> testMonoZip() { return Mono.zip(Mono.just("foo"), Mono.just(1)); } From 1794d3605320d6f12ecbbeea9df305631e0fb6d1 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 6 Dec 2022 09:04:37 +0100 Subject: [PATCH 102/601] Upgrade Pitest Git plugins 1.0.2 -> 1.0.3 (#391) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bfda0bd0d7..4c7822595b 100644 --- a/pom.xml +++ b/pom.xml @@ -157,7 +157,7 @@ 4.9.0 1.0.1 0.10.5 - 1.0.2 + 1.0.3 2.22.2 From a6f794de3d4799f0fd489a7bd1a86056ed3668a4 Mon Sep 17 00:00:00 2001 From: Gonzalo Amestoy <68620914+amestoyg@users.noreply.github.com> Date: Tue, 6 Dec 2022 09:28:24 +0100 Subject: [PATCH 103/601] Introduce `CollectionForEach` Refaster rule (#390) Fixes #387. --- .../errorprone/refasterrules/CollectionRules.java | 14 ++++++++++++++ .../refasterrules/CollectionRulesTestInput.java | 4 ++++ .../refasterrules/CollectionRulesTestOutput.java | 4 ++++ 3 files changed, 22 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java index 19df9107db..90dc4f183f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java @@ -17,6 +17,7 @@ import java.util.Queue; import java.util.Set; import java.util.SortedSet; +import java.util.function.Consumer; import java.util.function.IntFunction; import java.util.stream.Stream; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; @@ -404,6 +405,19 @@ Optional after(Queue queue) { } } + /** Prefer {@link Collection#forEach(Consumer)} over more contrived alternatives. */ + static final class CollectionForEach { + @BeforeTemplate + void before(Collection collection, Consumer consumer) { + collection.stream().forEach(consumer); + } + + @AfterTemplate + void after(Collection collection, Consumer consumer) { + collection.forEach(consumer); + } + } + // XXX: collection.stream().noneMatch(e -> e.equals(other)) // ^ This is !collection.contains(other). Do we already rewrite variations on this? } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java index c5c3f686d5..68f6f79bfb 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestInput.java @@ -186,4 +186,8 @@ ImmutableSet> testRemoveOptionalFirstQueueElement() { ? Optional.ofNullable(new LinkedList().remove()) : Optional.empty()); } + + void testCollectionForEach() { + ImmutableSet.of(1).stream().forEach(String::valueOf); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java index 7d580729cc..0ebaa40f3b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/CollectionRulesTestOutput.java @@ -136,4 +136,8 @@ ImmutableSet> testRemoveOptionalFirstQueueElement() { Optional.ofNullable(new LinkedList().poll()), Optional.ofNullable(new LinkedList().poll())); } + + void testCollectionForEach() { + ImmutableSet.of(1).forEach(String::valueOf); + } } From ae327d8d643a8ed2cd523385af19123b83a1b406 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 6 Dec 2022 11:58:47 +0100 Subject: [PATCH 104/601] Upgrade pitest-maven-plugin 1.9.11 -> 1.10.3 (#378) See: - https://github.com/hcoles/pitest/releases/tag/1.10.0 - https://github.com/hcoles/pitest/releases/tag/1.10.1 - https://github.com/hcoles/pitest/releases/tag/1.10.2 - https://github.com/hcoles/pitest/releases/tag/1.10.3 - https://github.com/hcoles/pitest/compare/1.9.11...1.10.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4c7822595b..a62b53dd0c 100644 --- a/pom.xml +++ b/pom.xml @@ -1239,7 +1239,7 @@ org.pitest pitest-maven - 1.9.11 + 1.10.3 From d427e298e200409b099fad6e75465f002326ab59 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 7 Dec 2022 11:38:25 +0100 Subject: [PATCH 105/601] Introduce additional Refaster rules to `ComparatorRules` (#388) --- .../refasterrules/ComparatorRules.java | 129 ++++++++++++++---- .../errorprone/refasterrules/StreamRules.java | 3 + .../ComparatorRulesTestInput.java | 64 +++++++-- .../ComparatorRulesTestOutput.java | 67 +++++++-- 4 files changed, 218 insertions(+), 45 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java index 83ea4c7378..438fbe8b6c 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java @@ -15,6 +15,7 @@ import com.google.errorprone.refaster.Refaster; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; +import com.google.errorprone.refaster.annotation.Repeated; import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Arrays; import java.util.Collections; @@ -24,6 +25,7 @@ import java.util.function.ToDoubleFunction; import java.util.function.ToIntFunction; import java.util.function.ToLongFunction; +import java.util.stream.Stream; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; /** Refaster rules related to expressions dealing with {@link Comparator}s. */ @@ -37,7 +39,10 @@ static final class NaturalOrder> { @BeforeTemplate Comparator before() { return Refaster.anyOf( - comparing(Refaster.anyOf(identity(), v -> v)), Comparator.reverseOrder().reversed()); + T::compareTo, + comparing(Refaster.anyOf(identity(), v -> v)), + Collections.reverseOrder(reverseOrder()), + Comparator.reverseOrder().reversed()); } @AfterTemplate @@ -51,7 +56,10 @@ Comparator after() { static final class ReverseOrder> { @BeforeTemplate Comparator before() { - return Comparator.naturalOrder().reversed(); + return Refaster.anyOf( + Collections.reverseOrder(), + Collections.reverseOrder(naturalOrder()), + Comparator.naturalOrder().reversed()); } @AfterTemplate @@ -189,15 +197,54 @@ Comparator after(Comparator cmp) { } } + /** Prefer {@link Comparable#compareTo(Object)}} over more verbose alternatives. */ + static final class CompareTo> { + @BeforeTemplate + int before(T value1, T value2) { + return Refaster.anyOf( + Comparator.naturalOrder().compare(value1, value2), + Comparator.reverseOrder().compare(value2, value1)); + } + + @AfterTemplate + int after(T value1, T value2) { + return value1.compareTo(value2); + } + } + + /** + * Avoid unnecessary creation of a {@link Stream} to determine the minimum of a known collection + * of values. + */ + static final class MinOfVarargs { + @BeforeTemplate + @SuppressWarnings("StreamOfArray" /* In practice individual values are provided. */) + T before(@Repeated T value, Comparator cmp) { + return Stream.of(Refaster.asVarargs(value)).min(cmp).orElseThrow(); + } + + @AfterTemplate + T after(@Repeated T value, Comparator cmp) { + return Collections.min(Arrays.asList(value), cmp); + } + } + /** Prefer {@link Comparators#min(Comparable, Comparable)}} over more verbose alternatives. */ static final class MinOfPairNaturalOrder> { @BeforeTemplate T before(T value1, T value2) { - return Collections.min( - Refaster.anyOf( - Arrays.asList(value1, value2), - ImmutableList.of(value1, value2), - ImmutableSet.of(value1, value2))); + return Refaster.anyOf( + value1.compareTo(value2) <= 0 ? value1 : value2, + value1.compareTo(value2) > 0 ? value2 : value1, + value2.compareTo(value1) < 0 ? value2 : value1, + value2.compareTo(value1) >= 0 ? value1 : value2, + Comparators.min(value1, value2, naturalOrder()), + Comparators.max(value1, value2, reverseOrder()), + Collections.min( + Refaster.anyOf( + Arrays.asList(value1, value2), + ImmutableList.of(value1, value2), + ImmutableSet.of(value1, value2)))); } @AfterTemplate @@ -212,12 +259,17 @@ T after(T value1, T value2) { static final class MinOfPairCustomOrder { @BeforeTemplate T before(T value1, T value2, Comparator cmp) { - return Collections.min( - Refaster.anyOf( - Arrays.asList(value1, value2), - ImmutableList.of(value1, value2), - ImmutableSet.of(value1, value2)), - cmp); + return Refaster.anyOf( + cmp.compare(value1, value2) <= 0 ? value1 : value2, + cmp.compare(value1, value2) > 0 ? value2 : value1, + cmp.compare(value2, value1) < 0 ? value2 : value1, + cmp.compare(value2, value1) >= 0 ? value1 : value2, + Collections.min( + Refaster.anyOf( + Arrays.asList(value1, value2), + ImmutableList.of(value1, value2), + ImmutableSet.of(value1, value2)), + cmp)); } @AfterTemplate @@ -226,15 +278,39 @@ T after(T value1, T value2, Comparator cmp) { } } + /** + * Avoid unnecessary creation of a {@link Stream} to determine the maximum of a known collection + * of values. + */ + static final class MaxOfVarargs { + @BeforeTemplate + @SuppressWarnings("StreamOfArray" /* In practice individual values are provided. */) + T before(@Repeated T value, Comparator cmp) { + return Stream.of(Refaster.asVarargs(value)).max(cmp).orElseThrow(); + } + + @AfterTemplate + T after(@Repeated T value, Comparator cmp) { + return Collections.max(Arrays.asList(value), cmp); + } + } + /** Prefer {@link Comparators#max(Comparable, Comparable)}} over more verbose alternatives. */ static final class MaxOfPairNaturalOrder> { @BeforeTemplate T before(T value1, T value2) { - return Collections.max( - Refaster.anyOf( - Arrays.asList(value1, value2), - ImmutableList.of(value1, value2), - ImmutableSet.of(value1, value2))); + return Refaster.anyOf( + value1.compareTo(value2) >= 0 ? value1 : value2, + value1.compareTo(value2) < 0 ? value2 : value1, + value2.compareTo(value1) > 0 ? value2 : value1, + value2.compareTo(value1) <= 0 ? value1 : value2, + Comparators.max(value1, value2, naturalOrder()), + Comparators.min(value1, value2, reverseOrder()), + Collections.max( + Refaster.anyOf( + Arrays.asList(value1, value2), + ImmutableList.of(value1, value2), + ImmutableSet.of(value1, value2)))); } @AfterTemplate @@ -249,12 +325,17 @@ T after(T value1, T value2) { static final class MaxOfPairCustomOrder { @BeforeTemplate T before(T value1, T value2, Comparator cmp) { - return Collections.max( - Refaster.anyOf( - Arrays.asList(value1, value2), - ImmutableList.of(value1, value2), - ImmutableSet.of(value1, value2)), - cmp); + return Refaster.anyOf( + cmp.compare(value1, value2) >= 0 ? value1 : value2, + cmp.compare(value1, value2) < 0 ? value2 : value1, + cmp.compare(value2, value1) > 0 ? value2 : value1, + cmp.compare(value2, value1) <= 0 ? value1 : value2, + Collections.max( + Refaster.anyOf( + Arrays.asList(value1, value2), + ImmutableList.of(value1, value2), + ImmutableSet.of(value1, value2)), + cmp)); } @AfterTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java index 9238ec0f80..322f232831 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java @@ -77,6 +77,9 @@ Stream after(T object) { * Prefer {@link Arrays#stream(Object[])} over {@link Stream#of(Object[])}, as the former is * clearer. */ + // XXX: Introduce a `Matcher` that identifies `Refaster.asVarargs(...)` invocations and annotate + // the `array` parameter as `@NotMatches(IsRefasterAsVarargs.class)`. Then elsewhere + // `@SuppressWarnings("StreamOfArray")` annotations can be dropped. static final class StreamOfArray { @BeforeTemplate Stream before(T[] array) { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestInput.java index 961a5f21c0..8fde90183a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestInput.java @@ -4,30 +4,42 @@ import static java.util.Comparator.reverseOrder; import static java.util.function.Function.identity; +import com.google.common.collect.Comparators; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.function.BinaryOperator; +import java.util.stream.Stream; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class ComparatorRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( - Arrays.class, Collections.class, ImmutableList.class, ImmutableSet.class, identity()); + Arrays.class, + Collections.class, + ImmutableList.class, + ImmutableSet.class, + Stream.class, + identity()); } ImmutableSet> testNaturalOrder() { return ImmutableSet.of( + String::compareTo, Comparator.comparing(identity()), Comparator.comparing(s -> s), + Collections.reverseOrder(reverseOrder()), Comparator.reverseOrder().reversed()); } - Comparator testReverseOrder() { - return Comparator.naturalOrder().reversed(); + ImmutableSet> testReverseOrder() { + return ImmutableSet.of( + Collections.reverseOrder(), + Collections.reverseOrder(naturalOrder()), + Comparator.naturalOrder().reversed()); } ImmutableSet> testCustomComparator() { @@ -77,8 +89,24 @@ ImmutableSet> testThenComparingNaturalOrder() { Comparator.naturalOrder().thenComparing(s -> s)); } + ImmutableSet testCompareTo() { + return ImmutableSet.of( + Comparator.naturalOrder().compare("foo", "bar"), + Comparator.reverseOrder().compare("baz", "qux")); + } + + int testMinOfVarargs() { + return Stream.of(1, 2).min(naturalOrder()).orElseThrow(); + } + ImmutableSet testMinOfPairNaturalOrder() { return ImmutableSet.of( + "a".compareTo("b") <= 0 ? "a" : "b", + "a".compareTo("b") > 0 ? "b" : "a", + "a".compareTo("b") < 0 ? "a" : "b", + "a".compareTo("b") >= 0 ? "b" : "a", + Comparators.min("a", "b", naturalOrder()), + Comparators.max("a", "b", reverseOrder()), Collections.min(Arrays.asList("a", "b")), Collections.min(ImmutableList.of("a", "b")), Collections.min(ImmutableSet.of("a", "b"))); @@ -86,13 +114,27 @@ ImmutableSet testMinOfPairNaturalOrder() { ImmutableSet testMinOfPairCustomOrder() { return ImmutableSet.of( - Collections.min(Arrays.asList(new Object(), new Object()), (a, b) -> -1), - Collections.min(ImmutableList.of(new Object(), new Object()), (a, b) -> 0), - Collections.min(ImmutableSet.of(new Object(), new Object()), (a, b) -> 1)); + Comparator.comparingInt(String::length).compare("a", "b") <= 0 ? "a" : "b", + Comparator.comparingInt(String::length).compare("a", "b") > 0 ? "b" : "a", + Comparator.comparingInt(String::length).compare("a", "b") < 0 ? "a" : "b", + Comparator.comparingInt(String::length).compare("a", "b") >= 0 ? "b" : "a", + Collections.min(Arrays.asList("a", "b"), (a, b) -> -1), + Collections.min(ImmutableList.of("a", "b"), (a, b) -> 0), + Collections.min(ImmutableSet.of("a", "b"), (a, b) -> 1)); + } + + int testMaxOfVarargs() { + return Stream.of(1, 2).max(naturalOrder()).orElseThrow(); } ImmutableSet testMaxOfPairNaturalOrder() { return ImmutableSet.of( + "a".compareTo("b") >= 0 ? "a" : "b", + "a".compareTo("b") < 0 ? "b" : "a", + "a".compareTo("b") > 0 ? "a" : "b", + "a".compareTo("b") <= 0 ? "b" : "a", + Comparators.max("a", "b", naturalOrder()), + Comparators.min("a", "b", reverseOrder()), Collections.max(Arrays.asList("a", "b")), Collections.max(ImmutableList.of("a", "b")), Collections.max(ImmutableSet.of("a", "b"))); @@ -100,9 +142,13 @@ ImmutableSet testMaxOfPairNaturalOrder() { ImmutableSet testMaxOfPairCustomOrder() { return ImmutableSet.of( - Collections.max(Arrays.asList(new Object(), new Object()), (a, b) -> -1), - Collections.max(ImmutableList.of(new Object(), new Object()), (a, b) -> 0), - Collections.max(ImmutableSet.of(new Object(), new Object()), (a, b) -> 1)); + Comparator.comparingInt(String::length).compare("a", "b") >= 0 ? "a" : "b", + Comparator.comparingInt(String::length).compare("a", "b") < 0 ? "b" : "a", + Comparator.comparingInt(String::length).compare("a", "b") > 0 ? "a" : "b", + Comparator.comparingInt(String::length).compare("a", "b") <= 0 ? "b" : "a", + Collections.max(Arrays.asList("a", "b"), (a, b) -> -1), + Collections.max(ImmutableList.of("a", "b"), (a, b) -> 0), + Collections.max(ImmutableSet.of("a", "b"), (a, b) -> 1)); } BinaryOperator testComparatorsMin() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java index b2a54f06a1..743b859c59 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java @@ -11,21 +11,28 @@ import java.util.Collections; import java.util.Comparator; import java.util.function.BinaryOperator; +import java.util.stream.Stream; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class ComparatorRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of( - Arrays.class, Collections.class, ImmutableList.class, ImmutableSet.class, identity()); + Arrays.class, + Collections.class, + ImmutableList.class, + ImmutableSet.class, + Stream.class, + identity()); } ImmutableSet> testNaturalOrder() { - return ImmutableSet.of(naturalOrder(), naturalOrder(), naturalOrder()); + return ImmutableSet.of( + naturalOrder(), naturalOrder(), naturalOrder(), naturalOrder(), naturalOrder()); } - Comparator testReverseOrder() { - return reverseOrder(); + ImmutableSet> testReverseOrder() { + return ImmutableSet.of(reverseOrder(), reverseOrder(), reverseOrder()); } ImmutableSet> testCustomComparator() { @@ -68,28 +75,64 @@ ImmutableSet> testThenComparingNaturalOrder() { Comparator.naturalOrder().thenComparing(naturalOrder())); } + ImmutableSet testCompareTo() { + return ImmutableSet.of("foo".compareTo("bar"), "qux".compareTo("baz")); + } + + int testMinOfVarargs() { + return Collections.min(Arrays.asList(1, 2), naturalOrder()); + } + ImmutableSet testMinOfPairNaturalOrder() { return ImmutableSet.of( - Comparators.min("a", "b"), Comparators.min("a", "b"), Comparators.min("a", "b")); + Comparators.min("a", "b"), + Comparators.min("a", "b"), + Comparators.min("b", "a"), + Comparators.min("b", "a"), + Comparators.min("a", "b"), + Comparators.min("a", "b"), + Comparators.min("a", "b"), + Comparators.min("a", "b"), + Comparators.min("a", "b")); } ImmutableSet testMinOfPairCustomOrder() { return ImmutableSet.of( - Comparators.min(new Object(), new Object(), (a, b) -> -1), - Comparators.min(new Object(), new Object(), (a, b) -> 0), - Comparators.min(new Object(), new Object(), (a, b) -> 1)); + Comparators.min("a", "b", Comparator.comparingInt(String::length)), + Comparators.min("a", "b", Comparator.comparingInt(String::length)), + Comparators.min("b", "a", Comparator.comparingInt(String::length)), + Comparators.min("b", "a", Comparator.comparingInt(String::length)), + Comparators.min("a", "b", (a, b) -> -1), + Comparators.min("a", "b", (a, b) -> 0), + Comparators.min("a", "b", (a, b) -> 1)); + } + + int testMaxOfVarargs() { + return Collections.max(Arrays.asList(1, 2), naturalOrder()); } ImmutableSet testMaxOfPairNaturalOrder() { return ImmutableSet.of( - Comparators.max("a", "b"), Comparators.max("a", "b"), Comparators.max("a", "b")); + Comparators.max("a", "b"), + Comparators.max("a", "b"), + Comparators.max("b", "a"), + Comparators.max("b", "a"), + Comparators.max("a", "b"), + Comparators.max("a", "b"), + Comparators.max("a", "b"), + Comparators.max("a", "b"), + Comparators.max("a", "b")); } ImmutableSet testMaxOfPairCustomOrder() { return ImmutableSet.of( - Comparators.max(new Object(), new Object(), (a, b) -> -1), - Comparators.max(new Object(), new Object(), (a, b) -> 0), - Comparators.max(new Object(), new Object(), (a, b) -> 1)); + Comparators.max("a", "b", Comparator.comparingInt(String::length)), + Comparators.max("a", "b", Comparator.comparingInt(String::length)), + Comparators.max("b", "a", Comparator.comparingInt(String::length)), + Comparators.max("b", "a", Comparator.comparingInt(String::length)), + Comparators.max("a", "b", (a, b) -> -1), + Comparators.max("a", "b", (a, b) -> 0), + Comparators.max("a", "b", (a, b) -> 1)); } BinaryOperator testComparatorsMin() { From cf995ece2baca811513964208a259ea586479d6c Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 7 Dec 2022 11:48:55 +0100 Subject: [PATCH 106/601] Upgrade actions/setup-java v3.6.0 -> v3.8.0 (#395) See: - https://github.com/actions/setup-java/releases/tag/v3.8.0 - https://github.com/actions/setup-java/compare/v3.6.0...v3.8.0 --- .github/workflows/build.yaml | 2 +- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/pitest-update-pr.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4979e59dc0..188450955e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -37,7 +37,7 @@ jobs: - name: Check out code uses: actions/checkout@v3.1.0 - name: Set up JDK - uses: actions/setup-java@v3.6.0 + uses: actions/setup-java@v3.8.0 with: java-version: ${{ matrix.jdk }} distribution: ${{ matrix.distribution }} diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index 8d1bf61330..1c536124a8 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -16,7 +16,7 @@ jobs: with: fetch-depth: 2 - name: Set up JDK - uses: actions/setup-java@v3.6.0 + uses: actions/setup-java@v3.8.0 with: java-version: 17.0.4 distribution: temurin diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index 2acaf65398..240f14275f 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -20,7 +20,7 @@ jobs: - name: Check out code uses: actions/checkout@v3.1.0 - name: Set up JDK - uses: actions/setup-java@v3.6.0 + uses: actions/setup-java@v3.8.0 with: java-version: 17.0.4 distribution: temurin From bc1f204877325cf230e2a133aae0dfa09b62f12b Mon Sep 17 00:00:00 2001 From: Vincent Koeman Date: Wed, 7 Dec 2022 18:58:54 +0100 Subject: [PATCH 107/601] Prefer `BigDecimal.valueOf(double)` over `new BigDecimal(double)` (#394) See https://rules.sonarsource.com/java/RSPEC-2111 --- .../errorprone/refasterrules/BigDecimalRules.java | 13 +++++++------ .../refasterrules/BigDecimalRulesTestInput.java | 4 ++-- .../refasterrules/BigDecimalRulesTestOutput.java | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java index b23406170b..08e3878fa5 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java @@ -50,17 +50,18 @@ BigDecimal after() { } } - /** Prefer {@link BigDecimal#valueOf(long)} over the associated constructor. */ - // XXX: Ideally we'd also rewrite `BigDecimal.valueOf("")`, but it doesn't - // appear that's currently possible with Error Prone. - static final class BigDecimalFactoryMethod { + /** Prefer {@link BigDecimal#valueOf(double)} over the associated constructor. */ + // XXX: Ideally we also rewrite `new BigDecimal("")` in cases where the + // specified number can be represented as an `int` or `long`, but that requires a custom + // `BugChecker`. + static final class BigDecimalValueOf { @BeforeTemplate - BigDecimal before(long value) { + BigDecimal before(double value) { return new BigDecimal(value); } @AfterTemplate - BigDecimal after(long value) { + BigDecimal after(double value) { return BigDecimal.valueOf(value); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java index 37db5459ce..4f6a02bfe5 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java @@ -17,7 +17,7 @@ ImmutableSet testBigDecimalTen() { return ImmutableSet.of(BigDecimal.valueOf(10), BigDecimal.valueOf(10L), new BigDecimal("10")); } - ImmutableSet testBigDecimalFactoryMethod() { - return ImmutableSet.of(new BigDecimal(0), new BigDecimal(0L)); + ImmutableSet testBigDecimalValueOf() { + return ImmutableSet.of(new BigDecimal(2), new BigDecimal(2L), new BigDecimal(2.0)); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java index 8be65ad520..37c226eb7a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java @@ -17,7 +17,7 @@ ImmutableSet testBigDecimalTen() { return ImmutableSet.of(BigDecimal.TEN, BigDecimal.TEN, BigDecimal.TEN); } - ImmutableSet testBigDecimalFactoryMethod() { - return ImmutableSet.of(BigDecimal.valueOf(0), BigDecimal.valueOf(0L)); + ImmutableSet testBigDecimalValueOf() { + return ImmutableSet.of(BigDecimal.valueOf(2), BigDecimal.valueOf(2L), BigDecimal.valueOf(2.0)); } } From b1c815770bb1e0be98ef3a9bf909b6fea234ba72 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Thu, 8 Dec 2022 09:06:19 +0100 Subject: [PATCH 108/601] Prevent `ReverseOrder` Refaster rule from introducing a static import (#397) This is a workaround for the issue resolved by google/error-prone#3584. After application of this Refaster rule, any static imports of `java.util.Collections.reverseOrder` are obsolete. These can be removed by running Google Java Format or Error Prone's `RemoveUnusedImports` check. Where possible, subsequent application of the `StaticImport` check will statically import `java.util.Comparator.reverseOrder`. --- .../tech/picnic/errorprone/refasterrules/ComparatorRules.java | 3 ++- .../errorprone/refasterrules/ComparatorRulesTestOutput.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java index 438fbe8b6c..c15b466aa4 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ComparatorRules.java @@ -62,8 +62,9 @@ Comparator before() { Comparator.naturalOrder().reversed()); } + // XXX: Add `@UseImportPolicy(STATIC_IMPORT_ALWAYS)` if/when + // https://github.com/google/error-prone/pull/3584 is merged and released. @AfterTemplate - @UseImportPolicy(STATIC_IMPORT_ALWAYS) Comparator after() { return reverseOrder(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java index 743b859c59..9c27527ddf 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ComparatorRulesTestOutput.java @@ -32,7 +32,8 @@ ImmutableSet> testNaturalOrder() { } ImmutableSet> testReverseOrder() { - return ImmutableSet.of(reverseOrder(), reverseOrder(), reverseOrder()); + return ImmutableSet.of( + Comparator.reverseOrder(), Comparator.reverseOrder(), Comparator.reverseOrder()); } ImmutableSet> testCustomComparator() { From 3ee527fda2cdf48d3006bd777a4896f8627b3e36 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Fri, 9 Dec 2022 08:55:12 +0100 Subject: [PATCH 109/601] Drop indentation in feature request issue template (#403) While there, add "Improve performance" as a rewrite reason. --- .github/ISSUE_TEMPLATE/feature_request.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index b9b7adac05..3d34623663 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -17,22 +17,23 @@ you'd like to be solved through Error Prone Support. --> - [ ] Support a stylistic preference. - [ ] Avoid a common gotcha, or potential problem. +- [ ] Improve performance. - I would like to rewrite the following code: - ```java - // XXX: Write the code to match here. - ``` +I would like to rewrite the following code: +```java +// XXX: Write the code to match here. +``` - to: - ```java - // XXX: Write the desired code here. - ``` ---> +to: +```java +// XXX: Write the desired code here. +``` ### Considerations From 17bcdb6faaefc69024d6def504d52021d4d5f9a4 Mon Sep 17 00:00:00 2001 From: Shang Xiang <24667806+CoolTomatos@users.noreply.github.com> Date: Fri, 9 Dec 2022 13:07:31 +0100 Subject: [PATCH 110/601] Introduce `Flux` and `Stream` Refaster rules to suggest filtering before sorting (#393) Fixes #386. --- .../refasterrules/DoubleStreamRules.java | 16 +++++++++ .../refasterrules/IntStreamRules.java | 16 +++++++++ .../refasterrules/LongStreamRules.java | 16 +++++++++ .../refasterrules/ReactorRules.java | 33 ++++++++++++++++++ .../errorprone/refasterrules/StreamRules.java | 34 +++++++++++++++++++ .../DoubleStreamRulesTestInput.java | 4 +++ .../DoubleStreamRulesTestOutput.java | 4 +++ .../IntStreamRulesTestInput.java | 4 +++ .../IntStreamRulesTestOutput.java | 4 +++ .../LongStreamRulesTestInput.java | 4 +++ .../LongStreamRulesTestOutput.java | 4 +++ .../refasterrules/ReactorRulesTestInput.java | 9 +++++ .../refasterrules/ReactorRulesTestOutput.java | 9 +++++ .../refasterrules/StreamRulesTestInput.java | 10 +++++- .../refasterrules/StreamRulesTestOutput.java | 10 +++++- 15 files changed, 175 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java index ca64f929d8..ae8a389258 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java @@ -141,6 +141,22 @@ DoubleStream after(Stream stream, DoubleFunction func } } + /** + * Apply {@link DoubleStream#filter(DoublePredicate)} before {@link DoubleStream#sorted()} to + * reduce the number of elements to sort. + */ + static final class DoubleStreamFilterSorted { + @BeforeTemplate + DoubleStream before(DoubleStream stream, DoublePredicate predicate) { + return stream.sorted().filter(predicate); + } + + @AfterTemplate + DoubleStream after(DoubleStream stream, DoublePredicate predicate) { + return stream.filter(predicate).sorted(); + } + } + /** In order to test whether a stream has any element, simply try to find one. */ static final class DoubleStreamIsEmpty { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java index 2c43fc3cc1..679bddaa13 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java @@ -154,6 +154,22 @@ IntStream after(Stream stream, IntFunction function) { } } + /** + * Apply {@link IntStream#filter(IntPredicate)} before {@link IntStream#sorted()} to reduce the + * number of elements to sort. + */ + static final class IntStreamFilterSorted { + @BeforeTemplate + IntStream before(IntStream stream, IntPredicate predicate) { + return stream.sorted().filter(predicate); + } + + @AfterTemplate + IntStream after(IntStream stream, IntPredicate predicate) { + return stream.filter(predicate).sorted(); + } + } + /** In order to test whether a stream has any element, simply try to find one. */ static final class IntStreamIsEmpty { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java index 363157c55f..76da55b072 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java @@ -154,6 +154,22 @@ LongStream after(Stream stream, LongFunction function) } } + /** + * Apply {@link LongStream#filter(LongPredicate)} before {@link LongStream#sorted()} to reduce the + * number of elements to sort. + */ + static final class LongStreamFilterSorted { + @BeforeTemplate + LongStream before(LongStream stream, LongPredicate predicate) { + return stream.sorted().filter(predicate); + } + + @AfterTemplate + LongStream after(LongStream stream, LongPredicate predicate) { + return stream.filter(predicate).sorted(); + } + } + /** In order to test whether a stream has any element, simply try to find one. */ static final class LongStreamIsEmpty { @BeforeTemplate diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 6b6997a5ed..e698b07f59 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -17,6 +17,7 @@ import com.google.errorprone.refaster.annotation.Placeholder; import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.time.Duration; +import java.util.Comparator; import java.util.HashMap; import java.util.Optional; import java.util.concurrent.Callable; @@ -1062,6 +1063,38 @@ Flux after(Flux flux, Class clazz, T fallbackValue) { } } + /** + * Apply {@link Flux#filter(Predicate)} before {@link Flux#sort()} to reduce the number of + * elements to sort. + */ + static final class FluxFilterSort { + @BeforeTemplate + Flux before(Flux flux, Predicate predicate) { + return flux.sort().filter(predicate); + } + + @AfterTemplate + Flux after(Flux flux, Predicate predicate) { + return flux.filter(predicate).sort(); + } + } + + /** + * Apply {@link Flux#filter(Predicate)} before {@link Flux#sort(Comparator)} to reduce the number + * of elements to sort. + */ + static final class FluxFilterSortWithComparator { + @BeforeTemplate + Flux before(Flux flux, Predicate predicate, Comparator comparator) { + return flux.sort(comparator).filter(predicate); + } + + @AfterTemplate + Flux after(Flux flux, Predicate predicate, Comparator comparator) { + return flux.filter(predicate).sort(comparator); + } + } + /** Prefer {@link reactor.util.context.Context#empty()}} over more verbose alternatives. */ // XXX: Consider introducing an `IsEmpty` matcher that identifies a wide range of guaranteed-empty // `Collection` and `Map` expressions. diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java index 322f232831..251fdea9c6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java @@ -167,6 +167,40 @@ Stream after(Stream stream, Function { + @BeforeTemplate + Stream before(Stream stream, Predicate predicate) { + return stream.sorted().filter(predicate); + } + + @AfterTemplate + Stream after(Stream stream, Predicate predicate) { + return stream.filter(predicate).sorted(); + } + } + + /** + * Apply {@link Stream#filter(Predicate)} before {@link Stream#sorted(Comparator)} to reduce the + * number of elements to sort. + */ + static final class StreamFilterSortedWithComparator { + @BeforeTemplate + Stream before( + Stream stream, Predicate predicate, Comparator comparator) { + return stream.sorted(comparator).filter(predicate); + } + + @AfterTemplate + Stream after( + Stream stream, Predicate predicate, Comparator comparator) { + return stream.filter(predicate).sorted(comparator); + } + } + /** * Where possible, clarify that a mapping operation will be applied only to a single stream * element. diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java index 9c35f9c651..5f8ab5a000 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java @@ -46,6 +46,10 @@ DoubleStream testFlatMapOuterStreamAfterFlatMapToDouble() { return Stream.of(1).flatMapToDouble(v -> DoubleStream.of(v * v).flatMap(DoubleStream::of)); } + DoubleStream testDoubleStreamFilterSorted() { + return DoubleStream.of(1, 4, 3, 2).sorted().filter(d -> d % 2 == 0); + } + ImmutableSet testDoubleStreamIsEmpty() { return ImmutableSet.of( DoubleStream.of(1).count() == 0, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java index 0f5c7db8eb..c382f567c8 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java @@ -46,6 +46,10 @@ DoubleStream testFlatMapOuterStreamAfterFlatMapToDouble() { return Stream.of(1).flatMapToDouble(v -> DoubleStream.of(v * v)).flatMap(DoubleStream::of); } + DoubleStream testDoubleStreamFilterSorted() { + return DoubleStream.of(1, 4, 3, 2).filter(d -> d % 2 == 0).sorted(); + } + ImmutableSet testDoubleStreamIsEmpty() { return ImmutableSet.of( DoubleStream.of(1).findAny().isEmpty(), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java index 32458e2bbb..6ff668b016 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java @@ -50,6 +50,10 @@ IntStream testFlatMapOuterStreamAfterFlatMapToInt() { return Stream.of(1).flatMapToInt(v -> IntStream.of(v * v).flatMap(IntStream::of)); } + IntStream testIntStreamFilterSorted() { + return IntStream.of(1, 4, 3, 2).sorted().filter(i -> i % 2 == 0); + } + ImmutableSet testIntStreamIsEmpty() { return ImmutableSet.of( IntStream.of(1).count() == 0, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java index c75ce7bb7f..23ab645e09 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java @@ -50,6 +50,10 @@ IntStream testFlatMapOuterStreamAfterFlatMapToInt() { return Stream.of(1).flatMapToInt(v -> IntStream.of(v * v)).flatMap(IntStream::of); } + IntStream testIntStreamFilterSorted() { + return IntStream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(); + } + ImmutableSet testIntStreamIsEmpty() { return ImmutableSet.of( IntStream.of(1).findAny().isEmpty(), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java index 3909ce3df7..83e4bb6a4a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java @@ -50,6 +50,10 @@ LongStream testFlatMapOuterStreamAfterFlatMapToLong() { return Stream.of(1).flatMapToLong(v -> LongStream.of(v * v).flatMap(LongStream::of)); } + LongStream testLongStreamFilterSorted() { + return LongStream.of(1, 4, 3, 2).sorted().filter(l -> l % 2 == 0); + } + ImmutableSet testLongStreamIsEmpty() { return ImmutableSet.of( LongStream.of(1).count() == 0, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java index b585534a33..629028e76a 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java @@ -50,6 +50,10 @@ LongStream testFlatMapOuterStreamAfterFlatMapToLong() { return Stream.of(1).flatMapToLong(v -> LongStream.of(v * v)).flatMap(LongStream::of); } + LongStream testLongStreamFilterSorted() { + return LongStream.of(1, 4, 3, 2).filter(l -> l % 2 == 0).sorted(); + } + ImmutableSet testLongStreamIsEmpty() { return ImmutableSet.of( LongStream.of(1).findAny().isEmpty(), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index e256522c08..6ee8cbf8fc 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -1,5 +1,6 @@ package tech.picnic.errorprone.refasterrules; +import static java.util.Comparator.reverseOrder; import static java.util.function.Function.identity; import static org.assertj.core.api.Assertions.assertThat; @@ -327,6 +328,14 @@ Flux testFluxOnErrorReturn() { return Flux.just(1).onErrorReturn(IllegalArgumentException.class::isInstance, 2); } + Flux testFluxFilterSort() { + return Flux.just(1, 4, 3, 2).sort().filter(i -> i % 2 == 0); + } + + Flux testFluxFilterSortWithComparator() { + return Flux.just(1, 4, 3, 2).sort(reverseOrder()).filter(i -> i % 2 == 0); + } + ImmutableSet testContextEmpty() { return ImmutableSet.of(Context.of(new HashMap<>()), Context.of(ImmutableMap.of())); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index 3c247811e4..5a15684ad4 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -1,6 +1,7 @@ package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.MoreCollectors.toOptional; +import static java.util.Comparator.reverseOrder; import static java.util.function.Function.identity; import static org.assertj.core.api.Assertions.assertThat; import static reactor.function.TupleUtils.function; @@ -322,6 +323,14 @@ Flux testFluxOnErrorReturn() { return Flux.just(1).onErrorReturn(IllegalArgumentException.class, 2); } + Flux testFluxFilterSort() { + return Flux.just(1, 4, 3, 2).filter(i -> i % 2 == 0).sort(); + } + + Flux testFluxFilterSortWithComparator() { + return Flux.just(1, 4, 3, 2).filter(i -> i % 2 == 0).sort(reverseOrder()); + } + ImmutableSet testContextEmpty() { return ImmutableSet.of(Context.empty(), Context.empty()); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java index 67911c452f..0f291c343e 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java @@ -16,7 +16,7 @@ final class StreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(Objects.class, Streams.class, not(null), reverseOrder()); + return ImmutableSet.of(Objects.class, Streams.class, not(null)); } String testJoining() { @@ -56,6 +56,14 @@ Stream testFlatMapOuterStreamAfterFlatMap() { return Stream.of("foo").flatMap(v -> Stream.of(v.length()).flatMap(Stream::of)); } + Stream testStreamFilterSorted() { + return Stream.of(1, 4, 3, 2).sorted().filter(i -> i % 2 == 0); + } + + Stream testStreamFilterSortedWithComparator() { + return Stream.of(1, 4, 3, 2).sorted(reverseOrder()).filter(i -> i % 2 == 0); + } + ImmutableSet> testStreamMapFirst() { return ImmutableSet.of( Stream.of("foo").map(s -> s.length()).findFirst(), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java index 87e7619539..19e7d9fdda 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java @@ -18,7 +18,7 @@ final class StreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(Objects.class, Streams.class, not(null), reverseOrder()); + return ImmutableSet.of(Objects.class, Streams.class, not(null)); } String testJoining() { @@ -57,6 +57,14 @@ Stream testFlatMapOuterStreamAfterFlatMap() { return Stream.of("foo").flatMap(v -> Stream.of(v.length())).flatMap(Stream::of); } + Stream testStreamFilterSorted() { + return Stream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(); + } + + Stream testStreamFilterSortedWithComparator() { + return Stream.of(1, 4, 3, 2).filter(i -> i % 2 == 0).sorted(reverseOrder()); + } + ImmutableSet> testStreamMapFirst() { return ImmutableSet.of( Stream.of("foo").findFirst().map(s -> s.length()), From 096acfb14f38b6b285599c5effef71d27b2682b3 Mon Sep 17 00:00:00 2001 From: Bastien Diederichs Date: Fri, 9 Dec 2022 13:27:46 +0100 Subject: [PATCH 111/601] Improve `IsInstanceLambdaUsage` check (#401) Fixes #399. --- .../bugpatterns/IsInstanceLambdaUsage.java | 15 ++++++++++---- .../IsInstanceLambdaUsageTest.java | 20 +++++++++++++++++-- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IsInstanceLambdaUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IsInstanceLambdaUsage.java index 874260702c..75c4e1b630 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IsInstanceLambdaUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IsInstanceLambdaUsage.java @@ -6,15 +6,18 @@ import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; import com.google.auto.service.AutoService; +import com.google.common.collect.Iterables; import com.google.errorprone.BugPattern; import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.BugChecker; import com.google.errorprone.bugpatterns.BugChecker.LambdaExpressionTreeMatcher; import com.google.errorprone.fixes.SuggestedFix; import com.google.errorprone.matchers.Description; +import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.InstanceOfTree; import com.sun.source.tree.LambdaExpressionTree; import com.sun.source.tree.Tree.Kind; +import com.sun.source.tree.VariableTree; import tech.picnic.errorprone.bugpatterns.util.SourceCode; /** @@ -39,15 +42,19 @@ public IsInstanceLambdaUsage() {} @Override public Description matchLambdaExpression(LambdaExpressionTree tree, VisitorState state) { - if (tree.getKind() != Kind.LAMBDA_EXPRESSION || tree.getBody().getKind() != Kind.INSTANCE_OF) { + if (tree.getParameters().size() != 1 || tree.getBody().getKind() != Kind.INSTANCE_OF) { + return Description.NO_MATCH; + } + + VariableTree param = Iterables.getOnlyElement(tree.getParameters()); + InstanceOfTree instanceOf = (InstanceOfTree) tree.getBody(); + if (!ASTHelpers.getSymbol(param).equals(ASTHelpers.getSymbol(instanceOf.getExpression()))) { return Description.NO_MATCH; } return describeMatch( tree, SuggestedFix.replace( - tree, - SourceCode.treeToString(((InstanceOfTree) tree.getBody()).getType(), state) - + ".class::isInstance")); + tree, SourceCode.treeToString(instanceOf.getType(), state) + ".class::isInstance")); } } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IsInstanceLambdaUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IsInstanceLambdaUsageTest.java index 205cebd270..3249f5a464 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IsInstanceLambdaUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IsInstanceLambdaUsageTest.java @@ -17,12 +17,28 @@ void identification() { .addSourceLines( "A.java", "import java.util.stream.Stream;", + "import reactor.core.publisher.Flux;", "", "class A {", " void m() {", + " Integer localVariable = 0;", + "", + " Stream.of(0).map(i -> i + 1);", + " Stream.of(1).filter(Integer.class::isInstance);", + " Stream.of(2).filter(i -> i.getClass() instanceof Class);", + " Stream.of(3).filter(i -> localVariable instanceof Integer);", + " // XXX: Ideally this case is also flagged. Pick this up in the context of merging the", + " // `IsInstanceLambdaUsage` and `MethodReferenceUsage` checks, or introduce a separate check that", + " // simplifies unnecessary block lambda expressions.", + " Stream.of(4)", + " .filter(", + " i -> {", + " return localVariable instanceof Integer;", + " });", + " Flux.just(5, \"foo\").distinctUntilChanged(v -> v, (a, b) -> a instanceof Integer);", + "", " // BUG: Diagnostic contains:", - " Stream.of(1).filter(i -> i instanceof Integer);", - " Stream.of(2).filter(Integer.class::isInstance);", + " Stream.of(6).filter(i -> i instanceof Integer);", " }", "}") .doTest(); From 81450285be3c62f5a404f0a3dd79aeb64775bbeb Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Fri, 9 Dec 2022 14:35:35 +0100 Subject: [PATCH 112/601] Fix suggestions emitted by the `StringCaseLocaleUsage` check (#400) The suggested `Locale` arguments are now always located in the correct place. --- .../bugpatterns/StringCaseLocaleUsage.java | 35 ++++++++++++++----- .../StringCaseLocaleUsageTest.java | 32 +++++++++++++++-- pom.xml | 2 ++ 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsage.java index 11b441229c..9aa40e0130 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsage.java @@ -4,9 +4,11 @@ import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; import static com.google.errorprone.BugPattern.StandardTags.FRAGILE_CODE; import static com.google.errorprone.matchers.method.MethodMatchers.instanceMethod; +import static com.sun.tools.javac.parser.Tokens.TokenKind.RPAREN; import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; import com.google.auto.service.AutoService; +import com.google.common.collect.Streams; import com.google.errorprone.BugPattern; import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.BugChecker; @@ -15,8 +17,11 @@ import com.google.errorprone.fixes.SuggestedFix; import com.google.errorprone.matchers.Description; import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.util.ASTHelpers; +import com.google.errorprone.util.ErrorProneTokens; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.MethodInvocationTree; +import com.sun.tools.javac.util.Position; import tech.picnic.errorprone.bugpatterns.util.SourceCode; /** @@ -51,20 +56,34 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState return Description.NO_MATCH; } + int closingParenPosition = getClosingParenPosition(tree, state); + if (closingParenPosition == Position.NOPOS) { + return describeMatch(tree); + } + return buildDescription(tree) - .addFix(suggestLocale(tree, "Locale.ROOT", state)) - .addFix(suggestLocale(tree, "Locale.getDefault()", state)) + .addFix(suggestLocale(closingParenPosition, "Locale.ROOT")) + .addFix(suggestLocale(closingParenPosition, "Locale.getDefault()")) .build(); } - private static Fix suggestLocale(MethodInvocationTree tree, String locale, VisitorState state) { - // XXX: The logic that replaces the first parenthesis assumes that `tree` does not have a source - // code representation such as `str.toLowerCase/* Some comment with parens (). */()`. In such a - // case the comment, rather than the method invocation arguments, will be modified. Implement a - // generic solution for this. + private static Fix suggestLocale(int insertPosition, String locale) { return SuggestedFix.builder() .addImport("java.util.Locale") - .replace(tree, SourceCode.treeToString(tree, state).replaceFirst("\\(", '(' + locale)) + .replace(insertPosition, insertPosition, locale) .build(); } + + private static int getClosingParenPosition(MethodInvocationTree tree, VisitorState state) { + int startPosition = ASTHelpers.getStartPosition(tree); + if (startPosition == Position.NOPOS) { + return Position.NOPOS; + } + + return Streams.findLast( + ErrorProneTokens.getTokens(SourceCode.treeToString(tree, state), state.context).stream() + .filter(t -> t.kind() == RPAREN)) + .map(token -> startPosition + token.pos()) + .orElse(Position.NOPOS); + } } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java index f47b0c434c..caec7843c3 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java @@ -62,6 +62,13 @@ void replacementFirstSuggestedFix() { " void m() {", " \"a\".toLowerCase(/* Comment with parens: (). */ );", " \"b\".toUpperCase();", + " \"c\".toLowerCase().toString();", + "", + " toString().toLowerCase();", + " toString().toUpperCase /* Comment with parens: (). */();", + "", + " this.toString().toLowerCase() /* Comment with parens: (). */;", + " this.toString().toUpperCase();", " }", "}") .addOutputLines( @@ -70,8 +77,15 @@ void replacementFirstSuggestedFix() { "", "class A {", " void m() {", - " \"a\".toLowerCase(Locale.ROOT /* Comment with parens: (). */);", + " \"a\".toLowerCase(/* Comment with parens: (). */ Locale.ROOT);", " \"b\".toUpperCase(Locale.ROOT);", + " \"c\".toLowerCase(Locale.ROOT).toString();", + "", + " toString().toLowerCase(Locale.ROOT);", + " toString().toUpperCase /* Comment with parens: (). */(Locale.ROOT);", + "", + " this.toString().toLowerCase(Locale.ROOT) /* Comment with parens: (). */;", + " this.toString().toUpperCase(Locale.ROOT);", " }", "}") .doTest(TestMode.TEXT_MATCH); @@ -87,6 +101,13 @@ void replacementSecondSuggestedFix() { " void m() {", " \"a\".toLowerCase();", " \"b\".toUpperCase(/* Comment with parens: (). */ );", + " \"c\".toLowerCase().toString();", + "", + " toString().toLowerCase();", + " toString().toUpperCase /* Comment with parens: (). */();", + "", + " this.toString().toLowerCase() /* Comment with parens: (). */;", + " this.toString().toUpperCase();", " }", "}") .addOutputLines( @@ -96,7 +117,14 @@ void replacementSecondSuggestedFix() { "class A {", " void m() {", " \"a\".toLowerCase(Locale.getDefault());", - " \"b\".toUpperCase(Locale.getDefault() /* Comment with parens: (). */);", + " \"b\".toUpperCase(/* Comment with parens: (). */ Locale.getDefault());", + " \"c\".toLowerCase(Locale.getDefault()).toString();", + "", + " toString().toLowerCase(Locale.getDefault());", + " toString().toUpperCase /* Comment with parens: (). */(Locale.getDefault());", + "", + " this.toString().toLowerCase(Locale.getDefault()) /* Comment with parens: (). */;", + " this.toString().toUpperCase(Locale.getDefault());", " }", "}") .doTest(TestMode.TEXT_MATCH); diff --git a/pom.xml b/pom.xml index a62b53dd0c..82cc841a76 100644 --- a/pom.xml +++ b/pom.xml @@ -852,6 +852,7 @@ --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED + --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED -Xmaxerrs @@ -997,6 +998,7 @@ --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED + --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED From 0153c1495f6fc8ce5af2062e974f0ae9092bafd6 Mon Sep 17 00:00:00 2001 From: jarmilakaiser <117719126+jarmilakaiser@users.noreply.github.com> Date: Fri, 9 Dec 2022 16:27:51 +0100 Subject: [PATCH 113/601] Show Christmas Cody in README and on website home page (#404) --- website/assets/images/logo-dark.svg | 255 ++++++++++++++++++++++++++-- website/assets/images/logo.svg | 255 ++++++++++++++++++++++++++-- 2 files changed, 490 insertions(+), 20 deletions(-) diff --git a/website/assets/images/logo-dark.svg b/website/assets/images/logo-dark.svg index bd0c9ff013..9ff31f178c 100644 --- a/website/assets/images/logo-dark.svg +++ b/website/assets/images/logo-dark.svg @@ -1,10 +1,245 @@ - - 1 0 - - 1 1 0 - - 0 0 1 - - 1 0 0 1 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/website/assets/images/logo.svg b/website/assets/images/logo.svg index 97f1342ffc..9ff31f178c 100644 --- a/website/assets/images/logo.svg +++ b/website/assets/images/logo.svg @@ -1,10 +1,245 @@ - - 1 0 - - 1 1 0 - - 0 0 1 - - 1 0 0 1 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 2cbd48ec47ff0dff07e063e24426ced33339e8ba Mon Sep 17 00:00:00 2001 From: Paco van Beckhoven Date: Mon, 12 Dec 2022 03:52:56 -0400 Subject: [PATCH 114/601] Introduce `MonoIdentity` and `MonoThen` Refaster rules (#405) The `MonoIdentity` rule is a generalization of the existing `MonoSwitchIfEmptyOfEmptyPublisher` rule. --- .../refasterrules/ReactorRules.java | 25 +++++++++++++++++-- .../refasterrules/ReactorRulesTestInput.java | 8 ++++-- .../refasterrules/ReactorRulesTestOutput.java | 8 ++++-- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index e698b07f59..52a3e5fdd8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -365,13 +365,21 @@ Flux after(Flux flux, T object) { } } - /** Don't unnecessarily pass an empty publisher to {@link Mono#switchIfEmpty(Mono)}. */ - static final class MonoSwitchIfEmptyOfEmptyPublisher { + /** Don't unnecessarily transform a {@link Mono} to an equivalent instance. */ + static final class MonoIdentity { @BeforeTemplate Mono before(Mono mono) { return mono.switchIfEmpty(Mono.empty()); } + // XXX: Review the suppression once NullAway has better support for generics. Keep an eye on + // https://github.com/uber/NullAway/issues?q=is%3Aopen+generics. + @BeforeTemplate + @SuppressWarnings("NullAway" /* False positive. */) + Mono<@Nullable Void> before2(Mono<@Nullable Void> mono) { + return mono.then(); + } + @AfterTemplate Mono after(Mono mono) { return mono; @@ -675,6 +683,19 @@ Flux after(Mono mono) { } } + /** Prefer direct invocation of {@link Mono#then()}} over more contrived alternatives. */ + static final class MonoThen { + @BeforeTemplate + Mono<@Nullable Void> before(Mono mono) { + return mono.flux().then(); + } + + @AfterTemplate + Mono<@Nullable Void> after(Mono mono) { + return mono.then(); + } + } + /** * Prefer a collection using {@link MoreCollectors#toOptional()} over more contrived alternatives. */ diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 6ee8cbf8fc..c483d1e320 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -115,8 +115,8 @@ ImmutableSet> testFluxDefaultIfEmpty() { Flux.just("baz").switchIfEmpty(Flux.just("qux"))); } - Mono testMonoSwitchIfEmptyOfEmptyPublisher() { - return Mono.just(1).switchIfEmpty(Mono.empty()); + ImmutableSet> testMonoIdentity() { + return ImmutableSet.of(Mono.just(1).switchIfEmpty(Mono.empty()), Mono.empty().then()); } ImmutableSet> testFluxSwitchIfEmptyOfEmptyPublisher() { @@ -221,6 +221,10 @@ ImmutableSet> testMonoFlux() { Flux.concat(Mono.just("baz"))); } + Mono testMonoThen() { + return Mono.just("foo").flux().then(); + } + Mono> testMonoCollectToOptional() { return Mono.just("foo").map(Optional::of).defaultIfEmpty(Optional.empty()); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index 5a15684ad4..619334bab0 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -120,8 +120,8 @@ ImmutableSet> testFluxDefaultIfEmpty() { Flux.just("foo").defaultIfEmpty("bar"), Flux.just("baz").defaultIfEmpty("qux")); } - Mono testMonoSwitchIfEmptyOfEmptyPublisher() { - return Mono.just(1); + ImmutableSet> testMonoIdentity() { + return ImmutableSet.of(Mono.just(1), Mono.empty()); } ImmutableSet> testFluxSwitchIfEmptyOfEmptyPublisher() { @@ -220,6 +220,10 @@ ImmutableSet> testMonoFlux() { Mono.just("foo").flux(), Mono.just("bar").flux(), Mono.just("baz").flux()); } + Mono testMonoThen() { + return Mono.just("foo").then(); + } + Mono> testMonoCollectToOptional() { return Mono.just("foo").flux().collect(toOptional()); } From 465b16c47186a5f463ecfb5cd8f675ee0024cbe7 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 12 Dec 2022 09:57:03 +0100 Subject: [PATCH 115/601] [maven-release-plugin] prepare release v0.6.0 --- error-prone-contrib/pom.xml | 2 +- pom.xml | 4 ++-- refaster-compiler/pom.xml | 2 +- refaster-runner/pom.xml | 2 +- refaster-support/pom.xml | 2 +- refaster-test-support/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index 5644ab18e0..4d7d6efa84 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.5.1-SNAPSHOT + 0.6.0 error-prone-contrib diff --git a/pom.xml b/pom.xml index 82cc841a76..bef3fd7d43 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ tech.picnic.error-prone-support error-prone-support - 0.5.1-SNAPSHOT + 0.6.0 pom Picnic :: Error Prone Support @@ -48,7 +48,7 @@ scm:git:git@github.com:PicnicSupermarket/error-prone-support.git - HEAD + v0.6.0 https://github.com/PicnicSupermarket/error-prone-support diff --git a/refaster-compiler/pom.xml b/refaster-compiler/pom.xml index e8594aae04..9ee26b9b12 100644 --- a/refaster-compiler/pom.xml +++ b/refaster-compiler/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.5.1-SNAPSHOT + 0.6.0 refaster-compiler diff --git a/refaster-runner/pom.xml b/refaster-runner/pom.xml index a3b2e97004..e39f59a805 100644 --- a/refaster-runner/pom.xml +++ b/refaster-runner/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.5.1-SNAPSHOT + 0.6.0 refaster-runner diff --git a/refaster-support/pom.xml b/refaster-support/pom.xml index dfa5feb60a..bb6917a7c8 100644 --- a/refaster-support/pom.xml +++ b/refaster-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.5.1-SNAPSHOT + 0.6.0 refaster-support diff --git a/refaster-test-support/pom.xml b/refaster-test-support/pom.xml index 75917cbfff..6320a23e12 100644 --- a/refaster-test-support/pom.xml +++ b/refaster-test-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.5.1-SNAPSHOT + 0.6.0 refaster-test-support From ec00a5522fac9f6f1566aaa948989fc52f4d7bc6 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 12 Dec 2022 09:57:05 +0100 Subject: [PATCH 116/601] [maven-release-plugin] prepare for next development iteration --- error-prone-contrib/pom.xml | 2 +- pom.xml | 4 ++-- refaster-compiler/pom.xml | 2 +- refaster-runner/pom.xml | 2 +- refaster-support/pom.xml | 2 +- refaster-test-support/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index 4d7d6efa84..959208f32f 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.6.0 + 0.6.1-SNAPSHOT error-prone-contrib diff --git a/pom.xml b/pom.xml index bef3fd7d43..a68f9c58f5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ tech.picnic.error-prone-support error-prone-support - 0.6.0 + 0.6.1-SNAPSHOT pom Picnic :: Error Prone Support @@ -48,7 +48,7 @@ scm:git:git@github.com:PicnicSupermarket/error-prone-support.git - v0.6.0 + HEAD https://github.com/PicnicSupermarket/error-prone-support diff --git a/refaster-compiler/pom.xml b/refaster-compiler/pom.xml index 9ee26b9b12..001471cf80 100644 --- a/refaster-compiler/pom.xml +++ b/refaster-compiler/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.6.0 + 0.6.1-SNAPSHOT refaster-compiler diff --git a/refaster-runner/pom.xml b/refaster-runner/pom.xml index e39f59a805..c965a24640 100644 --- a/refaster-runner/pom.xml +++ b/refaster-runner/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.6.0 + 0.6.1-SNAPSHOT refaster-runner diff --git a/refaster-support/pom.xml b/refaster-support/pom.xml index bb6917a7c8..99da547a17 100644 --- a/refaster-support/pom.xml +++ b/refaster-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.6.0 + 0.6.1-SNAPSHOT refaster-support diff --git a/refaster-test-support/pom.xml b/refaster-test-support/pom.xml index 6320a23e12..c6c614b8ad 100644 --- a/refaster-test-support/pom.xml +++ b/refaster-test-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.6.0 + 0.6.1-SNAPSHOT refaster-test-support From 8d0f1d78e637802c8bbf1c73ed18fcaaa7ff2d24 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Tue, 13 Dec 2022 12:51:50 +0100 Subject: [PATCH 117/601] Upgrade Error Prone fork v2.16-picnic-1 -> v2.16-picnic-2 (#410) See: - https://github.com/PicnicSupermarket/error-prone/releases/tag/v2.16-picnic-2 - https://github.com/PicnicSupermarket/error-prone/compare/v2.16-picnic-1...v2.16-picnic-2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a68f9c58f5..adfe4e64df 100644 --- a/pom.xml +++ b/pom.xml @@ -148,7 +148,7 @@ 1.0.1 1.10.1 ${version.error-prone-orig} - v${version.error-prone-orig}-picnic-1 + v${version.error-prone-orig}-picnic-2 2.16 0.1.16 1.0 From bfbf748d477807df6e16205269deb9b720bf4964 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 13 Dec 2022 17:11:06 +0100 Subject: [PATCH 118/601] Upgrade SLF4J API 2.0.5 -> 2.0.6 (#409) See: - https://www.slf4j.org/news.html - https://github.com/qos-ch/slf4j/compare/v_2.0.5...v_2.0.6 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index adfe4e64df..eaf796aea4 100644 --- a/pom.xml +++ b/pom.xml @@ -377,7 +377,7 @@ org.slf4j slf4j-api - 2.0.5 + 2.0.6 org.springframework From 96114235c50217b09cb2e5dfd77b36d803ae614c Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 14 Dec 2022 07:18:40 +0100 Subject: [PATCH 119/601] Upgrade Project Reactor 2022.0.0 -> 2022.0.1 (#411) See: - https://github.com/reactor/reactor/releases/tag/2022.0.1 - https://github.com/reactor/reactor/compare/2022.0.0...2022.0.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index eaf796aea4..ccda990c9a 100644 --- a/pom.xml +++ b/pom.xml @@ -281,7 +281,7 @@ io.projectreactor reactor-bom - 2022.0.0 + 2022.0.1 pom import From 870d16a0b67b6cf334d1d1be0e38fe012af683be Mon Sep 17 00:00:00 2001 From: Guillaume Toison <86775455+gtoison@users.noreply.github.com> Date: Fri, 16 Dec 2022 08:40:05 +0000 Subject: [PATCH 120/601] Prevent `NestedOptionals` from throwing an NPE (#412) Previously, a `NullPointerException` was thrown if during compilation the `java.util.Optional` class was not loaded at all. --- .../errorprone/bugpatterns/NestedOptionals.java | 9 ++++++--- .../bugpatterns/NestedOptionalsTest.java | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedOptionals.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedOptionals.java index b736d5a050..8fe464fd09 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedOptionals.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedOptionals.java @@ -41,8 +41,11 @@ public NestedOptionals() {} @Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { - return state.getTypes().isSubtype(ASTHelpers.getType(tree), OPTIONAL_OF_OPTIONAL.get(state)) - ? describeMatch(tree) - : Description.NO_MATCH; + Type type = OPTIONAL_OF_OPTIONAL.get(state); + if (type == null || !state.getTypes().isSubtype(ASTHelpers.getType(tree), type)) { + return Description.NO_MATCH; + } + + return describeMatch(tree); } } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java index d5154cf554..5cebca69e5 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java @@ -39,4 +39,19 @@ void identification() { "}") .doTest(); } + + @Test + void identificationOptionalTypeNotLoaded() { + compilationTestHelper + .addSourceLines( + "A.java", + "import java.time.Duration;", + "", + "class A {", + " void m() {", + " Duration.ofSeconds(1);", + " }", + "}") + .doTest(); + } } From fd2946a9c8b8234227952ef7fbb0850752c9992b Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 19 Dec 2022 09:37:03 +0100 Subject: [PATCH 121/601] Disable failing JDK 20-ea build for now (#419) The build fails due to openjdk/jdk20@2cb64a75578ccc15a1dfc8c2843aa11d05ca8aa7; the upcoming Error Prone release includes a workaround for this: google/error-prone@df033f03cb55c3f26221660ac5ea49bbaeeab289. --- .github/workflows/build.yaml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 188450955e..738e11dfbc 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -22,10 +22,11 @@ jobs: jdk: 17.0.4 distribution: temurin experimental: false - - os: ubuntu-22.04 - jdk: 20-ea - distribution: zulu - experimental: true + # XXX: Re-enable this build after upgrading to Error Prone 2.17. + #- os: ubuntu-22.04 + # jdk: 20-ea + # distribution: zulu + # experimental: true runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.experimental }} steps: From 17aeeb9ea94a932bb86a5bde7ce852a59e7db063 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 19 Dec 2022 12:56:03 +0100 Subject: [PATCH 122/601] Upgrade versions-maven-plugin 2.13.0 -> 2.14.1 (#414) See: - https://github.com/mojohaus/versions/releases/tag/2.14.0 - https://github.com/mojohaus/versions/releases/tag/2.14.1 - https://github.com/mojohaus/versions-maven-plugin/compare/2.13.0...2.14.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ccda990c9a..66ad13c967 100644 --- a/pom.xml +++ b/pom.xml @@ -1197,7 +1197,7 @@ org.codehaus.mojo versions-maven-plugin - 2.13.0 + 2.14.1 never From ff2ed6f82cc8cface6f63829fb67eb8cc4520601 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 19 Dec 2022 13:14:50 +0100 Subject: [PATCH 123/601] Upgrade JSpecify 0.2.0 -> 0.3.0 (#415) See: - https://github.com/jspecify/jspecify/releases/tag/v0.3.0-alpha-1 - https://github.com/jspecify/jspecify/releases/tag/v0.3.0-alpha-2 - https://github.com/jspecify/jspecify/releases/tag/v0.3.0-alpha-3 - https://github.com/jspecify/jspecify/releases/tag/v0.3.0 - https://github.com/jspecify/jspecify/compare/v0.2.0...v0.3.0 --- .../bugpatterns/FormatStringConcatenation.java | 2 +- .../LexicographicalAnnotationAttributeListing.java | 2 +- .../bugpatterns/LexicographicalAnnotationListing.java | 2 +- .../tech/picnic/errorprone/bugpatterns/StringJoin.java | 2 +- .../picnic/errorprone/bugpatterns/package-info.java | 2 +- .../errorprone/bugpatterns/util/MoreJUnitMatchers.java | 2 +- .../errorprone/bugpatterns/util/package-info.java | 2 +- .../picnic/errorprone/refasterrules/AssortedRules.java | 5 +++-- .../tech/picnic/errorprone/refasterrules/MapRules.java | 8 +++++--- .../picnic/errorprone/refasterrules/MultimapRules.java | 5 +++-- .../picnic/errorprone/refasterrules/NullRules.java | 2 +- .../picnic/errorprone/refasterrules/OptionalRules.java | 2 +- .../picnic/errorprone/refasterrules/ReactorRules.java | 2 +- .../errorprone/refasterrules/RxJava2AdapterRules.java | 2 +- .../picnic/errorprone/refasterrules/StringRules.java | 2 +- .../picnic/errorprone/refasterrules/package-info.java | 2 +- .../errorprone/bugpatterns/RequestParamTypeTest.java | 2 +- pom.xml | 10 +++++----- .../plugin/RefasterRuleCompilerTaskListener.java | 2 +- .../errorprone/refaster/plugin/package-info.java | 2 +- .../errorprone/refaster/runner/package-info.java | 2 +- .../errorprone/refaster/annotation/package-info.java | 2 +- .../errorprone/refaster/matchers/package-info.java | 2 +- .../tech/picnic/errorprone/refaster/package-info.java | 2 +- .../refaster/matchers/AbstractMatcherTestChecker.java | 2 +- .../refaster/test/RefasterRuleCollection.java | 2 +- .../picnic/errorprone/refaster/test/package-info.java | 2 +- .../picnic/errorprone/refaster/test/ValidRules.java | 2 +- 28 files changed, 40 insertions(+), 36 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenation.java index a51ec69db9..4c8f1fdd4a 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenation.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenation.java @@ -32,7 +32,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.bugpatterns.util.SourceCode; /** diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java index baefb2fa34..28e5f51b40 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java @@ -40,7 +40,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Stream; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.bugpatterns.util.AnnotationAttributeMatcher; import tech.picnic.errorprone.bugpatterns.util.SourceCode; diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListing.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListing.java index 046d95e71d..01cd32f5e7 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListing.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListing.java @@ -27,7 +27,7 @@ import com.sun.tools.javac.code.TypeAnnotations.AnnotationType; import java.util.Comparator; import java.util.List; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.bugpatterns.util.SourceCode; /** diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java index f7d8f810b7..ff520704f3 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java @@ -27,7 +27,7 @@ import java.util.Formattable; import java.util.Iterator; import java.util.List; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.bugpatterns.util.SourceCode; /** diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/package-info.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/package-info.java index 08a3ad5ec2..7c79d4135e 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/package-info.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/package-info.java @@ -1,4 +1,4 @@ /** Picnic Error Prone Contrib checks. */ @com.google.errorprone.annotations.CheckReturnValue -@org.jspecify.nullness.NullMarked +@org.jspecify.annotations.NullMarked package tech.picnic.errorprone.bugpatterns; diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java index 59aacd1791..c26bda471f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java @@ -18,7 +18,7 @@ import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.MethodTree; import com.sun.source.tree.NewArrayTree; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; /** * A collection of JUnit-specific helper methods and {@link Matcher}s. diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/package-info.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/package-info.java index 280aa786d0..4b8726cede 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/package-info.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/package-info.java @@ -1,4 +1,4 @@ /** Auxiliary utilities for use by Error Prone checks. */ @com.google.errorprone.annotations.CheckReturnValue -@org.jspecify.nullness.NullMarked +@org.jspecify.annotations.NullMarked package tech.picnic.errorprone.bugpatterns.util; diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssortedRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssortedRules.java index 80d97c7b25..ff0cd1f17a 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssortedRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssortedRules.java @@ -24,7 +24,7 @@ import java.util.Objects; import java.util.Set; import java.util.stream.Stream; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; /** @@ -103,7 +103,8 @@ T before(Iterator iterator, T defaultValue) { } @AfterTemplate - @Nullable T after(Iterator iterator, T defaultValue) { + @Nullable + T after(Iterator iterator, T defaultValue) { return Iterators.getNext(iterator, defaultValue); } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java index 2d56fbbc76..cdf99f5e60 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java @@ -7,7 +7,7 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.Stream; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; /** Refaster rules related to expressions dealing with {@link Map} instances. */ @@ -31,12 +31,14 @@ Map after() { static final class MapGetOrNull { @BeforeTemplate - @Nullable V before(Map map, T key) { + @Nullable + V before(Map map, T key) { return map.getOrDefault(key, null); } @AfterTemplate - @Nullable V after(Map map, T key) { + @Nullable + V after(Map map, T key) { return map.get(key); } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MultimapRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MultimapRules.java index 0fba35943a..0e17d57f32 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MultimapRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MultimapRules.java @@ -7,7 +7,7 @@ import com.google.errorprone.refaster.annotation.BeforeTemplate; import java.util.Collection; import java.util.Set; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; /** Refaster rules related to expressions dealing with {@link Multimap}s. */ @@ -50,7 +50,8 @@ int after(Multimap multimap) { */ static final class MultimapGet { @BeforeTemplate - @Nullable Collection before(Multimap multimap, K key) { + @Nullable + Collection before(Multimap multimap, K key) { return Refaster.anyOf(multimap.asMap(), Multimaps.asMap(multimap)).get(key); } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/NullRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/NullRules.java index 823d82cea5..0a77f8c5e6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/NullRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/NullRules.java @@ -9,7 +9,7 @@ import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Objects; import java.util.function.Predicate; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; /** Refaster rules related to expressions dealing with (possibly) null values. */ diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java index a42a8198f2..676c7633e9 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java @@ -16,7 +16,7 @@ import java.util.function.Predicate; import java.util.function.Supplier; import java.util.stream.Stream; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; /** Refaster rules related to expressions dealing with {@link Optional}s. */ diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 52a3e5fdd8..40faa052f8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -27,7 +27,7 @@ import java.util.function.Function; import java.util.function.Predicate; import java.util.function.Supplier; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/RxJava2AdapterRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/RxJava2AdapterRules.java index ad75d06fc5..c2d2724dcd 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/RxJava2AdapterRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/RxJava2AdapterRules.java @@ -9,7 +9,7 @@ import io.reactivex.Maybe; import io.reactivex.Observable; import io.reactivex.Single; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import reactor.adapter.rxjava.RxJava2Adapter; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java index ec4f6c005b..4b403a02fb 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java @@ -16,7 +16,7 @@ import java.util.Objects; import java.util.Optional; import java.util.function.Function; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; /** Refaster rules related to expressions dealing with {@link String}s. */ diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/package-info.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/package-info.java index 3423a8048d..4a2bb28cd0 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/package-info.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/package-info.java @@ -1,4 +1,4 @@ /** Picnic Refaster rules. */ @com.google.errorprone.annotations.CheckReturnValue -@org.jspecify.nullness.NullMarked +@org.jspecify.annotations.NullMarked package tech.picnic.errorprone.refasterrules; diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java index 6dfc7fb329..45d58534c6 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java @@ -19,7 +19,7 @@ void identification() { "import java.util.List;", "import java.util.Map;", "import java.util.Set;", - "import org.jspecify.nullness.Nullable;", + "import org.jspecify.annotations.Nullable;", "import org.springframework.web.bind.annotation.DeleteMapping;", "import org.springframework.web.bind.annotation.GetMapping;", "import org.springframework.web.bind.annotation.PostMapping;", diff --git a/pom.xml b/pom.xml index 66ad13c967..ee60ff903f 100644 --- a/pom.xml +++ b/pom.xml @@ -358,7 +358,7 @@ org.jspecify jspecify - 0.2.0 + 0.3.0 org.junit @@ -611,15 +611,15 @@ + `org.jspecify.annotations.Nullable`. --> + `org.jspecify.annotations.Nullable`. --> + `org.jspecify.annotations.Nullable`. --> + `org.jspecify.annotations.Nullable`. --> diff --git a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java index f7bd2c2908..f62efde196 100644 --- a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java +++ b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/RefasterRuleCompilerTaskListener.java @@ -31,7 +31,7 @@ import javax.tools.FileObject; import javax.tools.JavaFileManager; import javax.tools.StandardLocation; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.refaster.AnnotatedCompositeCodeTransformer; /** diff --git a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/package-info.java b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/package-info.java index 4217cb239c..69a9593418 100644 --- a/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/package-info.java +++ b/refaster-compiler/src/main/java/tech/picnic/errorprone/refaster/plugin/package-info.java @@ -3,5 +3,5 @@ * files on the classpath. */ @com.google.errorprone.annotations.CheckReturnValue -@org.jspecify.nullness.NullMarked +@org.jspecify.annotations.NullMarked package tech.picnic.errorprone.refaster.plugin; diff --git a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java index f71089d3e1..04188c8a86 100644 --- a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java +++ b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/package-info.java @@ -1,4 +1,4 @@ /** Exposes Refaster rules found on the classpath through a regular Error Prone check. */ @com.google.errorprone.annotations.CheckReturnValue -@org.jspecify.nullness.NullMarked +@org.jspecify.annotations.NullMarked package tech.picnic.errorprone.refaster.runner; diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java index 99339a5c9f..b534085429 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/package-info.java @@ -4,5 +4,5 @@ * non-patch mode. */ @com.google.errorprone.annotations.CheckReturnValue -@org.jspecify.nullness.NullMarked +@org.jspecify.annotations.NullMarked package tech.picnic.errorprone.refaster.annotation; diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/package-info.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/package-info.java index 7a68fc5e30..0507845cc3 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/package-info.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/package-info.java @@ -5,5 +5,5 @@ * com.google.errorprone.refaster.annotation.NotMatches @NotMatches} annotations. */ @com.google.errorprone.annotations.CheckReturnValue -@org.jspecify.nullness.NullMarked +@org.jspecify.annotations.NullMarked package tech.picnic.errorprone.refaster.matchers; diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/package-info.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/package-info.java index 99bd0885b7..edb92bf1e4 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/package-info.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/package-info.java @@ -1,4 +1,4 @@ /** Assorted classes that aid the compilation or evaluation of Refaster rules. */ @com.google.errorprone.annotations.CheckReturnValue -@org.jspecify.nullness.NullMarked +@org.jspecify.annotations.NullMarked package tech.picnic.errorprone.refaster; diff --git a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java index b1370b519d..9449b8169c 100644 --- a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java +++ b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java @@ -11,7 +11,7 @@ import com.sun.source.tree.MethodTree; import com.sun.source.tree.Tree; import com.sun.source.util.TreeScanner; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; /** * An abstract {@link BugChecker} that reports a match for each expression matched by the given diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java index 45a734cea6..588077a10e 100644 --- a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java @@ -44,7 +44,7 @@ import java.util.Optional; import java.util.Set; import java.util.regex.Pattern; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.refaster.runner.CodeTransformers; import tech.picnic.errorprone.refaster.runner.Refaster; diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/package-info.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/package-info.java index cce5279378..c4b7c62d9f 100644 --- a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/package-info.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/package-info.java @@ -1,4 +1,4 @@ /** Opinionated utilities for the testing of Refaster rules. */ @com.google.errorprone.annotations.CheckReturnValue -@org.jspecify.nullness.NullMarked +@org.jspecify.annotations.NullMarked package tech.picnic.errorprone.refaster.test; diff --git a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/ValidRules.java b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/ValidRules.java index 1d6c2359c9..45921ca60b 100644 --- a/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/ValidRules.java +++ b/refaster-test-support/src/test/java/tech/picnic/errorprone/refaster/test/ValidRules.java @@ -8,7 +8,7 @@ import com.google.errorprone.refaster.annotation.Placeholder; import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Set; -import org.jspecify.nullness.Nullable; +import org.jspecify.annotations.Nullable; /** Refaster rule collection to validate that having no violations works as expected. */ final class ValidRules { From e9ae238c2b91a54a84a923e6335f8a9d6c0ab0fc Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 19 Dec 2022 13:52:49 +0100 Subject: [PATCH 124/601] Upgrade Mockito 4.9.0 -> 4.10.0 (#416) See: - https://github.com/mockito/mockito/releases/tag/v4.10.0 - https://github.com/mockito/mockito/compare/v4.9.0...v4.10.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ee60ff903f..f917e4d7a9 100644 --- a/pom.xml +++ b/pom.xml @@ -154,7 +154,7 @@ 1.0 11 3.8.6 - 4.9.0 + 4.10.0 1.0.1 0.10.5 1.0.3 From 8724701baf0909a533d4530bc168f3153b0443f2 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 19 Dec 2022 14:12:40 +0100 Subject: [PATCH 125/601] Upgrade Immutables Annotations 2.9.2 -> 2.9.3 (#413) See: - https://github.com/immutables/immutables/releases/tag/2.9.3 - https://github.com/immutables/immutables/compare/2.9.2...2.9.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f917e4d7a9..6dcd838e72 100644 --- a/pom.xml +++ b/pom.xml @@ -353,7 +353,7 @@ org.immutables value-annotations - 2.9.2 + 2.9.3 org.jspecify From 7c40fdc033c2a05892a34cdc4b569d5225d6d58f Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 19 Dec 2022 21:02:39 +0100 Subject: [PATCH 126/601] Upgrade Arcmutate 1.0.1 -> 1.0.2 (#418) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6dcd838e72..933950cbfb 100644 --- a/pom.xml +++ b/pom.xml @@ -1270,7 +1270,7 @@ com.groupcdg.arcmutate base - 1.0.1 + 1.0.2 com.groupcdg.pitest From d0a89da24dab83840fbbd10fba1ac077c7994410 Mon Sep 17 00:00:00 2001 From: EvgheniiShipilov Date: Tue, 20 Dec 2022 11:14:46 +0100 Subject: [PATCH 127/601] Have `IdentityConversion` flag `com.google.errorprone.matchers.Matchers#{allOf,anyOf}` (#420) While there, sort and rename some (test) code. Fixes #340. --- .../bugpatterns/IdentityConversion.java | 17 +++--- .../bugpatterns/IdentityConversionTest.java | 57 +++++++++++++------ 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java index 00d6d9bdcb..c99b496d32 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java @@ -32,7 +32,7 @@ /** A {@link BugChecker} that flags redundant identity conversions. */ // XXX: Consider detecting cases where a flagged expression is passed to a method, and where removal -// of the identify conversion would cause a different method overload to be selected. Depending on +// of the identity conversion would cause a different method overload to be selected. Depending on // the target method such a modification may change the code's semantics or performance. @AutoService(BugChecker.class) @BugPattern( @@ -45,6 +45,13 @@ public final class IdentityConversion extends BugChecker implements MethodInvoca private static final long serialVersionUID = 1L; private static final Matcher IS_CONVERSION_METHOD = anyOf( + staticMethod() + .onClassAny( + Primitives.allWrapperTypes().stream() + .map(Class::getName) + .collect(toImmutableSet())) + .named("valueOf"), + staticMethod().onClass(String.class.getName()).named("valueOf"), staticMethod() .onClassAny( "com.google.common.collect.ImmutableBiMap", @@ -60,12 +67,8 @@ public final class IdentityConversion extends BugChecker implements MethodInvoca "com.google.common.collect.ImmutableTable") .named("copyOf"), staticMethod() - .onClassAny( - Primitives.allWrapperTypes().stream() - .map(Class::getName) - .collect(toImmutableSet())) - .named("valueOf"), - staticMethod().onClass(String.class.getName()).named("valueOf"), + .onClass("com.google.errorprone.matchers.Matchers") + .namedAnyOf("allOf", "anyOf"), staticMethod().onClass("reactor.adapter.rxjava.RxJava2Adapter"), staticMethod() .onClass("reactor.core.publisher.Flux") diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java index a8f867502a..baa74babdc 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java @@ -16,7 +16,10 @@ final class IdentityConversionTest { void identification() { compilationTestHelper .addSourceLines( - "Foo.java", + "A.java", + "import static com.google.errorprone.matchers.Matchers.instanceMethod;", + "import static com.google.errorprone.matchers.Matchers.staticMethod;", + "", "import com.google.common.collect.ImmutableBiMap;", "import com.google.common.collect.ImmutableList;", "import com.google.common.collect.ImmutableListMultimap;", @@ -28,12 +31,14 @@ void identification() { "import com.google.common.collect.ImmutableSet;", "import com.google.common.collect.ImmutableSetMultimap;", "import com.google.common.collect.ImmutableTable;", + "import com.google.errorprone.matchers.Matcher;", + "import com.google.errorprone.matchers.Matchers;", "import reactor.adapter.rxjava.RxJava2Adapter;", "import reactor.core.publisher.Flux;", "import reactor.core.publisher.Mono;", "", - "public final class Foo {", - " public void foo() {", + "public final class A {", + " public void m() {", " // BUG: Diagnostic contains:", " Boolean b1 = Boolean.valueOf(Boolean.FALSE);", " // BUG: Diagnostic contains:", @@ -143,7 +148,15 @@ void identification() { " ImmutableTable o11 = ImmutableTable.copyOf(ImmutableTable.of());", "", " // BUG: Diagnostic contains:", + " Matcher allOf1 = Matchers.allOf(instanceMethod());", + " Matcher allOf2 = Matchers.allOf(instanceMethod(), staticMethod());", + " // BUG: Diagnostic contains:", + " Matcher anyOf1 = Matchers.anyOf(staticMethod());", + " Matcher anyOf2 = Matchers.anyOf(instanceMethod(), staticMethod());", + "", + " // BUG: Diagnostic contains:", " Flux flux1 = Flux.just(1).flatMap(e -> RxJava2Adapter.fluxToFlowable(Flux.just(2)));", + "", " // BUG: Diagnostic contains:", " Flux flux2 = Flux.concat(Flux.just(1));", " // BUG: Diagnostic contains:", @@ -154,9 +167,9 @@ void identification() { " Flux flux5 = Flux.merge(Flux.just(1));", "", " // BUG: Diagnostic contains:", - " Mono m1 = Mono.from(Mono.just(1));", + " Mono mono1 = Mono.from(Mono.just(1));", " // BUG: Diagnostic contains:", - " Mono m2 = Mono.fromDirect(Mono.just(1));", + " Mono mono2 = Mono.fromDirect(Mono.just(1));", " }", "}") .doTest(); @@ -167,12 +180,15 @@ void replacementFirstSuggestedFix() { refactoringTestHelper .setFixChooser(FixChoosers.FIRST) .addInputLines( - "Foo.java", + "A.java", + "import static com.google.errorprone.matchers.Matchers.staticMethod;", "import static org.mockito.Mockito.when;", "", "import com.google.common.collect.ImmutableCollection;", "import com.google.common.collect.ImmutableList;", "import com.google.common.collect.ImmutableSet;", + "import com.google.errorprone.matchers.Matcher;", + "import com.google.errorprone.matchers.Matchers;", "import java.util.ArrayList;", "import java.util.Collection;", "import org.reactivestreams.Publisher;", @@ -180,8 +196,8 @@ void replacementFirstSuggestedFix() { "import reactor.core.publisher.Flux;", "import reactor.core.publisher.Mono;", "", - "public final class Foo {", - " public void foo() {", + "public final class A {", + " public void m() {", " ImmutableSet set1 = ImmutableSet.copyOf(ImmutableSet.of());", " ImmutableSet set2 = ImmutableSet.copyOf(ImmutableList.of());", "", @@ -206,18 +222,23 @@ void replacementFirstSuggestedFix() { " Object o1 = ImmutableSet.copyOf(ImmutableList.of());", " Object o2 = ImmutableSet.copyOf(ImmutableSet.of());", "", + " Matcher matcher = Matchers.allOf(staticMethod());", + "", " when(\"foo\".contains(\"f\")).thenAnswer(inv -> ImmutableSet.copyOf(ImmutableList.of(1)));", " }", "", " void bar(Publisher publisher) {}", "}") .addOutputLines( - "Foo.java", + "A.java", + "import static com.google.errorprone.matchers.Matchers.staticMethod;", "import static org.mockito.Mockito.when;", "", "import com.google.common.collect.ImmutableCollection;", "import com.google.common.collect.ImmutableList;", "import com.google.common.collect.ImmutableSet;", + "import com.google.errorprone.matchers.Matcher;", + "import com.google.errorprone.matchers.Matchers;", "import java.util.ArrayList;", "import java.util.Collection;", "import org.reactivestreams.Publisher;", @@ -225,8 +246,8 @@ void replacementFirstSuggestedFix() { "import reactor.core.publisher.Flux;", "import reactor.core.publisher.Mono;", "", - "public final class Foo {", - " public void foo() {", + "public final class A {", + " public void m() {", " ImmutableSet set1 = ImmutableSet.of();", " ImmutableSet set2 = ImmutableSet.copyOf(ImmutableList.of());", "", @@ -251,6 +272,8 @@ void replacementFirstSuggestedFix() { " Object o1 = ImmutableSet.copyOf(ImmutableList.of());", " Object o2 = ImmutableSet.of();", "", + " Matcher matcher = staticMethod();", + "", " when(\"foo\".contains(\"f\")).thenAnswer(inv -> ImmutableSet.copyOf(ImmutableList.of(1)));", " }", "", @@ -264,14 +287,14 @@ void replacementSecondSuggestedFix() { refactoringTestHelper .setFixChooser(FixChoosers.SECOND) .addInputLines( - "Foo.java", + "A.java", "import com.google.common.collect.ImmutableCollection;", "import com.google.common.collect.ImmutableList;", "import com.google.common.collect.ImmutableSet;", "import java.util.ArrayList;", "", - "public final class Foo {", - " public void foo() {", + "public final class A {", + " public void m() {", " ImmutableSet set1 = ImmutableSet.copyOf(ImmutableSet.of());", " ImmutableSet set2 = ImmutableSet.copyOf(ImmutableList.of());", "", @@ -280,14 +303,14 @@ void replacementSecondSuggestedFix() { " }", "}") .addOutputLines( - "Foo.java", + "A.java", "import com.google.common.collect.ImmutableCollection;", "import com.google.common.collect.ImmutableList;", "import com.google.common.collect.ImmutableSet;", "import java.util.ArrayList;", "", - "public final class Foo {", - " public void foo() {", + "public final class A {", + " public void m() {", " @SuppressWarnings(\"IdentityConversion\")", " ImmutableSet set1 = ImmutableSet.copyOf(ImmutableSet.of());", " ImmutableSet set2 = ImmutableSet.copyOf(ImmutableList.of());", From 5665470fe4b6b2cc63ecf6aa4b8710a2649785f1 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 21 Dec 2022 09:44:30 +0100 Subject: [PATCH 128/601] Improve `IdentityConversion` check (#407) If the result of an explicit boxing operation is immediately dereferenced, then the explicit conversion operation is not redundant. --- .../errorprone/bugpatterns/IdentityConversion.java | 10 ++++++++++ .../errorprone/bugpatterns/IdentityConversionTest.java | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java index c99b496d32..f6522ab3df 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java @@ -23,6 +23,7 @@ import com.google.errorprone.util.ASTHelpers; import com.google.errorprone.util.ASTHelpers.TargetType; import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.MemberSelectTree; import com.sun.source.tree.MethodInvocationTree; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Types; @@ -98,6 +99,15 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState return Description.NO_MATCH; } + if (sourceType.isPrimitive() + && state.getPath().getParentPath().getLeaf() instanceof MemberSelectTree) { + /* + * The result of the conversion method is dereferenced, while the source type is a primitive: + * dropping the conversion would yield uncompilable code. + */ + return Description.NO_MATCH; + } + return buildDescription(tree) .setMessage( "This method invocation appears redundant; remove it or suppress this warning and " diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java index baa74babdc..03d6c3fd72 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java @@ -118,6 +118,13 @@ void identification() { " // BUG: Diagnostic contains:", " short s4 = Short.valueOf(Short.MIN_VALUE);", "", + " // BUG: Diagnostic contains:", + " String boolStr = Boolean.valueOf(Boolean.FALSE).toString();", + " int boolHash = Boolean.valueOf(false).hashCode();", + " // BUG: Diagnostic contains:", + " int byteHash = Byte.valueOf((Byte) Byte.MIN_VALUE).hashCode();", + " String byteStr = Byte.valueOf(Byte.MIN_VALUE).toString();", + "", " String str1 = String.valueOf(0);", " // BUG: Diagnostic contains:", " String str2 = String.valueOf(\"1\");", From 6313bd56d8370720c79669d4fa041876d30fd0fa Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Thu, 22 Dec 2022 08:34:11 +0100 Subject: [PATCH 129/601] Improve `JUnitMethodDeclaration` check (#406) Implemented changes: - Ignore method overrides even if not annotated with `@Override`. - Don't rename methods to `true`, `false` or `null`. - Don't rename methods to a name declared in a super type. This prevents e.g. renaming `testToString` to `toString`. --- .../bugpatterns/JUnitMethodDeclaration.java | 66 +++++++++++-------- .../bugpatterns/util/JavaKeywords.java | 30 ++++++++- .../JUnitMethodDeclarationTest.java | 57 +++++++++++++++- .../bugpatterns/util/JavaKeywordsTest.java | 34 ++++++++++ 4 files changed, 155 insertions(+), 32 deletions(-) create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/JavaKeywordsTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitMethodDeclaration.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitMethodDeclaration.java index 5b9a67388e..20afd2fc96 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitMethodDeclaration.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitMethodDeclaration.java @@ -3,21 +3,19 @@ import static com.google.errorprone.BugPattern.LinkType.CUSTOM; import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; import static com.google.errorprone.BugPattern.StandardTags.SIMPLIFICATION; -import static com.google.errorprone.matchers.ChildMultiMatcher.MatchType.AT_LEAST_ONE; import static com.google.errorprone.matchers.Matchers.allOf; -import static com.google.errorprone.matchers.Matchers.annotations; -import static com.google.errorprone.matchers.Matchers.anyOf; import static com.google.errorprone.matchers.Matchers.enclosingClass; import static com.google.errorprone.matchers.Matchers.hasModifier; -import static com.google.errorprone.matchers.Matchers.isType; +import static com.google.errorprone.matchers.Matchers.not; import static java.util.function.Predicate.not; import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; -import static tech.picnic.errorprone.bugpatterns.util.JavaKeywords.isReservedKeyword; +import static tech.picnic.errorprone.bugpatterns.util.JavaKeywords.isValidIdentifier; import static tech.picnic.errorprone.bugpatterns.util.MoreJUnitMatchers.SETUP_OR_TEARDOWN_METHOD; import static tech.picnic.errorprone.bugpatterns.util.MoreJUnitMatchers.TEST_METHOD; import com.google.auto.service.AutoService; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; import com.google.errorprone.BugPattern; import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.BugChecker; @@ -26,14 +24,15 @@ import com.google.errorprone.fixes.SuggestedFixes; import com.google.errorprone.matchers.Description; import com.google.errorprone.matchers.Matcher; -import com.google.errorprone.matchers.Matchers; import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.ImportTree; import com.sun.source.tree.MethodTree; import com.sun.source.tree.Tree; +import com.sun.tools.javac.code.Symbol; +import com.sun.tools.javac.code.Symbol.MethodSymbol; +import com.sun.tools.javac.code.Type; import java.util.Optional; import javax.lang.model.element.Modifier; -import tech.picnic.errorprone.bugpatterns.util.MoreASTHelpers; import tech.picnic.errorprone.bugpatterns.util.SourceCode; /** A {@link BugChecker} that flags non-canonical JUnit method declarations. */ @@ -53,21 +52,19 @@ public final class JUnitMethodDeclaration extends BugChecker implements MethodTr private static final long serialVersionUID = 1L; private static final String TEST_PREFIX = "test"; private static final ImmutableSet ILLEGAL_MODIFIERS = - ImmutableSet.of(Modifier.PRIVATE, Modifier.PROTECTED, Modifier.PUBLIC); - private static final Matcher HAS_UNMODIFIABLE_SIGNATURE = - anyOf( - annotations(AT_LEAST_ONE, isType("java.lang.Override")), - allOf( - Matchers.not(hasModifier(Modifier.FINAL)), - Matchers.not(hasModifier(Modifier.PRIVATE)), - enclosingClass(hasModifier(Modifier.ABSTRACT)))); + Sets.immutableEnumSet(Modifier.PRIVATE, Modifier.PROTECTED, Modifier.PUBLIC); + private static final Matcher IS_LIKELY_OVERRIDDEN = + allOf( + not(hasModifier(Modifier.FINAL)), + not(hasModifier(Modifier.PRIVATE)), + enclosingClass(hasModifier(Modifier.ABSTRACT))); /** Instantiates a new {@link JUnitMethodDeclaration} instance. */ public JUnitMethodDeclaration() {} @Override public Description matchMethod(MethodTree tree, VisitorState state) { - if (HAS_UNMODIFIABLE_SIGNATURE.matches(tree, state)) { + if (IS_LIKELY_OVERRIDDEN.matches(tree, state) || isOverride(tree, state)) { return Description.NO_MATCH; } @@ -89,10 +86,11 @@ public Description matchMethod(MethodTree tree, VisitorState state) { private void suggestTestMethodRenameIfApplicable( MethodTree tree, SuggestedFix.Builder fixBuilder, VisitorState state) { - tryCanonicalizeMethodName(tree) + MethodSymbol symbol = ASTHelpers.getSymbol(tree); + tryCanonicalizeMethodName(symbol) .ifPresent( newName -> - findMethodRenameBlocker(newName, state) + findMethodRenameBlocker(symbol, newName, state) .ifPresentOrElse( blocker -> reportMethodRenameBlocker(tree, blocker, state), () -> fixBuilder.merge(SuggestedFixes.renameMethod(tree, newName, state)))); @@ -124,23 +122,31 @@ private void reportMethodRenameBlocker(MethodTree tree, String reason, VisitorSt * consideration cannot be referenced directly.) * */ - private static Optional findMethodRenameBlocker(String methodName, VisitorState state) { - if (MoreASTHelpers.methodExistsInEnclosingClass(methodName, state)) { + private static Optional findMethodRenameBlocker( + MethodSymbol method, String newName, VisitorState state) { + if (isExistingMethodName(method.owner.type, newName, state)) { return Optional.of( - String.format("a method named `%s` already exists in this class", methodName)); + String.format( + "a method named `%s` is already defined in this class or a supertype", newName)); } - if (isSimpleNameStaticallyImported(methodName, state)) { - return Optional.of(String.format("`%s` is already statically imported", methodName)); + if (isSimpleNameStaticallyImported(newName, state)) { + return Optional.of(String.format("`%s` is already statically imported", newName)); } - if (isReservedKeyword(methodName)) { - return Optional.of(String.format("`%s` is a reserved keyword", methodName)); + if (!isValidIdentifier(newName)) { + return Optional.of(String.format("`%s` is not a valid identifier", newName)); } return Optional.empty(); } + private static boolean isExistingMethodName(Type clazz, String name, VisitorState state) { + return ASTHelpers.matchingMethods(state.getName(name), method -> true, clazz, state.getTypes()) + .findAny() + .isPresent(); + } + private static boolean isSimpleNameStaticallyImported(String simpleName, VisitorState state) { return state.getPath().getCompilationUnit().getImports().stream() .filter(ImportTree::isStatic) @@ -154,12 +160,18 @@ private static CharSequence getStaticImportSimpleName(Tree tree, VisitorState st return source.subSequence(source.lastIndexOf('.') + 1, source.length()); } - private static Optional tryCanonicalizeMethodName(MethodTree tree) { - return Optional.of(ASTHelpers.getSymbol(tree).getQualifiedName().toString()) + private static Optional tryCanonicalizeMethodName(Symbol symbol) { + return Optional.of(symbol.getQualifiedName().toString()) .filter(name -> name.startsWith(TEST_PREFIX)) .map(name -> name.substring(TEST_PREFIX.length())) .filter(not(String::isEmpty)) .map(name -> Character.toLowerCase(name.charAt(0)) + name.substring(1)) .filter(name -> !Character.isDigit(name.charAt(0))); } + + private static boolean isOverride(MethodTree tree, VisitorState state) { + return ASTHelpers.streamSuperMethods(ASTHelpers.getSymbol(tree), state.getTypes()) + .findAny() + .isPresent(); + } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/JavaKeywords.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/JavaKeywords.java index afb7a2985c..e9e70515c8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/JavaKeywords.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/JavaKeywords.java @@ -4,7 +4,19 @@ import com.google.common.collect.Sets; /** Utility class that can be used to identify reserved keywords of the Java language. */ +// XXX: This class is no longer only about keywords. Consider changing its name and class-level +// documentation. public final class JavaKeywords { + /** + * Enumeration of boolean and null literals. + * + * @see JDK 17 + * JLS section 3.10.3: Boolean Literals + * @see JDK 17 + * JLS section 3.10.8: The Null Literal + */ + private static final ImmutableSet BOOLEAN_AND_NULL_LITERALS = + ImmutableSet.of("true", "false", "null"); /** * List of all reserved keywords in the Java language. * @@ -64,7 +76,6 @@ public final class JavaKeywords { "void", "volatile", "while"); - /** * List of all contextual keywords in the Java language. * @@ -89,13 +100,28 @@ public final class JavaKeywords { "var", "with", "yield"); - /** List of all keywords in the Java language. */ private static final ImmutableSet ALL_KEYWORDS = Sets.union(RESERVED_KEYWORDS, CONTEXTUAL_KEYWORDS).immutableCopy(); private JavaKeywords() {} + /** + * Tells whether the given string is a valid identifier in the Java language. + * + * @param str The string of interest. + * @return {@code true} if the given string is a valid identifier in the Java language. + * @see JDK 17 JLS + * section 3.8: Identifiers + */ + public static boolean isValidIdentifier(String str) { + return !str.isEmpty() + && !isReservedKeyword(str) + && !BOOLEAN_AND_NULL_LITERALS.contains(str) + && Character.isJavaIdentifierStart(str.codePointAt(0)) + && str.codePoints().skip(1).allMatch(Character::isUnicodeIdentifierPart); + } + /** * Tells whether the given string is a reserved keyword in the Java language. * diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitMethodDeclarationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitMethodDeclarationTest.java index 2320daf7c9..92f2e16b8f 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitMethodDeclarationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitMethodDeclarationTest.java @@ -91,6 +91,9 @@ void identification() { " private void tearDown8() {}", "", " @Test", + " void test() {}", + "", + " @Test", " void method1() {}", "", " @Test", @@ -144,8 +147,13 @@ void identification() { " void test5() {}", "", " @Test", - " // BUG: Diagnostic contains: (but note that a method named `overload` already exists in this", - " // class)", + " // BUG: Diagnostic contains: (but note that a method named `toString` is already defined in this", + " // class or a supertype)", + " void testToString() {}", + "", + " @Test", + " // BUG: Diagnostic contains: (but note that a method named `overload` is already defined in this", + " // class or a supertype)", " void testOverload() {}", "", " void overload() {}", @@ -155,8 +163,20 @@ void identification() { " void testArguments() {}", "", " @Test", - " // BUG: Diagnostic contains: (but note that `public` is a reserved keyword)", + " // BUG: Diagnostic contains: (but note that `public` is not a valid identifier)", " void testPublic() {}", + "", + " @Test", + " // BUG: Diagnostic contains: (but note that `null` is not a valid identifier)", + " void testNull() {}", + "", + " @Test", + " // BUG: Diagnostic contains:", + " void testRecord() {}", + "", + " @Test", + " // BUG: Diagnostic contains:", + " void testMethodThatIsOverriddenWithoutOverrideAnnotation() {}", "}") .addSourceLines( "B.java", @@ -218,6 +238,10 @@ void identification() { "", " @Override", " @Test", + " void test() {}", + "", + " @Override", + " @Test", " void method1() {}", "", " @Override", @@ -267,6 +291,10 @@ void identification() { "", " @Override", " @Test", + " void testToString() {}", + "", + " @Override", + " @Test", " void testOverload() {}", "", " @Override", @@ -279,6 +307,17 @@ void identification() { " @Override", " @Test", " void testPublic() {}", + "", + " @Override", + " @Test", + " void testNull() {}", + "", + " @Override", + " @Test", + " void testRecord() {}", + "", + " @Test", + " void testMethodThatIsOverriddenWithoutOverrideAnnotation() {}", "}") .addSourceLines( "C.java", @@ -352,6 +391,9 @@ void replacement() { " protected void quux() {}", "", " @Test", + " public void testToString() {}", + "", + " @Test", " public void testOverload() {}", "", " void overload() {}", @@ -361,6 +403,9 @@ void replacement() { "", " @Test", " private void testClass() {}", + "", + " @Test", + " private void testTrue() {}", "}") .addOutputLines( "A.java", @@ -407,6 +452,9 @@ void replacement() { " void quux() {}", "", " @Test", + " void testToString() {}", + "", + " @Test", " void testOverload() {}", "", " void overload() {}", @@ -416,6 +464,9 @@ void replacement() { "", " @Test", " void testClass() {}", + "", + " @Test", + " void testTrue() {}", "}") .doTest(TestMode.TEXT_MATCH); } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/JavaKeywordsTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/JavaKeywordsTest.java new file mode 100644 index 0000000000..4f4b6a8664 --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/JavaKeywordsTest.java @@ -0,0 +1,34 @@ +package tech.picnic.errorprone.bugpatterns.util; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; + +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +final class JavaKeywordsTest { + private static Stream isValidIdentifierTestCases() { + /* { str, expected } */ + return Stream.of( + arguments("", false), + arguments("public", false), + arguments("true", false), + arguments("false", false), + arguments("null", false), + arguments("0", false), + arguments("\0", false), + arguments("a%\0", false), + arguments("a", true), + arguments("a0", true), + arguments("_a0", true), + arguments("test", true)); + } + + @MethodSource("isValidIdentifierTestCases") + @ParameterizedTest + void isValidIdentifier(String str, boolean expected) { + assertThat(JavaKeywords.isValidIdentifier(str)).isEqualTo(expected); + } +} From ecb8820d8005574ec6290a14a3f17a24589e9e38 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 27 Dec 2022 06:38:04 +0100 Subject: [PATCH 130/601] Upgrade versions-maven-plugin 2.14.1 -> 2.14.2 (#424) See: - https://github.com/mojohaus/versions/releases/tag/2.14.2 - https://github.com/mojohaus/versions-maven-plugin/compare/2.14.1...2.14.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 933950cbfb..e35bff4669 100644 --- a/pom.xml +++ b/pom.xml @@ -1197,7 +1197,7 @@ org.codehaus.mojo versions-maven-plugin - 2.14.1 + 2.14.2 never From 165a003f6ae841355ebecd44fcd1ef86eabd967a Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 27 Dec 2022 08:34:41 +0100 Subject: [PATCH 131/601] Upgrade Spring Boot 2.7.6 -> 2.7.7 (#423) See: - https://github.com/spring-projects/spring-boot/releases/tag/v2.7.7 - https://github.com/spring-projects/spring-boot/compare/v2.7.6...v2.7.7 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e35bff4669..da4e0de9a9 100644 --- a/pom.xml +++ b/pom.xml @@ -389,7 +389,7 @@ org.springframework.boot spring-boot-test - 2.7.6 + 2.7.7 org.testng From b22078657af33173b19ca3df9ffbdaa9d74eecd9 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 27 Dec 2022 08:51:16 +0100 Subject: [PATCH 132/601] Upgrade AspectJ 1.9.9.1 -> 1.9.19 (#422) See: - https://github.com/eclipse/org.aspectj/releases/tag/V1_9_19 - https://github.com/eclipse/org.aspectj/compare/V1_9_9_1...V1_9_19 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index da4e0de9a9..a88859fb35 100644 --- a/pom.xml +++ b/pom.xml @@ -333,7 +333,7 @@ org.aspectj aspectjweaver - 1.9.9.1 + 1.9.19 org.assertj From 27c6c48e68f57835a10ee7aade920b5e32a79dd9 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 29 Dec 2022 08:02:16 +0100 Subject: [PATCH 133/601] Upgrade Mockito 4.10.0 -> 4.11.0 (#427) See: - https://github.com/mockito/mockito/releases/tag/v4.11.0 - https://github.com/mockito/mockito/compare/v4.10.0...v4.11.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a88859fb35..7fcac36621 100644 --- a/pom.xml +++ b/pom.xml @@ -154,7 +154,7 @@ 1.0 11 3.8.6 - 4.10.0 + 4.11.0 1.0.1 0.10.5 1.0.3 From 601fcf26489a91b0df01848d0d207df13a48d870 Mon Sep 17 00:00:00 2001 From: Pieter Dirk Soels Date: Fri, 30 Dec 2022 08:46:27 +0100 Subject: [PATCH 134/601] Update website styling and add Google site verification (#408) --- website/README.md | 4 ++++ website/_config.yml | 6 ++++++ website/_includes/footer_custom.html | 4 ++-- website/_includes/head_custom.html | 12 ++++++------ website/_sass/color_schemes/_common.scss | 17 ++++++++++++++++- website/_sass/color_schemes/_variables.scss | 4 ++++ website/_sass/color_schemes/eps-dark.scss | 13 +++++++++++++ 7 files changed, 51 insertions(+), 9 deletions(-) diff --git a/website/README.md b/website/README.md index b9d0f9833a..a8fe96535e 100644 --- a/website/README.md +++ b/website/README.md @@ -24,6 +24,9 @@ If you are not familiar with Jekyll, be sure to check out its [documentation][jekyll-docs]. It is recommended to follow the provided step-by-step tutorial. +We use the [Just the Docs][just-the-docs] Jekyll theme, which also includes +several configuration options. + ###### Switch Ruby versions The required Ruby version is set in `.ruby-version`. To switch, you can use @@ -56,5 +59,6 @@ Actions workflow any time a change is merged to `master`. [jekyll]: https://jekyllrb.com [jekyll-docs]: https://jekyllrb.com/docs [jekyll-docs-installation]: https://jekyllrb.com/docs/installation +[just-the-docs]: https://just-the-docs.github.io/just-the-docs/ [localhost-port-4000]: http://127.0.0.1:4000 [rvm]: https://rvm.io diff --git a/website/_config.yml b/website/_config.yml index c1f90f5a02..46422b4a99 100644 --- a/website/_config.yml +++ b/website/_config.yml @@ -28,6 +28,12 @@ nav_external_links: url: https://github.com/PicnicSupermarket/error-prone-support hide_icon: false +callouts: + summary: + color: blue + note: + color: grey-dk + # SEO configuration. # See https://jekyll.github.io/jekyll-seo-tag/usage. social: diff --git a/website/_includes/footer_custom.html b/website/_includes/footer_custom.html index 156df3e228..1f18ad553c 100644 --- a/website/_includes/footer_custom.html +++ b/website/_includes/footer_custom.html @@ -1,5 +1,5 @@ - + -

+

Copyright © 2017-2022 Picnic Technologies BV

diff --git a/website/_includes/head_custom.html b/website/_includes/head_custom.html index 74b77b7772..e3033725a8 100644 --- a/website/_includes/head_custom.html +++ b/website/_includes/head_custom.html @@ -4,15 +4,15 @@ - - + + media="(prefers-color-scheme: light)"> + media="(prefers-color-scheme: dark)"> + + diff --git a/website/_sass/color_schemes/_common.scss b/website/_sass/color_schemes/_common.scss index 477b57bec3..f004a964e4 100644 --- a/website/_sass/color_schemes/_common.scss +++ b/website/_sass/color_schemes/_common.scss @@ -1,5 +1,20 @@ -footer > img#logo { +// Add support for external anchor icons. +.external > svg { + width: 1rem; + vertical-align: text-bottom; +} + +.label { + // Reduce spacing between labels and align with surrounding elements. + margin-left: 0 !important; +} + +footer { + text-align: center; + + img#logo { width: 2rem; margin: 0 auto; display: block; + } } diff --git a/website/_sass/color_schemes/_variables.scss b/website/_sass/color_schemes/_variables.scss index fb0a8addf8..fe5b768382 100644 --- a/website/_sass/color_schemes/_variables.scss +++ b/website/_sass/color_schemes/_variables.scss @@ -1 +1,5 @@ +// Overrides for Just the Docs. See +// https://github.com/just-the-docs/just-the-docs/blob/main/_sass/support/_variables.scss. + +// Grid system. $nav-width: 400px; diff --git a/website/_sass/color_schemes/eps-dark.scss b/website/_sass/color_schemes/eps-dark.scss index 67cf318f23..849dd884d8 100644 --- a/website/_sass/color_schemes/eps-dark.scss +++ b/website/_sass/color_schemes/eps-dark.scss @@ -1,3 +1,16 @@ @import "./color_schemes/dark"; @import "_variables"; @import "_common"; + +// Swap `$blue-000` and `$blue-300`, mainly for callouts. This is done by +// default for red, but not for other colors. +$blue-000: #183385; +$blue-300: #2c84fa; + +// Use light-theme greys in dark theme so that summary callouts stand out more. +// (Note that the former has four shades, while the latter has five.) +$grey-dk-000: $grey-lt-000; +$grey-dk-100: $grey-lt-100; +$grey-dk-200: $grey-lt-200; +$grey-dk-250: $grey-lt-200; +$grey-dk-300: $grey-lt-300; From 834f9ae49b12672203ac3829f68a94894fe4e752 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 30 Dec 2022 12:22:12 +0100 Subject: [PATCH 135/601] Upgrade NullAway 0.10.5 -> 0.10.6 (#429) See: - https://github.com/uber/NullAway/blob/master/CHANGELOG.md - https://github.com/uber/NullAway/compare/v0.10.5...v0.10.6 --- .../picnic/errorprone/refasterrules/AssertJOptionalRules.java | 1 - .../tech/picnic/errorprone/refasterrules/ReactorRules.java | 3 --- pom.xml | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJOptionalRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJOptionalRules.java index 2cab238072..2b22542a23 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJOptionalRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJOptionalRules.java @@ -22,7 +22,6 @@ private AssertJOptionalRules() {} static final class AssertThatOptional { @BeforeTemplate - @SuppressWarnings("NullAway") ObjectAssert before(Optional optional) { return assertThat(optional.orElseThrow()); } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 40faa052f8..fa8b50cb97 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -372,10 +372,7 @@ Mono before(Mono mono) { return mono.switchIfEmpty(Mono.empty()); } - // XXX: Review the suppression once NullAway has better support for generics. Keep an eye on - // https://github.com/uber/NullAway/issues?q=is%3Aopen+generics. @BeforeTemplate - @SuppressWarnings("NullAway" /* False positive. */) Mono<@Nullable Void> before2(Mono<@Nullable Void> mono) { return mono.then(); } diff --git a/pom.xml b/pom.xml index 7fcac36621..830a7652ae 100644 --- a/pom.xml +++ b/pom.xml @@ -156,7 +156,7 @@ 3.8.6 4.11.0 1.0.1 - 0.10.5 + 0.10.6 1.0.3 2.22.2 From e6e50717d336092e7fe60b19f0e5a083054337f9 Mon Sep 17 00:00:00 2001 From: Christos Giallouros Date: Mon, 2 Jan 2023 09:51:46 +0200 Subject: [PATCH 136/601] Introduce `JUnitToAssertJRules` Refaster rule collection (#417) --- error-prone-contrib/pom.xml | 2 +- .../refasterrules/JUnitToAssertJRules.java | 521 ++++++++++++++++++ .../refasterrules/RefasterRulesTest.java | 1 + .../JUnitToAssertJRulesTestInput.java | 173 ++++++ .../JUnitToAssertJRulesTestOutput.java | 183 ++++++ pom.xml | 4 - 6 files changed, 879 insertions(+), 5 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JUnitToAssertJRules.java create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestInput.java create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestOutput.java diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index 959208f32f..e8e95dbb7e 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -146,7 +146,7 @@ org.junit.jupiter junit-jupiter-api - test + provided org.junit.jupiter diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JUnitToAssertJRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JUnitToAssertJRules.java new file mode 100644 index 0000000000..7d89b6ec29 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/JUnitToAssertJRules.java @@ -0,0 +1,521 @@ +package tech.picnic.errorprone.refasterrules; + +import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrowsExactly; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.google.common.collect.ImmutableSet; +import com.google.errorprone.annotations.DoNotCall; +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; +import com.google.errorprone.refaster.annotation.UseImportPolicy; +import java.util.function.Supplier; +import org.assertj.core.api.ThrowableAssert.ThrowingCallable; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.function.Executable; +import org.junit.jupiter.api.function.ThrowingSupplier; +import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; + +/** + * Refaster rules to replace JUnit assertions with AssertJ equivalents. + * + *

Note that, while both libraries throw an {@link AssertionError} in case of an assertion + * failure, the exact subtype used generally differs. + */ +// XXX: Not all `org.assertj.core.api.Assertions` methods have an associated Refaster rule yet; +// expand this class. +// XXX: Introduce a `@Matcher` on `Executable` and `ThrowingSupplier` expressions, such that they +// are only matched if they are also compatible with the `ThrowingCallable` functional interface. +// When implementing such a matcher, note that expressions with a non-void return type such as +// `() -> toString()` match both `ThrowingSupplier` and `ThrowingCallable`, but `() -> "constant"` +// is only compatible with the former. +@OnlineDocumentation +final class JUnitToAssertJRules { + private JUnitToAssertJRules() {} + + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of( + Assertions.class, + assertDoesNotThrow(() -> null), + assertInstanceOf(null, null), + assertThrows(null, null), + assertThrowsExactly(null, null), + (Runnable) () -> assertFalse(true), + (Runnable) () -> assertNotNull(null), + (Runnable) () -> assertNotSame(null, null), + (Runnable) () -> assertNull(null), + (Runnable) () -> assertSame(null, null), + (Runnable) () -> assertTrue(true)); + } + + static final class ThrowNewAssertionError { + @BeforeTemplate + void before() { + Assertions.fail(); + } + + @AfterTemplate + @DoNotCall + void after() { + throw new AssertionError(); + } + } + + static final class FailWithMessage { + @BeforeTemplate + T before(String message) { + return Assertions.fail(message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + T after(String message) { + return fail(message); + } + } + + static final class FailWithMessageAndThrowable { + @BeforeTemplate + T before(String message, Throwable throwable) { + return Assertions.fail(message, throwable); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + T after(String message, Throwable throwable) { + return fail(message, throwable); + } + } + + static final class FailWithThrowable { + @BeforeTemplate + void before(Throwable throwable) { + Assertions.fail(throwable); + } + + @AfterTemplate + @DoNotCall + void after(Throwable throwable) { + throw new AssertionError(throwable); + } + } + + static final class AssertThatIsTrue { + @BeforeTemplate + void before(boolean actual) { + assertTrue(actual); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(boolean actual) { + assertThat(actual).isTrue(); + } + } + + static final class AssertThatWithFailMessageStringIsTrue { + @BeforeTemplate + void before(boolean actual, String message) { + assertTrue(actual, message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(boolean actual, String message) { + assertThat(actual).withFailMessage(message).isTrue(); + } + } + + static final class AssertThatWithFailMessageSupplierIsTrue { + @BeforeTemplate + void before(boolean actual, Supplier supplier) { + assertTrue(actual, supplier); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(boolean actual, Supplier supplier) { + assertThat(actual).withFailMessage(supplier).isTrue(); + } + } + + static final class AssertThatIsFalse { + @BeforeTemplate + void before(boolean actual) { + assertFalse(actual); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(boolean actual) { + assertThat(actual).isFalse(); + } + } + + static final class AssertThatWithFailMessageStringIsFalse { + @BeforeTemplate + void before(boolean actual, String message) { + assertFalse(actual, message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(boolean actual, String message) { + assertThat(actual).withFailMessage(message).isFalse(); + } + } + + static final class AssertThatWithFailMessageSupplierIsFalse { + @BeforeTemplate + void before(boolean actual, Supplier supplier) { + assertFalse(actual, supplier); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(boolean actual, Supplier supplier) { + assertThat(actual).withFailMessage(supplier).isFalse(); + } + } + + static final class AssertThatIsNull { + @BeforeTemplate + void before(Object actual) { + assertNull(actual); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual) { + assertThat(actual).isNull(); + } + } + + static final class AssertThatWithFailMessageStringIsNull { + @BeforeTemplate + void before(Object actual, String message) { + assertNull(actual, message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, String message) { + assertThat(actual).withFailMessage(message).isNull(); + } + } + + static final class AssertThatWithFailMessageSupplierIsNull { + @BeforeTemplate + void before(Object actual, Supplier supplier) { + assertNull(actual, supplier); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, Supplier supplier) { + assertThat(actual).withFailMessage(supplier).isNull(); + } + } + + static final class AssertThatIsNotNull { + @BeforeTemplate + void before(Object actual) { + assertNotNull(actual); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual) { + assertThat(actual).isNotNull(); + } + } + + static final class AssertThatWithFailMessageStringIsNotNull { + @BeforeTemplate + void before(Object actual, String message) { + assertNotNull(actual, message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, String message) { + assertThat(actual).withFailMessage(message).isNotNull(); + } + } + + static final class AssertThatWithFailMessageSupplierIsNotNull { + @BeforeTemplate + void before(Object actual, Supplier supplier) { + assertNotNull(actual, supplier); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, Supplier supplier) { + assertThat(actual).withFailMessage(supplier).isNotNull(); + } + } + + static final class AssertThatIsSameAs { + @BeforeTemplate + void before(Object actual, Object expected) { + assertSame(expected, actual); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, Object expected) { + assertThat(actual).isSameAs(expected); + } + } + + static final class AssertThatWithFailMessageStringIsSameAs { + @BeforeTemplate + void before(Object actual, Object expected, String message) { + assertSame(expected, actual, message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, Object expected, String message) { + assertThat(actual).withFailMessage(message).isSameAs(expected); + } + } + + static final class AssertThatWithFailMessageSupplierIsSameAs { + @BeforeTemplate + void before(Object actual, Object expected, Supplier supplier) { + assertSame(expected, actual, supplier); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, Object expected, Supplier supplier) { + assertThat(actual).withFailMessage(supplier).isSameAs(expected); + } + } + + static final class AssertThatIsNotSameAs { + @BeforeTemplate + void before(Object actual, Object expected) { + assertNotSame(expected, actual); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, Object expected) { + assertThat(actual).isNotSameAs(expected); + } + } + + static final class AssertThatWithFailMessageStringIsNotSameAs { + @BeforeTemplate + void before(Object actual, Object expected, String message) { + assertNotSame(expected, actual, message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, Object expected, String message) { + assertThat(actual).withFailMessage(message).isNotSameAs(expected); + } + } + + static final class AssertThatWithFailMessageSupplierIsNotSameAs { + @BeforeTemplate + void before(Object actual, Object expected, Supplier supplier) { + assertNotSame(expected, actual, supplier); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, Object expected, Supplier supplier) { + assertThat(actual).withFailMessage(supplier).isNotSameAs(expected); + } + } + + static final class AssertThatThrownByIsExactlyInstanceOf { + @BeforeTemplate + void before(Executable throwingCallable, Class clazz) { + assertThrowsExactly(clazz, throwingCallable); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(ThrowingCallable throwingCallable, Class clazz) { + assertThatThrownBy(throwingCallable).isExactlyInstanceOf(clazz); + } + } + + static final class AssertThatThrownByWithFailMessageStringIsExactlyInstanceOf< + T extends Throwable> { + @BeforeTemplate + void before(Executable throwingCallable, Class clazz, String message) { + assertThrowsExactly(clazz, throwingCallable, message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(ThrowingCallable throwingCallable, Class clazz, String message) { + assertThatThrownBy(throwingCallable).withFailMessage(message).isExactlyInstanceOf(clazz); + } + } + + static final class AssertThatThrownByWithFailMessageSupplierIsExactlyInstanceOf< + T extends Throwable> { + @BeforeTemplate + void before(Executable throwingCallable, Class clazz, Supplier supplier) { + assertThrowsExactly(clazz, throwingCallable, supplier); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(ThrowingCallable throwingCallable, Class clazz, Supplier supplier) { + assertThatThrownBy(throwingCallable).withFailMessage(supplier).isExactlyInstanceOf(clazz); + } + } + + static final class AssertThatThrownByIsInstanceOf { + @BeforeTemplate + void before(Executable throwingCallable, Class clazz) { + assertThrows(clazz, throwingCallable); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(ThrowingCallable throwingCallable, Class clazz) { + assertThatThrownBy(throwingCallable).isInstanceOf(clazz); + } + } + + static final class AssertThatThrownByWithFailMessageStringIsInstanceOf { + @BeforeTemplate + void before(Executable throwingCallable, Class clazz, String message) { + assertThrows(clazz, throwingCallable, message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(ThrowingCallable throwingCallable, Class clazz, String message) { + assertThatThrownBy(throwingCallable).withFailMessage(message).isInstanceOf(clazz); + } + } + + static final class AssertThatThrownByWithFailMessageSupplierIsInstanceOf { + @BeforeTemplate + void before(Executable throwingCallable, Class clazz, Supplier supplier) { + assertThrows(clazz, throwingCallable, supplier); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(ThrowingCallable throwingCallable, Class clazz, Supplier supplier) { + assertThatThrownBy(throwingCallable).withFailMessage(supplier).isInstanceOf(clazz); + } + } + + static final class AssertThatCodeDoesNotThrowAnyException { + @BeforeTemplate + void before(Executable throwingCallable) { + assertDoesNotThrow(throwingCallable); + } + + @BeforeTemplate + void before(ThrowingSupplier throwingCallable) { + assertDoesNotThrow(throwingCallable); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(ThrowingCallable throwingCallable) { + assertThatCode(throwingCallable).doesNotThrowAnyException(); + } + } + + static final class AssertThatCodeWithFailMessageStringDoesNotThrowAnyException { + @BeforeTemplate + void before(Executable throwingCallable, String message) { + assertDoesNotThrow(throwingCallable, message); + } + + @BeforeTemplate + void before(ThrowingSupplier throwingCallable, String message) { + assertDoesNotThrow(throwingCallable, message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(ThrowingCallable throwingCallable, String message) { + assertThatCode(throwingCallable).withFailMessage(message).doesNotThrowAnyException(); + } + } + + static final class AssertThatCodeWithFailMessageSupplierDoesNotThrowAnyException { + @BeforeTemplate + void before(Executable throwingCallable, Supplier supplier) { + assertDoesNotThrow(throwingCallable, supplier); + } + + @BeforeTemplate + void before(ThrowingSupplier throwingCallable, Supplier supplier) { + assertDoesNotThrow(throwingCallable, supplier); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(ThrowingCallable throwingCallable, Supplier supplier) { + assertThatCode(throwingCallable).withFailMessage(supplier).doesNotThrowAnyException(); + } + } + + static final class AssertThatIsInstanceOf { + @BeforeTemplate + void before(Object actual, Class clazz) { + assertInstanceOf(clazz, actual); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, Class clazz) { + assertThat(actual).isInstanceOf(clazz); + } + } + + static final class AssertThatWithFailMessageStringIsInstanceOf { + @BeforeTemplate + void before(Object actual, Class clazz, String message) { + assertInstanceOf(clazz, actual, message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, Class clazz, String message) { + assertThat(actual).withFailMessage(message).isInstanceOf(clazz); + } + } + + static final class AssertThatWithFailMessageSupplierIsInstanceOf { + @BeforeTemplate + void before(Object actual, Class clazz, Supplier supplier) { + assertInstanceOf(clazz, actual, supplier); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + void after(Object actual, Class clazz, Supplier supplier) { + assertThat(actual).withFailMessage(supplier).isInstanceOf(clazz); + } + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java index 1129ca80f6..c60bb8b286 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java @@ -50,6 +50,7 @@ final class RefasterRulesTest { ImmutableSortedSetRules.class, IntStreamRules.class, JUnitRules.class, + JUnitToAssertJRules.class, LongStreamRules.class, MapEntryRules.class, MapRules.class, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestInput.java new file mode 100644 index 0000000000..d1a68ad7a9 --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestInput.java @@ -0,0 +1,173 @@ +package tech.picnic.errorprone.refasterrules; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrowsExactly; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.google.common.collect.ImmutableSet; +import org.junit.jupiter.api.Assertions; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; + +final class JUnitToAssertJRulesTest implements RefasterRuleCollectionTestCase { + @Override + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of( + Assertions.class, + assertDoesNotThrow(() -> null), + assertInstanceOf(null, null), + assertThrows(null, null), + assertThrowsExactly(null, null), + (Runnable) () -> assertFalse(true), + (Runnable) () -> assertNotNull(null), + (Runnable) () -> assertNotSame(null, null), + (Runnable) () -> assertNull(null), + (Runnable) () -> assertSame(null, null), + (Runnable) () -> assertTrue(true)); + } + + void testThrowNewAssertionError() { + Assertions.fail(); + } + + Object testFailWithMessage() { + return Assertions.fail("foo"); + } + + Object testFailWithMessageAndThrowable() { + return Assertions.fail("foo", new IllegalStateException()); + } + + void testFailWithThrowable() { + Assertions.fail(new IllegalStateException()); + } + + void testAssertThatIsTrue() { + assertTrue(true); + } + + void testAssertThatWithFailMessageStringIsTrue() { + assertTrue(true, "foo"); + } + + void testAssertThatWithFailMessageSupplierIsTrue() { + assertTrue(true, () -> "foo"); + } + + void testAssertThatIsFalse() { + assertFalse(true); + } + + void testAssertThatWithFailMessageStringIsFalse() { + assertFalse(true, "foo"); + } + + void testAssertThatWithFailMessageSupplierIsFalse() { + assertFalse(true, () -> "foo"); + } + + void testAssertThatIsNull() { + assertNull(new Object()); + } + + void testAssertThatWithFailMessageStringIsNull() { + assertNull(new Object(), "foo"); + } + + void testAssertThatWithFailMessageSupplierIsNull() { + assertNull(new Object(), () -> "foo"); + } + + void testAssertThatIsNotNull() { + assertNotNull(new Object()); + } + + void testAssertThatWithFailMessageStringIsNotNull() { + assertNotNull(new Object(), "foo"); + } + + void testAssertThatWithFailMessageSupplierIsNotNull() { + assertNotNull(new Object(), () -> "foo"); + } + + void testAssertThatIsSameAs() { + assertSame("foo", "bar"); + } + + void testAssertThatWithFailMessageStringIsSameAs() { + assertSame("foo", "bar", "baz"); + } + + void testAssertThatWithFailMessageSupplierIsSameAs() { + assertSame("foo", "bar", () -> "baz"); + } + + void testAssertThatIsNotSameAs() { + assertNotSame("foo", "bar"); + } + + void testAssertThatWithFailMessageStringIsNotSameAs() { + assertNotSame("foo", "bar", "baz"); + } + + void testAssertThatWithFailMessageSupplierIsNotSameAs() { + assertNotSame("foo", "bar", () -> "baz"); + } + + void testAssertThatThrownByIsExactlyInstanceOf() { + assertThrowsExactly(IllegalStateException.class, () -> {}); + } + + void testAssertThatThrownByWithFailMessageStringIsExactlyInstanceOf() { + assertThrowsExactly(IllegalStateException.class, () -> {}, "foo"); + } + + void testAssertThatThrownByWithFailMessageSupplierIsExactlyInstanceOf() { + assertThrowsExactly(IllegalStateException.class, () -> {}, () -> "foo"); + } + + void testAssertThatThrownByIsInstanceOf() { + assertThrows(IllegalStateException.class, () -> {}); + } + + void testAssertThatThrownByWithFailMessageStringIsInstanceOf() { + assertThrows(IllegalStateException.class, () -> {}, "foo"); + } + + void testAssertThatThrownByWithFailMessageSupplierIsInstanceOf() { + assertThrows(IllegalStateException.class, () -> {}, () -> "foo"); + } + + void testAssertThatCodeDoesNotThrowAnyException() { + assertDoesNotThrow(() -> {}); + assertDoesNotThrow(() -> toString()); + } + + void testAssertThatCodeWithFailMessageStringDoesNotThrowAnyException() { + assertDoesNotThrow(() -> {}, "foo"); + assertDoesNotThrow(() -> toString(), "bar"); + } + + void testAssertThatCodeWithFailMessageSupplierDoesNotThrowAnyException() { + assertDoesNotThrow(() -> {}, () -> "foo"); + assertDoesNotThrow(() -> toString(), () -> "bar"); + } + + void testAssertThatIsInstanceOf() { + assertInstanceOf(Object.class, new Object()); + } + + void testAssertThatWithFailMessageStringIsInstanceOf() { + assertInstanceOf(Object.class, new Object(), "foo"); + } + + void testAssertThatWithFailMessageSupplierIsInstanceOf() { + assertInstanceOf(Object.class, new Object(), () -> "foo"); + } +} diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestOutput.java new file mode 100644 index 0000000000..c41d0246ac --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/JUnitToAssertJRulesTestOutput.java @@ -0,0 +1,183 @@ +package tech.picnic.errorprone.refasterrules; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertThrowsExactly; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.google.common.collect.ImmutableSet; +import org.junit.jupiter.api.Assertions; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; + +final class JUnitToAssertJRulesTest implements RefasterRuleCollectionTestCase { + @Override + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of( + Assertions.class, + assertDoesNotThrow(() -> null), + assertInstanceOf(null, null), + assertThrows(null, null), + assertThrowsExactly(null, null), + (Runnable) () -> assertFalse(true), + (Runnable) () -> assertNotNull(null), + (Runnable) () -> assertNotSame(null, null), + (Runnable) () -> assertNull(null), + (Runnable) () -> assertSame(null, null), + (Runnable) () -> assertTrue(true)); + } + + void testThrowNewAssertionError() { + throw new AssertionError(); + } + + Object testFailWithMessage() { + return fail("foo"); + } + + Object testFailWithMessageAndThrowable() { + return fail("foo", new IllegalStateException()); + } + + void testFailWithThrowable() { + throw new AssertionError(new IllegalStateException()); + } + + void testAssertThatIsTrue() { + assertThat(true).isTrue(); + } + + void testAssertThatWithFailMessageStringIsTrue() { + assertThat(true).withFailMessage("foo").isTrue(); + } + + void testAssertThatWithFailMessageSupplierIsTrue() { + assertThat(true).withFailMessage(() -> "foo").isTrue(); + } + + void testAssertThatIsFalse() { + assertThat(true).isFalse(); + } + + void testAssertThatWithFailMessageStringIsFalse() { + assertThat(true).withFailMessage("foo").isFalse(); + } + + void testAssertThatWithFailMessageSupplierIsFalse() { + assertThat(true).withFailMessage(() -> "foo").isFalse(); + } + + void testAssertThatIsNull() { + assertThat(new Object()).isNull(); + } + + void testAssertThatWithFailMessageStringIsNull() { + assertThat(new Object()).withFailMessage("foo").isNull(); + } + + void testAssertThatWithFailMessageSupplierIsNull() { + assertThat(new Object()).withFailMessage(() -> "foo").isNull(); + } + + void testAssertThatIsNotNull() { + assertThat(new Object()).isNotNull(); + } + + void testAssertThatWithFailMessageStringIsNotNull() { + assertThat(new Object()).withFailMessage("foo").isNotNull(); + } + + void testAssertThatWithFailMessageSupplierIsNotNull() { + assertThat(new Object()).withFailMessage(() -> "foo").isNotNull(); + } + + void testAssertThatIsSameAs() { + assertThat("bar").isSameAs("foo"); + } + + void testAssertThatWithFailMessageStringIsSameAs() { + assertThat("bar").withFailMessage("baz").isSameAs("foo"); + } + + void testAssertThatWithFailMessageSupplierIsSameAs() { + assertThat("bar").withFailMessage(() -> "baz").isSameAs("foo"); + } + + void testAssertThatIsNotSameAs() { + assertThat("bar").isNotSameAs("foo"); + } + + void testAssertThatWithFailMessageStringIsNotSameAs() { + assertThat("bar").withFailMessage("baz").isNotSameAs("foo"); + } + + void testAssertThatWithFailMessageSupplierIsNotSameAs() { + assertThat("bar").withFailMessage(() -> "baz").isNotSameAs("foo"); + } + + void testAssertThatThrownByIsExactlyInstanceOf() { + assertThatThrownBy(() -> {}).isExactlyInstanceOf(IllegalStateException.class); + } + + void testAssertThatThrownByWithFailMessageStringIsExactlyInstanceOf() { + assertThatThrownBy(() -> {}) + .withFailMessage("foo") + .isExactlyInstanceOf(IllegalStateException.class); + } + + void testAssertThatThrownByWithFailMessageSupplierIsExactlyInstanceOf() { + assertThatThrownBy(() -> {}) + .withFailMessage(() -> "foo") + .isExactlyInstanceOf(IllegalStateException.class); + } + + void testAssertThatThrownByIsInstanceOf() { + assertThatThrownBy(() -> {}).isInstanceOf(IllegalStateException.class); + } + + void testAssertThatThrownByWithFailMessageStringIsInstanceOf() { + assertThatThrownBy(() -> {}).withFailMessage("foo").isInstanceOf(IllegalStateException.class); + } + + void testAssertThatThrownByWithFailMessageSupplierIsInstanceOf() { + assertThatThrownBy(() -> {}) + .withFailMessage(() -> "foo") + .isInstanceOf(IllegalStateException.class); + } + + void testAssertThatCodeDoesNotThrowAnyException() { + assertThatCode(() -> {}).doesNotThrowAnyException(); + assertThatCode(() -> toString()).doesNotThrowAnyException(); + } + + void testAssertThatCodeWithFailMessageStringDoesNotThrowAnyException() { + assertThatCode(() -> {}).withFailMessage("foo").doesNotThrowAnyException(); + assertThatCode(() -> toString()).withFailMessage("bar").doesNotThrowAnyException(); + } + + void testAssertThatCodeWithFailMessageSupplierDoesNotThrowAnyException() { + assertThatCode(() -> {}).withFailMessage(() -> "foo").doesNotThrowAnyException(); + assertThatCode(() -> toString()).withFailMessage(() -> "bar").doesNotThrowAnyException(); + } + + void testAssertThatIsInstanceOf() { + assertThat(new Object()).isInstanceOf(Object.class); + } + + void testAssertThatWithFailMessageStringIsInstanceOf() { + assertThat(new Object()).withFailMessage("foo").isInstanceOf(Object.class); + } + + void testAssertThatWithFailMessageSupplierIsInstanceOf() { + assertThat(new Object()).withFailMessage(() -> "foo").isInstanceOf(Object.class); + } +} diff --git a/pom.xml b/pom.xml index 830a7652ae..d3e7f2e673 100644 --- a/pom.xml +++ b/pom.xml @@ -686,10 +686,6 @@ - - - ${error-prone.patch-args} ${error-prone.self-check-args} From 190b47870b7ba6ac486154ae61b8bf8ffc8a6922 Mon Sep 17 00:00:00 2001 From: jarmilakaiser <117719126+jarmilakaiser@users.noreply.github.com> Date: Wed, 4 Jan 2023 09:27:21 +0100 Subject: [PATCH 141/601] Show original Cody in README and on website home page (#438) This reverts commit 0153c1495f6fc8ce5af2062e974f0ae9092bafd6. --- website/assets/images/logo-dark.svg | 255 ++-------------------------- website/assets/images/logo.svg | 255 ++-------------------------- 2 files changed, 20 insertions(+), 490 deletions(-) diff --git a/website/assets/images/logo-dark.svg b/website/assets/images/logo-dark.svg index 9ff31f178c..bd0c9ff013 100644 --- a/website/assets/images/logo-dark.svg +++ b/website/assets/images/logo-dark.svg @@ -1,245 +1,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + 1 0 + + 1 1 0 + + 0 0 1 + + 1 0 0 1 + + diff --git a/website/assets/images/logo.svg b/website/assets/images/logo.svg index 9ff31f178c..97f1342ffc 100644 --- a/website/assets/images/logo.svg +++ b/website/assets/images/logo.svg @@ -1,245 +1,10 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + 1 0 + + 1 1 0 + + 0 0 1 + + 1 0 0 1 + + From 9992ff49ce8b5aa90cd1f63aa3ed817b766f8c47 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 4 Jan 2023 10:21:44 +0100 Subject: [PATCH 142/601] Upgrade pitest-junit5-plugin 1.1.0 -> 1.1.1 (#440) See https://github.com/pitest/pitest-junit5-plugin/compare/1.1.0...1.1.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f1c5cea48f..71a3aa651f 100644 --- a/pom.xml +++ b/pom.xml @@ -1276,7 +1276,7 @@ org.pitest pitest-junit5-plugin - 1.1.0 + 1.1.1 From 9d08e8fd4d0868a3f98e1b6b0ec981c5dd590f0f Mon Sep 17 00:00:00 2001 From: chamil-prabodha Date: Wed, 4 Jan 2023 11:13:44 +0100 Subject: [PATCH 143/601] Have `RequestParamType` ignore parameter types with custom deserialization support (#426) While there, introduce and use a new `Flags` utility class; various checks' list flags now better support empty lists. --- ...cographicalAnnotationAttributeListing.java | 3 +- .../RedundantStringConversion.java | 13 +++-- .../bugpatterns/RequestParamType.java | 48 ++++++++++++++--- .../errorprone/bugpatterns/util/Flags.java | 25 +++++++++ .../bugpatterns/RequestParamTypeTest.java | 53 +++++++++++++++++++ .../bugpatterns/util/FlagsTest.java | 31 +++++++++++ 6 files changed, 157 insertions(+), 16 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/Flags.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/FlagsTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java index 28e5f51b40..2bf8cbd739 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java @@ -42,6 +42,7 @@ import java.util.stream.Stream; import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.bugpatterns.util.AnnotationAttributeMatcher; +import tech.picnic.errorprone.bugpatterns.util.Flags; import tech.picnic.errorprone.bugpatterns.util.SourceCode; /** @@ -220,7 +221,7 @@ private static AnnotationAttributeMatcher createAnnotationAttributeMatcher( private static ImmutableList excludedAnnotations(ErrorProneFlags flags) { Set exclusions = new HashSet<>(); - flags.getList(EXCLUDED_ANNOTATIONS_FLAG).ifPresent(exclusions::addAll); + exclusions.addAll(Flags.getList(flags, EXCLUDED_ANNOTATIONS_FLAG)); exclusions.addAll(BLACKLISTED_ANNOTATIONS); return ImmutableList.copyOf(exclusions); } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java index fae14e3d36..3fae404499 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java @@ -49,6 +49,7 @@ import java.util.Objects; import java.util.Optional; import java.util.stream.Stream; +import tech.picnic.errorprone.bugpatterns.util.Flags; import tech.picnic.errorprone.bugpatterns.util.MethodMatcherFactory; import tech.picnic.errorprone.bugpatterns.util.SourceCode; @@ -63,9 +64,8 @@ public final class RedundantStringConversion extends BugChecker implements BinaryTreeMatcher, CompoundAssignmentTreeMatcher, MethodInvocationTreeMatcher { private static final long serialVersionUID = 1L; - private static final String FLAG_PREFIX = "RedundantStringConversion:"; private static final String EXTRA_STRING_CONVERSION_METHODS_FLAG = - FLAG_PREFIX + "ExtraConversionMethods"; + "RedundantStringConversion:ExtraConversionMethods"; @SuppressWarnings("UnnecessaryLambda") private static final Matcher ANY_EXPR = (t, s) -> true; @@ -374,10 +374,9 @@ private static Matcher createConversionMethodMatcher( ErrorProneFlags flags) { // XXX: ErrorProneFlags#getList splits by comma, but method signatures may also contain commas. // For this class methods accepting more than one argument are not valid, but still: not nice. - return flags - .getList(EXTRA_STRING_CONVERSION_METHODS_FLAG) - .map(new MethodMatcherFactory()::create) - .map(m -> anyOf(WELL_KNOWN_STRING_CONVERSION_METHODS, m)) - .orElse(WELL_KNOWN_STRING_CONVERSION_METHODS); + return anyOf( + WELL_KNOWN_STRING_CONVERSION_METHODS, + new MethodMatcherFactory() + .create(Flags.getList(flags, EXTRA_STRING_CONVERSION_METHODS_FLAG))); } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestParamType.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestParamType.java index eb076e3867..28b9e8d439 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestParamType.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestParamType.java @@ -1,5 +1,6 @@ package tech.picnic.errorprone.bugpatterns; +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.errorprone.BugPattern.LinkType.CUSTOM; import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; import static com.google.errorprone.BugPattern.StandardTags.LIKELY_ERROR; @@ -9,41 +10,72 @@ import static com.google.errorprone.matchers.Matchers.anyOf; import static com.google.errorprone.matchers.Matchers.isSubtypeOf; import static com.google.errorprone.matchers.Matchers.isType; +import static com.google.errorprone.matchers.Matchers.not; import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; import com.google.auto.service.AutoService; import com.google.common.collect.ImmutableCollection; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.errorprone.BugPattern; +import com.google.errorprone.ErrorProneFlags; import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.BugChecker; import com.google.errorprone.bugpatterns.BugChecker.VariableTreeMatcher; import com.google.errorprone.matchers.Description; import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.suppliers.Suppliers; +import com.sun.source.tree.Tree; import com.sun.source.tree.VariableTree; +import tech.picnic.errorprone.bugpatterns.util.Flags; /** A {@link BugChecker} that flags {@code @RequestParam} parameters with an unsupported type. */ @AutoService(BugChecker.class) @BugPattern( - summary = "`@RequestParam` does not support `ImmutableCollection` and `ImmutableMap` subtypes", + summary = + "By default, `@RequestParam` does not support `ImmutableCollection` and `ImmutableMap` subtypes", link = BUG_PATTERNS_BASE_URL + "RequestParamType", linkType = CUSTOM, severity = ERROR, tags = LIKELY_ERROR) public final class RequestParamType extends BugChecker implements VariableTreeMatcher { private static final long serialVersionUID = 1L; - private static final Matcher HAS_UNSUPPORTED_REQUEST_PARAM = - allOf( - annotations(AT_LEAST_ONE, isType("org.springframework.web.bind.annotation.RequestParam")), - anyOf(isSubtypeOf(ImmutableCollection.class), isSubtypeOf(ImmutableMap.class))); + private static final String SUPPORTED_CUSTOM_TYPES_FLAG = "RequestParamType:SupportedCustomTypes"; - /** Instantiates a new {@link RequestParamType} instance. */ - public RequestParamType() {} + private final Matcher hasUnsupportedRequestParamType; + + /** Instantiates a default {@link RequestParamType} instance. */ + public RequestParamType() { + this(ErrorProneFlags.empty()); + } + + /** + * Instantiates a customized {@link RequestParamType} instance. + * + * @param flags Any provided command line flags. + */ + public RequestParamType(ErrorProneFlags flags) { + hasUnsupportedRequestParamType = hasUnsupportedRequestParamType(flags); + } @Override public Description matchVariable(VariableTree tree, VisitorState state) { - return HAS_UNSUPPORTED_REQUEST_PARAM.matches(tree, state) + return hasUnsupportedRequestParamType.matches(tree, state) ? describeMatch(tree) : Description.NO_MATCH; } + + private static Matcher hasUnsupportedRequestParamType(ErrorProneFlags flags) { + return allOf( + annotations(AT_LEAST_ONE, isType("org.springframework.web.bind.annotation.RequestParam")), + anyOf(isSubtypeOf(ImmutableCollection.class), isSubtypeOf(ImmutableMap.class)), + not(isSubtypeOfAny(Flags.getList(flags, SUPPORTED_CUSTOM_TYPES_FLAG)))); + } + + private static Matcher isSubtypeOfAny(ImmutableList inclusions) { + return anyOf( + inclusions.stream() + .map(inclusion -> isSubtypeOf(Suppliers.typeFromString(inclusion))) + .collect(toImmutableList())); + } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/Flags.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/Flags.java new file mode 100644 index 0000000000..ec5f4e92b3 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/Flags.java @@ -0,0 +1,25 @@ +package tech.picnic.errorprone.bugpatterns.util; + +import com.google.common.collect.ImmutableList; +import com.google.errorprone.ErrorProneFlags; + +/** Helper methods for working with {@link ErrorProneFlags}. */ +public final class Flags { + private Flags() {} + + /** + * Returns the list of (comma-separated) arguments passed using the given Error Prone flag. + * + * @param errorProneFlags The full set of flags provided. + * @param name The name of the flag of interest. + * @return A non-{@code null} list of provided arguments; this list is empty if the flag was not + * provided, or if the flag's value is the empty string. + */ + public static ImmutableList getList(ErrorProneFlags errorProneFlags, String name) { + return errorProneFlags + .getList(name) + .map(ImmutableList::copyOf) + .filter(flags -> !flags.equals(ImmutableList.of(""))) + .orElseGet(ImmutableList::of); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java index 45d58534c6..97b4c3cc4b 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java @@ -6,6 +6,10 @@ final class RequestParamTypeTest { private final CompilationTestHelper compilationTestHelper = CompilationTestHelper.newInstance(RequestParamType.class, getClass()); + private final CompilationTestHelper restrictedCompilationTestHelper = + CompilationTestHelper.newInstance(RequestParamType.class, getClass()) + .setArgs( + "-XepOpt:RequestParamType:SupportedCustomTypes=com.google.common.collect.ImmutableSet,com.google.common.collect.ImmutableSortedMultiset"); @Test void identification() { @@ -63,4 +67,53 @@ void identification() { "}") .doTest(); } + + @Test + void identificationRestricted() { + restrictedCompilationTestHelper + .addSourceLines( + "A.java", + "import com.google.common.collect.ImmutableBiMap;", + "import com.google.common.collect.ImmutableCollection;", + "import com.google.common.collect.ImmutableList;", + "import com.google.common.collect.ImmutableMap;", + "import com.google.common.collect.ImmutableMultiset;", + "import com.google.common.collect.ImmutableSet;", + "import com.google.common.collect.ImmutableSortedMultiset;", + "import com.google.common.collect.ImmutableSortedSet;", + "import org.springframework.web.bind.annotation.GetMapping;", + "import org.springframework.web.bind.annotation.RequestParam;", + "", + "interface A {", + " @GetMapping", + " // BUG: Diagnostic contains:", + " A immutableCollection(@RequestParam ImmutableCollection param);", + "", + " @GetMapping", + " // BUG: Diagnostic contains:", + " A immutableList(@RequestParam ImmutableList param);", + "", + " @GetMapping", + " A immutableSet(@RequestParam ImmutableSet param);", + "", + " @GetMapping", + " A immutableSortedSet(@RequestParam ImmutableSortedSet param);", + "", + " @GetMapping", + " // BUG: Diagnostic contains:", + " A immutableMultiset(@RequestParam ImmutableMultiset param);", + "", + " @GetMapping", + " A immutableSortedMultiset(@RequestParam ImmutableSortedMultiset param);", + "", + " @GetMapping", + " // BUG: Diagnostic contains:", + " A immutableMap(@RequestParam ImmutableMap param);", + "", + " @GetMapping", + " // BUG: Diagnostic contains:", + " A immutableBiMap(@RequestParam ImmutableBiMap param);", + "}") + .doTest(); + } } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/FlagsTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/FlagsTest.java new file mode 100644 index 0000000000..3ba51f0511 --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/FlagsTest.java @@ -0,0 +1,31 @@ +package tech.picnic.errorprone.bugpatterns.util; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.params.provider.Arguments.arguments; + +import com.google.common.collect.ImmutableList; +import com.google.errorprone.ErrorProneOptions; +import java.util.stream.Stream; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +final class FlagsTest { + private static Stream getListTestCases() { + /* { args, flag, expected } */ + return Stream.of( + arguments(ImmutableList.of(), "Foo", ImmutableList.of()), + arguments(ImmutableList.of("-XepOpt:Foo=bar,baz"), "Qux", ImmutableList.of()), + arguments(ImmutableList.of("-XepOpt:Foo="), "Foo", ImmutableList.of()), + arguments(ImmutableList.of("-XepOpt:Foo=bar"), "Foo", ImmutableList.of("bar")), + arguments(ImmutableList.of("-XepOpt:Foo=bar,baz"), "Foo", ImmutableList.of("bar", "baz")), + arguments(ImmutableList.of("-XepOpt:Foo=,"), "Foo", ImmutableList.of("", ""))); + } + + @MethodSource("getListTestCases") + @ParameterizedTest + void getList(ImmutableList args, String flag, ImmutableList expected) { + assertThat(Flags.getList(ErrorProneOptions.processArgs(args).getFlags(), flag)) + .containsExactlyElementsOf(expected); + } +} From 6f4db8fc4daba531b49f55be9682a228a2ef95fa Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 5 Jan 2023 08:32:46 +0100 Subject: [PATCH 144/601] Upgrade NullAway 0.10.6 -> 0.10.7 (#444) See: - https://github.com/uber/NullAway/blob/master/CHANGELOG.md - https://github.com/uber/NullAway/compare/v0.10.6...v0.10.7 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 71a3aa651f..9430efd83e 100644 --- a/pom.xml +++ b/pom.xml @@ -156,7 +156,7 @@ 3.8.6 4.11.0 1.0.1 - 0.10.6 + 0.10.7 1.0.3 2.22.2 From 85e3db6f0a9b22e2f21ca1705dcd378d6ecaa0c5 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 5 Jan 2023 09:58:06 +0100 Subject: [PATCH 145/601] Upgrade pitest-maven-plugin 1.10.3 -> 1.10.4 (#445) See: - https://github.com/hcoles/pitest/releases/tag/1.10.4 - https://github.com/hcoles/pitest/compare/1.10.3...1.10.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9430efd83e..5b90d89c04 100644 --- a/pom.xml +++ b/pom.xml @@ -1237,7 +1237,7 @@ org.pitest pitest-maven - 1.10.3 + 1.10.4 From 1ed1e6cd03882350359b08ede974ea467e140bf5 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Thu, 5 Jan 2023 14:47:26 +0100 Subject: [PATCH 146/601] Update year to 2023 in `footer_custom.html` and `LICENSE.md` (#446) --- LICENSE.md | 2 +- website/_includes/footer_custom.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE.md b/LICENSE.md index 4b2daf1944..f40840e5ed 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2022 Picnic Technologies BV +Copyright (c) 2017-2023 Picnic Technologies BV Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/website/_includes/footer_custom.html b/website/_includes/footer_custom.html index 1f18ad553c..4a2a4bb7c1 100644 --- a/website/_includes/footer_custom.html +++ b/website/_includes/footer_custom.html @@ -1,5 +1,5 @@

- Copyright © 2017-2022 Picnic Technologies BV + Copyright © 2017-2023 Picnic Technologies BV

From 534ebb62a126de4af10ba9d736402210fec95ad9 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 6 Jan 2023 08:40:54 +0100 Subject: [PATCH 147/601] Upgrade Checker Framework Annotations 3.28.0 -> 3.29.0 (#449) See: - https://github.com/typetools/checker-framework/releases/tag/checker-framework-3.29.0 - https://github.com/typetools/checker-framework/compare/checker-framework-3.28.0...checker-framework-3.29.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5b90d89c04..d4297e1cd0 100644 --- a/pom.xml +++ b/pom.xml @@ -343,7 +343,7 @@ org.checkerframework checker-qual - 3.28.0 + 3.29.0 org.hamcrest From e9733f7426f224ccdba35339cd343e1b4dca5620 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 6 Jan 2023 09:12:29 +0100 Subject: [PATCH 148/601] Upgrade AssertJ Core 3.23.1 -> 3.24.0 (#448) While there, use the new BOM. See: - https://assertj.github.io/doc/#assertj-core-release-notes - https://github.com/joel-costigliola/assertj-core/compare/assertj-core-3.23.1...assertj-build-3.24.0 --- pom.xml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d4297e1cd0..a30d401964 100644 --- a/pom.xml +++ b/pom.xml @@ -337,8 +337,10 @@ org.assertj - assertj-core - 3.23.1 + assertj-bom + 3.24.0 + pom + import org.checkerframework From e9a1d54035ad4282f01f25452b476fca59eb242c Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Fri, 6 Jan 2023 10:28:21 +0100 Subject: [PATCH 149/601] Add `@OnlineDocumentation` to `TestNGToAssertJRules` (#447) --- .../picnic/errorprone/refasterrules/TestNGToAssertJRules.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TestNGToAssertJRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TestNGToAssertJRules.java index e49014fb0f..8c9521ca3a 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TestNGToAssertJRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/TestNGToAssertJRules.java @@ -28,6 +28,7 @@ import org.assertj.core.api.ThrowableAssert.ThrowingCallable; import org.testng.Assert; import org.testng.Assert.ThrowingRunnable; +import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; /** * Refaster rules that replace TestNG assertions with equivalent AssertJ assertions. @@ -72,6 +73,7 @@ // XXX: As-is these rules do not result in a complete migration: // - Expressions containing comments are skipped due to a limitation of Refaster. // - Assertions inside lambda expressions are also skipped. Unclear why. +@OnlineDocumentation final class TestNGToAssertJRules { private TestNGToAssertJRules() {} From 9a9ef3c59dcdd9a973ff5d9e47b848828bc813b7 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Fri, 6 Jan 2023 10:38:54 +0100 Subject: [PATCH 150/601] Have `apply-error-prone-suggestions.sh` download JitPack-hosted artifacts (#441) While there, tweak the usage message of both `apply-error-prone-suggestions.sh` and `run-mutation-tests.sh`. --- apply-error-prone-suggestions.sh | 3 ++- run-mutation-tests.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apply-error-prone-suggestions.sh b/apply-error-prone-suggestions.sh index da40367972..6ca82fc208 100755 --- a/apply-error-prone-suggestions.sh +++ b/apply-error-prone-suggestions.sh @@ -9,13 +9,14 @@ set -e -u -o pipefail if [ "${#}" -gt 1 ]; then - echo "Usage: ./$(basename "${0}") [PatchChecks]" + echo "Usage: ${0} [PatchChecks]" exit 1 fi patchChecks=${1:-} mvn clean test-compile fmt:format \ + -s "$(dirname "${0}")/settings.xml" \ -T 1.0C \ -Perror-prone \ -Perror-prone-fork \ diff --git a/run-mutation-tests.sh b/run-mutation-tests.sh index 66826c1423..5e9bc2891d 100755 --- a/run-mutation-tests.sh +++ b/run-mutation-tests.sh @@ -7,7 +7,7 @@ set -e -u -o pipefail if [ "${#}" -gt 1 ]; then - echo "Usage: ./$(basename "${0}") [TargetTests]" + echo "Usage: ${0} [TargetTests]" exit 1 fi From 2356c61314c048ee67f0a00c0101a2c97e8cb8cb Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Fri, 6 Jan 2023 11:29:09 +0100 Subject: [PATCH 151/601] [maven-release-plugin] prepare release v0.7.0 --- error-prone-contrib/pom.xml | 2 +- pom.xml | 4 ++-- refaster-compiler/pom.xml | 2 +- refaster-runner/pom.xml | 2 +- refaster-support/pom.xml | 2 +- refaster-test-support/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index e8e95dbb7e..9ea5503da3 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.6.1-SNAPSHOT + 0.7.0 error-prone-contrib diff --git a/pom.xml b/pom.xml index a30d401964..3f672ea8dd 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ tech.picnic.error-prone-support error-prone-support - 0.6.1-SNAPSHOT + 0.7.0 pom Picnic :: Error Prone Support @@ -48,7 +48,7 @@ scm:git:git@github.com:PicnicSupermarket/error-prone-support.git - HEAD + v0.7.0 https://github.com/PicnicSupermarket/error-prone-support diff --git a/refaster-compiler/pom.xml b/refaster-compiler/pom.xml index 001471cf80..51704511ab 100644 --- a/refaster-compiler/pom.xml +++ b/refaster-compiler/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.6.1-SNAPSHOT + 0.7.0 refaster-compiler diff --git a/refaster-runner/pom.xml b/refaster-runner/pom.xml index c965a24640..93b4fd8fd2 100644 --- a/refaster-runner/pom.xml +++ b/refaster-runner/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.6.1-SNAPSHOT + 0.7.0 refaster-runner diff --git a/refaster-support/pom.xml b/refaster-support/pom.xml index 99da547a17..6f64260e12 100644 --- a/refaster-support/pom.xml +++ b/refaster-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.6.1-SNAPSHOT + 0.7.0 refaster-support diff --git a/refaster-test-support/pom.xml b/refaster-test-support/pom.xml index c6c614b8ad..e00187b6f9 100644 --- a/refaster-test-support/pom.xml +++ b/refaster-test-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.6.1-SNAPSHOT + 0.7.0 refaster-test-support From 560f52bad058d176546c0334aaed8760756831c0 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Fri, 6 Jan 2023 11:29:12 +0100 Subject: [PATCH 152/601] [maven-release-plugin] prepare for next development iteration --- error-prone-contrib/pom.xml | 2 +- pom.xml | 4 ++-- refaster-compiler/pom.xml | 2 +- refaster-runner/pom.xml | 2 +- refaster-support/pom.xml | 2 +- refaster-test-support/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index 9ea5503da3..44e6a4516d 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.7.0 + 0.7.1-SNAPSHOT error-prone-contrib diff --git a/pom.xml b/pom.xml index 3f672ea8dd..c9cb944a6e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ tech.picnic.error-prone-support error-prone-support - 0.7.0 + 0.7.1-SNAPSHOT pom Picnic :: Error Prone Support @@ -48,7 +48,7 @@ scm:git:git@github.com:PicnicSupermarket/error-prone-support.git - v0.7.0 + HEAD https://github.com/PicnicSupermarket/error-prone-support diff --git a/refaster-compiler/pom.xml b/refaster-compiler/pom.xml index 51704511ab..d572823e2e 100644 --- a/refaster-compiler/pom.xml +++ b/refaster-compiler/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.7.0 + 0.7.1-SNAPSHOT refaster-compiler diff --git a/refaster-runner/pom.xml b/refaster-runner/pom.xml index 93b4fd8fd2..4fdbb5c747 100644 --- a/refaster-runner/pom.xml +++ b/refaster-runner/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.7.0 + 0.7.1-SNAPSHOT refaster-runner diff --git a/refaster-support/pom.xml b/refaster-support/pom.xml index 6f64260e12..10cdc5c48f 100644 --- a/refaster-support/pom.xml +++ b/refaster-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.7.0 + 0.7.1-SNAPSHOT refaster-support diff --git a/refaster-test-support/pom.xml b/refaster-test-support/pom.xml index e00187b6f9..6281bbfd74 100644 --- a/refaster-test-support/pom.xml +++ b/refaster-test-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.7.0 + 0.7.1-SNAPSHOT refaster-test-support From feb9abfa91b3b149661131c9b52805353baa6b96 Mon Sep 17 00:00:00 2001 From: Benedek Halasi Date: Fri, 6 Jan 2023 14:57:12 +0100 Subject: [PATCH 153/601] Introduce `MapGetOrDefault` Refaster rule (#439) Fixes #431. --- .../errorprone/refasterrules/MapRules.java | 17 +++++++++++++++++ .../refasterrules/MapRulesTestInput.java | 8 +++++++- .../refasterrules/MapRulesTestOutput.java | 8 +++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java index cdf99f5e60..b9610c255c 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java @@ -1,5 +1,7 @@ package tech.picnic.errorprone.refasterrules; +import static java.util.Objects.requireNonNullElse; + import com.google.errorprone.refaster.Refaster; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; @@ -43,6 +45,21 @@ V after(Map map, T key) { } } + /** Prefer {@link Map#getOrDefault(Object, Object)} over more contrived alternatives. */ + // XXX: Note that `requireNonNullElse` throws an NPE if the second argument is `null`, while the + // alternative does not. + static final class MapGetOrDefault { + @BeforeTemplate + V before(Map map, T key, V defaultValue) { + return requireNonNullElse(map.get(key), defaultValue); + } + + @AfterTemplate + V after(Map map, T key, V defaultValue) { + return map.getOrDefault(key, defaultValue); + } + } + /** Prefer {@link Map#isEmpty()} over more contrived alternatives. */ static final class MapIsEmpty { @BeforeTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java index a8dc6e7fa4..707243ba4d 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestInput.java @@ -1,5 +1,7 @@ package tech.picnic.errorprone.refasterrules; +import static java.util.Objects.requireNonNullElse; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.math.RoundingMode; @@ -11,7 +13,7 @@ final class MapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(HashMap.class); + return ImmutableSet.of(HashMap.class, requireNonNullElse(null, null)); } Map testCreateEnumMap() { @@ -22,6 +24,10 @@ String testMapGetOrNull() { return ImmutableMap.of(1, "foo").getOrDefault("bar", null); } + String testMapGetOrDefault() { + return requireNonNullElse(ImmutableMap.of(1, "foo").get("bar"), "baz"); + } + ImmutableSet testMapIsEmpty() { return ImmutableSet.of( ImmutableMap.of("foo", 1).keySet().isEmpty(), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java index 650cd4094f..9214fa6f79 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/MapRulesTestOutput.java @@ -1,5 +1,7 @@ package tech.picnic.errorprone.refasterrules; +import static java.util.Objects.requireNonNullElse; + import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.math.RoundingMode; @@ -12,7 +14,7 @@ final class MapRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(HashMap.class); + return ImmutableSet.of(HashMap.class, requireNonNullElse(null, null)); } Map testCreateEnumMap() { @@ -23,6 +25,10 @@ String testMapGetOrNull() { return ImmutableMap.of(1, "foo").get("bar"); } + String testMapGetOrDefault() { + return ImmutableMap.of(1, "foo").getOrDefault("bar", "baz"); + } + ImmutableSet testMapIsEmpty() { return ImmutableSet.of( ImmutableMap.of("foo", 1).isEmpty(), From 6370452803293bf7ade4c4046fa2cb053c132570 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 8 Jan 2023 12:16:52 +0100 Subject: [PATCH 154/601] Upgrade swagger-annotations 2.2.7 -> 2.2.8 (#452) See: - https://github.com/swagger-api/swagger-core/releases/tag/v2.2.8 - https://github.com/swagger-api/swagger-core/compare/v2.2.7...v2.2.8 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c9cb944a6e..fef0307323 100644 --- a/pom.xml +++ b/pom.xml @@ -298,7 +298,7 @@ io.swagger.core.v3 swagger-annotations - 2.2.7 + 2.2.8 jakarta.servlet From 9bd4b1600197882ce3d5626467c1914a39aba7cd Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Sun, 8 Jan 2023 12:40:20 +0100 Subject: [PATCH 155/601] Inline most `{BugCheckerRefactoring,Compilation}TestHelper` fields (#442) --- .../bugpatterns/AmbiguousJsonCreatorTest.java | 17 +++---- .../bugpatterns/AssertJIsNullTest.java | 9 +--- .../bugpatterns/AutowiredConstructorTest.java | 9 +--- .../CanonicalAnnotationSyntaxTest.java | 9 +--- .../bugpatterns/CollectorMutabilityTest.java | 13 ++---- .../bugpatterns/EmptyMethodTest.java | 9 +--- .../ErrorProneTestHelperSourceFormatTest.java | 10 +---- .../bugpatterns/ExplicitEnumOrderingTest.java | 5 +-- .../bugpatterns/FluxFlatMapUsageTest.java | 13 ++---- .../FormatStringConcatenationTest.java | 9 +--- .../bugpatterns/IdentityConversionTest.java | 11 ++--- .../ImmutablesSortedSetComparatorTest.java | 11 ++--- .../IsInstanceLambdaUsageTest.java | 9 +--- .../bugpatterns/JUnitClassModifiersTest.java | 9 +--- .../JUnitMethodDeclarationTest.java | 9 +--- ...aphicalAnnotationAttributeListingTest.java | 24 ++++------ .../LexicographicalAnnotationListingTest.java | 10 +---- .../bugpatterns/MethodReferenceUsageTest.java | 9 +--- .../MissingRefasterAnnotationTest.java | 12 ++--- .../bugpatterns/MockitoStubbingTest.java | 9 +--- .../bugpatterns/NestedOptionalsTest.java | 7 +-- .../bugpatterns/NonEmptyMonoTest.java | 9 +--- .../bugpatterns/PrimitiveComparisonTest.java | 45 +++++++++---------- .../RedundantStringConversionTest.java | 14 +++--- .../bugpatterns/RefasterAnyOfUsageTest.java | 9 +--- .../RefasterRuleModifiersTest.java | 9 +--- .../RequestMappingAnnotationTest.java | 5 +-- .../bugpatterns/RequestParamTypeTest.java | 13 ++---- .../ScheduledTransactionTraceTest.java | 11 ++--- .../bugpatterns/Slf4jLogStatementTest.java | 9 +--- .../bugpatterns/SpringMvcAnnotationTest.java | 9 +--- .../bugpatterns/StaticImportTest.java | 9 +--- .../StringCaseLocaleUsageTest.java | 13 ++---- .../bugpatterns/StringJoinTest.java | 15 +++---- .../bugpatterns/TimeZoneUsageTest.java | 5 +-- .../util/MethodMatcherFactoryTest.java | 5 +-- .../refaster/runner/RefasterTest.java | 12 ++--- 37 files changed, 118 insertions(+), 297 deletions(-) diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AmbiguousJsonCreatorTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AmbiguousJsonCreatorTest.java index f5a7b641ad..785642de02 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AmbiguousJsonCreatorTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AmbiguousJsonCreatorTest.java @@ -3,21 +3,16 @@ import static com.google.common.base.Predicates.containsPattern; import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.CompilationTestHelper; import org.junit.jupiter.api.Test; final class AmbiguousJsonCreatorTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(AmbiguousJsonCreator.class, getClass()) - .expectErrorMessage( - "X", - containsPattern("`JsonCreator.Mode` should be set for single-argument creators")); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(AmbiguousJsonCreator.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(AmbiguousJsonCreator.class, getClass()) + .expectErrorMessage( + "X", containsPattern("`JsonCreator.Mode` should be set for single-argument creators")) .addSourceLines( "Container.java", "import com.fasterxml.jackson.annotation.JsonCreator;", @@ -118,7 +113,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(AmbiguousJsonCreator.class, getClass()) .addInputLines( "A.java", "import com.fasterxml.jackson.annotation.JsonCreator;", @@ -143,6 +138,6 @@ void replacement() { " return FOO;", " }", "}") - .doTest(BugCheckerRefactoringTestHelper.TestMode.TEXT_MATCH); + .doTest(TestMode.TEXT_MATCH); } } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AssertJIsNullTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AssertJIsNullTest.java index a0f8242dfb..706a835de9 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AssertJIsNullTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AssertJIsNullTest.java @@ -7,14 +7,9 @@ import org.junit.jupiter.api.Test; final class AssertJIsNullTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(AssertJIsNull.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(AssertJIsNull.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(AssertJIsNull.class, getClass()) .addSourceLines( "A.java", "import static org.assertj.core.api.Assertions.assertThat;", @@ -38,7 +33,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(AssertJIsNull.class, getClass()) .addInputLines( "A.java", "import static org.assertj.core.api.Assertions.assertThat;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AutowiredConstructorTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AutowiredConstructorTest.java index ad63927d6a..12276bc591 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AutowiredConstructorTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AutowiredConstructorTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class AutowiredConstructorTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(AutowiredConstructor.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(AutowiredConstructor.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(AutowiredConstructor.class, getClass()) .addSourceLines( "Container.java", "import com.google.errorprone.annotations.Immutable;", @@ -71,7 +66,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(AutowiredConstructor.class, getClass()) .addInputLines( "Container.java", "import org.springframework.beans.factory.annotation.Autowired;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalAnnotationSyntaxTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalAnnotationSyntaxTest.java index e3c9b9e924..150d386682 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalAnnotationSyntaxTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalAnnotationSyntaxTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class CanonicalAnnotationSyntaxTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(CanonicalAnnotationSyntax.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(CanonicalAnnotationSyntax.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(CanonicalAnnotationSyntax.class, getClass()) .addSourceLines( "pkg/A.java", "package pkg;", @@ -133,7 +128,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(CanonicalAnnotationSyntax.class, getClass()) .addInputLines( "pkg/A.java", "package pkg;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CollectorMutabilityTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CollectorMutabilityTest.java index 1b837e61b5..d4e7f1310b 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CollectorMutabilityTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CollectorMutabilityTest.java @@ -8,14 +8,9 @@ import org.junit.jupiter.api.Test; final class CollectorMutabilityTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(CollectorMutability.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(CollectorMutability.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(CollectorMutability.class, getClass()) .addSourceLines( "A.java", "import static com.google.common.collect.ImmutableList.toImmutableList;", @@ -67,7 +62,7 @@ void identification() { @Test void identificationWithoutGuavaOnClasspath() { - compilationTestHelper + CompilationTestHelper.newInstance(CollectorMutability.class, getClass()) .withClasspath() .addSourceLines( "A.java", @@ -84,7 +79,7 @@ void identificationWithoutGuavaOnClasspath() { @Test void replacementFirstSuggestedFix() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(CollectorMutability.class, getClass()) .addInputLines( "A.java", "import static java.util.stream.Collectors.toList;", @@ -141,7 +136,7 @@ void replacementFirstSuggestedFix() { @Test void replacementSecondSuggestedFix() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(CollectorMutability.class, getClass()) .setFixChooser(SECOND) .addInputLines( "A.java", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/EmptyMethodTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/EmptyMethodTest.java index e7a4bc6f10..e2bbf87a5d 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/EmptyMethodTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/EmptyMethodTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class EmptyMethodTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(EmptyMethod.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(EmptyMethod.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(EmptyMethod.class, getClass()) .addSourceLines( "A.java", "class A {", @@ -69,7 +64,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(EmptyMethod.class, getClass()) .addInputLines( "A.java", "final class A {", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormatTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormatTest.java index be6e20306a..46be750780 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormatTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormatTest.java @@ -6,15 +6,9 @@ import org.junit.jupiter.api.Test; final class ErrorProneTestHelperSourceFormatTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(ErrorProneTestHelperSourceFormat.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance( - ErrorProneTestHelperSourceFormat.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(ErrorProneTestHelperSourceFormat.class, getClass()) .addSourceLines( "A.java", "import com.google.errorprone.BugCheckerRefactoringTestHelper;", @@ -63,7 +57,7 @@ void replacement() { * Verifies that import sorting and code formatting is performed unconditionally, while unused * imports are removed unless part of a `BugCheckerRefactoringTestHelper` expected output file. */ - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(ErrorProneTestHelperSourceFormat.class, getClass()) .addInputLines( "A.java", "import com.google.errorprone.BugCheckerRefactoringTestHelper;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrderingTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrderingTest.java index 3a8119a0ce..7afdf30ac3 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrderingTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrderingTest.java @@ -4,12 +4,9 @@ import org.junit.jupiter.api.Test; final class ExplicitEnumOrderingTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(ExplicitEnumOrdering.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(ExplicitEnumOrdering.class, getClass()) .addSourceLines( "A.java", "import static java.lang.annotation.RetentionPolicy.CLASS;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsageTest.java index a80414e18b..410993f614 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsageTest.java @@ -1,7 +1,5 @@ package tech.picnic.errorprone.bugpatterns; -import static com.google.errorprone.BugCheckerRefactoringTestHelper.newInstance; - import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; @@ -9,14 +7,9 @@ import org.junit.jupiter.api.Test; final class FluxFlatMapUsageTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(FluxFlatMapUsage.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - newInstance(FluxFlatMapUsage.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(FluxFlatMapUsage.class, getClass()) .addSourceLines( "A.java", "import java.util.function.BiFunction;", @@ -73,7 +66,7 @@ void identification() { @Test void replacementFirstSuggestedFix() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(FluxFlatMapUsage.class, getClass()) .setFixChooser(FixChoosers.FIRST) .addInputLines( "A.java", @@ -108,7 +101,7 @@ void replacementFirstSuggestedFix() { @Test void replacementSecondSuggestedFix() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(FluxFlatMapUsage.class, getClass()) .setFixChooser(FixChoosers.SECOND) .addInputLines( "A.java", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenationTest.java index 3eac62e01c..cf300ebf4d 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenationTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class FormatStringConcatenationTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(FormatStringConcatenation.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(FormatStringConcatenation.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(FormatStringConcatenation.class, getClass()) .addSourceLines( "A.java", "import static com.google.common.base.Preconditions.checkArgument;", @@ -309,7 +304,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(FormatStringConcatenation.class, getClass()) .addInputLines( "A.java", "import static com.google.common.base.Preconditions.checkArgument;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java index 03d6c3fd72..9341c76433 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java @@ -7,14 +7,9 @@ import org.junit.jupiter.api.Test; final class IdentityConversionTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(IdentityConversion.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(IdentityConversion.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(IdentityConversion.class, getClass()) .addSourceLines( "A.java", "import static com.google.errorprone.matchers.Matchers.instanceMethod;", @@ -184,7 +179,7 @@ void identification() { @Test void replacementFirstSuggestedFix() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(IdentityConversion.class, getClass()) .setFixChooser(FixChoosers.FIRST) .addInputLines( "A.java", @@ -291,7 +286,7 @@ void replacementFirstSuggestedFix() { @Test void replacementSecondSuggestedFix() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(IdentityConversion.class, getClass()) .setFixChooser(FixChoosers.SECOND) .addInputLines( "A.java", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ImmutablesSortedSetComparatorTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ImmutablesSortedSetComparatorTest.java index 3942c6de1e..b77767af84 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ImmutablesSortedSetComparatorTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ImmutablesSortedSetComparatorTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class ImmutablesSortedSetComparatorTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(ImmutablesSortedSetComparator.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(ImmutablesSortedSetComparator.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(ImmutablesSortedSetComparator.class, getClass()) .addSourceLines( "A.java", "import com.google.common.collect.ContiguousSet;", @@ -109,7 +104,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(ImmutablesSortedSetComparator.class, getClass()) .addInputLines( "A.java", "import com.google.common.collect.ImmutableSortedSet;", @@ -147,7 +142,7 @@ void replacement() { @Test void replacementWithImportClash() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(ImmutablesSortedSetComparator.class, getClass()) .addInputLines( "MySpringService.java", "import com.google.common.collect.ImmutableSortedSet;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IsInstanceLambdaUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IsInstanceLambdaUsageTest.java index 3249f5a464..a6204c5abf 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IsInstanceLambdaUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IsInstanceLambdaUsageTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class IsInstanceLambdaUsageTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(IsInstanceLambdaUsage.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(IsInstanceLambdaUsage.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(IsInstanceLambdaUsage.class, getClass()) .addSourceLines( "A.java", "import java.util.stream.Stream;", @@ -46,7 +41,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(IsInstanceLambdaUsage.class, getClass()) .addInputLines( "A.java", "import java.util.stream.Stream;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiersTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiersTest.java index 042a4e9d60..7d2ab28537 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiersTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitClassModifiersTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class JUnitClassModifiersTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(JUnitClassModifiers.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(JUnitClassModifiers.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(JUnitClassModifiers.class, getClass()) .addSourceLines( "Container.java", "import org.junit.jupiter.api.Test;", @@ -98,7 +93,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(JUnitClassModifiers.class, getClass()) .addInputLines( "A.java", "import org.junit.jupiter.api.Test;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitMethodDeclarationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitMethodDeclarationTest.java index 92f2e16b8f..b4c016da5f 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitMethodDeclarationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitMethodDeclarationTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class JUnitMethodDeclarationTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(JUnitMethodDeclaration.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(JUnitMethodDeclaration.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(JUnitMethodDeclaration.class, getClass()) .addSourceLines( "A.java", "import static org.junit.jupiter.params.provider.Arguments.arguments;", @@ -345,7 +340,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(JUnitMethodDeclaration.class, getClass()) .addInputLines( "A.java", "import static org.junit.jupiter.params.provider.Arguments.arguments;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListingTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListingTest.java index b7a204c457..43fb54c0e2 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListingTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListingTest.java @@ -7,22 +7,9 @@ import org.junit.jupiter.api.Test; final class LexicographicalAnnotationAttributeListingTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance( - LexicographicalAnnotationAttributeListing.class, getClass()); - private final CompilationTestHelper restrictedCompilationTestHelper = - CompilationTestHelper.newInstance(LexicographicalAnnotationAttributeListing.class, getClass()) - .setArgs( - ImmutableList.of( - "-XepOpt:LexicographicalAnnotationAttributeListing:Includes=pkg.A.Foo,pkg.A.Bar", - "-XepOpt:LexicographicalAnnotationAttributeListing:Excludes=pkg.A.Bar#value")); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance( - LexicographicalAnnotationAttributeListing.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(LexicographicalAnnotationAttributeListing.class, getClass()) .addSourceLines( "A.java", "import static java.math.RoundingMode.DOWN;", @@ -165,7 +152,8 @@ void identification() { // `CanonicalAnnotationSyntax` checker correct the situation in a subsequent run. @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance( + LexicographicalAnnotationAttributeListing.class, getClass()) .addInputLines( "A.java", "import static java.math.RoundingMode.DOWN;", @@ -246,7 +234,11 @@ void replacement() { @Test void filtering() { /* Some violations are not flagged because they are not in- or excluded. */ - restrictedCompilationTestHelper + CompilationTestHelper.newInstance(LexicographicalAnnotationAttributeListing.class, getClass()) + .setArgs( + ImmutableList.of( + "-XepOpt:LexicographicalAnnotationAttributeListing:Includes=pkg.A.Foo,pkg.A.Bar", + "-XepOpt:LexicographicalAnnotationAttributeListing:Excludes=pkg.A.Bar#value")) .addSourceLines( "pkg/A.java", "package pkg;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListingTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListingTest.java index 287a0e95f3..dd9722e77a 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListingTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListingTest.java @@ -6,15 +6,9 @@ import org.junit.jupiter.api.Test; final class LexicographicalAnnotationListingTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(LexicographicalAnnotationListing.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance( - LexicographicalAnnotationListing.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(LexicographicalAnnotationListing.class, getClass()) .addSourceLines( "A.java", "import java.lang.annotation.ElementType;", @@ -133,7 +127,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(LexicographicalAnnotationListing.class, getClass()) .addInputLines( "A.java", "import java.lang.annotation.ElementType;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MethodReferenceUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MethodReferenceUsageTest.java index 1ae63913ee..ca583d92e6 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MethodReferenceUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MethodReferenceUsageTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class MethodReferenceUsageTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(MethodReferenceUsage.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(MethodReferenceUsage.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(MethodReferenceUsage.class, getClass()) .addSourceLines( "A.java", "import com.google.common.collect.Streams;", @@ -323,7 +318,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(MethodReferenceUsage.class, getClass()) .addInputLines( "A.java", "import static java.util.Collections.emptyList;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotationTest.java index 74b2fcbfa0..b3ca1fd0c9 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotationTest.java @@ -6,16 +6,12 @@ import org.junit.jupiter.api.Test; final class MissingRefasterAnnotationTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(MissingRefasterAnnotation.class, getClass()) - .expectErrorMessage( - "X", - containsPattern( - "The Refaster rule contains a method without any Refaster annotations")); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(MissingRefasterAnnotation.class, getClass()) + .expectErrorMessage( + "X", + containsPattern("The Refaster rule contains a method without any Refaster annotations")) .addSourceLines( "A.java", "import com.google.errorprone.refaster.annotation.AfterTemplate;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MockitoStubbingTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MockitoStubbingTest.java index a1725d4b02..7a806301e8 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MockitoStubbingTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MockitoStubbingTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class MockitoStubbingTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(MockitoStubbing.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(MockitoStubbing.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(MockitoStubbing.class, getClass()) .addSourceLines( "A.java", "import static org.mockito.ArgumentMatchers.eq;", @@ -55,7 +50,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(MockitoStubbing.class, getClass()) .addInputLines( "A.java", "import static org.mockito.ArgumentMatchers.eq;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java index 5cebca69e5..62c5fb35fb 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java @@ -4,12 +4,9 @@ import org.junit.jupiter.api.Test; final class NestedOptionalsTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(NestedOptionals.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(NestedOptionals.class, getClass()) .addSourceLines( "A.java", "import java.util.Optional;", @@ -42,7 +39,7 @@ void identification() { @Test void identificationOptionalTypeNotLoaded() { - compilationTestHelper + CompilationTestHelper.newInstance(NestedOptionals.class, getClass()) .addSourceLines( "A.java", "import java.time.Duration;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NonEmptyMonoTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NonEmptyMonoTest.java index c4e79c91a8..ff33c78d4a 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NonEmptyMonoTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NonEmptyMonoTest.java @@ -7,14 +7,9 @@ import org.junit.jupiter.api.Test; final class NonEmptyMonoTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(NonEmptyMono.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(NonEmptyMono.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(NonEmptyMono.class, getClass()) .addSourceLines( "A.java", "import static com.google.common.collect.ImmutableList.toImmutableList;", @@ -111,7 +106,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(NonEmptyMono.class, getClass()) .addInputLines( "A.java", "import static com.google.common.collect.ImmutableList.toImmutableList;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparisonTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparisonTest.java index 276fb3633d..e205fb1c19 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparisonTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparisonTest.java @@ -5,22 +5,19 @@ import com.google.errorprone.CompilationTestHelper; import org.junit.jupiter.api.Test; +// XXX: There are no tests for multiple replacements within the same expression: +// - Error Prone doesn't currently support this, it seems. +// - The `BugCheckerRefactoringTestHelper` throws an exception in this case. +// - During actual compilation only the first replacement is applied. +// XXX: Can we perhaps work-around this by describing the fixes in reverse order? final class PrimitiveComparisonTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(PrimitiveComparison.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(PrimitiveComparison.class, getClass()); - - // XXX: There are no tests for multiple replacements within the same expression: - // - Error Prone doesn't currently support this, it seems. - // - The `BugCheckerRefactoringTestHelper` throws an exception in this case. - // - During actual compilation only the first replacement is applied. - // XXX: Can we perhaps work-around this by describing the fixes in reverse order? - - // The logic for `char` and `short` is exactly analogous to the `byte` case. + /** + * @implNote The logic for {@code char} and {@code short} is exactly analogous to the {@code byte} + * case. + */ @Test void byteComparison() { - compilationTestHelper + CompilationTestHelper.newInstance(PrimitiveComparison.class, getClass()) .addSourceLines( "A.java", "import java.util.Comparator;", @@ -120,7 +117,7 @@ void byteComparison() { @Test void intComparison() { - compilationTestHelper + CompilationTestHelper.newInstance(PrimitiveComparison.class, getClass()) .addSourceLines( "A.java", "import java.util.Comparator;", @@ -227,7 +224,7 @@ void intComparison() { @Test void longComparison() { - compilationTestHelper + CompilationTestHelper.newInstance(PrimitiveComparison.class, getClass()) .addSourceLines( "A.java", "import java.util.Comparator;", @@ -318,7 +315,7 @@ void longComparison() { @Test void floatComparison() { - compilationTestHelper + CompilationTestHelper.newInstance(PrimitiveComparison.class, getClass()) .addSourceLines( "A.java", "import java.util.Comparator;", @@ -386,7 +383,7 @@ void floatComparison() { @Test void doubleComparison() { - compilationTestHelper + CompilationTestHelper.newInstance(PrimitiveComparison.class, getClass()) .addSourceLines( "A.java", "import java.util.Comparator;", @@ -461,7 +458,7 @@ void doubleComparison() { @Test void stringComparison() { - compilationTestHelper + CompilationTestHelper.newInstance(PrimitiveComparison.class, getClass()) .addSourceLines( "A.java", "import java.util.Comparator;", @@ -497,7 +494,7 @@ void stringComparison() { @Test void replacementWithPrimitiveVariants() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(PrimitiveComparison.class, getClass()) .addInputLines( "A.java", "import java.util.Comparator;", @@ -577,7 +574,7 @@ void replacementWithPrimitiveVariants() { @Test void replacementWithBoxedVariants() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(PrimitiveComparison.class, getClass()) .addInputLines( "A.java", "import java.util.Comparator;", @@ -643,7 +640,7 @@ void replacementWithBoxedVariants() { @Test void replacementWithPrimitiveVariantsUsingStaticImports() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(PrimitiveComparison.class, getClass()) .addInputLines( "A.java", "import static java.util.Comparator.comparing;", @@ -682,7 +679,7 @@ void replacementWithPrimitiveVariantsUsingStaticImports() { @Test void replacementWithBoxedVariantsUsingStaticImports() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(PrimitiveComparison.class, getClass()) .addInputLines( "A.java", "import static java.util.Comparator.comparingDouble;", @@ -723,7 +720,7 @@ void replacementWithBoxedVariantsUsingStaticImports() { @Test void replacementWithPrimitiveVariantsInComplexSyntacticalContext() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(PrimitiveComparison.class, getClass()) .addInputLines( "A.java", "import java.util.Comparator;", @@ -755,7 +752,7 @@ void replacementWithPrimitiveVariantsInComplexSyntacticalContext() { @Test void replacementWithBoxedVariantsInComplexSyntacticalContext() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(PrimitiveComparison.class, getClass()) .addInputLines( "A.java", "import java.util.Comparator;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversionTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversionTest.java index 62f82b3f5a..f3d6f018c6 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversionTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversionTest.java @@ -12,13 +12,6 @@ final class RedundantStringConversionTest { private final CompilationTestHelper compilationTestHelper = CompilationTestHelper.newInstance(RedundantStringConversion.class, getClass()); - private final CompilationTestHelper customizedCompilationTestHelper = - CompilationTestHelper.newInstance(RedundantStringConversion.class, getClass()) - .setArgs( - ImmutableList.of( - "-XepOpt:RedundantStringConversion:ExtraConversionMethods=java.lang.Enum#name(),A#name(),A.B#toString(int)")); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(RedundantStringConversion.class, getClass()); @Test void identificationOfIdentityTransformation() { @@ -416,7 +409,10 @@ void identificationWithinSlf4jLoggerMethod() { @Test void identificationOfCustomConversionMethod() { - customizedCompilationTestHelper + CompilationTestHelper.newInstance(RedundantStringConversion.class, getClass()) + .setArgs( + ImmutableList.of( + "-XepOpt:RedundantStringConversion:ExtraConversionMethods=java.lang.Enum#name(),A#name(),A.B#toString(int)")) .addSourceLines( "A.java", "import java.math.RoundingMode;", @@ -509,7 +505,7 @@ void identificationOfCustomConversionMethod() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(RedundantStringConversion.class, getClass()) .addInputLines( "A.java", "class A {", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterAnyOfUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterAnyOfUsageTest.java index 20db60b0b6..c00458c7a0 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterAnyOfUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterAnyOfUsageTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class RefasterAnyOfUsageTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(RefasterAnyOfUsage.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(RefasterAnyOfUsage.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(RefasterAnyOfUsage.class, getClass()) .addSourceLines( "A.java", "import com.google.errorprone.refaster.Refaster;", @@ -38,7 +33,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(RefasterAnyOfUsage.class, getClass()) .addInputLines( "A.java", "import com.google.errorprone.refaster.Refaster;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiersTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiersTest.java index c21a784925..c2e2f287a9 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiersTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RefasterRuleModifiersTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class RefasterRuleModifiersTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(RefasterRuleModifiers.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(RefasterRuleModifiers.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(RefasterRuleModifiers.class, getClass()) .addSourceLines( "A.java", "import com.google.errorprone.refaster.annotation.BeforeTemplate;", @@ -136,7 +131,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(RefasterRuleModifiers.class, getClass()) .addInputLines( "A.java", "import com.google.errorprone.refaster.annotation.BeforeTemplate;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java index 3859356558..947e06e677 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java @@ -4,12 +4,9 @@ import org.junit.jupiter.api.Test; final class RequestMappingAnnotationTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(RequestMappingAnnotation.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(RequestMappingAnnotation.class, getClass()) .addSourceLines( "A.java", "import java.io.InputStream;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java index 97b4c3cc4b..38616e4ea0 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestParamTypeTest.java @@ -4,16 +4,9 @@ import org.junit.jupiter.api.Test; final class RequestParamTypeTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(RequestParamType.class, getClass()); - private final CompilationTestHelper restrictedCompilationTestHelper = - CompilationTestHelper.newInstance(RequestParamType.class, getClass()) - .setArgs( - "-XepOpt:RequestParamType:SupportedCustomTypes=com.google.common.collect.ImmutableSet,com.google.common.collect.ImmutableSortedMultiset"); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(RequestParamType.class, getClass()) .addSourceLines( "A.java", "import com.google.common.collect.ImmutableBiMap;", @@ -70,7 +63,9 @@ void identification() { @Test void identificationRestricted() { - restrictedCompilationTestHelper + CompilationTestHelper.newInstance(RequestParamType.class, getClass()) + .setArgs( + "-XepOpt:RequestParamType:SupportedCustomTypes=com.google.common.collect.ImmutableSet,com.google.common.collect.ImmutableSortedMultiset") .addSourceLines( "A.java", "import com.google.common.collect.ImmutableBiMap;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTraceTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTraceTest.java index 95478fe712..c61a99a8ca 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTraceTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTraceTest.java @@ -7,14 +7,9 @@ import org.springframework.scheduling.annotation.Scheduled; final class ScheduledTransactionTraceTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(ScheduledTransactionTrace.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(ScheduledTransactionTrace.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(ScheduledTransactionTrace.class, getClass()) .addSourceLines( "A.java", "import com.newrelic.api.agent.Trace;", @@ -46,7 +41,7 @@ void identification() { @Test void identificationWithoutNewRelicAgentApiOnClasspath() { - compilationTestHelper + CompilationTestHelper.newInstance(ScheduledTransactionTrace.class, getClass()) .withClasspath(Scheduled.class) .addSourceLines( "A.java", @@ -61,7 +56,7 @@ void identificationWithoutNewRelicAgentApiOnClasspath() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(ScheduledTransactionTrace.class, getClass()) .addInputLines( "A.java", "import com.newrelic.api.agent.Trace;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogStatementTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogStatementTest.java index 5900a45071..bd03f35e2e 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogStatementTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/Slf4jLogStatementTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class Slf4jLogStatementTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(Slf4jLogStatement.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(Slf4jLogStatement.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(Slf4jLogStatement.class, getClass()) .addSourceLines( "A.java", "import org.slf4j.Logger;", @@ -96,7 +91,7 @@ void identification() { // XXX: Drop what's unused. @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(Slf4jLogStatement.class, getClass()) .addInputLines( "A.java", "import org.slf4j.Logger;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotationTest.java index ee47ad2a7f..b28562c0a4 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotationTest.java @@ -6,14 +6,9 @@ import org.junit.jupiter.api.Test; final class SpringMvcAnnotationTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(SpringMvcAnnotation.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(SpringMvcAnnotation.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(SpringMvcAnnotation.class, getClass()) .addSourceLines( "A.java", "import static org.springframework.web.bind.annotation.RequestMethod.DELETE;", @@ -85,7 +80,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(SpringMvcAnnotation.class, getClass()) .addInputLines( "A.java", "import static org.springframework.web.bind.annotation.RequestMethod.PATCH;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java index 861ea8421d..d876f41082 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java @@ -8,11 +8,6 @@ import org.junit.jupiter.api.Test; final class StaticImportTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(StaticImport.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(StaticImport.class, getClass()); - @Test void candidateMethodsAreNotRedundant() { assertThat(StaticImport.STATIC_IMPORT_CANDIDATE_MEMBERS.keySet()) @@ -33,7 +28,7 @@ void exemptedMembersAreNotRedundant() { @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(StaticImport.class, getClass()) .addSourceLines( "A.java", "import static com.google.common.collect.ImmutableMap.toImmutableMap;", @@ -118,7 +113,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(StaticImport.class, getClass()) .addInputLines( "A.java", "import static java.util.function.Predicate.not;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java index caec7843c3..b1865d6089 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java @@ -1,7 +1,5 @@ package tech.picnic.errorprone.bugpatterns; -import static com.google.errorprone.BugCheckerRefactoringTestHelper.newInstance; - import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; @@ -9,14 +7,9 @@ import org.junit.jupiter.api.Test; final class StringCaseLocaleUsageTest { - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(StringCaseLocaleUsage.class, getClass()); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - newInstance(StringCaseLocaleUsage.class, getClass()); - @Test void identification() { - compilationTestHelper + CompilationTestHelper.newInstance(StringCaseLocaleUsage.class, getClass()) .addSourceLines( "A.java", "import static java.util.Locale.ROOT;", @@ -54,7 +47,7 @@ void identification() { @Test void replacementFirstSuggestedFix() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(StringCaseLocaleUsage.class, getClass()) .setFixChooser(FixChoosers.FIRST) .addInputLines( "A.java", @@ -93,7 +86,7 @@ void replacementFirstSuggestedFix() { @Test void replacementSecondSuggestedFix() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(StringCaseLocaleUsage.class, getClass()) .setFixChooser(FixChoosers.SECOND) .addInputLines( "A.java", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringJoinTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringJoinTest.java index 2dcd7ed510..379fc830ed 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringJoinTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringJoinTest.java @@ -8,17 +8,12 @@ import org.junit.jupiter.api.Test; final class StringJoinTest { - private final CompilationTestHelper compilationHelper = - CompilationTestHelper.newInstance(StringJoin.class, getClass()) - .expectErrorMessage( - "valueOf", containsPattern("Prefer `String#valueOf` over `String#format`")) - .expectErrorMessage("join", containsPattern("Prefer `String#join` over `String#format`")); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(StringJoin.class, getClass()); - @Test void identification() { - compilationHelper + CompilationTestHelper.newInstance(StringJoin.class, getClass()) + .expectErrorMessage( + "valueOf", containsPattern("Prefer `String#valueOf` over `String#format`")) + .expectErrorMessage("join", containsPattern("Prefer `String#join` over `String#format`")) .addSourceLines( "A.java", "import java.util.Formattable;", @@ -63,7 +58,7 @@ void identification() { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(StringJoin.class, getClass()) .addInputLines( "A.java", "class A {", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsageTest.java index ad4e8a8b07..abca2d4ec6 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsageTest.java @@ -4,12 +4,9 @@ import org.junit.jupiter.api.Test; final class TimeZoneUsageTest { - private final CompilationTestHelper compilationHelper = - CompilationTestHelper.newInstance(TimeZoneUsage.class, getClass()); - @Test void identification() { - compilationHelper + CompilationTestHelper.newInstance(TimeZoneUsage.class, getClass()) .addSourceLines( "A.java", "import static java.time.ZoneOffset.UTC;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MethodMatcherFactoryTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MethodMatcherFactoryTest.java index 782b5f77c9..62b6e66071 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MethodMatcherFactoryTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MethodMatcherFactoryTest.java @@ -40,9 +40,6 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState "com.example.A#m2(java.lang.String)", "com.example.sub.B#m3(int,int)")); - private final CompilationTestHelper compilationTestHelper = - CompilationTestHelper.newInstance(MatchedMethodsFlagger.class, getClass()); - @Test void createWithMalformedSignatures() { MethodMatcherFactory factory = new MethodMatcherFactory(); @@ -58,7 +55,7 @@ void createWithMalformedSignatures() { @Test void matcher() { - compilationTestHelper + CompilationTestHelper.newInstance(MatchedMethodsFlagger.class, getClass()) .addSourceLines( "com/example/A.java", "package com.example;", diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java index 8ec4e5122c..11db1cd771 100644 --- a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java @@ -50,12 +50,6 @@ final class RefasterTest { "\\[Refaster Rule\\] FooRules\\.ExtraGrouping\\.StringOfSizeThreeRule: " + "A custom description about matching three-char strings\\s+.+\\s+" + "\\(see https://example.com/custom\\)")); - private final BugCheckerRefactoringTestHelper refactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(Refaster.class, getClass()); - private final BugCheckerRefactoringTestHelper restrictedRefactoringTestHelper = - BugCheckerRefactoringTestHelper.newInstance(Refaster.class, getClass()) - .setArgs( - "-XepOpt:Refaster:NamePattern=.*\\$(StringOfSizeZeroVerboseRule|StringOfSizeTwoRule)$"); @Test void identification() { @@ -220,7 +214,7 @@ private static SeverityLevel toSeverityLevel(String compilerDiagnosticsPrefix) { @Test void replacement() { - refactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(Refaster.class, getClass()) .addInputLines( "A.java", "class A {", @@ -246,7 +240,9 @@ void replacement() { @Test void restrictedReplacement() { - restrictedRefactoringTestHelper + BugCheckerRefactoringTestHelper.newInstance(Refaster.class, getClass()) + .setArgs( + "-XepOpt:Refaster:NamePattern=.*\\$(StringOfSizeZeroVerboseRule|StringOfSizeTwoRule)$") .addInputLines( "A.java", "class A {", From 3c89a1c80d81e01bbe5ff3253fa5dd97c49068de Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 9 Jan 2023 09:05:59 +0100 Subject: [PATCH 156/601] Upgrade AssertJ 3.24.0 -> 3.24.1 (#453) See: - https://assertj.github.io/doc/#assertj-core-release-notes - https://github.com/assertj/assertj/compare/assertj-build-3.24.0...assertj-build-3.24.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fef0307323..9493fbd19a 100644 --- a/pom.xml +++ b/pom.xml @@ -338,7 +338,7 @@ org.assertj assertj-bom - 3.24.0 + 3.24.1 pom import From 8e24da907d0498f5f8913083399a2938092d53bd Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 11 Jan 2023 11:16:10 +0100 Subject: [PATCH 157/601] Upgrade JUnit Jupiter 5.9.1 -> 5.9.2 (#457) See: - https://junit.org/junit5/docs/current/release-notes/index.html - https://github.com/junit-team/junit5/releases/tag/r5.9.2 - https://github.com/junit-team/junit5/compare/r5.9.1...r5.9.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9493fbd19a..911e289d86 100644 --- a/pom.xml +++ b/pom.xml @@ -365,7 +365,7 @@ org.junit junit-bom - 5.9.1 + 5.9.2 pom import From f079c53914e932ba0ca0913f3ef217f68d1cb4b9 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 11 Jan 2023 13:58:41 +0100 Subject: [PATCH 158/601] Upgrade Project Reactor 2022.0.1 -> 2022.0.2 (#456) See: - https://github.com/reactor/reactor/releases/tag/2022.0.2 - https://github.com/reactor/reactor/compare/2022.0.1...2022.0.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 911e289d86..f8f9a523ff 100644 --- a/pom.xml +++ b/pom.xml @@ -281,7 +281,7 @@ io.projectreactor reactor-bom - 2022.0.1 + 2022.0.2 pom import From 79356ac5534aad5ef2c05bfa85df9607e0d48c00 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 11 Jan 2023 19:12:39 +0100 Subject: [PATCH 159/601] Upgrade Error Prone 2.17.0 -> 2.18.0 (#455) See: - https://github.com/google/error-prone/releases/tag/v2.18.0 - https://github.com/google/error-prone/compare/v2.17.0...v2.18.0 - https://github.com/PicnicSupermarket/error-prone/compare/v2.17.0-picnic-1...v2.18.0-picnic-1 --- pom.xml | 9 ++++++++- .../tech/picnic/errorprone/refaster/runner/Refaster.java | 1 + .../refaster/AnnotatedCompositeCodeTransformer.java | 1 + .../refaster/AnnotatedCompositeCodeTransformerTest.java | 1 + .../refaster/matchers/AbstractMatcherTestChecker.java | 4 +--- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index f8f9a523ff..a62162ffa4 100644 --- a/pom.xml +++ b/pom.xml @@ -149,7 +149,7 @@ 1.10.1 ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 - 2.17.0 + 2.18.0 0.1.17 1.0 11 @@ -1575,6 +1575,10 @@ -Xep:BetaApi:OFF + + -Xep:InjectOnBugCheckers:OFF -Xep:Java7ApiChecker:OFF @@ -1583,6 +1587,9 @@ -Xep:StaticOrDefaultInterfaceMethod:OFF -Xep:Varifier:OFF + + -Xep:YodaCondition:OFF -XepOpt:CheckReturnValue:CheckAllConstructors=true From ac285f0c505aa78b703ab4746086170290f30d30 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 30 Jan 2023 09:25:08 +0100 Subject: [PATCH 178/601] Upgrade Mockito 5.0.0 -> 5.1.0 (#480) See: - https://github.com/mockito/mockito/releases/tag/v5.1.0 - https://github.com/mockito/mockito/compare/v5.0.0...v5.1.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5caa476905..30efdda72b 100644 --- a/pom.xml +++ b/pom.xml @@ -154,7 +154,7 @@ 1.0 11 3.8.6 - 5.0.0 + 5.1.0 1.0.1 0.10.8 1.0.3 From 4798f7cf5f5e083b079c9d70efe66ca9794ceff4 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 30 Jan 2023 09:36:53 +0100 Subject: [PATCH 179/601] Upgrade Jackson 2.14.1 -> 2.14.2 (#479) See: - https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.14.2 - https://github.com/FasterXML/jackson-bom/compare/jackson-bom-2.14.1...jackson-bom-2.14.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 30efdda72b..dc7dd74b77 100644 --- a/pom.xml +++ b/pom.xml @@ -211,7 +211,7 @@ com.fasterxml.jackson jackson-bom - 2.14.1 + 2.14.2 pom import From 37077bd03c34be046f31cdf5bd9dbfc20046ee36 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 31 Jan 2023 08:30:51 +0100 Subject: [PATCH 180/601] Upgrade Mockito 5.1.0 -> 5.1.1 (#482) See: - https://github.com/mockito/mockito/releases/tag/v5.1.1 - https://github.com/mockito/mockito/compare/v5.1.0...v5.1.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index dc7dd74b77..aec3bab59c 100644 --- a/pom.xml +++ b/pom.xml @@ -154,7 +154,7 @@ 1.0 11 3.8.6 - 5.1.0 + 5.1.1 1.0.1 0.10.8 1.0.3 From 04749ffcf5d3be5b0cc214b0e535d699d7c4687f Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 31 Jan 2023 08:49:11 +0100 Subject: [PATCH 181/601] Upgrade pitest-maven-plugin 1.10.4 -> 1.11.0 (#483) See https://github.com/hcoles/pitest/compare/1.10.4...1.11.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index aec3bab59c..c47ba4ae7e 100644 --- a/pom.xml +++ b/pom.xml @@ -1242,7 +1242,7 @@ org.pitest pitest-maven - 1.10.4 + 1.11.0 From 0ed2788dbd5253077806393a3bf18aff6c768f08 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 2 Feb 2023 09:22:00 +0100 Subject: [PATCH 182/601] Upgrade NullAway 0.10.8 -> 0.10.9 (#485) See: - https://github.com/uber/NullAway/blob/master/CHANGELOG.md - https://github.com/uber/NullAway/compare/v0.10.8...v0.10.9 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c47ba4ae7e..c3fc858776 100644 --- a/pom.xml +++ b/pom.xml @@ -156,7 +156,7 @@ 3.8.6 5.1.1 1.0.1 - 0.10.8 + 0.10.9 1.0.3 2.22.2 From adbcc4a94fef3e80515b3efabfd6a8f2626f69d8 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 2 Feb 2023 10:19:11 +0100 Subject: [PATCH 183/601] Upgrade Checkstyle 10.6.0 -> 10.7.0 (#486) See: - https://checkstyle.sourceforge.io/releasenotes.html - https://github.com/checkstyle/checkstyle/releases/tag/checkstyle-10.7.0 - https://github.com/checkstyle/checkstyle/compare/checkstyle-10.6.0...checkstyle-10.7.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c3fc858776..305c7b6acf 100644 --- a/pom.xml +++ b/pom.xml @@ -772,7 +772,7 @@ com.puppycrawl.tools checkstyle - 10.6.0 + 10.7.0 io.spring.nohttp From 6ea756f3ce8209fc4c6d0a6d4f9f5cddafd00292 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 3 Feb 2023 09:06:17 +0100 Subject: [PATCH 184/601] Upgrade sortpom-maven-plugin 3.2.0 -> 3.2.1 (#481) See: - https://github.com/Ekryd/sortpom/wiki/Versions - https://github.com/Ekryd/sortpom/releases/tag/sortpom-parent-3.2.1 - https://github.com/Ekryd/sortpom/compare/sortpom-parent-3.2.0...sortpom-parent-3.2.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 305c7b6acf..30971f65f2 100644 --- a/pom.xml +++ b/pom.xml @@ -407,7 +407,7 @@ com.github.ekryd.sortpom sortpom-maven-plugin - 3.2.0 + 3.2.1 false ${project.build.sourceEncoding} From 9b191f46aaf769e60e36880dc1253d6498409f9a Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 3 Feb 2023 09:37:00 +0100 Subject: [PATCH 185/601] Upgrade Checker Framework Annotations 3.29.0 -> 3.30.0 (#488) See: - https://github.com/typetools/checker-framework/releases/tag/checker-framework-3.30.0 - https://github.com/typetools/checker-framework/compare/checker-framework-3.29.0...checker-framework-3.30.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 30971f65f2..850f3fafab 100644 --- a/pom.xml +++ b/pom.xml @@ -345,7 +345,7 @@ org.checkerframework checker-qual - 3.29.0 + 3.30.0 org.hamcrest From a55ed9cea9aef6ae04ed78237612aa9ca008b06a Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 4 Feb 2023 10:33:11 +0100 Subject: [PATCH 186/601] Upgrade maven-enforcer-plugin 3.1.0 -> 3.2.1 (#487) See: - https://issues.apache.org/jira/issues/?jql=project%20%3D%20MENFORCER%20AND%20fixVersion%20%3E%203.1.0%20AND%20fixVersion%20%3C%3D%203.2.1%20 - https://github.com/apache/maven-enforcer/releases/tag/enforcer-3.2.1 - https://github.com/apache/maven-enforcer/compare/enforcer-3.1.0...enforcer-3.2.1 --- pom.xml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 850f3fafab..6959bfcaca 100644 --- a/pom.xml +++ b/pom.xml @@ -322,6 +322,11 @@ junit 4.13.2 + + net.bytebuddy + byte-buddy + 1.12.22 + @@ -895,7 +900,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.1.0 + 3.2.1 false @@ -913,7 +918,6 @@ ${version.maven} - + + org.checkerframework.dataflow.qual.* + + + + true + + + + ${version.jdk} + true ISO-8859-1 @@ -917,6 +946,7 @@ ${version.maven} + @@ -1339,6 +1369,30 @@ + + org.apache.maven.plugins + maven-enforcer-plugin + + + + + + + com.google.errorprone + error_prone_annotations + + * + + + + + + + org.apache.maven.plugins maven-surefire-plugin From 14b5fa1feb3187cb7a25b91af8de6c14687c083f Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 8 Feb 2023 09:08:09 +0100 Subject: [PATCH 190/601] Update `.mvn/maven.config` for compatibility with Maven 3.9.0 (#493) See https://issues.apache.org/jira/browse/MNG-7684 --- .mvn/maven.config | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.mvn/maven.config b/.mvn/maven.config index d44ca857ee..7dd0bf2283 100644 --- a/.mvn/maven.config +++ b/.mvn/maven.config @@ -1 +1,3 @@ ---batch-mode --errors --strict-checksums +--batch-mode +--errors +--strict-checksums From 0f1507088350b014ebcca26193eb73929378d63d Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Mon, 13 Feb 2023 09:27:08 +0100 Subject: [PATCH 191/601] Introduce `documentation-support` module (#428) This new module provides the initial version of a framework for the extraction of data from bug checkers and Refaster rules, to be used as input for website generation. --- documentation-support/pom.xml | 87 ++++++++++ .../documentation/BugPatternExtractor.java | 103 ++++++++++++ .../documentation/DocumentationGenerator.java | 56 +++++++ .../DocumentationGeneratorTaskListener.java | 91 +++++++++++ .../errorprone/documentation/Extractor.java | 33 ++++ .../documentation/ExtractorType.java | 35 ++++ .../documentation/package-info.java | 7 + .../BugPatternExtractorTest.java | 153 ++++++++++++++++++ .../errorprone/documentation/Compilation.java | 45 ++++++ ...ocumentationGeneratorTaskListenerTest.java | 77 +++++++++ .../DocumentationGeneratorTest.java | 38 +++++ .../bugpattern-documentation-complete.json | 19 +++ .../bugpattern-documentation-minimal.json | 14 ++ ...ocumentation-undocumented-suppression.json | 12 ++ error-prone-contrib/pom.xml | 14 ++ pom.xml | 7 + 16 files changed, 791 insertions(+) create mode 100644 documentation-support/pom.xml create mode 100644 documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternExtractor.java create mode 100644 documentation-support/src/main/java/tech/picnic/errorprone/documentation/DocumentationGenerator.java create mode 100644 documentation-support/src/main/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListener.java create mode 100644 documentation-support/src/main/java/tech/picnic/errorprone/documentation/Extractor.java create mode 100644 documentation-support/src/main/java/tech/picnic/errorprone/documentation/ExtractorType.java create mode 100644 documentation-support/src/main/java/tech/picnic/errorprone/documentation/package-info.java create mode 100644 documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternExtractorTest.java create mode 100644 documentation-support/src/test/java/tech/picnic/errorprone/documentation/Compilation.java create mode 100644 documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListenerTest.java create mode 100644 documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTest.java create mode 100644 documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-complete.json create mode 100644 documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-minimal.json create mode 100644 documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-undocumented-suppression.json diff --git a/documentation-support/pom.xml b/documentation-support/pom.xml new file mode 100644 index 0000000000..27707b22a0 --- /dev/null +++ b/documentation-support/pom.xml @@ -0,0 +1,87 @@ + + + 4.0.0 + + + tech.picnic.error-prone-support + error-prone-support + 0.8.1-SNAPSHOT + + + documentation-support + + Picnic :: Error Prone Support :: Documentation Support + Data extraction support for the purpose of documentation generation. + + + + ${groupId.error-prone} + error_prone_annotation + + + ${groupId.error-prone} + error_prone_annotations + provided + + + ${groupId.error-prone} + error_prone_check_api + + + ${groupId.error-prone} + error_prone_test_helpers + test + + + com.fasterxml.jackson.core + jackson-annotations + + + com.fasterxml.jackson.core + jackson-databind + + + com.google.auto + auto-common + + + com.google.auto.service + auto-service-annotations + provided + + + com.google.auto.value + auto-value-annotations + provided + + + com.google.guava + guava + + + org.assertj + assertj-core + test + + + org.jspecify + jspecify + provided + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.jupiter + junit-jupiter-params + test + + + diff --git a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternExtractor.java b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternExtractor.java new file mode 100644 index 0000000000..071b3f91d0 --- /dev/null +++ b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternExtractor.java @@ -0,0 +1,103 @@ +package tech.picnic.errorprone.documentation; + +import static com.google.common.base.Verify.verify; +import static com.google.common.collect.ImmutableList.toImmutableList; +import static java.util.Objects.requireNonNull; + +import com.google.auto.common.AnnotationMirrors; +import com.google.auto.value.AutoValue; +import com.google.common.collect.ImmutableList; +import com.google.errorprone.BugPattern; +import com.google.errorprone.BugPattern.SeverityLevel; +import com.google.errorprone.annotations.Immutable; +import com.google.errorprone.util.ASTHelpers; +import com.sun.source.tree.AnnotationTree; +import com.sun.source.tree.ClassTree; +import com.sun.tools.javac.code.Attribute; +import com.sun.tools.javac.code.Symbol.ClassSymbol; +import com.sun.tools.javac.util.Context; +import javax.lang.model.element.AnnotationValue; +import tech.picnic.errorprone.documentation.BugPatternExtractor.BugPatternDocumentation; + +/** + * An {@link Extractor} that describes how to extract data from a {@code @BugPattern} annotation. + */ +@Immutable +final class BugPatternExtractor implements Extractor { + @Override + public BugPatternDocumentation extract(ClassTree tree, Context context) { + ClassSymbol symbol = ASTHelpers.getSymbol(tree); + BugPattern annotation = symbol.getAnnotation(BugPattern.class); + requireNonNull(annotation, "BugPattern annotation must be present"); + + return new AutoValue_BugPatternExtractor_BugPatternDocumentation( + symbol.getQualifiedName().toString(), + annotation.name().isEmpty() ? tree.getSimpleName().toString() : annotation.name(), + ImmutableList.copyOf(annotation.altNames()), + annotation.link(), + ImmutableList.copyOf(annotation.tags()), + annotation.summary(), + annotation.explanation(), + annotation.severity(), + annotation.disableable(), + annotation.documentSuppression() ? getSuppressionAnnotations(tree) : ImmutableList.of()); + } + + @Override + public boolean canExtract(ClassTree tree) { + return ASTHelpers.hasDirectAnnotationWithSimpleName(tree, BugPattern.class.getSimpleName()); + } + + /** + * Returns the fully-qualified class names of suppression annotations specified by the {@link + * BugPattern} annotation located on the given tree. + * + * @implNote This method cannot simply invoke {@link BugPattern#suppressionAnnotations()}, as that + * will yield an "Attempt to access Class objects for TypeMirrors" exception. + */ + private static ImmutableList getSuppressionAnnotations(ClassTree tree) { + AnnotationTree annotationTree = + ASTHelpers.getAnnotationWithSimpleName( + ASTHelpers.getAnnotations(tree), BugPattern.class.getSimpleName()); + requireNonNull(annotationTree, "BugPattern annotation must be present"); + + Attribute.Array types = + doCast( + AnnotationMirrors.getAnnotationValue( + ASTHelpers.getAnnotationMirror(annotationTree), "suppressionAnnotations"), + Attribute.Array.class); + + return types.getValue().stream() + .map(v -> doCast(v, Attribute.Class.class).classType.toString()) + .collect(toImmutableList()); + } + + @SuppressWarnings("unchecked") + private static T doCast(AnnotationValue value, Class target) { + verify(target.isInstance(value), "Value '%s' is not of type '%s'", value, target); + return (T) value; + } + + @AutoValue + abstract static class BugPatternDocumentation { + abstract String fullyQualifiedName(); + + abstract String name(); + + abstract ImmutableList altNames(); + + abstract String link(); + + abstract ImmutableList tags(); + + abstract String summary(); + + abstract String explanation(); + + abstract SeverityLevel severityLevel(); + + abstract boolean canDisable(); + + abstract ImmutableList suppressionAnnotations(); + } +} diff --git a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/DocumentationGenerator.java b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/DocumentationGenerator.java new file mode 100644 index 0000000000..39169faa2a --- /dev/null +++ b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/DocumentationGenerator.java @@ -0,0 +1,56 @@ +package tech.picnic.errorprone.documentation; + +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.auto.service.AutoService; +import com.google.common.annotations.VisibleForTesting; +import com.sun.source.util.JavacTask; +import com.sun.source.util.Plugin; +import com.sun.tools.javac.api.BasicJavacTask; +import java.nio.file.InvalidPathException; +import java.nio.file.Path; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * A compiler {@link Plugin} that analyzes and extracts relevant information for documentation + * purposes from processed files. + */ +// XXX: Find a better name for this class; it doesn't generate documentation per se. +@AutoService(Plugin.class) +public final class DocumentationGenerator implements Plugin { + @VisibleForTesting static final String OUTPUT_DIRECTORY_FLAG = "-XoutputDirectory"; + private static final Pattern OUTPUT_DIRECTORY_FLAG_PATTERN = + Pattern.compile(Pattern.quote(OUTPUT_DIRECTORY_FLAG) + "=(.*)"); + + /** Instantiates a new {@link DocumentationGenerator} instance. */ + public DocumentationGenerator() {} + + @Override + public String getName() { + return getClass().getSimpleName(); + } + + @Override + public void init(JavacTask javacTask, String... args) { + checkArgument(args.length == 1, "Precisely one path must be provided"); + + javacTask.addTaskListener( + new DocumentationGeneratorTaskListener( + ((BasicJavacTask) javacTask).getContext(), getOutputPath(args[0]))); + } + + @VisibleForTesting + static Path getOutputPath(String pathArg) { + Matcher matcher = OUTPUT_DIRECTORY_FLAG_PATTERN.matcher(pathArg); + checkArgument( + matcher.matches(), "'%s' must be of the form '%s='", pathArg, OUTPUT_DIRECTORY_FLAG); + + String path = matcher.group(1); + try { + return Path.of(path); + } catch (InvalidPathException e) { + throw new IllegalArgumentException(String.format("Invalid path '%s'", path), e); + } + } +} diff --git a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListener.java b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListener.java new file mode 100644 index 0000000000..29fa2203d2 --- /dev/null +++ b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListener.java @@ -0,0 +1,91 @@ +package tech.picnic.errorprone.documentation; + +import static java.nio.charset.StandardCharsets.UTF_8; + +import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; +import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.sun.source.tree.ClassTree; +import com.sun.source.util.TaskEvent; +import com.sun.source.util.TaskEvent.Kind; +import com.sun.source.util.TaskListener; +import com.sun.tools.javac.api.JavacTrees; +import com.sun.tools.javac.util.Context; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import javax.tools.JavaFileObject; + +/** + * A {@link TaskListener} that identifies and extracts relevant content for documentation generation + * and writes it to disk. + */ +// XXX: Find a better name for this class; it doesn't generate documentation per se. +final class DocumentationGeneratorTaskListener implements TaskListener { + private static final ObjectMapper OBJECT_MAPPER = + new ObjectMapper().setVisibility(PropertyAccessor.FIELD, Visibility.ANY); + + private final Context context; + private final Path docsPath; + + DocumentationGeneratorTaskListener(Context context, Path path) { + this.context = context; + this.docsPath = path; + } + + @Override + public void started(TaskEvent taskEvent) { + if (taskEvent.getKind() == Kind.ANALYZE) { + createDocsDirectory(); + } + } + + @Override + public void finished(TaskEvent taskEvent) { + if (taskEvent.getKind() != Kind.ANALYZE) { + return; + } + + ClassTree classTree = JavacTrees.instance(context).getTree(taskEvent.getTypeElement()); + JavaFileObject sourceFile = taskEvent.getSourceFile(); + if (classTree == null || sourceFile == null) { + return; + } + + ExtractorType.findMatchingType(classTree) + .ifPresent( + extractorType -> + writeToFile( + extractorType.getIdentifier(), + getSimpleClassName(sourceFile.toUri()), + extractorType.getExtractor().extract(classTree, context))); + } + + private void createDocsDirectory() { + try { + Files.createDirectories(docsPath); + } catch (IOException e) { + throw new IllegalStateException( + String.format("Error while creating directory with path '%s'", docsPath), e); + } + } + + private void writeToFile(String identifier, String className, T data) { + File file = docsPath.resolve(String.format("%s-%s.json", identifier, className)).toFile(); + + try (FileWriter fileWriter = new FileWriter(file, UTF_8)) { + OBJECT_MAPPER.writeValue(fileWriter, data); + } catch (IOException e) { + throw new UncheckedIOException(String.format("Cannot write to file '%s'", file.getPath()), e); + } + } + + private static String getSimpleClassName(URI path) { + return Paths.get(path).getFileName().toString().replace(".java", ""); + } +} diff --git a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/Extractor.java b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/Extractor.java new file mode 100644 index 0000000000..210c84ab94 --- /dev/null +++ b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/Extractor.java @@ -0,0 +1,33 @@ +package tech.picnic.errorprone.documentation; + +import com.google.errorprone.annotations.Immutable; +import com.sun.source.tree.ClassTree; +import com.sun.tools.javac.util.Context; + +/** + * Interface implemented by classes that define how to extract data of some type {@link T} from a + * given {@link ClassTree}. + * + * @param The type of data that is extracted. + */ +@Immutable +interface Extractor { + /** + * Extracts and returns an instance of {@link T} using the provided arguments. + * + * @param tree The {@link ClassTree} to analyze and from which to extract instances of {@link T}. + * @param context The {@link Context} in which the current compilation takes place. + * @return A non-null instance of {@link T}. + */ + // XXX: Drop `Context` parameter unless used. + T extract(ClassTree tree, Context context); + + /** + * Tells whether this {@link Extractor} can extract documentation content from the given {@link + * ClassTree}. + * + * @param tree The {@link ClassTree} of interest. + * @return {@code true} iff data extraction is supported. + */ + boolean canExtract(ClassTree tree); +} diff --git a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/ExtractorType.java b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/ExtractorType.java new file mode 100644 index 0000000000..42f5b48abd --- /dev/null +++ b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/ExtractorType.java @@ -0,0 +1,35 @@ +package tech.picnic.errorprone.documentation; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import com.sun.source.tree.ClassTree; +import java.util.EnumSet; +import java.util.Optional; + +/** An enumeration of {@link Extractor} types. */ +enum ExtractorType { + BUG_PATTERN("bugpattern", new BugPatternExtractor()); + + private static final ImmutableSet TYPES = + Sets.immutableEnumSet(EnumSet.allOf(ExtractorType.class)); + + private final String identifier; + private final Extractor extractor; + + ExtractorType(String identifier, Extractor extractor) { + this.identifier = identifier; + this.extractor = extractor; + } + + String getIdentifier() { + return identifier; + } + + Extractor getExtractor() { + return extractor; + } + + static Optional findMatchingType(ClassTree tree) { + return TYPES.stream().filter(type -> type.getExtractor().canExtract(tree)).findFirst(); + } +} diff --git a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/package-info.java b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/package-info.java new file mode 100644 index 0000000000..bdd32c366b --- /dev/null +++ b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/package-info.java @@ -0,0 +1,7 @@ +/** + * A Java compiler plugin that extracts data from compiled classes, in support of the Error Prone + * Support documentation. + */ +@com.google.errorprone.annotations.CheckReturnValue +@org.jspecify.annotations.NullMarked +package tech.picnic.errorprone.documentation; diff --git a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternExtractorTest.java b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternExtractorTest.java new file mode 100644 index 0000000000..1737f32ac4 --- /dev/null +++ b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternExtractorTest.java @@ -0,0 +1,153 @@ +package tech.picnic.errorprone.documentation; + +import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import com.google.common.io.Resources; +import com.google.errorprone.BugPattern; +import com.google.errorprone.CompilationTestHelper; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher; +import com.google.errorprone.matchers.Description; +import com.sun.source.tree.ClassTree; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +final class BugPatternExtractorTest { + @Test + void noBugPattern(@TempDir Path outputDirectory) { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "TestCheckerWithoutAnnotation.java", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "public final class TestCheckerWithoutAnnotation extends BugChecker {}"); + + assertThat(outputDirectory.toAbsolutePath()).isEmptyDirectory(); + } + + @Test + void minimalBugPattern(@TempDir Path outputDirectory) throws IOException { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "MinimalBugChecker.java", + "package pkg;", + "", + "import com.google.errorprone.BugPattern;", + "import com.google.errorprone.BugPattern.SeverityLevel;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "@BugPattern(summary = \"MinimalBugChecker summary\", severity = SeverityLevel.ERROR)", + "public final class MinimalBugChecker extends BugChecker {}"); + + verifyFileMatchesResource( + outputDirectory, + "bugpattern-MinimalBugChecker.json", + "bugpattern-documentation-minimal.json"); + } + + @Test + void completeBugPattern(@TempDir Path outputDirectory) throws IOException { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "CompleteBugChecker.java", + "package pkg;", + "", + "import com.google.errorprone.BugPattern;", + "import com.google.errorprone.BugPattern.SeverityLevel;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "import org.junit.jupiter.api.Test;", + "", + "@BugPattern(", + " name = \"OtherName\",", + " summary = \"CompleteBugChecker summary\",", + " linkType = BugPattern.LinkType.CUSTOM,", + " link = \"https://error-prone.picnic.tech\",", + " explanation = \"Example explanation\",", + " severity = SeverityLevel.SUGGESTION,", + " altNames = \"Check\",", + " tags = BugPattern.StandardTags.SIMPLIFICATION,", + " disableable = false,", + " suppressionAnnotations = {BugPattern.class, Test.class})", + "public final class CompleteBugChecker extends BugChecker {}"); + + verifyFileMatchesResource( + outputDirectory, + "bugpattern-CompleteBugChecker.json", + "bugpattern-documentation-complete.json"); + } + + @Test + void undocumentedSuppressionBugPattern(@TempDir Path outputDirectory) throws IOException { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "UndocumentedSuppressionBugPattern.java", + "package pkg;", + "", + "import com.google.errorprone.BugPattern;", + "import com.google.errorprone.BugPattern.SeverityLevel;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "@BugPattern(", + " summary = \"UndocumentedSuppressionBugPattern summary\",", + " severity = SeverityLevel.WARNING,", + " documentSuppression = false)", + "public final class UndocumentedSuppressionBugPattern extends BugChecker {}"); + + verifyFileMatchesResource( + outputDirectory, + "bugpattern-UndocumentedSuppressionBugPattern.json", + "bugpattern-documentation-undocumented-suppression.json"); + } + + @Test + void bugPatternAnnotationIsAbsent() { + CompilationTestHelper.newInstance(TestChecker.class, getClass()) + .addSourceLines( + "TestChecker.java", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "// BUG: Diagnostic contains: Can extract: false", + "public final class TestChecker extends BugChecker {}") + .doTest(); + } + + private static void verifyFileMatchesResource( + Path outputDirectory, String fileName, String resourceName) throws IOException { + assertThat(Files.readString(outputDirectory.resolve(fileName))) + .isEqualToIgnoringWhitespace(getResource(resourceName)); + } + + // XXX: Once we support only JDK 15+, drop this method in favour of including the resources as + // text blocks in this class. (This also requires renaming the `verifyFileMatchesResource` + // method.) + private static String getResource(String resourceName) throws IOException { + return Resources.toString( + Resources.getResource(BugPatternExtractorTest.class, resourceName), UTF_8); + } + + /** A {@link BugChecker} that validates the {@link BugPatternExtractor}. */ + @BugPattern(summary = "Validates `BugPatternExtractor` extraction", severity = ERROR) + public static final class TestChecker extends BugChecker implements ClassTreeMatcher { + private static final long serialVersionUID = 1L; + + @Override + public Description matchClass(ClassTree tree, VisitorState state) { + BugPatternExtractor extractor = new BugPatternExtractor(); + + assertThatThrownBy(() -> extractor.extract(tree, state.context)) + .isInstanceOf(NullPointerException.class) + .hasMessage("BugPattern annotation must be present"); + + return buildDescription(tree) + .setMessage(String.format("Can extract: %s", extractor.canExtract(tree))) + .build(); + } + } +} diff --git a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/Compilation.java b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/Compilation.java new file mode 100644 index 0000000000..26d5004c58 --- /dev/null +++ b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/Compilation.java @@ -0,0 +1,45 @@ +package tech.picnic.errorprone.documentation; + +import com.google.common.collect.ImmutableList; +import com.google.errorprone.FileManagers; +import com.google.errorprone.FileObjects; +import com.sun.tools.javac.api.JavacTaskImpl; +import com.sun.tools.javac.api.JavacTool; +import com.sun.tools.javac.file.JavacFileManager; +import java.nio.file.Path; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; + +// XXX: Generalize and move this class so that it can also be used by `refaster-compiler`. +// XXX: Add support for this class to the `ErrorProneTestHelperSourceFormat` check. +public final class Compilation { + private Compilation() {} + + public static void compileWithDocumentationGenerator( + Path outputDirectory, String fileName, String... lines) { + compileWithDocumentationGenerator(outputDirectory.toAbsolutePath().toString(), fileName, lines); + } + + public static void compileWithDocumentationGenerator( + String outputDirectory, String fileName, String... lines) { + compile( + ImmutableList.of("-Xplugin:DocumentationGenerator -XoutputDirectory=" + outputDirectory), + FileObjects.forSourceLines(fileName, lines)); + } + + private static void compile(ImmutableList options, JavaFileObject javaFileObject) { + JavacFileManager javacFileManager = FileManagers.testFileManager(); + JavaCompiler compiler = JavacTool.create(); + JavacTaskImpl task = + (JavacTaskImpl) + compiler.getTask( + null, + javacFileManager, + null, + options, + ImmutableList.of(), + ImmutableList.of(javaFileObject)); + + task.call(); + } +} diff --git a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListenerTest.java b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListenerTest.java new file mode 100644 index 0000000000..48b50ca68e --- /dev/null +++ b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListenerTest.java @@ -0,0 +1,77 @@ +package tech.picnic.errorprone.documentation; + +import static com.google.common.collect.ImmutableList.toImmutableList; +import static java.nio.file.attribute.AclEntryPermission.ADD_SUBDIRECTORY; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.condition.OS.WINDOWS; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import java.io.IOException; +import java.nio.file.FileSystemException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.AclEntry; +import java.nio.file.attribute.AclFileAttributeView; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.EnabledOnOs; +import org.junit.jupiter.api.io.TempDir; + +final class DocumentationGeneratorTaskListenerTest { + @EnabledOnOs(WINDOWS) + @Test + void readOnlyFileSystemWindows(@TempDir Path outputDirectory) throws IOException { + AclFileAttributeView view = + Files.getFileAttributeView(outputDirectory, AclFileAttributeView.class); + view.setAcl( + view.getAcl().stream() + .map( + entry -> + AclEntry.newBuilder(entry) + .setPermissions( + Sets.difference(entry.permissions(), ImmutableSet.of(ADD_SUBDIRECTORY))) + .build()) + .collect(toImmutableList())); + + readOnlyFileSystemFailsToWrite(outputDirectory.resolve("nonexistent")); + } + + @DisabledOnOs(WINDOWS) + @Test + void readOnlyFileSystemNonWindows(@TempDir Path outputDirectory) { + assertThat(outputDirectory.toFile().setWritable(false)) + .describedAs("Failed to make test directory unwritable") + .isTrue(); + + readOnlyFileSystemFailsToWrite(outputDirectory.resolve("nonexistent")); + } + + private static void readOnlyFileSystemFailsToWrite(Path outputDirectory) { + assertThatThrownBy( + () -> + Compilation.compileWithDocumentationGenerator( + outputDirectory, "A.java", "class A {}")) + .hasRootCauseInstanceOf(FileSystemException.class) + .hasCauseInstanceOf(IllegalStateException.class) + .hasMessageEndingWith("Error while creating directory with path '%s'", outputDirectory); + } + + @Test + void noClassNoOutput(@TempDir Path outputDirectory) { + Compilation.compileWithDocumentationGenerator(outputDirectory, "A.java", "package pkg;"); + + assertThat(outputDirectory).isEmptyDirectory(); + } + + @Test + void excessArguments(@TempDir Path outputDirectory) { + assertThatThrownBy( + () -> + Compilation.compileWithDocumentationGenerator( + outputDirectory.toAbsolutePath() + " extra-arg", "A.java", "package pkg;")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Precisely one path must be provided"); + } +} diff --git a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTest.java b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTest.java new file mode 100644 index 0000000000..2db9f6c3f8 --- /dev/null +++ b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTest.java @@ -0,0 +1,38 @@ +package tech.picnic.errorprone.documentation; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static tech.picnic.errorprone.documentation.DocumentationGenerator.OUTPUT_DIRECTORY_FLAG; + +import java.nio.file.InvalidPathException; +import java.nio.file.Path; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; + +final class DocumentationGeneratorTest { + @ParameterizedTest + @ValueSource(strings = {"bar", "foo"}) + void getOutputPath(String path) { + assertThat(DocumentationGenerator.getOutputPath(OUTPUT_DIRECTORY_FLAG + '=' + path)) + .isEqualTo(Path.of(path)); + } + + @ParameterizedTest + @ValueSource(strings = {"", "-XoutputDirectory", "invalidOption=Test", "nothing"}) + void getOutputPathWithInvalidArgument(String pathArg) { + assertThatThrownBy(() -> DocumentationGenerator.getOutputPath(pathArg)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("'%s' must be of the form '%s='", pathArg, OUTPUT_DIRECTORY_FLAG); + } + + @Test + void getOutputPathWithInvalidPath() { + String basePath = "path-with-null-char-\0"; + assertThatThrownBy( + () -> DocumentationGenerator.getOutputPath(OUTPUT_DIRECTORY_FLAG + '=' + basePath)) + .isInstanceOf(IllegalArgumentException.class) + .hasCauseInstanceOf(InvalidPathException.class) + .hasMessageEndingWith("Invalid path '%s'", basePath); + } +} diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-complete.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-complete.json new file mode 100644 index 0000000000..eb29080c05 --- /dev/null +++ b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-complete.json @@ -0,0 +1,19 @@ +{ + "fullyQualifiedName": "pkg.CompleteBugChecker", + "name": "OtherName", + "altNames": [ + "Check" + ], + "link": "https://error-prone.picnic.tech", + "tags": [ + "Simplification" + ], + "summary": "CompleteBugChecker summary", + "explanation": "Example explanation", + "severityLevel": "SUGGESTION", + "canDisable": false, + "suppressionAnnotations": [ + "com.google.errorprone.BugPattern", + "org.junit.jupiter.api.Test" + ] +} diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-minimal.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-minimal.json new file mode 100644 index 0000000000..8e64bdc887 --- /dev/null +++ b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-minimal.json @@ -0,0 +1,14 @@ +{ + "fullyQualifiedName": "pkg.MinimalBugChecker", + "name": "MinimalBugChecker", + "altNames": [], + "link": "", + "tags": [], + "summary": "MinimalBugChecker summary", + "explanation": "", + "severityLevel": "ERROR", + "canDisable": true, + "suppressionAnnotations": [ + "java.lang.SuppressWarnings" + ] +} diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-undocumented-suppression.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-undocumented-suppression.json new file mode 100644 index 0000000000..b738dfd988 --- /dev/null +++ b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-undocumented-suppression.json @@ -0,0 +1,12 @@ +{ + "fullyQualifiedName": "pkg.UndocumentedSuppressionBugPattern", + "name": "UndocumentedSuppressionBugPattern", + "altNames": [], + "link": "", + "tags": [], + "summary": "UndocumentedSuppressionBugPattern summary", + "explanation": "", + "severityLevel": "WARNING", + "canDisable": true, + "suppressionAnnotations": [] +} diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index 7734145c08..b16612d0e5 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -39,6 +39,14 @@ error_prone_test_helpers test + + ${project.groupId} + documentation-support + + provided + ${project.groupId} refaster-support @@ -213,6 +221,11 @@ maven-compiler-plugin + + ${project.groupId} + documentation-support + ${project.version} + ${project.groupId} refaster-compiler @@ -226,6 +239,7 @@ -Xplugin:RefasterRuleCompiler + -Xplugin:DocumentationGenerator -XoutputDirectory=${project.build.directory}/docs
diff --git a/pom.xml b/pom.xml index eef8de76ce..6fe01cb382 100644 --- a/pom.xml +++ b/pom.xml @@ -39,6 +39,7 @@ + documentation-support error-prone-contrib refaster-compiler refaster-runner @@ -188,6 +189,11 @@ error_prone_test_helpers ${version.error-prone} + + ${project.groupId} + documentation-support + ${project.version} + ${project.groupId} refaster-compiler @@ -856,6 +862,7 @@ --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED + --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED From 0cb03aa13201a525e48f70e28b67b6974b9d63c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6khun=20=C3=87elik?= <3802058+ghokun@users.noreply.github.com> Date: Mon, 13 Feb 2023 11:18:36 +0100 Subject: [PATCH 192/601] Add Gradle installation instructions to README (#430) --- README.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8008995960..295e120b4d 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,9 @@ code_][picnic-blog-ep-post]. ### Installation This library is built on top of [Error Prone][error-prone-orig-repo]. To use -it: +it, read the installation guide for Maven or Gradle below. + +#### Maven 1. First, follow Error Prone's [installation guide][error-prone-installation-guide]. @@ -94,6 +96,31 @@ it: Prone Support. Alternatively reference this project's `self-check` profile definition. --> +#### Gradle + +1. First, follow the [installation guide] + [error-prone-gradle-installation-guide] of the `gradle-errorprone-plugin`. +2. Next, edit your `build.gradle` file to add one or more Error Prone Support + modules: + + ```groovy + dependencies { + // Error Prone itself. + errorprone("com.google.errorprone:error_prone_core:${errorProneVersion}") + // Error Prone Support's additional bug checkers. + errorprone("tech.picnic.error-prone-support:error-prone-contrib:${errorProneSupportVersion}") + // Error Prone Support's Refaster rules. + errorprone("tech.picnic.error-prone-support:refaster-runner:${errorProneSupportVersion}") + } + + tasks.withType(JavaCompile).configureEach { + options.errorprone.disableWarningsInGeneratedCode = true + // Add other Error Prone flags here. See: + // - https://github.com/tbroyer/gradle-errorprone-plugin#configuration + // - https://errorprone.info/docs/flags + } + ``` + ### Seeing it in action Consider the following example code: @@ -207,6 +234,7 @@ guidelines][contributing]. [error-prone-bugchecker]: https://github.com/google/error-prone/blob/master/check_api/src/main/java/com/google/errorprone/bugpatterns/BugChecker.java [error-prone-fork-jitpack]: https://jitpack.io/#PicnicSupermarket/error-prone [error-prone-fork-repo]: https://github.com/PicnicSupermarket/error-prone +[error-prone-gradle-installation-guide]: https://github.com/tbroyer/gradle-errorprone-plugin [error-prone-installation-guide]: https://errorprone.info/docs/installation#maven [error-prone-orig-repo]: https://github.com/google/error-prone [error-prone-pull-3301]: https://github.com/google/error-prone/pull/3301 From da9a6dd2706c3c12828e952db153578a27577a75 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 13 Feb 2023 11:35:27 +0100 Subject: [PATCH 193/601] Upgrade Byte Buddy 1.12.23 -> 1.13.0 (#496) See: - https://github.com/raphw/byte-buddy/releases/tag/byte-buddy-1.13.0 - https://github.com/raphw/byte-buddy/compare/byte-buddy-1.12.23...byte-buddy-1.13.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6fe01cb382..8202ac1199 100644 --- a/pom.xml +++ b/pom.xml @@ -331,7 +331,7 @@ net.bytebuddy byte-buddy - 1.12.23 + 1.13.0 From d84de6efba9877ce1e91e105eedee414b298644b Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 26 Feb 2023 14:40:42 +0100 Subject: [PATCH 207/601] Upgrade Google Java Format 1.15.0 -> 1.16.0 (#511) See: - https://github.com/google/google-java-format/releases/tag/v1.16.0 - https://github.com/google/google-java-format/compare/v1.15.0...v1.16.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ef980a6506..6c6430e0cf 100644 --- a/pom.xml +++ b/pom.xml @@ -244,7 +244,7 @@ com.google.googlejavaformat google-java-format - 1.15.0 + 1.16.0 From e883e28e34bbf7309e59a0de7b5927b8ffb1132e Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 27 Feb 2023 07:46:00 +0100 Subject: [PATCH 208/601] Upgrade Checkstyle 10.7.0 -> 10.8.0 (#512) See: - https://checkstyle.sourceforge.io/releasenotes.html - https://github.com/checkstyle/checkstyle/releases/tag/checkstyle-10.8.0 - https://github.com/checkstyle/checkstyle/compare/checkstyle-10.7.0...checkstyle-10.8.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6c6430e0cf..3eca7a607e 100644 --- a/pom.xml +++ b/pom.xml @@ -783,7 +783,7 @@ com.puppycrawl.tools checkstyle - 10.7.0 + 10.8.0 io.spring.nohttp From 6b4fba62da0e53834c839174ef84da29afd386cb Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 27 Feb 2023 16:47:31 +0100 Subject: [PATCH 209/601] Upgrade pitest-maven-plugin 1.11.0 -> 1.11.1 (#509) See: - https://github.com/hcoles/pitest/releases/tag/1.11.1 - https://github.com/hcoles/pitest/compare/1.11.0...1.11.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3eca7a607e..ffa389db2e 100644 --- a/pom.xml +++ b/pom.xml @@ -1283,7 +1283,7 @@ org.pitest pitest-maven - 1.11.0 + 1.11.1 From ee265a87ae30405fa551e37c4804dda26a054297 Mon Sep 17 00:00:00 2001 From: Bastien Diederichs Date: Thu, 2 Mar 2023 08:48:33 +0100 Subject: [PATCH 210/601] Introduce `FluxCountMapMathToIntExact` Refaster rule (#516) --- .../refasterrules/ReactorRules.java | 32 +++++++++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 28 +++++++++++++++- .../refasterrules/ReactorRulesTestOutput.java | 28 +++++++++++++++- 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index b7017340bc..17a8922b47 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1,12 +1,16 @@ package tech.picnic.errorprone.refasterrules; +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.MoreCollectors.toOptional; import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static java.util.function.Function.identity; +import static java.util.stream.Collectors.toCollection; import static org.assertj.core.api.Assertions.assertThat; import static reactor.function.TupleUtils.function; +import com.google.common.collect.ImmutableCollection; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.errorprone.refaster.Refaster; import com.google.errorprone.refaster.annotation.AfterTemplate; @@ -16,8 +20,11 @@ import com.google.errorprone.refaster.annotation.Placeholder; import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.time.Duration; +import java.util.ArrayList; +import java.util.Collection; import java.util.Comparator; import java.util.HashMap; +import java.util.List; import java.util.Optional; import java.util.concurrent.Callable; import java.util.function.BiConsumer; @@ -805,6 +812,31 @@ Flux after(Flux> flux, int prefetch) { } } + /** + * Prefer {@link Flux#count()} followed by a conversion from {@code long} to {@code int} over + * collecting into a list and counting its elements. + */ + static final class FluxCountMapMathToIntExact { + @BeforeTemplate + Mono before(Flux flux) { + return Refaster.anyOf( + flux.collect(toImmutableList()) + .map( + Refaster.anyOf( + Collection::size, + List::size, + ImmutableCollection::size, + ImmutableList::size)), + flux.collect(toCollection(ArrayList::new)) + .map(Refaster.anyOf(Collection::size, List::size))); + } + + @AfterTemplate + Mono after(Flux flux) { + return flux.count().map(Math::toIntExact); + } + } + /** * Prefer {@link Mono#doOnError(Class, Consumer)} over {@link Mono#doOnError(Predicate, Consumer)} * where possible. diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 7c8af048be..e0781ae3af 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -1,15 +1,21 @@ package tech.picnic.errorprone.refasterrules; +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.MoreCollectors.toOptional; import static java.util.Comparator.reverseOrder; import static java.util.function.Function.identity; +import static java.util.stream.Collectors.toCollection; import static org.assertj.core.api.Assertions.assertThat; +import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.time.Duration; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Optional; import java.util.concurrent.Callable; import java.util.function.Supplier; @@ -24,7 +30,17 @@ final class ReactorRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(assertThat(0), HashMap.class, ImmutableMap.class, toOptional()); + return ImmutableSet.of( + ArrayList.class, + Collection.class, + HashMap.class, + List.class, + ImmutableCollection.class, + ImmutableMap.class, + assertThat(0), + toCollection(null), + toImmutableList(), + toOptional()); } ImmutableSet> testMonoFromSupplier() { @@ -264,6 +280,16 @@ ImmutableSet> testConcatMapIterableIdentityWithPrefetch() { Flux.just(ImmutableList.of("bar")).concatMap(Flux::fromIterable, 2)); } + ImmutableSet> testFluxCountMapMathToIntExact() { + return ImmutableSet.of( + Flux.just(1).collect(toImmutableList()).map(Collection::size), + Flux.just(2).collect(toImmutableList()).map(List::size), + Flux.just(3).collect(toImmutableList()).map(ImmutableCollection::size), + Flux.just(4).collect(toImmutableList()).map(ImmutableList::size), + Flux.just(5).collect(toCollection(ArrayList::new)).map(Collection::size), + Flux.just(6).collect(toCollection(ArrayList::new)).map(List::size)); + } + Mono testMonoDoOnError() { return Mono.just(1).doOnError(IllegalArgumentException.class::isInstance, e -> {}); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index fee65bae6b..19b3611e2b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -1,16 +1,22 @@ package tech.picnic.errorprone.refasterrules; +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.MoreCollectors.toOptional; import static java.util.Comparator.reverseOrder; import static java.util.function.Function.identity; +import static java.util.stream.Collectors.toCollection; import static org.assertj.core.api.Assertions.assertThat; import static reactor.function.TupleUtils.function; +import com.google.common.collect.ImmutableCollection; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.time.Duration; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Optional; import java.util.concurrent.Callable; import java.util.function.Supplier; @@ -26,7 +32,17 @@ final class ReactorRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(assertThat(0), HashMap.class, ImmutableMap.class, toOptional()); + return ImmutableSet.of( + ArrayList.class, + Collection.class, + HashMap.class, + List.class, + ImmutableCollection.class, + ImmutableMap.class, + assertThat(0), + toCollection(null), + toImmutableList(), + toOptional()); } ImmutableSet> testMonoFromSupplier() { @@ -256,6 +272,16 @@ ImmutableSet> testConcatMapIterableIdentityWithPrefetch() { Flux.just(ImmutableList.of("bar")).concatMapIterable(identity(), 2)); } + ImmutableSet> testFluxCountMapMathToIntExact() { + return ImmutableSet.of( + Flux.just(1).count().map(Math::toIntExact), + Flux.just(2).count().map(Math::toIntExact), + Flux.just(3).count().map(Math::toIntExact), + Flux.just(4).count().map(Math::toIntExact), + Flux.just(5).count().map(Math::toIntExact), + Flux.just(6).count().map(Math::toIntExact)); + } + Mono testMonoDoOnError() { return Mono.just(1).doOnError(IllegalArgumentException.class, e -> {}); } From 2d972fd9751b5001f09ffcfe92cf6810486401c4 Mon Sep 17 00:00:00 2001 From: Gijs de Jong <14833076+oxkitsune@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:45:35 +0100 Subject: [PATCH 211/601] Introduce `JUnitValueSource` check (#188) This new check replaces JUnit `@MethodSource` usages with an equivalent `@ValueSource` annotation where possible. --- .../bugpatterns/JUnitValueSource.java | 307 +++++++++++ .../RedundantStringConversion.java | 5 +- .../bugpatterns/util/MoreJUnitMatchers.java | 50 +- .../bugpatterns/JUnitValueSourceTest.java | 496 ++++++++++++++++++ .../util/MoreJUnitMatchersTest.java | 63 +++ 5 files changed, 910 insertions(+), 11 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitValueSourceTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java new file mode 100644 index 0000000000..e6fe6df852 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java @@ -0,0 +1,307 @@ +package tech.picnic.errorprone.bugpatterns; + +import static com.google.errorprone.BugPattern.LinkType.CUSTOM; +import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; +import static com.google.errorprone.BugPattern.StandardTags.SIMPLIFICATION; +import static com.google.errorprone.matchers.ChildMultiMatcher.MatchType.ALL; +import static com.google.errorprone.matchers.ChildMultiMatcher.MatchType.AT_LEAST_ONE; +import static com.google.errorprone.matchers.Matchers.allOf; +import static com.google.errorprone.matchers.Matchers.anyOf; +import static com.google.errorprone.matchers.Matchers.anything; +import static com.google.errorprone.matchers.Matchers.argument; +import static com.google.errorprone.matchers.Matchers.argumentCount; +import static com.google.errorprone.matchers.Matchers.classLiteral; +import static com.google.errorprone.matchers.Matchers.hasArguments; +import static com.google.errorprone.matchers.Matchers.isPrimitiveOrBoxedPrimitiveType; +import static com.google.errorprone.matchers.Matchers.isSameType; +import static com.google.errorprone.matchers.Matchers.methodHasParameters; +import static com.google.errorprone.matchers.Matchers.staticMethod; +import static com.google.errorprone.matchers.Matchers.toType; +import static java.util.function.Predicate.not; +import static java.util.stream.Collectors.joining; +import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; +import static tech.picnic.errorprone.bugpatterns.util.MoreJUnitMatchers.HAS_METHOD_SOURCE; +import static tech.picnic.errorprone.bugpatterns.util.MoreJUnitMatchers.getMethodSourceFactoryNames; + +import com.google.auto.service.AutoService; +import com.google.common.collect.Iterables; +import com.google.errorprone.BugPattern; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher; +import com.google.errorprone.fixes.SuggestedFix; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.util.ASTHelpers; +import com.sun.source.tree.AnnotationTree; +import com.sun.source.tree.ClassTree; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.LambdaExpressionTree; +import com.sun.source.tree.MethodInvocationTree; +import com.sun.source.tree.MethodTree; +import com.sun.source.tree.NewArrayTree; +import com.sun.source.tree.ReturnTree; +import com.sun.source.util.TreeScanner; +import com.sun.tools.javac.code.Type; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Locale; +import java.util.Optional; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.DoubleStream; +import java.util.stream.IntStream; +import java.util.stream.LongStream; +import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; +import tech.picnic.errorprone.bugpatterns.util.SourceCode; + +/** + * A {@link BugChecker} that flags JUnit tests with a {@link + * org.junit.jupiter.params.provider.MethodSource} annotation that can be replaced with an + * equivalent {@link org.junit.jupiter.params.provider.ValueSource} annotation. + */ +// XXX: Where applicable, also flag `@MethodSource` annotations that reference multiple value +// factory methods (or that repeat the same value factory method multiple times). +// XXX: Support inlining of overloaded value factory methods. +// XXX: Support inlining of value factory methods referenced by multiple `@MethodSource` +// annotations. +// XXX: Support value factory return expressions of the form `Stream.of(a, b, +// c).map(Arguments::argument)`. +// XXX: Support simplification of test methods that accept additional injected parameters such as +// `TestInfo`; such parameters should be ignored for the purpose of this check. +@AutoService(BugChecker.class) +@BugPattern( + summary = "Prefer `@ValueSource` over a `@MethodSource` where possible and reasonable", + linkType = CUSTOM, + link = BUG_PATTERNS_BASE_URL + "JUnitValueSource", + severity = SUGGESTION, + tags = SIMPLIFICATION) +public final class JUnitValueSource extends BugChecker implements MethodTreeMatcher { + private static final long serialVersionUID = 1L; + private static final Matcher SUPPORTED_VALUE_FACTORY_VALUES = + anyOf( + isArrayArgumentValueCandidate(), + toType( + MethodInvocationTree.class, + allOf( + staticMethod() + .onClass("org.junit.jupiter.params.provider.Arguments") + .namedAnyOf("arguments", "of"), + argumentCount(1), + argument(0, isArrayArgumentValueCandidate())))); + private static final Matcher ARRAY_OF_SUPPORTED_SINGLE_VALUE_ARGUMENTS = + isSingleDimensionArrayCreationWithAllElementsMatching(SUPPORTED_VALUE_FACTORY_VALUES); + private static final Matcher ENUMERATION_OF_SUPPORTED_SINGLE_VALUE_ARGUMENTS = + toType( + MethodInvocationTree.class, + allOf( + staticMethod() + .onClassAny( + Stream.class.getName(), + IntStream.class.getName(), + LongStream.class.getName(), + DoubleStream.class.getName(), + List.class.getName(), + Set.class.getName(), + "com.google.common.collect.ImmutableList", + "com.google.common.collect.ImmutableSet") + .named("of"), + hasArguments(AT_LEAST_ONE, anything()), + hasArguments(ALL, SUPPORTED_VALUE_FACTORY_VALUES))); + private static final Matcher IS_UNARY_METHOD_WITH_SUPPORTED_PARAMETER = + methodHasParameters( + anyOf( + isPrimitiveOrBoxedPrimitiveType(), + isSameType(String.class), + isSameType(state -> state.getSymtab().classType))); + + /** Instantiates a new {@link JUnitValueSource} instance. */ + public JUnitValueSource() {} + + @Override + public Description matchMethod(MethodTree tree, VisitorState state) { + if (!IS_UNARY_METHOD_WITH_SUPPORTED_PARAMETER.matches(tree, state)) { + return Description.NO_MATCH; + } + + Type parameterType = ASTHelpers.getType(Iterables.getOnlyElement(tree.getParameters())); + + return findMethodSourceAnnotation(tree, state) + .flatMap( + methodSourceAnnotation -> + getSoleLocalFactoryName(methodSourceAnnotation, tree) + .filter(factory -> !hasSiblingReferencingValueFactory(tree, factory, state)) + .flatMap(factory -> findSiblingWithName(tree, factory, state)) + .flatMap( + factoryMethod -> + tryConstructValueSourceFix( + parameterType, methodSourceAnnotation, factoryMethod, state)) + .map(fix -> describeMatch(methodSourceAnnotation, fix))) + .orElse(Description.NO_MATCH); + } + + /** + * Returns the name of the value factory method pointed to by the given {@code @MethodSource} + * annotation, if it (a) is the only one and (b) is a method in the same class as the annotated + * method. + */ + private static Optional getSoleLocalFactoryName( + AnnotationTree methodSourceAnnotation, MethodTree method) { + return getElementIfSingleton(getMethodSourceFactoryNames(methodSourceAnnotation, method)) + .filter(name -> name.indexOf('#') < 0); + } + + /** + * Tells whether the given method has a sibling method in the same class that depends on the + * specified value factory method. + */ + private static boolean hasSiblingReferencingValueFactory( + MethodTree tree, String valueFactory, VisitorState state) { + return findMatchingSibling(tree, m -> hasValueFactory(m, valueFactory, state), state) + .isPresent(); + } + + private static Optional findSiblingWithName( + MethodTree tree, String methodName, VisitorState state) { + return findMatchingSibling(tree, m -> m.getName().contentEquals(methodName), state); + } + + private static Optional findMatchingSibling( + MethodTree tree, Predicate predicate, VisitorState state) { + return state.findEnclosing(ClassTree.class).getMembers().stream() + .filter(MethodTree.class::isInstance) + .map(MethodTree.class::cast) + .filter(not(tree::equals)) + .filter(predicate) + .findFirst(); + } + + private static boolean hasValueFactory( + MethodTree tree, String valueFactoryMethodName, VisitorState state) { + return findMethodSourceAnnotation(tree, state).stream() + .anyMatch( + annotation -> + getMethodSourceFactoryNames(annotation, tree).contains(valueFactoryMethodName)); + } + + private static Optional findMethodSourceAnnotation( + MethodTree tree, VisitorState state) { + return HAS_METHOD_SOURCE.multiMatchResult(tree, state).matchingNodes().stream().findFirst(); + } + + private static Optional tryConstructValueSourceFix( + Type parameterType, + AnnotationTree methodSourceAnnotation, + MethodTree valueFactoryMethod, + VisitorState state) { + return getSingleReturnExpression(valueFactoryMethod) + .flatMap(expression -> tryExtractValueSourceAttributeValue(expression, state)) + .map( + valueSourceAttributeValue -> + SuggestedFix.builder() + .addImport("org.junit.jupiter.params.provider.ValueSource") + .replace( + methodSourceAnnotation, + String.format( + "@ValueSource(%s = %s)", + toValueSourceAttributeName(parameterType), valueSourceAttributeValue)) + .delete(valueFactoryMethod) + .build()); + } + + // XXX: This pattern also occurs a few times inside Error Prone; contribute upstream. + private static Optional getSingleReturnExpression(MethodTree methodTree) { + List returnExpressions = new ArrayList<>(); + new TreeScanner<@Nullable Void, @Nullable Void>() { + @Override + public @Nullable Void visitClass(ClassTree node, @Nullable Void unused) { + /* Ignore `return` statements inside anonymous/local classes. */ + return null; + } + + @Override + public @Nullable Void visitReturn(ReturnTree node, @Nullable Void unused) { + returnExpressions.add(node.getExpression()); + return super.visitReturn(node, unused); + } + + @Override + public @Nullable Void visitLambdaExpression( + LambdaExpressionTree node, @Nullable Void unused) { + /* Ignore `return` statements inside lambda expressions. */ + return null; + } + }.scan(methodTree, null); + + return getElementIfSingleton(returnExpressions); + } + + private static Optional tryExtractValueSourceAttributeValue( + ExpressionTree tree, VisitorState state) { + List arguments; + if (ENUMERATION_OF_SUPPORTED_SINGLE_VALUE_ARGUMENTS.matches(tree, state)) { + arguments = ((MethodInvocationTree) tree).getArguments(); + } else if (ARRAY_OF_SUPPORTED_SINGLE_VALUE_ARGUMENTS.matches(tree, state)) { + arguments = ((NewArrayTree) tree).getInitializers(); + } else { + return Optional.empty(); + } + + /* + * Join the values into a comma-separated string, unwrapping `Arguments` factory method + * invocations if applicable. + */ + return Optional.of( + arguments.stream() + .map( + arg -> + arg instanceof MethodInvocationTree + ? Iterables.getOnlyElement(((MethodInvocationTree) arg).getArguments()) + : arg) + .map(argument -> SourceCode.treeToString(argument, state)) + .collect(joining(", "))) + .map(value -> arguments.size() > 1 ? String.format("{%s}", value) : value); + } + + private static String toValueSourceAttributeName(Type type) { + String typeString = type.tsym.name.toString(); + + switch (typeString) { + case "Class": + return "classes"; + case "Character": + return "chars"; + case "Integer": + return "ints"; + default: + return typeString.toLowerCase(Locale.ROOT) + 's'; + } + } + + private static Optional getElementIfSingleton(Collection collection) { + return Optional.of(collection) + .filter(elements -> elements.size() == 1) + .map(Iterables::getOnlyElement); + } + + private static Matcher isSingleDimensionArrayCreationWithAllElementsMatching( + Matcher elementMatcher) { + return (tree, state) -> { + if (!(tree instanceof NewArrayTree)) { + return false; + } + + NewArrayTree newArray = (NewArrayTree) tree; + return newArray.getDimensions().isEmpty() + && !newArray.getInitializers().isEmpty() + && newArray.getInitializers().stream() + .allMatch(element -> elementMatcher.matches(element, state)); + }; + } + + private static Matcher isArrayArgumentValueCandidate() { + return anyOf(classLiteral(anything()), (tree, state) -> ASTHelpers.constValue(tree) != null); + } +} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java index 3fae404499..53c6e0f905 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java @@ -7,6 +7,7 @@ import static com.google.errorprone.matchers.Matchers.allOf; import static com.google.errorprone.matchers.Matchers.anyMethod; import static com.google.errorprone.matchers.Matchers.anyOf; +import static com.google.errorprone.matchers.Matchers.anything; import static com.google.errorprone.matchers.Matchers.argumentCount; import static com.google.errorprone.matchers.Matchers.isNonNullUsingDataflow; import static com.google.errorprone.matchers.Matchers.isSameType; @@ -67,9 +68,7 @@ public final class RedundantStringConversion extends BugChecker private static final String EXTRA_STRING_CONVERSION_METHODS_FLAG = "RedundantStringConversion:ExtraConversionMethods"; - @SuppressWarnings("UnnecessaryLambda") - private static final Matcher ANY_EXPR = (t, s) -> true; - + private static final Matcher ANY_EXPR = anything(); private static final Matcher LOCALE = isSameType(Locale.class); private static final Matcher MARKER = isSubtypeOf("org.slf4j.Marker"); private static final Matcher STRING = isSameType(String.class); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java index c26bda471f..04b230b61e 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java @@ -1,6 +1,6 @@ package tech.picnic.errorprone.bugpatterns.util; -import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.errorprone.matchers.ChildMultiMatcher.MatchType.AT_LEAST_ONE; import static com.google.errorprone.matchers.Matchers.annotations; import static com.google.errorprone.matchers.Matchers.anyOf; @@ -9,7 +9,7 @@ import static tech.picnic.errorprone.bugpatterns.util.MoreMatchers.hasMetaAnnotation; import com.google.common.base.Strings; -import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableList; import com.google.errorprone.matchers.AnnotationMatcherUtils; import com.google.errorprone.matchers.Matcher; import com.google.errorprone.matchers.MultiMatcher; @@ -55,25 +55,59 @@ private MoreJUnitMatchers() {} * Returns the names of the JUnit value factory methods specified by the given {@link * org.junit.jupiter.params.provider.MethodSource} annotation. * + *

This method differs from {@link #getMethodSourceFactoryDescriptors(AnnotationTree, + * MethodTree)} in that it drops any parenthesized method parameter type enumerations. That is, + * method descriptors such as {@code factoryMethod()} and {@code factoryMethod(java.lang.String)} + * are both simplified to just {@code factoryMethod}. This also means that the returned method + * names may not unambiguously reference a single value factory method; in such a case JUnit will + * throw an error at runtime. + * * @param methodSourceAnnotation The annotation from which to extract value factory method names. - * @return One or more value factory names. + * @param method The method on which the annotation is located. + * @return One or more value factory descriptors, in the order defined. + * @see #getMethodSourceFactoryDescriptors(AnnotationTree, MethodTree) + */ + // XXX: Drop this method in favour of `#getMethodSourceFactoryDescriptors`. That will require + // callers to either explicitly drop information, or perform a more advanced analysis. + public static ImmutableList getMethodSourceFactoryNames( + AnnotationTree methodSourceAnnotation, MethodTree method) { + return getMethodSourceFactoryDescriptors(methodSourceAnnotation, method).stream() + .map( + descriptor -> { + int index = descriptor.indexOf('('); + return index < 0 ? descriptor : descriptor.substring(0, index); + }) + .collect(toImmutableList()); + } + + /** + * Returns the descriptors of the JUnit value factory methods specified by the given {@link + * org.junit.jupiter.params.provider.MethodSource} annotation. + * + * @param methodSourceAnnotation The annotation from which to extract value factory method + * descriptors. + * @param method The method on which the annotation is located. + * @return One or more value factory descriptors, in the order defined. + * @see #getMethodSourceFactoryNames(AnnotationTree, MethodTree) */ - static ImmutableSet getMethodSourceFactoryNames( + // XXX: Rather than strings, have this method return instances of a value type capable of + // resolving the value factory method pointed to. + public static ImmutableList getMethodSourceFactoryDescriptors( AnnotationTree methodSourceAnnotation, MethodTree method) { String methodName = method.getName().toString(); ExpressionTree value = AnnotationMatcherUtils.getArgument(methodSourceAnnotation, "value"); if (!(value instanceof NewArrayTree)) { - return ImmutableSet.of(toMethodSourceFactoryName(value, methodName)); + return ImmutableList.of(toMethodSourceFactoryDescriptor(value, methodName)); } return ((NewArrayTree) value) .getInitializers().stream() - .map(name -> toMethodSourceFactoryName(name, methodName)) - .collect(toImmutableSet()); + .map(name -> toMethodSourceFactoryDescriptor(name, methodName)) + .collect(toImmutableList()); } - private static String toMethodSourceFactoryName( + private static String toMethodSourceFactoryDescriptor( @Nullable ExpressionTree tree, String annotatedMethodName) { return requireNonNullElse( Strings.emptyToNull(ASTHelpers.constValue(tree, String.class)), annotatedMethodName); diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitValueSourceTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitValueSourceTest.java new file mode 100644 index 0000000000..13ed3fa24d --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/JUnitValueSourceTest.java @@ -0,0 +1,496 @@ +package tech.picnic.errorprone.bugpatterns; + +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; +import com.google.errorprone.CompilationTestHelper; +import org.junit.jupiter.api.Test; + +final class JUnitValueSourceTest { + @Test + void identification() { + CompilationTestHelper.newInstance(JUnitValueSource.class, getClass()) + .addSourceLines( + "A.java", + "import static org.junit.jupiter.params.provider.Arguments.arguments;", + "", + "import java.util.Optional;", + "import java.util.stream.Stream;", + "import org.junit.jupiter.params.ParameterizedTest;", + "import org.junit.jupiter.params.provider.Arguments;", + "import org.junit.jupiter.params.provider.MethodSource;", + "", + "class A {", + " private static Stream identificationTestCases() {", + " return Stream.of(arguments(1), Arguments.of(2));", + " }", + "", + " @ParameterizedTest", + " // BUG: Diagnostic contains:", + " @MethodSource(\"identificationTestCases\")", + " void identification(int foo) {}", + "", + " private static int[] identificationWithParensTestCases() {", + " return new int[] {1, 2};", + " }", + "", + " @ParameterizedTest", + " // BUG: Diagnostic contains:", + " @MethodSource(\"identificationWithParensTestCases()\")", + " void identificationWithParens(int foo) {}", + "", + " @ParameterizedTest", + " @MethodSource(\"valueFactoryMissingTestCases\")", + " void valueFactoryMissing(int foo) {}", + "", + " private static Stream multipleUsagesTestCases() {", + " return Stream.of(arguments(1), Arguments.of(2));", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"multipleUsagesTestCases\")", + " void multipleUsages1(int foo) {}", + "", + " @ParameterizedTest", + " @MethodSource(\"multipleUsagesTestCases()\")", + " void multipleUsages2(int bar) {}", + "", + " private static Stream valueFactoryRepeatedTestCases() {", + " return Stream.of(arguments(1), arguments(2));", + " }", + "", + " @ParameterizedTest", + " @MethodSource({\"valueFactoryRepeatedTestCases\", \"valueFactoryRepeatedTestCases\"})", + " void valueFactoryRepeated(int foo) {}", + "", + " private static Stream multipleParametersTestCases() {", + " return Stream.of(arguments(1, 2), arguments(3, 4));", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"multipleParametersTestCases\")", + " void multipleParameters(int first, int second) {}", + "", + " private static int[] arrayWithoutInitializersTestCases() {", + " return new int[1];", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"arrayWithoutInitializersTestCases\")", + " void arrayWithoutInitializers(int foo) {}", + "", + " private static Stream runtimeValueTestCases() {", + " int second = 2;", + " return Stream.of(arguments(1), arguments(second));", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"runtimeValueTestCases\")", + " void runtimeValue(int foo) {}", + "", + " private static Stream streamChainTestCases() {", + " return Stream.of(1, 2).map(Arguments::arguments);", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"streamChainTestCases\")", + " void streamChain(int number) {}", + "", + " private static Stream multipleReturnsTestCases() {", + " if (true) {", + " return Stream.of(arguments(1), arguments(2));", + " } else {", + " return Stream.of(arguments(3), arguments(4));", + " }", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"multipleReturnsTestCases\")", + " void multipleReturns(int number) {}", + "", + " private static Stream multipleFactoriesFooTestCases() {", + " return Stream.of(arguments(1));", + " }", + "", + " private static Stream multipleFactoriesBarTestCases() {", + " return Stream.of(arguments(1));", + " }", + "", + " @ParameterizedTest", + " @MethodSource({\"multipleFactoriesFooTestCases\", \"multipleFactoriesBarTestCases\"})", + " void multipleFactories(int i) {}", + "", + " private static Stream extraArgsTestCases() {", + " return Stream.of(arguments(1), arguments(1, 2));", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"extraArgsTestCases\")", + " void extraArgs(int... i) {}", + "", + " private static Stream localClassTestCases() {", + " class Foo {", + " Stream foo() {", + " return Stream.of(arguments(1), arguments(2));", + " }", + " }", + " return Stream.of(arguments(1), arguments(2));", + " }", + "", + " @ParameterizedTest", + " // BUG: Diagnostic contains:", + " @MethodSource(\"localClassTestCases\")", + " void localClass(int i) {}", + "", + " private static Stream lambdaReturnTestCases() {", + " int foo =", + " Optional.of(10)", + " .map(", + " i -> {", + " return i / 2;", + " })", + " .orElse(0);", + " return Stream.of(arguments(1), arguments(1));", + " }", + "", + " @ParameterizedTest", + " // BUG: Diagnostic contains:", + " @MethodSource(\"lambdaReturnTestCases\")", + " void lambdaReturn(int i) {}", + "", + " @ParameterizedTest", + " @MethodSource(\"tech.picnic.errorprone.Foo#fooTestCases\")", + " void staticMethodReference(int foo) {}", + "", + " private static Stream valueFactoryWithArgumentTestCases(int amount) {", + " return Stream.of(arguments(1), arguments(2));", + " }", + "", + " @ParameterizedTest", + " // BUG: Diagnostic contains:", + " @MethodSource(\"valueFactoryWithArgumentTestCases\")", + " void valueFactoryWithArgument(int foo) {}", + "", + " private static Arguments[] emptyArrayValueFactoryTestCases() {", + " return new Arguments[] {};", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"emptyArrayValueFactoryTestCases\")", + " void emptyArrayValueFactory(int foo) {}", + "", + " private static Stream emptyStreamValueFactoryTestCases() {", + " return Stream.of();", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"emptyStreamValueFactoryTestCases\")", + " void emptyStreamValueFactory(int foo) {}", + "", + " private static Arguments[] invalidValueFactoryArgumentsTestCases() {", + " return new Arguments[] {arguments(1), arguments(new Object() {})};", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"invalidValueFactoryArgumentsTestCases\")", + " void invalidValueFactoryArguments(int foo) {}", + "}") + .doTest(); + } + + @Test + void replacement() { + BugCheckerRefactoringTestHelper.newInstance(JUnitValueSource.class, getClass()) + .addInputLines( + "A.java", + "import static org.junit.jupiter.params.provider.Arguments.arguments;", + "", + "import com.google.common.collect.ImmutableList;", + "import com.google.common.collect.ImmutableSet;", + "import java.util.List;", + "import java.util.Set;", + "import java.util.stream.DoubleStream;", + "import java.util.stream.IntStream;", + "import java.util.stream.LongStream;", + "import java.util.stream.Stream;", + "import org.junit.jupiter.params.ParameterizedTest;", + "import org.junit.jupiter.params.provider.Arguments;", + "import org.junit.jupiter.params.provider.MethodSource;", + "", + "class A {", + " private static final boolean CONST_BOOLEAN = false;", + " private static final byte CONST_BYTE = 42;", + " private static final char CONST_CHARACTER = 'a';", + " private static final short CONST_SHORT = 42;", + " private static final int CONST_INTEGER = 42;", + " private static final long CONST_LONG = 42;", + " private static final float CONST_FLOAT = 42;", + " private static final double CONST_DOUBLE = 42;", + " private static final String CONST_STRING = \"foo\";", + "", + " private static Stream streamOfBooleanArguments() {", + " return Stream.of(arguments(false), arguments(true), arguments(CONST_BOOLEAN));", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"streamOfBooleanArguments\")", + " void primitiveBoolean(boolean b) {}", + "", + " private static Stream streamOfBooleansAndBooleanArguments() {", + " return Stream.of(false, arguments(true), CONST_BOOLEAN);", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"streamOfBooleansAndBooleanArguments\")", + " void boxedBoolean(Boolean b) {}", + "", + " private static List listOfByteArguments() {", + " return List.of(arguments((byte) 0), arguments((byte) 1), arguments(CONST_BYTE));", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"listOfByteArguments\")", + " void primitiveByte(byte b) {}", + "", + " private static List listOfBytesAndByteArguments() {", + " return List.of((byte) 0, arguments((byte) 1), CONST_BYTE);", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"listOfBytesAndByteArguments\")", + " void boxedByte(Byte b) {}", + "", + " private static Set setOfCharacterArguments() {", + " return Set.of(arguments((char) 0), arguments((char) 1), arguments(CONST_CHARACTER));", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"setOfCharacterArguments\")", + " void primitiveCharacter(char c) {}", + "", + " private static Set setOfCharactersAndCharacterArguments() {", + " return Set.of((char) 0, arguments((char) 1), CONST_CHARACTER);", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"setOfCharactersAndCharacterArguments\")", + " void boxedCharacter(Character c) {}", + "", + " private static Arguments[] arrayOfShortArguments() {", + " return new Arguments[] {arguments((short) 0), arguments((short) 1), arguments(CONST_SHORT)};", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"arrayOfShortArguments\")", + " void primitiveShort(short s) {}", + "", + " private static Object[] arrayOfShortsAndShortArguments() {", + " return new Object[] {(short) 0, arguments((short) 1), CONST_SHORT};", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"arrayOfShortsAndShortArguments\")", + " void boxedShort(Short s) {}", + "", + " private static IntStream intStream() {", + " return IntStream.of(0, 1, CONST_INTEGER);", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"intStream\")", + " void primitiveInteger(int i) {}", + "", + " private static int[] intArray() {", + " return new int[] {0, 1, CONST_INTEGER};", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"intArray\")", + " void boxedInteger(Integer i) {}", + "", + " private static LongStream longStream() {", + " return LongStream.of(0, 1, CONST_LONG);", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"longStream\")", + " void primitiveLong(long l) {}", + "", + " private static long[] longArray() {", + " return new long[] {0, 1, CONST_LONG};", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"longArray\")", + " void boxedLong(Long l) {}", + "", + " private static ImmutableList immutableListOfFloatArguments() {", + " return ImmutableList.of(arguments(0.0F), arguments(1.0F), arguments(CONST_FLOAT));", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"immutableListOfFloatArguments\")", + " void primitiveFloat(float f) {}", + "", + " private static Stream streamOfFloatsAndFloatArguments() {", + " return Stream.of(0.0F, arguments(1.0F), CONST_FLOAT);", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"streamOfFloatsAndFloatArguments\")", + " void boxedFloat(Float f) {}", + "", + " private static DoubleStream doubleStream() {", + " return DoubleStream.of(0, 1, CONST_DOUBLE);", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"doubleStream\")", + " void primitiveDouble(double d) {}", + "", + " private static double[] doubleArray() {", + " return new double[] {0, 1, CONST_DOUBLE};", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"doubleArray\")", + " void boxedDouble(Double d) {}", + "", + " private static ImmutableSet immutableSetOfStringArguments() {", + " return ImmutableSet.of(arguments(\"foo\"), arguments(\"bar\"), arguments(CONST_STRING));", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"immutableSetOfStringArguments\")", + " void string(String s) {}", + "", + " private static Stream> streamOfClasses() {", + " return Stream.of(Stream.class, java.util.Map.class);", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"streamOfClasses\")", + " void clazz(Class c) {}", + "", + " private static Stream sameNameFactoryTestCases() {", + " return Stream.of(arguments(1));", + " }", + "", + " private static Stream sameNameFactoryTestCases(int overload) {", + " return Stream.of(arguments(overload));", + " }", + "", + " @ParameterizedTest", + " @MethodSource(\"sameNameFactoryTestCases\")", + " void sameNameFactory(int i) {}", + "}") + .addOutputLines( + "A.java", + "import static org.junit.jupiter.params.provider.Arguments.arguments;", + "", + "import com.google.common.collect.ImmutableList;", + "import com.google.common.collect.ImmutableSet;", + "import java.util.List;", + "import java.util.Set;", + "import java.util.stream.DoubleStream;", + "import java.util.stream.IntStream;", + "import java.util.stream.LongStream;", + "import java.util.stream.Stream;", + "import org.junit.jupiter.params.ParameterizedTest;", + "import org.junit.jupiter.params.provider.Arguments;", + "import org.junit.jupiter.params.provider.MethodSource;", + "import org.junit.jupiter.params.provider.ValueSource;", + "", + "class A {", + " private static final boolean CONST_BOOLEAN = false;", + " private static final byte CONST_BYTE = 42;", + " private static final char CONST_CHARACTER = 'a';", + " private static final short CONST_SHORT = 42;", + " private static final int CONST_INTEGER = 42;", + " private static final long CONST_LONG = 42;", + " private static final float CONST_FLOAT = 42;", + " private static final double CONST_DOUBLE = 42;", + " private static final String CONST_STRING = \"foo\";", + "", + " @ParameterizedTest", + " @ValueSource(booleans = {false, true, CONST_BOOLEAN})", + " void primitiveBoolean(boolean b) {}", + "", + " @ParameterizedTest", + " @ValueSource(booleans = {false, true, CONST_BOOLEAN})", + " void boxedBoolean(Boolean b) {}", + "", + " @ParameterizedTest", + " @ValueSource(bytes = {(byte) 0, (byte) 1, CONST_BYTE})", + " void primitiveByte(byte b) {}", + "", + " @ParameterizedTest", + " @ValueSource(bytes = {(byte) 0, (byte) 1, CONST_BYTE})", + " void boxedByte(Byte b) {}", + "", + " @ParameterizedTest", + " @ValueSource(chars = {(char) 0, (char) 1, CONST_CHARACTER})", + " void primitiveCharacter(char c) {}", + "", + " @ParameterizedTest", + " @ValueSource(chars = {(char) 0, (char) 1, CONST_CHARACTER})", + " void boxedCharacter(Character c) {}", + "", + " @ParameterizedTest", + " @ValueSource(shorts = {(short) 0, (short) 1, CONST_SHORT})", + " void primitiveShort(short s) {}", + "", + " @ParameterizedTest", + " @ValueSource(shorts = {(short) 0, (short) 1, CONST_SHORT})", + " void boxedShort(Short s) {}", + "", + " @ParameterizedTest", + " @ValueSource(ints = {0, 1, CONST_INTEGER})", + " void primitiveInteger(int i) {}", + "", + " @ParameterizedTest", + " @ValueSource(ints = {0, 1, CONST_INTEGER})", + " void boxedInteger(Integer i) {}", + "", + " @ParameterizedTest", + " @ValueSource(longs = {0, 1, CONST_LONG})", + " void primitiveLong(long l) {}", + "", + " @ParameterizedTest", + " @ValueSource(longs = {0, 1, CONST_LONG})", + " void boxedLong(Long l) {}", + "", + " @ParameterizedTest", + " @ValueSource(floats = {0.0F, 1.0F, CONST_FLOAT})", + " void primitiveFloat(float f) {}", + "", + " @ParameterizedTest", + " @ValueSource(floats = {0.0F, 1.0F, CONST_FLOAT})", + " void boxedFloat(Float f) {}", + "", + " @ParameterizedTest", + " @ValueSource(doubles = {0, 1, CONST_DOUBLE})", + " void primitiveDouble(double d) {}", + "", + " @ParameterizedTest", + " @ValueSource(doubles = {0, 1, CONST_DOUBLE})", + " void boxedDouble(Double d) {}", + "", + " @ParameterizedTest", + " @ValueSource(strings = {\"foo\", \"bar\", CONST_STRING})", + " void string(String s) {}", + "", + " @ParameterizedTest", + " @ValueSource(classes = {Stream.class, java.util.Map.class})", + " void clazz(Class c) {}", + "", + " private static Stream sameNameFactoryTestCases(int overload) {", + " return Stream.of(arguments(overload));", + " }", + "", + " @ParameterizedTest", + " @ValueSource(ints = 1)", + " void sameNameFactory(int i) {}", + "}") + .doTest(TestMode.TEXT_MATCH); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchersTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchersTest.java index caab722793..f21d57c608 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchersTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchersTest.java @@ -83,6 +83,40 @@ void methodMatchers() { @Test void getMethodSourceFactoryNames() { CompilationTestHelper.newInstance(MethodSourceFactoryNamesTestChecker.class, getClass()) + .addSourceLines( + "A.java", + "import org.junit.jupiter.params.provider.MethodSource;", + "", + "class A {", + " @MethodSource", + " // BUG: Diagnostic contains: [matchingMethodSource]", + " void matchingMethodSource(boolean b) {}", + "", + " @MethodSource(\"myValueFactory\")", + " // BUG: Diagnostic contains: [myValueFactory]", + " void singleCustomMethodSource(boolean b) {}", + "", + " @MethodSource({", + " \"nullary()\",", + " \"nullary()\",", + " \"\",", + " \"withStringParam(java.lang.String)\",", + " \"paramsUnspecified\"", + " })", + " // BUG: Diagnostic contains: [nullary, nullary, multipleMethodSources, withStringParam,", + " // paramsUnspecified]", + " void multipleMethodSources(boolean b) {}", + "", + " @MethodSource({\"foo\", \"()\", \"bar\"})", + " // BUG: Diagnostic contains: [foo, , bar]", + " void methodSourceWithoutName(boolean b) {}", + "}") + .doTest(); + } + + @Test + void getMethodSourceFactoryDescriptors() { + CompilationTestHelper.newInstance(MethodSourceFactoryDescriptorsTestChecker.class, getClass()) .addSourceLines( "A.java", "import org.junit.jupiter.params.provider.MethodSource;", @@ -119,6 +153,14 @@ void getMethodSourceFactoryNames() { " @MethodSource({\"myValueFactory\", \"\"})", " // BUG: Diagnostic contains: [myValueFactory, customAndMatchingMethodSources]", " void customAndMatchingMethodSources(boolean b) {}", + "", + " @MethodSource({\"factory\", \"\", \"factory\", \"\"})", + " // BUG: Diagnostic contains: [factory, repeatedMethodSources, factory, repeatedMethodSources]", + " void repeatedMethodSources(boolean b) {}", + "", + " @MethodSource({\"nullary()\", \"withStringParam(java.lang.String)\"})", + " // BUG: Diagnostic contains: [nullary(), withStringParam(java.lang.String)]", + " void methodSourcesWithParameterSpecification(boolean b) {}", "}") .doTest(); } @@ -170,4 +212,25 @@ public Description matchMethod(MethodTree tree, VisitorState state) { .build(); } } + + /** + * A {@link BugChecker} that flags methods with a JUnit {@code @MethodSource} annotation by + * enumerating the associated value factory method descriptors. + */ + @BugPattern(summary = "Interacts with `MoreJUnitMatchers` for testing purposes", severity = ERROR) + public static final class MethodSourceFactoryDescriptorsTestChecker extends BugChecker + implements MethodTreeMatcher { + private static final long serialVersionUID = 1L; + + @Override + public Description matchMethod(MethodTree tree, VisitorState state) { + AnnotationTree annotation = + Iterables.getOnlyElement(HAS_METHOD_SOURCE.multiMatchResult(tree, state).matchingNodes()); + + return buildDescription(tree) + .setMessage( + MoreJUnitMatchers.getMethodSourceFactoryDescriptors(annotation, tree).toString()) + .build(); + } + } } From 43d50f2ef905a4a96ab0fed54cdae014cff1a9b0 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 3 Mar 2023 08:35:36 +0100 Subject: [PATCH 212/601] Upgrade Project Reactor 2022.0.3 -> 2022.0.4 (#518) See: - https://github.com/reactor/reactor/releases/tag/2022.0.4 - https://github.com/reactor/reactor/compare/2022.0.3...2022.0.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ffa389db2e..de9655a3c4 100644 --- a/pom.xml +++ b/pom.xml @@ -287,7 +287,7 @@ io.projectreactor reactor-bom - 2022.0.3 + 2022.0.4 pom import From 2111c81784efcebde3d65eb227332b72105795e1 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 3 Mar 2023 08:53:01 +0100 Subject: [PATCH 213/601] Upgrade pitest-maven-plugin 1.11.1 -> 1.11.3 (#514) See: - https://github.com/hcoles/pitest/releases/tag/1.11.2 - https://github.com/hcoles/pitest/releases/tag/1.11.3 - https://github.com/hcoles/pitest/compare/1.11.1...1.11.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index de9655a3c4..a81f43c1f1 100644 --- a/pom.xml +++ b/pom.xml @@ -1283,7 +1283,7 @@ org.pitest pitest-maven - 1.11.1 + 1.11.3 From 03f0e0493bef7dd31ac84f2ace8d70c5ac17e1b1 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 3 Mar 2023 10:17:22 +0100 Subject: [PATCH 214/601] Upgrade Checker Framework Annotations 3.31.0 -> 3.32.0 (#519) See: - https://github.com/typetools/checker-framework/releases/tag/checker-framework-3.32.0 - https://github.com/typetools/checker-framework/compare/checker-framework-3.31.0...checker-framework-3.32.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a81f43c1f1..97de921540 100644 --- a/pom.xml +++ b/pom.xml @@ -356,7 +356,7 @@ org.checkerframework checker-qual - 3.31.0 + 3.32.0 org.hamcrest From b267b4dba814fc00fc73e040f551d6f1d1514e8f Mon Sep 17 00:00:00 2001 From: Bastien Diederichs Date: Fri, 3 Mar 2023 13:09:44 +0100 Subject: [PATCH 215/601] Introduce `ImmutableMapCopyOfMapsFilter{Keys,Values}` Refaster rules (#517) --- .../refasterrules/ImmutableMapRules.java | 52 ++++++++++++++++--- .../ImmutableMapRulesTestInput.java | 12 +++++ .../ImmutableMapRulesTestOutput.java | 8 +++ 3 files changed, 65 insertions(+), 7 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMapRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMapRules.java index aa68506b83..9e5096bbe8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMapRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMapRules.java @@ -6,6 +6,7 @@ import static java.util.Collections.singletonMap; import static java.util.function.Function.identity; +import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import com.google.common.collect.Streams; @@ -126,8 +127,8 @@ ImmutableMap after(Iterable> } /** - * Don't map a a stream's elements to map entries, only to subsequently collect them into an - * {@link ImmutableMap}. The collection can be performed directly. + * Don't map a stream's elements to map entries, only to subsequently collect them into an {@link + * ImmutableMap}. The collection can be performed directly. */ abstract static class StreamOfMapEntriesToImmutableMap { @Placeholder(allowsIdentity = true) @@ -315,6 +316,48 @@ ImmutableMap after(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V } } + /** + * Prefer creation of an immutable submap using {@link Maps#filterKeys(Map, Predicate)} over more + * contrived alternatives. + */ + abstract static class ImmutableMapCopyOfMapsFilterKeys { + @Placeholder(allowsIdentity = true) + abstract boolean keyFilter(@MayOptionallyUse K key); + + @BeforeTemplate + ImmutableMap before(ImmutableMap map) { + return map.entrySet().stream() + .filter(e -> keyFilter(e.getKey())) + .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)); + } + + @AfterTemplate + ImmutableMap after(ImmutableMap map) { + return ImmutableMap.copyOf(Maps.filterKeys(map, k -> keyFilter(k))); + } + } + + /** + * Prefer creation of an immutable submap using {@link Maps#filterValues(Map, Predicate)} over + * more contrived alternatives. + */ + abstract static class ImmutableMapCopyOfMapsFilterValues { + @Placeholder(allowsIdentity = true) + abstract boolean valueFilter(@MayOptionallyUse V value); + + @BeforeTemplate + ImmutableMap before(ImmutableMap map) { + return map.entrySet().stream() + .filter(e -> valueFilter(e.getValue())) + .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)); + } + + @AfterTemplate + ImmutableMap after(ImmutableMap map) { + return ImmutableMap.copyOf(Maps.filterValues(map, v -> valueFilter(v))); + } + } + // XXX: Add a rule for this: // Maps.transformValues(streamOfEntries.collect(groupBy(fun)), ImmutableMap::copyOf) // -> @@ -323,9 +366,4 @@ ImmutableMap after(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V // map.entrySet().stream().filter(keyPred).forEach(mapBuilder::put) // -> // mapBuilder.putAll(Maps.filterKeys(map, pred)) - // - // map.entrySet().stream().filter(entry -> - // pred(entry.getKey())).collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)) - // -> - // ImmutableMap.copyOf(Maps.filterKeys(map, pred)) } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestInput.java index b4cd5f950e..3db671a7a9 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestInput.java @@ -107,4 +107,16 @@ Map testImmutableMapOf4() { Map testImmutableMapOf5() { return Map.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5"); } + + ImmutableMap testImmutableMapCopyOfMapsFilterKeys() { + return ImmutableMap.of("foo", 1).entrySet().stream() + .filter(entry -> entry.getKey().length() > 1) + .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)); + } + + ImmutableMap testImmutableMapCopyOfMapsFilterValues() { + return ImmutableMap.of("foo", 1).entrySet().stream() + .filter(entry -> entry.getValue() > 0) + .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestOutput.java index 4c1ddf948f..1b135e32de 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestOutput.java @@ -90,4 +90,12 @@ Map testImmutableMapOf4() { Map testImmutableMapOf5() { return ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5"); } + + ImmutableMap testImmutableMapCopyOfMapsFilterKeys() { + return ImmutableMap.copyOf(Maps.filterKeys(ImmutableMap.of("foo", 1), k -> k.length() > 1)); + } + + ImmutableMap testImmutableMapCopyOfMapsFilterValues() { + return ImmutableMap.copyOf(Maps.filterValues(ImmutableMap.of("foo", 1), v -> v > 0)); + } } From 4bb14b01ec2452c41346222ac127c4e79ada9ada Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 4 Mar 2023 14:19:29 +0100 Subject: [PATCH 216/601] Upgrade pitest-maven-plugin 1.11.3 -> 1.11.4 (#520) See: - https://github.com/hcoles/pitest/releases/tag/1.11.4 - https://github.com/hcoles/pitest/compare/1.11.3...1.11.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 97de921540..711fb40dbc 100644 --- a/pom.xml +++ b/pom.xml @@ -1283,7 +1283,7 @@ org.pitest pitest-maven - 1.11.3 + 1.11.4 From 61c9f67f66c36ee5bc3909ab5e5295cf08a9674e Mon Sep 17 00:00:00 2001 From: Pieter Dirk Soels Date: Mon, 6 Mar 2023 09:54:26 +0100 Subject: [PATCH 217/601] Introduce `MockitoMockClassReference` check (#454) Flags Mockito mock and spy creation expressions that explicitly specify the type of mock or spy to create, while this information can also be inferred from context. --- .../MockitoMockClassReference.java | 90 ++++++++++++ .../MockitoMockClassReferenceTest.java | 136 ++++++++++++++++++ ...AnnotatedCompositeCodeTransformerTest.java | 10 +- 3 files changed, 231 insertions(+), 5 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MockitoMockClassReference.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MockitoMockClassReferenceTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MockitoMockClassReference.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MockitoMockClassReference.java new file mode 100644 index 0000000000..4aa3af46e6 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MockitoMockClassReference.java @@ -0,0 +1,90 @@ +package tech.picnic.errorprone.bugpatterns; + +import static com.google.errorprone.BugPattern.LinkType.CUSTOM; +import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; +import static com.google.errorprone.BugPattern.StandardTags.SIMPLIFICATION; +import static com.google.errorprone.matchers.Matchers.allOf; +import static com.google.errorprone.matchers.Matchers.argument; +import static com.google.errorprone.matchers.Matchers.isSameType; +import static com.google.errorprone.matchers.Matchers.isVariable; +import static com.google.errorprone.matchers.Matchers.not; +import static com.google.errorprone.matchers.Matchers.staticMethod; +import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; + +import com.google.auto.service.AutoService; +import com.google.errorprone.BugPattern; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; +import com.google.errorprone.fixes.SuggestedFixes; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.util.ASTHelpers; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.LambdaExpressionTree; +import com.sun.source.tree.MethodInvocationTree; +import com.sun.source.tree.MethodTree; +import com.sun.source.tree.Tree; +import com.sun.source.tree.VariableTree; +import java.util.List; + +/** + * A {@link BugChecker} that flags the use of {@link org.mockito.Mockito#mock(Class)} and {@link + * org.mockito.Mockito#spy(Class)} where instead the type to be mocked or spied can be derived from + * context. + */ +// XXX: This check currently does not flag method invocation arguments. When adding support for +// this, consider that in some cases the type to be mocked or spied must be specified explicitly so +// as to disambiguate between method overloads. +// XXX: This check currently does not flag (implicit or explicit) lambda return expressions. +// XXX: This check currently does not drop suppressions that become obsolete after the +// suggested fix is applied; consider adding support for this. +@AutoService(BugChecker.class) +@BugPattern( + summary = "Don't unnecessarily pass a type to Mockito's `mock(Class)` and `spy(Class)` methods", + link = BUG_PATTERNS_BASE_URL + "MockitoMockClassReference", + linkType = CUSTOM, + severity = SUGGESTION, + tags = SIMPLIFICATION) +public final class MockitoMockClassReference extends BugChecker + implements MethodInvocationTreeMatcher { + private static final long serialVersionUID = 1L; + private static final Matcher MOCKITO_MOCK_OR_SPY = + allOf( + argument(0, allOf(isSameType(Class.class.getName()), not(isVariable()))), + staticMethod().onClass("org.mockito.Mockito").namedAnyOf("mock", "spy")); + + /** Instantiates a new {@link MockitoMockClassReference} instance. */ + public MockitoMockClassReference() {} + + @Override + public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { + if (!MOCKITO_MOCK_OR_SPY.matches(tree, state) || !isTypeDerivableFromContext(tree, state)) { + return Description.NO_MATCH; + } + + List arguments = tree.getArguments(); + return describeMatch(tree, SuggestedFixes.removeElement(arguments.get(0), arguments, state)); + } + + private static boolean isTypeDerivableFromContext(MethodInvocationTree tree, VisitorState state) { + Tree parent = state.getPath().getParentPath().getLeaf(); + switch (parent.getKind()) { + case VARIABLE: + return !ASTHelpers.hasNoExplicitType((VariableTree) parent, state) + && areSameType(tree, parent, state); + case ASSIGNMENT: + return areSameType(tree, parent, state); + case RETURN: + Tree context = state.findEnclosing(LambdaExpressionTree.class, MethodTree.class); + return context instanceof MethodTree + && areSameType(tree, ((MethodTree) context).getReturnType(), state); + default: + return false; + } + } + + private static boolean areSameType(Tree treeA, Tree treeB, VisitorState state) { + return ASTHelpers.isSameType(ASTHelpers.getType(treeA), ASTHelpers.getType(treeB), state); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MockitoMockClassReferenceTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MockitoMockClassReferenceTest.java new file mode 100644 index 0000000000..8fc34e35c6 --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MockitoMockClassReferenceTest.java @@ -0,0 +1,136 @@ +package tech.picnic.errorprone.bugpatterns; + +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; +import com.google.errorprone.CompilationTestHelper; +import org.junit.jupiter.api.Test; + +final class MockitoMockClassReferenceTest { + @Test + void identification() { + CompilationTestHelper.newInstance(MockitoMockClassReference.class, getClass()) + .addSourceLines( + "A.java", + "import static org.mockito.Mockito.mock;", + "import static org.mockito.Mockito.spy;", + "import static org.mockito.Mockito.withSettings;", + "", + "import java.util.List;", + "import java.util.Objects;", + "import org.mockito.invocation.InvocationOnMock;", + "", + "class A {", + " {", + " Double d = Objects.requireNonNullElseGet(null, () -> mock(Double.class));", + " Double d2 =", + " Objects.requireNonNullElseGet(", + " null,", + " () -> {", + " return mock(Double.class);", + " });", + " }", + "", + " void m() {", + " Number variableMock = 42;", + " // BUG: Diagnostic contains:", + " variableMock = mock(Number.class);", + " // BUG: Diagnostic contains:", + " variableMock = mock(Number.class, \"name\");", + " // BUG: Diagnostic contains:", + " variableMock = mock(Number.class, InvocationOnMock::callRealMethod);", + " // BUG: Diagnostic contains:", + " variableMock = mock(Number.class, withSettings());", + " variableMock = mock(Integer.class);", + " variableMock = 42;", + " // BUG: Diagnostic contains:", + " List rawMock = mock(List.class);", + " // BUG: Diagnostic contains:", + " List genericMock = mock(List.class);", + " var varMock = mock(Integer.class);", + " Class numberType = Integer.class;", + " Number variableTypeMock = mock(numberType);", + " Object subtypeMock = mock(Integer.class);", + "", + " Number variableSpy = 42;", + " // BUG: Diagnostic contains:", + " variableSpy = spy(Number.class);", + " variableSpy = spy(Integer.class);", + " variableSpy = 42;", + " // BUG: Diagnostic contains:", + " List rawSpy = spy(List.class);", + " // BUG: Diagnostic contains:", + " List genericSpy = spy(List.class);", + " var varSpy = spy(Integer.class);", + " Number variableTypeSpy = spy(numberType);", + " Object subtypeSpy = spy(Integer.class);", + " Object objectSpy = spy(new Object());", + "", + " Objects.hash(mock(Integer.class));", + " Integer i = mock(mock(Integer.class));", + " String s = new String(mock(String.class));", + " }", + "", + " Double getDoubleMock() {", + " return Objects.requireNonNullElseGet(", + " null,", + " () -> {", + " return mock(Double.class);", + " });", + " }", + "", + " Integer getIntegerMock() {", + " // BUG: Diagnostic contains:", + " return mock(Integer.class);", + " }", + "", + " T getGenericMock(Class clazz) {", + " return mock(clazz);", + " }", + "", + " Number getSubTypeMock() {", + " return mock(Integer.class);", + " }", + "}") + .doTest(); + } + + @Test + void replacement() { + BugCheckerRefactoringTestHelper.newInstance(MockitoMockClassReference.class, getClass()) + .addInputLines( + "A.java", + "import static org.mockito.Mockito.mock;", + "import static org.mockito.Mockito.spy;", + "import static org.mockito.Mockito.withSettings;", + "", + "import org.mockito.invocation.InvocationOnMock;", + "", + "class A {", + " void m() {", + " Number simpleMock = mock(Number.class);", + " Number namedMock = mock(Number.class, \"name\");", + " Number customAnswerMock = mock(Number.class, InvocationOnMock::callRealMethod);", + " Number customSettingsMock = mock(Number.class, withSettings());", + " Number simpleSpy = spy(Number.class);", + " }", + "}") + .addOutputLines( + "A.java", + "import static org.mockito.Mockito.mock;", + "import static org.mockito.Mockito.spy;", + "import static org.mockito.Mockito.withSettings;", + "", + "import org.mockito.invocation.InvocationOnMock;", + "", + "class A {", + " void m() {", + " Number simpleMock = mock();", + " Number namedMock = mock(\"name\");", + " Number customAnswerMock = mock(InvocationOnMock::callRealMethod);", + " Number customSettingsMock = mock(withSettings());", + " Number simpleSpy = spy();", + " }", + "}") + .doTest(TestMode.TEXT_MATCH); + } +} diff --git a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformerTest.java b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformerTest.java index 51d4681543..47f30b7831 100644 --- a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformerTest.java +++ b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformerTest.java @@ -40,9 +40,9 @@ // through `RefasterTest`, but ideally it is covered by tests in this class, closer to the code that // implements the relevant logic.) See the comment in `#context()` below. final class AnnotatedCompositeCodeTransformerTest { - private static final DiagnosticPosition DUMMY_POSITION = mock(DiagnosticPosition.class); - private static final Fix DUMMY_FIX = mock(Fix.class); - private static final TreePath DUMMY_PATH = mock(TreePath.class); + private static final DiagnosticPosition DUMMY_POSITION = mock(); + private static final Fix DUMMY_FIX = mock(); + private static final TreePath DUMMY_PATH = mock(); private static final String DEFAULT_PACKAGE = ""; private static final String CUSTOM_PACKAGE = "com.example"; private static final String SIMPLE_CLASS_NAME = "MyRefasterRule"; @@ -149,7 +149,7 @@ private static CodeTransformer delegateCodeTransformer( ImmutableSet annotations, Context expectedContext, Description returnedDescription) { - CodeTransformer codeTransformer = mock(CodeTransformer.class); + CodeTransformer codeTransformer = mock(); when(codeTransformer.annotations()).thenReturn(indexAnnotations(annotations)); doAnswer( @@ -182,7 +182,7 @@ private static Description description( private static Context context() { // XXX: Use `ErrorProneOptions#processArgs` to test the // `AnnotatedCompositeCodeTransformer#overrideSeverity` logic. - Context context = mock(Context.class); + Context context = mock(); when(context.get(ErrorProneOptions.class)).thenReturn(ErrorProneOptions.empty()); return context; } From 64195279ccdc0ef58374ab63762f0c8330d41d35 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 9 Mar 2023 08:36:25 +0100 Subject: [PATCH 218/601] Upgrade Byte Buddy 1.14.0 -> 1.14.1 (#525) See: - https://github.com/raphw/byte-buddy/releases/tag/byte-buddy-1.14.1 - https://github.com/raphw/byte-buddy/compare/byte-buddy-1.14.0...byte-buddy-1.14.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 711fb40dbc..118cd2d080 100644 --- a/pom.xml +++ b/pom.xml @@ -331,7 +331,7 @@ net.bytebuddy byte-buddy - 1.14.0 + 1.14.1 - - org.apache.maven.surefire - surefire-junit-platform - ${version.surefire} - - org.codehaus.mojo From 06c8b164e9f9a82f18415efea406e62f333a2d4d Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 15 Mar 2023 13:26:40 +0100 Subject: [PATCH 225/601] Upgrade JDKs used by GitHub Actions builds (#521) Additionally: - Update the example version numbers mentioned in the issue template. - Drop some redundant whitespace from `SourceCodeTest` test code. - Sort some compiler arguments. See: - https://www.oracle.com/java/technologies/javase/11-0-17-relnotes.html - https://www.oracle.com/java/technologies/javase/11-0-18-relnotes.html - https://www.oracle.com/java/technologies/javase/17-0-5-relnotes.html - https://www.oracle.com/java/technologies/javase/17-0-6-relnotes.html - https://www.oracle.com/java/technologies/javase/19-0-1-relnotes.html - https://www.oracle.com/java/technologies/javase/19-0-2-relnotes.html --- .github/ISSUE_TEMPLATE/bug_report.md | 6 +++--- .github/workflows/build.yaml | 6 +++--- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/pitest-update-pr.yml | 2 +- .../picnic/errorprone/bugpatterns/util/SourceCodeTest.java | 4 ---- pom.xml | 2 +- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 9f7e1941b6..fce8a8f1af 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -42,9 +42,9 @@ Please replace this sentence with log output, if applicable. - Operating system (e.g. MacOS Monterey). -- Java version (i.e. `java --version`, e.g. `17.0.3`). -- Error Prone version (e.g. `2.15.0`). -- Error Prone Support version (e.g. `0.3.0`). +- Java version (i.e. `java --version`, e.g. `17.0.6`). +- Error Prone version (e.g. `2.18.0`). +- Error Prone Support version (e.g. `0.8.0`). ### Additional context diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 188450955e..5eab31a497 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,16 +10,16 @@ jobs: strategy: matrix: os: [ ubuntu-22.04 ] - jdk: [ 11.0.16, 17.0.4, 19 ] + jdk: [ 11.0.18, 17.0.6, 19.0.2 ] distribution: [ temurin ] experimental: [ false ] include: - os: macos-12 - jdk: 17.0.4 + jdk: 17.0.6 distribution: temurin experimental: false - os: windows-2022 - jdk: 17.0.4 + jdk: 17.0.6 distribution: temurin experimental: false - os: ubuntu-22.04 diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index 1c536124a8..db23d0b958 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -18,7 +18,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3.8.0 with: - java-version: 17.0.4 + java-version: 17.0.6 distribution: temurin cache: maven - name: Run Pitest diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index 240f14275f..1e3283b27a 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -22,7 +22,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3.8.0 with: - java-version: 17.0.4 + java-version: 17.0.6 distribution: temurin cache: maven - name: Download Pitest analysis artifact diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/SourceCodeTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/SourceCodeTest.java index 56668a1506..76089514b7 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/SourceCodeTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/SourceCodeTest.java @@ -31,7 +31,6 @@ void deleteWithTrailingWhitespaceAnnotations() { .expectUnchanged() .addInputLines( "AnnotationDeletions.java", - "", "interface AnnotationDeletions {", " class SoleAnnotation {", " @AnnotationToBeDeleted", @@ -66,7 +65,6 @@ void deleteWithTrailingWhitespaceAnnotations() { "}") .addOutputLines( "AnnotationDeletions.java", - "", "interface AnnotationDeletions {", " class SoleAnnotation {", " void m() {}", @@ -101,7 +99,6 @@ void deleteWithTrailingWhitespaceMethods() { refactoringTestHelper .addInputLines( "MethodDeletions.java", - "", "interface MethodDeletions {", " class SoleMethod {", " void methodToBeDeleted() {}", @@ -141,7 +138,6 @@ void deleteWithTrailingWhitespaceMethods() { "}") .addOutputLines( "MethodDeletions.java", - "", "interface MethodDeletions {", " class SoleMethod {}", "", diff --git a/pom.xml b/pom.xml index 4777ae1dec..0cabf8d9ac 100644 --- a/pom.xml +++ b/pom.xml @@ -862,8 +862,8 @@ --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED - --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED + --add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED From 8580e89008887442f76b001ee203fd110cf78aca Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 16 Mar 2023 15:48:01 +0100 Subject: [PATCH 226/601] Upgrade Project Reactor 2022.0.4 -> 2022.0.5 (#533) See: - https://github.com/reactor/reactor/releases/tag/2022.0.5 - https://github.com/reactor/reactor/compare/2022.0.4...2022.0.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0cabf8d9ac..9c861f4ae3 100644 --- a/pom.xml +++ b/pom.xml @@ -287,7 +287,7 @@ io.projectreactor reactor-bom - 2022.0.4 + 2022.0.5 pom import From 62c1c277ae55cff8df4c8b809ed91f50c9a3e704 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 18 Mar 2023 14:23:16 +0100 Subject: [PATCH 227/601] Upgrade Checkstyle 10.8.1 -> 10.9.1 (#535) See: - https://checkstyle.sourceforge.io/releasenotes.html - https://github.com/checkstyle/checkstyle/releases/tag/checkstyle-10.9.0 - https://github.com/checkstyle/checkstyle/releases/tag/checkstyle-10.9.1 - https://github.com/checkstyle/checkstyle/compare/checkstyle-10.8.1...checkstyle-10.9.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9c861f4ae3..a3728406f9 100644 --- a/pom.xml +++ b/pom.xml @@ -783,7 +783,7 @@ com.puppycrawl.tools checkstyle - 10.8.1 + 10.9.1 io.spring.nohttp From 29c23542da9fd063713d0a99547a830ef17585f4 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 18 Mar 2023 15:10:16 +0100 Subject: [PATCH 228/601] Upgrade pitest-maven-plugin 1.11.4 -> 1.11.5 (#534) While there, fix `run-mutation-tests.sh` for compatibility with Surefire 3.0.0. See: - https://github.com/hcoles/pitest/releases/tag/1.11.5 - https://github.com/hcoles/pitest/compare/1.11.4...1.11.5 --- pom.xml | 2 +- run-mutation-tests.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a3728406f9..89191e3d73 100644 --- a/pom.xml +++ b/pom.xml @@ -1270,7 +1270,7 @@ org.pitest pitest-maven - 1.11.4 + 1.11.5 diff --git a/run-mutation-tests.sh b/run-mutation-tests.sh index 5e9bc2891d..270ab31836 100755 --- a/run-mutation-tests.sh +++ b/run-mutation-tests.sh @@ -16,6 +16,6 @@ targetTests=${1:-*} mvn clean test pitest:mutationCoverage \ -DargLine.xmx=2048m \ -Dverification.skip \ - -DfailIfNoTests=false \ + -Dsurefire.failIfNoSpecifiedTests=false \ -Dtest="${targetTests}" \ -DtargetTests="${targetTests}" From d30c99a28f685dab55834a60c532377a43fbfd1e Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 20 Mar 2023 13:48:41 +0100 Subject: [PATCH 229/601] Introduce `AssertThatPathContent{,Utf8}` Refaster rules (#530) --- .../BugPatternExtractorTest.java | 4 +-- .../refasterrules/AssertJStringRules.java | 31 +++++++++++++++++++ .../AssertJStringRulesTestInput.java | 18 +++++++++++ .../AssertJStringRulesTestOutput.java | 19 ++++++++++++ 4 files changed, 70 insertions(+), 2 deletions(-) diff --git a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternExtractorTest.java b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternExtractorTest.java index 1737f32ac4..da6467c78d 100644 --- a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternExtractorTest.java +++ b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternExtractorTest.java @@ -14,7 +14,6 @@ import com.google.errorprone.matchers.Description; import com.sun.source.tree.ClassTree; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -120,7 +119,8 @@ void bugPatternAnnotationIsAbsent() { private static void verifyFileMatchesResource( Path outputDirectory, String fileName, String resourceName) throws IOException { - assertThat(Files.readString(outputDirectory.resolve(fileName))) + assertThat(outputDirectory.resolve(fileName)) + .content(UTF_8) .isEqualToIgnoringWhitespace(getResource(resourceName)); } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJStringRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJStringRules.java index 0f3fee47ba..4143884ea6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJStringRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJStringRules.java @@ -1,11 +1,16 @@ package tech.picnic.errorprone.refasterrules; import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.refaster.annotation.UseImportPolicy; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractStringAssert; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; @@ -89,4 +94,30 @@ static final class AssertThatDoesNotMatch { return assertThat(string).doesNotMatch(regex); } } + + static final class AssertThatPathContent { + @BeforeTemplate + AbstractStringAssert before(Path path, Charset charset) throws IOException { + return assertThat(Files.readString(path, charset)); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractStringAssert after(Path path, Charset charset) { + return assertThat(path).content(charset); + } + } + + static final class AssertThatPathContentUtf8 { + @BeforeTemplate + AbstractStringAssert before(Path path) throws IOException { + return assertThat(Files.readString(path)); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractStringAssert after(Path path) { + return assertThat(path).content(UTF_8); + } + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestInput.java index 7efb588db8..3d6c1763b0 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestInput.java @@ -2,11 +2,21 @@ import static org.assertj.core.api.Assertions.assertThat; +import com.google.common.collect.ImmutableSet; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractStringAssert; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class AssertJStringRulesTest implements RefasterRuleCollectionTestCase { + @Override + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of(Files.class); + } + void testAbstractStringAssertStringIsEmpty() { assertThat("foo").isEqualTo(""); } @@ -30,4 +40,12 @@ AbstractStringAssert testAbstractStringAssertStringIsNotEmpty() { AbstractAssert testAssertThatDoesNotMatch() { return assertThat("foo".matches(".*")).isFalse(); } + + AbstractStringAssert testAssertThatPathContent() throws IOException { + return assertThat(Files.readString(Paths.get(""), Charset.defaultCharset())); + } + + AbstractStringAssert testAssertThatPathContentUtf8() throws IOException { + return assertThat(Files.readString(Paths.get(""))); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestOutput.java index f0d8293bd9..0804620bf5 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJStringRulesTestOutput.java @@ -1,12 +1,23 @@ package tech.picnic.errorprone.refasterrules; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; +import com.google.common.collect.ImmutableSet; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Paths; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractStringAssert; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class AssertJStringRulesTest implements RefasterRuleCollectionTestCase { + @Override + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of(Files.class); + } + void testAbstractStringAssertStringIsEmpty() { assertThat("foo").isEmpty(); } @@ -30,4 +41,12 @@ AbstractStringAssert testAbstractStringAssertStringIsNotEmpty() { AbstractAssert testAssertThatDoesNotMatch() { return assertThat("foo").doesNotMatch(".*"); } + + AbstractStringAssert testAssertThatPathContent() throws IOException { + return assertThat(Paths.get("")).content(Charset.defaultCharset()); + } + + AbstractStringAssert testAssertThatPathContentUtf8() throws IOException { + return assertThat(Paths.get("")).content(UTF_8); + } } From 80d0d858261a430cce658da83bfa36db16ebe02c Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 21 Mar 2023 11:44:37 +0100 Subject: [PATCH 230/601] Upgrade Checkstyle 10.9.1 -> 10.9.2 (#537) See: - https://checkstyle.sourceforge.io/releasenotes.html - https://github.com/checkstyle/checkstyle/releases/tag/checkstyle-10.9.2 - https://github.com/checkstyle/checkstyle/compare/checkstyle-10.9.1...checkstyle-10.9.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 89191e3d73..bd7e2deb21 100644 --- a/pom.xml +++ b/pom.xml @@ -783,7 +783,7 @@ com.puppycrawl.tools checkstyle - 10.9.1 + 10.9.2 io.spring.nohttp From 64b1c7eea46f081c7049286d3b44e8896a92a88d Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 21 Mar 2023 17:15:44 +0100 Subject: [PATCH 231/601] Upgrade swagger-annotations 2.2.8 -> 2.2.9 (#538) See: - https://github.com/swagger-api/swagger-core/releases/tag/v2.2.9 - https://github.com/swagger-api/swagger-core/compare/v2.2.8...v2.2.9 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bd7e2deb21..954f545a65 100644 --- a/pom.xml +++ b/pom.xml @@ -304,7 +304,7 @@ io.swagger.core.v3 swagger-annotations - 2.2.8 + 2.2.9 jakarta.servlet From 156df71616ed61a3577a8399223edf72b3816398 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 21 Mar 2023 17:28:18 +0100 Subject: [PATCH 232/601] Upgrade Spring 5.3.25 -> 5.3.26 (#539) See: - https://github.com/spring-projects/spring-framework/releases/tag/v5.3.26 - https://github.com/spring-projects/spring-framework/compare/v5.3.25...v5.3.26 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 954f545a65..d784483d83 100644 --- a/pom.xml +++ b/pom.xml @@ -395,7 +395,7 @@ org.springframework spring-framework-bom - 5.3.25 + 5.3.26 pom import From 04368e924399d8dcad969a13ed8a9d35bdc6e189 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 22 Mar 2023 18:52:40 +0100 Subject: [PATCH 233/601] Upgrade SLF4J API 2.0.6 -> 2.0.7 (#536) See: - https://www.slf4j.org/news.html - https://github.com/qos-ch/slf4j/compare/v_2.0.6...v_2.0.7 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d784483d83..c44dc6e379 100644 --- a/pom.xml +++ b/pom.xml @@ -390,7 +390,7 @@ org.slf4j slf4j-api - 2.0.6 + 2.0.7 org.springframework From 8f1d1df747571337bc9a1c3b2cd1154b1e61b05e Mon Sep 17 00:00:00 2001 From: Bastien Diederichs Date: Thu, 23 Mar 2023 09:01:18 +0100 Subject: [PATCH 234/601] Introduce `BugCheckerRules` Refaster rule collection (#526) --- error-prone-contrib/pom.xml | 2 +- .../refasterrules/BugCheckerRules.java | 53 +++++++++++++++++++ .../bugpatterns/FluxFlatMapUsageTest.java | 1 - .../bugpatterns/IdentityConversionTest.java | 1 - .../StringCaseLocaleUsageTest.java | 1 - .../refasterrules/RefasterRulesTest.java | 1 + .../BugCheckerRulesTestInput.java | 29 ++++++++++ .../BugCheckerRulesTestOutput.java | 27 ++++++++++ 8 files changed, 111 insertions(+), 4 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BugCheckerRules.java create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestInput.java create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestOutput.java diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index b16612d0e5..41f6b74e6d 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -37,7 +37,7 @@ ${groupId.error-prone} error_prone_test_helpers - test + provided ${project.groupId} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BugCheckerRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BugCheckerRules.java new file mode 100644 index 0000000000..a65dff6783 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BugCheckerRules.java @@ -0,0 +1,53 @@ +package tech.picnic.errorprone.refasterrules; + +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChooser; +import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; +import com.google.errorprone.refaster.Refaster; +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; +import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; + +/** Refaster rules related to {@link com.google.errorprone.bugpatterns.BugChecker} classes. */ +@OnlineDocumentation +final class BugCheckerRules { + private BugCheckerRules() {} + + /** + * Avoid calling {@link BugCheckerRefactoringTestHelper#setFixChooser(FixChooser)} or {@link + * BugCheckerRefactoringTestHelper#setImportOrder(String)} with their respective default values. + */ + static final class BugCheckerRefactoringTestHelperIdentity { + @BeforeTemplate + BugCheckerRefactoringTestHelper before(BugCheckerRefactoringTestHelper helper) { + return Refaster.anyOf( + helper.setFixChooser(FixChoosers.FIRST), helper.setImportOrder("static-first")); + } + + @AfterTemplate + BugCheckerRefactoringTestHelper after(BugCheckerRefactoringTestHelper helper) { + return helper; + } + } + + /** + * Prefer {@link BugCheckerRefactoringTestHelper.ExpectOutput#expectUnchanged()} over repeating + * the input. + */ + // XXX: This rule assumes that the full source code is specified as a single string, e.g. using a + // text block. Support for multi-line source code input would require a `BugChecker` + // implementation instead. + static final class BugCheckerRefactoringTestHelperAddInputLinesExpectUnchanged { + @BeforeTemplate + BugCheckerRefactoringTestHelper before( + BugCheckerRefactoringTestHelper helper, String path, String source) { + return helper.addInputLines(path, source).addOutputLines(path, source); + } + + @AfterTemplate + BugCheckerRefactoringTestHelper after( + BugCheckerRefactoringTestHelper helper, String path, String source) { + return helper.addInputLines(path, source).expectUnchanged(); + } + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsageTest.java index 410993f614..bce223a2b4 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsageTest.java @@ -67,7 +67,6 @@ void identification() { @Test void replacementFirstSuggestedFix() { BugCheckerRefactoringTestHelper.newInstance(FluxFlatMapUsage.class, getClass()) - .setFixChooser(FixChoosers.FIRST) .addInputLines( "A.java", "import reactor.core.publisher.Flux;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java index 9341c76433..631acdad68 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/IdentityConversionTest.java @@ -180,7 +180,6 @@ void identification() { @Test void replacementFirstSuggestedFix() { BugCheckerRefactoringTestHelper.newInstance(IdentityConversion.class, getClass()) - .setFixChooser(FixChoosers.FIRST) .addInputLines( "A.java", "import static com.google.errorprone.matchers.Matchers.staticMethod;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java index b1865d6089..a3d087aef4 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringCaseLocaleUsageTest.java @@ -48,7 +48,6 @@ void identification() { @Test void replacementFirstSuggestedFix() { BugCheckerRefactoringTestHelper.newInstance(StringCaseLocaleUsage.class, getClass()) - .setFixChooser(FixChoosers.FIRST) .addInputLines( "A.java", "class A {", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java index c60bb8b286..d1b461536c 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java @@ -35,6 +35,7 @@ final class RefasterRulesTest { AssertJThrowingCallableRules.class, AssortedRules.class, BigDecimalRules.class, + BugCheckerRules.class, CollectionRules.class, ComparatorRules.class, DoubleStreamRules.class, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestInput.java new file mode 100644 index 0000000000..49eaa57945 --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestInput.java @@ -0,0 +1,29 @@ +package tech.picnic.errorprone.refasterrules; + +import com.google.common.collect.ImmutableSet; +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; +import com.google.errorprone.bugpatterns.BugChecker; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; + +final class BugCheckerRulesTest implements RefasterRuleCollectionTestCase { + @Override + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of(FixChoosers.class); + } + + ImmutableSet testBugCheckerRefactoringTestHelperIdentity() { + return ImmutableSet.of( + BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()) + .setFixChooser(FixChoosers.FIRST), + BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()) + .setImportOrder("static-first")); + } + + BugCheckerRefactoringTestHelper + testBugCheckerRefactoringTestHelperAddInputLinesExpectUnchanged() { + return BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()) + .addInputLines("A.java", "class A {}") + .addOutputLines("A.java", "class A {}"); + } +} diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestOutput.java new file mode 100644 index 0000000000..39aef89159 --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestOutput.java @@ -0,0 +1,27 @@ +package tech.picnic.errorprone.refasterrules; + +import com.google.common.collect.ImmutableSet; +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; +import com.google.errorprone.bugpatterns.BugChecker; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; + +final class BugCheckerRulesTest implements RefasterRuleCollectionTestCase { + @Override + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of(FixChoosers.class); + } + + ImmutableSet testBugCheckerRefactoringTestHelperIdentity() { + return ImmutableSet.of( + BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()), + BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass())); + } + + BugCheckerRefactoringTestHelper + testBugCheckerRefactoringTestHelperAddInputLinesExpectUnchanged() { + return BugCheckerRefactoringTestHelper.newInstance(BugChecker.class, getClass()) + .addInputLines("A.java", "class A {}") + .expectUnchanged(); + } +} From ae89a37934af3123cea2bc6fab9f3f5bbd3d0e2e Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 23 Mar 2023 09:22:22 +0100 Subject: [PATCH 235/601] Upgrade swagger-annotations 1.6.9 -> 1.6.10 (#542) See: - https://github.com/swagger-api/swagger-core/releases/tag/v1.6.10 - https://github.com/swagger-api/swagger-core/compare/v1.6.9...v1.6.10 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c44dc6e379..f9724ff467 100644 --- a/pom.xml +++ b/pom.xml @@ -299,7 +299,7 @@ io.swagger swagger-annotations - 1.6.9 + 1.6.10 io.swagger.core.v3 From 978c90db9da604b73c4b64410fc8c8023f28156c Mon Sep 17 00:00:00 2001 From: Guillaume Toison <86775455+gtoison@users.noreply.github.com> Date: Sat, 25 Mar 2023 18:48:00 +0000 Subject: [PATCH 236/601] Extend set of parameter types recognized by `RequestMappingAnnotation` (#543) Additional types recognized: - `jakarta.servlet.http.HttpServletRequest` - `jakarta.servlet.http.HttpServletResponse` - `org.springframework.ui.Model` - `org.springframework.validation.BindingResult` --- .../errorprone/bugpatterns/RequestMappingAnnotation.java | 4 ++++ .../bugpatterns/RequestMappingAnnotationTest.java | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java index df0dbe330e..f626075aef 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java @@ -74,9 +74,13 @@ public final class RequestMappingAnnotation extends BugChecker implements Method isSameType("java.time.ZoneId"), isSameType("java.util.Locale"), isSameType("java.util.TimeZone"), + isSameType("jakarta.servlet.http.HttpServletRequest"), + isSameType("jakarta.servlet.http.HttpServletResponse"), isSameType("javax.servlet.http.HttpServletRequest"), isSameType("javax.servlet.http.HttpServletResponse"), isSameType("org.springframework.http.HttpMethod"), + isSameType("org.springframework.ui.Model"), + isSameType("org.springframework.validation.BindingResult"), isSameType("org.springframework.web.context.request.NativeWebRequest"), isSameType("org.springframework.web.context.request.WebRequest"), isSameType("org.springframework.web.server.ServerWebExchange"), diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java index 947e06e677..4943e76d1d 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotationTest.java @@ -16,6 +16,8 @@ void identification() { "import javax.servlet.http.HttpServletRequest;", "import javax.servlet.http.HttpServletResponse;", "import org.springframework.http.HttpMethod;", + "import org.springframework.ui.Model;", + "import org.springframework.validation.BindingResult;", "import org.springframework.web.bind.annotation.DeleteMapping;", "import org.springframework.web.bind.annotation.GetMapping;", "import org.springframework.web.bind.annotation.PatchMapping;", @@ -82,6 +84,12 @@ void identification() { " A properHttpMethod(HttpMethod method);", "", " @RequestMapping", + " A properModel(Model model);", + "", + " @RequestMapping", + " A properBindingResult(BindingResult result);", + "", + " @RequestMapping", " A properNativeWebRequest(NativeWebRequest request);", "", " @RequestMapping", From f784c64150bf339d5e88e41394a9713815827c47 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 25 Mar 2023 19:57:48 +0100 Subject: [PATCH 237/601] Upgrade pitest-maven-plugin 1.11.5 -> 1.11.6 (#544) See: - https://github.com/hcoles/pitest/releases/tag/1.11.6 - https://github.com/hcoles/pitest/compare/1.11.5...1.11.6 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f9724ff467..ae814aa661 100644 --- a/pom.xml +++ b/pom.xml @@ -1270,7 +1270,7 @@ org.pitest pitest-maven - 1.11.5 + 1.11.6 From d5c45e003fd0a0f2e565d4a5979fb0d96cb72951 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 26 Mar 2023 19:22:16 +0200 Subject: [PATCH 238/601] Upgrade modernizer-maven-plugin 2.5.0 -> 2.6.0 (#550) See: - https://github.com/gaul/modernizer-maven-plugin/releases/tag/modernizer-maven-plugin-2.6.0 - https://github.com/gaul/modernizer-maven-plugin/compare/modernizer-maven-plugin-2.5.0...modernizer-maven-plugin-2.6.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ae814aa661..f39d7785e1 100644 --- a/pom.xml +++ b/pom.xml @@ -1234,7 +1234,7 @@ org.gaul modernizer-maven-plugin - 2.5.0 + 2.6.0 From aef9c5da7a5c2876f3e725932317f97cfdd58bb3 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 28 Mar 2023 08:09:28 +0200 Subject: [PATCH 248/601] Upgrade Forbidden APIs plugin 3.4 -> 3.5 (#553) See: - https://github.com/policeman-tools/forbidden-apis/wiki/Changes - https://github.com/policeman-tools/forbidden-apis/compare/3.4...3.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7f4cfafe69..4722621743 100644 --- a/pom.xml +++ b/pom.xml @@ -467,7 +467,7 @@ de.thetaphi forbiddenapis - 3.4 + 3.5 jdk-internal From 5fb4aed3ad1e94afd9a50997ebb775139eb1d5f0 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 30 Mar 2023 09:34:58 +0200 Subject: [PATCH 249/601] Upgrade extra-enforcer-rules 1.6.1 -> 1.6.2 (#554) See: - https://github.com/mojohaus/extra-enforcer-rules/releases/tag/1.6.2 - https://github.com/mojohaus/extra-enforcer-rules/compare/extra-enforcer-rules-1.6.1...1.6.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4722621743..b7a6ab102d 100644 --- a/pom.xml +++ b/pom.xml @@ -973,7 +973,7 @@ org.codehaus.mojo extra-enforcer-rules - 1.6.1 + 1.6.2 From 8a0abf59572bc79c1bdf478611bc27e85bc56959 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 30 Mar 2023 20:39:49 +0200 Subject: [PATCH 250/601] Upgrade Byte Buddy 1.14.2 -> 1.14.3 (#555) See: - https://github.com/raphw/byte-buddy/releases/tag/byte-buddy-1.14.3 - https://github.com/raphw/byte-buddy/compare/byte-buddy-1.14.2...byte-buddy-1.14.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b7a6ab102d..e3155f379b 100644 --- a/pom.xml +++ b/pom.xml @@ -331,7 +331,7 @@ net.bytebuddy byte-buddy - 1.14.2 + 1.14.3 - ${git.commit.time} + 2023-03-31T07:29:10Z UTF-8 - 2023-03-31T07:29:10Z + 2023-03-31T07:31:01Z UTF-8 From 68d0bed36c7d536aacde410d96802fb6cef2da64 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 7 Apr 2023 08:43:11 +0200 Subject: [PATCH 261/601] Upgrade Byte Buddy 1.14.3 -> 1.14.4 (#569) See: - https://github.com/raphw/byte-buddy/releases/tag/byte-buddy-1.14.4 - https://github.com/raphw/byte-buddy/compare/byte-buddy-1.14.3...byte-buddy-1.14.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 909a00f1c8..44e8ba8d93 100644 --- a/pom.xml +++ b/pom.xml @@ -331,7 +331,7 @@ net.bytebuddy byte-buddy - 1.14.3 + 1.14.4 From 9ddd91a50ecb80d15712ee3562fd4f775621c658 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sat, 15 Apr 2023 19:23:25 +0200 Subject: [PATCH 273/601] Introduce CodeQL security vulnerability analysis (#573) See https://codeql.github.com --- .github/workflows/codeql.yml | 44 ++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000000..f6bcd764dd --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,44 @@ +# Analyzes the code using GitHub's default CodeQL query database. +# Identified issues are registered with GitHub's code scanning dashboard. When +# a pull request is analyzed, any offending lines are annotated. See +# https://codeql.github.com for details. +name: CodeQL analysis +on: + pull_request: + push: + branches: [ master ] + schedule: + - cron: '0 4 * * 1' +permissions: + contents: read +jobs: + analyze: + strategy: + matrix: + language: [ java, ruby ] + permissions: + contents: read + security-events: write + runs-on: ubuntu-22.04 + steps: + - name: Check out code + uses: actions/checkout@v3.1.0 + with: + persist-credentials: false + - name: Set up JDK + uses: actions/setup-java@v3.8.0 + with: + java-version: 17.0.6 + distribution: temurin + cache: maven + - name: Initialize CodeQL + uses: github/codeql-action/init@v2.2.11 + with: + languages: ${{ matrix.language }} + - name: Perform minimal build + if: matrix.language == 'java' + run: mvn -T1C clean install -DskipTests -Dverification.skip + - name: Perform CodeQL analysis + uses: github/codeql-action/analyze@v2.2.11 + with: + category: /language:${{ matrix.language }} From 929f1dd1c7989f5a1d6a26336f09c079b1b97369 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sun, 16 Apr 2023 09:56:14 +0200 Subject: [PATCH 274/601] Introduce OpenSSF Scorecard GitHub action (#574) And resolve some of the issues it identified. See https://securityscorecards.dev --- .github/workflows/build.yaml | 12 +++++---- .github/workflows/deploy-website.yaml | 6 +++-- .github/workflows/openssf-scorecard.yml | 36 +++++++++++++++++++++++++ .github/workflows/pitest-analyze-pr.yml | 1 + .github/workflows/pitest-update-pr.yml | 10 ++++--- 5 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/openssf-scorecard.yml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5eab31a497..457fc2b73c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -29,13 +29,15 @@ jobs: runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.experimental }} steps: - # We run the build twice for each supported JDK: once against the - # original Error Prone release, using only Error Prone checks available - # on Maven Central, and once against the Picnic Error Prone fork, - # additionally enabling all checks defined in this project and any - # Error Prone checks available only from other artifact repositories. + # We run the build twice for each supported JDK: once against the + # original Error Prone release, using only Error Prone checks available + # on Maven Central, and once against the Picnic Error Prone fork, + # additionally enabling all checks defined in this project and any Error + # Prone checks available only from other artifact repositories. - name: Check out code uses: actions/checkout@v3.1.0 + with: + persist-credentials: false - name: Set up JDK uses: actions/setup-java@v3.8.0 with: diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index 2f2e7ad54a..a17d1a0bdd 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -3,16 +3,18 @@ on: pull_request: push: branches: [ master, website ] +permissions: + contents: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} jobs: build: - permissions: - contents: read runs-on: ubuntu-22.04 steps: - name: Check out code uses: actions/checkout@v3.1.0 + with: + persist-credentials: false - uses: ruby/setup-ruby@v1.126.0 with: working-directory: ./website diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml new file mode 100644 index 0000000000..202e8c170d --- /dev/null +++ b/.github/workflows/openssf-scorecard.yml @@ -0,0 +1,36 @@ +# Analyzes the code base and GitHub project configuration for adherence to +# security best practices for open source software. Identified issues are +# registered with GitHub's code scanning dashboard. When a pull request is +# analyzed, any offending lines are annotated. See +# https://securityscorecards.dev for details. +name: OpenSSF Scorecard update +on: + pull_request: + push: + branches: [ master ] + schedule: + - cron: '0 4 * * 1' +permissions: + contents: read +jobs: + analyze: + permissions: + contents: read + security-events: write + id-token: write + runs-on: ubuntu-22.04 + steps: + - name: Check out code + uses: actions/checkout@v3.1.0 + with: + persist-credentials: false + - name: Run OpenSSF Scorecard analysis + uses: ossf/scorecard-action@v2.1.3 + with: + results_file: results.sarif + results_format: sarif + publish_results: ${{ github.ref == 'refs/heads/master' }} + - name: Update GitHub's code scanning dashboard + uses: github/codeql-action/upload-sarif@v2.2.11 + with: + sarif_file: results.sarif diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index db23d0b958..918022529a 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -15,6 +15,7 @@ jobs: uses: actions/checkout@v3.1.0 with: fetch-depth: 2 + persist-credentials: false - name: Set up JDK uses: actions/setup-java@v3.8.0 with: diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index 1e3283b27a..913b781c10 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -9,16 +9,20 @@ on: - completed permissions: actions: read - checks: write - contents: read - pull-requests: write jobs: update-pr: if: ${{ github.event.workflow_run.conclusion == 'success' }} + permissions: + actions: read + checks: write + contents: read + pull-requests: write runs-on: ubuntu-22.04 steps: - name: Check out code uses: actions/checkout@v3.1.0 + with: + persist-credentials: false - name: Set up JDK uses: actions/setup-java@v3.8.0 with: From ebd64c107710756619cfb16acf02325cc93c299c Mon Sep 17 00:00:00 2001 From: Mohamed Sameh <110535847+mohamedsamehsalah@users.noreply.github.com> Date: Tue, 18 Apr 2023 08:09:17 +0200 Subject: [PATCH 275/601] Introduce `AssertThatMapContainsOnlyKeys` Refaster rule (#576) --- .../refasterrules/AssertJMapRules.java | 16 ++++++++++++++++ .../refasterrules/AssertJMapRulesTestInput.java | 4 ++++ .../refasterrules/AssertJMapRulesTestOutput.java | 4 ++++ 3 files changed, 24 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJMapRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJMapRules.java index 4f3d782a7f..f206791760 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJMapRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJMapRules.java @@ -16,15 +16,18 @@ import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; +import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AbstractBooleanAssert; +import org.assertj.core.api.AbstractCollectionAssert; import org.assertj.core.api.AbstractMapAssert; import org.assertj.core.api.MapAssert; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; @@ -220,6 +223,19 @@ MapAssert after(Map map, K key) { } } + static final class AssertThatMapContainsOnlyKeys { + @BeforeTemplate + AbstractCollectionAssert, K, ?> before(Map map, Set keys) { + return assertThat(map.keySet()).hasSameElementsAs(keys); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + MapAssert after(Map map, Set keys) { + return assertThat(map).containsOnlyKeys(keys); + } + } + static final class AssertThatMapContainsValue { @BeforeTemplate AbstractBooleanAssert before(Map map, V value) { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestInput.java index 82436281ab..66ebdc0ef1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestInput.java @@ -130,6 +130,10 @@ MapAssert testAbstractMapAssertHasSameSizeAs() { return assertThat(ImmutableMap.of(1, 2).containsKey(3)).isFalse(); } + AbstractAssert testAssertThatMapContainsOnlyKeys() { + return assertThat(ImmutableMap.of(1, 2).keySet()).hasSameElementsAs(ImmutableSet.of(3)); + } + AbstractAssert testAssertThatMapContainsValue() { return assertThat(ImmutableMap.of(1, 2).containsValue(3)).isTrue(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestOutput.java index e6087c8267..413d8fbec1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJMapRulesTestOutput.java @@ -130,6 +130,10 @@ MapAssert testAbstractMapAssertHasSameSizeAs() { return assertThat(ImmutableMap.of(1, 2)).doesNotContainKey(3); } + AbstractAssert testAssertThatMapContainsOnlyKeys() { + return assertThat(ImmutableMap.of(1, 2)).containsOnlyKeys(ImmutableSet.of(3)); + } + AbstractAssert testAssertThatMapContainsValue() { return assertThat(ImmutableMap.of(1, 2)).containsValue(3); } From 3af81d8b10ee2a4fb83c05b386194bf5092077d8 Mon Sep 17 00:00:00 2001 From: Mohamed Sameh <110535847+mohamedsamehsalah@users.noreply.github.com> Date: Tue, 18 Apr 2023 09:04:03 +0200 Subject: [PATCH 276/601] Introduce `StringIs{,Not}EmptyPredicate` Refaster rules (#577) --- .../errorprone/refasterrules/StringRules.java | 42 +++++++++++++++++-- .../refasterrules/StringRulesTestInput.java | 8 ++++ .../refasterrules/StringRulesTestOutput.java | 20 ++++++--- 3 files changed, 62 insertions(+), 8 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java index 4b403a02fb..c45c0550f5 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java @@ -1,6 +1,8 @@ package tech.picnic.errorprone.refasterrules; +import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.function.Predicate.not; import static java.util.stream.Collectors.joining; import com.google.common.base.Joiner; @@ -11,21 +13,23 @@ import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.AlsoNegation; import com.google.errorprone.refaster.annotation.BeforeTemplate; +import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Arrays; import java.util.Collection; import java.util.Objects; import java.util.Optional; import java.util.function.Function; +import java.util.function.Predicate; import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; /** Refaster rules related to expressions dealing with {@link String}s. */ -// XXX: Should we prefer `s -> !s.isEmpty()` or `not(String::isEmpty)`? @OnlineDocumentation final class StringRules { private StringRules() {} /** Prefer {@link String#isEmpty()} over alternatives that consult the string's length. */ + // XXX: Once we target JDK 15+, generalize this rule to cover all `CharSequence` subtypes. static final class StringIsEmpty { @BeforeTemplate boolean before(String str) { @@ -39,6 +43,37 @@ boolean after(String str) { } } + /** Prefer a method reference to {@link String#isEmpty()} over the equivalent lambda function. */ + // XXX: Once we target JDK 15+, generalize this rule to cover all `CharSequence` subtypes. + // XXX: As it stands, this rule is a special case of what `MethodReferenceUsage` tries to achieve. + // If/when `MethodReferenceUsage` becomes production ready, we should simply drop this check. + static final class StringIsEmptyPredicate { + @BeforeTemplate + Predicate before() { + return s -> s.isEmpty(); + } + + @AfterTemplate + Predicate after() { + return String::isEmpty; + } + } + + /** Prefer a method reference to {@link String#isEmpty()} over the equivalent lambda function. */ + // XXX: Once we target JDK 15+, generalize this rule to cover all `CharSequence` subtypes. + static final class StringIsNotEmptyPredicate { + @BeforeTemplate + Predicate before() { + return s -> !s.isEmpty(); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + Predicate after() { + return not(String::isEmpty); + } + } + /** Prefer {@link Strings#isNullOrEmpty(String)} over the more verbose alternative. */ static final class StringIsNullOrEmpty { @BeforeTemplate @@ -65,7 +100,7 @@ Optional before(String str) { @AfterTemplate Optional after(String str) { - return Optional.ofNullable(str).filter(s -> !s.isEmpty()); + return Optional.ofNullable(str).filter(not(String::isEmpty)); } } @@ -76,8 +111,9 @@ Optional before(Optional optional) { } @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) Optional after(Optional optional) { - return optional.filter(s -> !s.isEmpty()); + return optional.filter(not(String::isEmpty)); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestInput.java index f70407c02b..420411b245 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestInput.java @@ -33,6 +33,14 @@ ImmutableSet testStringIsEmpty() { "baz".length() >= 1); } + boolean testStringIsEmptyPredicate() { + return Stream.of("foo").anyMatch(s -> s.isEmpty()); + } + + boolean testStringIsNotEmptyPredicate() { + return Stream.of("foo").anyMatch(s -> !s.isEmpty()); + } + ImmutableSet testStringIsNullOrEmpty() { return ImmutableSet.of( getClass().getName() == null || getClass().getName().isEmpty(), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestOutput.java index 723cfe3ce3..f637936691 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestOutput.java @@ -1,6 +1,7 @@ package tech.picnic.errorprone.refasterrules; import static java.nio.charset.StandardCharsets.UTF_8; +import static java.util.function.Predicate.not; import static java.util.stream.Collectors.joining; import com.google.common.base.Joiner; @@ -14,6 +15,7 @@ import java.util.Objects; import java.util.Optional; import java.util.function.Function; +import java.util.function.Predicate; import java.util.stream.Stream; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; @@ -34,6 +36,14 @@ ImmutableSet testStringIsEmpty() { !"baz".isEmpty()); } + boolean testStringIsEmptyPredicate() { + return Stream.of("foo").anyMatch(String::isEmpty); + } + + boolean testStringIsNotEmptyPredicate() { + return Stream.of("foo").anyMatch(not(String::isEmpty)); + } + ImmutableSet testStringIsNullOrEmpty() { return ImmutableSet.of( Strings.isNullOrEmpty(getClass().getName()), !Strings.isNullOrEmpty(getClass().getName())); @@ -41,14 +51,14 @@ ImmutableSet testStringIsNullOrEmpty() { ImmutableSet> testOptionalNonEmptyString() { return ImmutableSet.of( - Optional.ofNullable(toString()).filter(s -> !s.isEmpty()), - Optional.ofNullable(toString()).filter(s -> !s.isEmpty()), - Optional.ofNullable(toString()).filter(s -> !s.isEmpty()), - Optional.ofNullable(toString()).filter(s -> !s.isEmpty())); + Optional.ofNullable(toString()).filter(Predicate.not(String::isEmpty)), + Optional.ofNullable(toString()).filter(Predicate.not(String::isEmpty)), + Optional.ofNullable(toString()).filter(Predicate.not(String::isEmpty)), + Optional.ofNullable(toString()).filter(Predicate.not(String::isEmpty))); } Optional testFilterEmptyString() { - return Optional.of("foo").filter(s -> !s.isEmpty()); + return Optional.of("foo").filter(not(String::isEmpty)); } ImmutableSet testJoinStrings() { From ee0884e65fd5b3a5ce3e0b21a9f25a1db5dfe939 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 19 Apr 2023 08:55:14 +0200 Subject: [PATCH 277/601] Introduce `AssociativeMethodInvocation` check (#560) --- .../AssociativeMethodInvocation.java | 96 +++++++++++++++ .../AssociativeMethodInvocationTest.java | 110 ++++++++++++++++++ 2 files changed, 206 insertions(+) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/AssociativeMethodInvocation.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AssociativeMethodInvocationTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/AssociativeMethodInvocation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/AssociativeMethodInvocation.java new file mode 100644 index 0000000000..40259d7d15 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/AssociativeMethodInvocation.java @@ -0,0 +1,96 @@ +package tech.picnic.errorprone.bugpatterns; + +import static com.google.errorprone.BugPattern.LinkType.CUSTOM; +import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; +import static com.google.errorprone.BugPattern.StandardTags.SIMPLIFICATION; +import static com.google.errorprone.matchers.Matchers.allOf; +import static com.google.errorprone.matchers.Matchers.not; +import static com.google.errorprone.matchers.Matchers.staticMethod; +import static com.google.errorprone.matchers.Matchers.toType; +import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; + +import com.google.auto.service.AutoService; +import com.google.common.collect.ImmutableSet; +import com.google.errorprone.BugPattern; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; +import com.google.errorprone.fixes.SuggestedFix; +import com.google.errorprone.fixes.SuggestedFixes; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.matchers.Matchers; +import com.google.errorprone.refaster.Refaster; +import com.google.errorprone.suppliers.Supplier; +import com.google.errorprone.suppliers.Suppliers; +import com.google.errorprone.util.ASTHelpers; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.MethodInvocationTree; +import com.sun.tools.javac.code.Type; +import tech.picnic.errorprone.bugpatterns.util.SourceCode; + +/** + * A {@link BugChecker} that flags unnecessarily nested usage of methods that implement an + * associative operation. + * + *

The arguments to such methods can be flattened without affecting semantics, while making the + * code more readable. + */ +@AutoService(BugChecker.class) +@BugPattern( + summary = + "These methods implement an associative operation, so the list of operands can be flattened", + link = BUG_PATTERNS_BASE_URL + "AssociativeMethodInvocation", + linkType = CUSTOM, + severity = SUGGESTION, + tags = SIMPLIFICATION) +public final class AssociativeMethodInvocation extends BugChecker + implements MethodInvocationTreeMatcher { + private static final long serialVersionUID = 1L; + private static final Supplier ITERABLE = Suppliers.typeFromClass(Iterable.class); + private static final ImmutableSet> ASSOCIATIVE_OPERATIONS = + ImmutableSet.of( + allOf( + staticMethod().onClass(Suppliers.typeFromClass(Matchers.class)).named("allOf"), + toType(MethodInvocationTree.class, not(hasArgumentOfType(ITERABLE)))), + allOf( + staticMethod().onClass(Suppliers.typeFromClass(Matchers.class)).named("anyOf"), + toType(MethodInvocationTree.class, not(hasArgumentOfType(ITERABLE)))), + staticMethod().onClass(Suppliers.typeFromClass(Refaster.class)).named("anyOf")); + + /** Instantiates a new {@link AssociativeMethodInvocation} instance. */ + public AssociativeMethodInvocation() {} + + @Override + public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { + if (tree.getArguments().isEmpty()) { + /* Absent any arguments, there is nothing to simplify. */ + return Description.NO_MATCH; + } + + for (Matcher matcher : ASSOCIATIVE_OPERATIONS) { + if (matcher.matches(tree, state)) { + SuggestedFix.Builder fix = SuggestedFix.builder(); + for (ExpressionTree arg : tree.getArguments()) { + if (matcher.matches(arg, state)) { + MethodInvocationTree invocation = (MethodInvocationTree) arg; + fix.merge( + invocation.getArguments().isEmpty() + ? SuggestedFixes.removeElement(arg, tree.getArguments(), state) + : SourceCode.unwrapMethodInvocation(invocation, state)); + } + } + + return fix.isEmpty() ? Description.NO_MATCH : describeMatch(tree, fix.build()); + } + } + + return Description.NO_MATCH; + } + + private static Matcher hasArgumentOfType(Supplier type) { + return (tree, state) -> + tree.getArguments().stream() + .anyMatch(arg -> ASTHelpers.isSubtype(ASTHelpers.getType(arg), type.get(state), state)); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AssociativeMethodInvocationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AssociativeMethodInvocationTest.java new file mode 100644 index 0000000000..789fb14ec6 --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AssociativeMethodInvocationTest.java @@ -0,0 +1,110 @@ +package tech.picnic.errorprone.bugpatterns; + +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; +import com.google.errorprone.CompilationTestHelper; +import org.junit.jupiter.api.Test; + +final class AssociativeMethodInvocationTest { + @Test + void identification() { + CompilationTestHelper.newInstance(AssociativeMethodInvocation.class, getClass()) + .addSourceLines( + "A.java", + "import com.google.common.collect.ImmutableList;", + "import com.google.errorprone.matchers.Matchers;", + "import com.google.errorprone.refaster.Refaster;", + "", + "class A {", + " void m() {", + " Matchers.allOf();", + " Matchers.anyOf();", + " Refaster.anyOf();", + "", + " Matchers.allOf((t, s) -> true);", + " Matchers.anyOf((t, s) -> true);", + " Refaster.anyOf(0);", + "", + " Matchers.allOf(Matchers.anyOf((t, s) -> true));", + " Matchers.anyOf(Matchers.allOf((t, s) -> true));", + " Refaster.anyOf(Matchers.allOf((t, s) -> true));", + "", + " // BUG: Diagnostic contains:", + " Matchers.allOf(Matchers.allOf((t, s) -> true));", + " // BUG: Diagnostic contains:", + " Matchers.anyOf(Matchers.anyOf((t, s) -> true));", + " // BUG: Diagnostic contains:", + " Refaster.anyOf(Refaster.anyOf(0));", + "", + " Matchers.allOf(Matchers.allOf(ImmutableList.of((t, s) -> true)));", + " Matchers.anyOf(Matchers.anyOf(ImmutableList.of((t, s) -> true)));", + "", + " // BUG: Diagnostic contains:", + " Matchers.allOf(", + " (t, s) -> true, Matchers.allOf((t, s) -> false, (t, s) -> true), (t, s) -> false);", + " // BUG: Diagnostic contains:", + " Matchers.anyOf(", + " (t, s) -> true, Matchers.anyOf((t, s) -> false, (t, s) -> true), (t, s) -> false);", + " // BUG: Diagnostic contains:", + " Refaster.anyOf(0, Refaster.anyOf(1, 2), 3);", + " }", + "}") + .doTest(); + } + + @Test + void replacement() { + BugCheckerRefactoringTestHelper.newInstance(AssociativeMethodInvocation.class, getClass()) + .addInputLines( + "A.java", + "import com.google.errorprone.matchers.Matchers;", + "import com.google.errorprone.refaster.Refaster;", + "", + "class A {", + " void m() {", + " Matchers.allOf(Matchers.allOf());", + " Matchers.anyOf(Matchers.anyOf());", + " Refaster.anyOf(Refaster.anyOf());", + "", + " Matchers.allOf(Matchers.allOf((t, s) -> true));", + " Matchers.anyOf(Matchers.anyOf((t, s) -> true));", + " Refaster.anyOf(Refaster.anyOf(0));", + "", + " Matchers.allOf(", + " Matchers.anyOf(),", + " Matchers.allOf((t, s) -> false, (t, s) -> true),", + " Matchers.allOf(),", + " Matchers.anyOf((t, s) -> false));", + " Matchers.anyOf(", + " Matchers.allOf(),", + " Matchers.anyOf((t, s) -> false, (t, s) -> true),", + " Matchers.anyOf(),", + " Matchers.allOf((t, s) -> false));", + " Refaster.anyOf(Matchers.allOf(), Refaster.anyOf(1, 2), Matchers.anyOf());", + " }", + "}") + .addOutputLines( + "A.java", + "import com.google.errorprone.matchers.Matchers;", + "import com.google.errorprone.refaster.Refaster;", + "", + "class A {", + " void m() {", + " Matchers.allOf();", + " Matchers.anyOf();", + " Refaster.anyOf();", + "", + " Matchers.allOf((t, s) -> true);", + " Matchers.anyOf((t, s) -> true);", + " Refaster.anyOf(0);", + "", + " Matchers.allOf(", + " Matchers.anyOf(), (t, s) -> false, (t, s) -> true, Matchers.anyOf((t, s) -> false));", + " Matchers.anyOf(", + " Matchers.allOf(), (t, s) -> false, (t, s) -> true, Matchers.allOf((t, s) -> false));", + " Refaster.anyOf(Matchers.allOf(), 1, 2, Matchers.anyOf());", + " }", + "}") + .doTest(TestMode.TEXT_MATCH); + } +} From 53daabe5df66dcc75f52baad8ab03d6acde92ad7 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 21 Apr 2023 08:21:49 +0200 Subject: [PATCH 278/601] Upgrade maven-checkstyle-plugin 3.2.1 -> 3.2.2 (#587) See: - https://issues.apache.org/jira/issues/?jql=project%20%3D%20MCHECKSTYLE%20AND%20fixVersion%20%3E%203.2.1%20AND%20fixVersion%20%3C%3D%203.2.2 - https://github.com/apache/maven-checkstyle-plugin/compare/maven-checkstyle-plugin-3.2.1...maven-checkstyle-plugin-3.2.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index abebea26ae..2f623ff1e7 100644 --- a/pom.xml +++ b/pom.xml @@ -533,7 +533,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.2.1 + 3.2.2 2023-03-31T07:31:01Z UTF-8 + + **/tech/picnic/errorprone/refasterrules/*.java + + ${refaster-rules.path-pattern} + https://sonarcloud.io + + java-resource,refaster-rules-1,refaster-rules-2,refaster-rules-3,refaster-rules-4,refaster-rules-5,refaster-rules-6 + **/src/test/resources/**/*.java + java:* + + ${refaster-rules.path-pattern} + java:S1452 + + ${refaster-rules.path-pattern} + java:S1610 + + ${refaster-rules.path-pattern} + java:S1612 + + ${refaster-rules.path-pattern} + java:S2166 + + ${refaster-rules.path-pattern} + java:S3959 + + ${refaster-rules.path-pattern} + java:S5960 + picnic-technologies + + pom.xml,src/main + src/test @@ -1267,6 +1318,13 @@ org.jacoco jacoco-maven-plugin 0.8.9 + + + + ${refaster-rules.path-pattern} + + org.pitest diff --git a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/CodeTransformers.java b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/CodeTransformers.java index cda3004c0e..7830b3c100 100644 --- a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/CodeTransformers.java +++ b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/CodeTransformers.java @@ -72,11 +72,16 @@ private static Optional getRefasterRuleName(ResourceInfo resource) { } int lastPathSeparator = resourceName.lastIndexOf('/'); - int beginIndex = lastPathSeparator < 0 ? 0 : lastPathSeparator + 1; + int beginIndex = lastPathSeparator < 0 ? 0 : (lastPathSeparator + 1); int endIndex = resourceName.length() - REFASTER_RULE_SUFFIX.length(); return Optional.of(resourceName.substring(beginIndex, endIndex)); } + @SuppressWarnings({ + "java:S1166" /* The caught exception's stack traces are not relevant. */, + "java:S2147" /* The `catch` clauses have distinct comments. */, + "key-to-resolve-AnnotationUseStyle-and-TrailingComment-check-conflict" + }) private static Optional loadCodeTransformer(ResourceInfo resource) { try (InputStream in = resource.url().openStream(); ObjectInputStream ois = new ObjectInputStream(in)) { @@ -84,7 +89,13 @@ private static Optional loadCodeTransformer(ResourceInfo resour CodeTransformer codeTransformer = (CodeTransformer) ois.readObject(); return Optional.of(codeTransformer); } catch (NoSuchElementException e) { - /* For some reason we can't load the resource. Skip it. */ + /* + * For some reason we can't load the resource; skip it. This issue has been observed when + * executing the code using Maven Surefire, in which case `ResourceInfo` may reference a path + * relative to the current working directory, even though the current working directory is not + */ + // XXX: This appears to be a bug in Guava's ClassPath implementation. Consider migrating to + // ClassGraph. // XXX: Should we log this? return Optional.empty(); } catch (ClassCastException e) { diff --git a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java index 4cfbeb727c..4973060243 100644 --- a/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java +++ b/refaster-runner/src/main/java/tech/picnic/errorprone/refaster/runner/Refaster.java @@ -55,13 +55,14 @@ linkType = NONE, severity = SUGGESTION, tags = SIMPLIFICATION) +@SuppressWarnings("java:S2160" /* Super class equality definition suffices. */) public final class Refaster extends BugChecker implements CompilationUnitTreeMatcher { /** Flag to pass a pattern that restricts which Refaster rules are loaded. */ public static final String INCLUDED_RULES_PATTERN_FLAG = "Refaster:NamePattern"; private static final long serialVersionUID = 1L; - @SuppressWarnings("serial" /* Concrete instance will be `Serializable`. */) + @SuppressWarnings({"java:S1948", "serial"} /* Concrete instance will be `Serializable`. */) private final CodeTransformer codeTransformer; /** Instantiates a default {@link Refaster} instance. */ @@ -123,7 +124,10 @@ private void applyMatches( for (Description description : byReplacementSize) { ImmutableRangeSet ranges = getReplacementRanges(description, endPositions); if (ranges.asRanges().stream().noneMatch(replacedSections::intersects)) { - /* This suggested fix does not overlap with any ("larger") replacement seen until now. Apply it. */ + /* + * This suggested fix does not overlap with any ("larger") replacement seen until now, so + * apply it. + */ state.reportMatch(augmentDescription(description, getSeverityOverride(state))); replacedSections.addAll(ranges); } diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java index 11db1cd771..2fa0f54876 100644 --- a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java @@ -161,23 +161,22 @@ private static Stream severityAssignmentTestCases() { @ParameterizedTest void severityAssignment( ImmutableList arguments, ImmutableList expectedSeverities) { - assertThatThrownBy( - () -> - compilationHelper - .setArgs(arguments) - .addSourceLines( - "A.java", - "class A {", - " void m() {", - " boolean[] bs = {", - " \"foo\".toCharArray().length == 0,", - " \"bar\".toCharArray().length == 1,", - " \"baz\".toCharArray().length == 2,", - " \"qux\".toCharArray().length == 3", - " };", - " }", - "}") - .doTest()) + CompilationTestHelper compilationTestHelper = + compilationHelper + .setArgs(arguments) + .addSourceLines( + "A.java", + "class A {", + " void m() {", + " boolean[] bs = {", + " \"foo\".toCharArray().length == 0,", + " \"bar\".toCharArray().length == 1,", + " \"baz\".toCharArray().length == 2,", + " \"qux\".toCharArray().length == 3", + " };", + " }", + "}"); + assertThatThrownBy(compilationTestHelper::doTest) .isInstanceOf(AssertionError.class) .message() .satisfies( diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java index ee2dccbf62..6f865b1b71 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java @@ -49,6 +49,7 @@ public abstract class AnnotatedCompositeCodeTransformer implements CodeTransform abstract ImmutableList transformers(); @Override + @SuppressWarnings("java:S3038" /* All AutoValue properties must be specified explicitly. */) public abstract ImmutableClassToInstanceMap annotations(); /** @@ -92,16 +93,17 @@ private Description augmentDescription( } private String getShortCheckName(String fullCheckName) { - if (packageName().isEmpty()) { + String packageName = packageName(); + if (packageName.isEmpty()) { return fullCheckName; } - String prefix = packageName() + '.'; + String prefix = packageName + '.'; checkState( fullCheckName.startsWith(prefix), "Refaster rule class '%s' is not located in package '%s'", fullCheckName, - packageName()); + packageName); return fullCheckName.substring(prefix.length()); } diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/ThrowsCheckedException.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/ThrowsCheckedException.java index 71989ea1e0..15d743e696 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/ThrowsCheckedException.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/ThrowsCheckedException.java @@ -16,6 +16,7 @@ * A matcher of functional interface expressions for which execution of the functional interface * method may throw a checked exception. */ +@SuppressWarnings("java:S2166" /* This type's name is suitable for a `Matcher`. */) public final class ThrowsCheckedException implements Matcher { private static final long serialVersionUID = 1L; @@ -48,7 +49,9 @@ private static Collection getThrownTypes(ExpressionTree tree, VisitorState try { return state.getTypes().findDescriptorType(type).getThrownTypes(); - } catch (FunctionDescriptorLookupError e) { + } catch ( + @SuppressWarnings("java:S1166" /* Not exceptional. */) + FunctionDescriptorLookupError e) { return ImmutableSet.of(); } } diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java index 588077a10e..8fd5803bc4 100644 --- a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java @@ -62,6 +62,7 @@ // `@BeforeTemplate` method is covered by a test. Review how we can make sure that _all_ // `@BeforeTemplate` methods and `Refaster.anyOf` branches are covered. @BugPattern(summary = "Exercises a Refaster rule collection", severity = ERROR) +@SuppressWarnings("java:S2160" /* Super class equality definition suffices. */) public final class RefasterRuleCollection extends BugChecker implements CompilationUnitTreeMatcher { private static final long serialVersionUID = 1L; private static final String RULE_COLLECTION_FLAG = "RefasterRuleCollection:RuleCollection"; @@ -159,13 +160,14 @@ private void reportIncorrectClassName(CompilationUnitTree tree, VisitorState sta SuggestedFix.prefixWith( typeDeclaration, String.format( - "/* ERROR: Class should be named `%s`. */\n", expectedClassName)))); + "/* ERROR: Class should be named `%s`. */%n", expectedClassName)))); } } else { state.reportMatch( describeMatch( typeDeclaration, - SuggestedFix.prefixWith(typeDeclaration, "/* ERROR: Unexpected token. */\n"))); + SuggestedFix.prefixWith( + typeDeclaration, String.format("/* ERROR: Unexpected token. */%n")))); } } } @@ -216,13 +218,13 @@ private void reportUnexpectedMatches( private void reportViolations( Tree tree, String message, ImmutableSet violations, VisitorState state) { - String violationEnumeration = String.join("\n* - ", violations); + String violationEnumeration = String.join(String.format("%n* - "), violations); String comment = - String.format("/*\n* ERROR: %s:\n* - %s\n*/\n", message, violationEnumeration); + String.format("/*%n* ERROR: %s:%n* - %s%n*/%n", message, violationEnumeration); SuggestedFix fixWithComment = tree instanceof MethodTree ? SuggestedFix.prefixWith(tree, comment) - : SuggestedFix.postfixWith(tree, '\n' + comment); + : SuggestedFix.postfixWith(tree, String.format("%n%s", comment)); state.reportMatch(describeMatch(tree, fixWithComment)); } @@ -295,7 +297,7 @@ private Optional getRuleUnderTest(MethodTree tree, VisitorState state) { describeMatch( tree, SuggestedFix.prefixWith( - tree, "/* ERROR: Method names should start with `test`. */\n"))); + tree, String.format("/* ERROR: Method names should start with `test`. */%n")))); } return Optional.empty(); diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollectionTestCase.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollectionTestCase.java index 37c3c0c594..4923b9c53e 100644 --- a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollectionTestCase.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollectionTestCase.java @@ -19,7 +19,7 @@ public interface RefasterRuleCollectionTestCase { * *Input.java} import statements are also required to be present in the associated {@code * *Output.java} file. */ - default ImmutableSet elidedTypesAndStaticImports() { + default ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(); } } diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixRulesTestInput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixRulesTestInput.java index 466d8f8984..fb1bf0ceeb 100644 --- a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixRulesTestInput.java +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixRulesTestInput.java @@ -5,7 +5,7 @@ /** Code to test the Refaster rules from {@link MethodWithoutPrefixRules}. */ final class MethodWithoutPrefixRulesTest implements RefasterRuleCollectionTestCase { @Override - public ImmutableSet elidedTypesAndStaticImports() { + public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(); } diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixRulesTestOutput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixRulesTestOutput.java index 74d509e4e8..ccdded90fe 100644 --- a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixRulesTestOutput.java +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/MethodWithoutPrefixRulesTestOutput.java @@ -5,7 +5,7 @@ /** Code to test the Refaster rules from {@link MethodWithoutPrefixRules}. */ final class MethodWithoutPrefixRulesTest implements RefasterRuleCollectionTestCase { @Override - public ImmutableSet elidedTypesAndStaticImports() { + public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(); } diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidRulesTestInput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidRulesTestInput.java index 8752bc0fcd..cf6d842c8f 100644 --- a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidRulesTestInput.java +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidRulesTestInput.java @@ -8,7 +8,7 @@ /** Code to test the Refaster rules from {@link ValidRules}. */ final class ValidRulesTest implements RefasterRuleCollectionTestCase { @Override - public ImmutableSet elidedTypesAndStaticImports() { + public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Strings.class); } diff --git a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidRulesTestOutput.java b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidRulesTestOutput.java index 1822797c3e..45b31289f5 100644 --- a/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidRulesTestOutput.java +++ b/refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/ValidRulesTestOutput.java @@ -10,7 +10,7 @@ /** Code to test the Refaster rules from {@link ValidRules}. */ final class ValidRulesTest implements RefasterRuleCollectionTestCase { @Override - public ImmutableSet elidedTypesAndStaticImports() { + public ImmutableSet elidedTypesAndStaticImports() { return ImmutableSet.of(Strings.class); } From 2f2e7e7a357a6ff398d86425f94cef6cbcaa794b Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Tue, 25 Apr 2023 08:54:31 +0200 Subject: [PATCH 285/601] Add additional quality badges to README (#584) --- README.md | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 312ea2ce0b..bc9aebff40 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,18 @@ code_][picnic-blog-ep-post]. [![Maven Central][maven-central-badge]][maven-central-search] [![Reproducible Builds][reproducible-builds-badge]][reproducible-builds-report] +[![OpenSSF Best Practices][openssf-best-practices-badge]][openssf-best-practices-checklist] +[![OpenSSF Scorecard][openssf-scorecard-badge]][openssf-scorecard-report] +[![CodeQL Analysis][codeql-badge]][codeql-master] [![GitHub Actions][github-actions-build-badge]][github-actions-build-master] +[![Mutation tested with PIT][pitest-badge]][pitest] +[![Quality Gate Status][sonarcloud-quality-badge]][sonarcloud-quality-master] +[![Maintainability Rating][sonarcloud-maintainability-badge]][sonarcloud-maintainability-master] +[![Reliability Rating][sonarcloud-reliability-badge]][sonarcloud-reliability-master] +[![Security Rating][sonarcloud-security-badge]][sonarcloud-security-master] +[![Coverage][sonarcloud-coverage-badge]][sonarcloud-coverage-master] +[![Duplicated Lines (%)][sonarcloud-duplication-badge]][sonarcloud-duplication-master] +[![Technical Debt][sonarcloud-technical-debt-badge]][sonarcloud-technical-debt-master] [![License][license-badge]][license] [![PRs Welcome][pr-badge]][contributing] @@ -243,11 +254,13 @@ guidelines][contributing]. ### Security -If you want to report a security vulnerablity, please do so through a private +If you want to report a security vulnerability, please do so through a private channel; please see our [security policy][security] for details. [bug-checks]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ [bug-checks-identity-conversion]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java +[codeql-badge]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/codeql.yml/badge.svg?branch=master&event=push +[codeql-master]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/codeql.yml?query=branch:master+event:push [contributing]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/CONTRIBUTING.md [contributing-pull-request]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/CONTRIBUTING.md#-opening-a-pull-request [error-prone-bugchecker]: https://github.com/google/error-prone/blob/master/check_api/src/main/java/com/google/errorprone/bugpatterns/BugChecker.java @@ -258,7 +271,7 @@ channel; please see our [security policy][security] for details. [error-prone-orig-repo]: https://github.com/google/error-prone [error-prone-pull-3301]: https://github.com/google/error-prone/pull/3301 [github-actions-build-badge]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/build.yaml/badge.svg -[github-actions-build-master]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/build.yaml?query=branch%3Amaster +[github-actions-build-master]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/build.yaml?query=branch:master&event=push [google-java-format]: https://github.com/google/google-java-format [idea-288052]: https://youtrack.jetbrains.com/issue/IDEA-288052 [license-badge]: https://img.shields.io/github/license/PicnicSupermarket/error-prone-support @@ -266,8 +279,13 @@ channel; please see our [security policy][security] for details. [maven-central-badge]: https://img.shields.io/maven-central/v/tech.picnic.error-prone-support/error-prone-support?color=blue [maven-central-search]: https://search.maven.org/artifact/tech.picnic.error-prone-support/error-prone-support [maven]: https://maven.apache.org +[openssf-best-practices-badge]: https://bestpractices.coreinfrastructure.org/projects/7199/badge +[openssf-best-practices-checklist]: https://bestpractices.coreinfrastructure.org/projects/7199 +[openssf-scorecard-badge]: https://img.shields.io/ossf-scorecard/github.com/PicnicSupermarket/error-prone-support?label=openssf%20scorecard +[openssf-scorecard-report]: https://api.securityscorecards.dev/projects/github.com/PicnicSupermarket/error-prone-support [picnic-blog-ep-post]: https://blog.picnic.nl/picnic-loves-error-prone-producing-high-quality-and-consistent-java-code-b8a566be6886 [picnic-blog]: https://blog.picnic.nl +[pitest-badge]: https://img.shields.io/badge/-Mutation%20tested%20with%20PIT-blue.svg [pitest]: https://pitest.org [pitest-maven]: https://pitest.org/quickstart/maven [pr-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg @@ -280,3 +298,17 @@ channel; please see our [security policy][security] for details. [script-run-full-build]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/run-full-build.sh [script-run-mutation-tests]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/run-mutation-tests.sh [security]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/SECURITY.md +[sonarcloud-coverage-badge]: https://sonarcloud.io/api/project_badges/measure?project=PicnicSupermarket_error-prone-support&metric=coverage +[sonarcloud-coverage-master]: https://sonarcloud.io/component_measures?id=PicnicSupermarket_error-prone-support&metric=coverage +[sonarcloud-duplication-badge]: https://sonarcloud.io/api/project_badges/measure?project=PicnicSupermarket_error-prone-support&metric=duplicated_lines_density +[sonarcloud-duplication-master]: https://sonarcloud.io/component_measures?id=PicnicSupermarket_error-prone-support&metric=duplicated_lines_density +[sonarcloud-maintainability-badge]: https://sonarcloud.io/api/project_badges/measure?project=PicnicSupermarket_error-prone-support&metric=sqale_rating +[sonarcloud-maintainability-master]: https://sonarcloud.io/component_measures?id=PicnicSupermarket_error-prone-support&metric=sqale_rating +[sonarcloud-quality-badge]: https://sonarcloud.io/api/project_badges/measure?project=PicnicSupermarket_error-prone-support&metric=alert_status +[sonarcloud-quality-master]: https://sonarcloud.io/summary/new_code?id=PicnicSupermarket_error-prone-support +[sonarcloud-reliability-badge]: https://sonarcloud.io/api/project_badges/measure?project=PicnicSupermarket_error-prone-support&metric=reliability_rating +[sonarcloud-reliability-master]: https://sonarcloud.io/component_measures?id=PicnicSupermarket_error-prone-support&metric=reliability_rating +[sonarcloud-security-badge]: https://sonarcloud.io/api/project_badges/measure?project=PicnicSupermarket_error-prone-support&metric=security_rating +[sonarcloud-security-master]: https://sonarcloud.io/component_measures?id=PicnicSupermarket_error-prone-support&metric=security_rating +[sonarcloud-technical-debt-badge]: https://sonarcloud.io/api/project_badges/measure?project=PicnicSupermarket_error-prone-support&metric=sqale_index +[sonarcloud-technical-debt-master]: https://sonarcloud.io/component_measures?id=PicnicSupermarket_error-prone-support&metric=sqale_index From 4dd2aa12cc040af6809842030115d8e6f0c86a2b Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 25 Apr 2023 09:52:52 +0200 Subject: [PATCH 286/601] Upgrade Jackson 2.14.2 -> 2.15.0 (#594) See: - https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.15 - https://github.com/FasterXML/jackson-bom/compare/jackson-bom-2.14.2...jackson-bom-2.15.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5523482ef0..242ce05108 100644 --- a/pom.xml +++ b/pom.xml @@ -268,7 +268,7 @@ com.fasterxml.jackson jackson-bom - 2.14.2 + 2.15.0 pom import From c807568b9cc46c635f2d84a9f2f420fdf8cf136a Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 26 Apr 2023 07:59:38 +0200 Subject: [PATCH 287/601] Upgrade pitest-maven-plugin 1.12.0 -> 1.13.0 (#591) See: - https://github.com/hcoles/pitest/releases/tag/1.13.0 - https://github.com/hcoles/pitest/compare/1.12.0...1.13.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 242ce05108..375e85dc5d 100644 --- a/pom.xml +++ b/pom.xml @@ -1329,7 +1329,7 @@ org.pitest pitest-maven - 1.12.0 + 1.13.0 From 32d50ab6fe324b3eca5900ffa48bd1d989831c33 Mon Sep 17 00:00:00 2001 From: Mohamed Sameh <110535847+mohamedsamehsalah@users.noreply.github.com> Date: Wed, 26 Apr 2023 09:07:50 +0200 Subject: [PATCH 288/601] Extend `StreamRules` Refaster rule collection (#593) All changes suggested by SonarCloud's java:S4266 rule are now covered. See https://sonarcloud.io/organizations/picnic-technologies/rules?open=java%3AS4266&rule_key=java%3AS4266 Fixes #578. --- .../errorprone/refasterrules/StreamRules.java | 177 +++++++++++++++++- .../refasterrules/StreamRulesTestInput.java | 98 ++++++++-- .../refasterrules/StreamRulesTestOutput.java | 98 ++++++++-- 3 files changed, 344 insertions(+), 29 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java index fb922ca499..c1b1180bcc 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java @@ -4,7 +4,20 @@ import static java.util.Comparator.naturalOrder; import static java.util.Comparator.reverseOrder; import static java.util.function.Predicate.not; +import static java.util.stream.Collectors.counting; +import static java.util.stream.Collectors.filtering; +import static java.util.stream.Collectors.flatMapping; import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.mapping; +import static java.util.stream.Collectors.maxBy; +import static java.util.stream.Collectors.minBy; +import static java.util.stream.Collectors.reducing; +import static java.util.stream.Collectors.summarizingDouble; +import static java.util.stream.Collectors.summarizingInt; +import static java.util.stream.Collectors.summarizingLong; +import static java.util.stream.Collectors.summingDouble; +import static java.util.stream.Collectors.summingInt; +import static java.util.stream.Collectors.summingLong; import com.google.common.collect.Streams; import com.google.errorprone.refaster.Refaster; @@ -16,8 +29,12 @@ import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Arrays; import java.util.Comparator; +import java.util.DoubleSummaryStatistics; +import java.util.IntSummaryStatistics; +import java.util.LongSummaryStatistics; import java.util.Objects; import java.util.Optional; +import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.function.Predicate; import java.util.function.ToDoubleFunction; @@ -263,9 +280,12 @@ boolean after(Stream stream) { static final class StreamMin { @BeforeTemplate + @SuppressWarnings("java:S4266" /* This violation will be rewritten. */) Optional before(Stream stream, Comparator comparator) { return Refaster.anyOf( - stream.max(comparator.reversed()), stream.sorted(comparator).findFirst()); + stream.max(comparator.reversed()), + stream.sorted(comparator).findFirst(), + stream.collect(minBy(comparator))); } @AfterTemplate @@ -289,9 +309,12 @@ Optional after(Stream stream) { static final class StreamMax { @BeforeTemplate + @SuppressWarnings("java:S4266" /* This violation will be rewritten. */) Optional before(Stream stream, Comparator comparator) { return Refaster.anyOf( - stream.min(comparator.reversed()), Streams.findLast(stream.sorted(comparator))); + stream.min(comparator.reversed()), + Streams.findLast(stream.sorted(comparator)), + stream.collect(maxBy(comparator))); } @AfterTemplate @@ -389,7 +412,13 @@ boolean after(Stream stream) { static final class StreamMapToIntSum { @BeforeTemplate - int before( + @SuppressWarnings("java:S4266" /* This violation will be rewritten. */) + long before(Stream stream, ToIntFunction mapper) { + return stream.collect(summingInt(mapper)); + } + + @BeforeTemplate + int before2( Stream stream, @Matches(IsLambdaExpressionOrMethodReference.class) Function mapper) { return stream.map(mapper).reduce(0, Integer::sum); @@ -403,7 +432,13 @@ int after(Stream stream, ToIntFunction mapper) { static final class StreamMapToDoubleSum { @BeforeTemplate - double before( + @SuppressWarnings("java:S4266" /* This violation will be rewritten. */) + double before(Stream stream, ToDoubleFunction mapper) { + return stream.collect(summingDouble(mapper)); + } + + @BeforeTemplate + double before2( Stream stream, @Matches(IsLambdaExpressionOrMethodReference.class) Function mapper) { return stream.map(mapper).reduce(0.0, Double::sum); @@ -417,7 +452,13 @@ static final class StreamMapToDoubleSum { static final class StreamMapToLongSum { @BeforeTemplate - long before( + @SuppressWarnings("java:S4266" /* This violation will be rewritten. */) + long before(Stream stream, ToLongFunction mapper) { + return stream.collect(summingLong(mapper)); + } + + @BeforeTemplate + long before2( Stream stream, @Matches(IsLambdaExpressionOrMethodReference.class) Function mapper) { return stream.map(mapper).reduce(0L, Long::sum); @@ -428,4 +469,130 @@ long after(Stream stream, ToLongFunction mapper) { return stream.mapToLong(mapper).sum(); } } + + static final class StreamMapToIntSummaryStatistics { + @BeforeTemplate + IntSummaryStatistics before(Stream stream, ToIntFunction mapper) { + return stream.collect(summarizingInt(mapper)); + } + + @AfterTemplate + IntSummaryStatistics after(Stream stream, ToIntFunction mapper) { + return stream.mapToInt(mapper).summaryStatistics(); + } + } + + static final class StreamMapToDoubleSummaryStatistics { + @BeforeTemplate + DoubleSummaryStatistics before(Stream stream, ToDoubleFunction mapper) { + return stream.collect(summarizingDouble(mapper)); + } + + @AfterTemplate + DoubleSummaryStatistics after(Stream stream, ToDoubleFunction mapper) { + return stream.mapToDouble(mapper).summaryStatistics(); + } + } + + static final class StreamMapToLongSummaryStatistics { + @BeforeTemplate + LongSummaryStatistics before(Stream stream, ToLongFunction mapper) { + return stream.collect(summarizingLong(mapper)); + } + + @AfterTemplate + LongSummaryStatistics after(Stream stream, ToLongFunction mapper) { + return stream.mapToLong(mapper).summaryStatistics(); + } + } + + static final class StreamCount { + @BeforeTemplate + @SuppressWarnings("java:S4266" /* This violation will be rewritten. */) + long before(Stream stream) { + return stream.collect(counting()); + } + + @AfterTemplate + long after(Stream stream) { + return stream.count(); + } + } + + static final class StreamReduce { + @BeforeTemplate + @SuppressWarnings("java:S4266" /* This violation will be rewritten. */) + Optional before(Stream stream, BinaryOperator accumulator) { + return stream.collect(reducing(accumulator)); + } + + @AfterTemplate + Optional after(Stream stream, BinaryOperator accumulator) { + return stream.reduce(accumulator); + } + } + + static final class StreamReduceWithIdentity { + @BeforeTemplate + @SuppressWarnings("java:S4266" /* This violation will be rewritten. */) + T before(Stream stream, T identity, BinaryOperator accumulator) { + return stream.collect(reducing(identity, accumulator)); + } + + @AfterTemplate + T after(Stream stream, T identity, BinaryOperator accumulator) { + return stream.reduce(identity, accumulator); + } + } + + static final class StreamFilterCollect { + @BeforeTemplate + R before( + Stream stream, Predicate predicate, Collector collector) { + return stream.collect(filtering(predicate, collector)); + } + + @AfterTemplate + R after( + Stream stream, Predicate predicate, Collector collector) { + return stream.filter(predicate).collect(collector); + } + } + + static final class StreamMapCollect { + @BeforeTemplate + @SuppressWarnings("java:S4266" /* This violation will be rewritten. */) + R before( + Stream stream, + Function mapper, + Collector collector) { + return stream.collect(mapping(mapper, collector)); + } + + @AfterTemplate + R after( + Stream stream, + Function mapper, + Collector collector) { + return stream.map(mapper).collect(collector); + } + } + + static final class StreamFlatMapCollect { + @BeforeTemplate + R before( + Stream stream, + Function> mapper, + Collector collector) { + return stream.collect(flatMapping(mapper, collector)); + } + + @AfterTemplate + R after( + Stream stream, + Function> mapper, + Collector collector) { + return stream.flatMap(mapper).collect(collector); + } + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java index 1ef30d1e3d..c568e49507 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java @@ -1,12 +1,29 @@ package tech.picnic.errorprone.refasterrules; +import static com.google.common.collect.ImmutableSet.toImmutableSet; import static java.util.Comparator.comparingInt; import static java.util.Comparator.reverseOrder; import static java.util.function.Predicate.not; +import static java.util.stream.Collectors.counting; +import static java.util.stream.Collectors.filtering; +import static java.util.stream.Collectors.flatMapping; import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.mapping; +import static java.util.stream.Collectors.maxBy; +import static java.util.stream.Collectors.minBy; +import static java.util.stream.Collectors.reducing; +import static java.util.stream.Collectors.summarizingDouble; +import static java.util.stream.Collectors.summarizingInt; +import static java.util.stream.Collectors.summarizingLong; +import static java.util.stream.Collectors.summingDouble; +import static java.util.stream.Collectors.summingInt; +import static java.util.stream.Collectors.summingLong; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; +import java.util.DoubleSummaryStatistics; +import java.util.IntSummaryStatistics; +import java.util.LongSummaryStatistics; import java.util.Objects; import java.util.Optional; import java.util.function.Function; @@ -17,7 +34,23 @@ final class StreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(Objects.class, Streams.class, not(null)); + return ImmutableSet.of( + Objects.class, + Streams.class, + counting(), + filtering(null, null), + flatMapping(null, null), + mapping(null, null), + maxBy(null), + minBy(null), + not(null), + reducing(null), + summarizingDouble(null), + summarizingInt(null), + summarizingLong(null), + summingDouble(null), + summingInt(null), + summingLong(null)); } String testJoining() { @@ -90,7 +123,8 @@ ImmutableSet testStreamIsNotEmpty() { ImmutableSet> testStreamMin() { return ImmutableSet.of( Stream.of("foo").max(comparingInt(String::length).reversed()), - Stream.of("bar").sorted(comparingInt(String::length)).findFirst()); + Stream.of("bar").sorted(comparingInt(String::length)).findFirst(), + Stream.of("baz").collect(minBy(comparingInt(String::length)))); } ImmutableSet> testStreamMinNaturalOrder() { @@ -101,7 +135,8 @@ ImmutableSet> testStreamMinNaturalOrder() { ImmutableSet> testStreamMax() { return ImmutableSet.of( Stream.of("foo").min(comparingInt(String::length).reversed()), - Streams.findLast(Stream.of("bar").sorted(comparingInt(String::length)))); + Streams.findLast(Stream.of("bar").sorted(comparingInt(String::length))), + Stream.of("baz").collect(maxBy(comparingInt(String::length)))); } ImmutableSet> testStreamMaxNaturalOrder() { @@ -143,24 +178,63 @@ boolean testStreamAllMatch2() { ImmutableSet testStreamMapToIntSum() { Function parseIntFunction = Integer::parseInt; return ImmutableSet.of( - Stream.of(1).map(i -> i * 2).reduce(0, Integer::sum), - Stream.of("2").map(Integer::parseInt).reduce(0, Integer::sum), - Stream.of("3").map(parseIntFunction).reduce(0, Integer::sum)); + Stream.of("1").collect(summingInt(Integer::parseInt)), + Stream.of(2).map(i -> i * 2).reduce(0, Integer::sum), + Stream.of("3").map(Integer::parseInt).reduce(0, Integer::sum), + Stream.of("4").map(parseIntFunction).reduce(0, Integer::sum)); } ImmutableSet testStreamMapToDoubleSum() { Function parseDoubleFunction = Double::parseDouble; return ImmutableSet.of( - Stream.of(1).map(i -> i * 2.0).reduce(0.0, Double::sum), - Stream.of("2").map(Double::parseDouble).reduce(0.0, Double::sum), - Stream.of("3").map(parseDoubleFunction).reduce(0.0, Double::sum)); + Stream.of("1").collect(summingDouble(Double::parseDouble)), + Stream.of(2).map(i -> i * 2.0).reduce(0.0, Double::sum), + Stream.of("3").map(Double::parseDouble).reduce(0.0, Double::sum), + Stream.of("4").map(parseDoubleFunction).reduce(0.0, Double::sum)); } ImmutableSet testStreamMapToLongSum() { Function parseLongFunction = Long::parseLong; return ImmutableSet.of( - Stream.of(1).map(i -> i * 2L).reduce(0L, Long::sum), - Stream.of("2").map(Long::parseLong).reduce(0L, Long::sum), - Stream.of("3").map(parseLongFunction).reduce(0L, Long::sum)); + Stream.of("1").collect(summingLong(Long::parseLong)), + Stream.of(2).map(i -> i * 2L).reduce(0L, Long::sum), + Stream.of("3").map(Long::parseLong).reduce(0L, Long::sum), + Stream.of("4").map(parseLongFunction).reduce(0L, Long::sum)); + } + + IntSummaryStatistics testStreamMapToIntSummaryStatistics() { + return Stream.of("1").collect(summarizingInt(Integer::parseInt)); + } + + DoubleSummaryStatistics testStreamMapToDoubleSummaryStatistics() { + return Stream.of("1").collect(summarizingDouble(Double::parseDouble)); + } + + LongSummaryStatistics testStreamMapToLongSummaryStatistics() { + return Stream.of("1").collect(summarizingLong(Long::parseLong)); + } + + Long testStreamCount() { + return Stream.of(1).collect(counting()); + } + + Optional testStreamReduce() { + return Stream.of(1).collect(reducing(Integer::sum)); + } + + Integer testStreamReduceWithIdentity() { + return Stream.of(1).collect(reducing(0, Integer::sum)); + } + + ImmutableSet testStreamFilterCollect() { + return Stream.of("1").collect(filtering(String::isEmpty, toImmutableSet())); + } + + ImmutableSet testStreamMapCollect() { + return Stream.of("1").collect(mapping(Integer::parseInt, toImmutableSet())); + } + + ImmutableSet testStreamFlatMapCollect() { + return Stream.of(1).collect(flatMapping(n -> Stream.of(n, n), toImmutableSet())); } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java index 549df57117..fb7484f6b5 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java @@ -1,14 +1,31 @@ package tech.picnic.errorprone.refasterrules; +import static com.google.common.collect.ImmutableSet.toImmutableSet; import static java.util.Comparator.comparingInt; import static java.util.Comparator.naturalOrder; import static java.util.Comparator.reverseOrder; import static java.util.function.Predicate.not; +import static java.util.stream.Collectors.counting; +import static java.util.stream.Collectors.filtering; +import static java.util.stream.Collectors.flatMapping; import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.mapping; +import static java.util.stream.Collectors.maxBy; +import static java.util.stream.Collectors.minBy; +import static java.util.stream.Collectors.reducing; +import static java.util.stream.Collectors.summarizingDouble; +import static java.util.stream.Collectors.summarizingInt; +import static java.util.stream.Collectors.summarizingLong; +import static java.util.stream.Collectors.summingDouble; +import static java.util.stream.Collectors.summingInt; +import static java.util.stream.Collectors.summingLong; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Streams; import java.util.Arrays; +import java.util.DoubleSummaryStatistics; +import java.util.IntSummaryStatistics; +import java.util.LongSummaryStatistics; import java.util.Objects; import java.util.Optional; import java.util.function.Function; @@ -19,7 +36,23 @@ final class StreamRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(Objects.class, Streams.class, not(null)); + return ImmutableSet.of( + Objects.class, + Streams.class, + counting(), + filtering(null, null), + flatMapping(null, null), + mapping(null, null), + maxBy(null), + minBy(null), + not(null), + reducing(null), + summarizingDouble(null), + summarizingInt(null), + summarizingLong(null), + summingDouble(null), + summingInt(null), + summingLong(null)); } String testJoining() { @@ -91,7 +124,8 @@ ImmutableSet testStreamIsNotEmpty() { ImmutableSet> testStreamMin() { return ImmutableSet.of( Stream.of("foo").min(comparingInt(String::length)), - Stream.of("bar").min(comparingInt(String::length))); + Stream.of("bar").min(comparingInt(String::length)), + Stream.of("baz").min(comparingInt(String::length))); } ImmutableSet> testStreamMinNaturalOrder() { @@ -102,7 +136,8 @@ ImmutableSet> testStreamMinNaturalOrder() { ImmutableSet> testStreamMax() { return ImmutableSet.of( Stream.of("foo").max(comparingInt(String::length)), - Stream.of("bar").max(comparingInt(String::length))); + Stream.of("bar").max(comparingInt(String::length)), + Stream.of("baz").max(comparingInt(String::length))); } ImmutableSet> testStreamMaxNaturalOrder() { @@ -142,24 +177,63 @@ boolean testStreamAllMatch2() { ImmutableSet testStreamMapToIntSum() { Function parseIntFunction = Integer::parseInt; return ImmutableSet.of( - Stream.of(1).mapToInt(i -> i * 2).sum(), - Stream.of("2").mapToInt(Integer::parseInt).sum(), - Stream.of("3").map(parseIntFunction).reduce(0, Integer::sum)); + Stream.of("1").mapToInt(Integer::parseInt).sum(), + Stream.of(2).mapToInt(i -> i * 2).sum(), + Stream.of("3").mapToInt(Integer::parseInt).sum(), + Stream.of("4").map(parseIntFunction).reduce(0, Integer::sum)); } ImmutableSet testStreamMapToDoubleSum() { Function parseDoubleFunction = Double::parseDouble; return ImmutableSet.of( - Stream.of(1).mapToDouble(i -> i * 2.0).sum(), - Stream.of("2").mapToDouble(Double::parseDouble).sum(), - Stream.of("3").map(parseDoubleFunction).reduce(0.0, Double::sum)); + Stream.of("1").mapToDouble(Double::parseDouble).sum(), + Stream.of(2).mapToDouble(i -> i * 2.0).sum(), + Stream.of("3").mapToDouble(Double::parseDouble).sum(), + Stream.of("4").map(parseDoubleFunction).reduce(0.0, Double::sum)); } ImmutableSet testStreamMapToLongSum() { Function parseLongFunction = Long::parseLong; return ImmutableSet.of( - Stream.of(1).mapToLong(i -> i * 2L).sum(), - Stream.of("2").mapToLong(Long::parseLong).sum(), - Stream.of("3").map(parseLongFunction).reduce(0L, Long::sum)); + Stream.of("1").mapToLong(Long::parseLong).sum(), + Stream.of(2).mapToLong(i -> i * 2L).sum(), + Stream.of("3").mapToLong(Long::parseLong).sum(), + Stream.of("4").map(parseLongFunction).reduce(0L, Long::sum)); + } + + IntSummaryStatistics testStreamMapToIntSummaryStatistics() { + return Stream.of("1").mapToInt(Integer::parseInt).summaryStatistics(); + } + + DoubleSummaryStatistics testStreamMapToDoubleSummaryStatistics() { + return Stream.of("1").mapToDouble(Double::parseDouble).summaryStatistics(); + } + + LongSummaryStatistics testStreamMapToLongSummaryStatistics() { + return Stream.of("1").mapToLong(Long::parseLong).summaryStatistics(); + } + + Long testStreamCount() { + return Stream.of(1).count(); + } + + Optional testStreamReduce() { + return Stream.of(1).reduce(Integer::sum); + } + + Integer testStreamReduceWithIdentity() { + return Stream.of(1).reduce(0, Integer::sum); + } + + ImmutableSet testStreamFilterCollect() { + return Stream.of("1").filter(String::isEmpty).collect(toImmutableSet()); + } + + ImmutableSet testStreamMapCollect() { + return Stream.of("1").map(Integer::parseInt).collect(toImmutableSet()); + } + + ImmutableSet testStreamFlatMapCollect() { + return Stream.of(1).flatMap(n -> Stream.of(n, n)).collect(toImmutableSet()); } } From 393aebca9f37a59fd045f0fd5cf06a03311f57c2 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 26 Apr 2023 09:20:42 +0200 Subject: [PATCH 289/601] Upgrade Arcmutate 1.0.3 -> 1.0.4 (#596) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 375e85dc5d..42ac06b3cf 100644 --- a/pom.xml +++ b/pom.xml @@ -1358,7 +1358,7 @@ com.groupcdg.arcmutate base - 1.0.3 + 1.0.4 com.groupcdg.pitest From b344d4640ce534150858e7329ea28b9e551ccd61 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 26 Apr 2023 10:28:55 +0200 Subject: [PATCH 290/601] Upgrade jacoco-maven-plugin 0.8.9 -> 0.8.10 (#597) See: - https://github.com/jacoco/jacoco/releases/tag/v0.8.10 - https://github.com/jacoco/jacoco/compare/v0.8.9...v0.8.10 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 42ac06b3cf..d3bd91db08 100644 --- a/pom.xml +++ b/pom.xml @@ -1317,7 +1317,7 @@ org.jacoco jacoco-maven-plugin - 0.8.9 + 0.8.10 #### Gradle -1. First, follow the [installation guide] - [error-prone-gradle-installation-guide] of the `gradle-errorprone-plugin`. +1. First, follow the [installation + guide][error-prone-gradle-installation-guide] of the + `gradle-errorprone-plugin`. 2. Next, edit your `build.gradle` file to add one or more Error Prone Support modules: From deebd21d34cbd9533367d5a61338b516e5a4c8be Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 1 May 2023 13:43:43 +0200 Subject: [PATCH 295/601] Upgrade maven-enforcer-plugin 3.2.1 -> 3.3.0 (#566) See: - https://github.com/apache/maven-enforcer/releases/tag/enforcer-3.3.0 - https://github.com/apache/maven-enforcer/compare/enforcer-3.2.1...enforcer-3.3.0 --- pom.xml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index e2e0e1775d..b26ec1b703 100644 --- a/pom.xml +++ b/pom.xml @@ -958,7 +958,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.2.1 + 3.3.0 false @@ -985,10 +985,21 @@ true - + + + true + + + + ${version.jdk} From de224deffa9436e537edec60f4bccce83091dcea Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Tue, 2 May 2023 08:51:39 +0200 Subject: [PATCH 296/601] Upgrade JDKs used by GitHub Actions builds (#604) Summary of changes: - Use JDK 11.0.19 instead of 11.0.18. - Use JDK 17.0.7 instead of 17.0.6. - Use JDK 20.0.1 instead of 19.0.2. - Drop the early access build, as Error Prone is currently not compatible with JDK 21-ea. See: - https://www.oracle.com/java/technologies/javase/11-0-19-relnotes.html - https://www.oracle.com/java/technologies/javase/17-0-7-relnotes.html - https://www.oracle.com/java/technologies/javase/20-relnote-issues.html - https://www.oracle.com/java/technologies/javase/20-0-1-relnotes.html --- .github/ISSUE_TEMPLATE/bug_report.md | 4 ++-- .github/workflows/build.yaml | 10 +++------- .github/workflows/codeql.yml | 2 +- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/pitest-update-pr.yml | 2 +- .github/workflows/sonarcloud.yml | 2 +- 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index fce8a8f1af..f186587c59 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -42,9 +42,9 @@ Please replace this sentence with log output, if applicable. - Operating system (e.g. MacOS Monterey). -- Java version (i.e. `java --version`, e.g. `17.0.6`). +- Java version (i.e. `java --version`, e.g. `17.0.7`). - Error Prone version (e.g. `2.18.0`). -- Error Prone Support version (e.g. `0.8.0`). +- Error Prone Support version (e.g. `0.9.0`). ### Additional context diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6890219eab..e9fd28307c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,22 +10,18 @@ jobs: strategy: matrix: os: [ ubuntu-22.04 ] - jdk: [ 11.0.18, 17.0.6, 19.0.2 ] + jdk: [ 11.0.19, 17.0.7, 20.0.1 ] distribution: [ temurin ] experimental: [ false ] include: - os: macos-12 - jdk: 17.0.6 + jdk: 17.0.7 distribution: temurin experimental: false - os: windows-2022 - jdk: 17.0.6 + jdk: 17.0.7 distribution: temurin experimental: false - - os: ubuntu-22.04 - jdk: 20-ea - distribution: zulu - experimental: true runs-on: ${{ matrix.os }} continue-on-error: ${{ matrix.experimental }} steps: diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f6bcd764dd..9456ab1700 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -28,7 +28,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3.8.0 with: - java-version: 17.0.6 + java-version: 17.0.7 distribution: temurin cache: maven - name: Initialize CodeQL diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index 918022529a..5a14fa2ae9 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -19,7 +19,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3.8.0 with: - java-version: 17.0.6 + java-version: 17.0.7 distribution: temurin cache: maven - name: Run Pitest diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index 913b781c10..cbaae60813 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -26,7 +26,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3.8.0 with: - java-version: 17.0.6 + java-version: 17.0.7 distribution: temurin cache: maven - name: Download Pitest analysis artifact diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 3966960a4b..5df6b84646 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -23,7 +23,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@v3.8.0 with: - java-version: 17.0.6 + java-version: 17.0.7 distribution: temurin cache: maven - name: Create missing `test` directory From ced1ce625d51a7c674271e32a62297825cfda87a Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 3 May 2023 08:43:27 +0200 Subject: [PATCH 297/601] Upgrade pitest-maven-plugin 1.13.0 -> 1.13.1 (#610) See: - https://github.com/hcoles/pitest/releases/tag/1.13.1 - https://github.com/hcoles/pitest/compare/1.13.0...1.13.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b26ec1b703..1f6ed72e60 100644 --- a/pom.xml +++ b/pom.xml @@ -1340,7 +1340,7 @@ org.pitest pitest-maven - 1.13.0 + 1.13.1 From 97fa90b64e438db3eaf68d2cb32faf2f48c45344 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 3 May 2023 09:11:31 +0200 Subject: [PATCH 298/601] Upgrade Checker Framework Annotations 3.33.0 -> 3.34.0 (#614) See: - https://github.com/typetools/checker-framework/releases/tag/checker-framework-3.34.0 - https://github.com/typetools/checker-framework/compare/checker-framework-3.33.0...checker-framework-3.34.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1f6ed72e60..936cef740d 100644 --- a/pom.xml +++ b/pom.xml @@ -407,7 +407,7 @@ org.checkerframework checker-qual - 3.33.0 + 3.34.0 org.hamcrest From 7d3d6a3cf880a65dd6bd245fbf72810033dfe048 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 3 May 2023 09:38:45 +0200 Subject: [PATCH 299/601] Upgrade fmt-maven-plugin 2.19 -> 2.20 (#613) See: - https://github.com/spotify/fmt-maven-plugin/releases/tag/fmt-maven-plugin-2.20 - https://github.com/spotify/fmt-maven-plugin/compare/2.19.0...fmt-maven-plugin-2.20 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 936cef740d..eb03a0e14c 100644 --- a/pom.xml +++ b/pom.xml @@ -506,7 +506,7 @@ com.spotify.fmt fmt-maven-plugin - 2.19 + 2.20 ${basedir}/src/test/resources From 3405962703d5dc5c411b51861f6ae88119db6bac Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 3 May 2023 10:10:33 +0200 Subject: [PATCH 300/601] Upgrade New Relic Java Agent 8.1.0 -> 8.2.0 (#612) See: - https://github.com/newrelic/newrelic-java-agent/releases/tag/v8.2.0 - https://github.com/newrelic/newrelic-java-agent/compare/v8.1.0...v8.2.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index eb03a0e14c..1956c48e70 100644 --- a/pom.xml +++ b/pom.xml @@ -326,7 +326,7 @@ com.newrelic.agent.java newrelic-api - 8.1.0 + 8.2.0 From 4b69fe9de960da3f26fff303d4a301023d99effa Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Wed, 3 May 2023 10:22:33 +0200 Subject: [PATCH 301/601] Extend `AssertJThrowingCallableRules` Refaster rule collection (#609) --- .../AssertJThrowingCallableRules.java | 158 ++++++++++++++++++ ...AssertJThrowingCallableRulesTestInput.java | 38 +++++ ...ssertJThrowingCallableRulesTestOutput.java | 46 +++++ 3 files changed, 242 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRules.java index a1c571ee21..74bd22df35 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRules.java @@ -319,6 +319,44 @@ static final class AssertThatThrownByNullPointerExceptionHasMessageStartingWith } } + static final class AssertThatThrownByNullPointerExceptionHasMessageContaining { + @BeforeTemplate + @SuppressWarnings( + "AssertThatThrownByNullPointerException" /* This is a more specific template. */) + AbstractObjectAssert before(ThrowingCallable throwingCallable, String message) { + return assertThatNullPointerException() + .isThrownBy(throwingCallable) + .withMessageContaining(message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractObjectAssert after(ThrowingCallable throwingCallable, String message) { + return assertThatThrownBy(throwingCallable) + .isInstanceOf(NullPointerException.class) + .hasMessageContaining(message); + } + } + + static final class AssertThatThrownByNullPointerExceptionHasMessageNotContaining { + @BeforeTemplate + @SuppressWarnings( + "AssertThatThrownByNullPointerException" /* This is a more specific template. */) + AbstractObjectAssert before(ThrowingCallable throwingCallable, String message) { + return assertThatNullPointerException() + .isThrownBy(throwingCallable) + .withMessageNotContaining(message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractObjectAssert after(ThrowingCallable throwingCallable, String message) { + return assertThatThrownBy(throwingCallable) + .isInstanceOf(NullPointerException.class) + .hasMessageNotContaining(message); + } + } + static final class AssertThatThrownByIOException { @BeforeTemplate AbstractObjectAssert before(ThrowingCallable throwingCallable) { @@ -366,6 +404,54 @@ static final class AssertThatThrownByIOExceptionHasMessageParameters { } } + static final class AssertThatThrownByIOExceptionHasMessageStartingWith { + @BeforeTemplate + @SuppressWarnings("AssertThatThrownByIOException" /* This is a more specific template. */) + AbstractObjectAssert before(ThrowingCallable throwingCallable, String message) { + return assertThatIOException().isThrownBy(throwingCallable).withMessageStartingWith(message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractObjectAssert after(ThrowingCallable throwingCallable, String message) { + return assertThatThrownBy(throwingCallable) + .isInstanceOf(IOException.class) + .hasMessageStartingWith(message); + } + } + + static final class AssertThatThrownByIOExceptionHasMessageContaining { + @BeforeTemplate + @SuppressWarnings("AssertThatThrownByIOException" /* This is a more specific template. */) + AbstractObjectAssert before(ThrowingCallable throwingCallable, String message) { + return assertThatIOException().isThrownBy(throwingCallable).withMessageContaining(message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractObjectAssert after(ThrowingCallable throwingCallable, String message) { + return assertThatThrownBy(throwingCallable) + .isInstanceOf(IOException.class) + .hasMessageContaining(message); + } + } + + static final class AssertThatThrownByIOExceptionHasMessageNotContaining { + @BeforeTemplate + @SuppressWarnings("AssertThatThrownByIOException" /* This is a more specific template. */) + AbstractObjectAssert before(ThrowingCallable throwingCallable, String message) { + return assertThatIOException().isThrownBy(throwingCallable).withMessageNotContaining(message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractObjectAssert after(ThrowingCallable throwingCallable, String message) { + return assertThatThrownBy(throwingCallable) + .isInstanceOf(IOException.class) + .hasMessageNotContaining(message); + } + } + static final class AssertThatThrownBy { @BeforeTemplate AbstractObjectAssert before( @@ -429,6 +515,78 @@ static final class AssertThatThrownByHasMessageParameters { } } + static final class AssertThatThrownByHasMessageStartingWith { + @BeforeTemplate + @SuppressWarnings("AssertThatThrownBy" /* This is a more specific template. */) + AbstractObjectAssert before( + Class exceptionType, + ThrowingCallable throwingCallable, + String message) { + return assertThatExceptionOfType(exceptionType) + .isThrownBy(throwingCallable) + .withMessageStartingWith(message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractObjectAssert after( + Class exceptionType, + ThrowingCallable throwingCallable, + String message) { + return assertThatThrownBy(throwingCallable) + .isInstanceOf(exceptionType) + .hasMessageStartingWith(message); + } + } + + static final class AssertThatThrownByHasMessageContaining { + @BeforeTemplate + @SuppressWarnings("AssertThatThrownBy" /* This is a more specific template. */) + AbstractObjectAssert before( + Class exceptionType, + ThrowingCallable throwingCallable, + String message) { + return assertThatExceptionOfType(exceptionType) + .isThrownBy(throwingCallable) + .withMessageContaining(message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractObjectAssert after( + Class exceptionType, + ThrowingCallable throwingCallable, + String message) { + return assertThatThrownBy(throwingCallable) + .isInstanceOf(exceptionType) + .hasMessageContaining(message); + } + } + + static final class AssertThatThrownByHasMessageNotContaining { + @BeforeTemplate + @SuppressWarnings("AssertThatThrownBy" /* This is a more specific template. */) + AbstractObjectAssert before( + Class exceptionType, + ThrowingCallable throwingCallable, + String message) { + return assertThatExceptionOfType(exceptionType) + .isThrownBy(throwingCallable) + .withMessageNotContaining(message); + } + + @AfterTemplate + @UseImportPolicy(STATIC_IMPORT_ALWAYS) + AbstractObjectAssert after( + Class exceptionType, + ThrowingCallable throwingCallable, + String message) { + return assertThatThrownBy(throwingCallable) + .isInstanceOf(exceptionType) + .hasMessageNotContaining(message); + } + } + // XXX: Drop this rule in favour of a generic Error Prone check that flags `String.format(...)` // arguments to a wide range of format methods. static final class AbstractThrowableAssertHasMessage { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestInput.java index a6fb1b2bec..e34dc55611 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestInput.java @@ -91,6 +91,14 @@ public ImmutableSet elidedTypesAndStaticImports() { return assertThatNullPointerException().isThrownBy(() -> {}).withMessageStartingWith("foo"); } + AbstractObjectAssert testAssertThatThrownByNullPointerExceptionHasMessageContaining() { + return assertThatNullPointerException().isThrownBy(() -> {}).withMessageContaining("foo"); + } + + AbstractObjectAssert testAssertThatThrownByNullPointerExceptionHasMessageNotContaining() { + return assertThatNullPointerException().isThrownBy(() -> {}).withMessageNotContaining("foo"); + } + AbstractObjectAssert testAssertThatThrownByIOException() { return assertThatIOException().isThrownBy(() -> {}); } @@ -103,6 +111,18 @@ public ImmutableSet elidedTypesAndStaticImports() { return assertThatIOException().isThrownBy(() -> {}).withMessage("foo %s", "bar"); } + AbstractObjectAssert testAssertThatThrownByIOExceptionHasMessageStartingWith() { + return assertThatIOException().isThrownBy(() -> {}).withMessageStartingWith("foo"); + } + + AbstractObjectAssert testAssertThatThrownByIOExceptionHasMessageContaining() { + return assertThatIOException().isThrownBy(() -> {}).withMessageContaining("foo"); + } + + AbstractObjectAssert testAssertThatThrownByIOExceptionHasMessageNotContaining() { + return assertThatIOException().isThrownBy(() -> {}).withMessageNotContaining("foo"); + } + AbstractObjectAssert testAssertThatThrownBy() { return assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {}); } @@ -119,6 +139,24 @@ public ImmutableSet elidedTypesAndStaticImports() { .withMessage("foo %s", "bar"); } + AbstractObjectAssert testAssertThatThrownByHasMessageStartingWith() { + return assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> {}) + .withMessageStartingWith("foo"); + } + + AbstractObjectAssert testAssertThatThrownByHasMessageContaining() { + return assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> {}) + .withMessageContaining("foo"); + } + + AbstractObjectAssert testAssertThatThrownByHasMessageNotContaining() { + return assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> {}) + .withMessageNotContaining("foo"); + } + ImmutableSet> testAbstractThrowableAssertHasMessage() { return ImmutableSet.of( diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestOutput.java index e4c70ca061..bb2a99ca82 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/AssertJThrowingCallableRulesTestOutput.java @@ -112,6 +112,18 @@ public ImmutableSet elidedTypesAndStaticImports() { .hasMessageStartingWith("foo"); } + AbstractObjectAssert testAssertThatThrownByNullPointerExceptionHasMessageContaining() { + return assertThatThrownBy(() -> {}) + .isInstanceOf(NullPointerException.class) + .hasMessageContaining("foo"); + } + + AbstractObjectAssert testAssertThatThrownByNullPointerExceptionHasMessageNotContaining() { + return assertThatThrownBy(() -> {}) + .isInstanceOf(NullPointerException.class) + .hasMessageNotContaining("foo"); + } + AbstractObjectAssert testAssertThatThrownByIOException() { return assertThatThrownBy(() -> {}).isInstanceOf(IOException.class); } @@ -124,6 +136,22 @@ public ImmutableSet elidedTypesAndStaticImports() { return assertThatThrownBy(() -> {}).isInstanceOf(IOException.class).hasMessage("foo %s", "bar"); } + AbstractObjectAssert testAssertThatThrownByIOExceptionHasMessageStartingWith() { + return assertThatThrownBy(() -> {}) + .isInstanceOf(IOException.class) + .hasMessageStartingWith("foo"); + } + + AbstractObjectAssert testAssertThatThrownByIOExceptionHasMessageContaining() { + return assertThatThrownBy(() -> {}).isInstanceOf(IOException.class).hasMessageContaining("foo"); + } + + AbstractObjectAssert testAssertThatThrownByIOExceptionHasMessageNotContaining() { + return assertThatThrownBy(() -> {}) + .isInstanceOf(IOException.class) + .hasMessageNotContaining("foo"); + } + AbstractObjectAssert testAssertThatThrownBy() { return assertThatThrownBy(() -> {}).isInstanceOf(IllegalArgumentException.class); } @@ -140,6 +168,24 @@ public ImmutableSet elidedTypesAndStaticImports() { .hasMessage("foo %s", "bar"); } + AbstractObjectAssert testAssertThatThrownByHasMessageStartingWith() { + return assertThatThrownBy(() -> {}) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageStartingWith("foo"); + } + + AbstractObjectAssert testAssertThatThrownByHasMessageContaining() { + return assertThatThrownBy(() -> {}) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("foo"); + } + + AbstractObjectAssert testAssertThatThrownByHasMessageNotContaining() { + return assertThatThrownBy(() -> {}) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageNotContaining("foo"); + } + ImmutableSet> testAbstractThrowableAssertHasMessage() { return ImmutableSet.of( From 52245c6310a4d347dfb2fac0588418bfe050de80 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 3 May 2023 14:39:03 +0200 Subject: [PATCH 302/601] Extend `PrimitiveRules` Refaster rule collection (#608) Assorted methods and constants exposed by Guava's `com.google.common.primitives.*` types are now replaced with their JDK equivalents. While there, also update the parameter types of some existing `@AfterTemplate` methods, resolving an inconsistency flagged by @knutwannheden. --- .../refasterrules/PrimitiveRules.java | 322 +++++++++++++++++- .../PrimitiveRulesTestInput.java | 109 +++++- .../PrimitiveRulesTestOutput.java | 109 +++++- 3 files changed, 530 insertions(+), 10 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/PrimitiveRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/PrimitiveRules.java index 9baead99fd..f0d39d0320 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/PrimitiveRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/PrimitiveRules.java @@ -1,6 +1,13 @@ package tech.picnic.errorprone.refasterrules; +import com.google.common.primitives.Booleans; +import com.google.common.primitives.Bytes; +import com.google.common.primitives.Chars; +import com.google.common.primitives.Doubles; +import com.google.common.primitives.Floats; import com.google.common.primitives.Ints; +import com.google.common.primitives.Longs; +import com.google.common.primitives.Shorts; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; @@ -19,7 +26,7 @@ boolean before(double a, double b) { } @AfterTemplate - boolean after(long a, long b) { + boolean after(double a, double b) { return a < b; } } @@ -33,7 +40,7 @@ boolean before(double a, double b) { } @AfterTemplate - boolean after(long a, long b) { + boolean after(double a, double b) { return a <= b; } } @@ -47,7 +54,7 @@ boolean before(double a, double b) { } @AfterTemplate - boolean after(long a, long b) { + boolean after(double a, double b) { return a > b; } } @@ -61,7 +68,7 @@ boolean before(double a, double b) { } @AfterTemplate - boolean after(long a, long b) { + boolean after(double a, double b) { return a >= b; } } @@ -69,13 +76,312 @@ boolean after(long a, long b) { /** Prefer {@link Math#toIntExact(long)} over the Guava alternative. */ static final class LongToIntExact { @BeforeTemplate - int before(long a) { - return Ints.checkedCast(a); + int before(long l) { + return Ints.checkedCast(l); } @AfterTemplate - int after(long a) { - return Math.toIntExact(a); + int after(long l) { + return Math.toIntExact(l); + } + } + + /** Prefer {@link Boolean#hashCode(boolean)} over the Guava alternative. */ + static final class BooleanHashCode { + @BeforeTemplate + int before(boolean b) { + return Booleans.hashCode(b); + } + + @AfterTemplate + int after(boolean b) { + return Boolean.hashCode(b); + } + } + + /** Prefer {@link Byte#hashCode(byte)} over the Guava alternative. */ + static final class ByteHashCode { + @BeforeTemplate + int before(byte b) { + return Bytes.hashCode(b); + } + + @AfterTemplate + int after(byte b) { + return Byte.hashCode(b); + } + } + + /** Prefer {@link Character#hashCode(char)} over the Guava alternative. */ + static final class CharacterHashCode { + @BeforeTemplate + int before(char c) { + return Chars.hashCode(c); + } + + @AfterTemplate + int after(char c) { + return Character.hashCode(c); + } + } + + /** Prefer {@link Short#hashCode(short)} over the Guava alternative. */ + static final class ShortHashCode { + @BeforeTemplate + int before(short s) { + return Shorts.hashCode(s); + } + + @AfterTemplate + int after(short s) { + return Short.hashCode(s); + } + } + + /** Prefer {@link Integer#hashCode(int)} over the Guava alternative. */ + static final class IntegerHashCode { + @BeforeTemplate + int before(int i) { + return Ints.hashCode(i); + } + + @AfterTemplate + int after(int i) { + return Integer.hashCode(i); + } + } + + /** Prefer {@link Long#hashCode(long)} over the Guava alternative. */ + static final class LongHashCode { + @BeforeTemplate + int before(long l) { + return Longs.hashCode(l); + } + + @AfterTemplate + int after(long l) { + return Long.hashCode(l); + } + } + + /** Prefer {@link Float#hashCode(float)} over the Guava alternative. */ + static final class FloatHashCode { + @BeforeTemplate + int before(float f) { + return Floats.hashCode(f); + } + + @AfterTemplate + int after(float f) { + return Float.hashCode(f); + } + } + + /** Prefer {@link Double#hashCode(double)} over the Guava alternative. */ + static final class DoubleHashCode { + @BeforeTemplate + int before(double d) { + return Doubles.hashCode(d); + } + + @AfterTemplate + int after(double d) { + return Double.hashCode(d); + } + } + + /** Prefer {@link Boolean#compare(boolean, boolean)} over the Guava alternative. */ + static final class BooleanCompare { + @BeforeTemplate + int before(boolean a, boolean b) { + return Booleans.compare(a, b); + } + + @AfterTemplate + int after(boolean a, boolean b) { + return Boolean.compare(a, b); + } + } + + /** Prefer {@link Character#compare(char, char)} over the Guava alternative. */ + static final class CharacterCompare { + @BeforeTemplate + int before(char a, char b) { + return Chars.compare(a, b); + } + + @AfterTemplate + int after(char a, char b) { + return Character.compare(a, b); + } + } + + /** Prefer {@link Short#compare(short, short)} over the Guava alternative. */ + static final class ShortCompare { + @BeforeTemplate + int before(short a, short b) { + return Shorts.compare(a, b); + } + + @AfterTemplate + int after(short a, short b) { + return Short.compare(a, b); + } + } + + /** Prefer {@link Integer#compare(int, int)} over the Guava alternative. */ + static final class IntegerCompare { + @BeforeTemplate + int before(int a, int b) { + return Ints.compare(a, b); + } + + @AfterTemplate + int after(int a, int b) { + return Integer.compare(a, b); + } + } + + /** Prefer {@link Long#compare(long, long)} over the Guava alternative. */ + static final class LongCompare { + @BeforeTemplate + int before(long a, long b) { + return Longs.compare(a, b); + } + + @AfterTemplate + int after(long a, long b) { + return Long.compare(a, b); + } + } + + /** Prefer {@link Float#compare(float, float)} over the Guava alternative. */ + static final class FloatCompare { + @BeforeTemplate + int before(float a, float b) { + return Floats.compare(a, b); + } + + @AfterTemplate + int after(float a, float b) { + return Float.compare(a, b); + } + } + + /** Prefer {@link Double#compare(double, double)} over the Guava alternative. */ + static final class DoubleCompare { + @BeforeTemplate + int before(double a, double b) { + return Doubles.compare(a, b); + } + + @AfterTemplate + int after(double a, double b) { + return Double.compare(a, b); + } + } + + /** Prefer {@link Character#BYTES} over the Guava alternative. */ + static final class CharacterBytes { + @BeforeTemplate + int before() { + return Chars.BYTES; + } + + @AfterTemplate + int after() { + return Character.BYTES; + } + } + + /** Prefer {@link Short#BYTES} over the Guava alternative. */ + static final class ShortBytes { + @BeforeTemplate + int before() { + return Shorts.BYTES; + } + + @AfterTemplate + int after() { + return Short.BYTES; + } + } + + /** Prefer {@link Integer#BYTES} over the Guava alternative. */ + static final class IntegerBytes { + @BeforeTemplate + int before() { + return Ints.BYTES; + } + + @AfterTemplate + int after() { + return Integer.BYTES; + } + } + + /** Prefer {@link Long#BYTES} over the Guava alternative. */ + static final class LongBytes { + @BeforeTemplate + int before() { + return Longs.BYTES; + } + + @AfterTemplate + int after() { + return Long.BYTES; + } + } + + /** Prefer {@link Float#BYTES} over the Guava alternative. */ + static final class FloatBytes { + @BeforeTemplate + int before() { + return Floats.BYTES; + } + + @AfterTemplate + int after() { + return Float.BYTES; + } + } + + /** Prefer {@link Double#BYTES} over the Guava alternative. */ + static final class DoubleBytes { + @BeforeTemplate + int before() { + return Doubles.BYTES; + } + + @AfterTemplate + int after() { + return Double.BYTES; + } + } + + /** Prefer {@link Float#isFinite(float)} over the Guava alternative. */ + static final class FloatIsFinite { + @BeforeTemplate + boolean before(float f) { + return Floats.isFinite(f); + } + + @AfterTemplate + boolean after(float f) { + return Float.isFinite(f); + } + } + + /** Prefer {@link Double#isFinite(double)} over the Guava alternative. */ + static final class DoubleIsFinite { + @BeforeTemplate + boolean before(double d) { + return Doubles.isFinite(d); + } + + @AfterTemplate + boolean after(double d) { + return Double.isFinite(d); } } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestInput.java index aefee758fb..c1affa87e5 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestInput.java @@ -1,13 +1,28 @@ package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; +import com.google.common.primitives.Booleans; +import com.google.common.primitives.Bytes; +import com.google.common.primitives.Chars; +import com.google.common.primitives.Doubles; +import com.google.common.primitives.Floats; import com.google.common.primitives.Ints; +import com.google.common.primitives.Longs; +import com.google.common.primitives.Shorts; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class PrimitiveRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(Ints.class); + return ImmutableSet.of( + Booleans.class, + Bytes.class, + Chars.class, + Doubles.class, + Floats.class, + Ints.class, + Longs.class, + Shorts.class); } ImmutableSet testLessThan() { @@ -57,4 +72,96 @@ ImmutableSet testGreaterThanOrEqualTo() { int testLongToIntExact() { return Ints.checkedCast(Long.MAX_VALUE); } + + int testBooleanHashCode() { + return Booleans.hashCode(true); + } + + int testByteHashCode() { + return Bytes.hashCode((byte) 1); + } + + int testCharacterHashCode() { + return Chars.hashCode('a'); + } + + int testShortHashCode() { + return Shorts.hashCode((short) 1); + } + + int testIntegerHashCode() { + return Ints.hashCode(1); + } + + int testLongHashCode() { + return Longs.hashCode(1); + } + + int testFloatHashCode() { + return Floats.hashCode(1); + } + + int testDoubleHashCode() { + return Doubles.hashCode(1); + } + + int testBooleanCompare() { + return Booleans.compare(false, true); + } + + int testCharacterCompare() { + return Chars.compare('a', 'b'); + } + + int testShortCompare() { + return Shorts.compare((short) 1, (short) 2); + } + + int testIntegerCompare() { + return Ints.compare(1, 2); + } + + int testLongCompare() { + return Longs.compare(1, 2); + } + + int testFloatCompare() { + return Floats.compare(1, 2); + } + + int testDoubleCompare() { + return Doubles.compare(1, 2); + } + + int testCharacterBytes() { + return Chars.BYTES; + } + + int testShortBytes() { + return Shorts.BYTES; + } + + int testIntegerBytes() { + return Ints.BYTES; + } + + int testLongBytes() { + return Longs.BYTES; + } + + int testFloatBytes() { + return Floats.BYTES; + } + + int testDoubleBytes() { + return Doubles.BYTES; + } + + boolean testFloatIsFinite() { + return Floats.isFinite(1); + } + + boolean testDoubleIsFinite() { + return Doubles.isFinite(1); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestOutput.java index 9b2294424c..6f91d4d9ee 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PrimitiveRulesTestOutput.java @@ -1,13 +1,28 @@ package tech.picnic.errorprone.refasterrules; import com.google.common.collect.ImmutableSet; +import com.google.common.primitives.Booleans; +import com.google.common.primitives.Bytes; +import com.google.common.primitives.Chars; +import com.google.common.primitives.Doubles; +import com.google.common.primitives.Floats; import com.google.common.primitives.Ints; +import com.google.common.primitives.Longs; +import com.google.common.primitives.Shorts; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class PrimitiveRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(Ints.class); + return ImmutableSet.of( + Booleans.class, + Bytes.class, + Chars.class, + Doubles.class, + Floats.class, + Ints.class, + Longs.class, + Shorts.class); } ImmutableSet testLessThan() { @@ -57,4 +72,96 @@ ImmutableSet testGreaterThanOrEqualTo() { int testLongToIntExact() { return Math.toIntExact(Long.MAX_VALUE); } + + int testBooleanHashCode() { + return Boolean.hashCode(true); + } + + int testByteHashCode() { + return Byte.hashCode((byte) 1); + } + + int testCharacterHashCode() { + return Character.hashCode('a'); + } + + int testShortHashCode() { + return Short.hashCode((short) 1); + } + + int testIntegerHashCode() { + return Integer.hashCode(1); + } + + int testLongHashCode() { + return Long.hashCode(1); + } + + int testFloatHashCode() { + return Float.hashCode(1); + } + + int testDoubleHashCode() { + return Double.hashCode(1); + } + + int testBooleanCompare() { + return Boolean.compare(false, true); + } + + int testCharacterCompare() { + return Character.compare('a', 'b'); + } + + int testShortCompare() { + return Short.compare((short) 1, (short) 2); + } + + int testIntegerCompare() { + return Integer.compare(1, 2); + } + + int testLongCompare() { + return Long.compare(1, 2); + } + + int testFloatCompare() { + return Float.compare(1, 2); + } + + int testDoubleCompare() { + return Double.compare(1, 2); + } + + int testCharacterBytes() { + return Character.BYTES; + } + + int testShortBytes() { + return Short.BYTES; + } + + int testIntegerBytes() { + return Integer.BYTES; + } + + int testLongBytes() { + return Long.BYTES; + } + + int testFloatBytes() { + return Float.BYTES; + } + + int testDoubleBytes() { + return Double.BYTES; + } + + boolean testFloatIsFinite() { + return Float.isFinite(1); + } + + boolean testDoubleIsFinite() { + return Double.isFinite(1); + } } From 7d728e956efe76e19cff903d14abd7e9593dc33c Mon Sep 17 00:00:00 2001 From: Mohamed Sameh <110535847+mohamedsamehsalah@users.noreply.github.com> Date: Wed, 3 May 2023 16:56:02 +0200 Subject: [PATCH 303/601] Introduce `Sets{Difference,Intersection}{,Map,Multimap}` and `SetsUnion` Refaster rules (#607) --- .../refasterrules/ImmutableSetRules.java | 116 ++++++++++++++++++ .../ImmutableSetRulesTestInput.java | 58 ++++++++- .../ImmutableSetRulesTestOutput.java | 41 ++++++- 3 files changed, 213 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetRules.java index f4d5ba78b7..628bb1cf6b 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSetRules.java @@ -4,8 +4,11 @@ import static com.google.errorprone.refaster.ImportPolicy.STATIC_IMPORT_ALWAYS; import static java.util.Collections.emptySet; import static java.util.Collections.singleton; +import static java.util.function.Predicate.not; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; +import com.google.common.collect.Sets; import com.google.common.collect.Sets.SetView; import com.google.common.collect.Streams; import com.google.errorprone.refaster.Refaster; @@ -15,6 +18,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; +import java.util.Map; import java.util.Set; import java.util.stream.Stream; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; @@ -211,4 +215,116 @@ ImmutableSet after(T e1, T e2, T e3, T e4, T e5) { return ImmutableSet.of(e1, e2, e3, e4, e5); } } + + /** + * Prefer an immutable copy of {@link Sets#difference(Set, Set)} over more contrived alternatives. + */ + static final class SetsDifference { + @BeforeTemplate + ImmutableSet before(Set set1, Set set2) { + return set1.stream() + .filter(Refaster.anyOf(not(set2::contains), e -> !set2.contains(e))) + .collect(toImmutableSet()); + } + + @AfterTemplate + ImmutableSet after(Set set1, Set set2) { + return Sets.difference(set1, set2).immutableCopy(); + } + } + + /** + * Prefer an immutable copy of {@link Sets#difference(Set, Set)} over more contrived alternatives. + */ + static final class SetsDifferenceMap { + @BeforeTemplate + ImmutableSet before(Set set, Map map) { + return set.stream() + .filter(Refaster.anyOf(not(map::containsKey), e -> !map.containsKey(e))) + .collect(toImmutableSet()); + } + + @AfterTemplate + ImmutableSet after(Set set, Map map) { + return Sets.difference(set, map.keySet()).immutableCopy(); + } + } + + /** + * Prefer an immutable copy of {@link Sets#difference(Set, Set)} over more contrived alternatives. + */ + static final class SetsDifferenceMultimap { + @BeforeTemplate + ImmutableSet before(Set set, Multimap multimap) { + return set.stream() + .filter(Refaster.anyOf(not(multimap::containsKey), e -> !multimap.containsKey(e))) + .collect(toImmutableSet()); + } + + @AfterTemplate + ImmutableSet after(Set set, Multimap multimap) { + return Sets.difference(set, multimap.keySet()).immutableCopy(); + } + } + + /** + * Prefer an immutable copy of {@link Sets#intersection(Set, Set)} over more contrived + * alternatives. + */ + static final class SetsIntersection { + @BeforeTemplate + ImmutableSet before(Set set1, Set set2) { + return set1.stream().filter(set2::contains).collect(toImmutableSet()); + } + + @AfterTemplate + ImmutableSet after(Set set1, Set set2) { + return Sets.intersection(set1, set2).immutableCopy(); + } + } + + /** + * Prefer an immutable copy of {@link Sets#intersection(Set, Set)} over more contrived + * alternatives. + */ + static final class SetsIntersectionMap { + @BeforeTemplate + ImmutableSet before(Set set, Map map) { + return set.stream().filter(map::containsKey).collect(toImmutableSet()); + } + + @AfterTemplate + ImmutableSet after(Set set, Map map) { + return Sets.intersection(set, map.keySet()).immutableCopy(); + } + } + + /** + * Prefer an immutable copy of {@link Sets#intersection(Set, Set)} over more contrived + * alternatives. + */ + static final class SetsIntersectionMultimap { + @BeforeTemplate + ImmutableSet before(Set set, Multimap multimap) { + return set.stream().filter(multimap::containsKey).collect(toImmutableSet()); + } + + @AfterTemplate + ImmutableSet after(Set set, Multimap multimap) { + return Sets.intersection(set, multimap.keySet()).immutableCopy(); + } + } + + /** Prefer an immutable copy of {@link Sets#union(Set, Set)} over more contrived alternatives. */ + static final class SetsUnion { + @BeforeTemplate + ImmutableSet before(Set set1, Set set2) { + return Stream.concat(set1.stream(), set2.stream()).collect(toImmutableSet()); + } + + @AfterTemplate + ImmutableSet after(Set set1, Set set2) { + return Sets.union(set1, set2).immutableCopy(); + } + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestInput.java index 9512cdea64..53e7c41556 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestInput.java @@ -1,9 +1,12 @@ package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static java.util.function.Predicate.not; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSetMultimap; import com.google.common.collect.Sets; import com.google.common.collect.Streams; import java.util.Arrays; @@ -15,7 +18,7 @@ final class ImmutableSetRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(Arrays.class, Collections.class, Streams.class); + return ImmutableSet.of(Arrays.class, Collections.class, Streams.class, not(null)); } ImmutableSet.Builder testImmutableSetBuilder() { @@ -72,4 +75,57 @@ Set testImmutableSetOf4() { Set testImmutableSetOf5() { return Set.of(1, 2, 3, 4, 5); } + + ImmutableSet> testSetsDifference() { + return ImmutableSet.of( + ImmutableSet.of(1).stream() + .filter(not(ImmutableSet.of(2)::contains)) + .collect(toImmutableSet()), + ImmutableSet.of(3).stream() + .filter(v -> !ImmutableSet.of(4).contains(v)) + .collect(toImmutableSet())); + } + + ImmutableSet> testSetsDifferenceMap() { + return ImmutableSet.of( + ImmutableSet.of(1).stream() + .filter(not(ImmutableMap.of(2, 3)::containsKey)) + .collect(toImmutableSet()), + ImmutableSet.of(4).stream() + .filter(v -> !ImmutableMap.of(5, 6).containsKey(v)) + .collect(toImmutableSet())); + } + + ImmutableSet> testSetsDifferenceMultimap() { + return ImmutableSet.of( + ImmutableSet.of(1).stream() + .filter(not(ImmutableSetMultimap.of(2, 3)::containsKey)) + .collect(toImmutableSet()), + ImmutableSet.of(4).stream() + .filter(v -> !ImmutableSetMultimap.of(5, 6).containsKey(v)) + .collect(toImmutableSet())); + } + + ImmutableSet testSetsIntersection() { + return ImmutableSet.of(1).stream() + .filter(ImmutableSet.of(2)::contains) + .collect(toImmutableSet()); + } + + ImmutableSet testSetsIntersectionMap() { + return ImmutableSet.of(1).stream() + .filter(ImmutableMap.of(2, 3)::containsKey) + .collect(toImmutableSet()); + } + + ImmutableSet testSetsIntersectionMultimap() { + return ImmutableSet.of(1).stream() + .filter(ImmutableSetMultimap.of(2, 3)::containsKey) + .collect(toImmutableSet()); + } + + ImmutableSet testSetsUnion() { + return Stream.concat(ImmutableSet.of(1).stream(), ImmutableSet.of(2).stream()) + .collect(toImmutableSet()); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestOutput.java index b081feee13..74a6c9d67e 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSetRulesTestOutput.java @@ -1,9 +1,12 @@ package tech.picnic.errorprone.refasterrules; import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static java.util.function.Predicate.not; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSetMultimap; import com.google.common.collect.Sets; import com.google.common.collect.Streams; import java.util.Arrays; @@ -15,7 +18,7 @@ final class ImmutableSetRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(Arrays.class, Collections.class, Streams.class); + return ImmutableSet.of(Arrays.class, Collections.class, Streams.class, not(null)); } ImmutableSet.Builder testImmutableSetBuilder() { @@ -67,4 +70,40 @@ Set testImmutableSetOf4() { Set testImmutableSetOf5() { return ImmutableSet.of(1, 2, 3, 4, 5); } + + ImmutableSet> testSetsDifference() { + return ImmutableSet.of( + Sets.difference(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy(), + Sets.difference(ImmutableSet.of(3), ImmutableSet.of(4)).immutableCopy()); + } + + ImmutableSet> testSetsDifferenceMap() { + return ImmutableSet.of( + Sets.difference(ImmutableSet.of(1), ImmutableMap.of(2, 3).keySet()).immutableCopy(), + Sets.difference(ImmutableSet.of(4), ImmutableMap.of(5, 6).keySet()).immutableCopy()); + } + + ImmutableSet> testSetsDifferenceMultimap() { + return ImmutableSet.of( + Sets.difference(ImmutableSet.of(1), ImmutableSetMultimap.of(2, 3).keySet()).immutableCopy(), + Sets.difference(ImmutableSet.of(4), ImmutableSetMultimap.of(5, 6).keySet()) + .immutableCopy()); + } + + ImmutableSet testSetsIntersection() { + return Sets.intersection(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy(); + } + + ImmutableSet testSetsIntersectionMap() { + return Sets.intersection(ImmutableSet.of(1), ImmutableMap.of(2, 3).keySet()).immutableCopy(); + } + + ImmutableSet testSetsIntersectionMultimap() { + return Sets.intersection(ImmutableSet.of(1), ImmutableSetMultimap.of(2, 3).keySet()) + .immutableCopy(); + } + + ImmutableSet testSetsUnion() { + return Sets.union(ImmutableSet.of(1), ImmutableSet.of(2)).immutableCopy(); + } } From 6229fa92458c7c7f3431d045f8c63adc67343c15 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Thu, 4 May 2023 08:08:27 +0200 Subject: [PATCH 304/601] Extend `StreamRules` Refaster rule collection (#605) All changes suggested by SonarCloud's `java:s4034` rule, as well as the examples mentioned in openrewrite/rewrite#2984 are now covered. (In a number of cases through composition of more generic rules.) See https://rules.sonarsource.com/java/RSPEC-4034 --- .../errorprone/refasterrules/StreamRules.java | 33 +++++++++++++++++-- .../refasterrules/StreamRulesTestInput.java | 21 +++++++++--- .../refasterrules/StreamRulesTestOutput.java | 23 ++++++++++--- 3 files changed, 67 insertions(+), 10 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java index c1b1180bcc..604abf1f74 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java @@ -28,6 +28,7 @@ import com.google.errorprone.refaster.annotation.Placeholder; import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Arrays; +import java.util.Collection; import java.util.Comparator; import java.util.DoubleSummaryStatistics; import java.util.IntSummaryStatistics; @@ -245,14 +246,18 @@ Optional after(Stream stream, Function function) { } /** In order to test whether a stream has any element, simply try to find one. */ + // XXX: This rule assumes that any matched `Collector` does not perform any filtering. + // (Perhaps we could add a `@Matches` guard that validates that the collector expression does not + // contain a `Collectors#filtering` call. That'd still not be 100% accurate, though.) static final class StreamIsEmpty { @BeforeTemplate - boolean before(Stream stream) { + boolean before(Stream stream, Collector> collector) { return Refaster.anyOf( stream.count() == 0, stream.count() <= 0, stream.count() < 1, - stream.findFirst().isEmpty()); + stream.findFirst().isEmpty(), + stream.collect(collector).isEmpty()); } @AfterTemplate @@ -347,6 +352,14 @@ boolean before(Stream stream, Predicate predicate) { stream.filter(predicate).findAny().isEmpty()); } + @BeforeTemplate + boolean before2( + Stream stream, + @Matches(IsLambdaExpressionOrMethodReference.class) + Function predicate) { + return stream.map(predicate).noneMatch(Refaster.anyOf(Boolean::booleanValue, b -> b)); + } + @AfterTemplate boolean after(Stream stream, Predicate predicate) { return stream.noneMatch(predicate); @@ -377,6 +390,14 @@ boolean before(Stream stream, Predicate predicate) { !stream.noneMatch(predicate), stream.filter(predicate).findAny().isPresent()); } + @BeforeTemplate + boolean before2( + Stream stream, + @Matches(IsLambdaExpressionOrMethodReference.class) + Function predicate) { + return stream.map(predicate).anyMatch(Refaster.anyOf(Boolean::booleanValue, b -> b)); + } + @AfterTemplate boolean after(Stream stream, Predicate predicate) { return stream.anyMatch(predicate); @@ -389,6 +410,14 @@ boolean before(Stream stream, Predicate predicate) { return stream.noneMatch(Refaster.anyOf(not(predicate), predicate.negate())); } + @BeforeTemplate + boolean before2( + Stream stream, + @Matches(IsLambdaExpressionOrMethodReference.class) + Function predicate) { + return stream.map(predicate).allMatch(Refaster.anyOf(Boolean::booleanValue, b -> b)); + } + @AfterTemplate boolean after(Stream stream, Predicate predicate) { return stream.allMatch(predicate); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java index c568e49507..48f0de13a7 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java @@ -109,7 +109,8 @@ ImmutableSet testStreamIsEmpty() { Stream.of(1).count() == 0, Stream.of(2).count() <= 0, Stream.of(3).count() < 1, - Stream.of(4).findFirst().isEmpty()); + Stream.of(4).findFirst().isEmpty(), + Stream.of(5).collect(toImmutableSet()).isEmpty()); } ImmutableSet testStreamIsNotEmpty() { @@ -146,11 +147,15 @@ ImmutableSet> testStreamMaxNaturalOrder() { ImmutableSet testStreamNoneMatch() { Predicate pred = String::isBlank; + Function toBooleanFunction = Boolean::valueOf; return ImmutableSet.of( !Stream.of("foo").anyMatch(s -> s.length() > 1), Stream.of("bar").allMatch(not(String::isBlank)), Stream.of("baz").allMatch(pred.negate()), - Stream.of("qux").filter(String::isEmpty).findAny().isEmpty()); + Stream.of("qux").filter(String::isEmpty).findAny().isEmpty(), + Stream.of("quux").map(s -> s.isBlank()).noneMatch(Boolean::booleanValue), + Stream.of("quuz").map(Boolean::valueOf).noneMatch(r -> r), + Stream.of("corge").map(toBooleanFunction).noneMatch(Boolean::booleanValue)); } ImmutableSet testStreamNoneMatch2() { @@ -159,16 +164,24 @@ ImmutableSet testStreamNoneMatch2() { } ImmutableSet testStreamAnyMatch() { + Function toBooleanFunction = Boolean::valueOf; return ImmutableSet.of( !Stream.of("foo").noneMatch(s -> s.length() > 1), - Stream.of("bar").filter(String::isEmpty).findAny().isPresent()); + Stream.of("bar").filter(String::isEmpty).findAny().isPresent(), + Stream.of("baz").map(s -> s.isBlank()).anyMatch(Boolean::booleanValue), + Stream.of("qux").map(Boolean::valueOf).anyMatch(r -> r), + Stream.of("quux").map(toBooleanFunction).anyMatch(Boolean::booleanValue)); } ImmutableSet testStreamAllMatch() { Predicate pred = String::isBlank; + Function toBooleanFunction = Boolean::valueOf; return ImmutableSet.of( Stream.of("foo").noneMatch(not(String::isBlank)), - Stream.of("bar").noneMatch(pred.negate())); + Stream.of("bar").noneMatch(pred.negate()), + Stream.of("baz").map(s -> s.isBlank()).allMatch(Boolean::booleanValue), + Stream.of("qux").map(Boolean::valueOf).allMatch(r -> r), + Stream.of("quux").map(toBooleanFunction).anyMatch(Boolean::booleanValue)); } boolean testStreamAllMatch2() { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java index fb7484f6b5..7ed6bbd4ae 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java @@ -110,7 +110,8 @@ ImmutableSet testStreamIsEmpty() { Stream.of(1).findAny().isEmpty(), Stream.of(2).findAny().isEmpty(), Stream.of(3).findAny().isEmpty(), - Stream.of(4).findAny().isEmpty()); + Stream.of(4).findAny().isEmpty(), + Stream.of(5).findAny().isEmpty()); } ImmutableSet testStreamIsNotEmpty() { @@ -147,11 +148,15 @@ ImmutableSet> testStreamMaxNaturalOrder() { ImmutableSet testStreamNoneMatch() { Predicate pred = String::isBlank; + Function toBooleanFunction = Boolean::valueOf; return ImmutableSet.of( Stream.of("foo").noneMatch(s -> s.length() > 1), Stream.of("bar").noneMatch(String::isBlank), Stream.of("baz").noneMatch(pred), - Stream.of("qux").noneMatch(String::isEmpty)); + Stream.of("qux").noneMatch(String::isEmpty), + Stream.of("quux").noneMatch(s -> s.isBlank()), + Stream.of("quuz").noneMatch(Boolean::valueOf), + Stream.of("corge").map(toBooleanFunction).noneMatch(Boolean::booleanValue)); } ImmutableSet testStreamNoneMatch2() { @@ -160,14 +165,24 @@ ImmutableSet testStreamNoneMatch2() { } ImmutableSet testStreamAnyMatch() { + Function toBooleanFunction = Boolean::valueOf; return ImmutableSet.of( - Stream.of("foo").anyMatch(s -> s.length() > 1), Stream.of("bar").anyMatch(String::isEmpty)); + Stream.of("foo").anyMatch(s -> s.length() > 1), + Stream.of("bar").anyMatch(String::isEmpty), + Stream.of("baz").anyMatch(s -> s.isBlank()), + Stream.of("qux").anyMatch(Boolean::valueOf), + Stream.of("quux").map(toBooleanFunction).anyMatch(Boolean::booleanValue)); } ImmutableSet testStreamAllMatch() { Predicate pred = String::isBlank; + Function toBooleanFunction = Boolean::valueOf; return ImmutableSet.of( - Stream.of("foo").allMatch(String::isBlank), Stream.of("bar").allMatch(pred)); + Stream.of("foo").allMatch(String::isBlank), + Stream.of("bar").allMatch(pred), + Stream.of("baz").allMatch(s -> s.isBlank()), + Stream.of("qux").allMatch(Boolean::valueOf), + Stream.of("quux").map(toBooleanFunction).anyMatch(Boolean::booleanValue)); } boolean testStreamAllMatch2() { From 760b1ddf31df002bab2defdd3896f5f9ae060934 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 4 May 2023 09:53:57 +0200 Subject: [PATCH 305/601] Upgrade Google Java Format 1.16.0 -> 1.17.0 (#611) See: - https://github.com/google/google-java-format/releases/tag/v1.17.0 - https://github.com/google/google-java-format/compare/v1.16.0...v1.17.0 --- .../bugpatterns/CanonicalAnnotationSyntaxTest.java | 10 ++++++++++ .../LexicographicalAnnotationAttributeListingTest.java | 10 ++++++++++ .../LexicographicalAnnotationListingTest.java | 5 +++++ .../bugpatterns/SpringMvcAnnotationTest.java | 5 +++++ pom.xml | 2 +- 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalAnnotationSyntaxTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalAnnotationSyntaxTest.java index 150d386682..1c37fad188 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalAnnotationSyntaxTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalAnnotationSyntaxTest.java @@ -34,9 +34,11 @@ void identification() { " // BUG: Diagnostic contains:", " @pkg.A.Foo()", " A functional1();", + "", " // BUG: Diagnostic contains:", " @A.Foo()", " A functional2();", + "", " // BUG: Diagnostic contains:", " @Foo()", " A functional3();", @@ -53,9 +55,11 @@ void identification() { " // BUG: Diagnostic contains:", " @pkg.A.Foo({1})", " A singleton1();", + "", " // BUG: Diagnostic contains:", " @A.Foo({1})", " A singleton2();", + "", " // BUG: Diagnostic contains:", " @Foo({1})", " A singleton3();", @@ -63,9 +67,11 @@ void identification() { " // BUG: Diagnostic contains:", " @pkg.A.Foo(value = 1)", " A verbose1();", + "", " // BUG: Diagnostic contains:", " @A.Foo(value = 1)", " A verbose2();", + "", " // BUG: Diagnostic contains:", " @Foo(value = 1)", " A verbose3();", @@ -82,9 +88,11 @@ void identification() { " // BUG: Diagnostic contains:", " @pkg.A.Foo(value2 = {2})", " A customSingleton1();", + "", " // BUG: Diagnostic contains:", " @A.Foo(value2 = {2})", " A customSingleton2();", + "", " // BUG: Diagnostic contains:", " @Foo(value2 = {2})", " A customSingleton3();", @@ -112,11 +120,13 @@ void identification() { " 1, 1,", " })", " A trailingComma1();", + "", " // BUG: Diagnostic contains:", " @A.Foo({", " 1, 1,", " })", " A trailingComma2();", + "", " // BUG: Diagnostic contains:", " @Foo({", " 1, 1,", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListingTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListingTest.java index 43fb54c0e2..da842fd92a 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListingTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListingTest.java @@ -50,18 +50,21 @@ void identification() { "", " @Foo({\"a\", \"b\"})", " A sortedStrings();", + "", " // BUG: Diagnostic contains:", " @Foo({\"b\", \"a\"})", " A unsortedString();", "", " @Foo({\"ab\", \"Ac\"})", " A sortedStringCaseInsensitive();", + "", " // BUG: Diagnostic contains:", " @Foo({\"ac\", \"Ab\"})", " A unsortedStringCaseInsensitive();", "", " @Foo({\"A\", \"a\"})", " A sortedStringCaseInsensitiveWithTotalOrderFallback();", + "", " // BUG: Diagnostic contains:", " @Foo({\"a\", \"A\"})", " A unsortedStringCaseInsensitiveWithTotalOrderFallback();", @@ -86,6 +89,7 @@ void identification() { "", " @Foo(cls = {int.class, long.class})", " A sortedClasses();", + "", " // BUG: Diagnostic contains:", " @Foo(cls = {long.class, int.class})", " A unsortedClasses();", @@ -98,6 +102,7 @@ void identification() { "", " @Foo(enums = {DOWN, UP})", " A sortedEnums();", + "", " // BUG: Diagnostic contains:", " @Foo(enums = {UP, DOWN})", " A unsortedEnums();", @@ -110,15 +115,18 @@ void identification() { "", " @Foo(anns = {@Bar(\"a\"), @Bar(\"b\")})", " A sortedAnns();", + "", " // BUG: Diagnostic contains:", " @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})", " A unsortedAnns();", + "", " // BUG: Diagnostic contains:", " @Foo(anns = {@Bar(\"a\"), @Bar({\"b\", \"a\"})})", " A unsortedInnderAnns();", "", " @Foo({\"a=foo\", \"a.b=bar\", \"a.c=baz\"})", " A hierarchicallySorted();", + "", " // BUG: Diagnostic contains:", " @Foo({\"a.b=bar\", \"a.c=baz\", \"a=foo\"})", " A hierarchicallyUnsorted();", @@ -265,12 +273,14 @@ void filtering() { " // BUG: Diagnostic contains:", " @Foo({\"b\", \"a\"})", " A fooValue();", + "", " // BUG: Diagnostic contains:", " @Foo(value2 = {\"b\", \"a\"})", " A fooValue2();", "", " @Bar({\"b\", \"a\"})", " A barValue();", + "", " // BUG: Diagnostic contains:", " @Bar(value2 = {\"b\", \"a\"})", " A barValue2();", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListingTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListingTest.java index dd9722e77a..e485715754 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListingTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListingTest.java @@ -52,6 +52,7 @@ void identification() { " @Foo", " @Bar", " A unsortedSimpleCase();", + "", " // BUG: Diagnostic contains:", " @Foo()", " @Bar()", @@ -69,6 +70,7 @@ void identification() { " @Baz", " @Bar", " A threeUnsortedAnnotationsSameInitialLetter();", + "", " // BUG: Diagnostic contains:", " @Bar", " @Foo()", @@ -84,11 +86,13 @@ void identification() { " @Foo({\"b\"})", " @Bar({\"a\"})", " A unsortedWithStringAttributes();", + "", " // BUG: Diagnostic contains:", " @Baz(str = {\"a\", \"b\"})", " @Foo(ints = {1, 0})", " @Bar", " A unsortedWithAttributes();", + "", " // BUG: Diagnostic contains:", " @Bar", " @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})", @@ -104,6 +108,7 @@ void identification() { " @Foo(ints = {1, 2})", " @Foo({\"b\"})", " A sortedRepeatableAnnotation();", + "", " // BUG: Diagnostic contains:", " @Foo(anns = {@Bar(\"b\"), @Bar(\"a\")})", " @Bar", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotationTest.java index b28562c0a4..d0ae0c49ca 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotationTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotationTest.java @@ -32,18 +32,23 @@ void identification() { "", " @RequestMapping(method = {})", " A explicitDefault();", + "", " // BUG: Diagnostic contains:", " @RequestMapping(method = RequestMethod.GET)", " A get();", + "", " // BUG: Diagnostic contains:", " @RequestMapping(method = {RequestMethod.POST})", " A post();", + "", " // BUG: Diagnostic contains:", " @RequestMapping(method = {PUT})", " A put();", + "", " // BUG: Diagnostic contains:", " @RequestMapping(method = {DELETE})", " A delete();", + "", " // BUG: Diagnostic contains:", " @RequestMapping(method = {PATCH})", " A patch();", diff --git a/pom.xml b/pom.xml index 1956c48e70..b6ded400e2 100644 --- a/pom.xml +++ b/pom.xml @@ -295,7 +295,7 @@ com.google.googlejavaformat google-java-format - 1.16.0 + 1.17.0 From bb122388f50454da84ee892e09682fc0fe128293 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Thu, 4 May 2023 10:02:03 +0200 Subject: [PATCH 306/601] [maven-release-plugin] prepare release v0.10.0 --- documentation-support/pom.xml | 2 +- error-prone-contrib/pom.xml | 2 +- pom.xml | 6 +++--- refaster-compiler/pom.xml | 2 +- refaster-runner/pom.xml | 2 +- refaster-support/pom.xml | 2 +- refaster-test-support/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/documentation-support/pom.xml b/documentation-support/pom.xml index 45d86c6333..d61ae10507 100644 --- a/documentation-support/pom.xml +++ b/documentation-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.9.1-SNAPSHOT + 0.10.0 documentation-support diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index b0128801e7..9d948c5675 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.9.1-SNAPSHOT + 0.10.0 error-prone-contrib diff --git a/pom.xml b/pom.xml index b6ded400e2..4b8d05bcd9 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ tech.picnic.error-prone-support error-prone-support - 0.9.1-SNAPSHOT + 0.10.0 pom Picnic :: Error Prone Support @@ -49,7 +49,7 @@ scm:git:git@github.com:PicnicSupermarket/error-prone-support.git - HEAD + v0.10.0 https://github.com/PicnicSupermarket/error-prone-support @@ -141,7 +141,7 @@ com.google.errorprone - 2023-03-31T07:31:01Z + 2023-05-04T07:57:55Z UTF-8 - 2023-05-04T07:57:55Z + 2023-05-04T10:47:27Z UTF-8 + + org.aopalliance.* + + true @@ -1700,10 +1716,6 @@ -Xep:BetaApi:OFF - - -Xep:InjectOnBugCheckers:OFF -Xep:Java7ApiChecker:OFF @@ -1724,6 +1736,8 @@ -XepOpt:NullAway:AssertsEnabled=true -XepOpt:NullAway:CheckOptionalEmptiness=true -XepOpt:Nullness:Conservative=false + -XepOpt:StatementSwitchToExpressionSwitch:EnableAssignmentSwitchConversion=true + -XepOpt:StatementSwitchToExpressionSwitch:EnableReturnSwitchConversion=true - 2023-05-04T10:47:27Z + 2023-05-14T15:07:55Z UTF-8 - 2023-05-14T15:07:55Z + 2023-05-14T15:09:08Z UTF-8 - 2023-05-14T15:09:08Z + 2023-05-16T15:37:41Z UTF-8 - 2023-05-16T15:37:41Z + 2023-05-16T15:38:46Z UTF-8 - 1.0.1 + 1.1.0 1.10.1 ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 From 04e2900a48b7f93a75a4d918e066921b32d4a61c Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 24 May 2023 16:00:11 +0200 Subject: [PATCH 331/601] Upgrade git-commit-id-maven-plugin 5.0.0 -> 6.0.0 (#635) See: - https://github.com/git-commit-id/git-commit-id-maven-plugin/releases/tag/v6.0.0 - https://github.com/git-commit-id/git-commit-id-maven-plugin/compare/v5.0.0...v6.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 80bf2ed202..93dac6b444 100644 --- a/pom.xml +++ b/pom.xml @@ -570,7 +570,7 @@ io.github.git-commit-id git-commit-id-maven-plugin - 5.0.0 + 6.0.0 true true From da532c79c76055f3e2ce470eb4067e277758a7ea Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 24 May 2023 16:10:58 +0200 Subject: [PATCH 332/601] Upgrade Pitest Git plugins 1.0.10 -> 1.0.11 (#634) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 93dac6b444..8b621543cb 100644 --- a/pom.xml +++ b/pom.xml @@ -209,7 +209,7 @@ 5.3.1 1.0.1 0.10.10 - 1.0.10 + 1.0.11 3.1.0 From d0bbc5c14b9efd1664324a242f0beb695ae6545e Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 24 May 2023 16:30:06 +0200 Subject: [PATCH 333/601] Upgrade pitest-maven-plugin 1.13.1 -> 1.14.0 (#633) See: - https://github.com/hcoles/pitest/releases/tag/1.13.2 - https://github.com/hcoles/pitest/releases/tag/1.14.0 - https://github.com/hcoles/pitest/compare/1.13.1...1.14.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8b621543cb..cc81ca0f5a 100644 --- a/pom.xml +++ b/pom.xml @@ -1356,7 +1356,7 @@ org.pitest pitest-maven - 1.13.1 + 1.14.0 From da1528129fe01513f33d72ffbacebf381bcc71e0 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 24 May 2023 17:08:20 +0200 Subject: [PATCH 334/601] Upgrade maven-source-plugin 3.2.1 -> 3.3.0 (#643) See: - https://issues.apache.org/jira/issues/?jql=project%20%3D%20MSOURCES%20AND%20fixVersion%20%3E%203.2.1%20AND%20fixVersion%20%3C%3D%203.3.0 - https://github.com/apache/maven-source-plugin/compare/maven-source-plugin-3.2.1...maven-source-plugin-3.3.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cc81ca0f5a..1895e5cebe 100644 --- a/pom.xml +++ b/pom.xml @@ -1168,7 +1168,7 @@ org.apache.maven.plugins maven-source-plugin - 3.2.1 + 3.3.0 generate-source-jar From 7dba641a79bce0c17e85b175227dcadcbe03eaa3 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 24 May 2023 17:20:57 +0200 Subject: [PATCH 335/601] Upgrade pitest-junit5-plugin 1.1.2 -> 1.2.0 (#638) See https://github.com/pitest/pitest-junit5-plugin/compare/1.1.2...1.2.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1895e5cebe..8534a1781f 100644 --- a/pom.xml +++ b/pom.xml @@ -1395,7 +1395,7 @@ org.pitest pitest-junit5-plugin - 1.1.2 + 1.2.0 From b399ef89107c1d0cf8fc2e76b965a2fa22241a78 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 24 May 2023 19:03:38 +0200 Subject: [PATCH 336/601] Upgrade Spring Boot 2.7.11 -> 2.7.12 (#637) See: - https://github.com/spring-projects/spring-boot/releases/tag/v2.7.12 - https://github.com/spring-projects/spring-boot/compare/v2.7.11...v2.7.12 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8534a1781f..b8c16357cf 100644 --- a/pom.xml +++ b/pom.xml @@ -458,7 +458,7 @@ org.springframework.boot spring-boot-test - 2.7.11 + 2.7.12 org.testng From 8bc878a05ce91e2213cd4c80d1a7e467ad0fa688 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Fri, 26 May 2023 08:29:26 +0200 Subject: [PATCH 337/601] Improve `AbstractMatcherTestChecker` (#599) These changes enable testing of a wider range of `Matcher` implementations. In a nutshell: - The `Matcher` under test is now passed `VisitorState` instances with an accurate `TreePath`. - The `Matcher` under test is no longer consulted for method select and cast type expressions, mirroring Refaster behavior. --- .../matchers/AbstractMatcherTestChecker.java | 57 ++++++++++++++++--- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java index c0361ab6e3..48fac2d44f 100644 --- a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java +++ b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java @@ -8,8 +8,11 @@ import com.sun.source.tree.CompilationUnitTree; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.ImportTree; +import com.sun.source.tree.MethodInvocationTree; import com.sun.source.tree.MethodTree; import com.sun.source.tree.Tree; +import com.sun.source.tree.TypeCastTree; +import com.sun.source.util.TreePath; import com.sun.source.util.TreeScanner; import org.jspecify.annotations.Nullable; @@ -31,18 +34,27 @@ abstract class AbstractMatcherTestChecker extends BugChecker implements Compilat @Override public Description matchCompilationUnit(CompilationUnitTree compilationUnit, VisitorState state) { - new TreeScanner<@Nullable Void, @Nullable Void>() { + new TreeScanner<@Nullable Void, TreePath>() { @Override - public @Nullable Void scan(Tree tree, @Nullable Void unused) { - if (tree instanceof ExpressionTree && delegate.matches((ExpressionTree) tree, state)) { - state.reportMatch(describeMatch(tree)); + public @Nullable Void scan(@Nullable Tree tree, TreePath treePath) { + if (tree == null) { + return null; } - return super.scan(tree, unused); + TreePath path = new TreePath(treePath, tree); + if (tree instanceof ExpressionTree) { + ExpressionTree expressionTree = (ExpressionTree) tree; + if (!isMethodSelect(expressionTree, path) + && delegate.matches(expressionTree, state.withPath(path))) { + state.reportMatch(describeMatch(tree)); + } + } + + return super.scan(tree, path); } @Override - public @Nullable Void visitImport(ImportTree node, @Nullable Void unused) { + public @Nullable Void visitImport(ImportTree tree, TreePath path) { /* * We're not interested in matching import statements. While components of these * can be `ExpressionTree`s, they will never be matched by Refaster. @@ -51,15 +63,42 @@ public Description matchCompilationUnit(CompilationUnitTree compilationUnit, Vis } @Override - public @Nullable Void visitMethod(MethodTree node, @Nullable Void unused) { + public @Nullable Void visitMethod(MethodTree tree, TreePath path) { /* * We're not interested in matching e.g. parameter and return type declarations. While these * can be `ExpressionTree`s, they will never be matched by Refaster. */ - return scan(node.getBody(), unused); + return scan(tree.getBody(), new TreePath(path, tree)); + } + + @Override + public @Nullable Void visitTypeCast(TypeCastTree tree, TreePath path) { + /* + * We're not interested in matching the parenthesized type subtree that is part of a type + * cast expression. While such trees can be `ExpressionTree`s, they will never be matched by + * Refaster. + */ + return scan(tree.getExpression(), new TreePath(path, tree)); } - }.scan(compilationUnit, null); + }.scan(compilationUnit, state.getPath()); return Description.NO_MATCH; } + + /** + * Tells whether the given {@link ExpressionTree} is the {@link + * MethodInvocationTree#getMethodSelect() method select} portion of a method invocation. + * + *

Such {@link ExpressionTree}s will never be matched by Refaster. + */ + private static boolean isMethodSelect(ExpressionTree tree, TreePath path) { + TreePath parentPath = path.getParentPath(); + if (parentPath == null) { + return false; + } + + Tree parentTree = parentPath.getLeaf(); + return parentTree instanceof MethodInvocationTree + && ((MethodInvocationTree) parentTree).getMethodSelect().equals(tree); + } } From cc2c49edc32e83d999bbddcac1db5caa9d45c0fb Mon Sep 17 00:00:00 2001 From: Luke Prananta Date: Fri, 26 May 2023 09:19:51 +0200 Subject: [PATCH 338/601] Introduce `OptionalOrElseGet` Refaster rule (#527) While there, introduce `IsLikelyTrivialComputation` Matcher. --- .../refasterrules/OptionalRules.java | 32 +++- .../refasterrules/OptionalRulesTestInput.java | 7 + .../OptionalRulesTestOutput.java | 7 + .../matchers/IsLikelyTrivialComputation.java | 92 +++++++++++ .../IsLikelyTrivialComputationTest.java | 147 ++++++++++++++++++ 5 files changed, 283 insertions(+), 2 deletions(-) create mode 100644 refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsLikelyTrivialComputation.java create mode 100644 refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/IsLikelyTrivialComputationTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java index 86fbe12501..2a84eaf419 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/OptionalRules.java @@ -8,6 +8,7 @@ import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; import com.google.errorprone.refaster.annotation.MayOptionallyUse; +import com.google.errorprone.refaster.annotation.NotMatches; import com.google.errorprone.refaster.annotation.Placeholder; import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Comparator; @@ -19,6 +20,7 @@ import java.util.stream.Stream; import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; +import tech.picnic.errorprone.refaster.matchers.IsLikelyTrivialComputation; /** Refaster rules related to expressions dealing with {@link Optional}s. */ @OnlineDocumentation @@ -118,7 +120,7 @@ Optional after(Iterator it) { /** Prefer {@link Optional#filter(Predicate)} over usage of the ternary operator. */ // XXX: This rule may introduce a compilation error: the `test` expression may reference a // non-effectively final variable, which is not allowed in the replacement lambda expression. - // Maybe our `Refaster` checker should test `compilesWithFix`? + // Review whether a `@Matcher` can be used to avoid this. abstract static class TernaryOperatorOptionalPositiveFiltering { @Placeholder abstract boolean test(T value); @@ -138,7 +140,7 @@ Optional after(T input) { /** Prefer {@link Optional#filter(Predicate)} over usage of the ternary operator. */ // XXX: This rule may introduce a compilation error: the `test` expression may reference a // non-effectively final variable, which is not allowed in the replacement lambda expression. - // Maybe our `Refaster` checker should test `compilesWithFix`? + // Review whether a `@Matcher` can be used to avoid this. abstract static class TernaryOperatorOptionalNegativeFiltering { @Placeholder abstract boolean test(T value); @@ -161,6 +163,7 @@ Optional after(T input) { */ static final class MapOptionalToBoolean { @BeforeTemplate + @SuppressWarnings("OptionalOrElseGet" /* Rule is confused by `Refaster#anyOf` usage. */) boolean before(Optional optional, Function predicate) { return optional.map(predicate).orElse(Refaster.anyOf(false, Boolean.FALSE)); } @@ -224,6 +227,28 @@ T after(Optional o1, Optional o2) { } } + /** + * Prefer {@link Optional#orElseGet(Supplier)} over {@link Optional#orElse(Object)} if the + * fallback value is not the result of a trivial computation. + */ + // XXX: This rule may introduce a compilation error: the `value` expression may reference a + // non-effectively final variable, which is not allowed in the replacement lambda expression. + // Review whether a `@Matcher` can be used to avoid this. + // XXX: Once `MethodReferenceUsage` is "production ready", replace + // `@NotMatches(IsLikelyTrivialComputation.class)` with `@Matches(RequiresComputation.class)` (and + // reimplement the matcher accordingly). + static final class OptionalOrElseGet { + @BeforeTemplate + T before(Optional optional, @NotMatches(IsLikelyTrivialComputation.class) T value) { + return optional.orElse(value); + } + + @AfterTemplate + T after(Optional optional, T value) { + return optional.orElseGet(() -> value); + } + } + /** * Flatten a stream of {@link Optional}s using {@link Optional#stream()}, rather than using one of * the more verbose alternatives. @@ -325,6 +350,9 @@ static final class OptionalOrOtherOptional { Optional before(Optional optional1, Optional optional2) { // XXX: Note that rewriting the first and third variant will change the code's behavior if // `optional2` has side-effects. + // XXX: Note that rewriting the first and third variant will introduce a compilation error if + // `optional2` is not effectively final. Review whether a `@Matcher` can be used to avoid + // this. return Refaster.anyOf( optional1.map(Optional::of).orElse(optional2), optional1.map(Optional::of).orElseGet(() -> optional2), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestInput.java index 16c4d856c7..979717fcfd 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestInput.java @@ -119,4 +119,11 @@ ImmutableSet> testOptionalFilter() { Optional testOptionalMap() { return Optional.of(1).stream().map(String::valueOf).findAny(); } + + ImmutableSet testOptionalOrElseGet() { + return ImmutableSet.of( + Optional.of("foo").orElse("bar"), + Optional.of("baz").orElse(toString()), + Optional.of("qux").orElse(String.valueOf(true))); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestOutput.java index a24fb5e8f9..cafc70cfa3 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/OptionalRulesTestOutput.java @@ -112,4 +112,11 @@ ImmutableSet> testOptionalFilter() { Optional testOptionalMap() { return Optional.of(1).map(String::valueOf); } + + ImmutableSet testOptionalOrElseGet() { + return ImmutableSet.of( + Optional.of("foo").orElse("bar"), + Optional.of("baz").orElse(toString()), + Optional.of("qux").orElseGet(() -> String.valueOf(true))); + } } diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsLikelyTrivialComputation.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsLikelyTrivialComputation.java new file mode 100644 index 0000000000..9cfa30b511 --- /dev/null +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsLikelyTrivialComputation.java @@ -0,0 +1,92 @@ +package tech.picnic.errorprone.refaster.matchers; + +import com.google.errorprone.VisitorState; +import com.google.errorprone.matchers.Matcher; +import com.sun.source.tree.ArrayAccessTree; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.IdentifierTree; +import com.sun.source.tree.LambdaExpressionTree; +import com.sun.source.tree.LiteralTree; +import com.sun.source.tree.MemberReferenceTree; +import com.sun.source.tree.MemberSelectTree; +import com.sun.source.tree.MethodInvocationTree; +import com.sun.source.tree.ParenthesizedTree; +import com.sun.source.tree.TypeCastTree; +import com.sun.source.tree.UnaryTree; + +/** A matcher of expressions that likely require little to no computation. */ +public final class IsLikelyTrivialComputation implements Matcher { + private static final long serialVersionUID = 1L; + + /** Instantiates a new {@link IsLikelyTrivialComputation} instance. */ + public IsLikelyTrivialComputation() {} + + @Override + public boolean matches(ExpressionTree expressionTree, VisitorState state) { + if (expressionTree instanceof MethodInvocationTree) { + // XXX: Method invocations are generally *not* trivial computations, but we make an exception + // for nullary method invocations on the result of a trivial computation. This exception + // allows this `Matcher` to by the `OptionalOrElseGet` Refaster rule, such that it does not + // suggest the introduction of lambda expressions that are better expressed as method + // references. Once the `MethodReferenceUsage` bug checker is production-ready, this exception + // should be removed. (But at that point, instead defining a `RequiresComputation` matcher may + // be more appropriate.) + MethodInvocationTree methodInvocation = (MethodInvocationTree) expressionTree; + if (methodInvocation.getArguments().isEmpty() + && matches(methodInvocation.getMethodSelect())) { + return true; + } + } + + return matches(expressionTree); + } + + // XXX: Some `BinaryTree`s may represent what could be considered "trivial computations". + // Depending on feedback such trees may be matched in the future. + private static boolean matches(ExpressionTree expressionTree) { + if (expressionTree instanceof ArrayAccessTree) { + return matches(((ArrayAccessTree) expressionTree).getExpression()) + && matches(((ArrayAccessTree) expressionTree).getIndex()); + } + + if (expressionTree instanceof LiteralTree) { + return true; + } + + if (expressionTree instanceof LambdaExpressionTree) { + /* + * Lambda expressions encapsulate computations, but their definition does not involve + * significant computation. + */ + return true; + } + + if (expressionTree instanceof IdentifierTree) { + return true; + } + + if (expressionTree instanceof MemberReferenceTree) { + return matches(((MemberReferenceTree) expressionTree).getQualifierExpression()); + } + + if (expressionTree instanceof MemberSelectTree) { + return matches(((MemberSelectTree) expressionTree).getExpression()); + } + + if (expressionTree instanceof ParenthesizedTree) { + return matches(((ParenthesizedTree) expressionTree).getExpression()); + } + + if (expressionTree instanceof TypeCastTree) { + return matches(((TypeCastTree) expressionTree).getExpression()); + } + + if (expressionTree instanceof UnaryTree) { + // XXX: Arguably side-effectful options such as pre- and post-increment and -decrement are not + // trivial. + return matches(((UnaryTree) expressionTree).getExpression()); + } + + return false; + } +} diff --git a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/IsLikelyTrivialComputationTest.java b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/IsLikelyTrivialComputationTest.java new file mode 100644 index 0000000000..a140e7248f --- /dev/null +++ b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/IsLikelyTrivialComputationTest.java @@ -0,0 +1,147 @@ +package tech.picnic.errorprone.refaster.matchers; + +import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; + +import com.google.errorprone.BugPattern; +import com.google.errorprone.CompilationTestHelper; +import com.google.errorprone.bugpatterns.BugChecker; +import com.sun.source.tree.ReturnTree; +import org.junit.jupiter.api.Test; + +final class IsLikelyTrivialComputationTest { + @Test + void matches() { + CompilationTestHelper.newInstance(MatcherTestChecker.class, getClass()) + .addSourceLines( + "A.java", + "import java.util.function.Predicate;", + "", + "class A {", + " String negative1() {", + " return String.valueOf(1);", + " }", + "", + " String negative2() {", + " return toString().toString();", + " }", + "", + " String negative3() {", + " return \"foo\" + toString();", + " }", + "", + " byte negative4() {", + " return \"foo\".getBytes()[0];", + " }", + "", + " int negative5() {", + " int[] arr = new int[0];", + " return arr[hashCode()];", + " }", + "", + " int negative6() {", + " return 1 * 2;", + " }", + "", + " Predicate negative7() {", + " return toString()::equals;", + " }", + "", + " String negative8() {", + " return (toString());", + " }", + "", + " Object negative9() {", + " return (Object) toString();", + " }", + "", + " int negative10() {", + " return -hashCode();", + " }", + "", + " String positive1() {", + " // BUG: Diagnostic contains:", + " return toString();", + " }", + "", + " String positive2() {", + " // BUG: Diagnostic contains:", + " return this.toString();", + " }", + "", + " int positive3() {", + " int[] arr = new int[0];", + " // BUG: Diagnostic contains:", + " return arr[0];", + " }", + "", + " String positive4() {", + " // BUG: Diagnostic contains:", + " return null;", + " }", + "", + " boolean positive5() {", + " // BUG: Diagnostic contains:", + " return false;", + " }", + "", + " int positive6() {", + " // BUG: Diagnostic contains:", + " return 0;", + " }", + "", + " String positive7() {", + " // BUG: Diagnostic contains:", + " return \"foo\" + \"bar\";", + " }", + "", + " Predicate positive8() {", + " // BUG: Diagnostic contains:", + " return v -> \"foo\".equals(v);", + " }", + "", + " A positive9() {", + " // BUG: Diagnostic contains:", + " return this;", + " }", + "", + " Predicate positive10() {", + " // BUG: Diagnostic contains:", + " return \"foo\"::equals;", + " }", + "", + " A positive11() {", + " // BUG: Diagnostic contains:", + " return (this);", + " }", + "", + " Object positive12() {", + " // BUG: Diagnostic contains:", + " return (Object) this;", + " }", + "", + " boolean positive13() {", + " // BUG: Diagnostic contains:", + " return !false;", + " }", + "}") + .doTest(); + } + + /** A {@link BugChecker} that simply delegates to {@link IsLikelyTrivialComputation}. */ + @BugPattern( + summary = "Flags return statement expressions matched by `IsLikelyTrivialComputation`", + severity = ERROR) + public static final class MatcherTestChecker extends AbstractMatcherTestChecker { + private static final long serialVersionUID = 1L; + + // XXX: This is a false positive reported by Checkstyle. See + // https://github.com/checkstyle/checkstyle/issues/10161#issuecomment-1242732120. + @SuppressWarnings("RedundantModifier") + public MatcherTestChecker() { + super( + (expressionTree, state) -> + state.getPath().getParentPath().getLeaf() instanceof ReturnTree + && new IsLikelyTrivialComputation().matches(expressionTree, state)); + } + } +} From ea02144bff25069a7ebfa92ad576c3b1c8e615b9 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 26 May 2023 10:13:47 +0200 Subject: [PATCH 339/601] Upgrade pitest-maven-plugin 1.14.0 -> 1.14.1 (#648) See: - https://github.com/hcoles/pitest/releases/tag/1.14.1 - https://github.com/hcoles/pitest/compare/1.14.0...1.14.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b8c16357cf..8f7c63852b 100644 --- a/pom.xml +++ b/pom.xml @@ -1356,7 +1356,7 @@ org.pitest pitest-maven - 1.14.0 + 1.14.1 From 125d24bc131d4291f65d7047c06610cd5316bd5e Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 30 May 2023 08:44:15 +0200 Subject: [PATCH 340/601] Upgrade Checkstyle 10.11.0 -> 10.12.0 (#651) See: - https://checkstyle.sourceforge.io/releasenotes.html - https://github.com/checkstyle/checkstyle/releases/tag/checkstyle-10.12.0 - https://github.com/checkstyle/checkstyle/compare/checkstyle-10.11.0...checkstyle-10.12.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8f7c63852b..54fa78cb1f 100644 --- a/pom.xml +++ b/pom.xml @@ -839,7 +839,7 @@ com.puppycrawl.tools checkstyle - 10.11.0 + 10.12.0 io.spring.nohttp From 5085db25c091bee841080532e32bed1bfb35c0e2 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 30 May 2023 16:49:11 +0200 Subject: [PATCH 341/601] Upgrade Guava 31.1-jre -> 32.0.0-jre (#650) See: - https://guava.dev/releases/32.0.0-jre/api/diffs/ - https://github.com/google/guava/releases/tag/v32.0.0 - https://github.com/google/guava/compare/v31.1...v32.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 54fa78cb1f..f029a2b19c 100644 --- a/pom.xml +++ b/pom.xml @@ -307,7 +307,7 @@ com.google.guava guava-bom - 31.1-jre + 32.0.0-jre pom import From 49e5fd127303e4fdafb140508588ad673e9db783 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 6 Jun 2023 07:20:46 +0200 Subject: [PATCH 342/601] Upgrade extra-enforcer-rules 1.6.2 -> 1.7.0 (#661) See: - https://github.com/mojohaus/extra-enforcer-rules/releases/tag/1.7.0 - https://github.com/mojohaus/extra-enforcer-rules/compare/1.6.2...1.7.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f029a2b19c..2970922608 100644 --- a/pom.xml +++ b/pom.xml @@ -1051,7 +1051,7 @@ org.codehaus.mojo extra-enforcer-rules - 1.6.2 + 1.7.0 From cdf27acd9cd1542f930090c4d2218d97dc2a5ef9 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 6 Jun 2023 07:40:05 +0200 Subject: [PATCH 343/601] Upgrade Checker Framework Annotations 3.34.0 -> 3.35.0 (#660) See: - https://github.com/typetools/checker-framework/releases/tag/checker-framework-3.35.0 - https://github.com/typetools/checker-framework/compare/checker-framework-3.34.0...checker-framework-3.35.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2970922608..741c6c3966 100644 --- a/pom.xml +++ b/pom.xml @@ -412,7 +412,7 @@ org.checkerframework checker-qual - 3.34.0 + 3.35.0 org.hamcrest From ce8f9f60c853881726fcc059dc4b5f7fdcd76098 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 6 Jun 2023 07:50:01 +0200 Subject: [PATCH 344/601] Upgrade New Relic Java Agent 8.2.0 -> 8.3.0 (#659) See: - https://github.com/newrelic/newrelic-java-agent/releases/tag/v8.3.0 - https://github.com/newrelic/newrelic-java-agent/compare/v8.2.0...v8.3.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 741c6c3966..6995971bc0 100644 --- a/pom.xml +++ b/pom.xml @@ -326,7 +326,7 @@ com.newrelic.agent.java newrelic-api - 8.2.0 + 8.3.0 From c6b98e61ff261293f1125c3335af4f0bcc5c3fd4 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 6 Jun 2023 08:34:35 +0200 Subject: [PATCH 345/601] Upgrade maven-release-plugin 3.0.0 -> 3.0.1 (#662) See: - https://issues.apache.org/jira/issues/?jql=project%20%3D%20MRELEASE%20AND%20fixVersion%20%3E%203.0.0%20AND%20fixVersion%20%3C%3D%203.0.1 - https://github.com/apache/maven-release/releases/tag/maven-release-3.0.1 - https://github.com/apache/maven-release/compare/maven-release-3.0.0...maven-release-3.0.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6995971bc0..e9d4506fbd 100644 --- a/pom.xml +++ b/pom.xml @@ -1141,7 +1141,7 @@ org.apache.maven.plugins maven-release-plugin - 3.0.0 + 3.0.1 true release From 7371d03db80eed103a14316a746fc258ffedff16 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 6 Jun 2023 09:47:09 +0200 Subject: [PATCH 346/601] Upgrade Truth 1.1.3 -> 1.1.4 (#653) See: - https://github.com/google/truth/releases/tag/v1.1.4 - https://github.com/google/truth/compare/release_1_1_3...v1.1.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e9d4506fbd..71ccea7e6e 100644 --- a/pom.xml +++ b/pom.xml @@ -314,7 +314,7 @@ com.google.truth truth - 1.1.3 + 1.1.4 From 80dcae319e889e500e4839732ce1d469993161a9 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 6 Jun 2023 16:30:09 +0200 Subject: [PATCH 347/601] Upgrade Jackson 2.15.1 -> 2.15.2 (#652) See: - https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.15.2 - https://github.com/FasterXML/jackson-bom/compare/jackson-bom-2.15.1...jackson-bom-2.15.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 71ccea7e6e..2ea43965ed 100644 --- a/pom.xml +++ b/pom.xml @@ -268,7 +268,7 @@ com.fasterxml.jackson jackson-bom - 2.15.1 + 2.15.2 pom import From 93440826ed347633c392e0566cc7e93fe257fdf8 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 7 Jun 2023 08:02:44 +0200 Subject: [PATCH 348/601] Upgrade Arcmutate 1.0.4 -> 1.0.5 (#656) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2ea43965ed..ba4de38510 100644 --- a/pom.xml +++ b/pom.xml @@ -1385,7 +1385,7 @@ com.groupcdg.arcmutate base - 1.0.4 + 1.0.5 com.groupcdg.pitest From f5a8c412afaaad6abe60749326ba0dd30fe04409 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 7 Jun 2023 10:48:54 +0200 Subject: [PATCH 349/601] Upgrade Byte Buddy 1.14.4 -> 1.14.5 (#658) See: - https://github.com/raphw/byte-buddy/releases/tag/byte-buddy-1.14.5 - https://github.com/raphw/byte-buddy/compare/byte-buddy-1.14.4...byte-buddy-1.14.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ba4de38510..6fbb64c5fa 100644 --- a/pom.xml +++ b/pom.xml @@ -387,7 +387,7 @@ net.bytebuddy byte-buddy - 1.14.4 + 1.14.5 - 1.1.0 + 1.1.1 1.10.1 ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 From 57a22bf9de27d636fdc2a8fa4642b5e0d9a68356 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 16 Jun 2023 15:12:15 +0200 Subject: [PATCH 357/601] Upgrade Swagger 2.2.11 -> 2.2.12 (#684) See: - https://github.com/swagger-api/swagger-core/releases/tag/v2.2.12 - https://github.com/swagger-api/swagger-core/compare/v2.2.11...v2.2.12 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 47a419bb87..53f2c3b6ae 100644 --- a/pom.xml +++ b/pom.xml @@ -355,7 +355,7 @@ io.swagger.core.v3 swagger-annotations - 2.2.11 + 2.2.12 jakarta.servlet From c40e1d6691ad5e654263826db583ccbd8b5e584a Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 16 Jun 2023 15:35:04 +0200 Subject: [PATCH 358/601] Upgrade actions/setup-java v3.8.0 -> v3.11.0 (#668) See: - https://github.com/actions/setup-java/releases/tag/v3.9.0 - https://github.com/actions/setup-java/releases/tag/v3.10.0 - https://github.com/actions/setup-java/releases/tag/v3.11.0 --- .github/workflows/build.yaml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/pitest-update-pr.yml | 2 +- .github/workflows/sonarcloud.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index e9fd28307c..72bd75339a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -35,7 +35,7 @@ jobs: with: persist-credentials: false - name: Set up JDK - uses: actions/setup-java@v3.8.0 + uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 with: java-version: ${{ matrix.jdk }} distribution: ${{ matrix.distribution }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 9456ab1700..c71c074d1c 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -26,7 +26,7 @@ jobs: with: persist-credentials: false - name: Set up JDK - uses: actions/setup-java@v3.8.0 + uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 with: java-version: 17.0.7 distribution: temurin diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index 5a14fa2ae9..51ae07d3b7 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -17,7 +17,7 @@ jobs: fetch-depth: 2 persist-credentials: false - name: Set up JDK - uses: actions/setup-java@v3.8.0 + uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 with: java-version: 17.0.7 distribution: temurin diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index cbaae60813..c7ca04c8f9 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -24,7 +24,7 @@ jobs: with: persist-credentials: false - name: Set up JDK - uses: actions/setup-java@v3.8.0 + uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 with: java-version: 17.0.7 distribution: temurin diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 5df6b84646..ec7807efe4 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -21,7 +21,7 @@ jobs: fetch-depth: 0 persist-credentials: false - name: Set up JDK - uses: actions/setup-java@v3.8.0 + uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 with: java-version: 17.0.7 distribution: temurin From a62acfd7b5ef5503fe0256a46c33c261a806ecb0 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 16 Jun 2023 16:16:06 +0200 Subject: [PATCH 359/601] Upgrade Project Reactor 2022.0.7 -> 2022.0.8 (#683) See: - https://github.com/reactor/reactor/releases/tag/2022.0.8 - https://github.com/reactor/reactor/compare/2022.0.7...2022.0.8 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 53f2c3b6ae..acd2b3524d 100644 --- a/pom.xml +++ b/pom.xml @@ -338,7 +338,7 @@ io.projectreactor reactor-bom - 2022.0.7 + 2022.0.8 pom import From 524c7efb48d778d3ae0e143addd56360b9b8d188 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 19 Jun 2023 08:56:31 +0200 Subject: [PATCH 360/601] Upgrade actions/deploy-pages v1.2.3 -> v1.2.8 (#663) See: - https://github.com/actions/deploy-pages/releases/tag/v1.2.8 - https://github.com/actions/deploy-pages/releases/tag/v1.2.7 - https://github.com/actions/deploy-pages/releases/tag/v1.2.6 - https://github.com/actions/deploy-pages/releases/tag/v1.2.5 - https://github.com/actions/deploy-pages/releases/tag/v1.2.4 --- .github/workflows/deploy-website.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index a17d1a0bdd..119ef1fcdf 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -48,4 +48,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@v1.2.3 + uses: actions/deploy-pages@dcda0bb2bcba68842abb9414982734cde54a96d8 # v1.2.8 From d29fde885650dae7a0d654909a2801fbd2a547f9 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 19 Jun 2023 09:18:01 +0200 Subject: [PATCH 361/601] Upgrade actions/checkout v3.1.0 -> v3.5.3 (#667) See: - https://github.com/actions/checkout/blob/HEAD/CHANGELOG.md#v353 - https://github.com/actions/checkout/blob/HEAD/CHANGELOG.md#v352 - https://github.com/actions/checkout/blob/HEAD/CHANGELOG.md#v351 - https://github.com/actions/checkout/blob/HEAD/CHANGELOG.md#v350 - https://github.com/actions/checkout/blob/HEAD/CHANGELOG.md#v340 - https://github.com/actions/checkout/blob/HEAD/CHANGELOG.md#v330 - https://github.com/actions/checkout/blob/HEAD/CHANGELOG.md#v320 --- .github/workflows/build.yaml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/deploy-website.yaml | 2 +- .github/workflows/openssf-scorecard.yml | 2 +- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/pitest-update-pr.yml | 2 +- .github/workflows/sonarcloud.yml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 72bd75339a..04559e4caf 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -31,7 +31,7 @@ jobs: # additionally enabling all checks defined in this project and any Error # Prone checks available only from other artifact repositories. - name: Check out code - uses: actions/checkout@v3.1.0 + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 with: persist-credentials: false - name: Set up JDK diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index c71c074d1c..66bda1395b 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@v3.1.0 + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 with: persist-credentials: false - name: Set up JDK diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index 119ef1fcdf..bd6796b16b 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@v3.1.0 + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 with: persist-credentials: false - uses: ruby/setup-ruby@v1.126.0 diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index 202e8c170d..1961745a02 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@v3.1.0 + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 with: persist-credentials: false - name: Run OpenSSF Scorecard analysis diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index 51ae07d3b7..6f8b764902 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@v3.1.0 + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 with: fetch-depth: 2 persist-credentials: false diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index c7ca04c8f9..48e05eab59 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@v3.1.0 + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 with: persist-credentials: false - name: Set up JDK diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index ec7807efe4..606f114c04 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@v3.1.0 + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 with: fetch-depth: 0 persist-credentials: false From ef0d65d3608a52e9a0624a149c04e266704360e2 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 19 Jun 2023 11:01:54 +0200 Subject: [PATCH 362/601] Upgrade actions/deploy-pages v1.2.8 -> v2.0.2 (#674) See: - https://github.com/actions/deploy-pages/releases/tag/v2.0.2 - https://github.com/actions/deploy-pages/releases/tag/v2.0.1 - https://github.com/actions/deploy-pages/releases/tag/v2.0.0 --- .github/workflows/deploy-website.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index bd6796b16b..bd937b9bfb 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -48,4 +48,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@dcda0bb2bcba68842abb9414982734cde54a96d8 # v1.2.8 + uses: actions/deploy-pages@ee48c7b82e077d7b8ef30b50a719e6a792a50c9a # v2.0.2 From b2320779e75e8811476f3a7be12786cbc4a9cab4 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 19 Jun 2023 11:13:20 +0200 Subject: [PATCH 363/601] Upgrade actions/configure-pages v2.1.3 -> v3.0.6 (#673) See: - https://github.com/actions/configure-pages/releases/tag/v3.0.6 - https://github.com/actions/configure-pages/releases/tag/v3.0.5 - https://github.com/actions/configure-pages/releases/tag/v3.0.4 - https://github.com/actions/configure-pages/releases/tag/v3.0.3 - https://github.com/actions/configure-pages/releases/tag/v3.0.2 - https://github.com/actions/configure-pages/releases/tag/v3.0.1 - https://github.com/actions/configure-pages/releases/tag/v3.0.0 --- .github/workflows/deploy-website.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index bd937b9bfb..5f953370f2 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -20,7 +20,7 @@ jobs: working-directory: ./website bundler-cache: true - name: Configure Github Pages - uses: actions/configure-pages@v2.1.3 + uses: actions/configure-pages@f156874f8191504dae5b037505266ed5dda6c382 # v3.0.6 - name: Generate documentation run: ./generate-docs.sh - name: Build website with Jekyll From 2148b7ede4bd21fd5a72d6e10dc28c2c7605dad8 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 19 Jun 2023 11:30:48 +0200 Subject: [PATCH 364/601] Upgrade actions/upload-pages-artifact v1.0.5 -> v1.0.9 (#665) See: - https://github.com/actions/upload-pages-artifact/releases/tag/v1.0.9 - https://github.com/actions/upload-pages-artifact/releases/tag/v1.0.8 - https://github.com/actions/upload-pages-artifact/releases/tag/v1.0.7 - https://github.com/actions/upload-pages-artifact/releases/tag/v1.0.6 --- .github/workflows/deploy-website.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index 5f953370f2..5f91feb33f 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -32,7 +32,7 @@ jobs: # "Refaster rules" terminology on our website and in the code. run: bundle exec htmlproofer --disable_external true --check-external-hash false ./_site - name: Upload website as artifact - uses: actions/upload-pages-artifact@v1.0.5 + uses: actions/upload-pages-artifact@66b63f4a7de003f4f00cc8e9af4b83b8f2abdb96 # v1.0.9 with: path: ./website/_site deploy: From f4aaa5852c11a0b1e7eb553cfba315eda0e867fc Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 19 Jun 2023 11:54:34 +0200 Subject: [PATCH 365/601] Upgrade dawidd6/action-download-artifact v2.24.2 -> v2.27.0 (#669) See: - https://github.com/dawidd6/action-download-artifact/compare/v2.26.1...v2.27.0 - https://github.com/dawidd6/action-download-artifact/compare/v2.26.0...v2.26.1 - https://github.com/dawidd6/action-download-artifact/compare/v2.25.0...v2.26.0 - https://github.com/dawidd6/action-download-artifact/compare/v2.24.4...v2.25.0 - https://github.com/dawidd6/action-download-artifact/compare/v2.24.3...v2.24.4 - https://github.com/dawidd6/action-download-artifact/compare/v2.24.2...v2.24.3 --- .github/workflows/pitest-update-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index 48e05eab59..7655719f03 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -30,7 +30,7 @@ jobs: distribution: temurin cache: maven - name: Download Pitest analysis artifact - uses: dawidd6/action-download-artifact@v2.24.2 + uses: dawidd6/action-download-artifact@246dbf436b23d7c49e21a7ab8204ca9ecd1fe615 # v2.27.0 with: workflow: ${{ github.event.workflow_run.workflow_id }} name: pitest-reports From 8fb57b5bab44de3812f52a427f9d4eaa846fe8b7 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 20 Jun 2023 09:01:33 +0200 Subject: [PATCH 366/601] Upgrade actions/upload-artifact v3.1.1 -> v3.1.2 (#664) See: - https://github.com/actions/upload-artifact/releases/tag/v3.1.2 --- .github/workflows/pitest-analyze-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index 6f8b764902..6d18c0dbc0 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -32,7 +32,7 @@ jobs: - name: Aggregate Pitest reports run: mvn pitest-git:aggregate -DkilledEmoji=":tada:" -DmutantEmoji=":zombie:" -DtrailingText="Mutation testing report by [Pitest](https://pitest.org/). Review any surviving mutants by inspecting the line comments under [_Files changed_](${{ github.event.number }}/files)." - name: Upload Pitest reports as artifact - uses: actions/upload-artifact@v3.1.1 + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: name: pitest-reports path: ./target/pit-reports-ci From b81ec973a1eaabfcd2cc75735fc809ea9dcf8ff0 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Tue, 20 Jun 2023 15:52:26 +0200 Subject: [PATCH 367/601] Upgrade Error Prone 2.19.1 -> 2.20.0 (#685) Summary of key changes: - The `MissingRefasterAnnotation` check was contributed to Error Prone, and so is deleted here (multiple checks with the same name are not supported). - Similarly, Error Prone now supports the `-XepAllSuggestionsAsWarnings` flag out of the box. So the `ErrorProneFork` class is deleted, as it has currently no further use. While there, include a tweak to `run-mutation-tests.sh`. Fixes #686. See: - https://github.com/google/error-prone/releases/tag/v2.20.0 - https://github.com/google/error-prone/compare/v2.19.1...v2.20.0 - https://github.com/PicnicSupermarket/error-prone/compare/v2.19.1-picnic-1...v2.20.0-picnic-1 --- .../MissingRefasterAnnotation.java | 59 -------- .../refasterrules/CollectionRules.java | 2 + .../MissingRefasterAnnotationTest.java | 89 ------------ pom.xml | 7 +- refaster-runner/pom.xml | 1 + .../refaster/runner/RefasterTest.java | 129 ++++++++---------- .../AnnotatedCompositeCodeTransformer.java | 3 +- .../errorprone/refaster/ErrorProneFork.java | 56 -------- .../refaster/ErrorProneForkTest.java | 67 --------- run-mutation-tests.sh | 8 +- 10 files changed, 73 insertions(+), 348 deletions(-) delete mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotation.java delete mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotationTest.java delete mode 100644 refaster-support/src/main/java/tech/picnic/errorprone/refaster/ErrorProneFork.java delete mode 100644 refaster-support/src/test/java/tech/picnic/errorprone/refaster/ErrorProneForkTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotation.java deleted file mode 100644 index 12c71af619..0000000000 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotation.java +++ /dev/null @@ -1,59 +0,0 @@ -package tech.picnic.errorprone.bugpatterns; - -import static com.google.errorprone.BugPattern.LinkType.CUSTOM; -import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; -import static com.google.errorprone.BugPattern.StandardTags.LIKELY_ERROR; -import static com.google.errorprone.matchers.ChildMultiMatcher.MatchType.AT_LEAST_ONE; -import static com.google.errorprone.matchers.Matchers.annotations; -import static com.google.errorprone.matchers.Matchers.anyOf; -import static com.google.errorprone.matchers.Matchers.isType; -import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; - -import com.google.auto.service.AutoService; -import com.google.errorprone.BugPattern; -import com.google.errorprone.VisitorState; -import com.google.errorprone.bugpatterns.BugChecker; -import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher; -import com.google.errorprone.matchers.Description; -import com.google.errorprone.matchers.MultiMatcher; -import com.google.errorprone.util.ASTHelpers; -import com.sun.source.tree.AnnotationTree; -import com.sun.source.tree.ClassTree; -import com.sun.source.tree.MethodTree; -import com.sun.source.tree.Tree; - -/** A {@link BugChecker} that flags likely missing Refaster annotations. */ -@AutoService(BugChecker.class) -@BugPattern( - summary = "The Refaster rule contains a method without any Refaster annotations", - link = BUG_PATTERNS_BASE_URL + "MissingRefasterAnnotation", - linkType = CUSTOM, - severity = WARNING, - tags = LIKELY_ERROR) -public final class MissingRefasterAnnotation extends BugChecker implements ClassTreeMatcher { - private static final long serialVersionUID = 1L; - private static final MultiMatcher REFASTER_ANNOTATION = - annotations( - AT_LEAST_ONE, - anyOf( - isType("com.google.errorprone.refaster.annotation.Placeholder"), - isType("com.google.errorprone.refaster.annotation.BeforeTemplate"), - isType("com.google.errorprone.refaster.annotation.AfterTemplate"))); - - /** Instantiates a new {@link MissingRefasterAnnotation} instance. */ - public MissingRefasterAnnotation() {} - - @Override - public Description matchClass(ClassTree tree, VisitorState state) { - long methodTypes = - tree.getMembers().stream() - .filter(member -> member.getKind() == Tree.Kind.METHOD) - .map(MethodTree.class::cast) - .filter(method -> !ASTHelpers.isGeneratedConstructor(method)) - .map(method -> REFASTER_ANNOTATION.matches(method, state)) - .distinct() - .count(); - - return methodTypes < 2 ? Description.NO_MATCH : buildDescription(tree).build(); - } -} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java index ff8c9d4c41..ba6146025a 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/CollectionRules.java @@ -164,6 +164,8 @@ void after(Set removeFrom, Collection elementsToRemove) { } /** Prefer {@link ArrayList#ArrayList(Collection)} over the Guava alternative. */ + @SuppressWarnings( + "NonApiType" /* Matching against `List` would unnecessarily constrain the rule. */) static final class NewArrayListFromCollection { @BeforeTemplate ArrayList before(Collection collection) { diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotationTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotationTest.java deleted file mode 100644 index b3ca1fd0c9..0000000000 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/MissingRefasterAnnotationTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package tech.picnic.errorprone.bugpatterns; - -import static com.google.common.base.Predicates.containsPattern; - -import com.google.errorprone.CompilationTestHelper; -import org.junit.jupiter.api.Test; - -final class MissingRefasterAnnotationTest { - @Test - void identification() { - CompilationTestHelper.newInstance(MissingRefasterAnnotation.class, getClass()) - .expectErrorMessage( - "X", - containsPattern("The Refaster rule contains a method without any Refaster annotations")) - .addSourceLines( - "A.java", - "import com.google.errorprone.refaster.annotation.AfterTemplate;", - "import com.google.errorprone.refaster.annotation.AlsoNegation;", - "import com.google.errorprone.refaster.annotation.BeforeTemplate;", - "import java.util.Map;", - "", - "class A {", - " // BUG: Diagnostic matches: X", - " static final class MethodLacksBeforeTemplateAnnotation {", - " @BeforeTemplate", - " boolean before1(String string) {", - " return string.equals(\"\");", - " }", - "", - " // @BeforeTemplate is missing", - " boolean before2(String string) {", - " return string.length() == 0;", - " }", - "", - " @AfterTemplate", - " @AlsoNegation", - " boolean after(String string) {", - " return string.isEmpty();", - " }", - " }", - "", - " // BUG: Diagnostic matches: X", - " static final class MethodLacksAfterTemplateAnnotation {", - " @BeforeTemplate", - " boolean before(String string) {", - " return string.equals(\"\");", - " }", - "", - " // @AfterTemplate is missing", - " boolean after(String string) {", - " return string.isEmpty();", - " }", - " }", - "", - " // BUG: Diagnostic matches: X", - " abstract class MethodLacksPlaceholderAnnotation {", - " // @Placeholder is missing", - " abstract V function(K key);", - "", - " @BeforeTemplate", - " void before(Map map, K key) {", - " if (!map.containsKey(key)) {", - " map.put(key, function(key));", - " }", - " }", - "", - " @AfterTemplate", - " void after(Map map, K key) {", - " map.computeIfAbsent(key, k -> function(k));", - " }", - " }", - "", - " static final class ValidRefasterRule {", - " @BeforeTemplate", - " void unusedPureFunctionCall(Object o) {", - " o.toString();", - " }", - " }", - "", - " static final class NotARefasterRule {", - " @Override", - " public String toString() {", - " return \"This is not a Refaster rule\";", - " }", - " }", - "}") - .doTest(); - } -} diff --git a/pom.xml b/pom.xml index acd2b3524d..3fa0b96eed 100644 --- a/pom.xml +++ b/pom.xml @@ -201,7 +201,7 @@ 1.10.1 ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 - 2.19.1 + 2.20.0 0.1.18 1.0 11 @@ -972,7 +972,7 @@ - org.checkerframework + io.github.eisop dataflow-errorprone -Xep:Java8ApiChecker:OFF + + -Xep:MemberName:OFF -Xep:StaticOrDefaultInterfaceMethod:OFF diff --git a/refaster-runner/pom.xml b/refaster-runner/pom.xml index b3fd9c89d7..84ea61bad9 100644 --- a/refaster-runner/pom.xml +++ b/refaster-runner/pom.xml @@ -45,6 +45,7 @@ ${project.groupId} refaster-support + runtime com.google.auto.service diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java index 2fa0f54876..90b551b713 100644 --- a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java @@ -22,7 +22,6 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import tech.picnic.errorprone.refaster.ErrorProneFork; final class RefasterTest { private final CompilationTestHelper compilationHelper = @@ -80,74 +79,66 @@ private static Stream severityAssignmentTestCases() { SeverityLevel defaultSeverity = BugCheckerInfo.create(Refaster.class).defaultSeverity(); /* { arguments, expectedSeverities } */ - return Stream.concat( - Stream.of( - arguments( - ImmutableList.of(), ImmutableList.of(defaultSeverity, WARNING, ERROR, SUGGESTION)), - arguments(ImmutableList.of("-Xep:Refaster:OFF"), ImmutableList.of()), - arguments( - ImmutableList.of("-Xep:Refaster:DEFAULT"), - ImmutableList.of(defaultSeverity, WARNING, ERROR, SUGGESTION)), - arguments( - ImmutableList.of("-Xep:Refaster:WARN"), - ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), - arguments( - ImmutableList.of("-Xep:Refaster:ERROR"), - ImmutableList.of(ERROR, ERROR, ERROR, ERROR)), - arguments( - ImmutableList.of("-XepAllErrorsAsWarnings"), - ImmutableList.of(defaultSeverity, WARNING, WARNING, SUGGESTION)), - arguments( - ImmutableList.of("-Xep:Refaster:OFF", "-XepAllErrorsAsWarnings"), - ImmutableList.of()), - arguments( - ImmutableList.of("-Xep:Refaster:DEFAULT", "-XepAllErrorsAsWarnings"), - ImmutableList.of(defaultSeverity, WARNING, WARNING, SUGGESTION)), - arguments( - ImmutableList.of("-Xep:Refaster:WARN", "-XepAllErrorsAsWarnings"), - ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), - arguments( - ImmutableList.of("-Xep:Refaster:ERROR", "-XepAllErrorsAsWarnings"), - ImmutableList.of(WARNING, WARNING, WARNING, WARNING))), - ErrorProneFork.isErrorProneForkAvailable() - ? Stream.of( - arguments( - ImmutableList.of("-Xep:Refaster:OFF", "-XepAllSuggestionsAsWarnings"), - ImmutableList.of()), - arguments( - ImmutableList.of("-Xep:Refaster:DEFAULT", "-XepAllSuggestionsAsWarnings"), - ImmutableList.of(WARNING, WARNING, ERROR, WARNING)), - arguments( - ImmutableList.of("-Xep:Refaster:WARN", "-XepAllSuggestionsAsWarnings"), - ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), - arguments( - ImmutableList.of("-Xep:Refaster:ERROR", "-XepAllSuggestionsAsWarnings"), - ImmutableList.of(ERROR, ERROR, ERROR, ERROR)), - arguments( - ImmutableList.of( - "-Xep:Refaster:OFF", - "-XepAllErrorsAsWarnings", - "-XepAllSuggestionsAsWarnings"), - ImmutableList.of()), - arguments( - ImmutableList.of( - "-Xep:Refaster:DEFAULT", - "-XepAllErrorsAsWarnings", - "-XepAllSuggestionsAsWarnings"), - ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), - arguments( - ImmutableList.of( - "-Xep:Refaster:WARN", - "-XepAllErrorsAsWarnings", - "-XepAllSuggestionsAsWarnings"), - ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), - arguments( - ImmutableList.of( - "-Xep:Refaster:ERROR", - "-XepAllErrorsAsWarnings", - "-XepAllSuggestionsAsWarnings"), - ImmutableList.of(WARNING, WARNING, WARNING, WARNING))) - : Stream.empty()); + return Stream.of( + arguments( + ImmutableList.of(), ImmutableList.of(defaultSeverity, WARNING, ERROR, SUGGESTION)), + arguments(ImmutableList.of("-Xep:Refaster:OFF"), ImmutableList.of()), + arguments( + ImmutableList.of("-Xep:Refaster:DEFAULT"), + ImmutableList.of(defaultSeverity, WARNING, ERROR, SUGGESTION)), + arguments( + ImmutableList.of("-Xep:Refaster:WARN"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), + arguments( + ImmutableList.of("-Xep:Refaster:ERROR"), ImmutableList.of(ERROR, ERROR, ERROR, ERROR)), + arguments( + ImmutableList.of("-XepAllErrorsAsWarnings"), + ImmutableList.of(defaultSeverity, WARNING, WARNING, SUGGESTION)), + arguments( + ImmutableList.of("-Xep:Refaster:OFF", "-XepAllErrorsAsWarnings"), ImmutableList.of()), + arguments( + ImmutableList.of("-Xep:Refaster:DEFAULT", "-XepAllErrorsAsWarnings"), + ImmutableList.of(defaultSeverity, WARNING, WARNING, SUGGESTION)), + arguments( + ImmutableList.of("-Xep:Refaster:WARN", "-XepAllErrorsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), + arguments( + ImmutableList.of("-Xep:Refaster:ERROR", "-XepAllErrorsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), + arguments( + ImmutableList.of("-XepAllSuggestionsAsWarnings"), + ImmutableList.of(WARNING, WARNING, ERROR, WARNING)), + arguments( + ImmutableList.of("-Xep:Refaster:OFF", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of()), + arguments( + ImmutableList.of("-Xep:Refaster:DEFAULT", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(WARNING, WARNING, ERROR, WARNING)), + arguments( + ImmutableList.of("-Xep:Refaster:WARN", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), + arguments( + ImmutableList.of("-Xep:Refaster:ERROR", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(ERROR, ERROR, ERROR, ERROR)), + arguments( + ImmutableList.of("-XepAllErrorsAsWarnings", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), + arguments( + ImmutableList.of( + "-Xep:Refaster:OFF", "-XepAllErrorsAsWarnings", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of()), + arguments( + ImmutableList.of( + "-Xep:Refaster:DEFAULT", "-XepAllErrorsAsWarnings", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), + arguments( + ImmutableList.of( + "-Xep:Refaster:WARN", "-XepAllErrorsAsWarnings", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING)), + arguments( + ImmutableList.of( + "-Xep:Refaster:ERROR", "-XepAllErrorsAsWarnings", "-XepAllSuggestionsAsWarnings"), + ImmutableList.of(WARNING, WARNING, WARNING, WARNING))); } /** diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java index bd3cb5ef30..c7429291fb 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/AnnotatedCompositeCodeTransformer.java @@ -148,8 +148,7 @@ private static Optional getAnnotationValue( private static SeverityLevel overrideSeverity(SeverityLevel severity, Context context) { ErrorProneOptions options = context.get(ErrorProneOptions.class); - SeverityLevel minSeverity = - ErrorProneFork.isSuggestionsAsWarningsEnabled(options) ? WARNING : SUGGESTION; + SeverityLevel minSeverity = options.isSuggestionsAsWarnings() ? WARNING : SUGGESTION; SeverityLevel maxSeverity = options.isDropErrorsToWarnings() ? WARNING : ERROR; return Comparators.max(Comparators.min(severity, minSeverity), maxSeverity); diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/ErrorProneFork.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/ErrorProneFork.java deleted file mode 100644 index 38d29c403c..0000000000 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/ErrorProneFork.java +++ /dev/null @@ -1,56 +0,0 @@ -package tech.picnic.errorprone.refaster; - -import com.google.errorprone.ErrorProneOptions; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.Optional; - -/** - * Utility class that enables the runtime to determine whether Picnic's fork of Error Prone is on - * the classpath. - * - * @see Picnic's Error Prone fork - */ -public final class ErrorProneFork { - private static final Optional ERROR_PRONE_OPTIONS_IS_SUGGESTIONS_AS_WARNINGS_METHOD = - Arrays.stream(ErrorProneOptions.class.getDeclaredMethods()) - .filter(m -> Modifier.isPublic(m.getModifiers())) - .filter(m -> "isSuggestionsAsWarnings".equals(m.getName())) - .findFirst(); - - private ErrorProneFork() {} - - /** - * Tells whether Picnic's fork of Error Prone is available. - * - * @return {@code true} iff classpath introspection indicates the presence of Error Prone - * modifications that are assumed to be present only in Picnic's fork. - */ - public static boolean isErrorProneForkAvailable() { - return ERROR_PRONE_OPTIONS_IS_SUGGESTIONS_AS_WARNINGS_METHOD.isPresent(); - } - - /** - * Tells whether the custom {@code -XepAllSuggestionsAsWarnings} flag is set. - * - * @param options The currently active Error Prone options. - * @return {@code true} iff {@link #isErrorProneForkAvailable() the Error Prone fork is available} - * and the aforementioned flag is set. - * @see google/error-prone#3301 - */ - public static boolean isSuggestionsAsWarningsEnabled(ErrorProneOptions options) { - return ERROR_PRONE_OPTIONS_IS_SUGGESTIONS_AS_WARNINGS_METHOD - .filter(m -> Boolean.TRUE.equals(invoke(m, options))) - .isPresent(); - } - - private static Object invoke(Method method, Object obj, Object... args) { - try { - return method.invoke(obj, args); - } catch (IllegalAccessException | InvocationTargetException e) { - throw new IllegalStateException(String.format("Failed to invoke method '%s'", method), e); - } - } -} diff --git a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/ErrorProneForkTest.java b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/ErrorProneForkTest.java deleted file mode 100644 index 06b11b8501..0000000000 --- a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/ErrorProneForkTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package tech.picnic.errorprone.refaster; - -import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assumptions.assumeTrue; - -import com.google.errorprone.BugPattern; -import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.ErrorProneOptions; -import com.google.errorprone.VisitorState; -import com.google.errorprone.bugpatterns.BugChecker; -import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher; -import com.google.errorprone.matchers.Description; -import com.sun.source.tree.ClassTree; -import org.junit.jupiter.api.Test; - -final class ErrorProneForkTest { - @Test - void isErrorProneForkAvailable() { - assertThat(ErrorProneFork.isErrorProneForkAvailable()) - .isEqualTo(Boolean.TRUE.toString().equals(System.getProperty("error-prone-fork-in-use"))); - } - - @Test - void isSuggestionsAsWarningsEnabledWithoutFlag() { - CompilationTestHelper.newInstance(TestChecker.class, getClass()) - .addSourceLines( - "A.java", - "// BUG: Diagnostic contains: Suggestions as warnings enabled: false", - "class A {}") - .doTest(); - } - - @Test - void isSuggestionsAsWarningsEnabledWithFlag() { - assumeTrue( - ErrorProneFork.isErrorProneForkAvailable(), - "Picnic's Error Prone fork is not on the classpath"); - - CompilationTestHelper.newInstance(TestChecker.class, getClass()) - .setArgs("-XepAllSuggestionsAsWarnings") - .addSourceLines( - "A.java", - "// BUG: Diagnostic contains: Suggestions as warnings enabled: true", - "class A {}") - .doTest(); - } - - /** - * A {@link BugChecker} that reports the result of {@link - * ErrorProneFork#isSuggestionsAsWarningsEnabled(ErrorProneOptions)}. - */ - @BugPattern(summary = "Flags classes with a custom error message", severity = ERROR) - public static final class TestChecker extends BugChecker implements ClassTreeMatcher { - private static final long serialVersionUID = 1L; - - @Override - public Description matchClass(ClassTree tree, VisitorState state) { - return buildDescription(tree) - .setMessage( - String.format( - "Suggestions as warnings enabled: %s", - ErrorProneFork.isSuggestionsAsWarningsEnabled(state.errorProneOptions()))) - .build(); - } - } -} diff --git a/run-mutation-tests.sh b/run-mutation-tests.sh index 270ab31836..eb7a095ee6 100755 --- a/run-mutation-tests.sh +++ b/run-mutation-tests.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash -# Executes Pitest to determine the code base' mutation test coverage. The set -# of tests executed can optionally be restricted by name. The results are found -# in each Maven module's `target/pit-reports` directory. +# Executes Pitest to determine the code's mutation test coverage. The set of +# tests executed can optionally be restricted by name. The results are found in +# each Maven module's `target/pit-reports` directory. set -e -u -o pipefail @@ -11,7 +11,7 @@ if [ "${#}" -gt 1 ]; then exit 1 fi -targetTests=${1:-*} +targetTests="${1:-*}" mvn clean test pitest:mutationCoverage \ -DargLine.xmx=2048m \ From 09208aa49a6d68ac7b75752b96f195d8c0ee12b5 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 21 Jun 2023 21:15:38 +0200 Subject: [PATCH 368/601] [maven-release-plugin] prepare release v0.12.0 --- documentation-support/pom.xml | 2 +- error-prone-contrib/pom.xml | 2 +- pom.xml | 6 +++--- refaster-compiler/pom.xml | 2 +- refaster-runner/pom.xml | 2 +- refaster-support/pom.xml | 2 +- refaster-test-support/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/documentation-support/pom.xml b/documentation-support/pom.xml index 9ce63cfb20..49624ee452 100644 --- a/documentation-support/pom.xml +++ b/documentation-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.11.2-SNAPSHOT + 0.12.0 documentation-support diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index e9ba261e6c..bdf85e1691 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.11.2-SNAPSHOT + 0.12.0 error-prone-contrib diff --git a/pom.xml b/pom.xml index 3fa0b96eed..f116487f1a 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ tech.picnic.error-prone-support error-prone-support - 0.11.2-SNAPSHOT + 0.12.0 pom Picnic :: Error Prone Support @@ -49,7 +49,7 @@ scm:git:git@github.com:PicnicSupermarket/error-prone-support.git - v0.10.0 + v0.12.0 https://github.com/PicnicSupermarket/error-prone-support @@ -141,7 +141,7 @@ com.google.errorprone - 2023-05-16T15:38:46Z + 2023-06-21T19:08:33Z UTF-8 - 2023-06-21T19:08:33Z + 2023-06-21T19:15:38Z UTF-8 From c5a700c555c98a7bb6309ad38f0bae42a6a67cd6 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 23 Jun 2023 09:56:42 +0200 Subject: [PATCH 372/601] Upgrade Truth 1.1.4 -> 1.1.5 (#688) See: - https://github.com/google/truth/releases/tag/v1.1.5 - https://github.com/google/truth/compare/v1.1.4...v1.1.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ac3887dde0..9fc79765be 100644 --- a/pom.xml +++ b/pom.xml @@ -314,7 +314,7 @@ com.google.truth truth - 1.1.4 + 1.1.5 From bb969a8b80cf5cbc966ec4501ce5d6590276fec6 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 23 Jun 2023 10:09:55 +0200 Subject: [PATCH 373/601] Upgrade Mockito 5.3.1 -> 5.4.0 (#689) See: - https://github.com/mockito/mockito/releases/tag/v5.4.0 - https://github.com/mockito/mockito/compare/v5.3.1...v5.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9fc79765be..5b7ba97a6a 100644 --- a/pom.xml +++ b/pom.xml @@ -206,7 +206,7 @@ 1.0 11 3.8.7 - 5.3.1 + 5.4.0 1.0.1 0.10.10 1.0.11 From 705acc9164e037b01a61118e2698354effb988fe Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 23 Jun 2023 10:19:13 +0200 Subject: [PATCH 374/601] Upgrade Spring 5.3.27 -> 5.3.28 (#687) See: - https://github.com/spring-projects/spring-framework/releases/tag/v5.3.28 - https://github.com/spring-projects/spring-framework/compare/v5.3.27...v5.3.28 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5b7ba97a6a..6410252a2b 100644 --- a/pom.xml +++ b/pom.xml @@ -451,7 +451,7 @@ org.springframework spring-framework-bom - 5.3.27 + 5.3.28 pom import From f17d736356883845e1ab25238c0fdf4017986438 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 23 Jun 2023 10:32:40 +0200 Subject: [PATCH 375/601] Upgrade AutoCommon 1.2.1 -> 1.2.2 (#681) See: - https://github.com/google/auto/releases/tag/auto-common-1.2.2 - https://github.com/google/auto/compare/auto-common-1.2.1...auto-common-1.2.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6410252a2b..e60654356c 100644 --- a/pom.xml +++ b/pom.xml @@ -275,7 +275,7 @@ com.google.auto auto-common - 1.2.1 + 1.2.2 com.google.auto.service From 42810bc00c631e95d13f3eae2c29596865d81d1e Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 23 Jun 2023 11:11:10 +0200 Subject: [PATCH 376/601] Upgrade Spring Boot 2.7.12 -> 2.7.13 (#694) See: - https://github.com/spring-projects/spring-boot/releases/tag/v2.7.13 - https://github.com/spring-projects/spring-boot/compare/v2.7.12...v2.7.13 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e60654356c..4d4b188d00 100644 --- a/pom.xml +++ b/pom.xml @@ -458,7 +458,7 @@ org.springframework.boot spring-boot-test - 2.7.12 + 2.7.13 org.testng From fc862aad945f64df9fe4941e44a47485994e46ce Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 23 Jun 2023 17:47:37 +0200 Subject: [PATCH 377/601] Upgrade maven-clean-plugin 3.2.0 -> 3.3.1 (#693) See: - https://issues.apache.org/jira/issues/?jql=project%20%3D%20MCLEAN%20AND%20fixVersion%20%3E%203.2.0%20AND%20fixVersion%20%3C%3D%203.3.1 - https://github.com/apache/maven-clean-plugin/compare/maven-clean-plugin-3.2.0...maven-clean-plugin-3.3.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4d4b188d00..eb6fa58fd8 100644 --- a/pom.xml +++ b/pom.xml @@ -859,7 +859,7 @@ org.apache.maven.plugins maven-clean-plugin - 3.2.0 + 3.3.1 org.apache.maven.plugins From f541cd2e523e301993d24d08219ac1cc246f27fd Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 26 Jun 2023 09:20:25 +0200 Subject: [PATCH 378/601] Upgrade Swagger 2.2.12 -> 2.2.13 (#698) See: - https://github.com/swagger-api/swagger-core/releases/tag/v2.2.13 - https://github.com/swagger-api/swagger-core/compare/v2.2.12...v2.2.13 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index eb6fa58fd8..d091d3150f 100644 --- a/pom.xml +++ b/pom.xml @@ -355,7 +355,7 @@ io.swagger.core.v3 swagger-annotations - 2.2.12 + 2.2.13 jakarta.servlet From 9f500fd5bb48ff3141afeb26d35d76b63f1b37eb Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 26 Jun 2023 09:50:25 +0200 Subject: [PATCH 379/601] Upgrade ossf/scorecard-action v2.1.3 -> v2.2.0 (#697) And link to the new scorecard report page. See: - https://github.com/ossf/scorecard-action/releases/tag/v2.2.0 - https://github.com/ossf/scorecard-action/compare/v2.1.3...v2.2.0 --- .github/workflows/openssf-scorecard.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index 1961745a02..dff3908624 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -25,7 +25,7 @@ jobs: with: persist-credentials: false - name: Run OpenSSF Scorecard analysis - uses: ossf/scorecard-action@v2.1.3 + uses: ossf/scorecard-action@08b4669551908b1024bb425080c797723083c031 # v2.2.0 with: results_file: results.sarif results_format: sarif diff --git a/README.md b/README.md index 1c4b9409fa..5fb888f8d9 100644 --- a/README.md +++ b/README.md @@ -283,7 +283,7 @@ channel; please see our [security policy][security] for details. [openssf-best-practices-badge]: https://bestpractices.coreinfrastructure.org/projects/7199/badge [openssf-best-practices-checklist]: https://bestpractices.coreinfrastructure.org/projects/7199 [openssf-scorecard-badge]: https://img.shields.io/ossf-scorecard/github.com/PicnicSupermarket/error-prone-support?label=openssf%20scorecard -[openssf-scorecard-report]: https://api.securityscorecards.dev/projects/github.com/PicnicSupermarket/error-prone-support +[openssf-scorecard-report]: https://securityscorecards.dev/viewer/?uri=github.com/PicnicSupermarket/error-prone-support [picnic-blog-ep-post]: https://blog.picnic.nl/picnic-loves-error-prone-producing-high-quality-and-consistent-java-code-b8a566be6886 [picnic-blog]: https://blog.picnic.nl [pitest-badge]: https://img.shields.io/badge/-Mutation%20tested%20with%20PIT-blue.svg From 706b5f401f7f411639ce4511e10bd2e0b9e4bf3f Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 26 Jun 2023 11:20:21 +0200 Subject: [PATCH 380/601] Upgrade Checkstyle 10.12.0 -> 10.12.1 (#699) See: - https://checkstyle.sourceforge.io/releasenotes.html - https://github.com/checkstyle/checkstyle/releases/tag/checkstyle-10.12.1 - https://github.com/checkstyle/checkstyle/compare/checkstyle-10.12.0...checkstyle-10.12.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d091d3150f..7a49735c14 100644 --- a/pom.xml +++ b/pom.xml @@ -839,7 +839,7 @@ com.puppycrawl.tools checkstyle - 10.12.0 + 10.12.1 io.spring.nohttp From 782a790def6507817d92ef551dd7eeac4911779d Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 26 Jun 2023 11:31:05 +0200 Subject: [PATCH 381/601] Upgrade NullAway 0.10.10 -> 0.10.11 (#695) See: - https://github.com/uber/NullAway/blob/master/CHANGELOG.md - https://github.com/uber/NullAway/compare/v0.10.10...v0.10.11 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7a49735c14..abf78ba522 100644 --- a/pom.xml +++ b/pom.xml @@ -208,7 +208,7 @@ 3.8.7 5.4.0 1.0.1 - 0.10.10 + 0.10.11 1.0.11 3.1.2 From c8b3a6df82433590dd0a5a9d3a4e7afe060f6ece Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 26 Jun 2023 12:07:21 +0200 Subject: [PATCH 382/601] Upgrade pitest-maven-plugin 1.14.1 -> 1.14.2 (#696) See: - https://github.com/hcoles/pitest/releases/tag/1.14.2 - https://github.com/hcoles/pitest/compare/1.14.1...1.14.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index abf78ba522..ae72853dea 100644 --- a/pom.xml +++ b/pom.xml @@ -1356,7 +1356,7 @@ org.pitest pitest-maven - 1.14.1 + 1.14.2 From d9fefa68247763df95d4de610d537664e82f2335 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 27 Jun 2023 08:28:08 +0200 Subject: [PATCH 383/601] Upgrade Swagger 2.2.13 -> 2.2.14 (#702) See: - https://github.com/swagger-api/swagger-core/releases/tag/v2.2.14 - https://github.com/swagger-api/swagger-core/compare/v2.2.13...v2.2.14 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ae72853dea..9d2b7d25a9 100644 --- a/pom.xml +++ b/pom.xml @@ -355,7 +355,7 @@ io.swagger.core.v3 swagger-annotations - 2.2.13 + 2.2.14 jakarta.servlet From d6ab366f315b7ff75fe5fc2d66bc6800625ce58d Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 28 Jun 2023 13:20:53 +0200 Subject: [PATCH 384/601] Upgrade CodeQL v2.2.11 -> v2.20.1 (#670) See: - https://github.com/github/codeql-action/blob/main/CHANGELOG.md - https://github.com/github/codeql-action/compare/v2.20.0...v2.20.1 - https://github.com/github/codeql-action/compare/v2.3.6...v2.20.0 - https://github.com/github/codeql-action/compare/v2.3.5...v2.3.6 - https://github.com/github/codeql-action/compare/v2.3.4...v2.3.5 - https://github.com/github/codeql-action/compare/v2.3.3...v2.3.4 - https://github.com/github/codeql-action/compare/v2.3.2...v2.3.3 - https://github.com/github/codeql-action/compare/v2.3.1...v2.3.2 - https://github.com/github/codeql-action/compare/v2.3.0...v2.3.1 - https://github.com/github/codeql-action/compare/v2.2.12...v2.3.0 - https://github.com/github/codeql-action/compare/v2.2.11...v2.2.12 --- .github/workflows/codeql.yml | 4 ++-- .github/workflows/openssf-scorecard.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 66bda1395b..6d1058c43e 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -32,13 +32,13 @@ jobs: distribution: temurin cache: maven - name: Initialize CodeQL - uses: github/codeql-action/init@v2.2.11 + uses: github/codeql-action/init@f6e388ebf0efc915c6c5b165b019ee61a6746a38 # v2.20.1 with: languages: ${{ matrix.language }} - name: Perform minimal build if: matrix.language == 'java' run: mvn -T1C clean install -DskipTests -Dverification.skip - name: Perform CodeQL analysis - uses: github/codeql-action/analyze@v2.2.11 + uses: github/codeql-action/analyze@f6e388ebf0efc915c6c5b165b019ee61a6746a38 # v2.20.1 with: category: /language:${{ matrix.language }} diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index dff3908624..1a1284d495 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -31,6 +31,6 @@ jobs: results_format: sarif publish_results: ${{ github.ref == 'refs/heads/master' }} - name: Update GitHub's code scanning dashboard - uses: github/codeql-action/upload-sarif@v2.2.11 + uses: github/codeql-action/upload-sarif@f6e388ebf0efc915c6c5b165b019ee61a6746a38 # v2.20.1 with: sarif_file: results.sarif From a040310870a207de31866a4166906658736f676a Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 30 Jun 2023 12:59:26 +0200 Subject: [PATCH 385/601] Upgrade AutoValue 1.10.1 -> 1.10.2 (#704) See: - https://github.com/google/auto/releases/tag/auto-value-1.10.2 - https://github.com/google/auto/compare/auto-value-1.10.1...auto-value-1.10.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9d2b7d25a9..3f8aad2b80 100644 --- a/pom.xml +++ b/pom.xml @@ -198,7 +198,7 @@ one place. We use these to keep dependencies in sync. Version numbers that need to be referenced only once should *not* be listed here. --> 1.1.1 - 1.10.1 + 1.10.2 ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 2.20.0 From 777aa970f1d16ad8ea175b9c6bd7d5fcb4923b4e Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 5 Jul 2023 12:18:29 +0200 Subject: [PATCH 386/601] Upgrade ruby/setup-ruby v1.126.0 -> v1.152.0 (#706) See: - https://github.com/ruby/setup-ruby/releases/tag/v1.152.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.151.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.150.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.149.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.148.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.147.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.146.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.145.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.144.2 - https://github.com/ruby/setup-ruby/releases/tag/v1.144.1 - https://github.com/ruby/setup-ruby/releases/tag/v1.144.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.143.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.142.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.141.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.140.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.139.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.138.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.137.2 - https://github.com/ruby/setup-ruby/releases/tag/v1.137.1 - https://github.com/ruby/setup-ruby/releases/tag/v1.137.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.136.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.135.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.134.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.133.2 - https://github.com/ruby/setup-ruby/releases/tag/v1.133.1 - https://github.com/ruby/setup-ruby/releases/tag/v1.133.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.132.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.131.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.130.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.129.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.128.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.127.0 --- .github/workflows/deploy-website.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index 5f91feb33f..16d62b857d 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 with: persist-credentials: false - - uses: ruby/setup-ruby@v1.126.0 + - uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 # v1.152.0 with: working-directory: ./website bundler-cache: true From 08c49b9a58ea84869c3c51e08bc720eb057d54de Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 5 Jul 2023 13:42:54 +0200 Subject: [PATCH 387/601] Upgrade Pitest Git plugins 1.0.11 -> 1.0.12 (#710) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3f8aad2b80..90e7bc7682 100644 --- a/pom.xml +++ b/pom.xml @@ -209,7 +209,7 @@ 5.4.0 1.0.1 0.10.11 - 1.0.11 + 1.0.12 3.1.2 From 006665ee6d56a3a58bce0b5eb7c6b351d956315d Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Wed, 5 Jul 2023 13:54:49 +0200 Subject: [PATCH 388/601] Introduce `MonoSingle` Refaster rule (#703) --- .../errorprone/refasterrules/ReactorRules.java | 13 +++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 4 ++++ .../refasterrules/ReactorRulesTestOutput.java | 4 ++++ 3 files changed, 21 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index f7c9d15eaa..c30bbd11df 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -418,6 +418,19 @@ Mono after(Mono mono) { } } + /** Don't unnecessarily transform a {@link Mono} to a {@link Flux} to expect exactly one item. */ + static final class MonoSingle { + @BeforeTemplate + Mono before(Mono mono) { + return mono.flux().single(); + } + + @AfterTemplate + Mono after(Mono mono) { + return mono.single(); + } + } + /** Don't unnecessarily pass an empty publisher to {@link Flux#switchIfEmpty(Publisher)}. */ static final class FluxSwitchIfEmptyOfEmptyPublisher { @BeforeTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 3a15f612b9..18ce1d1dab 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -145,6 +145,10 @@ ImmutableSet> testMonoIdentity() { Mono.>empty().map(ImmutableList::copyOf)); } + Mono testMonoSingle() { + return Mono.just(1).flux().single(); + } + ImmutableSet> testFluxSwitchIfEmptyOfEmptyPublisher() { return ImmutableSet.of( Flux.just(1).switchIfEmpty(Mono.empty()), Flux.just(2).switchIfEmpty(Flux.empty())); diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index 67812db80f..c44d57e0ff 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -150,6 +150,10 @@ ImmutableSet> testMonoIdentity() { Mono.>empty()); } + Mono testMonoSingle() { + return Mono.just(1).single(); + } + ImmutableSet> testFluxSwitchIfEmptyOfEmptyPublisher() { return ImmutableSet.of(Flux.just(1), Flux.just(2)); } From ab33adfab80eadadbe3961efd69a9e0e0ddabdba Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 5 Jul 2023 17:48:22 +0200 Subject: [PATCH 389/601] Upgrade Arcmutate 1.1.0 -> 1.1.1 (#708) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 90e7bc7682..d8b2275e86 100644 --- a/pom.xml +++ b/pom.xml @@ -1385,7 +1385,7 @@ com.groupcdg.arcmutate base - 1.1.0 + 1.1.1 com.groupcdg.pitest From ba362ed4601700aeb3860f11e8d8290644096209 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 5 Jul 2023 17:59:46 +0200 Subject: [PATCH 390/601] Upgrade license-maven-plugin 2.1.0 -> 2.2.0 (#712) See: - https://github.com/mojohaus/license-maven-plugin/releases/tag/2.2.0 - https://github.com/mojohaus/license-maven-plugin/compare/2.1.0...2.2.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d8b2275e86..7aa19866c5 100644 --- a/pom.xml +++ b/pom.xml @@ -1202,7 +1202,7 @@ org.codehaus.mojo license-maven-plugin - 2.1.0 + 2.2.0 + + + org.mongodb + bson-record-codec + + + org.slf4j slf4j-api From d54ec83844dc8a03144d91e2bcc9158c51d895c8 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 1 Aug 2023 08:12:06 +0200 Subject: [PATCH 406/601] Upgrade New Relic Java Agent 8.4.0 -> 8.5.0 (#732) See: - https://github.com/newrelic/newrelic-java-agent/releases/tag/v8.5.0 - https://github.com/newrelic/newrelic-java-agent/compare/v8.4.0...v8.5.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 265360736b..c6ea96dc77 100644 --- a/pom.xml +++ b/pom.xml @@ -326,7 +326,7 @@ com.newrelic.agent.java newrelic-api - 8.4.0 + 8.5.0 From 3c38fd3495b8c722b171cf99dfc97db26cf8a43d Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 1 Aug 2023 09:54:17 +0200 Subject: [PATCH 407/601] Upgrade actions/setup-java v3.11.0 -> v3.12.0 (#730) See https://github.com/actions/setup-java/releases/tag/v3.12.0 --- .github/workflows/build.yaml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/pitest-update-pr.yml | 2 +- .github/workflows/sonarcloud.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 04559e4caf..4fe579c08a 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -35,7 +35,7 @@ jobs: with: persist-credentials: false - name: Set up JDK - uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 + uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0 with: java-version: ${{ matrix.jdk }} distribution: ${{ matrix.distribution }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 8bfde752b8..e0c20f7795 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -26,7 +26,7 @@ jobs: with: persist-credentials: false - name: Set up JDK - uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 + uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0 with: java-version: 17.0.7 distribution: temurin diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index 6d18c0dbc0..d3e23666fa 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -17,7 +17,7 @@ jobs: fetch-depth: 2 persist-credentials: false - name: Set up JDK - uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 + uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0 with: java-version: 17.0.7 distribution: temurin diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index 7655719f03..72cc4e7e07 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -24,7 +24,7 @@ jobs: with: persist-credentials: false - name: Set up JDK - uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 + uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0 with: java-version: 17.0.7 distribution: temurin diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 606f114c04..2cdb2ba621 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -21,7 +21,7 @@ jobs: fetch-depth: 0 persist-credentials: false - name: Set up JDK - uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 + uses: actions/setup-java@cd89f46ac9d01407894225f350157564c9c7cee2 # v3.12.0 with: java-version: 17.0.7 distribution: temurin From 10070bd4c801c685a65028d7d2870d7aca9b14a2 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 1 Aug 2023 15:54:26 +0200 Subject: [PATCH 408/601] Upgrade JUnit 5 5.9.3 -> 5.10.0 (#729) See: - https://junit.org/junit5/docs/current/release-notes/ - https://github.com/junit-team/junit5/releases/tag/r5.10.0-M1 - https://github.com/junit-team/junit5/releases/tag/r5.10.0-RC1 - https://github.com/junit-team/junit5/releases/tag/r5.10.0-RC2 - https://github.com/junit-team/junit5/releases/tag/r5.10.0 - https://github.com/junit-team/junit5/compare/r5.9.3...r5.10.0 --- pom.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c6ea96dc77..2f13349709 100644 --- a/pom.xml +++ b/pom.xml @@ -432,7 +432,7 @@ org.junit junit-bom - 5.9.3 + 5.10.0 pom import @@ -1202,7 +1202,8 @@ junit.jupiter.execution.parallel.enabled=true - junit.jupiter.execution.parallel.mode.default=concurrent + junit.jupiter.execution.parallel.mode.default=concurrent + junit.platform.stacktrace.pruning.enabled=false true From 08f0e5210462a72857bb7982c86313d30b1c1da0 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 2 Aug 2023 14:39:18 +0200 Subject: [PATCH 409/601] Upgrade sortpom-maven-plugin 3.2.1 -> 3.3.0 (#731) See: - https://github.com/Ekryd/sortpom/wiki/Versions - https://github.com/Ekryd/sortpom/releases/tag/sortpom-parent-3.3.0 - https://github.com/Ekryd/sortpom/compare/sortpom-parent-3.2.1...sortpom-parent-3.3.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2f13349709..548270fcc1 100644 --- a/pom.xml +++ b/pom.xml @@ -487,7 +487,7 @@ com.github.ekryd.sortpom sortpom-maven-plugin - 3.2.1 + 3.3.0 false ${project.build.sourceEncoding} From c4daa04ce1c0e97bea82df4a3def3841c445d63c Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 3 Aug 2023 10:36:41 +0200 Subject: [PATCH 410/601] Upgrade Checker Framework Annotations 3.36.0 -> 3.37.0 (#736) See: - https://github.com/typetools/checker-framework/releases/tag/checker-framework-3.37.0 - https://github.com/typetools/checker-framework/compare/checker-framework-3.36.0...checker-framework-3.37.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 548270fcc1..351b8a3678 100644 --- a/pom.xml +++ b/pom.xml @@ -412,7 +412,7 @@ org.checkerframework checker-qual - 3.36.0 + 3.37.0 org.hamcrest From 8375f1650f90aff8354300595ac3bac0d301a78b Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 3 Aug 2023 11:06:33 +0200 Subject: [PATCH 411/601] Upgrade Error Prone 2.20.0 -> 2.21.0 (#737) See: - https://github.com/google/error-prone/releases/tag/v2.21.0 - https://github.com/google/error-prone/compare/v2.20.0...v2.21.0 - https://github.com/PicnicSupermarket/error-prone/compare/v2.20.0-picnic-1...v2.21.0-picnic-1 --- pom.xml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 351b8a3678..64835a6766 100644 --- a/pom.xml +++ b/pom.xml @@ -200,8 +200,8 @@ 1.1.1 1.10.2 ${version.error-prone-orig} - v${version.error-prone-orig}-picnic-2 - 2.20.0 + v${version.error-prone-orig}-picnic-1 + 2.21.0 0.1.18 1.0 11 @@ -1734,9 +1734,6 @@ -Xep:Java7ApiChecker:OFF -Xep:Java8ApiChecker:OFF - - -Xep:MemberName:OFF -Xep:StaticOrDefaultInterfaceMethod:OFF @@ -1749,6 +1746,8 @@ false-positives. -XepOpt:CheckReturnValue:CheckAllMethods=true --> -XepOpt:InlineMe:SkipInliningsWithComments=false + -XepOpt:NamedLikeContextualKeyword:EnableClassNames=true + -XepOpt:NamedLikeContextualKeyword:EnableMethodNames=true -XepOpt:NullAway:AnnotatedPackages=tech.picnic -XepOpt:NullAway:AssertsEnabled=true -XepOpt:NullAway:CheckOptionalEmptiness=true From 2c47244571c069bf437c69935cc442216c5d5412 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 5 Aug 2023 13:27:26 +0200 Subject: [PATCH 412/601] Upgrade NullAway 0.10.11 -> 0.10.12 (#740) See: - https://github.com/uber/NullAway/blob/master/CHANGELOG.md - https://github.com/uber/NullAway/releases/tag/v0.10.12 - https://github.com/uber/NullAway/compare/v0.10.11...v0.10.12 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 64835a6766..0935af228f 100644 --- a/pom.xml +++ b/pom.xml @@ -208,7 +208,7 @@ 3.8.7 5.4.0 1.0.1 - 0.10.11 + 0.10.12 1.0.12 3.1.2 From fd70be081e531f2ed74efd4f89448c12f4a8a9ac Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 5 Aug 2023 20:13:27 +0200 Subject: [PATCH 413/601] Upgrade Arcmutate 1.1.2 -> 1.1.3 (#739) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0935af228f..04dadf0c93 100644 --- a/pom.xml +++ b/pom.xml @@ -1399,7 +1399,7 @@ com.groupcdg.arcmutate base - 1.1.2 + 1.1.3 com.groupcdg.pitest From c2e837819ec6620e04d2468e06e92b4f99ba2c1f Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 6 Aug 2023 11:15:07 +0200 Subject: [PATCH 414/601] Upgrade Pitest Git plugins 1.0.12 -> 1.1.0 (#742) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 04dadf0c93..7c5012a04f 100644 --- a/pom.xml +++ b/pom.xml @@ -209,7 +209,7 @@ 5.4.0 1.0.1 0.10.12 - 1.0.12 + 1.1.0 3.1.2 From 526227e8ed2f324265c945ee15493f388d367278 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 6 Aug 2023 16:06:25 +0200 Subject: [PATCH 415/601] Upgrade Error Prone 2.21.0 -> 2.21.1 (#743) See: - https://github.com/google/error-prone/releases/tag/v2.21.1 - https://github.com/google/error-prone/compare/v2.21.0...v2.21.1 - https://github.com/PicnicSupermarket/error-prone/compare/v2.21.0-picnic-1...v2.21.1-picnic-1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7c5012a04f..ce686e71c3 100644 --- a/pom.xml +++ b/pom.xml @@ -201,7 +201,7 @@ 1.10.2 ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 - 2.21.0 + 2.21.1 0.1.18 1.0 11 From 67a128a9b692b9a2cf83530d49a43eab1dfd08ad Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Sun, 6 Aug 2023 16:18:29 +0200 Subject: [PATCH 416/601] Fix typos in `CanonicalSyntaxAnnotation` source (#738) --- .../errorprone/bugpatterns/CanonicalAnnotationSyntax.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalAnnotationSyntax.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalAnnotationSyntax.java index b2073c7167..a0ad184b32 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalAnnotationSyntax.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalAnnotationSyntax.java @@ -91,8 +91,8 @@ private static Optional dropRedundantValueAttribute( ExpressionTree arg = args.get(0); if (state.getSourceForNode(arg) == null) { /* - * The annotation argument isn't doesn't have a source representation, e.g. because `value` - * isn't assigned to explicitly. + * The annotation argument doesn't have a source representation, e.g. because `value` isn't + * assigned explicitly. */ return Optional.empty(); } From 62abd51f4dfee2dc86a023589b30d75c5d31bffc Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 7 Aug 2023 07:24:39 +0200 Subject: [PATCH 417/601] Upgrade errorprone-slf4j 0.1.18 -> 0.1.20 (#741) See: - https://github.com/KengoTODA/errorprone-slf4j/releases/tag/v0.1.19 - https://github.com/KengoTODA/errorprone-slf4j/releases/tag/v0.1.20 - https://github.com/KengoTODA/errorprone-slf4j/compare/v0.1.18...v0.1.20 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ce686e71c3..4ec46b0029 100644 --- a/pom.xml +++ b/pom.xml @@ -202,7 +202,7 @@ ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 2.21.1 - 0.1.18 + 0.1.20 1.0 11 3.8.7 From 6a11b595174c3518c9dd8ff57b208f0357c34b62 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 7 Aug 2023 11:47:08 +0200 Subject: [PATCH 418/601] Upgrade CodeQL v2.20.3 -> v2.21.2 (#722) See: - https://github.com/github/codeql-action/blob/main/CHANGELOG.md - https://github.com/github/codeql-action/compare/v2.20.3...v2.21.2 --- .github/workflows/codeql.yml | 4 ++-- .github/workflows/openssf-scorecard.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index e0c20f7795..6a9b6de7b4 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -32,13 +32,13 @@ jobs: distribution: temurin cache: maven - name: Initialize CodeQL - uses: github/codeql-action/init@46ed16ded91731b2df79a2893d3aea8e9f03b5c4 # v2.20.3 + uses: github/codeql-action/init@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.21.2 with: languages: ${{ matrix.language }} - name: Perform minimal build if: matrix.language == 'java' run: mvn -T1C clean install -DskipTests -Dverification.skip - name: Perform CodeQL analysis - uses: github/codeql-action/analyze@46ed16ded91731b2df79a2893d3aea8e9f03b5c4 # v2.20.3 + uses: github/codeql-action/analyze@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.21.2 with: category: /language:${{ matrix.language }} diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index 2a4eb72601..d5258b1837 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -31,6 +31,6 @@ jobs: results_format: sarif publish_results: ${{ github.ref == 'refs/heads/master' }} - name: Update GitHub's code scanning dashboard - uses: github/codeql-action/upload-sarif@46ed16ded91731b2df79a2893d3aea8e9f03b5c4 # v2.20.3 + uses: github/codeql-action/upload-sarif@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.21.2 with: sarif_file: results.sarif From eb3b540537143d3d5216d5e2c70528b70823a10e Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 12 Aug 2023 14:05:50 +0200 Subject: [PATCH 419/601] Upgrade pitest-maven-plugin 1.14.2 -> 1.14.3 (#748) See: - https://github.com/hcoles/pitest/releases/tag/1.14.3 - https://github.com/hcoles/pitest/compare/1.14.2...1.14.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4ec46b0029..72a1a3c723 100644 --- a/pom.xml +++ b/pom.xml @@ -1370,7 +1370,7 @@ org.pitest pitest-maven - 1.14.2 + 1.14.3 From 26b941bbc5ff3bda21e5689ca38e4829ff612f29 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 12 Aug 2023 14:18:05 +0200 Subject: [PATCH 420/601] Upgrade Guava 32.1.1-jre -> 32.1.2-jre (#735) See: - https://github.com/google/guava/releases/tag/v32.1.2 - https://github.com/google/guava/compare/v32.1.1...v32.1.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 72a1a3c723..434f140aba 100644 --- a/pom.xml +++ b/pom.xml @@ -307,7 +307,7 @@ com.google.guava guava-bom - 32.1.1-jre + 32.1.2-jre pom import From b5ba4fa208d84bac6e7e6568aadac32e5ff2d2d8 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 12 Aug 2023 14:28:35 +0200 Subject: [PATCH 421/601] Upgrade actions/deploy-pages v2.0.3 -> v2.0.4 (#747) See: - https://github.com/actions/deploy-pages/releases/tag/v2.0.4 --- .github/workflows/deploy-website.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index 41d9b970e6..285a506646 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -48,4 +48,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@12ab2b16cf43a7a061fe99da74b6f8f11fb77f5b # v2.0.3 + uses: actions/deploy-pages@9dbe3824824f8a1377b8e298bafde1a50ede43e5 # v2.0.4 From 17cc8e0c31cd7efd9d56f1d45f18c97949f192e0 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 12 Aug 2023 14:39:33 +0200 Subject: [PATCH 422/601] Upgrade CodeQL v2.21.2 -> v2.21.3 (#746) See: - https://github.com/github/codeql-action/blob/main/CHANGELOG.md - https://github.com/github/codeql-action/compare/v2.21.2...v2.21.3 --- .github/workflows/codeql.yml | 4 ++-- .github/workflows/openssf-scorecard.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 6a9b6de7b4..02ec272679 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -32,13 +32,13 @@ jobs: distribution: temurin cache: maven - name: Initialize CodeQL - uses: github/codeql-action/init@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.21.2 + uses: github/codeql-action/init@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3 with: languages: ${{ matrix.language }} - name: Perform minimal build if: matrix.language == 'java' run: mvn -T1C clean install -DskipTests -Dverification.skip - name: Perform CodeQL analysis - uses: github/codeql-action/analyze@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.21.2 + uses: github/codeql-action/analyze@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3 with: category: /language:${{ matrix.language }} diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index d5258b1837..7956de203f 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -31,6 +31,6 @@ jobs: results_format: sarif publish_results: ${{ github.ref == 'refs/heads/master' }} - name: Update GitHub's code scanning dashboard - uses: github/codeql-action/upload-sarif@0ba4244466797eb048eb91a6cd43d5c03ca8bd05 # v2.21.2 + uses: github/codeql-action/upload-sarif@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3 with: sarif_file: results.sarif From 35a5944b81c27c288fcff59a62b6d117c6d37b61 Mon Sep 17 00:00:00 2001 From: Mohamed Sameh <110535847+mohamedsamehsalah@users.noreply.github.com> Date: Sat, 12 Aug 2023 15:36:43 +0200 Subject: [PATCH 423/601] Introduce `{Flux,{Double,Int,Long,}Stream}TakeWhile` Refaster rules (#727) --- .../refasterrules/DoubleStreamRules.java | 12 ++++++++++++ .../errorprone/refasterrules/IntStreamRules.java | 12 ++++++++++++ .../refasterrules/LongStreamRules.java | 12 ++++++++++++ .../errorprone/refasterrules/ReactorRules.java | 16 ++++++++++++++++ .../errorprone/refasterrules/StreamRules.java | 12 ++++++++++++ .../DoubleStreamRulesTestInput.java | 4 ++++ .../DoubleStreamRulesTestOutput.java | 4 ++++ .../refasterrules/IntStreamRulesTestInput.java | 4 ++++ .../refasterrules/IntStreamRulesTestOutput.java | 4 ++++ .../refasterrules/LongStreamRulesTestInput.java | 4 ++++ .../refasterrules/LongStreamRulesTestOutput.java | 4 ++++ .../refasterrules/ReactorRulesTestInput.java | 4 ++++ .../refasterrules/ReactorRulesTestOutput.java | 4 ++++ .../refasterrules/StreamRulesTestInput.java | 4 ++++ .../refasterrules/StreamRulesTestOutput.java | 4 ++++ 15 files changed, 104 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java index 409eb1ae18..db881d8cb6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/DoubleStreamRules.java @@ -277,4 +277,16 @@ boolean after(DoubleStream stream) { return stream.allMatch(e -> test(e)); } } + + static final class DoubleStreamTakeWhile { + @BeforeTemplate + DoubleStream before(DoubleStream stream, DoublePredicate predicate) { + return stream.takeWhile(predicate).filter(predicate); + } + + @AfterTemplate + DoubleStream after(DoubleStream stream, DoublePredicate predicate) { + return stream.takeWhile(predicate); + } + } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java index 5ba2ed292f..da309d7363 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/IntStreamRules.java @@ -290,4 +290,16 @@ boolean after(IntStream stream) { return stream.allMatch(e -> test(e)); } } + + static final class IntStreamTakeWhile { + @BeforeTemplate + IntStream before(IntStream stream, IntPredicate predicate) { + return stream.takeWhile(predicate).filter(predicate); + } + + @AfterTemplate + IntStream after(IntStream stream, IntPredicate predicate) { + return stream.takeWhile(predicate); + } + } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java index fe3bec8122..00f0f7338a 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/LongStreamRules.java @@ -290,4 +290,16 @@ boolean after(LongStream stream) { return stream.allMatch(e -> test(e)); } } + + static final class LongStreamTakeWhile { + @BeforeTemplate + LongStream before(LongStream stream, LongPredicate predicate) { + return stream.takeWhile(predicate).filter(predicate); + } + + @AfterTemplate + LongStream after(LongStream stream, LongPredicate predicate) { + return stream.takeWhile(predicate); + } + } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index c30bbd11df..e41d180890 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1193,6 +1193,22 @@ Flux after(Flux flux, Predicate predicate, Comparator { + @BeforeTemplate + Flux before(Flux flux, Predicate predicate) { + return flux.takeWhile(predicate).filter(predicate); + } + + @AfterTemplate + Flux after(Flux flux, Predicate predicate) { + return flux.takeWhile(predicate); + } + } + /** * Prefer {@link Flux#collect(Collector)} with {@link ImmutableList#toImmutableList()} over * alternatives that do not explicitly return an immutable collection. diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java index 0cfa9ab31f..fad5205868 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StreamRules.java @@ -639,4 +639,16 @@ Stream after(@Repeated Stream stream) { return Streams.concat(Refaster.asVarargs(stream)); } } + + static final class StreamTakeWhile { + @BeforeTemplate + Stream before(Stream stream, Predicate predicate) { + return stream.takeWhile(predicate).filter(predicate); + } + + @AfterTemplate + Stream after(Stream stream, Predicate predicate) { + return stream.takeWhile(predicate); + } + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java index b7dbcc9cba..b244a56af1 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestInput.java @@ -96,4 +96,8 @@ boolean testDoubleStreamAllMatch() { boolean testDoubleStreamAllMatch2() { return DoubleStream.of(1).noneMatch(n -> !(n > 1)); } + + DoubleStream testDoubleStreamTakeWhile() { + return DoubleStream.of(1, 2, 3).takeWhile(i -> i < 2).filter(i -> i < 2); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java index 089cf2e497..2fb16659d0 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/DoubleStreamRulesTestOutput.java @@ -95,4 +95,8 @@ boolean testDoubleStreamAllMatch() { boolean testDoubleStreamAllMatch2() { return DoubleStream.of(1).allMatch(n -> n > 1); } + + DoubleStream testDoubleStreamTakeWhile() { + return DoubleStream.of(1, 2, 3).takeWhile(i -> i < 2); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java index 76ccd17307..b95db96c44 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestInput.java @@ -100,4 +100,8 @@ boolean testIntStreamAllMatch() { boolean testIntStreamAllMatch2() { return IntStream.of(1).noneMatch(n -> !(n > 1)); } + + IntStream testIntStreamTakeWhile() { + return IntStream.of(1, 2, 3).takeWhile(i -> i < 2).filter(i -> i < 2); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java index 8c42b11118..7efb968827 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/IntStreamRulesTestOutput.java @@ -99,4 +99,8 @@ boolean testIntStreamAllMatch() { boolean testIntStreamAllMatch2() { return IntStream.of(1).allMatch(n -> n > 1); } + + IntStream testIntStreamTakeWhile() { + return IntStream.of(1, 2, 3).takeWhile(i -> i < 2); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java index e42aceeb35..c22d33f69c 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestInput.java @@ -100,4 +100,8 @@ boolean testLongStreamAllMatch() { boolean testLongStreamAllMatch2() { return LongStream.of(1).noneMatch(n -> !(n > 1)); } + + LongStream testLongStreamTakeWhile() { + return LongStream.of(1, 2, 3).takeWhile(i -> i < 2).filter(i -> i < 2); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java index d951371b30..99421d906f 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/LongStreamRulesTestOutput.java @@ -99,4 +99,8 @@ boolean testLongStreamAllMatch() { boolean testLongStreamAllMatch2() { return LongStream.of(1).allMatch(n -> n > 1); } + + LongStream testLongStreamTakeWhile() { + return LongStream.of(1, 2, 3).takeWhile(i -> i < 2); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 18ce1d1dab..1317776baa 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -382,6 +382,10 @@ Flux testFluxFilterSortWithComparator() { return Flux.just(1, 4, 3, 2).sort(reverseOrder()).filter(i -> i % 2 == 0); } + Flux testFluxTakeWhile() { + return Flux.just(1, 2, 3).takeWhile(i -> i % 2 == 0).filter(i -> i % 2 == 0); + } + Mono> testFluxCollectToImmutableList() { return Flux.just(1).collectList(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index c44d57e0ff..d52b8dd180 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -375,6 +375,10 @@ Flux testFluxFilterSortWithComparator() { return Flux.just(1, 4, 3, 2).filter(i -> i % 2 == 0).sort(reverseOrder()); } + Flux testFluxTakeWhile() { + return Flux.just(1, 2, 3).takeWhile(i -> i % 2 == 0); + } + Mono> testFluxCollectToImmutableList() { return Flux.just(1).collect(toImmutableList()); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java index a9ec0e4ca1..370c76c2af 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestInput.java @@ -258,4 +258,8 @@ ImmutableSet> testStreamsConcat() { Stream.of(Stream.of(1), Stream.of(2)).flatMap(identity()), Stream.of(Stream.of(3), Stream.of(4)).flatMap(v -> v)); } + + Stream testStreamTakeWhile() { + return Stream.of(1, 2, 3).takeWhile(i -> i < 2).filter(i -> i < 2); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java index ab69c763bc..4683df8f0d 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StreamRulesTestOutput.java @@ -258,4 +258,8 @@ ImmutableSet> testStreamsConcat() { return ImmutableSet.of( Streams.concat(Stream.of(1), Stream.of(2)), Streams.concat(Stream.of(3), Stream.of(4))); } + + Stream testStreamTakeWhile() { + return Stream.of(1, 2, 3).takeWhile(i -> i < 2); + } } From fc5f3bd4cc8b9d59da9669b50d0ca853f8de3103 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 14 Aug 2023 08:52:14 +0200 Subject: [PATCH 424/601] Upgrade Pitest Git plugins 1.1.0 -> 1.1.1 (#750) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 434f140aba..61049038c7 100644 --- a/pom.xml +++ b/pom.xml @@ -209,7 +209,7 @@ 5.4.0 1.0.1 0.10.12 - 1.1.0 + 1.1.1 3.1.2 From 4af7b21bf59b69741091945262847c80cf9e9ecd Mon Sep 17 00:00:00 2001 From: Mohamed Sameh <110535847+mohamedsamehsalah@users.noreply.github.com> Date: Mon, 14 Aug 2023 10:30:45 +0200 Subject: [PATCH 425/601] Introduce `NestedPublishers` check (#642) And introduce a few utility methods that simplify `Tree`- and `Type`-based matching, allowing the existing (and similar) `NestedOptionals` check to be simplified as well. --- .../bugpatterns/NestedOptionals.java | 21 ++--- .../bugpatterns/NestedPublishers.java | 63 +++++++++++++++ .../bugpatterns/util/MoreMatchers.java | 31 +++++--- .../bugpatterns/util/MoreTypePredicates.java | 63 +++++++++++++++ .../refasterrules/ReactorRules.java | 4 + .../bugpatterns/NestedOptionalsTest.java | 15 ---- .../bugpatterns/NestedPublishersTest.java | 37 +++++++++ .../bugpatterns/util/MoreMatchersTest.java | 79 ++++++++++++++++++- 8 files changed, 275 insertions(+), 38 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreTypePredicates.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedPublishersTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedOptionals.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedOptionals.java index 8fe464fd09..6bee75348a 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedOptionals.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedOptionals.java @@ -4,6 +4,7 @@ import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; import static com.google.errorprone.BugPattern.StandardTags.FRAGILE_CODE; import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; +import static tech.picnic.errorprone.bugpatterns.util.MoreMatchers.isSubTypeOf; import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.generic; import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.raw; import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.subOf; @@ -14,14 +15,19 @@ import com.google.errorprone.bugpatterns.BugChecker; import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; import com.google.errorprone.matchers.Description; +import com.google.errorprone.matchers.Matcher; import com.google.errorprone.suppliers.Supplier; import com.google.errorprone.suppliers.Suppliers; -import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.MethodInvocationTree; +import com.sun.source.tree.Tree; import com.sun.tools.javac.code.Type; import java.util.Optional; /** A {@link BugChecker} that flags nesting of {@link Optional Optionals}. */ +// XXX: Extend this checker to also flag method return types and variable/field types. +// XXX: Consider generalizing this checker and `NestedPublishers` to a single `NestedMonad` check, +// which e.g. also flags nested `Stream`s. Alternatively, combine these and other checkers into an +// even more generic `ConfusingType` checker. @AutoService(BugChecker.class) @BugPattern( summary = @@ -33,19 +39,16 @@ public final class NestedOptionals extends BugChecker implements MethodInvocationTreeMatcher { private static final long serialVersionUID = 1L; private static final Supplier OPTIONAL = Suppliers.typeFromClass(Optional.class); - private static final Supplier OPTIONAL_OF_OPTIONAL = - VisitorState.memoize(generic(OPTIONAL, subOf(raw(OPTIONAL)))); + private static final Matcher IS_OPTIONAL_OF_OPTIONAL = + isSubTypeOf(VisitorState.memoize(generic(OPTIONAL, subOf(raw(OPTIONAL))))); /** Instantiates a new {@link NestedOptionals} instance. */ public NestedOptionals() {} @Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { - Type type = OPTIONAL_OF_OPTIONAL.get(state); - if (type == null || !state.getTypes().isSubtype(ASTHelpers.getType(tree), type)) { - return Description.NO_MATCH; - } - - return describeMatch(tree); + return IS_OPTIONAL_OF_OPTIONAL.matches(tree, state) + ? describeMatch(tree) + : Description.NO_MATCH; } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java new file mode 100644 index 0000000000..d4f00b99b1 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NestedPublishers.java @@ -0,0 +1,63 @@ +package tech.picnic.errorprone.bugpatterns; + +import static com.google.errorprone.BugPattern.LinkType.CUSTOM; +import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; +import static com.google.errorprone.BugPattern.StandardTags.FRAGILE_CODE; +import static com.google.errorprone.matchers.Matchers.typePredicateMatcher; +import static com.google.errorprone.predicates.TypePredicates.allOf; +import static com.google.errorprone.predicates.TypePredicates.not; +import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypePredicates.hasTypeParameter; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypePredicates.isSubTypeOf; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.generic; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.raw; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.subOf; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.type; + +import com.google.auto.service.AutoService; +import com.google.errorprone.BugPattern; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.suppliers.Supplier; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.MethodInvocationTree; +import com.sun.tools.javac.code.Type; + +/** + * A {@link BugChecker} that flags {@code Publisher} instances, unless the + * nested {@link org.reactivestreams.Publisher} is a {@link reactor.core.publisher.GroupedFlux}. + */ +// XXX: See the `NestedOptionals` check for some ideas on how to generalize this kind of checker. +@AutoService(BugChecker.class) +@BugPattern( + summary = + "Avoid `Publisher`s that emit other `Publishers`s; " + + "the resultant code is hard to reason about", + link = BUG_PATTERNS_BASE_URL + "NestedPublishers", + linkType = CUSTOM, + severity = WARNING, + tags = FRAGILE_CODE) +public final class NestedPublishers extends BugChecker implements MethodInvocationTreeMatcher { + private static final long serialVersionUID = 1L; + private static final Supplier PUBLISHER = type("org.reactivestreams.Publisher"); + private static final Matcher IS_NON_GROUPED_PUBLISHER_OF_PUBLISHERS = + typePredicateMatcher( + allOf( + isSubTypeOf(generic(PUBLISHER, subOf(raw(PUBLISHER)))), + not( + hasTypeParameter( + 0, isSubTypeOf(raw(type("reactor.core.publisher.GroupedFlux"))))))); + + /** Instantiates a new {@link NestedPublishers} instance. */ + public NestedPublishers() {} + + @Override + public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { + return IS_NON_GROUPED_PUBLISHER_OF_PUBLISHERS.matches(tree, state) + ? describeMatch(tree) + : Description.NO_MATCH; + } +} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java index b62e761db0..eaa683c650 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchers.java @@ -1,11 +1,14 @@ package tech.picnic.errorprone.bugpatterns.util; +import static com.google.errorprone.matchers.Matchers.typePredicateMatcher; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypePredicates.hasAnnotation; + import com.google.errorprone.matchers.Matcher; import com.google.errorprone.matchers.Matchers; -import com.google.errorprone.predicates.TypePredicate; -import com.google.errorprone.util.ASTHelpers; +import com.google.errorprone.suppliers.Supplier; import com.sun.source.tree.AnnotationTree; -import com.sun.tools.javac.code.Symbol; +import com.sun.source.tree.Tree; +import com.sun.tools.javac.code.Type; /** * A collection of general-purpose {@link Matcher}s. @@ -25,15 +28,21 @@ private MoreMatchers() {} * @return A {@link Matcher} that matches trees with the specified meta-annotation. */ public static Matcher hasMetaAnnotation(String annotationType) { - TypePredicate typePredicate = hasAnnotation(annotationType); - return (tree, state) -> { - Symbol sym = ASTHelpers.getSymbol(tree); - return sym != null && typePredicate.apply(sym.type, state); - }; + return typePredicateMatcher(hasAnnotation(annotationType)); } - // XXX: Consider moving to a `MoreTypePredicates` utility class. - private static TypePredicate hasAnnotation(String annotationClassName) { - return (type, state) -> ASTHelpers.hasAnnotation(type.tsym, annotationClassName, state); + /** + * Returns a {@link Matcher} that determines whether the type of a given {@link Tree} is a subtype + * of the type returned by the specified {@link Supplier}. + * + *

This method differs from {@link Matchers#isSubtypeOf(Supplier)} in that it does not perform + * type erasure. + * + * @param The type of tree to match against. + * @param type The {@link Supplier} that returns the type to match against. + * @return A {@link Matcher} that matches trees with the specified type. + */ + public static Matcher isSubTypeOf(Supplier type) { + return typePredicateMatcher(MoreTypePredicates.isSubTypeOf(type)); } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreTypePredicates.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreTypePredicates.java new file mode 100644 index 0000000000..3ed401d6d6 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreTypePredicates.java @@ -0,0 +1,63 @@ +package tech.picnic.errorprone.bugpatterns.util; + +import com.google.errorprone.VisitorState; +import com.google.errorprone.predicates.TypePredicate; +import com.google.errorprone.predicates.TypePredicates; +import com.google.errorprone.suppliers.Supplier; +import com.google.errorprone.util.ASTHelpers; +import com.sun.tools.javac.code.Type; +import com.sun.tools.javac.util.List; + +/** + * A collection of general-purpose {@link TypePredicate}s. + * + *

These methods are additions to the ones found in {@link TypePredicates}. + */ +// XXX: The methods in this class are tested only indirectly. Consider adding a dedicated test +// class, or make sure that each method is explicitly covered by a tested analog in `MoreMatchers`. +public final class MoreTypePredicates { + private MoreTypePredicates() {} + + /** + * Returns a {@link TypePredicate} that matches types that are annotated with the indicated + * annotation type. + * + * @param annotationType The fully-qualified name of the annotation type. + * @return A {@link TypePredicate} that matches appropriate types. + */ + public static TypePredicate hasAnnotation(String annotationType) { + return (type, state) -> ASTHelpers.hasAnnotation(type.tsym, annotationType, state); + } + + /** + * Returns a {@link TypePredicate} that matches subtypes of the type returned by the specified + * {@link Supplier}. + * + * @implNote This method does not use {@link ASTHelpers#isSubtype(Type, Type, VisitorState)}, as + * that method performs type erasure. + * @param bound The {@link Supplier} that returns the type to match against. + * @return A {@link TypePredicate} that matches appropriate subtypes. + */ + public static TypePredicate isSubTypeOf(Supplier bound) { + Supplier memoizedType = VisitorState.memoize(bound); + return (type, state) -> { + Type boundType = memoizedType.get(state); + return boundType != null && state.getTypes().isSubtype(type, boundType); + }; + } + + /** + * Returns a {@link TypePredicate} that matches generic types with a type parameter that matches + * the specified {@link TypePredicate} at the indicated index. + * + * @param index The index of the type parameter to match against. + * @param predicate The {@link TypePredicate} to match against the type parameter. + * @return A {@link TypePredicate} that matches appropriate generic types. + */ + public static TypePredicate hasTypeParameter(int index, TypePredicate predicate) { + return (type, state) -> { + List typeArguments = type.getTypeArguments(); + return typeArguments.size() > index && predicate.apply(typeArguments.get(index), state); + }; + } +} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index e41d180890..5653673bca 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -448,6 +448,7 @@ Flux after(Flux flux) { /** Prefer {@link Flux#concatMap(Function)} over more contrived alternatives. */ static final class FluxConcatMap { @BeforeTemplate + @SuppressWarnings("NestedPublishers") Flux before(Flux flux, Function> function) { return Refaster.anyOf( flux.flatMap(function, 1), @@ -464,6 +465,7 @@ Flux after(Flux flux, Function /** Prefer {@link Flux#concatMap(Function, int)} over more contrived alternatives. */ static final class FluxConcatMapWithPrefetch { @BeforeTemplate + @SuppressWarnings("NestedPublishers") Flux before( Flux flux, Function> function, @@ -795,6 +797,7 @@ Flux after(Flux flux) { /** Prefer {@link Mono#flatMap(Function)} over more contrived alternatives. */ static final class MonoFlatMap { @BeforeTemplate + @SuppressWarnings("NestedPublishers") Mono before(Mono mono, Function> function) { return mono.map(function).flatMap(identity()); } @@ -808,6 +811,7 @@ Mono after(Mono mono, Function> fun /** Prefer {@link Mono#flatMapMany(Function)} over more contrived alternatives. */ static final class MonoFlatMapMany { @BeforeTemplate + @SuppressWarnings("NestedPublishers") Flux before(Mono mono, Function> function) { return mono.map(function).flatMapMany(identity()); } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java index 62c5fb35fb..8923c11b76 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedOptionalsTest.java @@ -36,19 +36,4 @@ void identification() { "}") .doTest(); } - - @Test - void identificationOptionalTypeNotLoaded() { - CompilationTestHelper.newInstance(NestedOptionals.class, getClass()) - .addSourceLines( - "A.java", - "import java.time.Duration;", - "", - "class A {", - " void m() {", - " Duration.ofSeconds(1);", - " }", - "}") - .doTest(); - } } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedPublishersTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedPublishersTest.java new file mode 100644 index 0000000000..846405becd --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NestedPublishersTest.java @@ -0,0 +1,37 @@ +package tech.picnic.errorprone.bugpatterns; + +import com.google.errorprone.CompilationTestHelper; +import org.junit.jupiter.api.Test; + +final class NestedPublishersTest { + @Test + void identification() { + CompilationTestHelper.newInstance(NestedPublishers.class, getClass()) + .addSourceLines( + "A.java", + "import org.reactivestreams.Publisher;", + "import reactor.core.publisher.Flux;", + "import reactor.core.publisher.GroupedFlux;", + "import reactor.core.publisher.Mono;", + "", + "class A {", + " void m() {", + " Mono.empty();", + " Flux.just(1);", + " Flux.just(1, 2).groupBy(i -> i).map(groupedFlux -> (GroupedFlux) groupedFlux);", + "", + " // BUG: Diagnostic contains:", + " Mono.just(Mono.empty());", + " // BUG: Diagnostic contains:", + " Flux.just(Flux.empty());", + " // BUG: Diagnostic contains:", + " Mono.just((Flux) Flux.just(1));", + " // BUG: Diagnostic contains:", + " Flux.just((Publisher) Mono.just(1));", + " // BUG: Diagnostic contains:", + " Mono.just(1).map(Mono::just);", + " }", + "}") + .doTest(); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java index 842fb57b6b..faed5900f3 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java @@ -1,21 +1,29 @@ package tech.picnic.errorprone.bugpatterns.util; import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.generic; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.subOf; +import static tech.picnic.errorprone.bugpatterns.util.MoreTypes.type; +import com.google.common.collect.ImmutableSet; import com.google.errorprone.BugPattern; import com.google.errorprone.CompilationTestHelper; import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.BugChecker; import com.google.errorprone.bugpatterns.BugChecker.AnnotationTreeMatcher; +import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; import com.google.errorprone.matchers.Description; import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.suppliers.Supplier; import com.sun.source.tree.AnnotationTree; +import com.sun.source.tree.MethodInvocationTree; +import com.sun.source.tree.Tree; import org.junit.jupiter.api.Test; final class MoreMatchersTest { @Test void hasMetaAnnotation() { - CompilationTestHelper.newInstance(TestMatcher.class, getClass()) + CompilationTestHelper.newInstance(HasMetaAnnotationTestChecker.class, getClass()) .addSourceLines( "A.java", "import org.junit.jupiter.api.AfterAll;", @@ -47,9 +55,59 @@ void hasMetaAnnotation() { .doTest(); } - /** A {@link BugChecker} that delegates to {@link MoreMatchers#hasMetaAnnotation(String)} . */ + @Test + void isSubTypeOf() { + CompilationTestHelper.newInstance(IsSubTypeOfTestChecker.class, getClass()) + .addSourceLines( + "A.java", + "import com.google.common.collect.ImmutableList;", + "import com.google.common.collect.ImmutableSet;", + "import com.google.common.collect.ImmutableSortedSet;", + "", + "class A {", + " void m() {", + " ImmutableSet.of(\"foo\");", + " ImmutableSortedSet.of(\"foo\");", + " ImmutableList.of(\"foo\");", + " ImmutableList.of(1);", + " ImmutableList.of(1.0);", + " ImmutableList.of((Number) 1);", + "", + " // BUG: Diagnostic contains:", + " ImmutableSet.of(1);", + " // BUG: Diagnostic contains:", + " ImmutableSet.of(1.0);", + " // BUG: Diagnostic contains:", + " ImmutableSet.of((Number) 1);", + " // BUG: Diagnostic contains:", + " ImmutableSortedSet.of(1);", + " // BUG: Diagnostic contains:", + " ImmutableSortedSet.of(1.0);", + " // BUG: Diagnostic contains:", + " ImmutableSortedSet.of((Number) 1);", + " }", + "}") + .doTest(); + } + + @Test + void isSubTypeOfBoundTypeUnknown() { + CompilationTestHelper.newInstance(IsSubTypeOfTestChecker.class, getClass()) + .withClasspath() + .addSourceLines( + "A.java", + "class A {", + " void m() {", + " System.out.println(toString());", + " }", + "}") + .doTest(); + } + + /** A {@link BugChecker} that delegates to {@link MoreMatchers#hasMetaAnnotation(String)}. */ @BugPattern(summary = "Interacts with `MoreMatchers` for testing purposes", severity = ERROR) - public static final class TestMatcher extends BugChecker implements AnnotationTreeMatcher { + public static final class HasMetaAnnotationTestChecker extends BugChecker + implements AnnotationTreeMatcher { private static final long serialVersionUID = 1L; private static final Matcher DELEGATE = MoreMatchers.hasMetaAnnotation("org.junit.jupiter.api.TestTemplate"); @@ -59,4 +117,19 @@ public Description matchAnnotation(AnnotationTree tree, VisitorState state) { return DELEGATE.matches(tree, state) ? describeMatch(tree) : Description.NO_MATCH; } } + + /** A {@link BugChecker} that delegates to {@link MoreMatchers#isSubTypeOf(Supplier)}. */ + @BugPattern(summary = "Interacts with `MoreMatchers` for testing purposes", severity = ERROR) + public static final class IsSubTypeOfTestChecker extends BugChecker + implements MethodInvocationTreeMatcher { + private static final long serialVersionUID = 1L; + private static final Matcher DELEGATE = + MoreMatchers.isSubTypeOf( + generic(type(ImmutableSet.class.getName()), subOf(type(Number.class.getName())))); + + @Override + public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { + return DELEGATE.matches(tree, state) ? describeMatch(tree) : Description.NO_MATCH; + } + } } From 7fb0e551d4f4deca5408dc1bbd723df69474bc26 Mon Sep 17 00:00:00 2001 From: Giovanni Zotta Date: Mon, 14 Aug 2023 14:05:14 +0200 Subject: [PATCH 426/601] Introduce `VerifyOnlyElementInFlux` Refaster rule (#617) --- .../errorprone/refasterrules/ReactorRules.java | 17 +++++++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 7 +++++++ .../refasterrules/ReactorRulesTestOutput.java | 4 ++++ 3 files changed, 28 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 5653673bca..c92668319f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1332,6 +1332,23 @@ StepVerifier.Step after(StepVerifier.Step step, T object) { } } + /** Avoid list collection when verifying that a {@link Flux} emits exactly one value. */ + // XXX: This rule assumes that the matched collector does not drop elements. Consider introducing + // a `@Matches(DoesNotDropElements.class)` or `@NotMatches(MayDropElements.class)` guard. + static final class FluxAsStepVerifierExpectNext> { + @BeforeTemplate + StepVerifier.Step before(Flux flux, Collector listCollector, T object) { + return flux.collect(listCollector) + .as(StepVerifier::create) + .assertNext(list -> assertThat(list).containsExactly(object)); + } + + @AfterTemplate + StepVerifier.Step after(Flux flux, T object) { + return flux.as(StepVerifier::create).expectNext(object); + } + } + /** Prefer {@link StepVerifier.LastStep#verifyComplete()} over more verbose alternatives. */ static final class StepVerifierLastStepVerifyComplete { @BeforeTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index 1317776baa..7f8021f70c 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -422,6 +422,13 @@ ImmutableSet> testStepVerifierStepExpectNext() { StepVerifier.create(Mono.just("baz")).expectNextMatches("qux"::equals)); } + StepVerifier.Step testFluxAsStepVerifierExpectNext() { + return Flux.just(1) + .collect(toImmutableList()) + .as(StepVerifier::create) + .assertNext(list -> assertThat(list).containsExactly(2)); + } + Duration testStepVerifierLastStepVerifyComplete() { return StepVerifier.create(Mono.empty()).expectComplete().verify(); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index d52b8dd180..b12af508c4 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -413,6 +413,10 @@ ImmutableSet> testStepVerifierStepExpectNext() { StepVerifier.create(Mono.just("baz")).expectNext("qux")); } + StepVerifier.Step testFluxAsStepVerifierExpectNext() { + return Flux.just(1).as(StepVerifier::create).expectNext(2); + } + Duration testStepVerifierLastStepVerifyComplete() { return StepVerifier.create(Mono.empty()).verifyComplete(); } From 88ed3ea9a99649c502fe5a68de151066e8aede34 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 15 Aug 2023 11:58:32 +0200 Subject: [PATCH 427/601] Upgrade CodeQL v2.21.3 -> v2.21.4 (#751) See: - https://github.com/github/codeql-action/blob/main/CHANGELOG.md - https://github.com/github/codeql-action/compare/v2.21.3...v2.21.4 --- .github/workflows/codeql.yml | 4 ++-- .github/workflows/openssf-scorecard.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 02ec272679..2f7c926367 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -32,13 +32,13 @@ jobs: distribution: temurin cache: maven - name: Initialize CodeQL - uses: github/codeql-action/init@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3 + uses: github/codeql-action/init@a09933a12a80f87b87005513f0abb1494c27a716 # v2.21.4 with: languages: ${{ matrix.language }} - name: Perform minimal build if: matrix.language == 'java' run: mvn -T1C clean install -DskipTests -Dverification.skip - name: Perform CodeQL analysis - uses: github/codeql-action/analyze@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3 + uses: github/codeql-action/analyze@a09933a12a80f87b87005513f0abb1494c27a716 # v2.21.4 with: category: /language:${{ matrix.language }} diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index 7956de203f..342def0cc5 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -31,6 +31,6 @@ jobs: results_format: sarif publish_results: ${{ github.ref == 'refs/heads/master' }} - name: Update GitHub's code scanning dashboard - uses: github/codeql-action/upload-sarif@5b6282e01c62d02e720b81eb8a51204f527c3624 # v2.21.3 + uses: github/codeql-action/upload-sarif@a09933a12a80f87b87005513f0abb1494c27a716 # v2.21.4 with: sarif_file: results.sarif From d758fab524d325c572c6ef688ba9fcfd7fded3d5 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Tue, 15 Aug 2023 14:08:52 +0200 Subject: [PATCH 428/601] Have Renovate file GitHub CodeQL upgrade PRs once every four weeks (#745) While there, match on the `depName` of `ruby/setup-ruby`. --- .renovaterc.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.renovaterc.json b/.renovaterc.json index bdeec3e80c..9cfce3a590 100644 --- a/.renovaterc.json +++ b/.renovaterc.json @@ -12,10 +12,11 @@ "separateMinorPatch": true }, { - "matchPackagePatterns": [ - "^ruby\\/setup-ruby$" + "matchDepNames": [ + "github/codeql-action", + "ruby/setup-ruby" ], - "schedule": "* * 1 * *" + "schedule": "every 4 weeks on Monday" } ], "reviewers": [ From 852442b55b89c26302701bbce26316c92dedac27 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 16 Aug 2023 09:02:16 +0200 Subject: [PATCH 429/601] Upgrade Project Reactor 2022.0.9 -> 2022.0.10 (#754) See: - https://github.com/reactor/reactor/releases/tag/2022.0.10 - https://github.com/reactor/reactor/compare/2022.0.9...2022.0.10 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 61049038c7..4ea4e3af5b 100644 --- a/pom.xml +++ b/pom.xml @@ -338,7 +338,7 @@ io.projectreactor reactor-bom - 2022.0.9 + 2022.0.10 pom import From 7b193f2fd5b72ce8fa9787705ea72351bd2f0e15 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 16 Aug 2023 09:24:45 +0200 Subject: [PATCH 430/601] Upgrade Byte Buddy 1.14.5 -> 1.14.6 (#753) See: - https://github.com/raphw/byte-buddy/releases/tag/byte-buddy-1.14.6 - https://github.com/raphw/byte-buddy/compare/byte-buddy-1.14.5...byte-buddy-1.14.6 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4ea4e3af5b..8d535d8f28 100644 --- a/pom.xml +++ b/pom.xml @@ -387,7 +387,7 @@ net.bytebuddy byte-buddy - 1.14.5 + 1.14.6 From a6bce960cbbe2bc4e88012e93058cc4ccfac96c3 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 17 Aug 2023 17:12:33 +0200 Subject: [PATCH 432/601] Upgrade AutoValue 1.10.2 -> 1.10.3 (#752) See: - https://github.com/google/auto/releases/tag/auto-value-1.10.3 - https://github.com/google/auto/compare/auto-value-1.10.2...auto-value-1.10.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8d5ae9f471..598536d2ae 100644 --- a/pom.xml +++ b/pom.xml @@ -198,7 +198,7 @@ one place. We use these to keep dependencies in sync. Version numbers that need to be referenced only once should *not* be listed here. --> 1.1.1 - 1.10.2 + 1.10.3 ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 2.21.1 From e612631cb8721d2d0453973a9f82837d67dc5ed1 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 17 Aug 2023 21:34:51 +0200 Subject: [PATCH 433/601] Upgrade AspectJ 1.9.19 -> 1.9.20 (#755) See: - https://github.com/eclipse-aspectj/aspectj/releases/tag/V1_9_20 - https://github.com/eclipse/org.aspectj/compare/V1_9_19...V1_9_20 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 598536d2ae..1e5c05990f 100644 --- a/pom.xml +++ b/pom.xml @@ -400,7 +400,7 @@ org.aspectj aspectjweaver - 1.9.19 + 1.9.20 org.assertj From 431c3e67acf5ae4f7a27271bd4071b94518242f3 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 25 Aug 2023 09:34:35 +0200 Subject: [PATCH 434/601] Upgrade actions/checkout v3.5.3 -> v3.6.0 (#761) See: - https://github.com/actions/checkout/blob/HEAD/CHANGELOG.md#v360 --- .github/workflows/build.yaml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/deploy-website.yaml | 2 +- .github/workflows/openssf-scorecard.yml | 2 +- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/pitest-update-pr.yml | 2 +- .github/workflows/sonarcloud.yml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4fe579c08a..048bf5010e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -31,7 +31,7 @@ jobs: # additionally enabling all checks defined in this project and any Error # Prone checks available only from other artifact repositories. - name: Check out code - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 with: persist-credentials: false - name: Set up JDK diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 2f7c926367..eb1b86334e 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 with: persist-credentials: false - name: Set up JDK diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index 285a506646..513706125b 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 with: persist-credentials: false - uses: ruby/setup-ruby@250fcd6a742febb1123a77a841497ccaa8b9e939 # v1.152.0 diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index 342def0cc5..20a51e77ae 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 with: persist-credentials: false - name: Run OpenSSF Scorecard analysis diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index d3e23666fa..11f069dd7a 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 with: fetch-depth: 2 persist-credentials: false diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index 72cc4e7e07..55aca7a1c1 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 with: persist-credentials: false - name: Set up JDK diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 2cdb2ba621..cc93944196 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0 with: fetch-depth: 0 persist-credentials: false From 1e80097bee6790fe7c42ed657eac658e4490d730 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 25 Aug 2023 21:14:26 +0200 Subject: [PATCH 435/601] Upgrade Spring Boot 2.7.14 -> 2.7.15 (#760) See: - https://github.com/spring-projects/spring-boot/releases/tag/v2.7.15 - https://github.com/spring-projects/spring-boot/compare/v2.7.14...v2.7.15 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1e5c05990f..f175796ad1 100644 --- a/pom.xml +++ b/pom.xml @@ -471,7 +471,7 @@ org.springframework.boot spring-boot-test - 2.7.14 + 2.7.15 org.testng From be818486bd591bce64aa6bffc226a3e9c3e2ab71 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 25 Aug 2023 22:05:51 +0200 Subject: [PATCH 436/601] Upgrade Mockito 5.4.0 -> 5.5.0 (#758) See: - https://github.com/mockito/mockito/releases/tag/v5.5.0 - https://github.com/mockito/mockito/compare/v5.4.0...v5.5.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f175796ad1..6fc8a39874 100644 --- a/pom.xml +++ b/pom.xml @@ -206,7 +206,7 @@ 1.0 11 3.8.7 - 5.4.0 + 5.5.0 1.0.1 0.10.12 1.1.1 From 9c158f11d41023a31231b6834301d55a9aa5ccea Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 25 Aug 2023 22:23:19 +0200 Subject: [PATCH 437/601] Upgrade maven-enforcer-plugin 3.3.0 -> 3.4.0 (#759) See: - https://github.com/apache/maven-enforcer/releases/tag/enforcer-3.4.0 - https://github.com/apache/maven-enforcer/compare/enforcer-3.3.0...enforcer-3.4.0 --- pom.xml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 6fc8a39874..818a32d9a9 100644 --- a/pom.xml +++ b/pom.xml @@ -976,7 +976,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.3.0 + 3.4.0 false @@ -1015,19 +1015,9 @@ - - true - - - + From 6131599d9d71f5860d929776db86ee1b1f46c873 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 28 Aug 2023 10:43:06 +0300 Subject: [PATCH 438/601] Introduce mutation test script for changed code (#757) While there, optimize the existing `run-mutation-tests.sh` script. --- CONTRIBUTING.md | 2 +- README.md | 12 ++++++++---- run-branch-mutation-tests.sh | 23 +++++++++++++++++++++++ run-mutation-tests.sh | 4 +--- 4 files changed, 33 insertions(+), 8 deletions(-) create mode 100755 run-branch-mutation-tests.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 558292f502..eab0c6185e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -80,6 +80,6 @@ Some pointers: [error-prone-support-developing]: https://github.com/PicnicSupermarket/error-prone-support/tree/master#-developing-error-prone-support [error-prone-support-full-build]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/run-full-build.sh [error-prone-support-issues]: https://github.com/PicnicSupermarket/error-prone-support/issues -[error-prone-support-mutation-tests]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/run-mutation-tests.sh +[error-prone-support-mutation-tests]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/run-branch-mutation-tests.sh [error-prone-support-patch]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/apply-error-prone-suggestions.sh [error-prone-support-pulls]: https://github.com/PicnicSupermarket/error-prone-support/pulls diff --git a/README.md b/README.md index 5fb888f8d9..f84b25250d 100644 --- a/README.md +++ b/README.md @@ -223,10 +223,13 @@ Other highly relevant commands: Before running this command, make sure to have installed the project (`mvn clean install`) and make sure that the current working directory does not contain unstaged or uncommited changes. -- [`./run-mutation-tests.sh`][script-run-mutation-tests] runs mutation tests - using [Pitest][pitest]. The results can be reviewed by opening the respective - `target/pit-reports/index.html` files. For more information check the [PIT - Maven plugin][pitest-maven]. +- [`./run-branch-mutation-tests.sh`][script-run-branch-mutation-tests] uses + [Pitest][pitest] to run mutation tests against code that is modified relative + to the upstream default branch. The results can be reviewed by opening the + respective `target/pit-reports/index.html` files. One can use + [`./run-mutation-tests.sh`][script-run-mutation-tests] to run mutation tests + against _all_ code in the current working directory. For more information + check the [PIT Maven plugin][pitest-maven]. When running the project's tests in IntelliJ IDEA, you might see the following error: @@ -296,6 +299,7 @@ channel; please see our [security policy][security] for details. [reproducible-builds-badge]: https://img.shields.io/badge/Reproducible_Builds-ok-success?labelColor=1e5b96 [reproducible-builds-report]: https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/tech/picnic/error-prone-support/error-prone-support/README.md [script-apply-error-prone-suggestions]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/apply-error-prone-suggestions.sh +[script-run-branch-mutation-tests]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/run-branch-mutation-tests.sh [script-run-full-build]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/run-full-build.sh [script-run-mutation-tests]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/run-mutation-tests.sh [security]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/SECURITY.md diff --git a/run-branch-mutation-tests.sh b/run-branch-mutation-tests.sh new file mode 100755 index 0000000000..d71e83f792 --- /dev/null +++ b/run-branch-mutation-tests.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# Executes Pitest to determine the mutation test coverage of changed code. By +# default code that is changed relative to the default branch is exercised, +# though another change set may be specified; see the Arcmutate Git integration +# documentation for details [1]. The results are found in each Maven module's +# `target/pit-reports` directory. +# +# [1] https://docs.arcmutate.com/docs/git-integration.html + +set -e -u -o pipefail + +if [ "${#}" -gt 1 ]; then + echo "Usage: ${0} [DiffSpec]" + exit 1 +fi + +diffSpec="${1:-+GIT(from[refs/remotes/origin/HEAD])}" + +mvn clean test-compile pitest:mutationCoverage \ + -DargLine.xmx=2048m \ + -Dverification.skip \ + -Dfeatures="${diffSpec}" diff --git a/run-mutation-tests.sh b/run-mutation-tests.sh index eb7a095ee6..9da338cf83 100755 --- a/run-mutation-tests.sh +++ b/run-mutation-tests.sh @@ -13,9 +13,7 @@ fi targetTests="${1:-*}" -mvn clean test pitest:mutationCoverage \ +mvn clean test-compile pitest:mutationCoverage \ -DargLine.xmx=2048m \ -Dverification.skip \ - -Dsurefire.failIfNoSpecifiedTests=false \ - -Dtest="${targetTests}" \ -DtargetTests="${targetTests}" From 37d95605b059c53979e690d34d4d2fa75d24cf1a Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 28 Aug 2023 10:06:30 +0200 Subject: [PATCH 439/601] Upgrade Byte Buddy 1.14.6 -> 1.14.7 (#768) See: - https://github.com/raphw/byte-buddy/releases/tag/byte-buddy-1.14.7 - https://github.com/raphw/byte-buddy/compare/byte-buddy-1.14.6...byte-buddy-1.14.7 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 818a32d9a9..57d07a8ced 100644 --- a/pom.xml +++ b/pom.xml @@ -387,7 +387,7 @@ net.bytebuddy byte-buddy - 1.14.6 + 1.14.7 - 2023-06-21T19:15:38Z + 2023-08-28T16:20:57Z UTF-8 - 2023-08-28T16:20:57Z + 2023-08-28T16:22:11Z UTF-8 + From 34fd69206466013d88bdf81a133f4b734678d89c Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 3 Oct 2023 08:07:16 +0200 Subject: [PATCH 456/601] Upgrade pitest-maven-plugin 1.14.4 -> 1.15.0 (#803) See: - https://github.com/hcoles/pitest/releases/tag/1.15.0 - https://github.com/hcoles/pitest/compare/1.14.4...1.15.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2231613e47..caf581db0c 100644 --- a/pom.xml +++ b/pom.xml @@ -1361,7 +1361,7 @@ org.pitest pitest-maven - 1.14.4 + 1.15.0 From f4e0fd2cc35e2b0ed222ccc74aa393c82b557f6d Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 3 Oct 2023 08:55:08 +0200 Subject: [PATCH 457/601] Upgrade Modernizer Maven Plugin 2.6.0 -> 2.7.0 (#801) See: - https://github.com/gaul/modernizer-maven-plugin/releases/tag/modernizer-maven-plugin-2.7.0 - https://github.com/gaul/modernizer-maven-plugin/compare/modernizer-maven-plugin-2.6.0...modernizer-maven-plugin-2.7.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index caf581db0c..3f499f7d47 100644 --- a/pom.xml +++ b/pom.xml @@ -1318,7 +1318,7 @@ org.gaul modernizer-maven-plugin - 2.6.0 + 2.7.0 From 15ff85c4eafad23d494b5ccc968db942a054f96c Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 3 Oct 2023 10:00:24 +0200 Subject: [PATCH 459/601] Upgrade Checker Framework Annotations 3.38.0 -> 3.39.0 (#808) See: - https://github.com/typetools/checker-framework/releases/tag/checker-framework-3.39.0 - https://github.com/typetools/checker-framework/compare/checker-framework-3.38.0...checker-framework-3.39.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6481f18b4f..a2a29f10b1 100644 --- a/pom.xml +++ b/pom.xml @@ -412,7 +412,7 @@ org.checkerframework checker-qual - 3.38.0 + 3.39.0 org.hamcrest From 87297c9a1d3bc705a2ba1ce743777ee2429a3831 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 3 Oct 2023 10:17:14 +0200 Subject: [PATCH 460/601] Upgrade versions-maven-plugin 2.16.0 -> 2.16.1 (#797) See: - https://github.com/mojohaus/versions/releases/tag/2.16.1 - https://github.com/mojohaus/versions-maven-plugin/compare/2.16.0...2.16.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a2a29f10b1..d0c4080d88 100644 --- a/pom.xml +++ b/pom.xml @@ -1310,7 +1310,7 @@ org.codehaus.mojo versions-maven-plugin - 2.16.0 + 2.16.1 never From 4e242a5b115542777bf09c5dcdfa088553ae71b8 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 3 Oct 2023 10:31:08 +0200 Subject: [PATCH 461/601] Upgrade Byte Buddy 1.14.7 -> 1.14.8 (#790) See: - https://github.com/raphw/byte-buddy/releases/tag/byte-buddy-1.14.8 - https://github.com/raphw/byte-buddy/compare/byte-buddy-1.14.7...byte-buddy-1.14.8 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d0c4080d88..454776b138 100644 --- a/pom.xml +++ b/pom.xml @@ -387,7 +387,7 @@ net.bytebuddy byte-buddy - 1.14.7 + 1.14.8 From a2e32ed1475bea0a6cafabd6c757f54ea305b6d6 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 3 Oct 2023 15:58:07 +0200 Subject: [PATCH 468/601] Upgrade maven-enforcer-plugin 3.4.0 -> 3.4.1 (#787) See: - https://github.com/apache/maven-enforcer/releases/tag/enforcer-3.4.1 - https://github.com/apache/maven-enforcer/compare/enforcer-3.4.0...enforcer-3.4.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a496bc4cfc..bc296164c0 100644 --- a/pom.xml +++ b/pom.xml @@ -977,7 +977,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.4.0 + 3.4.1 false From d1467e04246cb4ca09c83ce802bfd43979671fd7 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 3 Oct 2023 16:08:59 +0200 Subject: [PATCH 469/601] Upgrade actions/upload-artifact v3.1.2 -> v3.1.3 (#782) See: - https://github.com/actions/upload-artifact/releases/tag/v3.1.3 --- .github/workflows/pitest-analyze-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index 2068d768dc..569d167e42 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -32,7 +32,7 @@ jobs: - name: Aggregate Pitest reports run: mvn pitest-git:aggregate -DkilledEmoji=":tada:" -DmutantEmoji=":zombie:" -DtrailingText="Mutation testing report by [Pitest](https://pitest.org/). Review any surviving mutants by inspecting the line comments under [_Files changed_](${{ github.event.number }}/files)." - name: Upload Pitest reports as artifact - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 with: name: pitest-reports path: ./target/pit-reports-ci From 03fd050eae69155b254ff1fec28a9b138a3f2528 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 3 Oct 2023 16:42:00 +0200 Subject: [PATCH 470/601] Upgrade AutoValue 1.10.3 -> 1.10.4 (#784) See: - https://github.com/google/auto/releases/tag/auto-value-1.10.4 - https://github.com/google/auto/compare/auto-value-1.10.3...auto-value-1.10.4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bc296164c0..081a9da218 100644 --- a/pom.xml +++ b/pom.xml @@ -198,7 +198,7 @@ one place. We use these to keep dependencies in sync. Version numbers that need to be referenced only once should *not* be listed here. --> 1.1.1 - 1.10.3 + 1.10.4 ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 2.21.1 From 6e6efb3c133246e7c006be33668535b50164f481 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 3 Oct 2023 16:54:15 +0200 Subject: [PATCH 471/601] Upgrade Project Reactor 2022.0.10 -> 2022.0.11 (#789) See: - https://github.com/reactor/reactor/releases/tag/2022.0.11 - https://github.com/reactor/reactor/compare/2022.0.10...2022.0.11 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 081a9da218..b432286db0 100644 --- a/pom.xml +++ b/pom.xml @@ -338,7 +338,7 @@ io.projectreactor reactor-bom - 2022.0.10 + 2022.0.11 pom import From aa7de5777cd9e2cc173a2b6a9cdb7145535cac13 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 4 Oct 2023 08:25:50 +0200 Subject: [PATCH 472/601] Upgrade Spring 5.3.29 -> 5.3.30 (#791) See: - https://github.com/spring-projects/spring-framework/releases/tag/v5.3.30 - https://github.com/spring-projects/spring-framework/compare/v5.3.29...v5.3.30 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b432286db0..394d094ed4 100644 --- a/pom.xml +++ b/pom.xml @@ -464,7 +464,7 @@ org.springframework spring-framework-bom - 5.3.29 + 5.3.30 pom import From a726514e98be48b590e6e961dbe4452f54914732 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 4 Oct 2023 08:36:58 +0200 Subject: [PATCH 473/601] Upgrade AspectJ 1.9.20 -> 1.9.20.1 (#781) See: - https://github.com/eclipse-aspectj/aspectj/releases/tag/V1_9_20_1 - https://github.com/eclipse/org.aspectj/compare/V1_9_20...V1_9_20_1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 394d094ed4..0327a2875e 100644 --- a/pom.xml +++ b/pom.xml @@ -400,7 +400,7 @@ org.aspectj aspectjweaver - 1.9.20 + 1.9.20.1 org.assertj From 7d912d1b04e4c4089452e06583e71b1a5e6479d9 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 4 Oct 2023 08:45:30 +0200 Subject: [PATCH 474/601] Upgrade Swagger 2.2.15 -> 2.2.16 (#795) See: - https://github.com/swagger-api/swagger-core/releases/tag/v2.2.16 - https://github.com/swagger-api/swagger-core/compare/v2.2.15...v2.2.16 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0327a2875e..b14a5dcb77 100644 --- a/pom.xml +++ b/pom.xml @@ -355,7 +355,7 @@ io.swagger.core.v3 swagger-annotations - 2.2.15 + 2.2.16 jakarta.servlet From 82025a729fcaa414f3d5c4ba2220f739abe36cc7 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 4 Oct 2023 10:29:27 +0200 Subject: [PATCH 475/601] Upgrade fmt-maven-plugin 2.20 -> 2.21.1 (#804) See: - https://github.com/spotify/fmt-maven-plugin/releases/tag/2.21 - https://github.com/spotify/fmt-maven-plugin/releases/tag/2.21.1 - https://github.com/spotify/fmt-maven-plugin/compare/fmt-maven-plugin-2.20...2.21.1 --- .../errorprone/bugpatterns/FormatStringConcatenation.java | 2 ++ .../LexicographicalAnnotationAttributeListing.java | 1 + .../bugpatterns/LexicographicalAnnotationListing.java | 1 + .../picnic/errorprone/bugpatterns/util/JavaKeywords.java | 3 +++ .../errorprone/bugpatterns/util/MethodMatcherFactory.java | 1 + .../errorprone/bugpatterns/util/MoreJUnitMatchers.java | 2 ++ .../tech/picnic/errorprone/refasterrules/AssortedRules.java | 3 +-- .../java/tech/picnic/errorprone/refasterrules/MapRules.java | 6 ++---- .../tech/picnic/errorprone/refasterrules/MultimapRules.java | 3 +-- pom.xml | 2 +- .../errorprone/refaster/annotation/OnlineDocumentation.java | 1 + 11 files changed, 16 insertions(+), 9 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenation.java index 4c8f1fdd4a..7ea1f65d45 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenation.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenation.java @@ -59,6 +59,7 @@ public final class FormatStringConcatenation extends BugChecker implements MethodInvocationTreeMatcher { private static final long serialVersionUID = 1L; + /** * AssertJ exposes varargs {@code fail} methods with a {@link Throwable}-accepting overload, the * latter of which should not be flagged. @@ -68,6 +69,7 @@ public final class FormatStringConcatenation extends BugChecker .anyClass() .withAnyName() .withParameters(String.class.getName(), Throwable.class.getName()); + // XXX: Drop some of these methods if we use Refaster to replace some with others. private static final Matcher ASSERTJ_FORMAT_METHOD = anyOf( diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java index ad46c26541..7107ad8365 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java @@ -76,6 +76,7 @@ public final class LexicographicalAnnotationAttributeListing extends BugChecker private static final String FLAG_PREFIX = "LexicographicalAnnotationAttributeListing:"; private static final String INCLUDED_ANNOTATIONS_FLAG = FLAG_PREFIX + "Includes"; private static final String EXCLUDED_ANNOTATIONS_FLAG = FLAG_PREFIX + "Excludes"; + /** * The splitter applied to string-typed annotation arguments prior to lexicographical sorting. By * splitting on {@code =}, strings that represent e.g. inline Spring property declarations are diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListing.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListing.java index 2f026938ea..694cf41cb8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListing.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationListing.java @@ -46,6 +46,7 @@ public final class LexicographicalAnnotationListing extends BugChecker implements MethodTreeMatcher { private static final long serialVersionUID = 1L; + /** * A comparator that minimally reorders {@link AnnotationType}s, such that declaration annotations * are placed before type annotations. diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/JavaKeywords.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/JavaKeywords.java index d2654086e4..6571ecccf2 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/JavaKeywords.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/JavaKeywords.java @@ -17,6 +17,7 @@ public final class JavaKeywords { */ private static final ImmutableSet BOOLEAN_AND_NULL_LITERALS = ImmutableSet.of("true", "false", "null"); + /** * List of all reserved keywords in the Java language. * @@ -76,6 +77,7 @@ public final class JavaKeywords { "void", "volatile", "while"); + /** * List of all contextual keywords in the Java language. * @@ -100,6 +102,7 @@ public final class JavaKeywords { "var", "with", "yield"); + /** List of all keywords in the Java language. */ private static final ImmutableSet ALL_KEYWORDS = Sets.union(RESERVED_KEYWORDS, CONTEXTUAL_KEYWORDS).immutableCopy(); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MethodMatcherFactory.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MethodMatcherFactory.java index 6da736019f..de03abd098 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MethodMatcherFactory.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MethodMatcherFactory.java @@ -18,6 +18,7 @@ public final class MethodMatcherFactory { private static final Splitter ARGUMENT_TYPE_SPLITTER = Splitter.on(',').trimResults().omitEmptyStrings(); + // XXX: Check whether we can use a parser for "standard" Java signatures here. Maybe // `sun.reflect.generics.parser.SignatureParser`? @SuppressWarnings("java:S5998" /* In practice there will be only modest recursion. */) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java index 04b230b61e..6e5e546b42 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/MoreJUnitMatchers.java @@ -34,6 +34,7 @@ public final class MoreJUnitMatchers { anyOf( isType("org.junit.jupiter.api.Test"), hasMetaAnnotation("org.junit.jupiter.api.TestTemplate"))); + /** Matches JUnit Jupiter setup and teardown methods. */ public static final MultiMatcher SETUP_OR_TEARDOWN_METHOD = annotations( @@ -43,6 +44,7 @@ public final class MoreJUnitMatchers { isType("org.junit.jupiter.api.AfterEach"), isType("org.junit.jupiter.api.BeforeAll"), isType("org.junit.jupiter.api.BeforeEach"))); + /** * Matches methods that have a {@link org.junit.jupiter.params.provider.MethodSource} annotation. */ diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssortedRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssortedRules.java index a76e99c827..4841481ee8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssortedRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/AssortedRules.java @@ -103,8 +103,7 @@ T before(Iterator iterator, T defaultValue) { } @AfterTemplate - @Nullable - T after(Iterator iterator, T defaultValue) { + @Nullable T after(Iterator iterator, T defaultValue) { return Iterators.getNext(iterator, defaultValue); } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java index b9610c255c..4d89016c04 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MapRules.java @@ -33,14 +33,12 @@ Map after() { static final class MapGetOrNull { @BeforeTemplate - @Nullable - V before(Map map, T key) { + @Nullable V before(Map map, T key) { return map.getOrDefault(key, null); } @AfterTemplate - @Nullable - V after(Map map, T key) { + @Nullable V after(Map map, T key) { return map.get(key); } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MultimapRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MultimapRules.java index 0e17d57f32..c20184f17b 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MultimapRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/MultimapRules.java @@ -50,8 +50,7 @@ int after(Multimap multimap) { */ static final class MultimapGet { @BeforeTemplate - @Nullable - Collection before(Multimap multimap, K key) { + @Nullable Collection before(Multimap multimap, K key) { return Refaster.anyOf(multimap.asMap(), Multimaps.asMap(multimap)).get(key); } diff --git a/pom.xml b/pom.xml index b14a5dcb77..104a838ce3 100644 --- a/pom.xml +++ b/pom.xml @@ -524,7 +524,7 @@ com.spotify.fmt fmt-maven-plugin - 2.20 + 2.21.1 ${basedir}/src/test/resources diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/OnlineDocumentation.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/OnlineDocumentation.java index f41a2f1b67..01d0117984 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/OnlineDocumentation.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/annotation/OnlineDocumentation.java @@ -23,6 +23,7 @@ * the annotated Refaster rule is located. */ String TOP_LEVEL_CLASS_URL_PLACEHOLDER = "${topLevelClassName}"; + /** * The URL placeholder value that will be replaced with the name of the nested class in which the * annotated Refaster rule is located, if applicable. From 8fd87a5b6b8e663a8822676baeaaace16519b924 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 4 Oct 2023 10:59:37 +0200 Subject: [PATCH 476/601] Upgrade SLF4J 2.0.7 -> 2.0.9 (#778) See: - https://www.slf4j.org/news.html - https://github.com/qos-ch/slf4j/compare/v_2.0.7...v_2.0.9 --- pom.xml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 104a838ce3..5b26f4876d 100644 --- a/pom.xml +++ b/pom.xml @@ -458,8 +458,10 @@ org.slf4j - slf4j-api - 2.0.7 + slf4j-bom + 2.0.9 + pom + import org.springframework From c03ead9e5d8f6a9e9926d7c32fcd23fd9eb89091 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 4 Oct 2023 11:22:16 +0200 Subject: [PATCH 477/601] Upgrade JDKs used by GitHub Actions builds (#780) Summary of changes: - Use JDK 11.0.20 instead of 11.0.19. - Use JDK 17.0.8 instead of 17.0.7. - Use JDK 20.0.2 instead of 20.0.1. See: - https://www.oracle.com/java/technologies/javase/11-0-20-relnotes.html - https://www.oracle.com/java/technologies/javase/17-0-8-relnotes.html - https://www.oracle.com/java/technologies/javase/20-0-2-relnotes.html --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/workflows/build.yaml | 6 +++--- .github/workflows/codeql.yml | 2 +- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/pitest-update-pr.yml | 2 +- .github/workflows/sonarcloud.yml | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index f186587c59..5fc87d3fd5 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -42,7 +42,7 @@ Please replace this sentence with log output, if applicable. - Operating system (e.g. MacOS Monterey). -- Java version (i.e. `java --version`, e.g. `17.0.7`). +- Java version (i.e. `java --version`, e.g. `17.0.8`). - Error Prone version (e.g. `2.18.0`). - Error Prone Support version (e.g. `0.9.0`). diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8eb6e420b3..139047bc13 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,16 +10,16 @@ jobs: strategy: matrix: os: [ ubuntu-22.04 ] - jdk: [ 11.0.19, 17.0.7, 20.0.1 ] + jdk: [ 11.0.20, 17.0.8, 20.0.2 ] distribution: [ temurin ] experimental: [ false ] include: - os: macos-12 - jdk: 17.0.7 + jdk: 17.0.8 distribution: temurin experimental: false - os: windows-2022 - jdk: 17.0.7 + jdk: 17.0.8 distribution: temurin experimental: false runs-on: ${{ matrix.os }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 33b4cd9c74..4111d84f6c 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -28,7 +28,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 with: - java-version: 17.0.7 + java-version: 17.0.8 distribution: temurin cache: maven - name: Initialize CodeQL diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index 569d167e42..4ca50be467 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -19,7 +19,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 with: - java-version: 17.0.7 + java-version: 17.0.8 distribution: temurin cache: maven - name: Run Pitest diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index e11fb07b7f..02b9223b64 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -26,7 +26,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 with: - java-version: 17.0.7 + java-version: 17.0.8 distribution: temurin cache: maven - name: Download Pitest analysis artifact diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index e0f54b0c31..b39b0b61cf 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -23,7 +23,7 @@ jobs: - name: Set up JDK uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 with: - java-version: 17.0.7 + java-version: 17.0.8 distribution: temurin cache: maven - name: Create missing `test` directory From 7c618f7e2d75512af080743a752fbb8064247f53 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 4 Oct 2023 13:44:51 +0200 Subject: [PATCH 478/601] Upgrade sonar-maven-plugin 3.9.1.2184 -> 3.10.0.2594 (#792) See: - https://github.com/SonarSource/sonar-scanner-maven/releases/tag/3.10.0.2594 - https://github.com/SonarSource/sonar-scanner-maven/compare/3.9.1.2184...3.10.0.2594 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5b26f4876d..584235bd0f 100644 --- a/pom.xml +++ b/pom.xml @@ -1417,7 +1417,7 @@ org.sonarsource.scanner.maven sonar-maven-plugin - 3.9.1.2184 + 3.10.0.2594 From ef75b80e7b180f7c6cee50dcb68439237c381cf1 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 4 Oct 2023 14:43:27 +0200 Subject: [PATCH 479/601] Upgrade Error Prone 2.21.1 -> 2.22.0 (#800) See: - https://github.com/google/error-prone/releases/tag/v2.22.0 - https://github.com/google/error-prone/compare/v2.21.1...v2.22.0 - https://github.com/PicnicSupermarket/error-prone/compare/v2.21.1-picnic-1...v2.22.0-picnic-1 --- .../LexicographicalAnnotationAttributeListing.java | 5 ++++- .../tech/picnic/errorprone/bugpatterns/util/Flags.java | 7 ++----- pom.xml | 4 +--- .../errorprone/refaster/test/RefasterRuleCollection.java | 3 +-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java index 7107ad8365..4d0fcfbaac 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/LexicographicalAnnotationAttributeListing.java @@ -220,7 +220,10 @@ private static ImmutableList> getStructure(ExpressionTree private static AnnotationAttributeMatcher createAnnotationAttributeMatcher( ErrorProneFlags flags) { return AnnotationAttributeMatcher.create( - flags.getList(INCLUDED_ANNOTATIONS_FLAG), excludedAnnotations(flags)); + flags.get(INCLUDED_ANNOTATIONS_FLAG).isPresent() + ? Optional.of(flags.getListOrEmpty(INCLUDED_ANNOTATIONS_FLAG)) + : Optional.empty(), + excludedAnnotations(flags)); } private static ImmutableList excludedAnnotations(ErrorProneFlags flags) { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/Flags.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/Flags.java index ec5f4e92b3..349a003bef 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/Flags.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/Flags.java @@ -16,10 +16,7 @@ private Flags() {} * provided, or if the flag's value is the empty string. */ public static ImmutableList getList(ErrorProneFlags errorProneFlags, String name) { - return errorProneFlags - .getList(name) - .map(ImmutableList::copyOf) - .filter(flags -> !flags.equals(ImmutableList.of(""))) - .orElseGet(ImmutableList::of); + ImmutableList list = errorProneFlags.getListOrEmpty(name); + return list.equals(ImmutableList.of("")) ? ImmutableList.of() : list; } } diff --git a/pom.xml b/pom.xml index 584235bd0f..6d7a8f0738 100644 --- a/pom.xml +++ b/pom.xml @@ -201,7 +201,7 @@ 1.10.4 ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 - 2.21.1 + 2.22.0 0.1.20 1.0 11 @@ -1739,8 +1739,6 @@ false-positives. -XepOpt:CheckReturnValue:CheckAllMethods=true --> -XepOpt:InlineMe:SkipInliningsWithComments=false - -XepOpt:NamedLikeContextualKeyword:EnableClassNames=true - -XepOpt:NamedLikeContextualKeyword:EnableMethodNames=true -XepOpt:NullAway:AnnotatedPackages=tech.picnic -XepOpt:NullAway:AssertsEnabled=true -XepOpt:NullAway:CheckOptionalEmptiness=true diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java index 4d68be3781..e784140407 100644 --- a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java @@ -42,7 +42,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.regex.Pattern; import javax.inject.Inject; import org.jspecify.annotations.Nullable; @@ -180,7 +179,7 @@ private static ImmutableRangeMap indexRuleMatches( for (Description description : matches) { String ruleName = extractRefasterRuleName(description); - Set replacements = + ImmutableSet replacements = Iterables.getOnlyElement(description.fixes).getReplacements(endPositions); for (Replacement replacement : replacements) { ruleMatches.put(replacement.range(), ruleName); From 9a77a3f35fb71d0b51304808fe87222e5f87b3c0 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 4 Oct 2023 15:30:13 +0200 Subject: [PATCH 480/601] Drop `ScheduledTransactionTrace` check (#788) As well as any other references to New Relic. --- error-prone-contrib/README.md | 3 - error-prone-contrib/pom.xml | 5 - .../ScheduledTransactionTrace.java | 94 ---------------- .../bugpatterns/util/ThirdPartyLibrary.java | 7 -- .../ScheduledTransactionTraceTest.java | 105 ------------------ .../util/ThirdPartyLibraryTest.java | 14 +-- pom.xml | 6 - 7 files changed, 6 insertions(+), 228 deletions(-) delete mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTrace.java delete mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTraceTest.java diff --git a/error-prone-contrib/README.md b/error-prone-contrib/README.md index cf5d592597..5b360a3f29 100644 --- a/error-prone-contrib/README.md +++ b/error-prone-contrib/README.md @@ -125,9 +125,6 @@ The following is a list of checks we'd like to see implemented: statement. Idem for other exception types. - A Guava-specific check that replaces simple anonymous `CacheLoader` subclass declarations with `CacheLoader.from(someLambda)`. -- A Spring-specific check that enforces that methods with the `@Scheduled` - annotation are also annotated with New Relic's `@Trace` annotation. Such - methods should ideally not also represent Spring MVC endpoints. - A Spring-specific check that enforces that `@RequestMapping` annotations, when applied to a method, explicitly specify one or more target HTTP methods. - A Spring-specific check that looks for classes in which all `@RequestMapping` diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index cd4016dfe8..1c70012716 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -81,11 +81,6 @@ guava provided - - com.newrelic.agent.java - newrelic-api - test - io.projectreactor reactor-core diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTrace.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTrace.java deleted file mode 100644 index 73a9ec5f50..0000000000 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTrace.java +++ /dev/null @@ -1,94 +0,0 @@ -package tech.picnic.errorprone.bugpatterns; - -import static com.google.errorprone.BugPattern.LinkType.CUSTOM; -import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; -import static com.google.errorprone.BugPattern.StandardTags.LIKELY_ERROR; -import static com.google.errorprone.matchers.ChildMultiMatcher.MatchType.AT_LEAST_ONE; -import static com.google.errorprone.matchers.Matchers.annotations; -import static com.google.errorprone.matchers.Matchers.hasAnnotation; -import static com.google.errorprone.matchers.Matchers.isType; -import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; - -import com.google.auto.common.AnnotationMirrors; -import com.google.auto.service.AutoService; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.errorprone.BugPattern; -import com.google.errorprone.VisitorState; -import com.google.errorprone.bugpatterns.BugChecker; -import com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher; -import com.google.errorprone.fixes.SuggestedFix; -import com.google.errorprone.fixes.SuggestedFixes; -import com.google.errorprone.matchers.Description; -import com.google.errorprone.matchers.Matcher; -import com.google.errorprone.matchers.MultiMatcher; -import com.google.errorprone.util.ASTHelpers; -import com.sun.source.tree.AnnotationTree; -import com.sun.source.tree.MethodTree; -import com.sun.source.tree.Tree; -import tech.picnic.errorprone.bugpatterns.util.ThirdPartyLibrary; - -/** - * A {@link BugChecker} that flags methods with Spring's {@code @Scheduled} annotation that lack New - * Relic Agent's {@code @Trace(dispatcher = true)}. - */ -@AutoService(BugChecker.class) -@BugPattern( - summary = "Scheduled operation must start a new New Relic transaction", - link = BUG_PATTERNS_BASE_URL + "ScheduledTransactionTrace", - linkType = CUSTOM, - severity = ERROR, - tags = LIKELY_ERROR) -public final class ScheduledTransactionTrace extends BugChecker implements MethodTreeMatcher { - private static final long serialVersionUID = 1L; - private static final String TRACE_ANNOTATION_FQCN = "com.newrelic.api.agent.Trace"; - private static final Matcher IS_SCHEDULED = - hasAnnotation("org.springframework.scheduling.annotation.Scheduled"); - private static final MultiMatcher TRACE_ANNOTATION = - annotations(AT_LEAST_ONE, isType(TRACE_ANNOTATION_FQCN)); - - /** Instantiates a new {@link ScheduledTransactionTrace} instance. */ - public ScheduledTransactionTrace() {} - - @Override - public Description matchMethod(MethodTree tree, VisitorState state) { - if (!ThirdPartyLibrary.NEW_RELIC_AGENT_API.isIntroductionAllowed(state) - || !IS_SCHEDULED.matches(tree, state)) { - return Description.NO_MATCH; - } - - ImmutableList traceAnnotations = - TRACE_ANNOTATION.multiMatchResult(tree, state).matchingNodes(); - if (traceAnnotations.isEmpty()) { - /* This method completely lacks the `@Trace` annotation; add it. */ - return describeMatch( - tree, - SuggestedFix.builder() - .addImport(TRACE_ANNOTATION_FQCN) - .prefixWith(tree, "@Trace(dispatcher = true)") - .build()); - } - - AnnotationTree traceAnnotation = Iterables.getOnlyElement(traceAnnotations); - if (isCorrectAnnotation(traceAnnotation)) { - return Description.NO_MATCH; - } - - /* - * The `@Trace` annotation is present but does not specify `dispatcher = true`. Add or update - * the `dispatcher` annotation element. - */ - return describeMatch( - traceAnnotation, - SuggestedFixes.updateAnnotationArgumentValues( - traceAnnotation, state, "dispatcher", ImmutableList.of("true")) - .build()); - } - - private static boolean isCorrectAnnotation(AnnotationTree traceAnnotation) { - return Boolean.TRUE.equals( - AnnotationMirrors.getAnnotationValue( - ASTHelpers.getAnnotationMirror(traceAnnotation), "dispatcher") - .getValue()); - } -} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java index ad47462880..51678cd335 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java @@ -32,13 +32,6 @@ public enum ThirdPartyLibrary { * @see Guava on GitHub */ GUAVA("com.google.common.collect.ImmutableList"), - /** - * New Relic's Java agent API. - * - * @see New Relic - * Java agent API on GitHub - */ - NEW_RELIC_AGENT_API("com.newrelic.api.agent.Agent"), /** * VMWare's Project Reactor. * diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTraceTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTraceTest.java deleted file mode 100644 index c61a99a8ca..0000000000 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ScheduledTransactionTraceTest.java +++ /dev/null @@ -1,105 +0,0 @@ -package tech.picnic.errorprone.bugpatterns; - -import com.google.errorprone.BugCheckerRefactoringTestHelper; -import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; -import com.google.errorprone.CompilationTestHelper; -import org.junit.jupiter.api.Test; -import org.springframework.scheduling.annotation.Scheduled; - -final class ScheduledTransactionTraceTest { - @Test - void identification() { - CompilationTestHelper.newInstance(ScheduledTransactionTrace.class, getClass()) - .addSourceLines( - "A.java", - "import com.newrelic.api.agent.Trace;", - "import org.springframework.scheduling.annotation.Scheduled;", - "", - "class A {", - " void notScheduled() {}", - "", - " @Scheduled(fixedDelay = 1)", - " // BUG: Diagnostic contains:", - " void scheduledButNotTraced() {}", - "", - " @Scheduled(fixedDelay = 1)", - " // BUG: Diagnostic contains:", - " @Trace", - " void scheduledButImproperlyTraced1() {}", - "", - " @Scheduled(fixedDelay = 1)", - " // BUG: Diagnostic contains:", - " @Trace(dispatcher = false)", - " void scheduledButImproperlyTraced2() {}", - "", - " @Scheduled(fixedDelay = 1)", - " @Trace(dispatcher = true)", - " void scheduledAndProperlyTraced() {}", - "}") - .doTest(); - } - - @Test - void identificationWithoutNewRelicAgentApiOnClasspath() { - CompilationTestHelper.newInstance(ScheduledTransactionTrace.class, getClass()) - .withClasspath(Scheduled.class) - .addSourceLines( - "A.java", - "import org.springframework.scheduling.annotation.Scheduled;", - "", - "class A {", - " @Scheduled(fixedDelay = 1)", - " void scheduledButNotTraced() {}", - "}") - .doTest(); - } - - @Test - void replacement() { - BugCheckerRefactoringTestHelper.newInstance(ScheduledTransactionTrace.class, getClass()) - .addInputLines( - "A.java", - "import com.newrelic.api.agent.Trace;", - "import org.springframework.scheduling.annotation.Scheduled;", - "", - "class A {", - " @Scheduled(fixedDelay = 1)", - " void scheduledButNotTraced() {}", - "", - " @Scheduled(fixedDelay = 1)", - " @Trace", - " void scheduledButImproperlyTraced1() {}", - "", - " @Scheduled(fixedDelay = 1)", - " @Trace(dispatcher = false)", - " void scheduledButImproperlyTraced2() {}", - "", - " @Scheduled(fixedDelay = 1)", - " @Trace(leaf = true)", - " void scheduledButImproperlyTraced3() {}", - "}") - .addOutputLines( - "A.java", - "import com.newrelic.api.agent.Trace;", - "import org.springframework.scheduling.annotation.Scheduled;", - "", - "class A {", - " @Trace(dispatcher = true)", - " @Scheduled(fixedDelay = 1)", - " void scheduledButNotTraced() {}", - "", - " @Scheduled(fixedDelay = 1)", - " @Trace(dispatcher = true)", - " void scheduledButImproperlyTraced1() {}", - "", - " @Scheduled(fixedDelay = 1)", - " @Trace(dispatcher = true)", - " void scheduledButImproperlyTraced2() {}", - "", - " @Scheduled(fixedDelay = 1)", - " @Trace(dispatcher = true, leaf = true)", - " void scheduledButImproperlyTraced3() {}", - "}") - .doTest(TestMode.TEXT_MATCH); - } -} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibraryTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibraryTest.java index 090ef579b5..4338f9af35 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibraryTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibraryTest.java @@ -23,7 +23,7 @@ void isIntroductionAllowed() { CompilationTestHelper.newInstance(TestChecker.class, getClass()) .addSourceLines( "A.java", - "// BUG: Diagnostic contains: ASSERTJ: true, GUAVA: true, NEW_RELIC_AGENT_API: true, REACTOR: true", + "// BUG: Diagnostic contains: ASSERTJ: true, GUAVA: true, REACTOR: true", "class A {}") .doTest(); } @@ -34,16 +34,14 @@ void isIntroductionAllowedWitnessClassesInSymtab() { .addSourceLines( "A.java", "import com.google.common.collect.ImmutableList;", - "import com.newrelic.api.agent.Agent;", "import org.assertj.core.api.Assertions;", "import reactor.core.publisher.Flux;", "", - "// BUG: Diagnostic contains: ASSERTJ: true, GUAVA: true, NEW_RELIC_AGENT_API: true, REACTOR: true", + "// BUG: Diagnostic contains: ASSERTJ: true, GUAVA: true, REACTOR: true", "class A {", " void m(Class clazz) {", " m(Assertions.class);", " m(ImmutableList.class);", - " m(Agent.class);", " m(Flux.class);", " }", "}") @@ -56,7 +54,7 @@ void isIntroductionAllowedWitnessClassesPartiallyOnClassPath() { .withClasspath(ImmutableList.class, Flux.class) .addSourceLines( "A.java", - "// BUG: Diagnostic contains: ASSERTJ: false, GUAVA: true, NEW_RELIC_AGENT_API: false, REACTOR: true", + "// BUG: Diagnostic contains: ASSERTJ: false, GUAVA: true, REACTOR: true", "class A {}") .doTest(); } @@ -67,7 +65,7 @@ void isIntroductionAllowedWitnessClassesNotOnClassPath() { .withClasspath() .addSourceLines( "A.java", - "// BUG: Diagnostic contains: ASSERTJ: false, GUAVA: false, NEW_RELIC_AGENT_API: false, REACTOR:", + "// BUG: Diagnostic contains: ASSERTJ: false, GUAVA: false, REACTOR:", "// false", "class A {}") .doTest(); @@ -82,8 +80,8 @@ void isIntroductionAllowedIgnoreClasspathCompat(boolean ignoreClassPath) { .addSourceLines( "A.java", String.format( - "// BUG: Diagnostic contains: ASSERTJ: %s, GUAVA: true, NEW_RELIC_AGENT_API: %s, REACTOR: true", - ignoreClassPath, ignoreClassPath), + "// BUG: Diagnostic contains: ASSERTJ: %s, GUAVA: true, REACTOR: true", + ignoreClassPath), "class A {}") .doTest(); } diff --git a/pom.xml b/pom.xml index 6d7a8f0738..1bacddc2af 100644 --- a/pom.xml +++ b/pom.xml @@ -323,11 +323,6 @@ nopen-checker ${version.nopen-checker} - - com.newrelic.agent.java - newrelic-api - 8.6.0 - @@ -728,7 +723,6 @@ - From 4800522a0943ad410fae7ff9a4dd02919995c841 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 4 Oct 2023 16:40:37 +0200 Subject: [PATCH 481/601] [maven-release-plugin] prepare release v0.14.0 --- documentation-support/pom.xml | 2 +- error-prone-contrib/pom.xml | 2 +- pom.xml | 6 +++--- refaster-compiler/pom.xml | 2 +- refaster-runner/pom.xml | 2 +- refaster-support/pom.xml | 2 +- refaster-test-support/pom.xml | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/documentation-support/pom.xml b/documentation-support/pom.xml index 64432851d0..c98bb1047a 100644 --- a/documentation-support/pom.xml +++ b/documentation-support/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.13.1-SNAPSHOT + 0.14.0 documentation-support diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index 1c70012716..0b1f73f15e 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -5,7 +5,7 @@ tech.picnic.error-prone-support error-prone-support - 0.13.1-SNAPSHOT + 0.14.0 error-prone-contrib diff --git a/pom.xml b/pom.xml index 1bacddc2af..8427dce7c1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ tech.picnic.error-prone-support error-prone-support - 0.13.1-SNAPSHOT + 0.14.0 pom Picnic :: Error Prone Support @@ -49,7 +49,7 @@ scm:git:git@github.com:PicnicSupermarket/error-prone-support.git - v0.12.0 + v0.14.0 https://github.com/PicnicSupermarket/error-prone-support @@ -141,7 +141,7 @@ com.google.errorprone - 2023-08-28T16:22:11Z + 2023-10-04T14:37:51Z UTF-8 - 2023-10-04T14:37:51Z + 2023-10-04T14:40:37Z UTF-8 From 465f83b8559a77d1539532be02a1efb8db9f3c12 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 9 Oct 2023 10:42:34 +0200 Subject: [PATCH 491/601] Upgrade Arcmutate 1.2.0 -> 1.2.1 (#818) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7fb62203b3..4a40b03b74 100644 --- a/pom.xml +++ b/pom.xml @@ -1386,7 +1386,7 @@ com.groupcdg.arcmutate base - 1.2.0 + 1.2.1 com.groupcdg.pitest From 7ed3e63d2e3df8de311546cdccc7568f9cdc8f93 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 9 Oct 2023 11:20:56 +0200 Subject: [PATCH 492/601] Upgrade CodeQL v2.21.9 -> v2.22.0 (#824) See: - https://github.com/github/codeql-action/blob/main/CHANGELOG.md - https://github.com/github/codeql-action/compare/v2.21.9...v2.22.0 --- .github/workflows/codeql.yml | 4 ++-- .github/workflows/openssf-scorecard.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 4111d84f6c..489f550d54 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -32,13 +32,13 @@ jobs: distribution: temurin cache: maven - name: Initialize CodeQL - uses: github/codeql-action/init@ddccb873888234080b77e9bc2d4764d5ccaaccf9 # v2.21.9 + uses: github/codeql-action/init@2cb752a87e96af96708ab57187ab6372ee1973ab # v2.22.0 with: languages: ${{ matrix.language }} - name: Perform minimal build if: matrix.language == 'java' run: mvn -T1C clean install -DskipTests -Dverification.skip - name: Perform CodeQL analysis - uses: github/codeql-action/analyze@ddccb873888234080b77e9bc2d4764d5ccaaccf9 # v2.21.9 + uses: github/codeql-action/analyze@2cb752a87e96af96708ab57187ab6372ee1973ab # v2.22.0 with: category: /language:${{ matrix.language }} diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index 32271f8cf8..2b3c6e7042 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -31,6 +31,6 @@ jobs: results_format: sarif publish_results: ${{ github.ref == 'refs/heads/master' }} - name: Update GitHub's code scanning dashboard - uses: github/codeql-action/upload-sarif@ddccb873888234080b77e9bc2d4764d5ccaaccf9 # v2.21.9 + uses: github/codeql-action/upload-sarif@2cb752a87e96af96708ab57187ab6372ee1973ab # v2.22.0 with: sarif_file: results.sarif From 9ada0783dd36d154c98df8188e28cfe0da225e35 Mon Sep 17 00:00:00 2001 From: Vincent Koeman Date: Mon, 9 Oct 2023 11:30:50 +0200 Subject: [PATCH 493/601] Introduce `Flux{Empty,Just}` Refaster rules (#815) --- .../refasterrules/ReactorRules.java | 68 +++++++++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 31 +++++++++ .../refasterrules/ReactorRulesTestOutput.java | 31 +++++++++ 3 files changed, 130 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 3a72d4e818..68650e5b45 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -426,6 +426,74 @@ Flux after(Flux flux, T object) { } } + /** Prefer {@link Flux#empty()} over more contrived alternatives. */ + // XXX: In combination with the `IsEmpty` matcher introduced by + // https://github.com/PicnicSupermarket/error-prone-support/pull/744, the non-varargs overloads of + // most methods referenced here can be rewritten as well. Additionally, some invocations of + // methods such as `Flux#fromIterable`, `Flux#fromArray` and `Flux#justOrEmpty` can also be + // rewritten. + static final class FluxEmpty> { + @BeforeTemplate + Flux before( + int prefetch, + Function combinator, + Comparator comparator) { + return Refaster.anyOf( + Flux.concat(), + Flux.concatDelayError(), + Flux.firstWithSignal(), + Flux.just(), + Flux.merge(), + Flux.merge(prefetch), + Flux.mergeComparing(comparator), + Flux.mergeComparing(prefetch, comparator), + Flux.mergeComparingDelayError(prefetch, comparator), + Flux.mergeDelayError(prefetch), + Flux.mergePriority(comparator), + Flux.mergePriority(prefetch, comparator), + Flux.mergePriorityDelayError(prefetch, comparator), + Flux.mergeSequential(), + Flux.mergeSequential(prefetch), + Flux.mergeSequentialDelayError(prefetch), + Flux.zip(combinator), + Flux.zip(combinator, prefetch)); + } + + @BeforeTemplate + Flux before(int prefetch, Function combinator) { + return Refaster.anyOf( + Flux.combineLatest(combinator), Flux.combineLatest(combinator, prefetch)); + } + + @BeforeTemplate + Flux before() { + return Refaster.anyOf(Flux.mergeComparing(), Flux.mergePriority()); + } + + @BeforeTemplate + Flux before(int start) { + return Flux.range(start, 0); + } + + @AfterTemplate + Flux after() { + return Flux.empty(); + } + } + + /** Prefer {@link Flux#just(Object)} over more contrived alternatives. */ + static final class FluxJust { + @BeforeTemplate + Flux before(int start) { + return Flux.range(start, 1); + } + + @AfterTemplate + Flux after(int start) { + return Flux.just(start); + } + } + /** Don't unnecessarily transform a {@link Mono} to an equivalent instance. */ static final class MonoIdentity { @BeforeTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index f077307dcd..b10b47f57b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -148,6 +148,37 @@ ImmutableSet> testFluxDefaultIfEmpty() { Flux.just("baz").switchIfEmpty(Flux.just("qux"))); } + ImmutableSet> testFluxEmpty() { + return ImmutableSet.of( + Flux.concat(), + Flux.concatDelayError(), + Flux.firstWithSignal(), + Flux.just(), + Flux.merge(), + Flux.merge(1), + Flux.mergeComparing((a, b) -> 0), + Flux.mergeComparing(1, (a, b) -> 0), + Flux.mergeComparingDelayError(1, (a, b) -> 0), + Flux.mergeDelayError(1), + Flux.mergePriority((a, b) -> 0), + Flux.mergePriority(1, (a, b) -> 0), + Flux.mergePriorityDelayError(1, (a, b) -> 0), + Flux.mergeSequential(), + Flux.mergeSequential(1), + Flux.mergeSequentialDelayError(1), + Flux.zip(v -> v), + Flux.zip(v -> v, 1), + Flux.combineLatest(v -> v), + Flux.combineLatest(v -> v, 1), + Flux.mergeComparing(), + Flux.mergePriority(), + Flux.range(0, 0)); + } + + Flux testFluxJust() { + return Flux.range(0, 1); + } + ImmutableSet> testMonoIdentity() { return ImmutableSet.of( Mono.just(1).switchIfEmpty(Mono.empty()), diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index e762c242ad..98279c9060 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -152,6 +152,37 @@ ImmutableSet> testFluxDefaultIfEmpty() { Flux.just("foo").defaultIfEmpty("bar"), Flux.just("baz").defaultIfEmpty("qux")); } + ImmutableSet> testFluxEmpty() { + return ImmutableSet.of( + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty(), + Flux.empty()); + } + + Flux testFluxJust() { + return Flux.just(0); + } + ImmutableSet> testMonoIdentity() { return ImmutableSet.of( Mono.just(1), From 583e51c9b0b5819f851c045504a95761335b521c Mon Sep 17 00:00:00 2001 From: Phil Werli Date: Mon, 9 Oct 2023 11:57:36 +0200 Subject: [PATCH 494/601] Introduce `{Mono,Flux}OfType` Refaster rules (#810) --- .../refasterrules/ReactorRules.java | 26 +++++++++++++++++++ .../refasterrules/ReactorRulesTestInput.java | 8 ++++++ .../refasterrules/ReactorRulesTestOutput.java | 8 ++++++ 3 files changed, 42 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 68650e5b45..b9d79aa450 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -1053,6 +1053,32 @@ Flux after(Flux flux) { } } + /** Prefer {@link Mono#ofType(Class)} over more contrived alternatives. */ + static final class MonoOfType { + @BeforeTemplate + Mono before(Mono mono, Class clazz) { + return mono.filter(clazz::isInstance).cast(clazz); + } + + @AfterTemplate + Mono after(Mono mono, Class clazz) { + return mono.ofType(clazz); + } + } + + /** Prefer {@link Flux#ofType(Class)} over more contrived alternatives. */ + static final class FluxOfType { + @BeforeTemplate + Flux before(Flux flux, Class clazz) { + return flux.filter(clazz::isInstance).cast(clazz); + } + + @AfterTemplate + Flux after(Flux flux, Class clazz) { + return flux.ofType(clazz); + } + } + /** Prefer {@link Mono#flatMap(Function)} over more contrived alternatives. */ static final class MonoFlatMap { @BeforeTemplate diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java index b10b47f57b..cab6be19ef 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestInput.java @@ -364,6 +364,14 @@ Flux testFluxCast() { return Flux.just(1).map(Number.class::cast); } + Mono testMonoOfType() { + return Mono.just(1).filter(Number.class::isInstance).cast(Number.class); + } + + Flux testFluxOfType() { + return Flux.just(1).filter(Number.class::isInstance).cast(Number.class); + } + Mono testMonoFlatMap() { return Mono.just("foo").map(Mono::just).flatMap(identity()); } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java index 98279c9060..6e8005f65e 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ReactorRulesTestOutput.java @@ -357,6 +357,14 @@ Flux testFluxCast() { return Flux.just(1).cast(Number.class); } + Mono testMonoOfType() { + return Mono.just(1).ofType(Number.class); + } + + Flux testFluxOfType() { + return Flux.just(1).ofType(Number.class); + } + Mono testMonoFlatMap() { return Mono.just("foo").flatMap(Mono::just); } From b492a4afd3420792fb6f09fa8cd398c0a8949d9a Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Tue, 10 Oct 2023 08:37:43 +0200 Subject: [PATCH 495/601] Fix and enable `ClassRules` Refaster rule collection tests (#826) --- .../tech/picnic/errorprone/refasterrules/RefasterRulesTest.java | 1 + .../picnic/errorprone/refasterrules/ClassRulesTestInput.java | 1 + .../picnic/errorprone/refasterrules/ClassRulesTestOutput.java | 1 + 3 files changed, 3 insertions(+) diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java index 6a67c37b7f..0fe39dec04 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java @@ -36,6 +36,7 @@ final class RefasterRulesTest { AssortedRules.class, BigDecimalRules.class, BugCheckerRules.class, + ClassRules.class, CollectionRules.class, ComparatorRules.class, DoubleStreamRules.class, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ClassRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ClassRulesTestInput.java index d59e3e18d2..2e94c24213 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ClassRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ClassRulesTestInput.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableSet; import java.io.IOException; +import java.util.function.Predicate; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class ClassRulesTest implements RefasterRuleCollectionTestCase { diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ClassRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ClassRulesTestOutput.java index 548fa31439..39c08a5068 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ClassRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ClassRulesTestOutput.java @@ -2,6 +2,7 @@ import com.google.common.collect.ImmutableSet; import java.io.IOException; +import java.util.function.Predicate; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class ClassRulesTest implements RefasterRuleCollectionTestCase { From 605d045760bcfd4de93015e2b96d46298ca2246d Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 10 Oct 2023 09:22:48 +0200 Subject: [PATCH 496/601] Upgrade ossf/scorecard-action v2.2.0 -> v2.3.0 (#821) See: - https://github.com/ossf/scorecard-action/releases/tag/v2.3.0 --- .github/workflows/openssf-scorecard.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index 2b3c6e7042..e32843e2ee 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -25,7 +25,7 @@ jobs: with: persist-credentials: false - name: Run OpenSSF Scorecard analysis - uses: ossf/scorecard-action@08b4669551908b1024bb425080c797723083c031 # v2.2.0 + uses: ossf/scorecard-action@483ef80eb98fb506c348f7d62e28055e49fe2398 # v2.3.0 with: results_file: results.sarif results_format: sarif From f1882caf886fbaad2afcd92388801e0d68c7052e Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 11 Oct 2023 08:18:44 +0200 Subject: [PATCH 497/601] Upgrade pitest-maven-plugin 1.15.0 -> 1.15.1 (#830) See: - https://github.com/hcoles/pitest/releases/tag/1.15.1 - https://github.com/hcoles/pitest/compare/1.15.0...1.15.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4a40b03b74..18e4f77501 100644 --- a/pom.xml +++ b/pom.xml @@ -1357,7 +1357,7 @@ org.pitest pitest-maven - 1.15.0 + 1.15.1 From 75679396df1113566bd87b6f4be006add4bf09b5 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 11 Oct 2023 08:36:26 +0200 Subject: [PATCH 498/601] Introduce `PatternRules` Refaster rule collection (#771) While there, configure `StaticImport` to not require static importing of `com.google.common.base.Predicates.contains`. The new rules triggered cleanup of some `CompilationTestHelper` usages. See google/guava#6483. --- .../errorprone/bugpatterns/StaticImport.java | 1 + .../refasterrules/PatternRules.java | 46 ++++++++++++ .../bugpatterns/AmbiguousJsonCreatorTest.java | 4 +- .../bugpatterns/FluxImplicitBlockTest.java | 11 +-- .../bugpatterns/StringJoinTest.java | 6 +- .../refasterrules/RefasterRulesTest.java | 1 + .../refasterrules/PatternRulesTestInput.java | 22 ++++++ .../refasterrules/PatternRulesTestOutput.java | 22 ++++++ .../refaster/runner/RefasterTest.java | 72 ++++++++++--------- 9 files changed, 135 insertions(+), 50 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/PatternRules.java create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PatternRulesTestInput.java create mode 100644 error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PatternRulesTestOutput.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java index 6063562002..c5b3e52427 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java @@ -155,6 +155,7 @@ public final class StaticImport extends BugChecker implements MemberSelectTreeMa @VisibleForTesting static final ImmutableSetMultimap STATIC_IMPORT_EXEMPTED_MEMBERS = ImmutableSetMultimap.builder() + .put("com.google.common.base.Predicates", "contains") .put("com.mongodb.client.model.Filters", "empty") .putAll( "java.util.Collections", diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/PatternRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/PatternRules.java new file mode 100644 index 0000000000..39ad88262b --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/PatternRules.java @@ -0,0 +1,46 @@ +package tech.picnic.errorprone.refasterrules; + +import static com.google.common.base.Predicates.containsPattern; + +import com.google.common.base.Predicates; +import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.BeforeTemplate; +import java.util.function.Predicate; +import java.util.regex.Pattern; +import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; + +/** Refaster rules related to code dealing with regular expressions. */ +@OnlineDocumentation +final class PatternRules { + private PatternRules() {} + + /** Prefer {@link Pattern#asPredicate()} over non-JDK alternatives. */ + // XXX: This rule could also replace `s -> pattern.matcher(s).find()`, though the lambda + // expression may match functional interfaces other than `Predicate`. If we do add such a rule, we + // should also add a rule that replaces `s -> pattern.matcher(s).matches()` with + // `pattern.asMatchPredicate()`. + static final class PatternAsPredicate { + @BeforeTemplate + Predicate before(Pattern pattern) { + return Predicates.contains(pattern); + } + + @AfterTemplate + Predicate after(Pattern pattern) { + return pattern.asPredicate(); + } + } + + /** Prefer {@link Pattern#asPredicate()} over non-JDK alternatives. */ + static final class PatternCompileAsPredicate { + @BeforeTemplate + Predicate before(String pattern) { + return containsPattern(pattern); + } + + @AfterTemplate + Predicate after(String pattern) { + return Pattern.compile(pattern).asPredicate(); + } + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AmbiguousJsonCreatorTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AmbiguousJsonCreatorTest.java index 785642de02..82976c5336 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AmbiguousJsonCreatorTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/AmbiguousJsonCreatorTest.java @@ -1,7 +1,5 @@ package tech.picnic.errorprone.bugpatterns; -import static com.google.common.base.Predicates.containsPattern; - import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.CompilationTestHelper; @@ -12,7 +10,7 @@ final class AmbiguousJsonCreatorTest { void identification() { CompilationTestHelper.newInstance(AmbiguousJsonCreator.class, getClass()) .expectErrorMessage( - "X", containsPattern("`JsonCreator.Mode` should be set for single-argument creators")) + "X", m -> m.contains("`JsonCreator.Mode` should be set for single-argument creators")) .addSourceLines( "Container.java", "import com.fasterxml.jackson.annotation.JsonCreator;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxImplicitBlockTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxImplicitBlockTest.java index 6390b2d041..91cecd3439 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxImplicitBlockTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/FluxImplicitBlockTest.java @@ -1,14 +1,12 @@ package tech.picnic.errorprone.bugpatterns; -import static com.google.common.base.Predicates.and; -import static com.google.common.base.Predicates.containsPattern; -import static com.google.common.base.Predicates.not; import static com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers.SECOND; import static com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers.THIRD; import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.CompilationTestHelper; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import reactor.core.CorePublisher; @@ -20,10 +18,7 @@ void identification() { CompilationTestHelper.newInstance(FluxImplicitBlock.class, getClass()) .expectErrorMessage( "X", - and( - containsPattern("SuppressWarnings"), - containsPattern("toImmutableList"), - containsPattern("toList"))) + m -> Stream.of("SuppressWarnings", "toImmutableList", "toList").allMatch(m::contains)) .addSourceLines( "A.java", "import com.google.common.collect.ImmutableList;", @@ -63,7 +58,7 @@ void identification() { void identificationWithoutGuavaOnClasspath() { CompilationTestHelper.newInstance(FluxImplicitBlock.class, getClass()) .withClasspath(CorePublisher.class, Flux.class, Publisher.class) - .expectErrorMessage("X", not(containsPattern("toImmutableList"))) + .expectErrorMessage("X", m -> !m.contains("toImmutableList")) .addSourceLines( "A.java", "import reactor.core.publisher.Flux;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringJoinTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringJoinTest.java index 379fc830ed..3bc5eb9547 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringJoinTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StringJoinTest.java @@ -1,7 +1,5 @@ package tech.picnic.errorprone.bugpatterns; -import static com.google.common.base.Predicates.containsPattern; - import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; import com.google.errorprone.CompilationTestHelper; @@ -12,8 +10,8 @@ final class StringJoinTest { void identification() { CompilationTestHelper.newInstance(StringJoin.class, getClass()) .expectErrorMessage( - "valueOf", containsPattern("Prefer `String#valueOf` over `String#format`")) - .expectErrorMessage("join", containsPattern("Prefer `String#join` over `String#format`")) + "valueOf", m -> m.contains("Prefer `String#valueOf` over `String#format`")) + .expectErrorMessage("join", m -> m.contains("Prefer `String#join` over `String#format`")) .addSourceLines( "A.java", "import java.util.Formattable;", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java index 0fe39dec04..b7a7a017a6 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java @@ -61,6 +61,7 @@ final class RefasterRulesTest { MultimapRules.class, NullRules.class, OptionalRules.class, + PatternRules.class, PreconditionsRules.class, PrimitiveRules.class, ReactorRules.class, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PatternRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PatternRulesTestInput.java new file mode 100644 index 0000000000..2b19d9ea88 --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PatternRulesTestInput.java @@ -0,0 +1,22 @@ +package tech.picnic.errorprone.refasterrules; + +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableSet; +import java.util.function.Predicate; +import java.util.regex.Pattern; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; + +final class PatternRulesTest implements RefasterRuleCollectionTestCase { + @Override + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of(Predicates.class); + } + + Predicate testPatternAsPredicate() { + return Predicates.contains(Pattern.compile("foo")); + } + + Predicate testPatternCompileAsPredicate() { + return Predicates.containsPattern("foo"); + } +} diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PatternRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PatternRulesTestOutput.java new file mode 100644 index 0000000000..9e774fd474 --- /dev/null +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/PatternRulesTestOutput.java @@ -0,0 +1,22 @@ +package tech.picnic.errorprone.refasterrules; + +import com.google.common.base.Predicates; +import com.google.common.collect.ImmutableSet; +import java.util.function.Predicate; +import java.util.regex.Pattern; +import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; + +final class PatternRulesTest implements RefasterRuleCollectionTestCase { + @Override + public ImmutableSet elidedTypesAndStaticImports() { + return ImmutableSet.of(Predicates.class); + } + + Predicate testPatternAsPredicate() { + return Pattern.compile("foo").asPredicate(); + } + + Predicate testPatternCompileAsPredicate() { + return Pattern.compile("foo").asPredicate(); + } +} diff --git a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java index 90b551b713..8dd3bc2aff 100644 --- a/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java +++ b/refaster-runner/src/test/java/tech/picnic/errorprone/refaster/runner/RefasterTest.java @@ -1,6 +1,5 @@ package tech.picnic.errorprone.refaster.runner; -import static com.google.common.base.Predicates.containsPattern; import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; @@ -24,35 +23,33 @@ import org.junit.jupiter.params.provider.MethodSource; final class RefasterTest { - private final CompilationTestHelper compilationHelper = - CompilationTestHelper.newInstance(Refaster.class, getClass()) - .matchAllDiagnostics() - .expectErrorMessage( - "StringOfSizeZeroRule", - containsPattern( - "\\[Refaster Rule\\] FooRules\\.StringOfSizeZeroRule: Refactoring opportunity\\s+.+\\s+")) - .expectErrorMessage( - "StringOfSizeOneRule", - containsPattern( - "\\[Refaster Rule\\] FooRules\\.StringOfSizeOneRule: " - + "A custom description about matching single-char strings\\s+.+\\s+" - + "\\(see https://error-prone.picnic.tech/refasterrules/FooRules#StringOfSizeOneRule\\)")) - .expectErrorMessage( - "StringOfSizeTwoRule", - containsPattern( - "\\[Refaster Rule\\] FooRules\\.ExtraGrouping\\.StringOfSizeTwoRule: " - + "A custom subgroup description\\s+.+\\s+" - + "\\(see https://example.com/rule/FooRules#ExtraGrouping.StringOfSizeTwoRule\\)")) - .expectErrorMessage( - "StringOfSizeThreeRule", - containsPattern( - "\\[Refaster Rule\\] FooRules\\.ExtraGrouping\\.StringOfSizeThreeRule: " - + "A custom description about matching three-char strings\\s+.+\\s+" - + "\\(see https://example.com/custom\\)")); + private static final Pattern DIAGNOSTIC_STRING_OF_SIZE_ZERO = + Pattern.compile( + "\\[Refaster Rule\\] FooRules\\.StringOfSizeZeroRule: Refactoring opportunity\\s+.+\\s+"); + private static final Pattern DIAGNOSTIC_STRING_OF_SIZE_ONE = + Pattern.compile( + "\\[Refaster Rule\\] FooRules\\.StringOfSizeOneRule: " + + "A custom description about matching single-char strings\\s+.+\\s+" + + "\\(see https://error-prone.picnic.tech/refasterrules/FooRules#StringOfSizeOneRule\\)"); + private static final Pattern DIAGNOSTIC_STRING_OF_SIZE_TWO = + Pattern.compile( + "\\[Refaster Rule\\] FooRules\\.ExtraGrouping\\.StringOfSizeTwoRule: " + + "A custom subgroup description\\s+.+\\s+" + + "\\(see https://example.com/rule/FooRules#ExtraGrouping.StringOfSizeTwoRule\\)"); + private static final Pattern DIAGNOSTIC_STRING_OF_SIZE_THREE = + Pattern.compile( + "\\[Refaster Rule\\] FooRules\\.ExtraGrouping\\.StringOfSizeThreeRule: " + + "A custom description about matching three-char strings\\s+.+\\s+" + + "\\(see https://example.com/custom\\)"); @Test void identification() { - compilationHelper + CompilationTestHelper.newInstance(Refaster.class, getClass()) + .matchAllDiagnostics() + .expectErrorMessage("StringOfSizeZeroRule", DIAGNOSTIC_STRING_OF_SIZE_ZERO.asPredicate()) + .expectErrorMessage("StringOfSizeOneRule", DIAGNOSTIC_STRING_OF_SIZE_ONE.asPredicate()) + .expectErrorMessage("StringOfSizeTwoRule", DIAGNOSTIC_STRING_OF_SIZE_TWO.asPredicate()) + .expectErrorMessage("StringOfSizeThreeRule", DIAGNOSTIC_STRING_OF_SIZE_THREE.asPredicate()) .addSourceLines( "A.java", "class A {", @@ -153,7 +150,7 @@ private static Stream severityAssignmentTestCases() { void severityAssignment( ImmutableList arguments, ImmutableList expectedSeverities) { CompilationTestHelper compilationTestHelper = - compilationHelper + CompilationTestHelper.newInstance(Refaster.class, getClass()) .setArgs(arguments) .addSourceLines( "A.java", @@ -167,13 +164,18 @@ void severityAssignment( " };", " }", "}"); - assertThatThrownBy(compilationTestHelper::doTest) - .isInstanceOf(AssertionError.class) - .message() - .satisfies( - message -> - assertThat(extractRefasterSeverities("A.java", message)) - .containsExactlyElementsOf(expectedSeverities)); + + if (expectedSeverities.isEmpty()) { + compilationTestHelper.doTest(); + } else { + assertThatThrownBy(compilationTestHelper::doTest) + .isInstanceOf(AssertionError.class) + .message() + .satisfies( + message -> + assertThat(extractRefasterSeverities("A.java", message)) + .containsExactlyElementsOf(expectedSeverities)); + } } private static ImmutableList extractRefasterSeverities( From 05809b1c8596e3cd2b69c281bfe8a15ce1ebe0b4 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 11 Oct 2023 09:14:28 +0200 Subject: [PATCH 499/601] Upgrade Byte Buddy 1.14.8 -> 1.14.9 (#827) See: - https://github.com/raphw/byte-buddy/releases/tag/byte-buddy-1.14.9 - https://github.com/raphw/byte-buddy/compare/byte-buddy-1.14.8...byte-buddy-1.14.9 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 18e4f77501..974fedb0d1 100644 --- a/pom.xml +++ b/pom.xml @@ -382,7 +382,7 @@ net.bytebuddy byte-buddy - 1.14.8 + 1.14.9 From a424a3e94974169723a888a5e456d694ba659985 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 15 Oct 2023 15:24:37 +0200 Subject: [PATCH 506/601] Upgrade Jackson 2.15.2 -> 2.15.3 (#837) See: - https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.15.3 - https://github.com/FasterXML/jackson-bom/compare/jackson-bom-2.15.2...jackson-bom-2.15.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a17cf64635..2c4bba6803 100644 --- a/pom.xml +++ b/pom.xml @@ -268,7 +268,7 @@ com.fasterxml.jackson jackson-bom - 2.15.2 + 2.15.3 pom import From 82c0dd95ce87a6975128831fa3d2a0077ea348a4 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 16 Oct 2023 13:11:57 +0200 Subject: [PATCH 507/601] Build and test against JDK 21 instead of JDK 20 (#832) See https://jdk.java.net/21/release-notes --- .github/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 139047bc13..6b9fba345f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -10,7 +10,7 @@ jobs: strategy: matrix: os: [ ubuntu-22.04 ] - jdk: [ 11.0.20, 17.0.8, 20.0.2 ] + jdk: [ 11.0.20, 17.0.8, 21.0.0 ] distribution: [ temurin ] experimental: [ false ] include: From 3a76f91d1837ccf94babbb0e92223774323840ff Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 18 Oct 2023 08:17:15 +0200 Subject: [PATCH 508/601] Upgrade actions/checkout v4.1.0 -> v4.1.1 (#845) See: - https://github.com/actions/checkout/releases/tag/v4.1.1 --- .github/workflows/build.yaml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/deploy-website.yaml | 2 +- .github/workflows/openssf-scorecard.yml | 2 +- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/pitest-update-pr.yml | 2 +- .github/workflows/sonarcloud.yml | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6b9fba345f..da88764351 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -31,7 +31,7 @@ jobs: # additionally enabling all checks defined in this project and any Error # Prone checks available only from other artifact repositories. - name: Check out code - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: persist-credentials: false - name: Set up JDK diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 489f550d54..03ef52a5ad 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: persist-credentials: false - name: Set up JDK diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index f96ad51c2e..ce5be120b7 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: persist-credentials: false - uses: ruby/setup-ruby@d37167af451eb51448db3354e1057b75c4b268f7 # v1.155.0 diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index e32843e2ee..821ddc72be 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: persist-credentials: false - name: Run OpenSSF Scorecard analysis diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index 4ca50be467..4ded8ed954 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: fetch-depth: 2 persist-credentials: false diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index 02b9223b64..bc7b1ef632 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: persist-credentials: false - name: Set up JDK diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index b39b0b61cf..feaedba873 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-22.04 steps: - name: Check out code - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: fetch-depth: 0 persist-credentials: false From 62077dacbb20d696eee8fe06e6e2f9e123f50dc5 Mon Sep 17 00:00:00 2001 From: Vincent Koeman Date: Wed, 18 Oct 2023 08:59:36 +0200 Subject: [PATCH 509/601] Introduce assorted `BigDecimal#signum` Refaster rules (#812) --- .../refasterrules/BigDecimalRules.java | 58 +++++++++++++++++++ .../BigDecimalRulesTestInput.java | 32 ++++++++++ .../BigDecimalRulesTestOutput.java | 32 ++++++++++ 3 files changed, 122 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java index ca143ad24a..3800828a80 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BigDecimalRules.java @@ -2,6 +2,7 @@ import com.google.errorprone.refaster.Refaster; import com.google.errorprone.refaster.annotation.AfterTemplate; +import com.google.errorprone.refaster.annotation.AlsoNegation; import com.google.errorprone.refaster.annotation.BeforeTemplate; import java.math.BigDecimal; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; @@ -66,4 +67,61 @@ BigDecimal after(double value) { return BigDecimal.valueOf(value); } } + + /** Prefer using {@link BigDecimal#signum()} over more contrived alternatives. */ + static final class BigDecimalSignumIsZero { + @BeforeTemplate + boolean before(BigDecimal value) { + return Refaster.anyOf( + value.compareTo(BigDecimal.ZERO) == 0, BigDecimal.ZERO.compareTo(value) == 0); + } + + @AfterTemplate + @AlsoNegation + boolean after(BigDecimal value) { + return value.signum() == 0; + } + } + + /** + * Prefer a {@link BigDecimal#signum()} comparison to 1 over more contrived or less clear + * alternatives. + */ + static final class BigDecimalSignumIsPositive { + @BeforeTemplate + boolean before(BigDecimal value) { + return Refaster.anyOf( + value.compareTo(BigDecimal.ZERO) > 0, + BigDecimal.ZERO.compareTo(value) < 0, + value.signum() > 0, + value.signum() >= 1); + } + + @AfterTemplate + @AlsoNegation + boolean after(BigDecimal value) { + return value.signum() == 1; + } + } + + /** + * Prefer a {@link BigDecimal#signum()} comparison to -1 over more contrived or less clear + * alternatives. + */ + static final class BigDecimalSignumIsNegative { + @BeforeTemplate + boolean before(BigDecimal value) { + return Refaster.anyOf( + value.compareTo(BigDecimal.ZERO) < 0, + BigDecimal.ZERO.compareTo(value) > 0, + value.signum() < 0, + value.signum() <= -1); + } + + @AfterTemplate + @AlsoNegation + boolean after(BigDecimal value) { + return value.signum() == -1; + } + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java index 4f6a02bfe5..79dcc5ae54 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestInput.java @@ -20,4 +20,36 @@ ImmutableSet testBigDecimalTen() { ImmutableSet testBigDecimalValueOf() { return ImmutableSet.of(new BigDecimal(2), new BigDecimal(2L), new BigDecimal(2.0)); } + + ImmutableSet testBigDecimalSignumIsZero() { + return ImmutableSet.of( + BigDecimal.valueOf(1).compareTo(BigDecimal.ZERO) == 0, + BigDecimal.ZERO.compareTo(BigDecimal.valueOf(2)) == 0, + BigDecimal.valueOf(3).compareTo(BigDecimal.ZERO) != 0, + BigDecimal.ZERO.compareTo(BigDecimal.valueOf(4)) != 0); + } + + ImmutableSet testBigDecimalSignumIsPositive() { + return ImmutableSet.of( + BigDecimal.valueOf(1).compareTo(BigDecimal.ZERO) > 0, + BigDecimal.ZERO.compareTo(BigDecimal.valueOf(2)) < 0, + BigDecimal.valueOf(3).signum() > 0, + BigDecimal.valueOf(4).signum() >= 1, + BigDecimal.valueOf(5).compareTo(BigDecimal.ZERO) <= 0, + BigDecimal.ZERO.compareTo(BigDecimal.valueOf(6)) >= 0, + BigDecimal.valueOf(7).signum() <= 0, + BigDecimal.valueOf(8).signum() < 1); + } + + ImmutableSet testBigDecimalSignumIsNegative() { + return ImmutableSet.of( + BigDecimal.valueOf(1).compareTo(BigDecimal.ZERO) < 0, + BigDecimal.ZERO.compareTo(BigDecimal.valueOf(2)) > 0, + BigDecimal.valueOf(3).signum() < 0, + BigDecimal.valueOf(4).signum() <= -1, + BigDecimal.valueOf(5).compareTo(BigDecimal.ZERO) >= 0, + BigDecimal.ZERO.compareTo(BigDecimal.valueOf(6)) <= 0, + BigDecimal.valueOf(7).signum() >= 0, + BigDecimal.valueOf(8).signum() > -1); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java index 37c226eb7a..ea73698f76 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BigDecimalRulesTestOutput.java @@ -20,4 +20,36 @@ ImmutableSet testBigDecimalTen() { ImmutableSet testBigDecimalValueOf() { return ImmutableSet.of(BigDecimal.valueOf(2), BigDecimal.valueOf(2L), BigDecimal.valueOf(2.0)); } + + ImmutableSet testBigDecimalSignumIsZero() { + return ImmutableSet.of( + BigDecimal.valueOf(1).signum() == 0, + BigDecimal.valueOf(2).signum() == 0, + BigDecimal.valueOf(3).signum() != 0, + BigDecimal.valueOf(4).signum() != 0); + } + + ImmutableSet testBigDecimalSignumIsPositive() { + return ImmutableSet.of( + BigDecimal.valueOf(1).signum() == 1, + BigDecimal.valueOf(2).signum() == 1, + BigDecimal.valueOf(3).signum() == 1, + BigDecimal.valueOf(4).signum() == 1, + BigDecimal.valueOf(5).signum() != 1, + BigDecimal.valueOf(6).signum() != 1, + BigDecimal.valueOf(7).signum() != 1, + BigDecimal.valueOf(8).signum() != 1); + } + + ImmutableSet testBigDecimalSignumIsNegative() { + return ImmutableSet.of( + BigDecimal.valueOf(1).signum() == -1, + BigDecimal.valueOf(2).signum() == -1, + BigDecimal.valueOf(3).signum() == -1, + BigDecimal.valueOf(4).signum() == -1, + BigDecimal.valueOf(5).signum() != -1, + BigDecimal.valueOf(6).signum() != -1, + BigDecimal.valueOf(7).signum() != -1, + BigDecimal.valueOf(8).signum() != -1); + } } From 7a7a09d20840ef6821b979d0ed61ae1d9fce1481 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 18 Oct 2023 09:13:28 +0200 Subject: [PATCH 510/601] Upgrade jacoco-maven-plugin 0.8.10 -> 0.8.11 (#843) See: - https://github.com/jacoco/jacoco/releases/tag/v0.8.11 - https://github.com/jacoco/jacoco/compare/v0.8.10...v0.8.11 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2c4bba6803..672cc03626 100644 --- a/pom.xml +++ b/pom.xml @@ -1345,7 +1345,7 @@ org.jacoco jacoco-maven-plugin - 0.8.10 + 0.8.11 - ${project.groupId}:refaster-support - - - diff --git a/pom.xml b/pom.xml index 7d7e6f9e5f..34c7df3e17 100644 --- a/pom.xml +++ b/pom.xml @@ -1033,18 +1033,7 @@ - - - - com.google.truth:truth - - + @@ -1738,11 +1727,8 @@ -XepOpt:NullAway:CheckOptionalEmptiness=true -XepOpt:Nullness:Conservative=false -XepOpt:StatementSwitchToExpressionSwitch:EnableAssignmentSwitchConversion=true + -XepOpt:StatementSwitchToExpressionSwitch:EnableDirectConversion=true -XepOpt:StatementSwitchToExpressionSwitch:EnableReturnSwitchConversion=true - ${error-prone.patch-args} ${error-prone.self-check-args} From 01b30d767b4033e05c1dbd033bfeacbdde96ef2d Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Tue, 24 Oct 2023 13:57:37 +0200 Subject: [PATCH 520/601] Introduce `BugPatternTestExtractor` for documentation generation (#494) This new `Extractor` implementation collects identification and replacement source code from `BugChecker` unit tests. While there: - Refactor the existing `Extractor` setup such that instances are service-loaded and need to implement only a single method, thereby avoiding the need to align logic between multiple source code locations. - Extend the validation performed by the `Compilation` test helper class. - Extend the `ErrorProneTestHelperSourceFormat` check to support source code passed to the `Compilation` test helper class. --- .../documentation/BugPatternExtractor.java | 52 +- .../BugPatternTestExtractor.java | 229 +++++++++ .../DocumentationGeneratorTaskListener.java | 36 +- .../errorprone/documentation/Extractor.java | 24 +- .../documentation/ExtractorType.java | 36 -- .../BugPatternExtractorTest.java | 69 +-- .../BugPatternTestExtractorTest.java | 468 ++++++++++++++++++ .../errorprone/documentation/Compilation.java | 45 +- ...ocumentationGeneratorTaskListenerTest.java | 62 +++ ...orTest-bugpattern-CompleteBugChecker.json} | 0 ...torTest-bugpattern-MinimalBugChecker.json} | 0 ...rn-UndocumentedSuppressionBugPattern.json} | 0 ...dBugCheckerRefactoringTestHelpersTest.json | 24 + ...sWithCustomCheckerPackageAndNamesTest.json | 24 + ...leBugCheckerRefactoringTestHelperTest.json | 20 + ...st-MultiFileCompilationTestHelperTest.json | 18 + ...leBugCheckerRefactoringTestHelperTest.json | 15 + ...etArgsFixChooserAndCustomTestModeTest.json | 15 + ...t-SingleFileCompilationTestHelperTest.json | 14 + ...eCompilationTestHelperWithSetArgsTest.json | 14 + .../ErrorProneTestHelperSourceFormat.java | 14 +- 21 files changed, 1033 insertions(+), 146 deletions(-) create mode 100644 documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternTestExtractor.java delete mode 100644 documentation-support/src/main/java/tech/picnic/errorprone/documentation/ExtractorType.java create mode 100644 documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest.java rename documentation-support/src/test/resources/tech/picnic/errorprone/documentation/{bugpattern-documentation-complete.json => BugPatternExtractorTest-bugpattern-CompleteBugChecker.json} (100%) rename documentation-support/src/test/resources/tech/picnic/errorprone/documentation/{bugpattern-documentation-minimal.json => BugPatternExtractorTest-bugpattern-MinimalBugChecker.json} (100%) rename documentation-support/src/test/resources/tech/picnic/errorprone/documentation/{bugpattern-documentation-undocumented-suppression.json => BugPatternExtractorTest-bugpattern-UndocumentedSuppressionBugPattern.json} (100%) create mode 100644 documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-CompilationAndBugCheckerRefactoringTestHelpersTest.json create mode 100644 documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-CompilationAndBugCheckerRefactoringTestHelpersWithCustomCheckerPackageAndNamesTest.json create mode 100644 documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-MultiFileBugCheckerRefactoringTestHelperTest.json create mode 100644 documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-MultiFileCompilationTestHelperTest.json create mode 100644 documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileBugCheckerRefactoringTestHelperTest.json create mode 100644 documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileBugCheckerRefactoringTestHelperWithSetArgsFixChooserAndCustomTestModeTest.json create mode 100644 documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileCompilationTestHelperTest.json create mode 100644 documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileCompilationTestHelperWithSetArgsTest.json diff --git a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternExtractor.java b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternExtractor.java index 071b3f91d0..4f21588744 100644 --- a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternExtractor.java +++ b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternExtractor.java @@ -5,17 +5,19 @@ import static java.util.Objects.requireNonNull; import com.google.auto.common.AnnotationMirrors; +import com.google.auto.service.AutoService; import com.google.auto.value.AutoValue; import com.google.common.collect.ImmutableList; import com.google.errorprone.BugPattern; import com.google.errorprone.BugPattern.SeverityLevel; +import com.google.errorprone.VisitorState; import com.google.errorprone.annotations.Immutable; import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.AnnotationTree; import com.sun.source.tree.ClassTree; import com.sun.tools.javac.code.Attribute; import com.sun.tools.javac.code.Symbol.ClassSymbol; -import com.sun.tools.javac.util.Context; +import java.util.Optional; import javax.lang.model.element.AnnotationValue; import tech.picnic.errorprone.documentation.BugPatternExtractor.BugPatternDocumentation; @@ -23,29 +25,39 @@ * An {@link Extractor} that describes how to extract data from a {@code @BugPattern} annotation. */ @Immutable -final class BugPatternExtractor implements Extractor { +@AutoService(Extractor.class) +@SuppressWarnings("rawtypes" /* See https://github.com/google/auto/issues/870. */) +public final class BugPatternExtractor implements Extractor { + /** Instantiates a new {@link BugPatternExtractor} instance. */ + public BugPatternExtractor() {} + @Override - public BugPatternDocumentation extract(ClassTree tree, Context context) { - ClassSymbol symbol = ASTHelpers.getSymbol(tree); - BugPattern annotation = symbol.getAnnotation(BugPattern.class); - requireNonNull(annotation, "BugPattern annotation must be present"); - - return new AutoValue_BugPatternExtractor_BugPatternDocumentation( - symbol.getQualifiedName().toString(), - annotation.name().isEmpty() ? tree.getSimpleName().toString() : annotation.name(), - ImmutableList.copyOf(annotation.altNames()), - annotation.link(), - ImmutableList.copyOf(annotation.tags()), - annotation.summary(), - annotation.explanation(), - annotation.severity(), - annotation.disableable(), - annotation.documentSuppression() ? getSuppressionAnnotations(tree) : ImmutableList.of()); + public String identifier() { + return "bugpattern"; } @Override - public boolean canExtract(ClassTree tree) { - return ASTHelpers.hasDirectAnnotationWithSimpleName(tree, BugPattern.class.getSimpleName()); + public Optional tryExtract(ClassTree tree, VisitorState state) { + ClassSymbol symbol = ASTHelpers.getSymbol(tree); + BugPattern annotation = symbol.getAnnotation(BugPattern.class); + if (annotation == null) { + return Optional.empty(); + } + + return Optional.of( + new AutoValue_BugPatternExtractor_BugPatternDocumentation( + symbol.getQualifiedName().toString(), + annotation.name().isEmpty() ? tree.getSimpleName().toString() : annotation.name(), + ImmutableList.copyOf(annotation.altNames()), + annotation.link(), + ImmutableList.copyOf(annotation.tags()), + annotation.summary(), + annotation.explanation(), + annotation.severity(), + annotation.disableable(), + annotation.documentSuppression() + ? getSuppressionAnnotations(tree) + : ImmutableList.of())); } /** diff --git a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternTestExtractor.java b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternTestExtractor.java new file mode 100644 index 0000000000..cf7f7a0b0e --- /dev/null +++ b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternTestExtractor.java @@ -0,0 +1,229 @@ +package tech.picnic.errorprone.documentation; + +import static com.google.errorprone.matchers.Matchers.instanceMethod; +import static com.google.errorprone.matchers.method.MethodMatchers.staticMethod; +import static java.util.function.Predicate.not; + +import com.google.auto.service.AutoService; +import com.google.auto.value.AutoValue; +import com.google.common.collect.ImmutableList; +import com.google.errorprone.VisitorState; +import com.google.errorprone.annotations.Immutable; +import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.util.ASTHelpers; +import com.sun.source.tree.ClassTree; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.MethodInvocationTree; +import com.sun.source.util.TreeScanner; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.jspecify.annotations.Nullable; +import tech.picnic.errorprone.documentation.BugPatternTestExtractor.TestCases; + +/** + * An {@link Extractor} that describes how to extract data from classes that test a {@code + * BugChecker}. + */ +// XXX: Handle other methods from `{BugCheckerRefactoring,Compilation}TestHelper`: +// - Indicate which custom arguments are specified, if any. +// - For replacement tests, indicate which `FixChooser` is used. +// - ... (We don't use all optional features; TBD what else to support.) +@Immutable +@AutoService(Extractor.class) +@SuppressWarnings("rawtypes" /* See https://github.com/google/auto/issues/870. */) +public final class BugPatternTestExtractor implements Extractor { + /** Instantiates a new {@link BugPatternTestExtractor} instance. */ + public BugPatternTestExtractor() {} + + @Override + public String identifier() { + return "bugpattern-test"; + } + + @Override + public Optional tryExtract(ClassTree tree, VisitorState state) { + BugPatternTestCollector collector = new BugPatternTestCollector(); + + collector.scan(tree, state); + + return Optional.of(collector.getCollectedTests()) + .filter(not(ImmutableList::isEmpty)) + .map( + tests -> + new AutoValue_BugPatternTestExtractor_TestCases( + ASTHelpers.getSymbol(tree).className(), tests)); + } + + private static final class BugPatternTestCollector + extends TreeScanner<@Nullable Void, VisitorState> { + private static final Matcher COMPILATION_HELPER_DO_TEST = + instanceMethod() + .onDescendantOf("com.google.errorprone.CompilationTestHelper") + .named("doTest"); + private static final Matcher TEST_HELPER_NEW_INSTANCE = + staticMethod() + .onDescendantOfAny( + "com.google.errorprone.CompilationTestHelper", + "com.google.errorprone.BugCheckerRefactoringTestHelper") + .named("newInstance") + .withParameters("java.lang.Class", "java.lang.Class"); + private static final Matcher IDENTIFICATION_SOURCE_LINES = + instanceMethod() + .onDescendantOf("com.google.errorprone.CompilationTestHelper") + .named("addSourceLines"); + private static final Matcher REPLACEMENT_DO_TEST = + instanceMethod() + .onDescendantOf("com.google.errorprone.BugCheckerRefactoringTestHelper") + .named("doTest"); + private static final Matcher REPLACEMENT_EXPECT_UNCHANGED = + instanceMethod() + .onDescendantOf("com.google.errorprone.BugCheckerRefactoringTestHelper.ExpectOutput") + .named("expectUnchanged"); + private static final Matcher REPLACEMENT_OUTPUT_SOURCE_LINES = + instanceMethod() + .onDescendantOf("com.google.errorprone.BugCheckerRefactoringTestHelper.ExpectOutput") + .namedAnyOf("addOutputLines", "expectUnchanged"); + + private final List collectedTestCases = new ArrayList<>(); + + private ImmutableList getCollectedTests() { + return ImmutableList.copyOf(collectedTestCases); + } + + @Override + public @Nullable Void visitMethodInvocation(MethodInvocationTree node, VisitorState state) { + boolean isReplacementTest = REPLACEMENT_DO_TEST.matches(node, state); + if (isReplacementTest || COMPILATION_HELPER_DO_TEST.matches(node, state)) { + getClassUnderTest(node, state) + .ifPresent( + classUnderTest -> { + List entries = new ArrayList<>(); + if (isReplacementTest) { + extractReplacementTestCases(node, entries, state); + } else { + extractIdentificationTestCases(node, entries, state); + } + + if (!entries.isEmpty()) { + collectedTestCases.add( + new AutoValue_BugPatternTestExtractor_TestCase( + classUnderTest, ImmutableList.copyOf(entries).reverse())); + } + }); + } + + return super.visitMethodInvocation(node, state); + } + + private static Optional getClassUnderTest( + MethodInvocationTree tree, VisitorState state) { + if (TEST_HELPER_NEW_INSTANCE.matches(tree, state)) { + return Optional.ofNullable(ASTHelpers.getSymbol(tree.getArguments().get(0))) + .filter(s -> !s.type.allparams().isEmpty()) + .map(s -> s.type.allparams().get(0).tsym.getQualifiedName().toString()); + } + + ExpressionTree receiver = ASTHelpers.getReceiver(tree); + return receiver instanceof MethodInvocationTree + ? getClassUnderTest((MethodInvocationTree) receiver, state) + : Optional.empty(); + } + + private static void extractIdentificationTestCases( + MethodInvocationTree tree, List sink, VisitorState state) { + if (IDENTIFICATION_SOURCE_LINES.matches(tree, state)) { + String path = ASTHelpers.constValue(tree.getArguments().get(0), String.class); + Optional sourceCode = + getSourceCode(tree).filter(s -> s.contains("// BUG: Diagnostic")); + if (path != null && sourceCode.isPresent()) { + sink.add( + new AutoValue_BugPatternTestExtractor_IdentificationTestEntry( + path, sourceCode.orElseThrow())); + } + } + + ExpressionTree receiver = ASTHelpers.getReceiver(tree); + if (receiver instanceof MethodInvocationTree) { + extractIdentificationTestCases((MethodInvocationTree) receiver, sink, state); + } + } + + private static void extractReplacementTestCases( + MethodInvocationTree tree, List sink, VisitorState state) { + if (REPLACEMENT_OUTPUT_SOURCE_LINES.matches(tree, state)) { + /* + * Retrieve the method invocation that contains the input source code. Note that this cast + * is safe, because this code is guarded by an earlier call to `#getClassUnderTest(..)`, + * which ensures that `tree` is part of a longer method invocation chain. + */ + MethodInvocationTree inputTree = (MethodInvocationTree) ASTHelpers.getReceiver(tree); + + String path = ASTHelpers.constValue(inputTree.getArguments().get(0), String.class); + Optional inputCode = getSourceCode(inputTree); + if (path != null && inputCode.isPresent()) { + Optional outputCode = + REPLACEMENT_EXPECT_UNCHANGED.matches(tree, state) ? inputCode : getSourceCode(tree); + + if (outputCode.isPresent() && !inputCode.equals(outputCode)) { + sink.add( + new AutoValue_BugPatternTestExtractor_ReplacementTestEntry( + path, inputCode.orElseThrow(), outputCode.orElseThrow())); + } + } + } + + ExpressionTree receiver = ASTHelpers.getReceiver(tree); + if (receiver instanceof MethodInvocationTree) { + extractReplacementTestCases((MethodInvocationTree) receiver, sink, state); + } + } + + // XXX: This logic is duplicated in `ErrorProneTestSourceFormat`. Can we do better? + private static Optional getSourceCode(MethodInvocationTree tree) { + List sourceLines = + tree.getArguments().subList(1, tree.getArguments().size()); + StringBuilder source = new StringBuilder(); + + for (ExpressionTree sourceLine : sourceLines) { + String value = ASTHelpers.constValue(sourceLine, String.class); + if (value == null) { + return Optional.empty(); + } + source.append(value).append('\n'); + } + + return Optional.of(source.toString()); + } + } + + @AutoValue + abstract static class TestCases { + abstract String testClass(); + + abstract ImmutableList testCases(); + } + + @AutoValue + abstract static class TestCase { + abstract String classUnderTest(); + + abstract ImmutableList entries(); + } + + interface TestEntry { + String path(); + } + + @AutoValue + abstract static class ReplacementTestEntry implements TestEntry { + abstract String input(); + + abstract String output(); + } + + @AutoValue + abstract static class IdentificationTestEntry implements TestEntry { + abstract String code(); + } +} diff --git a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListener.java b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListener.java index 29fa2203d2..07261650ee 100644 --- a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListener.java +++ b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListener.java @@ -5,10 +5,14 @@ import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableList; +import com.google.errorprone.VisitorState; import com.sun.source.tree.ClassTree; +import com.sun.source.tree.CompilationUnitTree; import com.sun.source.util.TaskEvent; import com.sun.source.util.TaskEvent.Kind; import com.sun.source.util.TaskListener; +import com.sun.source.util.TreePath; import com.sun.tools.javac.api.JavacTrees; import com.sun.tools.javac.util.Context; import java.io.File; @@ -19,6 +23,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ServiceLoader; import javax.tools.JavaFileObject; /** @@ -27,6 +32,13 @@ */ // XXX: Find a better name for this class; it doesn't generate documentation per se. final class DocumentationGeneratorTaskListener implements TaskListener { + @SuppressWarnings({"rawtypes", "unchecked"}) + private static final ImmutableList> EXTRACTORS = + (ImmutableList) + ImmutableList.copyOf( + ServiceLoader.load( + Extractor.class, DocumentationGeneratorTaskListener.class.getClassLoader())); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().setVisibility(PropertyAccessor.FIELD, Visibility.ANY); @@ -51,19 +63,25 @@ public void finished(TaskEvent taskEvent) { return; } - ClassTree classTree = JavacTrees.instance(context).getTree(taskEvent.getTypeElement()); JavaFileObject sourceFile = taskEvent.getSourceFile(); - if (classTree == null || sourceFile == null) { + CompilationUnitTree compilationUnit = taskEvent.getCompilationUnit(); + ClassTree classTree = JavacTrees.instance(context).getTree(taskEvent.getTypeElement()); + if (sourceFile == null || compilationUnit == null || classTree == null) { return; } - ExtractorType.findMatchingType(classTree) - .ifPresent( - extractorType -> - writeToFile( - extractorType.getIdentifier(), - getSimpleClassName(sourceFile.toUri()), - extractorType.getExtractor().extract(classTree, context))); + VisitorState state = + VisitorState.createForUtilityPurposes(context) + .withPath(new TreePath(new TreePath(compilationUnit), classTree)); + + for (Extractor extractor : EXTRACTORS) { + extractor + .tryExtract(classTree, state) + .ifPresent( + data -> + writeToFile( + extractor.identifier(), getSimpleClassName(sourceFile.toUri()), data)); + } } private void createDocsDirectory() { diff --git a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/Extractor.java b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/Extractor.java index 210c84ab94..4a746fe0db 100644 --- a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/Extractor.java +++ b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/Extractor.java @@ -1,8 +1,9 @@ package tech.picnic.errorprone.documentation; +import com.google.errorprone.VisitorState; import com.google.errorprone.annotations.Immutable; import com.sun.source.tree.ClassTree; -import com.sun.tools.javac.util.Context; +import java.util.Optional; /** * Interface implemented by classes that define how to extract data of some type {@link T} from a @@ -13,21 +14,20 @@ @Immutable interface Extractor { /** - * Extracts and returns an instance of {@link T} using the provided arguments. + * Returns the unique identifier of this extractor. * - * @param tree The {@link ClassTree} to analyze and from which to extract instances of {@link T}. - * @param context The {@link Context} in which the current compilation takes place. - * @return A non-null instance of {@link T}. + * @return A non-{@code null} string. */ - // XXX: Drop `Context` parameter unless used. - T extract(ClassTree tree, Context context); + String identifier(); /** - * Tells whether this {@link Extractor} can extract documentation content from the given {@link - * ClassTree}. + * Attempts to extract an instance of type {@link T} using the provided arguments. * - * @param tree The {@link ClassTree} of interest. - * @return {@code true} iff data extraction is supported. + * @param tree The {@link ClassTree} to analyze and from which to extract an instance of type + * {@link T}. + * @param state A {@link VisitorState} describing the context in which the given {@link ClassTree} + * is found. + * @return An instance of type {@link T}, if possible. */ - boolean canExtract(ClassTree tree); + Optional tryExtract(ClassTree tree, VisitorState state); } diff --git a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/ExtractorType.java b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/ExtractorType.java deleted file mode 100644 index 8ba9e8b8d0..0000000000 --- a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/ExtractorType.java +++ /dev/null @@ -1,36 +0,0 @@ -package tech.picnic.errorprone.documentation; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; -import com.sun.source.tree.ClassTree; -import java.util.EnumSet; -import java.util.Optional; - -/** An enumeration of {@link Extractor} types. */ -enum ExtractorType { - BUG_PATTERN("bugpattern", new BugPatternExtractor()); - - private static final ImmutableSet TYPES = - Sets.immutableEnumSet(EnumSet.allOf(ExtractorType.class)); - - private final String identifier; - private final Extractor extractor; - - ExtractorType(String identifier, Extractor extractor) { - this.identifier = identifier; - this.extractor = extractor; - } - - String getIdentifier() { - return identifier; - } - - @SuppressWarnings("java:S1452" /* The extractor returns data of an unspecified type. */) - Extractor getExtractor() { - return extractor; - } - - static Optional findMatchingType(ClassTree tree) { - return TYPES.stream().filter(type -> type.getExtractor().canExtract(tree)).findFirst(); - } -} diff --git a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternExtractorTest.java b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternExtractorTest.java index da6467c78d..137b2aa88e 100644 --- a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternExtractorTest.java +++ b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternExtractorTest.java @@ -1,18 +1,9 @@ package tech.picnic.errorprone.documentation; -import static com.google.errorprone.BugPattern.SeverityLevel.ERROR; import static java.nio.charset.StandardCharsets.UTF_8; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import com.google.common.io.Resources; -import com.google.errorprone.BugPattern; -import com.google.errorprone.CompilationTestHelper; -import com.google.errorprone.VisitorState; -import com.google.errorprone.bugpatterns.BugChecker; -import com.google.errorprone.bugpatterns.BugChecker.ClassTreeMatcher; -import com.google.errorprone.matchers.Description; -import com.sun.source.tree.ClassTree; import java.io.IOException; import java.nio.file.Path; import org.junit.jupiter.api.Test; @@ -45,10 +36,7 @@ void minimalBugPattern(@TempDir Path outputDirectory) throws IOException { "@BugPattern(summary = \"MinimalBugChecker summary\", severity = SeverityLevel.ERROR)", "public final class MinimalBugChecker extends BugChecker {}"); - verifyFileMatchesResource( - outputDirectory, - "bugpattern-MinimalBugChecker.json", - "bugpattern-documentation-minimal.json"); + verifyGeneratedFileContent(outputDirectory, "MinimalBugChecker"); } @Test @@ -76,10 +64,7 @@ void completeBugPattern(@TempDir Path outputDirectory) throws IOException { " suppressionAnnotations = {BugPattern.class, Test.class})", "public final class CompleteBugChecker extends BugChecker {}"); - verifyFileMatchesResource( - outputDirectory, - "bugpattern-CompleteBugChecker.json", - "bugpattern-documentation-complete.json"); + verifyGeneratedFileContent(outputDirectory, "CompleteBugChecker"); } @Test @@ -99,55 +84,23 @@ void undocumentedSuppressionBugPattern(@TempDir Path outputDirectory) throws IOE " documentSuppression = false)", "public final class UndocumentedSuppressionBugPattern extends BugChecker {}"); - verifyFileMatchesResource( - outputDirectory, - "bugpattern-UndocumentedSuppressionBugPattern.json", - "bugpattern-documentation-undocumented-suppression.json"); - } - - @Test - void bugPatternAnnotationIsAbsent() { - CompilationTestHelper.newInstance(TestChecker.class, getClass()) - .addSourceLines( - "TestChecker.java", - "import com.google.errorprone.bugpatterns.BugChecker;", - "", - "// BUG: Diagnostic contains: Can extract: false", - "public final class TestChecker extends BugChecker {}") - .doTest(); + verifyGeneratedFileContent(outputDirectory, "UndocumentedSuppressionBugPattern"); } - private static void verifyFileMatchesResource( - Path outputDirectory, String fileName, String resourceName) throws IOException { - assertThat(outputDirectory.resolve(fileName)) + private static void verifyGeneratedFileContent(Path outputDirectory, String testClass) + throws IOException { + String resourceName = String.format("bugpattern-%s.json", testClass); + assertThat(outputDirectory.resolve(resourceName)) .content(UTF_8) - .isEqualToIgnoringWhitespace(getResource(resourceName)); + .isEqualToIgnoringWhitespace( + getResource( + String.join("-", BugPatternExtractorTest.class.getSimpleName(), resourceName))); } // XXX: Once we support only JDK 15+, drop this method in favour of including the resources as - // text blocks in this class. (This also requires renaming the `verifyFileMatchesResource` - // method.) + // text blocks in this class. private static String getResource(String resourceName) throws IOException { return Resources.toString( Resources.getResource(BugPatternExtractorTest.class, resourceName), UTF_8); } - - /** A {@link BugChecker} that validates the {@link BugPatternExtractor}. */ - @BugPattern(summary = "Validates `BugPatternExtractor` extraction", severity = ERROR) - public static final class TestChecker extends BugChecker implements ClassTreeMatcher { - private static final long serialVersionUID = 1L; - - @Override - public Description matchClass(ClassTree tree, VisitorState state) { - BugPatternExtractor extractor = new BugPatternExtractor(); - - assertThatThrownBy(() -> extractor.extract(tree, state.context)) - .isInstanceOf(NullPointerException.class) - .hasMessage("BugPattern annotation must be present"); - - return buildDescription(tree) - .setMessage(String.format("Can extract: %s", extractor.canExtract(tree))) - .build(); - } - } } diff --git a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest.java b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest.java new file mode 100644 index 0000000000..ecd6d2032c --- /dev/null +++ b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest.java @@ -0,0 +1,468 @@ +package tech.picnic.errorprone.documentation; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.common.io.Resources; +import java.io.IOException; +import java.nio.file.Path; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +final class BugPatternTestExtractorTest { + @Test + void noTestClass(@TempDir Path outputDirectory) { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "TestCheckerWithoutAnnotation.java", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "public final class TestCheckerWithoutAnnotation extends BugChecker {}"); + + assertThat(outputDirectory.toAbsolutePath()).isEmptyDirectory(); + } + + @Test + void noDoTestInvocation(@TempDir Path outputDirectory) { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "TestCheckerTest.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class TestCheckerTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " CompilationTestHelper.newInstance(TestChecker.class, getClass())", + " .addSourceLines(\"A.java\", \"// BUG: Diagnostic contains:\", \"class A {}\");", + "", + " BugCheckerRefactoringTestHelper.newInstance(TestChecker.class, getClass())", + " .addInputLines(\"A.java\", \"class A {}\")", + " .addOutputLines(\"A.java\", \"class A { /* This is a change. */ }\");", + " }", + "}"); + + assertThat(outputDirectory.toAbsolutePath()).isEmptyDirectory(); + } + + @Test + void nullBugCheckerInstance(@TempDir Path outputDirectory) { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "TestCheckerTest.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class TestCheckerTest {", + " void m() {", + " CompilationTestHelper.newInstance((Class) null, getClass())", + " .addSourceLines(\"A.java\", \"// BUG: Diagnostic contains:\", \"class A {}\")", + " .doTest();", + "", + " BugCheckerRefactoringTestHelper.newInstance((Class) null, getClass())", + " .addInputLines(\"A.java\", \"class A {}\")", + " .addOutputLines(\"A.java\", \"class A { /* This is a change. */ }\")", + " .doTest();", + " }", + "}"); + + assertThat(outputDirectory.toAbsolutePath()).isEmptyDirectory(); + } + + @Test + void rawBugCheckerInstance(@TempDir Path outputDirectory) { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "TestCheckerTest.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class TestCheckerTest {", + " private static class TestChecker extends BugChecker {}", + "", + " @SuppressWarnings(\"unchecked\")", + " void m() {", + " @SuppressWarnings(\"rawtypes\")", + " Class bugChecker = TestChecker.class;", + "", + " CompilationTestHelper.newInstance(bugChecker, getClass())", + " .addSourceLines(\"A.java\", \"// BUG: Diagnostic contains:\", \"class A {}\")", + " .doTest();", + "", + " BugCheckerRefactoringTestHelper.newInstance(bugChecker, getClass())", + " .addInputLines(\"A.java\", \"class A {}\")", + " .addOutputLines(\"A.java\", \"class A { /* This is a change. */ }\")", + " .doTest();", + " }", + "}"); + + assertThat(outputDirectory.toAbsolutePath()).isEmptyDirectory(); + } + + @Test + void scannerSupplierInstance(@TempDir Path outputDirectory) { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "TestCheckerTest.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "import com.google.errorprone.scanner.ScannerSupplier;", + "", + "final class TestCheckerTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " CompilationTestHelper.newInstance(", + " ScannerSupplier.fromBugCheckerClasses(TestChecker.class), getClass())", + " .addSourceLines(\"A.java\", \"// BUG: Diagnostic contains:\", \"class A {}\")", + " .doTest();", + "", + " BugCheckerRefactoringTestHelper.newInstance(", + " ScannerSupplier.fromBugCheckerClasses(TestChecker.class), getClass())", + " .addInputLines(\"A.java\", \"class A {}\")", + " .addOutputLines(\"A.java\", \"class A { /* This is a change. */ }\")", + " .doTest();", + " }", + "}"); + + assertThat(outputDirectory.toAbsolutePath()).isEmptyDirectory(); + } + + @Test + void nonCompileTimeConstantStrings(@TempDir Path outputDirectory) { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "TestCheckerTest.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class TestCheckerTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " CompilationTestHelper.newInstance(TestChecker.class, getClass())", + " .addSourceLines(toString() + \"A.java\", \"// BUG: Diagnostic contains:\", \"class A {}\")", + " .addSourceLines(\"B.java\", \"// BUG: Diagnostic contains:\", \"class B {}\", toString())", + " .doTest();", + "", + " BugCheckerRefactoringTestHelper.newInstance(TestChecker.class, getClass())", + " .addInputLines(toString() + \"A.java\", \"class A {}\")", + " .addOutputLines(\"A.java\", \"class A { /* This is a change. */ }\")", + " .addInputLines(\"B.java\", \"class B {}\", toString())", + " .addOutputLines(\"B.java\", \"class B { /* This is a change. */ }\")", + " .addInputLines(\"C.java\", \"class C {}\")", + " .addOutputLines(\"C.java\", \"class C { /* This is a change. */ }\", toString())", + " .doTest();", + " }", + "}"); + + assertThat(outputDirectory.toAbsolutePath()).isEmptyDirectory(); + } + + @Test + void nonFluentTestHelperExpressions(@TempDir Path outputDirectory) { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "TestCheckerTest.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class TestCheckerTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " CompilationTestHelper testHelper =", + " CompilationTestHelper.newInstance(TestChecker.class, getClass())", + " .addSourceLines(\"A.java\", \"class A {}\");", + " testHelper.doTest();", + "", + " BugCheckerRefactoringTestHelper.ExpectOutput expectedOutput =", + " BugCheckerRefactoringTestHelper.newInstance(TestChecker.class, getClass())", + " .addInputLines(\"A.java\", \"class A {}\");", + " expectedOutput.addOutputLines(\"A.java\", \"class A {}\").doTest();", + " expectedOutput.expectUnchanged().doTest();", + " }", + "}"); + + assertThat(outputDirectory.toAbsolutePath()).isEmptyDirectory(); + } + + @Test + void noSource(@TempDir Path outputDirectory) { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "TestCheckerTest.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class TestCheckerTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " CompilationTestHelper.newInstance(TestChecker.class, getClass()).doTest();", + "", + " BugCheckerRefactoringTestHelper.newInstance(TestChecker.class, getClass()).doTest();", + " }", + "}"); + + assertThat(outputDirectory.toAbsolutePath()).isEmptyDirectory(); + } + + @Test + void noDiagnostics(@TempDir Path outputDirectory) { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "TestCheckerTest.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class TestCheckerTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " CompilationTestHelper.newInstance(TestChecker.class, getClass())", + " .addSourceLines(\"A.java\", \"class A {}\")", + " .doTest();", + "", + " BugCheckerRefactoringTestHelper.newInstance(TestChecker.class, getClass())", + " .addInputLines(\"A.java\", \"class A {}\")", + " .addOutputLines(\"A.java\", \"class A {}\")", + " .addInputLines(\"B.java\", \"class B {}\")", + " .expectUnchanged()", + " .doTest();", + " }", + "}"); + + assertThat(outputDirectory.toAbsolutePath()).isEmptyDirectory(); + } + + @Test + void singleFileCompilationTestHelper(@TempDir Path outputDirectory) throws IOException { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "SingleFileCompilationTestHelperTest.java", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class SingleFileCompilationTestHelperTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " CompilationTestHelper.newInstance(TestChecker.class, getClass())", + " .addSourceLines(\"A.java\", \"// BUG: Diagnostic contains:\", \"class A {}\")", + " .doTest();", + " }", + "}"); + + verifyGeneratedFileContent(outputDirectory, "SingleFileCompilationTestHelperTest"); + } + + @Test + void singleFileCompilationTestHelperWithSetArgs(@TempDir Path outputDirectory) + throws IOException { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "SingleFileCompilationTestHelperWithSetArgsTest.java", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class SingleFileCompilationTestHelperWithSetArgsTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " CompilationTestHelper.newInstance(TestChecker.class, getClass())", + " .setArgs(\"-XepAllSuggestionsAsWarnings\")", + " .addSourceLines(\"A.java\", \"// BUG: Diagnostic contains:\", \"class A {}\")", + " .doTest();", + " }", + "}"); + + verifyGeneratedFileContent(outputDirectory, "SingleFileCompilationTestHelperWithSetArgsTest"); + } + + @Test + void multiFileCompilationTestHelper(@TempDir Path outputDirectory) throws IOException { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "MultiFileCompilationTestHelperTest.java", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class MultiFileCompilationTestHelperTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " CompilationTestHelper.newInstance(TestChecker.class, getClass())", + " .addSourceLines(\"A.java\", \"// BUG: Diagnostic contains:\", \"class A {}\")", + " .addSourceLines(\"B.java\", \"// BUG: Diagnostic contains:\", \"class B {}\")", + " .doTest();", + " }", + "}"); + + verifyGeneratedFileContent(outputDirectory, "MultiFileCompilationTestHelperTest"); + } + + @Test + void singleFileBugCheckerRefactoringTestHelper(@TempDir Path outputDirectory) throws IOException { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "SingleFileBugCheckerRefactoringTestHelperTest.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class SingleFileBugCheckerRefactoringTestHelperTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " BugCheckerRefactoringTestHelper.newInstance(TestChecker.class, getClass())", + " .addInputLines(\"A.java\", \"class A {}\")", + " .addOutputLines(\"A.java\", \"class A { /* This is a change. */ }\")", + " .doTest();", + " }", + "}"); + + verifyGeneratedFileContent(outputDirectory, "SingleFileBugCheckerRefactoringTestHelperTest"); + } + + @Test + void singleFileBugCheckerRefactoringTestHelperWithSetArgsFixChooserAndCustomTestMode( + @TempDir Path outputDirectory) throws IOException { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "SingleFileBugCheckerRefactoringTestHelperWithSetArgsFixChooserAndCustomTestModeTest.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers;", + "import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class SingleFileBugCheckerRefactoringTestHelperWithSetArgsFixChooserAndCustomTestModeTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " BugCheckerRefactoringTestHelper.newInstance(TestChecker.class, getClass())", + " .setArgs(\"-XepAllSuggestionsAsWarnings\")", + " .setFixChooser(FixChoosers.SECOND)", + " .addInputLines(\"A.java\", \"class A {}\")", + " .addOutputLines(\"A.java\", \"class A { /* This is a change. */ }\")", + " .doTest(TestMode.TEXT_MATCH);", + " }", + "}"); + + verifyGeneratedFileContent( + outputDirectory, + "SingleFileBugCheckerRefactoringTestHelperWithSetArgsFixChooserAndCustomTestModeTest"); + } + + @Test + void multiFileBugCheckerRefactoringTestHelper(@TempDir Path outputDirectory) throws IOException { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "MultiFileBugCheckerRefactoringTestHelperTest.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class MultiFileBugCheckerRefactoringTestHelperTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " BugCheckerRefactoringTestHelper.newInstance(TestChecker.class, getClass())", + " .addInputLines(\"A.java\", \"class A {}\")", + " .addOutputLines(\"A.java\", \"class A { /* This is a change. */ }\")", + " .addInputLines(\"B.java\", \"class B {}\")", + " .addOutputLines(\"B.java\", \"class B { /* This is a change. */ }\")", + " .doTest();", + " }", + "}"); + + verifyGeneratedFileContent(outputDirectory, "MultiFileBugCheckerRefactoringTestHelperTest"); + } + + @Test + void compilationAndBugCheckerRefactoringTestHelpers(@TempDir Path outputDirectory) + throws IOException { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "CompilationAndBugCheckerRefactoringTestHelpersTest.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class CompilationAndBugCheckerRefactoringTestHelpersTest {", + " private static class TestChecker extends BugChecker {}", + "", + " void m() {", + " CompilationTestHelper.newInstance(TestChecker.class, getClass())", + " .addSourceLines(\"A.java\", \"// BUG: Diagnostic contains:\", \"class A {}\")", + " .doTest();", + "", + " BugCheckerRefactoringTestHelper.newInstance(TestChecker.class, getClass())", + " .addInputLines(\"A.java\", \"class A {}\")", + " .addOutputLines(\"A.java\", \"class A { /* This is a change. */ }\")", + " .doTest();", + " }", + "}"); + + verifyGeneratedFileContent( + outputDirectory, "CompilationAndBugCheckerRefactoringTestHelpersTest"); + } + + @Test + void compilationAndBugCheckerRefactoringTestHelpersWithCustomCheckerPackageAndNames( + @TempDir Path outputDirectory) throws IOException { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "CompilationAndBugCheckerRefactoringTestHelpersWithCustomCheckerPackageAndNamesTest.java", + "package pkg;", + "", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "final class CompilationAndBugCheckerRefactoringTestHelpersWithCustomCheckerPackageAndNamesTest {", + " private static class CustomTestChecker extends BugChecker {}", + "", + " private static class CustomTestChecker2 extends BugChecker {}", + "", + " void m() {", + " CompilationTestHelper.newInstance(CustomTestChecker.class, getClass())", + " .addSourceLines(\"A.java\", \"// BUG: Diagnostic contains:\", \"class A {}\")", + " .doTest();", + "", + " BugCheckerRefactoringTestHelper.newInstance(CustomTestChecker2.class, getClass())", + " .addInputLines(\"A.java\", \"class A {}\")", + " .addOutputLines(\"A.java\", \"class A { /* This is a change. */ }\")", + " .doTest();", + " }", + "}"); + + verifyGeneratedFileContent( + outputDirectory, + "CompilationAndBugCheckerRefactoringTestHelpersWithCustomCheckerPackageAndNamesTest"); + } + + private static void verifyGeneratedFileContent(Path outputDirectory, String testClass) + throws IOException { + String resourceName = String.format("bugpattern-test-%s.json", testClass); + assertThat(outputDirectory.resolve(resourceName)) + .content(UTF_8) + .isEqualToIgnoringWhitespace( + getResource( + String.join("-", BugPatternTestExtractorTest.class.getSimpleName(), resourceName))); + } + + // XXX: Once we support only JDK 15+, drop this method in favour of including the resources as + // text blocks in this class. + private static String getResource(String resourceName) throws IOException { + return Resources.toString( + Resources.getResource(BugPatternTestExtractorTest.class, resourceName), UTF_8); + } +} diff --git a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/Compilation.java b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/Compilation.java index 26d5004c58..452b5d2df5 100644 --- a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/Compilation.java +++ b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/Compilation.java @@ -1,5 +1,7 @@ package tech.picnic.errorprone.documentation; +import static org.assertj.core.api.Assertions.assertThat; + import com.google.common.collect.ImmutableList; import com.google.errorprone.FileManagers; import com.google.errorprone.FileObjects; @@ -7,39 +9,66 @@ import com.sun.tools.javac.api.JavacTool; import com.sun.tools.javac.file.JavacFileManager; import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +import javax.tools.Diagnostic; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; // XXX: Generalize and move this class so that it can also be used by `refaster-compiler`. -// XXX: Add support for this class to the `ErrorProneTestHelperSourceFormat` check. +// XXX: This class is supported by the `ErrorProneTestHelperSourceFormat` check, but until that +// support is covered by unit tests, make sure to update that logic if this class or its methods are +// moved/renamed. public final class Compilation { private Compilation() {} public static void compileWithDocumentationGenerator( - Path outputDirectory, String fileName, String... lines) { - compileWithDocumentationGenerator(outputDirectory.toAbsolutePath().toString(), fileName, lines); + Path outputDirectory, String path, String... lines) { + compileWithDocumentationGenerator(outputDirectory.toAbsolutePath().toString(), path, lines); } public static void compileWithDocumentationGenerator( - String outputDirectory, String fileName, String... lines) { + String outputDirectory, String path, String... lines) { + /* + * The compiler options specified here largely match those used by Error Prone's + * `CompilationTestHelper`. A key difference is the stricter linting configuration. When + * compiling using JDK 21+, these lint options also require that certain JDK modules are + * explicitly exported. + */ compile( - ImmutableList.of("-Xplugin:DocumentationGenerator -XoutputDirectory=" + outputDirectory), - FileObjects.forSourceLines(fileName, lines)); + ImmutableList.of( + "--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "-encoding", + "UTF-8", + "-parameters", + "-proc:none", + "-Werror", + "-Xlint:all,-serial", + "-Xplugin:DocumentationGenerator -XoutputDirectory=" + outputDirectory, + "-XDdev", + "-XDcompilePolicy=simple"), + FileObjects.forSourceLines(path, lines)); } private static void compile(ImmutableList options, JavaFileObject javaFileObject) { JavacFileManager javacFileManager = FileManagers.testFileManager(); JavaCompiler compiler = JavacTool.create(); + + List> diagnostics = new ArrayList<>(); JavacTaskImpl task = (JavacTaskImpl) compiler.getTask( null, javacFileManager, - null, + diagnostics::add, options, ImmutableList.of(), ImmutableList.of(javaFileObject)); - task.call(); + Boolean result = task.call(); + assertThat(diagnostics).isEmpty(); + assertThat(result).isTrue(); } } diff --git a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListenerTest.java b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListenerTest.java index b49e7ba17d..2394b15a14 100644 --- a/documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListenerTest.java +++ b/documentation-support/src/test/java/tech/picnic/errorprone/documentation/DocumentationGeneratorTaskListenerTest.java @@ -1,19 +1,29 @@ package tech.picnic.errorprone.documentation; import static com.google.common.collect.ImmutableList.toImmutableList; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.nio.file.attribute.AclEntryPermission.ADD_SUBDIRECTORY; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.condition.OS.WINDOWS; +import com.google.auto.service.AutoService; +import com.google.auto.value.AutoValue; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; +import com.google.common.collect.Streams; +import com.google.errorprone.VisitorState; +import com.google.errorprone.annotations.Immutable; +import com.sun.source.tree.ClassTree; +import com.sun.source.tree.Tree; import java.io.IOException; import java.nio.file.FileSystemException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.AclEntry; import java.nio.file.attribute.AclFileAttributeView; +import java.util.Optional; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.EnabledOnOs; @@ -75,4 +85,56 @@ void excessArguments(@TempDir Path outputDirectory) { .isInstanceOf(IllegalArgumentException.class) .hasMessage("Precisely one path must be provided"); } + + @Test + void extraction(@TempDir Path outputDirectory) { + Compilation.compileWithDocumentationGenerator( + outputDirectory, + "DocumentationGeneratorTaskListenerTestClass.java", + "class DocumentationGeneratorTaskListenerTestClass {}"); + + // XXX: Once we support only JDK 15+, use a text block for the `expected` string. + assertThat( + outputDirectory.resolve( + "documentation-generator-task-listener-test-DocumentationGeneratorTaskListenerTestClass.json")) + .content(UTF_8) + .isEqualToIgnoringWhitespace( + "{\"className\":\"DocumentationGeneratorTaskListenerTestClass\",\"path\":[\"CLASS: DocumentationGeneratorTaskListenerTestClass\",\"COMPILATION_UNIT\"]}"); + } + + @Immutable + @AutoService(Extractor.class) + @SuppressWarnings("rawtypes" /* See https://github.com/google/auto/issues/870. */) + public static final class TestExtractor implements Extractor { + @Override + public String identifier() { + return "documentation-generator-task-listener-test"; + } + + @Override + public Optional tryExtract(ClassTree tree, VisitorState state) { + return Optional.of(tree.getSimpleName().toString()) + .filter(n -> n.contains(DocumentationGeneratorTaskListenerTest.class.getSimpleName())) + .map( + className -> + new AutoValue_DocumentationGeneratorTaskListenerTest_ExtractionParameters( + className, + Streams.stream(state.getPath()) + .map(TestExtractor::describeTree) + .collect(toImmutableList()))); + } + + private static String describeTree(Tree tree) { + return (tree instanceof ClassTree) + ? String.join(": ", String.valueOf(tree.getKind()), ((ClassTree) tree).getSimpleName()) + : tree.getKind().toString(); + } + } + + @AutoValue + abstract static class ExtractionParameters { + abstract String className(); + + abstract ImmutableList path(); + } } diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-complete.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternExtractorTest-bugpattern-CompleteBugChecker.json similarity index 100% rename from documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-complete.json rename to documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternExtractorTest-bugpattern-CompleteBugChecker.json diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-minimal.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternExtractorTest-bugpattern-MinimalBugChecker.json similarity index 100% rename from documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-minimal.json rename to documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternExtractorTest-bugpattern-MinimalBugChecker.json diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-undocumented-suppression.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternExtractorTest-bugpattern-UndocumentedSuppressionBugPattern.json similarity index 100% rename from documentation-support/src/test/resources/tech/picnic/errorprone/documentation/bugpattern-documentation-undocumented-suppression.json rename to documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternExtractorTest-bugpattern-UndocumentedSuppressionBugPattern.json diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-CompilationAndBugCheckerRefactoringTestHelpersTest.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-CompilationAndBugCheckerRefactoringTestHelpersTest.json new file mode 100644 index 0000000000..c7672cccc4 --- /dev/null +++ b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-CompilationAndBugCheckerRefactoringTestHelpersTest.json @@ -0,0 +1,24 @@ +{ + "testClass": "CompilationAndBugCheckerRefactoringTestHelpersTest", + "testCases": [ + { + "classUnderTest": "CompilationAndBugCheckerRefactoringTestHelpersTest.TestChecker", + "entries": [ + { + "path": "A.java", + "code": "// BUG: Diagnostic contains:\nclass A {}\n" + } + ] + }, + { + "classUnderTest": "CompilationAndBugCheckerRefactoringTestHelpersTest.TestChecker", + "entries": [ + { + "path": "A.java", + "input": "class A {}\n", + "output": "class A { /* This is a change. */ }\n" + } + ] + } + ] +} diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-CompilationAndBugCheckerRefactoringTestHelpersWithCustomCheckerPackageAndNamesTest.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-CompilationAndBugCheckerRefactoringTestHelpersWithCustomCheckerPackageAndNamesTest.json new file mode 100644 index 0000000000..49b1e6bb49 --- /dev/null +++ b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-CompilationAndBugCheckerRefactoringTestHelpersWithCustomCheckerPackageAndNamesTest.json @@ -0,0 +1,24 @@ +{ + "testClass": "pkg.CompilationAndBugCheckerRefactoringTestHelpersWithCustomCheckerPackageAndNamesTest", + "testCases": [ + { + "classUnderTest": "pkg.CompilationAndBugCheckerRefactoringTestHelpersWithCustomCheckerPackageAndNamesTest.CustomTestChecker", + "entries": [ + { + "path": "A.java", + "code": "// BUG: Diagnostic contains:\nclass A {}\n" + } + ] + }, + { + "classUnderTest": "pkg.CompilationAndBugCheckerRefactoringTestHelpersWithCustomCheckerPackageAndNamesTest.CustomTestChecker2", + "entries": [ + { + "path": "A.java", + "input": "class A {}\n", + "output": "class A { /* This is a change. */ }\n" + } + ] + } + ] +} diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-MultiFileBugCheckerRefactoringTestHelperTest.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-MultiFileBugCheckerRefactoringTestHelperTest.json new file mode 100644 index 0000000000..4f93dc9ce2 --- /dev/null +++ b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-MultiFileBugCheckerRefactoringTestHelperTest.json @@ -0,0 +1,20 @@ +{ + "testClass": "MultiFileBugCheckerRefactoringTestHelperTest", + "testCases": [ + { + "classUnderTest": "MultiFileBugCheckerRefactoringTestHelperTest.TestChecker", + "entries": [ + { + "path": "A.java", + "input": "class A {}\n", + "output": "class A { /* This is a change. */ }\n" + }, + { + "path": "B.java", + "input": "class B {}\n", + "output": "class B { /* This is a change. */ }\n" + } + ] + } + ] +} diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-MultiFileCompilationTestHelperTest.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-MultiFileCompilationTestHelperTest.json new file mode 100644 index 0000000000..608717802f --- /dev/null +++ b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-MultiFileCompilationTestHelperTest.json @@ -0,0 +1,18 @@ +{ + "testClass": "MultiFileCompilationTestHelperTest", + "testCases": [ + { + "classUnderTest": "MultiFileCompilationTestHelperTest.TestChecker", + "entries": [ + { + "path": "A.java", + "code": "// BUG: Diagnostic contains:\nclass A {}\n" + }, + { + "path": "B.java", + "code": "// BUG: Diagnostic contains:\nclass B {}\n" + } + ] + } + ] +} diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileBugCheckerRefactoringTestHelperTest.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileBugCheckerRefactoringTestHelperTest.json new file mode 100644 index 0000000000..636e19ebdf --- /dev/null +++ b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileBugCheckerRefactoringTestHelperTest.json @@ -0,0 +1,15 @@ +{ + "testClass": "SingleFileBugCheckerRefactoringTestHelperTest", + "testCases": [ + { + "classUnderTest": "SingleFileBugCheckerRefactoringTestHelperTest.TestChecker", + "entries": [ + { + "path": "A.java", + "input": "class A {}\n", + "output": "class A { /* This is a change. */ }\n" + } + ] + } + ] +} diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileBugCheckerRefactoringTestHelperWithSetArgsFixChooserAndCustomTestModeTest.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileBugCheckerRefactoringTestHelperWithSetArgsFixChooserAndCustomTestModeTest.json new file mode 100644 index 0000000000..4c2d66d89a --- /dev/null +++ b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileBugCheckerRefactoringTestHelperWithSetArgsFixChooserAndCustomTestModeTest.json @@ -0,0 +1,15 @@ +{ + "testClass": "SingleFileBugCheckerRefactoringTestHelperWithSetArgsFixChooserAndCustomTestModeTest", + "testCases": [ + { + "classUnderTest": "SingleFileBugCheckerRefactoringTestHelperWithSetArgsFixChooserAndCustomTestModeTest.TestChecker", + "entries": [ + { + "path": "A.java", + "input": "class A {}\n", + "output": "class A { /* This is a change. */ }\n" + } + ] + } + ] +} diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileCompilationTestHelperTest.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileCompilationTestHelperTest.json new file mode 100644 index 0000000000..37720e1ed5 --- /dev/null +++ b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileCompilationTestHelperTest.json @@ -0,0 +1,14 @@ +{ + "testClass": "SingleFileCompilationTestHelperTest", + "testCases": [ + { + "classUnderTest": "SingleFileCompilationTestHelperTest.TestChecker", + "entries": [ + { + "path": "A.java", + "code": "// BUG: Diagnostic contains:\nclass A {}\n" + } + ] + } + ] +} diff --git a/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileCompilationTestHelperWithSetArgsTest.json b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileCompilationTestHelperWithSetArgsTest.json new file mode 100644 index 0000000000..ea543ab7ed --- /dev/null +++ b/documentation-support/src/test/resources/tech/picnic/errorprone/documentation/BugPatternTestExtractorTest-bugpattern-test-SingleFileCompilationTestHelperWithSetArgsTest.json @@ -0,0 +1,14 @@ +{ + "testClass": "SingleFileCompilationTestHelperWithSetArgsTest", + "testCases": [ + { + "classUnderTest": "SingleFileCompilationTestHelperWithSetArgsTest.TestChecker", + "entries": [ + { + "path": "A.java", + "code": "// BUG: Diagnostic contains:\nclass A {}\n" + } + ] + } + ] +} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormat.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormat.java index 3663816479..99e1d92350 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormat.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ErrorProneTestHelperSourceFormat.java @@ -5,6 +5,7 @@ import static com.google.errorprone.BugPattern.StandardTags.STYLE; import static com.google.errorprone.matchers.Matchers.anyOf; import static com.google.errorprone.matchers.Matchers.instanceMethod; +import static com.google.errorprone.matchers.Matchers.staticMethod; import static java.util.stream.Collectors.joining; import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; @@ -66,7 +67,12 @@ public final class ErrorProneTestHelperSourceFormat extends BugChecker .named("addSourceLines"), instanceMethod() .onDescendantOf("com.google.errorprone.BugCheckerRefactoringTestHelper") - .named("addInputLines")); + .named("addInputLines"), + // XXX: Add tests for `Compilation.compileWithDocumentationGenerator`. Until done, make + // sure to update this matcher if that method's class or name is changed/moved. + staticMethod() + .onClass("tech.picnic.errorprone.documentation.Compilation") + .named("compileWithDocumentationGenerator")); private static final Matcher OUTPUT_SOURCE_ACCEPTING_METHOD = instanceMethod() .onDescendantOf("com.google.errorprone.BugCheckerRefactoringTestHelper.ExpectOutput") @@ -83,7 +89,8 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState } List sourceLines = - tree.getArguments().subList(1, tree.getArguments().size()); + tree.getArguments() + .subList(ASTHelpers.getSymbol(tree).params().size() - 1, tree.getArguments().size()); if (sourceLines.isEmpty()) { return buildDescription(tree).setMessage("No source code provided").build(); } @@ -149,12 +156,13 @@ private static String formatSourceCode(String source, boolean retainUnusedImport return FORMATTER.formatSource(withOptionallyRemovedImports); } + // XXX: This logic is duplicated in `BugPatternTestExtractor`. Can we do better? private static Optional getConstantSourceCode( List sourceLines) { StringBuilder source = new StringBuilder(); for (ExpressionTree sourceLine : sourceLines) { - Object value = ASTHelpers.constValue(sourceLine); + String value = ASTHelpers.constValue(sourceLine, String.class); if (value == null) { return Optional.empty(); } From 5972a8e225cf6687e16013374ec372bc621564c5 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 25 Oct 2023 17:20:39 +0200 Subject: [PATCH 521/601] Upgrade pitest-maven-plugin 1.15.1 -> 1.15.2 (#858) See: - https://github.com/hcoles/pitest/releases/tag/1.15.2 - https://github.com/hcoles/pitest/compare/1.15.1...1.15.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 34c7df3e17..32779b9942 100644 --- a/pom.xml +++ b/pom.xml @@ -1346,7 +1346,7 @@ org.pitest pitest-maven - 1.15.1 + 1.15.2 From e4e17664d0f80390f6ed9e3fe2ebfc2451cca52a Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 26 Oct 2023 09:14:34 +0200 Subject: [PATCH 522/601] Upgrade ossf/scorecard-action v2.3.0 -> v2.3.1 (#855) See: - https://github.com/ossf/scorecard-action/releases/tag/v2.3.1 --- .github/workflows/openssf-scorecard.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index 821ddc72be..65a96d597b 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -25,7 +25,7 @@ jobs: with: persist-credentials: false - name: Run OpenSSF Scorecard analysis - uses: ossf/scorecard-action@483ef80eb98fb506c348f7d62e28055e49fe2398 # v2.3.0 + uses: ossf/scorecard-action@0864cf19026789058feabb7e87baa5f140aac736 # v2.3.1 with: results_file: results.sarif results_format: sarif From 7383a11da75035e59acb5b89a513a43d4d7f1fb9 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 26 Oct 2023 09:32:11 +0200 Subject: [PATCH 523/601] Upgrade Swagger 2.2.17 -> 2.2.18 (#860) See: - https://github.com/swagger-api/swagger-core/releases/tag/v2.2.18 - https://github.com/swagger-api/swagger-core/compare/v2.2.17...v2.2.18 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 32779b9942..5cacf29745 100644 --- a/pom.xml +++ b/pom.xml @@ -350,7 +350,7 @@ io.swagger.core.v3 swagger-annotations - 2.2.17 + 2.2.18 jakarta.servlet From 00edc5ea1fea6e41194a10d74172d6a43a04f64a Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 26 Oct 2023 10:48:08 +0200 Subject: [PATCH 524/601] Upgrade pitest-junit5-plugin 1.2.0 -> 1.2.1 (#857) See https://github.com/pitest/pitest-junit5-plugin/compare/1.2.0...1.2.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5cacf29745..c6d0735087 100644 --- a/pom.xml +++ b/pom.xml @@ -1385,7 +1385,7 @@ org.pitest pitest-junit5-plugin - 1.2.0 + 1.2.1 From a435b657aed25f446fa2304473122f2366f6936f Mon Sep 17 00:00:00 2001 From: Cernat Catalin Stefan Date: Thu, 26 Oct 2023 11:00:48 +0200 Subject: [PATCH 525/601] Introduce `NonStaticImport` check (#450) This check complements the existing `StaticImport` check. We ensure that the two checks do not suggest mutually incompatible approaches to static imports. --- error-prone-contrib/pom.xml | 5 + .../bugpatterns/NonStaticImport.java | 211 ++++++++++++++++++ .../errorprone/bugpatterns/StaticImport.java | 96 +++----- .../bugpatterns/NonStaticImportTest.java | 196 ++++++++++++++++ .../bugpatterns/StaticImportTest.java | 21 +- 5 files changed, 452 insertions(+), 77 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NonStaticImportTest.java diff --git a/error-prone-contrib/pom.xml b/error-prone-contrib/pom.xml index 7c12e0c3e9..f268bbeab3 100644 --- a/error-prone-contrib/pom.xml +++ b/error-prone-contrib/pom.xml @@ -72,6 +72,11 @@ auto-service-annotations provided + + com.google.auto.value + auto-value-annotations + provided + com.google.googlejavaformat google-java-format diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java new file mode 100644 index 0000000000..4c84992619 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java @@ -0,0 +1,211 @@ +package tech.picnic.errorprone.bugpatterns; + +import static com.google.errorprone.BugPattern.LinkType.CUSTOM; +import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; +import static com.google.errorprone.BugPattern.StandardTags.STYLE; +import static tech.picnic.errorprone.bugpatterns.StaticImport.STATIC_IMPORT_CANDIDATE_MEMBERS; +import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; + +import com.google.auto.service.AutoService; +import com.google.auto.value.AutoValue; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSetMultimap; +import com.google.common.collect.ImmutableTable; +import com.google.errorprone.BugPattern; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.CompilationUnitTreeMatcher; +import com.google.errorprone.fixes.SuggestedFix; +import com.google.errorprone.fixes.SuggestedFixes; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.util.ASTHelpers; +import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.IdentifierTree; +import com.sun.source.tree.ImportTree; +import com.sun.source.tree.MemberSelectTree; +import com.sun.source.tree.Tree; +import com.sun.source.util.TreeScanner; +import com.sun.tools.javac.code.Symbol; +import org.jspecify.annotations.Nullable; +import tech.picnic.errorprone.bugpatterns.util.SourceCode; + +/** + * A {@link BugChecker} that flags static imports of type members that should *not* be statically + * imported. + */ +// XXX: This check is closely linked to `StaticImport`. Consider merging the two. +// XXX: Add suppression support. If qualification of one more more identifiers is suppressed, then +// the associated static import should *not* be removed. +// XXX: Also introduce logic that disallows statically importing `ZoneOffset.ofHours` and other +// `ofXXX`-style methods. +@AutoService(BugChecker.class) +@BugPattern( + summary = "Member should not be statically imported", + link = BUG_PATTERNS_BASE_URL + "NonStaticImport", + linkType = CUSTOM, + severity = SUGGESTION, + tags = STYLE) +public final class NonStaticImport extends BugChecker implements CompilationUnitTreeMatcher { + private static final long serialVersionUID = 1L; + + /** + * Types whose members should not be statically imported, unless exempted by {@link + * StaticImport#STATIC_IMPORT_CANDIDATE_MEMBERS}. + * + *

Types listed here should be mutually exclusive with {@link + * StaticImport#STATIC_IMPORT_CANDIDATE_TYPES}. + */ + @VisibleForTesting + static final ImmutableSet NON_STATIC_IMPORT_CANDIDATE_TYPES = + ImmutableSet.of("com.google.common.base.Strings", "java.time.Clock", "java.time.ZoneOffset"); + + /** + * Type members that should never be statically imported. + * + *

Please note that: + * + *

    + *
  • Types listed by {@link #NON_STATIC_IMPORT_CANDIDATE_TYPES} and members listed by {@link + * #NON_STATIC_IMPORT_CANDIDATE_IDENTIFIERS} should be omitted from this collection. + *
  • This collection should be mutually exclusive with {@link + * StaticImport#STATIC_IMPORT_CANDIDATE_MEMBERS}. + *
+ */ + // XXX: Perhaps the set of exempted `java.util.Collections` methods is too strict. For now any + // method name that could be considered "too vague" or could conceivably mean something else in a + // specific context is left out. + static final ImmutableSetMultimap NON_STATIC_IMPORT_CANDIDATE_MEMBERS = + ImmutableSetMultimap.builder() + .put("com.google.common.base.Predicates", "contains") + .putAll( + "java.util.Collections", + "addAll", + "copy", + "fill", + "list", + "max", + "min", + "nCopies", + "rotate", + "sort", + "swap") + .put("java.util.Locale", "ROOT") + .putAll("java.util.regex.Pattern", "compile", "matches", "quote") + .put("org.springframework.http.MediaType", "ALL") + .build(); + + /** + * Identifiers that should never be statically imported. + * + *

Please note that: + * + *

    + *
  • Identifiers listed by {@link StaticImport#STATIC_IMPORT_CANDIDATE_MEMBERS} should be + * mutually exclusive with identifiers listed here. + *
  • This list should contain a superset of the identifiers flagged by {@link + * com.google.errorprone.bugpatterns.BadImport}. + *
+ */ + static final ImmutableSet NON_STATIC_IMPORT_CANDIDATE_IDENTIFIERS = + ImmutableSet.of( + "builder", + "copyOf", + "create", + "empty", + "from", + "getDefaultInstance", + "INSTANCE", + "MAX", + "MAX_VALUE", + "MIN", + "MIN_VALUE", + "newBuilder", + "newInstance", + "of", + "ONE", + "parse", + "valueOf", + "ZERO"); + + /** Instantiates a new {@link NonStaticImport} instance. */ + public NonStaticImport() {} + + @Override + public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState state) { + ImmutableTable undesiredStaticImports = + getUndesiredStaticImports(tree, state); + + if (!undesiredStaticImports.isEmpty()) { + replaceUndesiredStaticImportUsages(tree, undesiredStaticImports, state); + + for (UndesiredStaticImport staticImport : undesiredStaticImports.values()) { + state.reportMatch( + describeMatch(staticImport.importTree(), staticImport.fixBuilder().build())); + } + } + + /* Any violations have been flagged against the offending static import statement. */ + return Description.NO_MATCH; + } + + private static ImmutableTable getUndesiredStaticImports( + CompilationUnitTree tree, VisitorState state) { + ImmutableTable.Builder imports = + ImmutableTable.builder(); + for (ImportTree importTree : tree.getImports()) { + Tree qualifiedIdentifier = importTree.getQualifiedIdentifier(); + if (importTree.isStatic() && qualifiedIdentifier instanceof MemberSelectTree) { + MemberSelectTree memberSelectTree = (MemberSelectTree) qualifiedIdentifier; + String type = SourceCode.treeToString(memberSelectTree.getExpression(), state); + String member = memberSelectTree.getIdentifier().toString(); + if (shouldNotBeStaticallyImported(type, member)) { + imports.put( + type, + member, + new AutoValue_NonStaticImport_UndesiredStaticImport( + importTree, SuggestedFix.builder().removeStaticImport(type + '.' + member))); + } + } + } + + return imports.build(); + } + + private static boolean shouldNotBeStaticallyImported(String type, String member) { + return (NON_STATIC_IMPORT_CANDIDATE_TYPES.contains(type) + && !STATIC_IMPORT_CANDIDATE_MEMBERS.containsEntry(type, member)) + || NON_STATIC_IMPORT_CANDIDATE_MEMBERS.containsEntry(type, member) + || NON_STATIC_IMPORT_CANDIDATE_IDENTIFIERS.contains(member); + } + + private static void replaceUndesiredStaticImportUsages( + CompilationUnitTree tree, + ImmutableTable undesiredStaticImports, + VisitorState state) { + new TreeScanner<@Nullable Void, @Nullable Void>() { + @Override + public @Nullable Void visitIdentifier(IdentifierTree node, @Nullable Void unused) { + Symbol symbol = ASTHelpers.getSymbol(node); + if (symbol != null) { + UndesiredStaticImport staticImport = + undesiredStaticImports.get( + symbol.owner.getQualifiedName().toString(), symbol.name.toString()); + if (staticImport != null) { + SuggestedFix.Builder fix = staticImport.fixBuilder(); + fix.prefixWith(node, SuggestedFixes.qualifyType(state, fix, symbol.owner) + '.'); + } + } + + return super.visitIdentifier(node, unused); + } + }.scan(tree, null); + } + + @AutoValue + abstract static class UndesiredStaticImport { + abstract ImportTree importTree(); + + abstract SuggestedFix.Builder fixBuilder(); + } +} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java index c5b3e52427..3adb431a9c 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java @@ -2,8 +2,10 @@ import static com.google.errorprone.BugPattern.LinkType.CUSTOM; import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; -import static com.google.errorprone.BugPattern.StandardTags.SIMPLIFICATION; +import static com.google.errorprone.BugPattern.StandardTags.STYLE; import static java.util.Objects.requireNonNull; +import static tech.picnic.errorprone.bugpatterns.NonStaticImport.NON_STATIC_IMPORT_CANDIDATE_IDENTIFIERS; +import static tech.picnic.errorprone.bugpatterns.NonStaticImport.NON_STATIC_IMPORT_CANDIDATE_MEMBERS; import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; import com.google.auto.service.AutoService; @@ -27,35 +29,30 @@ import com.sun.tools.javac.code.Type; import java.util.Optional; -/** - * A {@link BugChecker} that flags methods and constants that can and should be statically imported. - */ +/** A {@link BugChecker} that flags type members that can and should be statically imported. */ +// XXX: This check is closely linked to `NonStaticImport`. Consider merging the two. // XXX: Tricky cases: // - `org.springframework.http.HttpStatus` (not always an improvement, and `valueOf` must // certainly be excluded) // - `com.google.common.collect.Tables` -// - `ch.qos.logback.classic.Level.{DEBUG, ERROR, INFO, TRACE, WARN"}` -// XXX: Also introduce a check that disallows static imports of certain methods. Candidates: -// - `com.google.common.base.Strings` -// - `java.util.Optional.empty` -// - `java.util.Locale.ROOT` -// - `ZoneOffset.ofHours` and other `ofXXX`-style methods. -// - `java.time.Clock`. -// - Several other `java.time` classes. -// - Likely any of `*.{ZERO, ONE, MIX, MAX, MIN_VALUE, MAX_VALUE}`. +// - `ch.qos.logback.classic.Level.{DEBUG, ERROR, INFO, TRACE, WARN}` @AutoService(BugChecker.class) @BugPattern( summary = "Identifier should be statically imported", link = BUG_PATTERNS_BASE_URL + "StaticImport", linkType = CUSTOM, severity = SUGGESTION, - tags = SIMPLIFICATION) + tags = STYLE) public final class StaticImport extends BugChecker implements MemberSelectTreeMatcher { private static final long serialVersionUID = 1L; /** * Types whose members should be statically imported, unless exempted by {@link - * #STATIC_IMPORT_EXEMPTED_MEMBERS} or {@link #STATIC_IMPORT_EXEMPTED_IDENTIFIERS}. + * NonStaticImport#NON_STATIC_IMPORT_CANDIDATE_MEMBERS} or {@link + * NonStaticImport#NON_STATIC_IMPORT_CANDIDATE_IDENTIFIERS}. + * + *

Types listed here should be mutually exclusive with {@link + * NonStaticImport#NON_STATIC_IMPORT_CANDIDATE_TYPES}. */ @VisibleForTesting static final ImmutableSet STATIC_IMPORT_CANDIDATE_TYPES = @@ -104,8 +101,20 @@ public final class StaticImport extends BugChecker implements MemberSelectTreeMa "reactor.function.TupleUtils", "tech.picnic.errorprone.bugpatterns.util.MoreTypes"); - /** Type members that should be statically imported. */ - @VisibleForTesting + /** + * Type members that should be statically imported. + * + *

Please note that: + * + *

    + *
  • Types listed by {@link #STATIC_IMPORT_CANDIDATE_TYPES} should be omitted from this + * collection. + *
  • This collection should be mutually exclusive with {@link + * NonStaticImport#NON_STATIC_IMPORT_CANDIDATE_MEMBERS}. + *
  • This collection should not list members contained in {@link + * NonStaticImport#NON_STATIC_IMPORT_CANDIDATE_IDENTIFIERS}. + *
+ */ static final ImmutableSetMultimap STATIC_IMPORT_CANDIDATE_MEMBERS = ImmutableSetMultimap.builder() .putAll( @@ -143,55 +152,6 @@ public final class StaticImport extends BugChecker implements MemberSelectTreeMa .putAll("com.google.common.collect.Comparators", "emptiesFirst", "emptiesLast") .build(); - /** - * Type members that should never be statically imported. - * - *

Identifiers listed by {@link #STATIC_IMPORT_EXEMPTED_IDENTIFIERS} should be omitted from - * this collection. - */ - // XXX: Perhaps the set of exempted `java.util.Collections` methods is too strict. For now any - // method name that could be considered "too vague" or could conceivably mean something else in a - // specific context is left out. - @VisibleForTesting - static final ImmutableSetMultimap STATIC_IMPORT_EXEMPTED_MEMBERS = - ImmutableSetMultimap.builder() - .put("com.google.common.base.Predicates", "contains") - .put("com.mongodb.client.model.Filters", "empty") - .putAll( - "java.util.Collections", - "addAll", - "copy", - "fill", - "list", - "max", - "min", - "nCopies", - "rotate", - "sort", - "swap") - .putAll("java.util.regex.Pattern", "compile", "matches", "quote") - .put("org.springframework.http.MediaType", "ALL") - .build(); - - /** - * Identifiers that should never be statically imported. - * - *

This should be a superset of the identifiers flagged by {@link - * com.google.errorprone.bugpatterns.BadImport}. - */ - @VisibleForTesting - static final ImmutableSet STATIC_IMPORT_EXEMPTED_IDENTIFIERS = - ImmutableSet.of( - "builder", - "create", - "copyOf", - "from", - "getDefaultInstance", - "INSTANCE", - "newBuilder", - "of", - "valueOf"); - /** Instantiates a new {@link StaticImport} instance. */ public StaticImport() {} @@ -229,13 +189,13 @@ private static boolean isCandidateContext(VisitorState state) { private static boolean isCandidate(MemberSelectTree tree) { String identifier = tree.getIdentifier().toString(); - if (STATIC_IMPORT_EXEMPTED_IDENTIFIERS.contains(identifier)) { + if (NON_STATIC_IMPORT_CANDIDATE_IDENTIFIERS.contains(identifier)) { return false; } Type type = ASTHelpers.getType(tree.getExpression()); return type != null - && !STATIC_IMPORT_EXEMPTED_MEMBERS.containsEntry(type.toString(), identifier); + && !NON_STATIC_IMPORT_CANDIDATE_MEMBERS.containsEntry(type.toString(), identifier); } private static Optional getCandidateSimpleName(StaticImportInfo importInfo) { diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NonStaticImportTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NonStaticImportTest.java new file mode 100644 index 0000000000..86ef74d4e6 --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/NonStaticImportTest.java @@ -0,0 +1,196 @@ +package tech.picnic.errorprone.bugpatterns; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; +import com.google.errorprone.CompilationTestHelper; +import org.junit.jupiter.api.Test; + +final class NonStaticImportTest { + @Test + void candidateTypesDoNotClash() { + assertThat(NonStaticImport.NON_STATIC_IMPORT_CANDIDATE_TYPES) + .doesNotContainAnyElementsOf(StaticImport.STATIC_IMPORT_CANDIDATE_TYPES); + } + + @Test + void candidateMembersAreNotRedundant() { + assertThat(NonStaticImport.NON_STATIC_IMPORT_CANDIDATE_MEMBERS.keySet()) + .doesNotContainAnyElementsOf(NonStaticImport.NON_STATIC_IMPORT_CANDIDATE_TYPES); + + assertThat(NonStaticImport.NON_STATIC_IMPORT_CANDIDATE_MEMBERS.values()) + .doesNotContainAnyElementsOf(NonStaticImport.NON_STATIC_IMPORT_CANDIDATE_IDENTIFIERS); + } + + @Test + void candidateMembersDoNotClash() { + assertThat(NonStaticImport.NON_STATIC_IMPORT_CANDIDATE_MEMBERS.entries()) + .doesNotContainAnyElementsOf(StaticImport.STATIC_IMPORT_CANDIDATE_MEMBERS.entries()); + } + + @Test + void candidateIdentifiersDoNotClash() { + assertThat(NonStaticImport.NON_STATIC_IMPORT_CANDIDATE_IDENTIFIERS) + .doesNotContainAnyElementsOf(StaticImport.STATIC_IMPORT_CANDIDATE_MEMBERS.values()); + } + + @Test + void identification() { + CompilationTestHelper.newInstance(NonStaticImport.class, getClass()) + .addSourceLines( + "pkg/A.java", + "package pkg;", + "", + "// BUG: Diagnostic contains:", + "import static com.google.common.base.Strings.nullToEmpty;", + "// BUG: Diagnostic contains:", + "import static com.google.common.collect.ImmutableList.copyOf;", + "// BUG: Diagnostic contains:", + "import static java.lang.Integer.MAX_VALUE;", + "// BUG: Diagnostic contains:", + "import static java.lang.Integer.MIN_VALUE;", + "// BUG: Diagnostic contains:", + "import static java.time.Clock.systemUTC;", + "// BUG: Diagnostic contains:", + "import static java.time.Instant.MIN;", + "// BUG: Diagnostic contains:", + "import static java.time.ZoneOffset.SHORT_IDS;", + "import static java.time.ZoneOffset.UTC;", + "// BUG: Diagnostic contains:", + "import static java.util.Collections.min;", + "import static java.util.Locale.ENGLISH;", + "// BUG: Diagnostic contains:", + "import static java.util.Locale.ROOT;", + "// BUG: Diagnostic contains:", + "import static java.util.Optional.empty;", + "import static pkg.A.WithMethodThatIsSelectivelyFlagged.list;", + "", + "import com.google.common.collect.ImmutableList;", + "import com.google.common.collect.ImmutableSet;", + "import java.time.Instant;", + "import java.time.ZoneOffset;", + "import java.util.Locale;", + "import java.util.Map;", + "import pkg.A.Wrapper.ZERO;", + "", + "class A {", + " private Integer MIN_VALUE = 12;", + "", + " void m() {", + " nullToEmpty(null);", + " copyOf(ImmutableList.of());", + " int max = MAX_VALUE;", + " int min = MIN_VALUE;", + " systemUTC();", + " Instant minInstant = MIN;", + " Map shortIds = SHORT_IDS;", + " ZoneOffset utc = UTC;", + " min(ImmutableSet.of());", + " Locale english = ENGLISH;", + " Locale root = ROOT;", + " empty();", + "", + " list();", + " new ZERO();", + " }", + "", + " static final class WithMethodThatIsSelectivelyFlagged {", + " static ImmutableList list() {", + " return ImmutableList.of();", + " }", + " }", + "", + " static final class Wrapper {", + " static final class ZERO {}", + " }", + "}") + .doTest(); + } + + @Test + void replacement() { + BugCheckerRefactoringTestHelper.newInstance(NonStaticImport.class, getClass()) + .addInputLines( + "A.java", + "import static com.google.common.collect.ImmutableList.copyOf;", + "import static com.google.common.collect.ImmutableSet.of;", + "import static java.time.Clock.systemUTC;", + "import static java.time.Instant.MAX;", + "import static java.time.Instant.MIN;", + "import static java.util.Collections.min;", + "import static java.util.Locale.ROOT;", + "import static java.util.Optional.empty;", + "", + "import com.google.common.collect.ImmutableList;", + "import com.google.common.collect.ImmutableSet;", + "import java.time.Clock;", + "import java.time.Instant;", + "import java.util.Locale;", + "import java.util.Optional;", + "", + "class A {", + " void m() {", + " systemUTC();", + " Clock.systemUTC();", + "", + " Optional o1 = empty();", + " Optional o2 = Optional.empty();", + "", + " Object l1 = copyOf(ImmutableList.of());", + " Object l2 = ImmutableList.copyOf(ImmutableList.of());", + "", + " Locale lo1 = ROOT;", + " Locale lo2 = Locale.ROOT;", + "", + " Instant i1 = MIN;", + " Instant i2 = MAX;", + "", + " ImmutableSet.of(min(of()));", + " }", + "", + " private static final class WithCustomConstant {", + " private static final Instant MIN = Instant.EPOCH;", + " private static final Instant OTHER = MIN;", + " private static final Instant OTHER_MAX = MAX;", + " }", + "}") + .addOutputLines( + "A.java", + "import com.google.common.collect.ImmutableList;", + "import com.google.common.collect.ImmutableSet;", + "import java.time.Clock;", + "import java.time.Instant;", + "import java.util.Collections;", + "import java.util.Locale;", + "import java.util.Optional;", + "", + "class A {", + " void m() {", + " Clock.systemUTC();", + " Clock.systemUTC();", + "", + " Optional o1 = Optional.empty();", + " Optional o2 = Optional.empty();", + "", + " Object l1 = ImmutableList.copyOf(ImmutableList.of());", + " Object l2 = ImmutableList.copyOf(ImmutableList.of());", + "", + " Locale lo1 = Locale.ROOT;", + " Locale lo2 = Locale.ROOT;", + "", + " Instant i1 = Instant.MIN;", + " Instant i2 = Instant.MAX;", + "", + " ImmutableSet.of(Collections.min(ImmutableSet.of()));", + " }", + "", + " private static final class WithCustomConstant {", + " private static final Instant MIN = Instant.EPOCH;", + " private static final Instant OTHER = MIN;", + " private static final Instant OTHER_MAX = Instant.MAX;", + " }", + "}") + .doTest(TestMode.TEXT_MATCH); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java index d876f41082..bcfb097d39 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java @@ -9,21 +9,24 @@ final class StaticImportTest { @Test - void candidateMethodsAreNotRedundant() { - assertThat(StaticImport.STATIC_IMPORT_CANDIDATE_MEMBERS.keySet()) - .doesNotContainAnyElementsOf(StaticImport.STATIC_IMPORT_CANDIDATE_TYPES); + void candidateTypesDoNotClash() { + assertThat(StaticImport.STATIC_IMPORT_CANDIDATE_TYPES) + .doesNotContainAnyElementsOf(NonStaticImport.NON_STATIC_IMPORT_CANDIDATE_TYPES); } @Test - void exemptedMembersAreNotVacuous() { - assertThat(StaticImport.STATIC_IMPORT_EXEMPTED_MEMBERS.keySet()) - .isSubsetOf(StaticImport.STATIC_IMPORT_CANDIDATE_TYPES); + void candidateMembersAreNotRedundant() { + assertThat(StaticImport.STATIC_IMPORT_CANDIDATE_MEMBERS.keySet()) + .doesNotContainAnyElementsOf(StaticImport.STATIC_IMPORT_CANDIDATE_TYPES); } @Test - void exemptedMembersAreNotRedundant() { - assertThat(StaticImport.STATIC_IMPORT_EXEMPTED_MEMBERS.values()) - .doesNotContainAnyElementsOf(StaticImport.STATIC_IMPORT_EXEMPTED_IDENTIFIERS); + void candidateMembersDoNotClash() { + assertThat(StaticImport.STATIC_IMPORT_CANDIDATE_MEMBERS.entries()) + .doesNotContainAnyElementsOf(NonStaticImport.NON_STATIC_IMPORT_CANDIDATE_MEMBERS.entries()); + + assertThat(StaticImport.STATIC_IMPORT_CANDIDATE_MEMBERS.values()) + .doesNotContainAnyElementsOf(NonStaticImport.NON_STATIC_IMPORT_CANDIDATE_IDENTIFIERS); } @Test From dc14c4e970e127cb3f48f2c5c96adcce435183f5 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 27 Oct 2023 11:15:34 +0200 Subject: [PATCH 526/601] Upgrade maven-clean-plugin 3.3.1 -> 3.3.2 (#863) See: - https://github.com/apache/maven-clean-plugin/releases/tag/maven-clean-plugin-3.3.2 - https://github.com/apache/maven-clean-plugin/compare/maven-clean-plugin-3.3.1...maven-clean-plugin-3.3.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c6d0735087..3007665da7 100644 --- a/pom.xml +++ b/pom.xml @@ -869,7 +869,7 @@ org.apache.maven.plugins maven-clean-plugin - 3.3.1 + 3.3.2 org.apache.maven.plugins From 8781a9ede595daa954df6c80fe208fd6c248d131 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 27 Oct 2023 11:33:24 +0200 Subject: [PATCH 527/601] Upgrade git-commit-id-maven-plugin 6.0.0 -> 7.0.0 (#852) See: - https://github.com/git-commit-id/git-commit-id-maven-plugin/releases/tag/v7.0.0 - https://github.com/git-commit-id/git-commit-id-maven-plugin/compare/v6.0.0...v7.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3007665da7..730d6237c0 100644 --- a/pom.xml +++ b/pom.xml @@ -580,7 +580,7 @@ io.github.git-commit-id git-commit-id-maven-plugin - 6.0.0 + 7.0.0 true true From 701db7d61e14030b0a8da1515519f25dc21ff509 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 27 Oct 2023 11:55:29 +0200 Subject: [PATCH 528/601] Upgrade Surefire 3.1.2 -> 3.2.1 (#856) See: - https://issues.apache.org/jira/issues/?jql=project%20%3D%20SUREFIRE%20AND%20fixVersion%20%3E%203.1.2%20AND%20fixVersion%20%3C%3D%203.2.1 - https://github.com/apache/maven-surefire/releases/tag/surefire-3.2.1 - https://github.com/apache/maven-surefire/compare/surefire-3.1.2...surefire-3.2.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 730d6237c0..b10d80af56 100644 --- a/pom.xml +++ b/pom.xml @@ -210,7 +210,7 @@ 1.0.1 0.10.15 1.1.2 - 3.1.2 + 3.2.1 From e76dd5c31be0736489559391b7b98804d352da6e Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 27 Oct 2023 12:10:12 +0200 Subject: [PATCH 529/601] Upgrade maven-dependency-plugin 3.6.0 -> 3.6.1 (#854) See: - https://issues.apache.org/jira/issues/?jql=project%20%3D%20MDEP%20AND%20fixVersion%20%3E%203.6.0%20AND%20fixVersion%20%3C%3D%203.6.1 - https://github.com/apache/maven-dependency-plugin/compare/maven-dependency-plugin-3.6.0...maven-dependency-plugin-3.6.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b10d80af56..5fef9df24c 100644 --- a/pom.xml +++ b/pom.xml @@ -950,7 +950,7 @@ org.apache.maven.plugins maven-dependency-plugin - 3.6.0 + 3.6.1 From a1a865b87aee1c58b76b2c66c8ae949b1b9fbb0b Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 3 Nov 2023 08:06:40 +0100 Subject: [PATCH 536/601] Upgrade Checker Framework Annotations 3.39.0 -> 3.40.0 (#870) See: - https://github.com/typetools/checker-framework/releases/tag/checker-framework-3.40.0 - https://github.com/typetools/checker-framework/compare/checker-framework-3.39.0...checker-framework-3.40.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 56b3d1098b..a4c27b06d9 100644 --- a/pom.xml +++ b/pom.xml @@ -407,7 +407,7 @@ org.checkerframework checker-qual - 3.39.0 + 3.40.0 org.hamcrest From fd150af6c60b4df074ce20f58a32b5af341a4443 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 3 Nov 2023 08:29:27 +0100 Subject: [PATCH 537/601] Upgrade maven-checkstyle-plugin 3.3.0 -> 3.3.1 (#861) See https://github.com/apache/maven-checkstyle-plugin/compare/maven-checkstyle-plugin-3.3.0...maven-checkstyle-plugin-3.3.1 --- pom.xml | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index a4c27b06d9..89815e3473 100644 --- a/pom.xml +++ b/pom.xml @@ -599,7 +599,7 @@ org.apache.maven.plugins maven-checkstyle-plugin - 3.3.0 + 3.3.1 - - ${project.build.sourceDirectory} - - - ${project.build.testSourceDirectory} - - ${basedir}/src/test/resources - + **/* + + THIRD-PARTY.txt From d23684ee6df62534afd43c067c23da4aa63fe725 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 4 Nov 2023 09:41:24 +0100 Subject: [PATCH 538/601] Upgrade Mockito 5.6.0 -> 5.7.0 (#871) See: - https://github.com/mockito/mockito/releases/tag/v5.7.0 - https://github.com/mockito/mockito/compare/v5.6.0...v5.7.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 89815e3473..930a0b99fd 100644 --- a/pom.xml +++ b/pom.xml @@ -206,7 +206,7 @@ 1.0 11 3.8.7 - 5.6.0 + 5.7.0 1.0.1 0.10.16 1.1.2 From 62a7dacf4d507c0a19a107480c6247f298570954 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 6 Nov 2023 07:45:10 +0100 Subject: [PATCH 539/601] Upgrade ruby/setup-ruby v1.155.0 -> v1.159.0 (873) See: - https://github.com/ruby/setup-ruby/releases/tag/v1.159.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.158.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.157.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.156.0 --- .github/workflows/deploy-website.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yaml index ce5be120b7..476ea108d3 100644 --- a/.github/workflows/deploy-website.yaml +++ b/.github/workflows/deploy-website.yaml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: persist-credentials: false - - uses: ruby/setup-ruby@d37167af451eb51448db3354e1057b75c4b268f7 # v1.155.0 + - uses: ruby/setup-ruby@54a18e26dbbb1eabc604f317ade9a5788dddef81 # v1.159.0 with: working-directory: ./website bundler-cache: true From dbd4853e3edeb9741307e1fa63a7b0a0f57ac208 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 6 Nov 2023 08:14:47 +0100 Subject: [PATCH 540/601] Upgrade CodeQL v2.22.0 -> v2.22.5 (#872) See: - https://github.com/github/codeql-action/blob/main/CHANGELOG.md - https://github.com/github/codeql-action/compare/v2.22.0...v2.22.5 --- .github/workflows/codeql.yml | 4 ++-- .github/workflows/openssf-scorecard.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 03ef52a5ad..a5b5928c8c 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -32,13 +32,13 @@ jobs: distribution: temurin cache: maven - name: Initialize CodeQL - uses: github/codeql-action/init@2cb752a87e96af96708ab57187ab6372ee1973ab # v2.22.0 + uses: github/codeql-action/init@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5 with: languages: ${{ matrix.language }} - name: Perform minimal build if: matrix.language == 'java' run: mvn -T1C clean install -DskipTests -Dverification.skip - name: Perform CodeQL analysis - uses: github/codeql-action/analyze@2cb752a87e96af96708ab57187ab6372ee1973ab # v2.22.0 + uses: github/codeql-action/analyze@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5 with: category: /language:${{ matrix.language }} diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index 65a96d597b..d813420298 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -31,6 +31,6 @@ jobs: results_format: sarif publish_results: ${{ github.ref == 'refs/heads/master' }} - name: Update GitHub's code scanning dashboard - uses: github/codeql-action/upload-sarif@2cb752a87e96af96708ab57187ab6372ee1973ab # v2.22.0 + uses: github/codeql-action/upload-sarif@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5 with: sarif_file: results.sarif From 89c4969a31d321425ad4df36e85f392afffec2d3 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 12 Nov 2023 19:10:39 +0100 Subject: [PATCH 541/601] Upgrade Swagger 2.2.18 -> 2.2.19 (#879) See: - https://github.com/swagger-api/swagger-core/releases/tag/v2.2.19 - https://github.com/swagger-api/swagger-core/compare/v2.2.18...v2.2.19 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 930a0b99fd..866fedde03 100644 --- a/pom.xml +++ b/pom.xml @@ -350,7 +350,7 @@ io.swagger.core.v3 swagger-annotations - 2.2.18 + 2.2.19 jakarta.servlet From 57a43a1c856c7ccc112872a6d9b1026caf9e96f2 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 13 Nov 2023 08:18:45 +0100 Subject: [PATCH 542/601] Upgrade JUnit 5 5.10.0 -> 5.10.1 (#874) See: - https://junit.org/junit5/docs/current/release-notes/ - https://github.com/junit-team/junit5/releases/tag/r5.10.1 - https://github.com/junit-team/junit5/compare/r5.10.0...r5.10.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 866fedde03..f0509ae471 100644 --- a/pom.xml +++ b/pom.xml @@ -427,7 +427,7 @@ org.junit junit-bom - 5.10.0 + 5.10.1 pom import From 9ce7c6b40b3bd7a72dca4589ce5ac688863bfeeb Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 13 Nov 2023 08:39:26 +0100 Subject: [PATCH 543/601] Upgrade maven-javadoc-plugin 3.6.0 -> 3.6.2 (#875) See: - https://github.com/apache/maven-javadoc-plugin/releases/tag/maven-javadoc-plugin-3.6.2 - https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.6.0...maven-javadoc-plugin-3.6.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f0509ae471..0b72cf31fe 100644 --- a/pom.xml +++ b/pom.xml @@ -1094,7 +1094,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.6.0 + 3.6.2 --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED From 97acfbc3bc6a5d87991769ceaa847590f8de6339 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 16 Nov 2023 08:27:12 +0100 Subject: [PATCH 544/601] Upgrade Surefire 3.2.1 -> 3.2.2 (#876) See: - https://github.com/apache/maven-surefire/releases/tag/surefire-3.2.2 - https://github.com/apache/maven-surefire/compare/surefire-3.2.1...surefire-3.2.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0b72cf31fe..9588a34405 100644 --- a/pom.xml +++ b/pom.xml @@ -210,7 +210,7 @@ 1.0.1 0.10.16 1.1.2 - 3.2.1 + 3.2.2 From 96c836e6a97741512a2f938eff5a269788b08d72 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 20 Nov 2023 07:28:35 +0100 Subject: [PATCH 545/601] Upgrade versions-maven-plugin 2.16.1 -> 2.16.2 (#890) See: - https://github.com/mojohaus/versions/releases/tag/2.16.2 - https://github.com/mojohaus/versions-maven-plugin/compare/2.16.1...2.16.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9588a34405..55972d09b8 100644 --- a/pom.xml +++ b/pom.xml @@ -1288,7 +1288,7 @@ org.codehaus.mojo versions-maven-plugin - 2.16.1 + 2.16.2 never From 100305ed1fa5bf980b418e387c6716f5704d49e5 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 20 Nov 2023 07:41:53 +0100 Subject: [PATCH 546/601] Upgrade Spring 5.3.30 -> 5.3.31 (#888) See: - https://github.com/spring-projects/spring-framework/releases/tag/v5.3.31 - https://github.com/spring-projects/spring-framework/compare/v5.3.30...v5.3.31 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 55972d09b8..ee17b16ef8 100644 --- a/pom.xml +++ b/pom.xml @@ -461,7 +461,7 @@ org.springframework spring-framework-bom - 5.3.30 + 5.3.31 pom import From a230bbff12a5f3f02be3b04a23c138544b0674e9 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 21 Nov 2023 08:01:19 +0100 Subject: [PATCH 547/601] Upgrade Byte Buddy 1.14.9 -> 1.14.10 (#891) See: - https://github.com/raphw/byte-buddy/releases/tag/byte-buddy-1.14.10 - https://github.com/raphw/byte-buddy/compare/byte-buddy-1.14.9...byte-buddy-1.14.10 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ee17b16ef8..119ce32100 100644 --- a/pom.xml +++ b/pom.xml @@ -382,7 +382,7 @@ net.bytebuddy byte-buddy - 1.14.9 + 1.14.10 From 1d25b78c4c6bbc426b32766aaa373c1361a45a6e Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 23 Nov 2023 10:58:24 +0100 Subject: [PATCH 552/601] Upgrade Jackson 2.15.3 -> 2.16.0 (#889) See: - https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.16 - https://github.com/FasterXML/jackson-bom/compare/jackson-bom-2.15.3...jackson-bom-2.16.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e6ddd82b0e..97a3efc707 100644 --- a/pom.xml +++ b/pom.xml @@ -268,7 +268,7 @@ com.fasterxml.jackson jackson-bom - 2.15.3 + 2.16.0 pom import From 53e0a0cb41554b2daa95b25c788227c15637ad3e Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 24 Nov 2023 08:10:02 +0100 Subject: [PATCH 553/601] Upgrade Project Reactor 2022.0.13 -> 2023.0.0 (#887) See: - https://github.com/reactor/reactor/releases/tag/2023.0.0-M1 - https://github.com/reactor/reactor/releases/tag/2023.0.0-M2 - https://github.com/reactor/reactor/releases/tag/2023.0.0-M3 - https://github.com/reactor/reactor/releases/tag/2023.0.0-RC1 - https://github.com/reactor/reactor/releases/tag/2023.0.0 - https://github.com/reactor/reactor/compare/2022.0.13...2023.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 97a3efc707..fee337fa01 100644 --- a/pom.xml +++ b/pom.xml @@ -333,7 +333,7 @@ io.projectreactor reactor-bom - 2022.0.13 + 2023.0.0 pom import From 7733ceaaecc89d1f1f6a42e5e417c863f710cd9c Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 26 Nov 2023 15:06:23 +0100 Subject: [PATCH 554/601] Upgrade build-helper-maven-plugin 3.4.0 -> 3.5.0 (#896) See: - https://github.com/mojohaus/build-helper-maven-plugin/releases/tag/3.5.0 - https://github.com/mojohaus/build-helper-maven-plugin/compare/3.4.0...3.5.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fee337fa01..8dcac6147a 100644 --- a/pom.xml +++ b/pom.xml @@ -1180,7 +1180,7 @@ org.codehaus.mojo build-helper-maven-plugin - 3.4.0 + 3.5.0 org.codehaus.mojo From 7793006b5e6ef046698334b0a43c8a3d92a83438 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 26 Nov 2023 15:51:44 +0100 Subject: [PATCH 555/601] Upgrade Spring Boot 2.7.17 -> 2.7.18 (#895) See: - https://github.com/spring-projects/spring-boot/releases/tag/v2.7.18 - https://github.com/spring-projects/spring-boot/compare/v2.7.17...v2.7.18 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8dcac6147a..932a3c946f 100644 --- a/pom.xml +++ b/pom.xml @@ -468,7 +468,7 @@ org.springframework.boot spring-boot-test - 2.7.17 + 2.7.18 org.testng From eafb73814ace9e66bc24e6dbb0cf9f2476495a0d Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 27 Nov 2023 11:16:48 +0100 Subject: [PATCH 556/601] Apply assorted build improvements (#866) Summary of changes: - Consistently use `.yml` instead of `.yaml`. - Don't install SNAPSHOT artifacts during the CodeQL build, so that they don't end up in the Maven cache. - Sync a bunch of `pom.xml` changes from our internal Maven parent. --- .github/workflows/{build.yaml => build.yml} | 0 .github/workflows/codeql.yml | 2 +- ...deploy-website.yaml => deploy-website.yml} | 0 pom.xml | 88 ++++++++++++++----- 4 files changed, 69 insertions(+), 21 deletions(-) rename .github/workflows/{build.yaml => build.yml} (100%) rename .github/workflows/{deploy-website.yaml => deploy-website.yml} (100%) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yml similarity index 100% rename from .github/workflows/build.yaml rename to .github/workflows/build.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index a5b5928c8c..f753537304 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -37,7 +37,7 @@ jobs: languages: ${{ matrix.language }} - name: Perform minimal build if: matrix.language == 'java' - run: mvn -T1C clean install -DskipTests -Dverification.skip + run: mvn -T1C clean package -DskipTests -Dverification.skip - name: Perform CodeQL analysis uses: github/codeql-action/analyze@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5 with: diff --git a/.github/workflows/deploy-website.yaml b/.github/workflows/deploy-website.yml similarity index 100% rename from .github/workflows/deploy-website.yaml rename to .github/workflows/deploy-website.yml diff --git a/pom.xml b/pom.xml index 932a3c946f..5d4b6b7f60 100644 --- a/pom.xml +++ b/pom.xml @@ -47,9 +47,9 @@ refaster-test-support - + scm:git:git@github.com:PicnicSupermarket/error-prone-support.git - v0.12.0 + HEAD https://github.com/PicnicSupermarket/error-prone-support @@ -100,6 +100,10 @@ -XX:TieredStopAtLevel=1 + + -XX:+UseParallelGC @@ -141,7 +145,7 @@ com.google.errorprone - 2023-10-04T14:40:37Z + ${git.commit.time} UTF-8 + + + @@ -810,6 +826,7 @@ + @@ -1284,6 +1301,14 @@ org.codehaus.mojo tidy-maven-plugin 1.2.0 + + + check-pom + + check + + + org.codehaus.mojo @@ -1520,7 +1545,7 @@ `BugChecker` test code and the Refaster test files) does not exhibit anti-patterns other than those associated with the check/rule under test. Ideally all test cases are realistic. --> - -XepAllSuggestionsAsWarnings -Xep:MethodReferenceUsage:OFF + -Xep:MethodReferenceUsage:OFF @@ -1545,6 +1570,31 @@ + + + avoid-errors + + + verification.warn + + + + + + + org.codehaus.mojo + tidy-maven-plugin + + true + + + + + + -XepAllErrorsAsWarnings + -XepAllSuggestionsAsWarnings + + -XepAllDisabledChecksAsWarnings -XepDisableWarningsInGeneratedCode - - -XepAllDisabledChecksAsWarnings + -XepExcludedPaths:\Q${project.build.directory}${file.separator}\E.* -Xep:AndroidJdkLibsChecker:OFF + disallow-warnings From 17c7b396d20390a70a8c5a771db65c8363cb896a Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 27 Nov 2023 11:40:16 +0100 Subject: [PATCH 557/601] Simplify `AbstractMatcherTestChecker` (#853) By using `TreePathScanner` rather than directly using `TreeScanner`. --- .../matchers/AbstractMatcherTestChecker.java | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java index 48fac2d44f..2f1f7e7375 100644 --- a/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java +++ b/refaster-support/src/test/java/tech/picnic/errorprone/refaster/matchers/AbstractMatcherTestChecker.java @@ -13,7 +13,7 @@ import com.sun.source.tree.Tree; import com.sun.source.tree.TypeCastTree; import com.sun.source.util.TreePath; -import com.sun.source.util.TreeScanner; +import com.sun.source.util.TreePathScanner; import org.jspecify.annotations.Nullable; /** @@ -34,15 +34,11 @@ abstract class AbstractMatcherTestChecker extends BugChecker implements Compilat @Override public Description matchCompilationUnit(CompilationUnitTree compilationUnit, VisitorState state) { - new TreeScanner<@Nullable Void, TreePath>() { + new TreePathScanner<@Nullable Void, @Nullable Void>() { @Override - public @Nullable Void scan(@Nullable Tree tree, TreePath treePath) { - if (tree == null) { - return null; - } - - TreePath path = new TreePath(treePath, tree); + public @Nullable Void scan(@Nullable Tree tree, @Nullable Void unused) { if (tree instanceof ExpressionTree) { + TreePath path = new TreePath(getCurrentPath(), tree); ExpressionTree expressionTree = (ExpressionTree) tree; if (!isMethodSelect(expressionTree, path) && delegate.matches(expressionTree, state.withPath(path))) { @@ -50,11 +46,11 @@ public Description matchCompilationUnit(CompilationUnitTree compilationUnit, Vis } } - return super.scan(tree, path); + return super.scan(tree, null); } @Override - public @Nullable Void visitImport(ImportTree tree, TreePath path) { + public @Nullable Void visitImport(ImportTree tree, @Nullable Void unused) { /* * We're not interested in matching import statements. While components of these * can be `ExpressionTree`s, they will never be matched by Refaster. @@ -63,24 +59,24 @@ public Description matchCompilationUnit(CompilationUnitTree compilationUnit, Vis } @Override - public @Nullable Void visitMethod(MethodTree tree, TreePath path) { + public @Nullable Void visitMethod(MethodTree tree, @Nullable Void unused) { /* * We're not interested in matching e.g. parameter and return type declarations. While these * can be `ExpressionTree`s, they will never be matched by Refaster. */ - return scan(tree.getBody(), new TreePath(path, tree)); + return scan(tree.getBody(), null); } @Override - public @Nullable Void visitTypeCast(TypeCastTree tree, TreePath path) { + public @Nullable Void visitTypeCast(TypeCastTree tree, @Nullable Void unused) { /* * We're not interested in matching the parenthesized type subtree that is part of a type * cast expression. While such trees can be `ExpressionTree`s, they will never be matched by * Refaster. */ - return scan(tree.getExpression(), new TreePath(path, tree)); + return scan(tree.getExpression(), null); } - }.scan(compilationUnit, state.getPath()); + }.scan(compilationUnit, null); return Description.NO_MATCH; } From 5618de49f4917ae020ba9a0f6bd35b65aaff0c4e Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 27 Nov 2023 13:12:17 +0100 Subject: [PATCH 558/601] Introduce `ConstantsFormat` Refaster rule (#883) --- .../picnic/errorprone/bugpatterns/StringJoin.java | 4 ++-- .../errorprone/refasterrules/BugCheckerRules.java | 15 +++++++++++++++ .../refasterrules/BugCheckerRulesTestInput.java | 7 ++++++- .../refasterrules/BugCheckerRulesTestOutput.java | 8 +++++++- .../refaster/test/RefasterRuleCollection.java | 5 +++-- 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java index ff520704f3..8d256c4f11 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java @@ -23,7 +23,7 @@ import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.MethodInvocationTree; import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.util.Convert; +import com.sun.tools.javac.util.Constants; import java.util.Formattable; import java.util.Iterator; import java.util.List; @@ -150,7 +150,7 @@ private Description trySuggestExplicitJoin( SuggestedFix.Builder fix = SuggestedFix.builder() .replace(tree.getMethodSelect(), "String.join") - .replace(arguments.next(), String.format("\"%s\"", Convert.quote(separator))); + .replace(arguments.next(), Constants.format(separator)); while (arguments.hasNext()) { ExpressionTree argument = arguments.next(); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BugCheckerRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BugCheckerRules.java index fc3727af6d..db21ddb711 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BugCheckerRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/BugCheckerRules.java @@ -7,6 +7,8 @@ import com.google.errorprone.refaster.Refaster; import com.google.errorprone.refaster.annotation.AfterTemplate; import com.google.errorprone.refaster.annotation.BeforeTemplate; +import com.sun.tools.javac.util.Constants; +import com.sun.tools.javac.util.Convert; import tech.picnic.errorprone.refaster.annotation.OnlineDocumentation; /** Refaster rules related to {@link com.google.errorprone.bugpatterns.BugChecker} classes. */ @@ -52,4 +54,17 @@ BugCheckerRefactoringTestHelper after( return helper.addInputLines(path, source).expectUnchanged(); } } + + /** Prefer using the {@link Constants} API over more verbose alternatives. */ + static final class ConstantsFormat { + @BeforeTemplate + String before(String value) { + return String.format("\"%s\"", Convert.quote(value)); + } + + @AfterTemplate + String after(String value) { + return Constants.format(value); + } + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestInput.java index 2d0aa62291..91b0bf5962 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestInput.java @@ -4,12 +4,13 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; import com.google.errorprone.bugpatterns.BugChecker; +import com.sun.tools.javac.util.Convert; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class BugCheckerRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(FixChoosers.class); + return ImmutableSet.of(Convert.class, FixChoosers.class); } ImmutableSet testBugCheckerRefactoringTestHelperIdentity() { @@ -26,4 +27,8 @@ ImmutableSet testBugCheckerRefactoringTestHelpe .addInputLines("A.java", "class A {}") .addOutputLines("A.java", "class A {}"); } + + String testConstantsFormat() { + return String.format("\"%s\"", Convert.quote("foo")); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestOutput.java index d1f21fd0a7..013617aad6 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/BugCheckerRulesTestOutput.java @@ -4,12 +4,14 @@ import com.google.errorprone.BugCheckerRefactoringTestHelper; import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers; import com.google.errorprone.bugpatterns.BugChecker; +import com.sun.tools.javac.util.Constants; +import com.sun.tools.javac.util.Convert; import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase; final class BugCheckerRulesTest implements RefasterRuleCollectionTestCase { @Override public ImmutableSet elidedTypesAndStaticImports() { - return ImmutableSet.of(FixChoosers.class); + return ImmutableSet.of(Convert.class, FixChoosers.class); } ImmutableSet testBugCheckerRefactoringTestHelperIdentity() { @@ -24,4 +26,8 @@ ImmutableSet testBugCheckerRefactoringTestHelpe .addInputLines("A.java", "class A {}") .expectUnchanged(); } + + String testConstantsFormat() { + return Constants.format("foo"); + } } diff --git a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java index 150a606429..5fb620f496 100644 --- a/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java +++ b/refaster-test-support/src/main/java/tech/picnic/errorprone/refaster/test/RefasterRuleCollection.java @@ -8,7 +8,6 @@ import static java.util.Comparator.naturalOrder; import static tech.picnic.errorprone.refaster.runner.Refaster.INCLUDED_RULES_PATTERN_FLAG; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableRangeMap; @@ -123,7 +122,9 @@ public static void validate(Class clazz) { String className = clazz.getSimpleName(); BugCheckerRefactoringTestHelper.newInstance(RefasterRuleCollection.class, clazz) - .setArgs(ImmutableList.of("-XepOpt:" + RULE_COLLECTION_FLAG + '=' + className)) + .setArgs( + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED", + "-XepOpt:" + RULE_COLLECTION_FLAG + '=' + className) .addInput(className + "TestInput.java") .addOutput(className + "TestOutput.java") .doTest(TestMode.TEXT_MATCH); From 7ae9356c9eec700ea81adae39a1d6ca7496fc841 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 28 Nov 2023 08:58:20 +0100 Subject: [PATCH 559/601] Upgrade Pitest Git plugins 1.1.2 -> 1.1.3 (#897) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5d4b6b7f60..9c8ca4cc37 100644 --- a/pom.xml +++ b/pom.xml @@ -213,7 +213,7 @@ 5.7.0 1.0.1 0.10.17 - 1.1.2 + 1.1.3 3.2.2 From e9a5295e80d5e570b11e4fb7254f34f7d5c0a5de Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Thu, 30 Nov 2023 12:50:42 +0100 Subject: [PATCH 560/601] Reference conference talk in README (#877) While there, fix some URLs broken by eafb73814ace9e66bc24e6dbb0cf9f2476495a0d. --- README.md | 13 ++++++++----- website/README.md | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index f84b25250d..73a60757eb 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,11 @@ focussing on maintainability, consistency and avoidance of common pitfalls. > Error Prone is a static analysis tool for Java that catches common > programming mistakes at compile-time. -Read more on how Picnic uses Error Prone (Support) in the blog post [_Picnic -loves Error Prone: producing high-quality and consistent Java -code_][picnic-blog-ep-post]. +To learn more about Error Prone (Support), how you can start using Error Prone +in practice, and how we use it at Picnic, watch the conference talk +[_Automating away bugs with Error Prone in practice_][conference-talk]. Also +consider checking out the blog post [_Picnic loves Error Prone: producing +high-quality and consistent Java code_][picnic-blog-ep-post]. [![Maven Central][maven-central-badge]][maven-central-search] [![Reproducible Builds][reproducible-builds-badge]][reproducible-builds-report] @@ -265,6 +267,7 @@ channel; please see our [security policy][security] for details. [bug-checks-identity-conversion]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java [codeql-badge]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/codeql.yml/badge.svg?branch=master&event=push [codeql-master]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/codeql.yml?query=branch:master+event:push +[conference-talk]: https://www.youtube.com/watch?v=-47WD-3wKBs [contributing]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/CONTRIBUTING.md [contributing-pull-request]: https://github.com/PicnicSupermarket/error-prone-support/blob/master/CONTRIBUTING.md#-opening-a-pull-request [error-prone-bugchecker]: https://github.com/google/error-prone/blob/master/check_api/src/main/java/com/google/errorprone/bugpatterns/BugChecker.java @@ -274,8 +277,8 @@ channel; please see our [security policy][security] for details. [error-prone-installation-guide]: https://errorprone.info/docs/installation#maven [error-prone-orig-repo]: https://github.com/google/error-prone [error-prone-pull-3301]: https://github.com/google/error-prone/pull/3301 -[github-actions-build-badge]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/build.yaml/badge.svg -[github-actions-build-master]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/build.yaml?query=branch:master&event=push +[github-actions-build-badge]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/build.yml/badge.svg +[github-actions-build-master]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/build.yml?query=branch:master&event=push [google-java-format]: https://github.com/google/google-java-format [idea-288052]: https://youtrack.jetbrains.com/issue/IDEA-288052 [license-badge]: https://img.shields.io/github/license/PicnicSupermarket/error-prone-support diff --git a/website/README.md b/website/README.md index a8fe96535e..49111ad105 100644 --- a/website/README.md +++ b/website/README.md @@ -51,11 +51,11 @@ bundle install # Deployment The website is regenerated and deployed using the -[`deploy-website.yaml`][error-prone-support-website-deploy-workflow] GitHub +[`deploy-website.yml`][error-prone-support-website-deploy-workflow] GitHub Actions workflow any time a change is merged to `master`. [error-prone-support-website]: https://error-prone.picnic.tech -[error-prone-support-website-deploy-workflow]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/deploy-website.yaml +[error-prone-support-website-deploy-workflow]: https://github.com/PicnicSupermarket/error-prone-support/actions/workflows/deploy-website.yml [jekyll]: https://jekyllrb.com [jekyll-docs]: https://jekyllrb.com/docs [jekyll-docs-installation]: https://jekyllrb.com/docs/installation From ad5dd92b9ab1f3ae3eee2cacf0f341fc2f47f997 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 30 Nov 2023 18:59:39 +0100 Subject: [PATCH 561/601] Upgrade Pitest Git plugins 1.1.3 -> 1.1.4 (#898) --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9c8ca4cc37..7bbb638f74 100644 --- a/pom.xml +++ b/pom.xml @@ -213,7 +213,7 @@ 5.7.0 1.0.1 0.10.17 - 1.1.3 + 1.1.4 3.2.2 From 351b886e6c534423e0099b74170e8a8b94c6873f Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 1 Dec 2023 08:42:19 +0100 Subject: [PATCH 562/601] Upgrade NullAway 0.10.17 -> 0.10.18 (#900) See: - https://github.com/uber/NullAway/blob/master/CHANGELOG.md - https://github.com/uber/NullAway/releases/tag/v0.10.18 - https://github.com/uber/NullAway/compare/v0.10.17...v0.10.18 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7bbb638f74..6fd0598154 100644 --- a/pom.xml +++ b/pom.xml @@ -212,7 +212,7 @@ 3.8.7 5.7.0 1.0.1 - 0.10.17 + 0.10.18 1.1.4 3.2.2 From 5d120252ac921b736536e346d0a38027bd838298 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 3 Dec 2023 19:40:39 +0100 Subject: [PATCH 563/601] Upgrade Mockito 5.7.0 -> 5.8.0 (#902) See: - https://github.com/mockito/mockito/releases/tag/v5.8.0 - https://github.com/mockito/mockito/compare/v5.7.0...v5.8.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6fd0598154..443757fcd1 100644 --- a/pom.xml +++ b/pom.xml @@ -210,7 +210,7 @@ 1.0 11 3.8.7 - 5.7.0 + 5.8.0 1.0.1 0.10.18 1.1.4 From 6b73f03b221f5938e73d2b165f94eee644db52e4 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 4 Dec 2023 07:18:13 +0100 Subject: [PATCH 564/601] Upgrade CodeQL v2.22.5 -> v2.22.8 (#903) See: - https://github.com/github/codeql-action/blob/main/CHANGELOG.md - https://github.com/github/codeql-action/compare/v2.22.5...v2.22.8 --- .github/workflows/codeql.yml | 4 ++-- .github/workflows/openssf-scorecard.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f753537304..db4b53438e 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -32,13 +32,13 @@ jobs: distribution: temurin cache: maven - name: Initialize CodeQL - uses: github/codeql-action/init@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5 + uses: github/codeql-action/init@407ffafae6a767df3e0230c3df91b6443ae8df75 # v2.22.8 with: languages: ${{ matrix.language }} - name: Perform minimal build if: matrix.language == 'java' run: mvn -T1C clean package -DskipTests -Dverification.skip - name: Perform CodeQL analysis - uses: github/codeql-action/analyze@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5 + uses: github/codeql-action/analyze@407ffafae6a767df3e0230c3df91b6443ae8df75 # v2.22.8 with: category: /language:${{ matrix.language }} diff --git a/.github/workflows/openssf-scorecard.yml b/.github/workflows/openssf-scorecard.yml index d813420298..caa3aa3f90 100644 --- a/.github/workflows/openssf-scorecard.yml +++ b/.github/workflows/openssf-scorecard.yml @@ -31,6 +31,6 @@ jobs: results_format: sarif publish_results: ${{ github.ref == 'refs/heads/master' }} - name: Update GitHub's code scanning dashboard - uses: github/codeql-action/upload-sarif@74483a38d39275f33fcff5f35b679b5ca4a26a99 # v2.22.5 + uses: github/codeql-action/upload-sarif@407ffafae6a767df3e0230c3df91b6443ae8df75 # v2.22.8 with: sarif_file: results.sarif From a5b71410aec9b4bff6766fd2bee6895eb2fac6b3 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 4 Dec 2023 07:41:00 +0100 Subject: [PATCH 565/601] Upgrade actions/setup-java v3.13.0 -> v4.0.0 (#899) See: - https://github.com/actions/setup-java/releases/tag/v4.0.0 --- .github/workflows/build.yml | 2 +- .github/workflows/codeql.yml | 2 +- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/pitest-update-pr.yml | 2 +- .github/workflows/run-integration-tests.yml | 2 +- .github/workflows/sonarcloud.yml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index da88764351..1cf9ef8f11 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: with: persist-credentials: false - name: Set up JDK - uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 with: java-version: ${{ matrix.jdk }} distribution: ${{ matrix.distribution }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index db4b53438e..b45966b69c 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -26,7 +26,7 @@ jobs: with: persist-credentials: false - name: Set up JDK - uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 with: java-version: 17.0.8 distribution: temurin diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index 4ded8ed954..f97b90eabc 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -17,7 +17,7 @@ jobs: fetch-depth: 2 persist-credentials: false - name: Set up JDK - uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 with: java-version: 17.0.8 distribution: temurin diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index bc7b1ef632..1a5c8d3484 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -24,7 +24,7 @@ jobs: with: persist-credentials: false - name: Set up JDK - uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 with: java-version: 17.0.8 distribution: temurin diff --git a/.github/workflows/run-integration-tests.yml b/.github/workflows/run-integration-tests.yml index a51bba2706..22e6e890c6 100644 --- a/.github/workflows/run-integration-tests.yml +++ b/.github/workflows/run-integration-tests.yml @@ -24,7 +24,7 @@ jobs: persist-credentials: false ref: refs/pull/${{ github.event.issue.number }}/head - name: Set up JDK - uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 with: java-version: 17.0.8 distribution: temurin diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index feaedba873..bc9ce08e30 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -21,7 +21,7 @@ jobs: fetch-depth: 0 persist-credentials: false - name: Set up JDK - uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0 # v3.13.0 + uses: actions/setup-java@387ac29b308b003ca37ba93a6cab5eb57c8f5f93 # v4.0.0 with: java-version: 17.0.8 distribution: temurin From b3462b0a1eab09e0540bfbc3635a617388d9bcab Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 4 Dec 2023 08:27:55 +0100 Subject: [PATCH 566/601] Upgrade ruby/setup-ruby v1.159.0 -> v1.161.0 (#905) See: - https://github.com/ruby/setup-ruby/releases/tag/v1.161.0 - https://github.com/ruby/setup-ruby/releases/tag/v1.160.0 --- .github/workflows/deploy-website.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index 476ea108d3..8e80dbbf3b 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 with: persist-credentials: false - - uses: ruby/setup-ruby@54a18e26dbbb1eabc604f317ade9a5788dddef81 # v1.159.0 + - uses: ruby/setup-ruby@8575951200e472d5f2d95c625da0c7bec8217c42 # v1.161.0 with: working-directory: ./website bundler-cache: true From 49e7313e1c1a26c4bbda132c22cc332412da1057 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 4 Dec 2023 08:57:52 +0100 Subject: [PATCH 567/601] Upgrade maven-javadoc-plugin 3.6.2 -> 3.6.3 (#904) See: - https://github.com/apache/maven-javadoc-plugin/releases/tag/maven-javadoc-plugin-3.6.3 - https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.6.2...maven-javadoc-plugin-3.6.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 443757fcd1..2a6804cf7f 100644 --- a/pom.xml +++ b/pom.xml @@ -1111,7 +1111,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.6.2 + 3.6.3 --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED From f5022efe682089734cc7c8b7ee7414e6eab849a2 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 5 Dec 2023 18:25:46 +0100 Subject: [PATCH 568/601] Upgrade actions/deploy-pages v2.0.4 -> v2.0.5 (#901) See: - https://github.com/actions/deploy-pages/releases/tag/v2.0.5 --- .github/workflows/deploy-website.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index 8e80dbbf3b..869e5d6a6d 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -48,4 +48,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@9dbe3824824f8a1377b8e298bafde1a50ede43e5 # v2.0.4 + uses: actions/deploy-pages@de14547edc9944350dc0481aa5b7afb08e75f254 # v2.0.5 From 276529fd348b9fc9e8a498e654409937e7c72400 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 6 Dec 2023 09:05:12 +0100 Subject: [PATCH 569/601] Upgrade actions/configure-pages v3.0.6 -> v3.0.7 (#906) See: - https://github.com/actions/configure-pages/releases/tag/v3.0.7 --- .github/workflows/deploy-website.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index 869e5d6a6d..b1a8aa82e7 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -20,7 +20,7 @@ jobs: working-directory: ./website bundler-cache: true - name: Configure Github Pages - uses: actions/configure-pages@f156874f8191504dae5b037505266ed5dda6c382 # v3.0.6 + uses: actions/configure-pages@b8130d9ab958b325bbde9786d62f2c97a9885a0e # v3.0.7 - name: Generate documentation run: ./generate-docs.sh - name: Build website with Jekyll From 94edab3b4f9efa2c338b494673d1e527333696af Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 6 Dec 2023 09:15:36 +0100 Subject: [PATCH 570/601] Upgrade actions/configure-pages v3.0.7 -> v4.0.0 (#908) See: - https://github.com/actions/configure-pages/releases/tag/v4.0.0 --- .github/workflows/deploy-website.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index b1a8aa82e7..89ed046b36 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -20,7 +20,7 @@ jobs: working-directory: ./website bundler-cache: true - name: Configure Github Pages - uses: actions/configure-pages@b8130d9ab958b325bbde9786d62f2c97a9885a0e # v3.0.7 + uses: actions/configure-pages@1f0c5cde4bc74cd7e1254d0cb4de8d49e9068c7d # v4.0.0 - name: Generate documentation run: ./generate-docs.sh - name: Build website with Jekyll From ff3f96382084331f9aebbfbe0442dbb529b61012 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 6 Dec 2023 09:36:11 +0100 Subject: [PATCH 571/601] Upgrade actions/deploy-pages v2.0.5 -> v3.0.0 (#909) See: - https://github.com/actions/deploy-pages/releases/tag/v3.0.0 --- .github/workflows/deploy-website.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index 89ed046b36..e09db7ad6f 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -48,4 +48,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@de14547edc9944350dc0481aa5b7afb08e75f254 # v2.0.5 + uses: actions/deploy-pages@77d7344265e1f960dab5c00dbff52287a70b0d4f # v3.0.0 From 5b011312e18e720057512202d6f8e67b6243d9d2 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 11 Dec 2023 21:42:20 +0100 Subject: [PATCH 572/601] Upgrade errorprone-slf4j 0.1.20 -> 0.1.21 (#913) See: - https://github.com/KengoTODA/errorprone-slf4j/releases/tag/v0.1.21 - https://github.com/KengoTODA/errorprone-slf4j/compare/v0.1.20...v0.1.21 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2a6804cf7f..affb84312d 100644 --- a/pom.xml +++ b/pom.xml @@ -206,7 +206,7 @@ ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 2.23.0 - 0.1.20 + 0.1.21 1.0 11 3.8.7 From fd97ac3676dba4045ccf116ed476279a4a95fedf Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 12 Dec 2023 08:05:08 +0100 Subject: [PATCH 573/601] Upgrade actions/deploy-pages v3.0.0 -> v3.0.1 (#912) See: - https://github.com/actions/deploy-pages/releases/tag/v3.0.1 --- .github/workflows/deploy-website.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index e09db7ad6f..90df1ecff8 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -48,4 +48,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@77d7344265e1f960dab5c00dbff52287a70b0d4f # v3.0.0 + uses: actions/deploy-pages@13b55b33dd8996121833dbc1db458c793a334630 # v3.0.1 From 738a6706fdb73ce9575b44a2b76e217b3f1528fd Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Tue, 12 Dec 2023 08:16:29 +0100 Subject: [PATCH 574/601] Upgrade Checker Framework Annotations 3.40.0 -> 3.41.0 (#907) See: - https://github.com/typetools/checker-framework/releases/tag/checker-framework-3.41.0 - https://github.com/typetools/checker-framework/compare/checker-framework-3.40.0...checker-framework-3.41.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index affb84312d..016092a562 100644 --- a/pom.xml +++ b/pom.xml @@ -411,7 +411,7 @@ org.checkerframework checker-qual - 3.40.0 + 3.41.0 org.hamcrest From f0ff5c3fd6adf1cb6b27285486142b1699a63691 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 13 Dec 2023 08:57:00 +0100 Subject: [PATCH 575/601] Upgrade dawidd6/action-download-artifact v2.28.0 -> v2.28.1 (#917) See: - https://github.com/dawidd6/action-download-artifact/compare/v2.28.0...v2.28.1 --- .github/workflows/pitest-update-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index 1a5c8d3484..4cb389eacf 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -30,7 +30,7 @@ jobs: distribution: temurin cache: maven - name: Download Pitest analysis artifact - uses: dawidd6/action-download-artifact@268677152d06ba59fcec7a7f0b5d961b6ccd7e1e # v2.28.0 + uses: dawidd6/action-download-artifact@f29d1b6a8930683e80acedfbe6baa2930cd646b4 # v2.28.1 with: workflow: ${{ github.event.workflow_run.workflow_id }} name: pitest-reports From 74de2535f506c798ea4c2a3282d585403d71cc29 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 14 Dec 2023 07:09:49 +0100 Subject: [PATCH 576/601] Upgrade AspectJ 1.9.20.1 -> 1.9.21 (#916) See: - https://github.com/eclipse-aspectj/aspectj/releases/tag/V1_9_21 - https://github.com/eclipse-aspectj/aspectj/compare/V1_9_20_1...V1_9_21 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 016092a562..e3be1f5869 100644 --- a/pom.xml +++ b/pom.xml @@ -399,7 +399,7 @@ org.aspectj aspectjweaver - 1.9.20.1 + 1.9.21 org.assertj From b73b05a5c4a06d6a5abf843bfcaf3590d5c40ac0 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 14 Dec 2023 08:54:36 +0100 Subject: [PATCH 577/601] Upgrade dawidd6/action-download-artifact v2.28.1 -> v3.0.0 (#919) See: - https://github.com/dawidd6/action-download-artifact/releases/tag/v3.0.0 --- .github/workflows/pitest-update-pr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pitest-update-pr.yml b/.github/workflows/pitest-update-pr.yml index 4cb389eacf..5935100cf1 100644 --- a/.github/workflows/pitest-update-pr.yml +++ b/.github/workflows/pitest-update-pr.yml @@ -30,7 +30,7 @@ jobs: distribution: temurin cache: maven - name: Download Pitest analysis artifact - uses: dawidd6/action-download-artifact@f29d1b6a8930683e80acedfbe6baa2930cd646b4 # v2.28.1 + uses: dawidd6/action-download-artifact@e7466d1a7587ed14867642c2ca74b5bcc1e19a2d # v3.0.0 with: workflow: ${{ github.event.workflow_run.workflow_id }} name: pitest-reports From cc3e30f2530ba2050a24fd63c9affb786b63f7de Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Thu, 14 Dec 2023 09:07:04 +0100 Subject: [PATCH 578/601] Upgrade Project Reactor 2023.0.0 -> 2023.0.1 (#918) See: - https://github.com/reactor/reactor/releases/tag/2023.0.1 - https://github.com/reactor/reactor/compare/2023.0.0...2023.0.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e3be1f5869..9a0efe85e1 100644 --- a/pom.xml +++ b/pom.xml @@ -337,7 +337,7 @@ io.projectreactor reactor-bom - 2023.0.0 + 2023.0.1 pom import From a966c1a17a0d6a8d1248cc4b992e78023760e4e8 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 15 Dec 2023 08:25:01 +0100 Subject: [PATCH 579/601] Upgrade actions/upload-artifact v3.1.3 -> v4.0.0 (#921) See: - https://github.com/actions/upload-artifact/releases/tag/v4.0.0 - https://github.com/actions/upload-artifact/compare/v3.1.3...v4.0.0 --- .github/workflows/pitest-analyze-pr.yml | 2 +- .github/workflows/run-integration-tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pitest-analyze-pr.yml b/.github/workflows/pitest-analyze-pr.yml index f97b90eabc..bdcfc2ce77 100644 --- a/.github/workflows/pitest-analyze-pr.yml +++ b/.github/workflows/pitest-analyze-pr.yml @@ -32,7 +32,7 @@ jobs: - name: Aggregate Pitest reports run: mvn pitest-git:aggregate -DkilledEmoji=":tada:" -DmutantEmoji=":zombie:" -DtrailingText="Mutation testing report by [Pitest](https://pitest.org/). Review any surviving mutants by inspecting the line comments under [_Files changed_](${{ github.event.number }}/files)." - name: Upload Pitest reports as artifact - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 + uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0 with: name: pitest-reports path: ./target/pit-reports-ci diff --git a/.github/workflows/run-integration-tests.yml b/.github/workflows/run-integration-tests.yml index 22e6e890c6..aae394d708 100644 --- a/.github/workflows/run-integration-tests.yml +++ b/.github/workflows/run-integration-tests.yml @@ -35,7 +35,7 @@ jobs: run: xvfb-run ./integration-tests/checkstyle-10.12.4.sh "${{ runner.temp }}/artifacts" - name: Upload artifacts on failure if: ${{ failure() }} - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 + uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0 with: name: integration-test-checkstyle-10.12.4 path: "${{ runner.temp }}/artifacts" From 7529b9925145c3fdaf0864a6df99b6cbb20d7d7f Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Sat, 16 Dec 2023 13:14:33 +0100 Subject: [PATCH 580/601] Show Christmas Cody in README and on website home page (#923) --- website/assets/images/logo-dark.svg | 255 ++++++++++++++++++++++++++-- website/assets/images/logo.svg | 255 ++++++++++++++++++++++++++-- 2 files changed, 490 insertions(+), 20 deletions(-) diff --git a/website/assets/images/logo-dark.svg b/website/assets/images/logo-dark.svg index bd0c9ff013..23d9aa4e20 100644 --- a/website/assets/images/logo-dark.svg +++ b/website/assets/images/logo-dark.svg @@ -1,10 +1,245 @@ - - 1 0 - - 1 1 0 - - 0 0 1 - - 1 0 0 1 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/website/assets/images/logo.svg b/website/assets/images/logo.svg index 97f1342ffc..23d9aa4e20 100644 --- a/website/assets/images/logo.svg +++ b/website/assets/images/logo.svg @@ -1,10 +1,245 @@ - - 1 0 - - 1 1 0 - - 0 0 1 - - 1 0 0 1 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 7c2078b771f218269534f4c34966e170049d53d8 Mon Sep 17 00:00:00 2001 From: Austin Richardson Date: Mon, 18 Dec 2023 07:17:00 +0100 Subject: [PATCH 581/601] Require static importing of some `com.fasterxml.jackson.annotation` enums (#910) Types to be imported statically: - `com.fasterxml.jackson.annotation.JsonCreator.Mode` - `com.fasterxml.jackson.annotation.JsonFormat.Shape` - `com.fasterxml.jackson.annotation.JsonInclude.Include` - `com.fasterxml.jackson.annotation.JsonProperty.Access` --- .../errorprone/bugpatterns/StaticImport.java | 4 ++++ .../bugpatterns/StaticImportTest.java | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java index 3adb431a9c..8eb703f76d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java @@ -57,6 +57,10 @@ public final class StaticImport extends BugChecker implements MemberSelectTreeMa @VisibleForTesting static final ImmutableSet STATIC_IMPORT_CANDIDATE_TYPES = ImmutableSet.of( + "com.fasterxml.jackson.annotation.JsonCreator.Mode", + "com.fasterxml.jackson.annotation.JsonFormat.Shape", + "com.fasterxml.jackson.annotation.JsonInclude.Include", + "com.fasterxml.jackson.annotation.JsonProperty.Access", "com.google.common.base.Preconditions", "com.google.common.base.Predicates", "com.google.common.base.Verify", diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java index bcfb097d39..4dde83f6e1 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/StaticImportTest.java @@ -40,6 +40,7 @@ void identification() { "import static java.util.function.Predicate.not;", "import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;", "", + "import com.fasterxml.jackson.annotation.JsonCreator;", "import com.google.common.base.Predicates;", "import com.google.common.collect.ImmutableMap;", "import com.google.common.collect.ImmutableMultiset;", @@ -106,6 +107,12 @@ void identification() { " }", "", " // BUG: Diagnostic contains:", + " @JsonCreator(mode = JsonCreator.Mode.DELEGATING)", + " private static A jsonCreator(int a) {", + " return new A();", + " }", + "", + " // BUG: Diagnostic contains:", " @UseImportPolicy(ImportPolicy.IMPORT_TOP_LEVEL)", " void refasterAfterTemplate() {}", "", @@ -121,6 +128,7 @@ void replacement() { "A.java", "import static java.util.function.Predicate.not;", "", + "import com.fasterxml.jackson.annotation.JsonCreator;", "import com.google.common.base.Predicates;", "import com.google.common.collect.ImmutableMap;", "import com.google.common.collect.ImmutableSet;", @@ -177,6 +185,11 @@ void replacement() { " @DateTimeFormat(iso = ISO.DATE_TIME) String dateTime,", " @DateTimeFormat(iso = ISO.TIME) String time) {}", "", + " @JsonCreator(mode = JsonCreator.Mode.DELEGATING)", + " private static A jsonCreator(int a) {", + " return new A();", + " }", + "", " @BugPattern(", " summary = \"\",", " linkType = BugPattern.LinkType.NONE,", @@ -189,6 +202,7 @@ void replacement() { "}") .addOutputLines( "A.java", + "import static com.fasterxml.jackson.annotation.JsonCreator.Mode.DELEGATING;", "import static com.google.common.collect.ImmutableMap.toImmutableMap;", "import static com.google.common.collect.ImmutableSet.toImmutableSet;", "import static com.google.errorprone.BugPattern.LinkType.NONE;", @@ -208,6 +222,7 @@ void replacement() { "import static org.springframework.http.MediaType.APPLICATION_XHTML_XML;", "import static org.springframework.http.MediaType.TEXT_HTML;", "", + "import com.fasterxml.jackson.annotation.JsonCreator;", "import com.google.common.base.Predicates;", "import com.google.common.collect.ImmutableMap;", "import com.google.common.collect.ImmutableSet;", @@ -261,6 +276,11 @@ void replacement() { " @DateTimeFormat(iso = DATE_TIME) String dateTime,", " @DateTimeFormat(iso = TIME) String time) {}", "", + " @JsonCreator(mode = DELEGATING)", + " private static A jsonCreator(int a) {", + " return new A();", + " }", + "", " @BugPattern(summary = \"\", linkType = NONE, severity = SUGGESTION, tags = SIMPLIFICATION)", " static final class TestBugPattern {}", "", From ff3be8ae3fc23072976c601e73a2b46d0792d7e9 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 18 Dec 2023 08:34:30 +0100 Subject: [PATCH 582/601] Skip SonarCloud analysis of PRs from forked repositories (#926) Because such analysis will fail due to unavailability of the relevant secrets. Working around this is nontrivial and a likely source of security issues. --- .github/workflows/sonarcloud.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index bc9ce08e30..4239246183 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -11,6 +11,9 @@ permissions: contents: read jobs: analyze: + # Analysis of code in forked repositories is skipped, as such workflow runs + # do not have access to the requisite secrets. + if: github.event.pull_request.head.repo.full_name == github.repository permissions: contents: read runs-on: ubuntu-22.04 From 22272d60599b76a10f8cbd996ca020295b2534f2 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 18 Dec 2023 09:06:32 +0100 Subject: [PATCH 583/601] Upgrade Surefire 3.2.2 -> 3.2.3 (#920) See: - https://github.com/apache/maven-surefire/releases/tag/surefire-3.2.3 - https://github.com/apache/maven-surefire/compare/surefire-3.2.2...surefire-3.2.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9a0efe85e1..fbd99a0bc0 100644 --- a/pom.xml +++ b/pom.xml @@ -214,7 +214,7 @@ 1.0.1 0.10.18 1.1.4 - 3.2.2 + 3.2.3 From 626246bcc05935af9564d67289dbafea9b0f9e25 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 18 Dec 2023 09:19:13 +0100 Subject: [PATCH 584/601] Introduce `CanonicalClassNameUsage` check (#881) Error Prone checks deal with source code and type matchers, both of which generally involve canonical type names, rather than the strings produced by `Class#getName()`. This distinction is particularly relevant when dealing with nested types. --- .../bugpatterns/CanonicalClassNameUsage.java | 92 +++++++++++++++++++ .../errorprone/bugpatterns/DirectReturn.java | 5 +- .../bugpatterns/ExplicitEnumOrdering.java | 2 +- .../bugpatterns/FluxFlatMapUsage.java | 2 +- .../bugpatterns/FluxImplicitBlock.java | 3 +- .../FormatStringConcatenation.java | 2 +- .../bugpatterns/IdentityConversion.java | 2 +- .../bugpatterns/JUnitValueSource.java | 12 +-- .../MockitoMockClassReference.java | 2 +- .../errorprone/bugpatterns/NonEmptyMono.java | 2 +- .../bugpatterns/PrimitiveComparison.java | 14 +-- .../RedundantStringConversion.java | 26 +++--- .../bugpatterns/RefasterAnyOfUsage.java | 2 +- .../errorprone/bugpatterns/StringJoin.java | 2 +- .../errorprone/bugpatterns/TimeZoneUsage.java | 21 +++-- .../CanonicalClassNameUsageTest.java | 82 +++++++++++++++++ .../bugpatterns/util/MoreMatchersTest.java | 4 +- .../errorprone/refaster/matchers/IsEmpty.java | 24 ++--- .../matchers/IsIdentityOperation.java | 8 +- .../matchers/IsRefasterAsVarargs.java | 2 +- 20 files changed, 247 insertions(+), 62 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalClassNameUsage.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalClassNameUsageTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalClassNameUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalClassNameUsage.java new file mode 100644 index 0000000000..eb62e6b41b --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalClassNameUsage.java @@ -0,0 +1,92 @@ +package tech.picnic.errorprone.bugpatterns; + +import static com.google.errorprone.BugPattern.LinkType.CUSTOM; +import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; +import static com.google.errorprone.BugPattern.StandardTags.FRAGILE_CODE; +import static com.google.errorprone.matchers.Matchers.allOf; +import static com.google.errorprone.matchers.Matchers.anything; +import static com.google.errorprone.matchers.Matchers.classLiteral; +import static com.google.errorprone.matchers.Matchers.instanceMethod; +import static com.google.errorprone.matchers.Matchers.receiverOfInvocation; +import static com.google.errorprone.matchers.Matchers.toType; +import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; + +import com.google.auto.service.AutoService; +import com.google.errorprone.BugPattern; +import com.google.errorprone.VisitorState; +import com.google.errorprone.annotations.Var; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; +import com.google.errorprone.fixes.SuggestedFixes; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.util.ASTHelpers; +import com.sun.source.tree.BinaryTree; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.MethodInvocationTree; +import com.sun.source.util.TreePath; +import com.sun.tools.javac.code.Symbol.MethodSymbol; +import java.util.regex.Pattern; + +/** + * A {@link BugChecker} that flags invocations of {@link Class#getName()} where {@link + * Class#getCanonicalName()} was likely meant. + * + *

For top-level types these two methods generally return the same result, but for nested types + * the former separates identifiers using a dollar sign ({@code $}) rather than a dot ({@code .}). + * + * @implNote This check currently only flags {@link Class#getName()} invocations on class literals, + * and doesn't flag method references. This avoids false positives, such as suggesting use of + * {@link Class#getCanonicalName()} in contexts where the canonical name is {@code null}. + */ +@AutoService(BugChecker.class) +@BugPattern( + summary = "This code should likely use the type's canonical name", + link = BUG_PATTERNS_BASE_URL + "CanonicalClassNameUsage", + linkType = CUSTOM, + severity = WARNING, + tags = FRAGILE_CODE) +public final class CanonicalClassNameUsage extends BugChecker + implements MethodInvocationTreeMatcher { + private static final long serialVersionUID = 1L; + private static final Matcher GET_NAME_INVOCATION = + toType( + MethodInvocationTree.class, + allOf( + receiverOfInvocation(classLiteral(anything())), + instanceMethod().onExactClass(Class.class.getCanonicalName()).named("getName"))); + private static final Pattern CANONICAL_NAME_USING_TYPES = + Pattern.compile("(com\\.google\\.errorprone|tech\\.picnic\\.errorprone)\\..*"); + + /** Instantiates a new {@link CanonicalClassNameUsage} instance. */ + public CanonicalClassNameUsage() {} + + @Override + public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { + if (!GET_NAME_INVOCATION.matches(tree, state) || !isPassedToCanonicalNameUsingType(state)) { + /* + * This is not a `class.getName()` invocation of which the result is passed to another method + * known to accept canonical type names. + */ + return Description.NO_MATCH; + } + + return describeMatch( + tree, SuggestedFixes.renameMethodInvocation(tree, "getCanonicalName", state)); + } + + private static boolean isPassedToCanonicalNameUsingType(VisitorState state) { + @Var TreePath path = state.getPath().getParentPath(); + while (path.getLeaf() instanceof BinaryTree) { + path = path.getParentPath(); + } + + return path.getLeaf() instanceof MethodInvocationTree + && isOwnedByCanonicalNameUsingType( + ASTHelpers.getSymbol((MethodInvocationTree) path.getLeaf())); + } + + private static boolean isOwnedByCanonicalNameUsingType(MethodSymbol symbol) { + return CANONICAL_NAME_USING_TYPES.matcher(symbol.owner.getQualifiedName()).matches(); + } +} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java index 212d0b1245..9ed26605e1 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/DirectReturn.java @@ -58,7 +58,10 @@ public final class DirectReturn extends BugChecker implements BlockTreeMatcher { private static final Matcher VARIABLE_RETURN = returnStatement(isVariable()); private static final Matcher MOCKITO_MOCK_OR_SPY_WITH_IMPLICIT_TYPE = allOf( - not(toType(MethodInvocationTree.class, argument(0, isSameType(Class.class.getName())))), + not( + toType( + MethodInvocationTree.class, + argument(0, isSameType(Class.class.getCanonicalName())))), staticMethod().onClass("org.mockito.Mockito").namedAnyOf("mock", "spy")); /** Instantiates a new {@link DirectReturn} instance. */ diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrdering.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrdering.java index b04f78073d..37fb7d6086 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrdering.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExplicitEnumOrdering.java @@ -44,7 +44,7 @@ public final class ExplicitEnumOrdering extends BugChecker implements MethodInvocationTreeMatcher { private static final long serialVersionUID = 1L; private static final Matcher EXPLICIT_ORDERING = - staticMethod().onClass(Ordering.class.getName()).named("explicit"); + staticMethod().onClass(Ordering.class.getCanonicalName()).named("explicit"); /** Instantiates a new {@link ExplicitEnumOrdering} instance. */ public ExplicitEnumOrdering() {} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsage.java index 16e55d4cdd..8bd510f3da 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FluxFlatMapUsage.java @@ -66,7 +66,7 @@ public final class FluxFlatMapUsage extends BugChecker instanceMethod() .onDescendantOf(FLUX) .namedAnyOf("flatMap", "flatMapSequential") - .withParameters(Function.class.getName()); + .withParameters(Function.class.getCanonicalName()); private static final Supplier FLUX_OF_PUBLISHERS = VisitorState.memoize( generic(FLUX, subOf(generic(type("org.reactivestreams.Publisher"), unbound())))); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FluxImplicitBlock.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FluxImplicitBlock.java index 17c8098c09..7691de3e11 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FluxImplicitBlock.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FluxImplicitBlock.java @@ -48,7 +48,8 @@ public final class FluxImplicitBlock extends BugChecker implements MethodInvocat .onDescendantOf("reactor.core.publisher.Flux") .namedAnyOf("toIterable", "toStream") .withNoParameters(); - private static final Supplier STREAM = Suppliers.typeFromString(Stream.class.getName()); + private static final Supplier STREAM = + Suppliers.typeFromString(Stream.class.getCanonicalName()); /** Instantiates a new {@link FluxImplicitBlock} instance. */ public FluxImplicitBlock() {} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenation.java index 7ea1f65d45..ce41913501 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenation.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/FormatStringConcatenation.java @@ -68,7 +68,7 @@ public final class FormatStringConcatenation extends BugChecker anyMethod() .anyClass() .withAnyName() - .withParameters(String.class.getName(), Throwable.class.getName()); + .withParameters(String.class.getCanonicalName(), Throwable.class.getCanonicalName()); // XXX: Drop some of these methods if we use Refaster to replace some with others. private static final Matcher ASSERTJ_FORMAT_METHOD = diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java index fb11dbc86e..6389279366 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java @@ -56,7 +56,7 @@ public final class IdentityConversion extends BugChecker implements MethodInvoca .map(Class::getName) .collect(toImmutableSet())) .named("valueOf"), - staticMethod().onClass(String.class.getName()).named("valueOf"), + staticMethod().onClass(String.class.getCanonicalName()).named("valueOf"), staticMethod() .onClassAny( "com.google.common.collect.ImmutableBiMap", diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java index e6fe6df852..6a786e6ad0 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java @@ -99,12 +99,12 @@ public final class JUnitValueSource extends BugChecker implements MethodTreeMatc allOf( staticMethod() .onClassAny( - Stream.class.getName(), - IntStream.class.getName(), - LongStream.class.getName(), - DoubleStream.class.getName(), - List.class.getName(), - Set.class.getName(), + Stream.class.getCanonicalName(), + IntStream.class.getCanonicalName(), + LongStream.class.getCanonicalName(), + DoubleStream.class.getCanonicalName(), + List.class.getCanonicalName(), + Set.class.getCanonicalName(), "com.google.common.collect.ImmutableList", "com.google.common.collect.ImmutableSet") .named("of"), diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MockitoMockClassReference.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MockitoMockClassReference.java index 49f36937d3..f99bba08c9 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MockitoMockClassReference.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MockitoMockClassReference.java @@ -50,7 +50,7 @@ public final class MockitoMockClassReference extends BugChecker private static final long serialVersionUID = 1L; private static final Matcher MOCKITO_MOCK_OR_SPY_WITH_HARDCODED_TYPE = allOf( - argument(0, allOf(isSameType(Class.class.getName()), not(isVariable()))), + argument(0, allOf(isSameType(Class.class.getCanonicalName()), not(isVariable()))), staticMethod().onClass("org.mockito.Mockito").namedAnyOf("mock", "spy")); /** Instantiates a new {@link MockitoMockClassReference} instance. */ diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonEmptyMono.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonEmptyMono.java index 4108d703cb..79a185b440 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonEmptyMono.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonEmptyMono.java @@ -72,7 +72,7 @@ public final class NonEmptyMono extends BugChecker implements MethodInvocationTr instanceMethod() .onDescendantOf("reactor.core.publisher.Flux") .named("reduce") - .withParameters(Object.class.getName(), BiFunction.class.getName()), + .withParameters(Object.class.getCanonicalName(), BiFunction.class.getCanonicalName()), instanceMethod() .onDescendantOf("reactor.core.publisher.Mono") .namedAnyOf("defaultIfEmpty", "hasElement", "single")); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparison.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparison.java index 9f2d2f8219..8414d1da56 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparison.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparison.java @@ -55,21 +55,21 @@ public final class PrimitiveComparison extends BugChecker implements MethodInvoc private static final Matcher STATIC_COMPARISON_METHOD = anyOf( staticMethod() - .onClass(Comparator.class.getName()) + .onClass(Comparator.class.getCanonicalName()) .namedAnyOf("comparingInt", "comparingLong", "comparingDouble"), staticMethod() - .onClass(Comparator.class.getName()) + .onClass(Comparator.class.getCanonicalName()) .named("comparing") - .withParameters(Function.class.getName())); + .withParameters(Function.class.getCanonicalName())); private static final Matcher INSTANCE_COMPARISON_METHOD = anyOf( instanceMethod() - .onDescendantOf(Comparator.class.getName()) + .onDescendantOf(Comparator.class.getCanonicalName()) .namedAnyOf("thenComparingInt", "thenComparingLong", "thenComparingDouble"), instanceMethod() - .onDescendantOf(Comparator.class.getName()) + .onDescendantOf(Comparator.class.getCanonicalName()) .named("thenComparing") - .withParameters(Function.class.getName())); + .withParameters(Function.class.getCanonicalName())); /** Instantiates a new {@link PrimitiveComparison} instance. */ public PrimitiveComparison() {} @@ -168,7 +168,7 @@ private static Fix suggestFix( switch (expr.getKind()) { case IDENTIFIER: return SuggestedFix.builder() - .addStaticImport(Comparator.class.getName() + '.' + preferredMethodName) + .addStaticImport(Comparator.class.getCanonicalName() + '.' + preferredMethodName) .replace(expr, preferredMethodName) .build(); case MEMBER_SELECT: diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java index 8ea3f7adb8..201b43eeef 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java @@ -86,7 +86,7 @@ public final class RedundantStringConversion extends BugChecker private static final Matcher WELL_KNOWN_STRING_CONVERSION_METHODS = anyOf( instanceMethod() - .onDescendantOfAny(Object.class.getName()) + .onDescendantOfAny(Object.class.getCanonicalName()) .named("toString") .withNoParameters(), allOf( @@ -100,7 +100,7 @@ public final class RedundantStringConversion extends BugChecker .collect(toImmutableSet())) .named("toString"), allOf( - staticMethod().onClass(String.class.getName()).named("valueOf"), + staticMethod().onClass(String.class.getCanonicalName()).named("valueOf"), not( anyMethod() .anyClass() @@ -109,27 +109,29 @@ public final class RedundantStringConversion extends BugChecker ImmutableList.of(Suppliers.arrayOf(Suppliers.CHAR_TYPE)))))))); private static final Matcher STRINGBUILDER_APPEND_INVOCATION = instanceMethod() - .onDescendantOf(StringBuilder.class.getName()) + .onDescendantOf(StringBuilder.class.getCanonicalName()) .named("append") - .withParameters(String.class.getName()); + .withParameters(String.class.getCanonicalName()); private static final Matcher STRINGBUILDER_INSERT_INVOCATION = instanceMethod() - .onDescendantOf(StringBuilder.class.getName()) + .onDescendantOf(StringBuilder.class.getCanonicalName()) .named("insert") - .withParameters(int.class.getName(), String.class.getName()); + .withParameters(int.class.getCanonicalName(), String.class.getCanonicalName()); private static final Matcher FORMATTER_INVOCATION = anyOf( - staticMethod().onClass(String.class.getName()).named("format"), - instanceMethod().onDescendantOf(Formatter.class.getName()).named("format"), + staticMethod().onClass(String.class.getCanonicalName()).named("format"), + instanceMethod().onDescendantOf(Formatter.class.getCanonicalName()).named("format"), instanceMethod() - .onDescendantOfAny(PrintStream.class.getName(), PrintWriter.class.getName()) + .onDescendantOfAny( + PrintStream.class.getCanonicalName(), PrintWriter.class.getCanonicalName()) .namedAnyOf("format", "printf"), instanceMethod() - .onDescendantOfAny(PrintStream.class.getName(), PrintWriter.class.getName()) + .onDescendantOfAny( + PrintStream.class.getCanonicalName(), PrintWriter.class.getCanonicalName()) .namedAnyOf("print", "println") - .withParameters(Object.class.getName()), + .withParameters(Object.class.getCanonicalName()), staticMethod() - .onClass(Console.class.getName()) + .onClass(Console.class.getCanonicalName()) .namedAnyOf("format", "printf", "readline", "readPassword")); private static final Matcher GUAVA_GUARD_INVOCATION = anyOf( diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterAnyOfUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterAnyOfUsage.java index 97e6814644..96e6bc78c6 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterAnyOfUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RefasterAnyOfUsage.java @@ -35,7 +35,7 @@ public final class RefasterAnyOfUsage extends BugChecker implements MethodInvocationTreeMatcher { private static final long serialVersionUID = 1L; private static final Matcher REFASTER_ANY_OF = - staticMethod().onClass(Refaster.class.getName()).named("anyOf"); + staticMethod().onClass(Refaster.class.getCanonicalName()).named("anyOf"); /** Instantiates a new {@link RefasterAnyOfUsage} instance. */ public RefasterAnyOfUsage() {} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java index 8d256c4f11..0533d0cccd 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StringJoin.java @@ -49,7 +49,7 @@ public final class StringJoin extends BugChecker implements MethodInvocationTree private static final long serialVersionUID = 1L; private static final Splitter FORMAT_SPECIFIER_SPLITTER = Splitter.on("%s"); private static final Matcher STRING_FORMAT_INVOCATION = - staticMethod().onClass(String.class.getName()).named("format"); + staticMethod().onClass(String.class.getCanonicalName()).named("format"); private static final Supplier CHAR_SEQUENCE_TYPE = Suppliers.typeFromClass(CharSequence.class); private static final Supplier FORMATTABLE_TYPE = Suppliers.typeFromClass(Formattable.class); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsage.java index c4426261ff..5cdfec6cea 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/TimeZoneUsage.java @@ -45,11 +45,11 @@ public final class TimeZoneUsage extends BugChecker implements MethodInvocationT anyOf( allOf( instanceMethod() - .onDescendantOf(Clock.class.getName()) + .onDescendantOf(Clock.class.getCanonicalName()) .namedAnyOf("getZone", "withZone"), not(enclosingClass(isSubtypeOf(Clock.class)))), staticMethod() - .onClass(Clock.class.getName()) + .onClass(Clock.class.getCanonicalName()) .namedAnyOf( "system", "systemDefaultZone", @@ -59,14 +59,17 @@ public final class TimeZoneUsage extends BugChecker implements MethodInvocationT "tickSeconds"), staticMethod() .onClassAny( - LocalDate.class.getName(), - LocalDateTime.class.getName(), - LocalTime.class.getName(), - OffsetDateTime.class.getName(), - OffsetTime.class.getName(), - ZonedDateTime.class.getName()) + LocalDate.class.getCanonicalName(), + LocalDateTime.class.getCanonicalName(), + LocalTime.class.getCanonicalName(), + OffsetDateTime.class.getCanonicalName(), + OffsetTime.class.getCanonicalName(), + ZonedDateTime.class.getCanonicalName()) .named("now"), - staticMethod().onClassAny(Instant.class.getName()).named("now").withNoParameters()); + staticMethod() + .onClassAny(Instant.class.getCanonicalName()) + .named("now") + .withNoParameters()); /** Instantiates a new {@link TimeZoneUsage} instance. */ public TimeZoneUsage() {} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalClassNameUsageTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalClassNameUsageTest.java new file mode 100644 index 0000000000..27a57e4b13 --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalClassNameUsageTest.java @@ -0,0 +1,82 @@ +package tech.picnic.errorprone.bugpatterns; + +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; +import com.google.errorprone.CompilationTestHelper; +import org.junit.jupiter.api.Test; + +final class CanonicalClassNameUsageTest { + @Test + void identification() { + CompilationTestHelper.newInstance(CanonicalClassNameUsage.class, getClass()) + .setArgs( + "--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED", + "--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED") + .addSourceLines( + "A.java", + "import static com.google.errorprone.matchers.Matchers.instanceMethod;", + "", + "import com.google.errorprone.VisitorState;", + "import tech.picnic.errorprone.bugpatterns.util.MoreTypes;", + "", + "class A {", + " void m(VisitorState state) {", + " String a = A.class.getName();", + " String b = getClass().getName();", + " A.class.getName().toString();", + " System.out.println(A.class.getName());", + " methodInUnnamedPackage(A.class.getName());", + " instanceMethod().onExactClass(A.class.getCanonicalName());", + " MoreTypes.type(A.class.getCanonicalName());", + " MoreTypes.type(A.class.getCanonicalName() + \".SubType\");", + " instanceMethod().onExactClass(new Object() {}.getClass().getName());", + " instanceMethod().onExactClass(methodInUnnamedPackage(A.class.getName()));", + " // BUG: Diagnostic contains:", + " instanceMethod().onExactClass(A.class.getName());", + " // BUG: Diagnostic contains:", + " MoreTypes.type(A.class.getName());", + " // BUG: Diagnostic contains:", + " state.binaryNameFromClassname(A.class.getName() + \".SubType\");", + " }", + "", + " String methodInUnnamedPackage(String str) {", + " return str;", + " }", + "}") + .doTest(); + } + + @Test + void replacement() { + BugCheckerRefactoringTestHelper.newInstance(CanonicalClassNameUsage.class, getClass()) + .addInputLines( + "A.java", + "import static com.google.errorprone.matchers.Matchers.instanceMethod;", + "", + "import com.google.errorprone.BugPattern;", + "import tech.picnic.errorprone.bugpatterns.util.MoreTypes;", + "", + "class A {", + " void m() {", + " instanceMethod().onDescendantOfAny(A.class.getName(), BugPattern.LinkType.class.getName());", + " MoreTypes.type(String.class.getName());", + " }", + "}") + .addOutputLines( + "A.java", + "import static com.google.errorprone.matchers.Matchers.instanceMethod;", + "", + "import com.google.errorprone.BugPattern;", + "import tech.picnic.errorprone.bugpatterns.util.MoreTypes;", + "", + "class A {", + " void m() {", + " instanceMethod()", + " .onDescendantOfAny(", + " A.class.getCanonicalName(), BugPattern.LinkType.class.getCanonicalName());", + " MoreTypes.type(String.class.getCanonicalName());", + " }", + "}") + .doTest(TestMode.TEXT_MATCH); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java index faed5900f3..b299ff20eb 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreMatchersTest.java @@ -125,7 +125,9 @@ public static final class IsSubTypeOfTestChecker extends BugChecker private static final long serialVersionUID = 1L; private static final Matcher DELEGATE = MoreMatchers.isSubTypeOf( - generic(type(ImmutableSet.class.getName()), subOf(type(Number.class.getName())))); + generic( + type(ImmutableSet.class.getCanonicalName()), + subOf(type(Number.class.getCanonicalName())))); @Override public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsEmpty.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsEmpty.java index bbe9ee104e..fb0c77b748 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsEmpty.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsEmpty.java @@ -74,30 +74,30 @@ public final class IsEmpty implements Matcher { isSameType(Vector.class)); private static final Matcher EMPTY_INSTANCE_FACTORY = anyOf( - staticField(Collections.class.getName(), "EMPTY_LIST"), - staticField(Collections.class.getName(), "EMPTY_MAP"), - staticField(Collections.class.getName(), "EMPTY_SET"), + staticField(Collections.class.getCanonicalName(), "EMPTY_LIST"), + staticField(Collections.class.getCanonicalName(), "EMPTY_MAP"), + staticField(Collections.class.getCanonicalName(), "EMPTY_SET"), toType( MethodInvocationTree.class, allOf( argumentCount(0), anyOf( staticMethod() - .onClass(Collections.class.getName()) + .onClass(Collections.class.getCanonicalName()) .withNameMatching(EMPTY_INSTANCE_FACTORY_METHOD_PATTERN), staticMethod() .onDescendantOfAny( - ImmutableCollection.class.getName(), - ImmutableMap.class.getName(), - ImmutableMultimap.class.getName(), - List.class.getName(), - Map.class.getName(), - Set.class.getName(), - Stream.class.getName()) + ImmutableCollection.class.getCanonicalName(), + ImmutableMap.class.getCanonicalName(), + ImmutableMultimap.class.getCanonicalName(), + List.class.getCanonicalName(), + Map.class.getCanonicalName(), + Set.class.getCanonicalName(), + Stream.class.getCanonicalName()) .named("of"), staticMethod() .onClassAny( - Stream.class.getName(), + Stream.class.getCanonicalName(), "reactor.core.publisher.Flux", "reactor.core.publisher.Mono", "reactor.util.context.Context") diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsIdentityOperation.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsIdentityOperation.java index 706d61428f..f69c4b40a6 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsIdentityOperation.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsIdentityOperation.java @@ -25,10 +25,10 @@ public final class IsIdentityOperation implements Matcher { anyOf( staticMethod() .onDescendantOfAny( - DoubleUnaryOperator.class.getName(), - Function.class.getName(), - IntUnaryOperator.class.getName(), - LongUnaryOperator.class.getName()) + DoubleUnaryOperator.class.getCanonicalName(), + Function.class.getCanonicalName(), + IntUnaryOperator.class.getCanonicalName(), + LongUnaryOperator.class.getCanonicalName()) .named("identity"), isIdentityLambdaExpression()); diff --git a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsRefasterAsVarargs.java b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsRefasterAsVarargs.java index f9a4cd901d..ffd2d43a02 100644 --- a/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsRefasterAsVarargs.java +++ b/refaster-support/src/main/java/tech/picnic/errorprone/refaster/matchers/IsRefasterAsVarargs.java @@ -11,7 +11,7 @@ public final class IsRefasterAsVarargs implements Matcher { private static final long serialVersionUID = 1L; private static final Matcher DELEGATE = - staticMethod().onClass(Refaster.class.getName()).named("asVarargs"); + staticMethod().onClass(Refaster.class.getCanonicalName()).named("asVarargs"); /** Instantiates a new {@link IsRefasterAsVarargs} instance. */ public IsRefasterAsVarargs() {} From a0b1f7091ee4f902f4abdcc9649fe0e902669948 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Mon, 18 Dec 2023 12:51:28 +0100 Subject: [PATCH 585/601] Introduce `UnqualifiedSuggestedFixImport` check (#880) Usage of `SuggestedFix.Builder#add{,Static}Import` does not always yield valid code, so this check suggests alternatives instead. --- .../bugpatterns/CollectorMutability.java | 26 ++++--- .../bugpatterns/JUnitValueSource.java | 26 ++++--- .../bugpatterns/MethodReferenceUsage.java | 2 + .../bugpatterns/PrimitiveComparison.java | 10 +-- .../bugpatterns/SpringMvcAnnotation.java | 8 +-- .../UnqualifiedSuggestedFixImport.java | 67 +++++++++++++++++++ .../UnqualifiedSuggestedFixImportTest.java | 44 ++++++++++++ 7 files changed, 156 insertions(+), 27 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/UnqualifiedSuggestedFixImport.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/UnqualifiedSuggestedFixImportTest.java diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java index e5725f74a0..e3b2c76776 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java @@ -58,7 +58,10 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState if (LIST_COLLECTOR.matches(tree, state)) { return suggestToCollectionAlternatives( - tree, "com.google.common.collect.ImmutableList.toImmutableList", "ArrayList", state); + tree, + "com.google.common.collect.ImmutableList.toImmutableList", + "java.util.ArrayList", + state); } if (MAP_COLLECTOR.matches(tree, state)) { @@ -67,7 +70,10 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState if (SET_COLLECTOR.matches(tree, state)) { return suggestToCollectionAlternatives( - tree, "com.google.common.collect.ImmutableSet.toImmutableSet", "HashSet", state); + tree, + "com.google.common.collect.ImmutableSet.toImmutableSet", + "java.util.HashSet", + state); } return Description.NO_MATCH; @@ -75,20 +81,20 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState private Description suggestToCollectionAlternatives( MethodInvocationTree tree, - String fullyQualifiedImmutableReplacement, + String immutableReplacement, String mutableReplacement, VisitorState state) { SuggestedFix.Builder mutableFix = SuggestedFix.builder(); String toCollectionSelect = SuggestedFixes.qualifyStaticImport( "java.util.stream.Collectors.toCollection", mutableFix, state); + String mutableCollection = SuggestedFixes.qualifyType(state, mutableFix, mutableReplacement); return buildDescription(tree) - .addFix(replaceMethodInvocation(tree, fullyQualifiedImmutableReplacement, state)) + .addFix(replaceMethodInvocation(tree, immutableReplacement, state)) .addFix( mutableFix - .addImport(String.format("java.util.%s", mutableReplacement)) - .replace(tree, String.format("%s(%s::new)", toCollectionSelect, mutableReplacement)) + .replace(tree, String.format("%s(%s::new)", toCollectionSelect, mutableCollection)) .build()) .build(); } @@ -99,17 +105,19 @@ private Description suggestToMapAlternatives(MethodInvocationTree tree, VisitorS return Description.NO_MATCH; } + SuggestedFix.Builder mutableFix = SuggestedFix.builder(); + String hashMap = SuggestedFixes.qualifyType(state, mutableFix, "java.util.HashMap"); + return buildDescription(tree) .addFix( replaceMethodInvocation( tree, "com.google.common.collect.ImmutableMap.toImmutableMap", state)) .addFix( - SuggestedFix.builder() - .addImport("java.util.HashMap") + mutableFix .postfixWith( tree.getArguments().get(argCount - 1), (argCount == 2 ? ", (a, b) -> { throw new IllegalStateException(); }" : "") - + ", HashMap::new") + + String.format(", %s::new", hashMap)) .build()) .build(); } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java index 6a786e6ad0..4834267e94 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java @@ -30,6 +30,7 @@ import com.google.errorprone.bugpatterns.BugChecker; import com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher; import com.google.errorprone.fixes.SuggestedFix; +import com.google.errorprone.fixes.SuggestedFixes; import com.google.errorprone.matchers.Description; import com.google.errorprone.matchers.Matcher; import com.google.errorprone.util.ASTHelpers; @@ -199,16 +200,21 @@ private static Optional tryConstructValueSourceFix( return getSingleReturnExpression(valueFactoryMethod) .flatMap(expression -> tryExtractValueSourceAttributeValue(expression, state)) .map( - valueSourceAttributeValue -> - SuggestedFix.builder() - .addImport("org.junit.jupiter.params.provider.ValueSource") - .replace( - methodSourceAnnotation, - String.format( - "@ValueSource(%s = %s)", - toValueSourceAttributeName(parameterType), valueSourceAttributeValue)) - .delete(valueFactoryMethod) - .build()); + valueSourceAttributeValue -> { + SuggestedFix.Builder fix = SuggestedFix.builder(); + String valueSource = + SuggestedFixes.qualifyType( + state, fix, "org.junit.jupiter.params.provider.ValueSource"); + return fix.replace( + methodSourceAnnotation, + String.format( + "@%s(%s = %s)", + valueSource, + toValueSourceAttributeName(parameterType), + valueSourceAttributeValue)) + .delete(valueFactoryMethod) + .build(); + }); } // XXX: This pattern also occurs a few times inside Error Prone; contribute upstream. diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MethodReferenceUsage.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MethodReferenceUsage.java index 6c75d67e82..5c79baf817 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MethodReferenceUsage.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/MethodReferenceUsage.java @@ -196,6 +196,8 @@ private static ImmutableList getVariables(LambdaExpressionTree tree) { return tree.getParameters().stream().map(VariableTree::getName).collect(toImmutableList()); } + // XXX: Resolve this suppression. + @SuppressWarnings("UnqualifiedSuggestedFixImport") private static Optional constructFix( LambdaExpressionTree lambdaExpr, Symbol target, Object methodName) { Name sName = target.getSimpleName(); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparison.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparison.java index 8414d1da56..77a456af6d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparison.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/PrimitiveComparison.java @@ -17,6 +17,7 @@ import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; import com.google.errorprone.fixes.Fix; import com.google.errorprone.fixes.SuggestedFix; +import com.google.errorprone.fixes.SuggestedFixes; import com.google.errorprone.matchers.Description; import com.google.errorprone.matchers.Matcher; import com.google.errorprone.util.ASTHelpers; @@ -167,10 +168,11 @@ private static Fix suggestFix( ExpressionTree expr = tree.getMethodSelect(); switch (expr.getKind()) { case IDENTIFIER: - return SuggestedFix.builder() - .addStaticImport(Comparator.class.getCanonicalName() + '.' + preferredMethodName) - .replace(expr, preferredMethodName) - .build(); + SuggestedFix.Builder fix = SuggestedFix.builder(); + String replacement = + SuggestedFixes.qualifyStaticImport( + Comparator.class.getCanonicalName() + '.' + preferredMethodName, fix, state); + return fix.replace(expr, replacement).build(); case MEMBER_SELECT: MemberSelectTree ms = (MemberSelectTree) tree.getMethodSelect(); return SuggestedFix.replace( diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotation.java index 97cad60805..1b2119ab12 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotation.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotation.java @@ -18,6 +18,7 @@ import com.google.errorprone.bugpatterns.BugChecker.AnnotationTreeMatcher; import com.google.errorprone.fixes.Fix; import com.google.errorprone.fixes.SuggestedFix; +import com.google.errorprone.fixes.SuggestedFixes; import com.google.errorprone.matchers.Description; import com.sun.source.tree.AnnotationTree; import com.sun.source.tree.AssignmentTree; @@ -114,9 +115,8 @@ private static Fix replaceAnnotation( .map(arg -> SourceCode.treeToString(arg, state)) .collect(joining(", ")); - return SuggestedFix.builder() - .addImport(ANN_PACKAGE_PREFIX + newAnnotation) - .replace(tree, String.format("@%s(%s)", newAnnotation, newArguments)) - .build(); + SuggestedFix.Builder fix = SuggestedFix.builder(); + String annotation = SuggestedFixes.qualifyType(state, fix, ANN_PACKAGE_PREFIX + newAnnotation); + return fix.replace(tree, String.format("@%s(%s)", annotation, newArguments)).build(); } } diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/UnqualifiedSuggestedFixImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/UnqualifiedSuggestedFixImport.java new file mode 100644 index 0000000000..6d27c7c372 --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/UnqualifiedSuggestedFixImport.java @@ -0,0 +1,67 @@ +package tech.picnic.errorprone.bugpatterns; + +import static com.google.errorprone.BugPattern.LinkType.CUSTOM; +import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; +import static com.google.errorprone.BugPattern.StandardTags.FRAGILE_CODE; +import static com.google.errorprone.matchers.Matchers.instanceMethod; +import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; + +import com.google.auto.service.AutoService; +import com.google.errorprone.BugPattern; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; +import com.google.errorprone.fixes.SuggestedFix; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.util.ASTHelpers; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.MethodInvocationTree; + +/** + * A {@link BugChecker} that flags suggested fixes that involve unconditional imports. + * + *

Such unconditional imports may clash with other imports of the same identifier. + */ +@AutoService(BugChecker.class) +@BugPattern( + summary = "Avoid direct invocation of `SuggestedFix#add{,Static}Import`", + link = BUG_PATTERNS_BASE_URL + "UnqualifiedSuggestedFixImport", + linkType = CUSTOM, + severity = WARNING, + tags = FRAGILE_CODE) +public final class UnqualifiedSuggestedFixImport extends BugChecker + implements MethodInvocationTreeMatcher { + private static final long serialVersionUID = 1L; + private static final Matcher FIX_BUILDER_METHOD = + instanceMethod().onDescendantOf(SuggestedFix.Builder.class.getCanonicalName()); + + /** Instantiates a new {@link UnqualifiedSuggestedFixImport} instance. */ + public UnqualifiedSuggestedFixImport() {} + + @Override + public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) { + if (!FIX_BUILDER_METHOD.matches(tree, state)) { + return Description.NO_MATCH; + } + + switch (ASTHelpers.getSymbol(tree).getSimpleName().toString()) { + case "addImport": + return createDescription( + tree, "SuggestedFix.Builder#addImport", "SuggestedFixes#qualifyType"); + case "addStaticImport": + return createDescription( + tree, "SuggestedFix.Builder#addStaticImport", "SuggestedFixes#qualifyStaticImport"); + default: + return Description.NO_MATCH; + } + } + + private Description createDescription( + MethodInvocationTree tree, String method, String alternative) { + return buildDescription(tree) + .setMessage( + String.format("Prefer `%s` over direct invocation of `%s`", alternative, method)) + .build(); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/UnqualifiedSuggestedFixImportTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/UnqualifiedSuggestedFixImportTest.java new file mode 100644 index 0000000000..c414af3adc --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/UnqualifiedSuggestedFixImportTest.java @@ -0,0 +1,44 @@ +package tech.picnic.errorprone.bugpatterns; + +import com.google.errorprone.CompilationTestHelper; +import org.junit.jupiter.api.Test; + +final class UnqualifiedSuggestedFixImportTest { + @Test + void identification() { + CompilationTestHelper.newInstance(UnqualifiedSuggestedFixImport.class, getClass()) + .expectErrorMessage( + "IMPORT", + m -> + m.contains( + "Prefer `SuggestedFixes#qualifyType` over direct invocation of `SuggestedFix.Builder#addImport`")) + .expectErrorMessage( + "STATIC_IMPORT", + m -> + m.contains( + "Prefer `SuggestedFixes#qualifyStaticImport` over direct invocation of `SuggestedFix.Builder#addStaticImport`")) + .addSourceLines( + "A.java", + "import com.google.errorprone.fixes.SuggestedFix;", + "", + "class A {", + " void m() {", + " System.out.println(\"foo\");", + " addImport(\"bar\");", + " addStaticImport(\"baz\");", + "", + " SuggestedFix.Builder builder = SuggestedFix.builder();", + " // BUG: Diagnostic matches: IMPORT", + " builder.addImport(\"java.lang.String\");", + " // BUG: Diagnostic matches: STATIC_IMPORT", + " builder.addStaticImport(\"java.lang.String.toString\");", + " builder.build();", + " }", + "", + " private void addImport(String s) {}", + "", + " private void addStaticImport(String s) {}", + "}") + .doTest(); + } +} From 379bbf3f83de9f0128b8519210fbc32b7b2b9c48 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Mon, 18 Dec 2023 13:35:44 +0100 Subject: [PATCH 586/601] Upgrade Checker Framework Annotations 3.41.0 -> 3.42.0 (#924) See: - https://github.com/typetools/checker-framework/releases/tag/checker-framework-3.42.0 - https://github.com/typetools/checker-framework/compare/checker-framework-3.41.0...checker-framework-3.42.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fbd99a0bc0..60adb227ad 100644 --- a/pom.xml +++ b/pom.xml @@ -411,7 +411,7 @@ org.checkerframework checker-qual - 3.41.0 + 3.42.0 org.hamcrest From cc36aa993c7c7aedb5fc5c18dc829bd7a50ca9b3 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Mon, 18 Dec 2023 18:00:15 +0100 Subject: [PATCH 587/601] Disallow static import of `com.google.errorprone.{VisitorState,util.ASTHelpers}` members (#922) --- .../tech/picnic/errorprone/bugpatterns/NonStaticImport.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java index f913b93e09..8c5e2fa43a 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java @@ -61,6 +61,8 @@ public final class NonStaticImport extends BugChecker implements CompilationUnit ImmutableSet.of( "com.google.common.base.Strings", "com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode", + "com.google.errorprone.VisitorState", + "com.google.errorprone.util.ASTHelpers", "java.time.Clock", "java.time.ZoneOffset"); From 0c857b3d90f8fd85e8962c341645a44d6a319844 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 20 Dec 2023 08:03:40 +0100 Subject: [PATCH 588/601] Upgrade Guava 32.1.3-jre -> 33.0.0-jre (#931) See: - https://guava.dev/releases/33.0.0-jre/api/diffs/ - https://github.com/google/guava/releases/tag/v33.0.0 - https://github.com/google/guava/compare/v32.0.0...v33.0.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 60adb227ad..2cc996e616 100644 --- a/pom.xml +++ b/pom.xml @@ -311,7 +311,7 @@ com.google.guava guava-bom - 32.1.3-jre + 33.0.0-jre pom import From d01002de06f47809428bb04b5d687ddfa765bbff Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 20 Dec 2023 08:35:00 +0100 Subject: [PATCH 589/601] Upgrade Truth 1.1.5 -> 1.2.0 (#930) See: - https://github.com/google/truth/releases/tag/v1.2.0 - https://github.com/google/truth/compare/v1.1.5...v1.2.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 2cc996e616..531a2a361d 100644 --- a/pom.xml +++ b/pom.xml @@ -318,7 +318,7 @@ com.google.truth truth - 1.1.5 + 1.2.0 From 9d6637948616b834ee4b3c0fe533ff279edb2ac4 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 20 Dec 2023 13:21:48 +0100 Subject: [PATCH 590/601] Upgrade Swagger 2.2.19 -> 2.2.20 (#928) See: - https://github.com/swagger-api/swagger-core/releases/tag/v2.2.20 - https://github.com/swagger-api/swagger-core/compare/v2.2.19...v2.2.20 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 531a2a361d..4b37185d68 100644 --- a/pom.xml +++ b/pom.xml @@ -354,7 +354,7 @@ io.swagger.core.v3 swagger-annotations - 2.2.19 + 2.2.20 jakarta.servlet From e7c3d3905986ec90bd31a8707befbd02d9e18930 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Wed, 20 Dec 2023 14:23:09 +0100 Subject: [PATCH 591/601] Upgrade Checkstyle 10.12.5 -> 10.12.6 (#911) See: - https://checkstyle.sourceforge.io/releasenotes.html - https://github.com/checkstyle/checkstyle/releases/tag/checkstyle-10.12.6 - https://github.com/checkstyle/checkstyle/compare/checkstyle-10.12.5...checkstyle-10.12.6 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4b37185d68..07b6b4adc8 100644 --- a/pom.xml +++ b/pom.xml @@ -859,7 +859,7 @@ com.puppycrawl.tools checkstyle - 10.12.5 + 10.12.6 io.spring.nohttp From d569156a6b3c28c958b2d435b7be57052a4449f1 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Wed, 20 Dec 2023 22:14:22 +0100 Subject: [PATCH 592/601] Introduce `ErrorProneRuntimeClasspath` check (#882) Prefer "type-safe" type references were possible, but use string literals if the references type may not be available at runtime. --- .../BugPatternTestExtractor.java | 2 +- .../bugpatterns/CollectorMutability.java | 24 ++- .../errorprone/bugpatterns/EmptyMethod.java | 4 +- .../ErrorProneRuntimeClasspath.java | 165 ++++++++++++++++++ .../bugpatterns/FluxImplicitBlock.java | 7 +- .../FormatStringConcatenation.java | 11 +- .../bugpatterns/IdentityConversion.java | 38 ++-- .../bugpatterns/JUnitValueSource.java | 6 +- .../bugpatterns/NonStaticImport.java | 27 +-- .../RedundantStringConversion.java | 6 +- .../bugpatterns/RequestMappingAnnotation.java | 12 +- .../errorprone/bugpatterns/StaticImport.java | 99 +++++++---- .../bugpatterns/util/ThirdPartyLibrary.java | 12 +- .../ErrorProneRuntimeClasspathTest.java | 136 +++++++++++++++ .../bugpatterns/util/MoreTypesTest.java | 85 +++++---- 15 files changed, 516 insertions(+), 118 deletions(-) create mode 100644 error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ErrorProneRuntimeClasspath.java create mode 100644 error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ErrorProneRuntimeClasspathTest.java diff --git a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternTestExtractor.java b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternTestExtractor.java index cf7f7a0b0e..e24a23c865 100644 --- a/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternTestExtractor.java +++ b/documentation-support/src/main/java/tech/picnic/errorprone/documentation/BugPatternTestExtractor.java @@ -67,7 +67,7 @@ private static final class BugPatternTestCollector "com.google.errorprone.CompilationTestHelper", "com.google.errorprone.BugCheckerRefactoringTestHelper") .named("newInstance") - .withParameters("java.lang.Class", "java.lang.Class"); + .withParameters(Class.class.getCanonicalName(), Class.class.getCanonicalName()); private static final Matcher IDENTIFICATION_SOURCE_LINES = instanceMethod() .onDescendantOf("com.google.errorprone.CompilationTestHelper") diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java index e3b2c76776..08376ab358 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CollectorMutability.java @@ -7,6 +7,9 @@ import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; import com.google.auto.service.AutoService; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; import com.google.errorprone.BugPattern; import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.BugChecker; @@ -17,7 +20,11 @@ import com.google.errorprone.matchers.Matcher; import com.sun.source.tree.ExpressionTree; import com.sun.source.tree.MethodInvocationTree; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; import java.util.stream.Collector; +import java.util.stream.Collectors; import tech.picnic.errorprone.bugpatterns.util.ThirdPartyLibrary; /** @@ -38,7 +45,7 @@ public final class CollectorMutability extends BugChecker implements MethodInvocationTreeMatcher { private static final long serialVersionUID = 1L; private static final Matcher COLLECTOR_METHOD = - staticMethod().onClass("java.util.stream.Collectors"); + staticMethod().onClass(Collectors.class.getCanonicalName()); private static final Matcher LIST_COLLECTOR = staticMethod().anyClass().named("toList"); private static final Matcher MAP_COLLECTOR = @@ -59,8 +66,8 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState if (LIST_COLLECTOR.matches(tree, state)) { return suggestToCollectionAlternatives( tree, - "com.google.common.collect.ImmutableList.toImmutableList", - "java.util.ArrayList", + ImmutableList.class.getCanonicalName() + ".toImmutableList", + ArrayList.class.getCanonicalName(), state); } @@ -71,8 +78,8 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState if (SET_COLLECTOR.matches(tree, state)) { return suggestToCollectionAlternatives( tree, - "com.google.common.collect.ImmutableSet.toImmutableSet", - "java.util.HashSet", + ImmutableSet.class.getCanonicalName() + ".toImmutableSet", + HashSet.class.getCanonicalName(), state); } @@ -87,7 +94,7 @@ private Description suggestToCollectionAlternatives( SuggestedFix.Builder mutableFix = SuggestedFix.builder(); String toCollectionSelect = SuggestedFixes.qualifyStaticImport( - "java.util.stream.Collectors.toCollection", mutableFix, state); + Collectors.class.getCanonicalName() + ".toCollection", mutableFix, state); String mutableCollection = SuggestedFixes.qualifyType(state, mutableFix, mutableReplacement); return buildDescription(tree) @@ -106,12 +113,13 @@ private Description suggestToMapAlternatives(MethodInvocationTree tree, VisitorS } SuggestedFix.Builder mutableFix = SuggestedFix.builder(); - String hashMap = SuggestedFixes.qualifyType(state, mutableFix, "java.util.HashMap"); + String hashMap = + SuggestedFixes.qualifyType(state, mutableFix, HashMap.class.getCanonicalName()); return buildDescription(tree) .addFix( replaceMethodInvocation( - tree, "com.google.common.collect.ImmutableMap.toImmutableMap", state)) + tree, ImmutableMap.class.getCanonicalName() + ".toImmutableMap", state)) .addFix( mutableFix .postfixWith( diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/EmptyMethod.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/EmptyMethod.java index e1b4173c71..d2b53cdb98 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/EmptyMethod.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/EmptyMethod.java @@ -36,7 +36,9 @@ public final class EmptyMethod extends BugChecker implements MethodTreeMatcher { private static final Matcher PERMITTED_ANNOTATION = annotations( AT_LEAST_ONE, - anyOf(isType("java.lang.Override"), isType("org.aspectj.lang.annotation.Pointcut"))); + anyOf( + isType(Override.class.getCanonicalName()), + isType("org.aspectj.lang.annotation.Pointcut"))); /** Instantiates a new {@link EmptyMethod} instance. */ public EmptyMethod() {} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ErrorProneRuntimeClasspath.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ErrorProneRuntimeClasspath.java new file mode 100644 index 0000000000..df48d49f5b --- /dev/null +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ErrorProneRuntimeClasspath.java @@ -0,0 +1,165 @@ +package tech.picnic.errorprone.bugpatterns; + +import static com.google.common.collect.ImmutableSet.toImmutableSet; +import static com.google.errorprone.BugPattern.LinkType.CUSTOM; +import static com.google.errorprone.BugPattern.SeverityLevel.SUGGESTION; +import static com.google.errorprone.BugPattern.StandardTags.FRAGILE_CODE; +import static com.google.errorprone.matchers.Matchers.instanceMethod; +import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; + +import com.google.auto.service.AutoService; +import com.google.common.collect.ImmutableSet; +import com.google.common.primitives.Primitives; +import com.google.errorprone.BugPattern; +import com.google.errorprone.VisitorState; +import com.google.errorprone.bugpatterns.BugChecker; +import com.google.errorprone.bugpatterns.BugChecker.LiteralTreeMatcher; +import com.google.errorprone.bugpatterns.BugChecker.MethodInvocationTreeMatcher; +import com.google.errorprone.fixes.SuggestedFix; +import com.google.errorprone.fixes.SuggestedFixes; +import com.google.errorprone.matchers.Description; +import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.util.ASTHelpers; +import com.sun.source.tree.AnnotationTree; +import com.sun.source.tree.ExpressionTree; +import com.sun.source.tree.LiteralTree; +import com.sun.source.tree.MethodInvocationTree; +import com.sun.tools.javac.code.Symbol; +import com.sun.tools.javac.code.Symbol.ClassSymbol; +import com.sun.tools.javac.util.Constants; +import java.util.regex.Pattern; +import tech.picnic.errorprone.bugpatterns.util.ThirdPartyLibrary; + +/** + * A {@link BugChecker} that flags literal strings in Error Prone Support code that represent the + * fully qualified class name of a type that's on Error Prone's classpath. + * + *

Deriving such strings from the associated {@link Class} instance makes for more maintainable + * code. + */ +// XXX: Consider generalizing this to a `RuntimeClasspath` check with a configurable +// `CLASSPATH_TYPES` regex. Such a check would likely be a no-op by default, with Error Prone +// Support's parent specifying the regex that is currently hard-coded. +// XXX: As-is this check may suggest usage of a string literal even if the relevant type will be on +// the runtime classpath. Review how we can further reduce false-positives. +// XXX: Slightly "out there", but we could try to derive the subset of classpath types likely to be +// available at runtime from the `compile`-scoped Maven dependencies in the `pom.xml` file of +// the module being compiled. +// XXX: Right now this check does not rewrite primitive string references such as `"int"` to +// `int.class.getCanonicalName()`. Review whether that's worth it. +@AutoService(BugChecker.class) +@BugPattern( + summary = + "Prefer `Class#getCanonicalName()` over an equivalent string literal if and only if the " + + "type will be on the runtime classpath", + link = BUG_PATTERNS_BASE_URL + "ErrorProneRuntimeClasspath", + linkType = CUSTOM, + severity = SUGGESTION, + tags = FRAGILE_CODE) +public final class ErrorProneRuntimeClasspath extends BugChecker + implements LiteralTreeMatcher, MethodInvocationTreeMatcher { + private static final long serialVersionUID = 1L; + private static final Matcher GET_CANONICAL_NAME_INVOCATION = + instanceMethod().onExactClass(Class.class.getCanonicalName()).named("getCanonicalName"); + private static final ImmutableSet PRIMITIVE_TYPES = + Primitives.allPrimitiveTypes().stream() + .map(Class::getCanonicalName) + .collect(toImmutableSet()); + + /** + * A pattern that matches fully qualified type names that are expected to be runtime dependencies + * of Error Prone, and that are thus presumed to be unconditionally present on a bug checker's + * runtime classpath. + */ + private static final Pattern CLASSPATH_TYPES = + Pattern.compile( + "com\\.google\\.common\\..*|com\\.google\\.errorprone\\.([^.]+(? GUAVA_FORMAT_METHOD = anyOf( staticMethod() - .onClass("com.google.common.base.Preconditions") + .onClass(Preconditions.class.getCanonicalName()) .namedAnyOf("checkArgument", "checkNotNull", "checkState"), - staticMethod().onClass("com.google.common.base.Verify").named("verify")); + staticMethod().onClass(Verify.class.getCanonicalName()).named("verify")); // XXX: Add `PrintWriter`, maybe others. private static final Matcher JDK_FORMAT_METHOD = anyOf( - staticMethod().onClass("java.lang.String").named("format"), - instanceMethod().onExactClass("java.util.Formatter").named("format")); + staticMethod().onClass(String.class.getCanonicalName()).named("format"), + instanceMethod().onExactClass(Formatter.class.getCanonicalName()).named("format")); private static final Matcher SLF4J_FORMAT_METHOD = instanceMethod() .onDescendantOf("org.slf4j.Logger") diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java index 6389279366..f4b2a980b5 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/IdentityConversion.java @@ -10,6 +10,17 @@ import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; import com.google.auto.service.AutoService; +import com.google.common.collect.ImmutableBiMap; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableListMultimap; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultimap; +import com.google.common.collect.ImmutableMultiset; +import com.google.common.collect.ImmutableRangeMap; +import com.google.common.collect.ImmutableRangeSet; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSetMultimap; +import com.google.common.collect.ImmutableTable; import com.google.common.primitives.Primitives; import com.google.errorprone.BugPattern; import com.google.errorprone.VisitorState; @@ -20,6 +31,7 @@ import com.google.errorprone.fixes.SuggestedFixes; import com.google.errorprone.matchers.Description; import com.google.errorprone.matchers.Matcher; +import com.google.errorprone.matchers.Matchers; import com.google.errorprone.util.ASTHelpers; import com.google.errorprone.util.ASTHelpers.TargetType; import com.sun.source.tree.ExpressionTree; @@ -59,21 +71,19 @@ public final class IdentityConversion extends BugChecker implements MethodInvoca staticMethod().onClass(String.class.getCanonicalName()).named("valueOf"), staticMethod() .onClassAny( - "com.google.common.collect.ImmutableBiMap", - "com.google.common.collect.ImmutableList", - "com.google.common.collect.ImmutableListMultimap", - "com.google.common.collect.ImmutableMap", - "com.google.common.collect.ImmutableMultimap", - "com.google.common.collect.ImmutableMultiset", - "com.google.common.collect.ImmutableRangeMap", - "com.google.common.collect.ImmutableRangeSet", - "com.google.common.collect.ImmutableSet", - "com.google.common.collect.ImmutableSetMultimap", - "com.google.common.collect.ImmutableTable") + ImmutableBiMap.class.getCanonicalName(), + ImmutableList.class.getCanonicalName(), + ImmutableListMultimap.class.getCanonicalName(), + ImmutableMap.class.getCanonicalName(), + ImmutableMultimap.class.getCanonicalName(), + ImmutableMultiset.class.getCanonicalName(), + ImmutableRangeMap.class.getCanonicalName(), + ImmutableRangeSet.class.getCanonicalName(), + ImmutableSet.class.getCanonicalName(), + ImmutableSetMultimap.class.getCanonicalName(), + ImmutableTable.class.getCanonicalName()) .named("copyOf"), - staticMethod() - .onClass("com.google.errorprone.matchers.Matchers") - .namedAnyOf("allOf", "anyOf"), + staticMethod().onClass(Matchers.class.getCanonicalName()).namedAnyOf("allOf", "anyOf"), staticMethod().onClass("reactor.adapter.rxjava.RxJava2Adapter"), staticMethod() .onClass("reactor.core.publisher.Flux") diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java index 4834267e94..e6dc139f1d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/JUnitValueSource.java @@ -24,6 +24,8 @@ import static tech.picnic.errorprone.bugpatterns.util.MoreJUnitMatchers.getMethodSourceFactoryNames; import com.google.auto.service.AutoService; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.errorprone.BugPattern; import com.google.errorprone.VisitorState; @@ -106,8 +108,8 @@ public final class JUnitValueSource extends BugChecker implements MethodTreeMatc DoubleStream.class.getCanonicalName(), List.class.getCanonicalName(), Set.class.getCanonicalName(), - "com.google.common.collect.ImmutableList", - "com.google.common.collect.ImmutableSet") + ImmutableList.class.getCanonicalName(), + ImmutableSet.class.getCanonicalName()) .named("of"), hasArguments(AT_LEAST_ONE, anything()), hasArguments(ALL, SUPPORTED_VALUE_FACTORY_VALUES))); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java index 8c5e2fa43a..bacf57fbe5 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java @@ -9,6 +9,8 @@ import com.google.auto.service.AutoService; import com.google.auto.value.AutoValue; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Predicates; +import com.google.common.base.Strings; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; import com.google.common.collect.ImmutableTable; @@ -27,6 +29,11 @@ import com.sun.source.tree.Tree; import com.sun.source.util.TreeScanner; import com.sun.tools.javac.code.Symbol; +import java.time.Clock; +import java.time.ZoneOffset; +import java.util.Collections; +import java.util.Locale; +import java.util.regex.Pattern; import org.jspecify.annotations.Nullable; import tech.picnic.errorprone.bugpatterns.util.SourceCode; @@ -59,12 +66,12 @@ public final class NonStaticImport extends BugChecker implements CompilationUnit @VisibleForTesting static final ImmutableSet NON_STATIC_IMPORT_CANDIDATE_TYPES = ImmutableSet.of( - "com.google.common.base.Strings", - "com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode", - "com.google.errorprone.VisitorState", - "com.google.errorprone.util.ASTHelpers", - "java.time.Clock", - "java.time.ZoneOffset"); + ASTHelpers.class.getCanonicalName(), + Clock.class.getCanonicalName(), + Strings.class.getCanonicalName(), + VisitorState.class.getCanonicalName(), + ZoneOffset.class.getCanonicalName(), + "com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode"); /** * Type members that should never be statically imported. @@ -83,9 +90,8 @@ public final class NonStaticImport extends BugChecker implements CompilationUnit // specific context is left out. static final ImmutableSetMultimap NON_STATIC_IMPORT_CANDIDATE_MEMBERS = ImmutableSetMultimap.builder() - .put("com.google.common.base.Predicates", "contains") .putAll( - "java.util.Collections", + Collections.class.getCanonicalName(), "addAll", "copy", "fill", @@ -96,8 +102,9 @@ public final class NonStaticImport extends BugChecker implements CompilationUnit "rotate", "sort", "swap") - .put("java.util.Locale", "ROOT") - .putAll("java.util.regex.Pattern", "compile", "matches", "quote") + .put(Locale.class.getCanonicalName(), "ROOT") + .putAll(Pattern.class.getCanonicalName(), "compile", "matches", "quote") + .put(Predicates.class.getCanonicalName(), "contains") .put("org.springframework.http.MediaType", "ALL") .build(); diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java index 201b43eeef..4b6ba6ce3d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RedundantStringConversion.java @@ -18,6 +18,8 @@ import static tech.picnic.errorprone.bugpatterns.util.Documentation.BUG_PATTERNS_BASE_URL; import com.google.auto.service.AutoService; +import com.google.common.base.Preconditions; +import com.google.common.base.Verify; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.primitives.Primitives; @@ -136,10 +138,10 @@ public final class RedundantStringConversion extends BugChecker private static final Matcher GUAVA_GUARD_INVOCATION = anyOf( staticMethod() - .onClass("com.google.common.base.Preconditions") + .onClass(Preconditions.class.getCanonicalName()) .namedAnyOf("checkArgument", "checkState", "checkNotNull"), staticMethod() - .onClass("com.google.common.base.Verify") + .onClass(Verify.class.getCanonicalName()) .namedAnyOf("verify", "verifyNotNull")); private static final Matcher SLF4J_LOGGER_INVOCATION = instanceMethod() diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java index d8d6df2f80..7c1a48c01f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/RequestMappingAnnotation.java @@ -22,6 +22,10 @@ import com.google.errorprone.matchers.Matcher; import com.sun.source.tree.MethodTree; import com.sun.source.tree.Tree; +import java.io.InputStream; +import java.time.ZoneId; +import java.util.Locale; +import java.util.TimeZone; /** * A {@link BugChecker} that flags {@code @RequestMapping} methods that have one or more parameters @@ -70,10 +74,10 @@ public final class RequestMappingAnnotation extends BugChecker implements Method isType(ANN_PACKAGE_PREFIX + "RequestHeader"), isType(ANN_PACKAGE_PREFIX + "RequestParam"), isType(ANN_PACKAGE_PREFIX + "RequestPart"))), - isSameType("java.io.InputStream"), - isSameType("java.time.ZoneId"), - isSameType("java.util.Locale"), - isSameType("java.util.TimeZone"), + isSameType(InputStream.class.getCanonicalName()), + isSameType(Locale.class.getCanonicalName()), + isSameType(TimeZone.class.getCanonicalName()), + isSameType(ZoneId.class.getCanonicalName()), isSameType("jakarta.servlet.http.HttpServletRequest"), isSameType("jakarta.servlet.http.HttpServletResponse"), isSameType("javax.servlet.http.HttpServletRequest"), diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java index 8eb703f76d..f7fa3fe26b 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/StaticImport.java @@ -10,8 +10,24 @@ import com.google.auto.service.AutoService; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Functions; +import com.google.common.base.Preconditions; +import com.google.common.base.Predicates; +import com.google.common.base.Verify; +import com.google.common.collect.Comparators; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableListMultimap; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableMultiset; +import com.google.common.collect.ImmutableRangeSet; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; +import com.google.common.collect.ImmutableSortedMap; +import com.google.common.collect.ImmutableSortedMultiset; +import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.ImmutableTable; +import com.google.common.collect.MoreCollectors; +import com.google.common.collect.Sets; import com.google.errorprone.BugPattern; import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.BugChecker; @@ -22,12 +38,25 @@ import com.google.errorprone.fixes.SuggestedFix; import com.google.errorprone.fixes.SuggestedFixes; import com.google.errorprone.matchers.Description; +import com.google.errorprone.matchers.Matchers; +import com.google.errorprone.refaster.ImportPolicy; import com.google.errorprone.util.ASTHelpers; import com.sun.source.tree.MemberSelectTree; import com.sun.source.tree.MethodInvocationTree; import com.sun.source.tree.Tree; import com.sun.tools.javac.code.Type; +import java.nio.charset.StandardCharsets; +import java.time.ZoneOffset; +import java.util.Collections; +import java.util.Comparator; +import java.util.Map; +import java.util.Objects; import java.util.Optional; +import java.util.UUID; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.regex.Pattern; +import java.util.stream.Collectors; /** A {@link BugChecker} that flags type members that can and should be statically imported. */ // XXX: This check is closely linked to `NonStaticImport`. Consider merging the two. @@ -57,19 +86,25 @@ public final class StaticImport extends BugChecker implements MemberSelectTreeMa @VisibleForTesting static final ImmutableSet STATIC_IMPORT_CANDIDATE_TYPES = ImmutableSet.of( + BugPattern.LinkType.class.getCanonicalName(), + BugPattern.SeverityLevel.class.getCanonicalName(), + BugPattern.StandardTags.class.getCanonicalName(), + Collections.class.getCanonicalName(), + Collectors.class.getCanonicalName(), + Comparator.class.getCanonicalName(), + ImportPolicy.class.getCanonicalName(), + Map.Entry.class.getCanonicalName(), + Matchers.class.getCanonicalName(), + MoreCollectors.class.getCanonicalName(), + Pattern.class.getCanonicalName(), + Preconditions.class.getCanonicalName(), + Predicates.class.getCanonicalName(), + StandardCharsets.class.getCanonicalName(), + Verify.class.getCanonicalName(), "com.fasterxml.jackson.annotation.JsonCreator.Mode", "com.fasterxml.jackson.annotation.JsonFormat.Shape", "com.fasterxml.jackson.annotation.JsonInclude.Include", "com.fasterxml.jackson.annotation.JsonProperty.Access", - "com.google.common.base.Preconditions", - "com.google.common.base.Predicates", - "com.google.common.base.Verify", - "com.google.common.collect.MoreCollectors", - "com.google.errorprone.BugPattern.LinkType", - "com.google.errorprone.BugPattern.SeverityLevel", - "com.google.errorprone.BugPattern.StandardTags", - "com.google.errorprone.matchers.Matchers", - "com.google.errorprone.refaster.ImportPolicy", "com.mongodb.client.model.Accumulators", "com.mongodb.client.model.Aggregates", "com.mongodb.client.model.Filters", @@ -77,12 +112,6 @@ public final class StaticImport extends BugChecker implements MemberSelectTreeMa "com.mongodb.client.model.Projections", "com.mongodb.client.model.Sorts", "com.mongodb.client.model.Updates", - "java.nio.charset.StandardCharsets", - "java.util.Collections", - "java.util.Comparator", - "java.util.Map.Entry", - "java.util.regex.Pattern", - "java.util.stream.Collectors", "org.assertj.core.api.Assertions", "org.assertj.core.api.InstanceOfAssertFactories", "org.assertj.core.api.SoftAssertions", @@ -121,39 +150,39 @@ public final class StaticImport extends BugChecker implements MemberSelectTreeMa */ static final ImmutableSetMultimap STATIC_IMPORT_CANDIDATE_MEMBERS = ImmutableSetMultimap.builder() + .putAll(Comparators.class.getCanonicalName(), "emptiesFirst", "emptiesLast") + .put(Function.class.getCanonicalName(), "identity") + .put(Functions.class.getCanonicalName(), "identity") + .put(ImmutableList.class.getCanonicalName(), "toImmutableList") .putAll( - "com.google.common.collect.ImmutableListMultimap", + ImmutableListMultimap.class.getCanonicalName(), "flatteningToImmutableListMultimap", "toImmutableListMultimap") - .put("com.google.common.collect.ImmutableList", "toImmutableList") - .put("com.google.common.collect.ImmutableMap", "toImmutableMap") - .put("com.google.common.collect.ImmutableMultiset", "toImmutableMultiset") - .put("com.google.common.collect.ImmutableRangeSet", "toImmutableRangeSet") + .put(ImmutableMap.class.getCanonicalName(), "toImmutableMap") + .put(ImmutableMultiset.class.getCanonicalName(), "toImmutableMultiset") + .put(ImmutableRangeSet.class.getCanonicalName(), "toImmutableRangeSet") + .put(ImmutableSet.class.getCanonicalName(), "toImmutableSet") .putAll( - "com.google.common.collect.ImmutableSetMultimap", + ImmutableSetMultimap.class.getCanonicalName(), "flatteningToImmutableSetMultimap", "toImmutableSetMultimap") - .put("com.google.common.collect.ImmutableSet", "toImmutableSet") - .put("com.google.common.collect.ImmutableSortedMap", "toImmutableSortedMap") - .put("com.google.common.collect.ImmutableSortedMultiset", "toImmutableSortedMultiset") - .put("com.google.common.collect.ImmutableSortedSet", "toImmutableSortedSet") - .put("com.google.common.collect.ImmutableTable", "toImmutableTable") - .put("com.google.common.collect.Sets", "toImmutableEnumSet") - .put("com.google.common.base.Functions", "identity") - .put("java.time.ZoneOffset", "UTC") - .put("java.util.function.Function", "identity") - .put("java.util.function.Predicate", "not") - .put("java.util.UUID", "randomUUID") - .put("org.junit.jupiter.params.provider.Arguments", "arguments") + .put(ImmutableSortedMap.class.getCanonicalName(), "toImmutableSortedMap") + .put(ImmutableSortedMultiset.class.getCanonicalName(), "toImmutableSortedMultiset") + .put(ImmutableSortedSet.class.getCanonicalName(), "toImmutableSortedSet") + .put(ImmutableTable.class.getCanonicalName(), "toImmutableTable") .putAll( - "java.util.Objects", + Objects.class.getCanonicalName(), "checkIndex", "checkFromIndexSize", "checkFromToIndex", "requireNonNull", "requireNonNullElse", "requireNonNullElseGet") - .putAll("com.google.common.collect.Comparators", "emptiesFirst", "emptiesLast") + .put(Predicate.class.getCanonicalName(), "not") + .put(Sets.class.getCanonicalName(), "toImmutableEnumSet") + .put(UUID.class.getCanonicalName(), "randomUUID") + .put(ZoneOffset.class.getCanonicalName(), "UTC") + .put("org.junit.jupiter.params.provider.Arguments", "arguments") .build(); /** Instantiates a new {@link StaticImport} instance. */ diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java index 51678cd335..04c994a915 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/util/ThirdPartyLibrary.java @@ -1,5 +1,6 @@ package tech.picnic.errorprone.bugpatterns.util; +import com.google.common.collect.ImmutableList; import com.google.errorprone.VisitorState; import com.google.errorprone.bugpatterns.BugChecker; import com.google.errorprone.suppliers.Supplier; @@ -31,7 +32,7 @@ public enum ThirdPartyLibrary { * * @see Guava on GitHub */ - GUAVA("com.google.common.collect.ImmutableList"), + GUAVA(ImmutableList.class.getCanonicalName()), /** * VMWare's Project Reactor. * @@ -66,7 +67,14 @@ public boolean isIntroductionAllowed(VisitorState state) { return canUse.get(state); } - private static boolean canIntroduceUsage(String className, VisitorState state) { + /** + * Tells whether the given fully qualified type is available on the current class path. + * + * @param className The type of interest. + * @param state The context under consideration. + * @return {@code true} iff it is okay to assume or create a dependency on this type. + */ + public static boolean canIntroduceUsage(String className, VisitorState state) { return shouldIgnoreClasspath(state) || isKnownClass(className, state); } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ErrorProneRuntimeClasspathTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ErrorProneRuntimeClasspathTest.java new file mode 100644 index 0000000000..7aff4887d0 --- /dev/null +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/ErrorProneRuntimeClasspathTest.java @@ -0,0 +1,136 @@ +package tech.picnic.errorprone.bugpatterns; + +import com.google.errorprone.BugCheckerRefactoringTestHelper; +import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode; +import com.google.errorprone.CompilationTestHelper; +import org.junit.jupiter.api.Test; + +final class ErrorProneRuntimeClasspathTest { + @Test + void identification() { + CompilationTestHelper.newInstance(ErrorProneRuntimeClasspath.class, getClass()) + .expectErrorMessage( + "USE_CLASS_REFERENCE", + m -> + m.contains( + "This type will be on the runtime classpath; use `Class#getCanonicalName()` instead")) + .expectErrorMessage( + "USE_STRING_LITERAL", + m -> + m.contains( + "This type may not be on the runtime classpath; use a string literal instead")) + .addSourceLines( + "A.java", + "import com.google.common.collect.ImmutableList;", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.BugPattern;", + "import com.google.errorprone.CompilationTestHelper;", + "import org.junit.jupiter.api.Test;", + "", + "class A {", + " @SuppressWarnings(\"java.lang.String\")", + " void m(Object o) {", + " m(null);", + " m(0);", + " m(getClass().getName());", + " m(getClass().getCanonicalName());", + " m(\"\");", + " m(\"foo\");", + " m(\"java.util.\");", + "", + " m(\"org.junit.jupiter.api.Test\");", + " m(\"org.junit.jupiter.api.Test.toString\");", + " m(\"com.google.errorprone.CompilationTestHelper\");", + " m(\"com.google.errorprone.CompilationTestHelper.toString\");", + " m(\"com.google.errorprone.BugCheckerRefactoringTestHelper.ExpectOutput\");", + " m(\"com.google.errorprone.BugCheckerRefactoringTestHelper.ExpectOutput.toString\");", + " m(\"com.google.errorprone.NonExistent\");", + " m(\"com.google.common.NonExistent.toString\");", + " m(\"java.lang.NonExistent\");", + " // BUG: Diagnostic matches: USE_CLASS_REFERENCE", + " m(\"com.google.errorprone.BugPattern\");", + " // BUG: Diagnostic matches: USE_CLASS_REFERENCE", + " m(\"com.google.errorprone.util.ErrorProneToken\");", + " // BUG: Diagnostic matches: USE_CLASS_REFERENCE", + " m(\"com.google.common.collect.ImmutableList\");", + " // BUG: Diagnostic matches: USE_CLASS_REFERENCE", + " m(\"java.lang.String\");", + " // BUG: Diagnostic matches: USE_CLASS_REFERENCE", + " m(\"java.lang.String.toString\");", + "", + " m(BugPattern.class.getCanonicalName());", + " m(ImmutableList.class.getCanonicalName());", + " m(String.class.getCanonicalName());", + " m(void.class.getCanonicalName());", + " m(boolean.class.getCanonicalName());", + " m(byte.class.getCanonicalName());", + " m(char.class.getCanonicalName());", + " m(short.class.getCanonicalName());", + " m(int.class.getCanonicalName());", + " m(long.class.getCanonicalName());", + " m(float.class.getCanonicalName());", + " m(double.class.getCanonicalName());", + " m(java.lang.Iterable.class.getCanonicalName());", + " m(CompilationTestHelper.class.toString());", + " // BUG: Diagnostic matches: USE_STRING_LITERAL", + " m(CompilationTestHelper.class.getCanonicalName());", + " // BUG: Diagnostic matches: USE_STRING_LITERAL", + " m(BugCheckerRefactoringTestHelper.ExpectOutput.class.getCanonicalName());", + " // BUG: Diagnostic matches: USE_STRING_LITERAL", + " m(Test.class.getCanonicalName());", + " // BUG: Diagnostic matches: USE_STRING_LITERAL", + " m(org.junit.jupiter.api.Nested.class.getCanonicalName());", + " }", + "}") + .doTest(); + } + + @Test + void replacement() { + BugCheckerRefactoringTestHelper.newInstance(ErrorProneRuntimeClasspath.class, getClass()) + .addInputLines( + "A.java", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.CompilationTestHelper;", + "import org.junit.jupiter.api.Test;", + "", + "class A {", + " void m(Object o) {", + " m(\"com.google.errorprone.BugPattern\");", + " m(\"com.google.errorprone.util.ErrorProneToken\");", + " m(\"com.google.common.collect.ImmutableList\");", + " m(\"java.lang.String\");", + " m(\"java.lang.String.toString\");", + "", + " m(CompilationTestHelper.class.getCanonicalName());", + " m(BugCheckerRefactoringTestHelper.ExpectOutput.class.getCanonicalName());", + " m(Test.class.getCanonicalName());", + " m(org.junit.jupiter.api.Nested.class.getCanonicalName());", + " }", + "}") + .addOutputLines( + "A.java", + "import com.google.common.collect.ImmutableList;", + "import com.google.errorprone.BugCheckerRefactoringTestHelper;", + "import com.google.errorprone.BugPattern;", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.util.ErrorProneToken;", + "import org.junit.jupiter.api.Test;", + "", + "class A {", + " void m(Object o) {", + " m(BugPattern.class.getCanonicalName());", + " m(ErrorProneToken.class.getCanonicalName());", + " m(ImmutableList.class.getCanonicalName());", + " m(String.class.getCanonicalName());", + " m(String.class.getCanonicalName() + \".toString\");", + "", + " m(\"com.google.errorprone.CompilationTestHelper\");", + " m(\"com.google.errorprone.BugCheckerRefactoringTestHelper.ExpectOutput\");", + " m(\"org.junit.jupiter.api.Test\");", + " m(\"org.junit.jupiter.api.Nested\");", + " }", + "}") + .doTest(TestMode.TEXT_MATCH); + } +} diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreTypesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreTypesTest.java index 29b6fed550..0a30ba4bc6 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreTypesTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/util/MoreTypesTest.java @@ -21,7 +21,10 @@ import com.sun.source.tree.MethodInvocationTree; import com.sun.tools.javac.code.Type; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import java.util.Map; +import java.util.Optional; import org.junit.jupiter.api.Test; final class MoreTypesTest { @@ -155,41 +158,57 @@ private static ImmutableSet> getTestTypes() { return ImmutableSet.of( // Invalid types. type("java.lang.Nonexistent"), - generic(type("java.util.Integer"), unbound()), + generic(type("java.util.Nonexistent"), unbound()), // Valid types. - type("java.lang.String"), - type("java.lang.Number"), - superOf(type("java.lang.Number")), - subOf(type("java.lang.Number")), - type("java.lang.Integer"), - superOf(type("java.lang.Integer")), - subOf(type("java.lang.Integer")), - type("java.util.Optional"), - raw(type("java.util.Optional")), - generic(type("java.util.Optional"), unbound()), - generic(type("java.util.Optional"), type("java.lang.Number")), - type("java.util.Collection"), - raw(type("java.util.Collection")), - generic(type("java.util.Collection"), unbound()), - generic(type("java.util.Collection"), type("java.lang.Number")), - generic(type("java.util.Collection"), superOf(type("java.lang.Number"))), - generic(type("java.util.Collection"), subOf(type("java.lang.Number"))), - generic(type("java.util.Collection"), type("java.lang.Integer")), - generic(type("java.util.Collection"), superOf(type("java.lang.Integer"))), - generic(type("java.util.Collection"), subOf(type("java.lang.Integer"))), - type("java.util.List"), - raw(type("java.util.List")), - generic(type("java.util.List"), unbound()), - generic(type("java.util.List"), type("java.lang.Number")), - generic(type("java.util.List"), superOf(type("java.lang.Number"))), - generic(type("java.util.List"), subOf(type("java.lang.Number"))), - generic(type("java.util.List"), type("java.lang.Integer")), - generic(type("java.util.List"), superOf(type("java.lang.Integer"))), - generic(type("java.util.List"), subOf(type("java.lang.Integer"))), + type(String.class.getCanonicalName()), + type(Number.class.getCanonicalName()), + superOf(type(Number.class.getCanonicalName())), + subOf(type(Number.class.getCanonicalName())), + type(Integer.class.getCanonicalName()), + superOf(type(Integer.class.getCanonicalName())), + subOf(type(Integer.class.getCanonicalName())), + type(Optional.class.getCanonicalName()), + raw(type(Optional.class.getCanonicalName())), + generic(type(Optional.class.getCanonicalName()), unbound()), + generic(type(Optional.class.getCanonicalName()), type(Number.class.getCanonicalName())), + type(Collection.class.getCanonicalName()), + raw(type(Collection.class.getCanonicalName())), + generic(type(Collection.class.getCanonicalName()), unbound()), + generic(type(Collection.class.getCanonicalName()), type(Number.class.getCanonicalName())), generic( - type("java.util.Map"), - type("java.lang.String"), - subOf(generic(type("java.util.Collection"), superOf(type("java.lang.Short")))))); + type(Collection.class.getCanonicalName()), + superOf(type(Number.class.getCanonicalName()))), + generic( + type(Collection.class.getCanonicalName()), + subOf(type(Number.class.getCanonicalName()))), + generic( + type(Collection.class.getCanonicalName()), type(Integer.class.getCanonicalName())), + generic( + type(Collection.class.getCanonicalName()), + superOf(type(Integer.class.getCanonicalName()))), + generic( + type(Collection.class.getCanonicalName()), + subOf(type(Integer.class.getCanonicalName()))), + type(List.class.getCanonicalName()), + raw(type(List.class.getCanonicalName())), + generic(type(List.class.getCanonicalName()), unbound()), + generic(type(List.class.getCanonicalName()), type(Number.class.getCanonicalName())), + generic( + type(List.class.getCanonicalName()), superOf(type(Number.class.getCanonicalName()))), + generic( + type(List.class.getCanonicalName()), subOf(type(Number.class.getCanonicalName()))), + generic(type(List.class.getCanonicalName()), type(Integer.class.getCanonicalName())), + generic( + type(List.class.getCanonicalName()), superOf(type(Integer.class.getCanonicalName()))), + generic( + type(List.class.getCanonicalName()), subOf(type(Integer.class.getCanonicalName()))), + generic( + type(Map.class.getCanonicalName()), + type(String.class.getCanonicalName()), + subOf( + generic( + type(Collection.class.getCanonicalName()), + superOf(type(Short.class.getCanonicalName())))))); } } } From 1ca0f536c4af215b572af68d93fb5affb4ef11b1 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 22 Dec 2023 08:54:11 +0100 Subject: [PATCH 593/601] Upgrade Byte Buddy 1.14.10 -> 1.14.11 (#934) See: - https://github.com/raphw/byte-buddy/releases/tag/byte-buddy-1.14.11 - https://github.com/raphw/byte-buddy/compare/byte-buddy-1.14.10...byte-buddy-1.14.11 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 07b6b4adc8..66aaa35a09 100644 --- a/pom.xml +++ b/pom.xml @@ -386,7 +386,7 @@ net.bytebuddy byte-buddy - 1.14.10 + 1.14.11 From 66967fb90321d22ac75278aab6f8d5ee4aa6f504 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 22 Dec 2023 10:41:58 +0100 Subject: [PATCH 595/601] Upgrade actions/upload-pages-artifact v2.0.0 -> v3.0.0 (#933) See: - https://github.com/actions/upload-pages-artifact/releases/tag/v3.0.0 --- .github/workflows/deploy-website.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index 90df1ecff8..529d00e257 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -32,7 +32,7 @@ jobs: # "Refaster rules" terminology on our website and in the code. run: bundle exec htmlproofer --disable_external true --check-external-hash false ./_site - name: Upload website as artifact - uses: actions/upload-pages-artifact@a753861a5debcf57bf8b404356158c8e1e33150c # v2.0.0 + uses: actions/upload-pages-artifact@0252fc4ba7626f0298f0cf00902a25c6afc77fa8 # v3.0.0 with: path: ./website/_site deploy: From 4d30329448c494701f0dbbfdb219dacfc33881ca Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Fri, 22 Dec 2023 11:50:52 +0100 Subject: [PATCH 596/601] Upgrade actions/deploy-pages v3.0.1 -> v4.0.0 (#932) See: - https://github.com/actions/deploy-pages/releases/tag/v4.0.0 --- .github/workflows/deploy-website.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index 529d00e257..b9d31d1a80 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -48,4 +48,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@13b55b33dd8996121833dbc1db458c793a334630 # v3.0.1 + uses: actions/deploy-pages@f33f41b675f0ab2dc5a6863c9a170fe83af3571e # v4.0.0 From 967a44690931064be5810595e84598b11095d067 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sat, 23 Dec 2023 10:17:42 +0100 Subject: [PATCH 597/601] Upgrade Error Prone 2.23.0 -> 2.24.0 (#935) See: - https://github.com/google/error-prone/releases/tag/v2.24.0 - https://github.com/google/error-prone/compare/v2.23.0...v2.24.0 - https://github.com/PicnicSupermarket/error-prone/compare/v2.23.0-picnic-1...v2.24.0-picnic-1 --- .../java/tech/picnic/errorprone/refasterrules/ReactorRules.java | 2 +- pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java index 0a323cc36e..977248a2d8 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ReactorRules.java @@ -100,7 +100,7 @@ Mono after(T value) { } /** Prefer {@link Mono#justOrEmpty(Object)} over more contrived alternatives. */ - static final class MonoJustOrEmptyObject<@Nullable T> { + static final class MonoJustOrEmptyObject { @BeforeTemplate Mono before(T value) { return Mono.justOrEmpty(Optional.ofNullable(value)); diff --git a/pom.xml b/pom.xml index 3a97429c43..f9f15b81ff 100644 --- a/pom.xml +++ b/pom.xml @@ -205,7 +205,7 @@ 1.10.4 ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 - 2.23.0 + 2.24.0 0.1.21 1.0 11 From 1650b6b00d74d309108fff4002127b164709f132 Mon Sep 17 00:00:00 2001 From: Picnic-Bot Date: Sun, 24 Dec 2023 16:38:51 +0100 Subject: [PATCH 598/601] Upgrade actions/deploy-pages v4.0.0 -> v4.0.2 (#936) See: - https://github.com/actions/deploy-pages/releases/tag/v4.0.2 - https://github.com/actions/deploy-pages/releases/tag/v4.0.1 --- .github/workflows/deploy-website.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index b9d31d1a80..2d36fbbb78 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -48,4 +48,4 @@ jobs: steps: - name: Deploy to GitHub Pages id: deployment - uses: actions/deploy-pages@f33f41b675f0ab2dc5a6863c9a170fe83af3571e # v4.0.0 + uses: actions/deploy-pages@7a9bd943aa5e5175aeb8502edcc6c1c02d398e10 # v4.0.2 From 0109632b70a493a451e25e2207de28766bab1168 Mon Sep 17 00:00:00 2001 From: Stephan Schroevers Date: Sun, 24 Dec 2023 18:52:42 +0100 Subject: [PATCH 599/601] Update Error Prone `-XepExcludedPaths` flag to be Windows-compatible (#927) Prior to these changes the provided pattern would never match on Windows, as Error Prone matches against file URIs, which in practice will always contain forward slashes, even on Windows. --- pom.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f9f15b81ff..c314106585 100644 --- a/pom.xml +++ b/pom.xml @@ -1741,7 +1741,13 @@ avoid that, so we simply tell Error Prone not to warn about generated code. --> -XepDisableWarningsInGeneratedCode - -XepExcludedPaths:\Q${project.build.directory}${file.separator}\E.* + + -XepExcludedPaths:(?!.*/src/[^/]+/java/.*).* -Xep:AndroidJdkLibsChecker:OFF + 3.12.0 @@ -94,8 +96,6 @@ it, read the installation guide for Maven or Gradle below. -XDcompilePolicy=simple - - true diff --git a/pom.xml b/pom.xml index 83be671628..6d2ffc4b27 100644 --- a/pom.xml +++ b/pom.xml @@ -206,15 +206,9 @@ ${version.error-prone-orig} v${version.error-prone-orig}-picnic-1 2.24.0 - 0.1.21 - 1.0 11 3.8.7 - 5.8.0 - 1.0.1 - 0.10.18 1.1.4 - 3.2.3 @@ -249,6 +243,11 @@ documentation-support ${project.version} + + ${project.groupId} + error-prone-contrib + ${project.version} + ${project.groupId} refaster-compiler @@ -281,6 +280,11 @@ auto-common 1.2.2 + + com.google.auto.service + auto-service + ${version.auto-service} + com.google.auto.service auto-service-annotations @@ -301,12 +305,10 @@ google-java-format 1.19.1 - com.google.guava guava-beta-checker - ${version.guava-beta-checker} + 1.0 com.google.guava @@ -320,19 +322,15 @@ truth 1.2.0 - com.jakewharton.nopen nopen-checker - ${version.nopen-checker} + 1.0.1 - com.uber.nullaway nullaway - ${version.nullaway} + 0.10.18 io.projectreactor @@ -371,12 +369,10 @@ jaxb-api 2.3.1 - jp.skypencil.errorprone.slf4j errorprone-slf4j - ${version.error-prone-slf4j} + 0.1.21 junit @@ -438,7 +434,7 @@ org.mockito mockito-bom - ${version.mockito} + 5.8.0 pom import @@ -884,56 +880,16 @@ org.apache.maven.plugins maven-compiler-plugin - 3.10.1 + 3.12.1 - - - ${groupId.error-prone} - error_prone_core - ${version.error-prone} - com.google.auto.value auto-value - ${version.auto-value} com.google.auto.service auto-service - ${version.auto-service} - - - com.google.guava - guava-beta-checker - ${version.guava-beta-checker} - - - com.jakewharton.nopen - nopen-checker - ${version.nopen-checker} - - - com.uber.nullaway - nullaway - ${version.nullaway} - - - jp.skypencil.errorprone.slf4j - errorprone-slf4j - ${version.error-prone-slf4j} - - - org.mockito - mockito-errorprone - ${version.mockito} @@ -952,6 +908,7 @@ true ${version.jdk} ${version.jdk} + false false @@ -1181,7 +1138,7 @@ org.apache.maven.plugins maven-surefire-plugin - ${version.surefire} + 3.2.3 **/*Test.java @@ -1500,17 +1457,12 @@ non-maven-central - - 0.1.4 - - com.github.lhotari reactor-error-prone - ${version.reactor-error-prone} + 0.1.4 @@ -1524,7 +1476,6 @@ com.github.lhotari reactor-error-prone - ${version.reactor-error-prone} @@ -1557,12 +1508,10 @@ ${project.groupId} error-prone-contrib - ${project.version} ${project.groupId} refaster-runner - ${project.version} @@ -1721,6 +1670,32 @@ org.apache.maven.plugins maven-compiler-plugin + + + ${groupId.error-prone} + error_prone_core + + + com.google.guava + guava-beta-checker + + + com.jakewharton.nopen + nopen-checker + + + com.uber.nullaway + nullaway + + + jp.skypencil.errorprone.slf4j + errorprone-slf4j + + + org.mockito + mockito-errorprone + +