openrewrite / rewrite-templating

Automated templating using code snippets.
Apache License 2.0
16 stars 7 forks source link

Add `@SuppressWarnings("all")` to stop scanning tool complaints #52

Closed timtebeek closed 11 months ago

timtebeek commented 11 months ago

For https://github.com/PicnicSupermarket/error-prone-support/pull/925 & @Stephan202

timtebeek commented 11 months ago

@stephan202 When running this branch against error-prone-support I do see a rather curious error

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:testCompile (default-testCompile) on project refaster-runner: Compilation failure: Compilation failure: 
[ERROR] /home/tim/Documents/workspace/timtebeek/error-prone-support/refaster-runner/target/generated-test-sources/test-annotations/tech/picnic/errorprone/refaster/runner/FooRulesRecipes.java:[25,18] cannot find symbol
[ERROR]   symbol:   class Generated
[ERROR]   location: package javax.annotation
  1. somehow the RefasterTemplateProcessor configured in error-prone-contrib is active on refaster-runner
  2. the javax.annotation.Generated annotation can not be found there; should we use a different one?

Any ideas there? Wouldn't want to release a version that breaks things on error-prone-support, or requires undesired changes there.

Stephan202 commented 11 months ago

somehow the RefasterTemplateProcessor configured in error-prone-contrib is active on refaster-runner

Yeah, that's because I moved the annotation processor declaration :)

the javax.annotation.Generated annotation can not be found there; should we use a different one?

Indeed, javax.annotation.Generated is no longer present on newer JDKs, where it's replaced with javax.annotation.processing.Generated (since JDK 9). IIRC this had something to do with splitting up the javax.annotation package to comply with the module system. Since you also target JDK 8, this can get a bit messy. Two other options:

  1. Define a custom @Generated annotation. Tools such as Error Prone support this, and there's precedent set by e.g. Lombok.
  2. Instead add @SuppressWarnings("all"). That matches what Lombok and Immutables do, and since google/error-prone@47f0c72513801eeb2ef19b07f2e3dbdc8414668b this is also supported by Error Prone.
timtebeek commented 11 months ago

Helpful context once again, thanks! Switched to @SuppressWarnings("all") as that seemed easiest: no additional API surface or dependency. Thanks!

timtebeek commented 11 months ago

Does that also mean I can drop the empty constructors and Javadoc again? 😇