-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8354090: Refactor import warning suppression in Check.java #24532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,12 @@ protected Check(Context context) { | |
*/ | ||
private final boolean allowSealed; | ||
|
||
/** Whether to force suppression of deprecation and preview warnings. | ||
* This happens when attributing import statements for JDK 9+. | ||
* @see Feature#DEPRECATION_ON_IMPORT | ||
*/ | ||
private boolean importSuppression; | ||
|
||
/* ************************************************************************* | ||
* Errors and Warnings | ||
**************************************************************************/ | ||
|
@@ -228,6 +234,12 @@ Lint setLint(Lint newLint) { | |
return prev; | ||
} | ||
|
||
boolean setImportSuppression(boolean newImportSuppression) { | ||
boolean prev = importSuppression; | ||
importSuppression = newImportSuppression; | ||
return prev; | ||
} | ||
|
||
MethodSymbol setMethod(MethodSymbol newMethod) { | ||
MethodSymbol prev = method; | ||
method = newMethod; | ||
|
@@ -261,19 +273,10 @@ void warnDeprecated(DiagnosticPosition pos, Symbol sym) { | |
* @param msg A Warning describing the problem. | ||
*/ | ||
public void warnPreviewAPI(DiagnosticPosition pos, LintWarning warnKey) { | ||
if (!lint.isSuppressed(LintCategory.PREVIEW)) | ||
if (!importSuppression && !lint.isSuppressed(LintCategory.PREVIEW)) | ||
preview.reportPreviewWarning(pos, warnKey); | ||
} | ||
|
||
/** Log a preview warning. | ||
* @param pos Position to be used for error reporting. | ||
* @param msg A Warning describing the problem. | ||
*/ | ||
public void warnDeclaredUsingPreview(DiagnosticPosition pos, Symbol sym) { | ||
if (!lint.isSuppressed(LintCategory.PREVIEW)) | ||
preview.reportPreviewWarning(pos, LintWarnings.DeclaredUsingPreview(kindName(sym), sym)); | ||
} | ||
|
||
/** Log a preview warning. | ||
* @param pos Position to be used for error reporting. | ||
* @param msg A Warning describing the problem. | ||
|
@@ -3773,8 +3776,8 @@ void checkDeprecated(final DiagnosticPosition pos, final Symbol other, final Sym | |
} | ||
|
||
void checkDeprecated(Supplier<DiagnosticPosition> pos, final Symbol other, final Symbol s) { | ||
if ( (s.isDeprecatedForRemoval() | ||
|| s.isDeprecated() && !other.isDeprecated()) | ||
if (!importSuppression | ||
&& (s.isDeprecatedForRemoval() || s.isDeprecated() && !other.isDeprecated()) | ||
&& (s.outermostClass() != other.outermostClass() || s.outermostClass() == null) | ||
&& s.kind != Kind.PCK) { | ||
deferredLintHandler.report(_l -> warnDeprecated(pos.get(), s)); | ||
|
@@ -3823,10 +3826,10 @@ void checkPreview(DiagnosticPosition pos, Symbol other, Type site, Symbol s) { | |
log.error(pos, Errors.IsPreview(s)); | ||
} else { | ||
preview.markUsesPreview(pos); | ||
deferredLintHandler.report(_l -> warnPreviewAPI(pos, LintWarnings.IsPreview(s))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't defer here because we want |
||
warnPreviewAPI(pos, LintWarnings.IsPreview(s)); | ||
} | ||
} else { | ||
deferredLintHandler.report(_l -> warnPreviewAPI(pos, LintWarnings.IsPreviewReflective(s))); | ||
warnPreviewAPI(pos, LintWarnings.IsPreviewReflective(s)); | ||
} | ||
} | ||
if (preview.declaredUsingPreviewFeature(s)) { | ||
|
@@ -3835,7 +3838,7 @@ void checkPreview(DiagnosticPosition pos, Symbol other, Type site, Symbol s) { | |
//If "s" is compiled from source, then there was an error for it already; | ||
//if "s" is from classfile, there already was an error for the classfile. | ||
preview.markUsesPreview(pos); | ||
deferredLintHandler.report(_l -> warnDeclaredUsingPreview(pos, s)); | ||
warnPreviewAPI(pos, LintWarnings.DeclaredUsingPreview(kindName(s), s)); | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 inCheck
to accept an extraenv
parameter).