Interface DiagnosticSink
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Trees.
By default a SourceChecker reports each finding directly to javac. A host that embeds
the Checker Framework can install a DiagnosticSink (see SourceChecker.setDiagnosticSink(org.checkerframework.framework.source.DiagnosticSink)) to receive findings and report them through its own channel
instead. This is used when the Checker Framework runs as an Error Prone plugin, so that Checker
Framework findings become Error Prone Descriptions (honoring Error Prone severity,
suppression, and the suggested-fix / patch pipeline).
Only findings positioned at a Tree reach the sink. A finding positioned at an Element (rather than a tree), or with no source position at all, is
still reported directly through javac's Messager, because such a finding has no
Tree/TreePath for a host to anchor its own diagnostic to. In Error Prone mode those
(rare) findings therefore appear as plain javac diagnostics rather than host diagnostics. Almost
all Checker Framework findings are positioned at a tree.
This interface intentionally uses only javax.tools, com.sun.source.tree, and
Checker Framework types, so the Checker Framework core has no dependency on any host framework
(in particular, no dependency on Error Prone). The translation from these neutral values to a
host-specific representation is the host's responsibility.
-
Method Summary
Modifier and TypeMethodDescriptionvoidreport(Diagnostic.Kind kind, String message, Tree source, CompilationUnitTree root, @Nullable TreePath path, List<SuggestedFixData> fixes) Receives one Checker Framework finding, which may carry machine-applicable suggested fixes (as alternatives).
-
Method Details
-
report
void report(Diagnostic.Kind kind, String message, Tree source, CompilationUnitTree root, @Nullable TreePath path, List<SuggestedFixData> fixes) Receives one Checker Framework finding, which may carry machine-applicable suggested fixes (as alternatives). A host with no fix pipeline simply ignoresfixes, so this interface can be implemented with a lambda.- Parameters:
kind- the diagnostic kind (typicallyDiagnostic.Kind.ERRORorDiagnostic.Kind.WARNING)message- the fully-formatted, localized message textsource- the tree at which the finding is reported; its source position locates the diagnostic. Nevernull: a finding with no tree position is reported through javac before reaching a sink (see above), so an installed sink is called only for tree-positioned findings.root- the compilation unit containingsourcepath- the path tosource, or null if it could not be determined. The checker computes it while visiting the finding, which is far cheaper than a host re-deriving it afterwards: by the time findings are handed over, locating a tree costs a scan of the whole compilation unit, so re-deriving it per finding is quadratic in the number of findings in a file.fixes- suggested fixes for the finding, as alternatives (possibly empty)
-