diff --git a/checker/src/main/java/org/checkerframework/checker/initialization/InitializationChecker.java b/checker/src/main/java/org/checkerframework/checker/initialization/InitializationChecker.java index 12f5a219fd1c..efe89737d460 100644 --- a/checker/src/main/java/org/checkerframework/checker/initialization/InitializationChecker.java +++ b/checker/src/main/java/org/checkerframework/checker/initialization/InitializationChecker.java @@ -109,9 +109,6 @@ public NavigableSet getSuppressWarningsPrefixes() { // "fbc" is for backward compatibility only; you should use // "initialization" instead. result.add("fbc"); - // The default prefix "initialization" must be added manually because this checker class - // is abstract and its subclasses are not named "InitializationChecker". - result.add("initialization"); return result; } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index d5f4d358af06..6b230f444b14 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -11,6 +11,7 @@ Optional Checker. **Closed issues:** +eisop#1011. Version 3.49.5-eisop1 (April 26, 2026) -------------------------------------- diff --git a/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java b/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java index 076ccaaed36b..7576191bd63c 100644 --- a/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java +++ b/framework/src/main/java/org/checkerframework/framework/source/SourceChecker.java @@ -836,8 +836,20 @@ protected void setRoot(CompilationUnitTree newRoot) { * Returns a list containing this checker name and all checkers it is a part of (that is, * checkers that called it). * + *

This list has two uses: + * + *

+ * * @return a list containing this checker name and all checkers it is a part of (that is, * checkers that called it) + * @see #getSuppressWarningsPrefixes() */ public List<@FullyQualifiedName String> getUpstreamCheckerNames() { if (upstreamCheckerNames == null) { @@ -3062,7 +3074,13 @@ private boolean isAnnotatedForThisCheckerOrUpstreamChecker(@Nullable Element elt * *

The collection must not be empty and must not contain only {@link #SUPPRESS_ALL_PREFIX}. * + *

This method is related to {@link #getUpstreamCheckerNames()}. By default, the returned set + * includes lower-case prefixes derived from all checker names returned by {@link + * #getUpstreamCheckerNames()}, unless this checker class has a {@link SuppressWarningsPrefix} + * meta-annotation. + * * @return non-empty modifiable set of lower-case prefixes for SuppressWarnings strings + * @see #getUpstreamCheckerNames() */ public NavigableSet getSuppressWarningsPrefixes() { return getStandardSuppressWarningsPrefixes(); @@ -3071,8 +3089,9 @@ public NavigableSet getSuppressWarningsPrefixes() { /** * Returns a sorted set of SuppressWarnings prefixes read from the {@link * SuppressWarningsPrefix} meta-annotation on the checker class. Or if no {@link - * SuppressWarningsPrefix} is used, the checker name is used. {@link #SUPPRESS_ALL_PREFIX} is - * also added, at the end, unless {@link #useAllcheckersPrefix} is false. + * SuppressWarningsPrefix} is used, prefixes are inferred from the upstream checker names. + * {@link #SUPPRESS_ALL_PREFIX} is also added, at the end, unless {@link #useAllcheckersPrefix} + * is false. * * @return a sorted set of SuppressWarnings prefixes */ @@ -3090,9 +3109,11 @@ protected final NavigableSet getStandardSuppressWarningsPrefixes() { return prefixes; } - // No @SuppressWarningsPrefixes annotation, by default infer key from class name. - String defaultPrefix = getDefaultSuppressWarningsPrefix(); - prefixes.add(defaultPrefix); + // No @SuppressWarningsPrefixes annotation, by default infer keys from upstream checker + // names. + for (String checkerName : getUpstreamCheckerNames()) { + prefixes.add(getDefaultSuppressWarningsPrefix(checkerName)); + } return prefixes; } @@ -3102,7 +3123,18 @@ protected final NavigableSet getStandardSuppressWarningsPrefixes() { * @return the default SuppressWarnings prefix for this checker based on the checker name */ private String getDefaultSuppressWarningsPrefix() { - String className = this.getClass().getSimpleName(); + return getDefaultSuppressWarningsPrefix(this.getClass().getSimpleName()); + } + + /** + * Returns the default SuppressWarnings prefix for the given checker name. + * + * @param checkerName a fully-qualified or simple checker class name + * @return the default SuppressWarnings prefix for the given checker name + */ + private static String getDefaultSuppressWarningsPrefix(String checkerName) { + int lastDot = checkerName.lastIndexOf('.'); + String className = lastDot == -1 ? checkerName : checkerName.substring(lastDot + 1); int indexOfChecker = className.lastIndexOf("Checker"); if (indexOfChecker == -1) { indexOfChecker = className.lastIndexOf("Subchecker");