@@ -218,6 +218,12 @@ protected Check(Context context) {
218218 */
219219 private final boolean allowSealed ;
220220
221+ /** Whether to force suppression of deprecation and preview warnings.
222+ * This happens when attributing import statements for JDK 9+.
223+ * @see Feature#DEPRECATION_ON_IMPORT
224+ */
225+ private boolean importSuppression ;
226+
221227/* *************************************************************************
222228 * Errors and Warnings
223229 **************************************************************************/
@@ -228,6 +234,12 @@ Lint setLint(Lint newLint) {
228234 return prev ;
229235 }
230236
237+ boolean setImportSuppression (boolean newImportSuppression ) {
238+ boolean prev = importSuppression ;
239+ importSuppression = newImportSuppression ;
240+ return prev ;
241+ }
242+
231243 MethodSymbol setMethod (MethodSymbol newMethod ) {
232244 MethodSymbol prev = method ;
233245 method = newMethod ;
@@ -261,19 +273,10 @@ void warnDeprecated(DiagnosticPosition pos, Symbol sym) {
261273 * @param msg A Warning describing the problem.
262274 */
263275 public void warnPreviewAPI (DiagnosticPosition pos , LintWarning warnKey ) {
264- if (!lint .isSuppressed (LintCategory .PREVIEW ))
276+ if (!importSuppression && ! lint .isSuppressed (LintCategory .PREVIEW ))
265277 preview .reportPreviewWarning (pos , warnKey );
266278 }
267279
268- /** Log a preview warning.
269- * @param pos Position to be used for error reporting.
270- * @param msg A Warning describing the problem.
271- */
272- public void warnDeclaredUsingPreview (DiagnosticPosition pos , Symbol sym ) {
273- if (!lint .isSuppressed (LintCategory .PREVIEW ))
274- preview .reportPreviewWarning (pos , LintWarnings .DeclaredUsingPreview (kindName (sym ), sym ));
275- }
276-
277280 /** Log a preview warning.
278281 * @param pos Position to be used for error reporting.
279282 * @param msg A Warning describing the problem.
@@ -3780,8 +3783,8 @@ void checkDeprecated(final DiagnosticPosition pos, final Symbol other, final Sym
37803783 }
37813784
37823785 void checkDeprecated (Supplier <DiagnosticPosition > pos , final Symbol other , final Symbol s ) {
3783- if ( ( s . isDeprecatedForRemoval ()
3784- || s .isDeprecated () && !other .isDeprecated ())
3786+ if (! importSuppression
3787+ && ( s . isDeprecatedForRemoval () || s .isDeprecated () && !other .isDeprecated ())
37853788 && (s .outermostClass () != other .outermostClass () || s .outermostClass () == null )
37863789 && s .kind != Kind .PCK ) {
37873790 deferredLintHandler .report (_l -> warnDeprecated (pos .get (), s ));
@@ -3830,10 +3833,10 @@ void checkPreview(DiagnosticPosition pos, Symbol other, Type site, Symbol s) {
38303833 log .error (pos , Errors .IsPreview (s ));
38313834 } else {
38323835 preview .markUsesPreview (pos );
3833- deferredLintHandler . report ( _l -> warnPreviewAPI (pos , LintWarnings .IsPreview (s ) ));
3836+ warnPreviewAPI (pos , LintWarnings .IsPreview (s ));
38343837 }
38353838 } else {
3836- deferredLintHandler . report ( _l -> warnPreviewAPI (pos , LintWarnings .IsPreviewReflective (s ) ));
3839+ warnPreviewAPI (pos , LintWarnings .IsPreviewReflective (s ));
38373840 }
38383841 }
38393842 if (preview .declaredUsingPreviewFeature (s )) {
@@ -3842,7 +3845,7 @@ void checkPreview(DiagnosticPosition pos, Symbol other, Type site, Symbol s) {
38423845 //If "s" is compiled from source, then there was an error for it already;
38433846 //if "s" is from classfile, there already was an error for the classfile.
38443847 preview .markUsesPreview (pos );
3845- deferredLintHandler . report ( _l -> warnDeclaredUsingPreview ( pos , s ));
3848+ warnPreviewAPI ( pos , LintWarnings . DeclaredUsingPreview ( kindName ( s ) , s ));
38463849 }
38473850 }
38483851 }
0 commit comments