Skip to content

Commit

Permalink
Call AnnotatedTypeFactory#getPath instead of Trees.getPath (#5096)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nargeshdb authored Mar 31, 2022
1 parent d943309 commit 7336fd9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,8 @@ public TransferResult<V, S> visitInstanceOf(InstanceOfNode node, TransferInput<V
* @return whether to perform whole-program inference on the tree
*/
private boolean shouldPerformWholeProgramInference(Tree tree) {
return infer && (tree == null || !analysis.checker.shouldSuppressWarnings(tree, ""));
@Nullable TreePath path = this.analysis.atypeFactory.getPath(tree);
return infer && (tree == null || !analysis.checker.shouldSuppressWarnings(path, ""));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2023,9 +2023,6 @@ public boolean shouldSuppressWarnings(Tree tree, String errKey) {
"Checker must provide a SuppressWarnings prefix."
+ " SourceChecker#getSuppressWarningsPrefixes was not overridden correctly.");
}
if (shouldSuppress(getSuppressWarningsStringsFromOption(), errKey)) {
return true;
}

if (shouldSuppress(getSuppressWarningsStringsFromOption(), errKey)) {
// If the error key matches a warning string in the -AsuppressWarnings, then suppress
Expand All @@ -2036,6 +2033,25 @@ public boolean shouldSuppressWarnings(Tree tree, String errKey) {
// trees.getPath might be slow, but this is only used in error reporting
@Nullable TreePath path = trees.getPath(this.currentRoot, tree);

return shouldSuppressWarnings(path, errKey);
}

/**
* Determines whether all the warnings pertaining to a given tree path should be suppressed.
* Returns true if the path is within the scope of a @SuppressWarnings annotation, one of whose
* values suppresses all the checker's warnings.
*
* @param path the TreePath that might be a source of, or related to, a warning
* @param errKey the error key the checker is emitting
* @return true if no warning should be emitted for the given path because it is contained by a
* declaration with an appropriately-valued {@code @SuppressWarnings} annotation; false
* otherwise
*/
public boolean shouldSuppressWarnings(@Nullable TreePath path, String errKey) {
if (path == null) {
return false;
}

@Nullable VariableTree var = TreePathUtil.enclosingVariable(path);
if (var != null && shouldSuppressWarnings(TreeUtils.elementFromTree(var), errKey)) {
return true;
Expand Down

0 comments on commit 7336fd9

Please sign in to comment.