INNER CODE UNIT · Python
_rewrite_single_line_annotation
uber/NullAway · scripts/nullaway-suppression-remover/src/suppression_remover/core.py:192
def _rewrite_single_line_annotation(
annotation_line: str, new_value: str, suppression_names: set[str]
) -> str:
"""Rewrite one suppression annotation while preserving surrounding text exactly."""
source = annotation_line.encode("utf-8")
tree = _get_parser().parse(source)
for node in find_suppress_warnings_nodes(tree.root_node):
if any(checker in suppression_names for checker in annotation_checkers(node)):
replacement = f"@SuppressWarnings({new_value})".encode("utf-8")
rewritten = (
source[: node.start_byte] + replacement + source[node.end_byte :]
)
return rewritten.decode("utf-8")
raise ValueError("Could not reparse @SuppressWarnings annotation")
def _rewrite_multiline_annotation(
annotation_text: str, suppression_names: set[str]