RFR: 8354090: Refactor import warning suppression in Check.java
Maurizio Cimadamore
mcimadamore at openjdk.org
Wed Apr 9 08:41:29 UTC 2025
On Wed, 9 Apr 2025 01:20:50 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:
> This is split off as a sub-task of [JDK-8224228](https://bugs.openjdk.org/browse/JDK-8224228), which seeks to add `@SuppressWarnings` support for lexical features.
>
> In JDK 9 and later, there is a special exception to the normal rules for deprecation and preview warnings, which is that these warnings are automatically suppressed for import statements. This is because an import statement is just a lexical shortcut, not an actual use of the symbol.
>
> The current code in `Check.java` implements this by manipulating the current `Lint` instance directly, but this operation is incompatible upcoming changes to deferred lint handling. Instead, there can be an explicit flag for "import warning suppression" in `Check.java` to handle this. This will also make the code a bit clearer.
Looks good
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java line 239:
> 237: boolean setImportSuppression(boolean newImportSuppression) {
> 238: boolean prev = importSuppression;
> 239: importSuppression = newImportSuppression;
This is fine. Another alternative that I'm mentioning for completeness would have been for `attribImportType` to set a flag on AttrContext (and then augment some of the methods in `Check` to accept an extra `env` parameter).
-------------
Marked as reviewed by mcimadamore (Reviewer).
PR Review: https://git.openjdk.org/jdk/pull/24532#pullrequestreview-2752590983
PR Review Comment: https://git.openjdk.org/jdk/pull/24532#discussion_r2034796606
More information about the compiler-dev
mailing list