Class OutputEmitter

java.lang.Object
org.egothor.methodatlas.emit.OutputEmitter

public final class OutputEmitter extends Object
Formats and emits test method records to a configured output writer.

This class centralizes all output rendering logic for the MethodAtlas application. It supports both CSV and plain-text output modes and handles optional AI enrichment columns.

The PrintWriter supplied at construction time is the sole output destination, which allows the caller to redirect output for testing or piping without manipulating System.out.

Instances of this class are immutable after construction.

See Also:
  • Constructor Details

    • OutputEmitter

      public OutputEmitter(PrintWriter out, boolean aiEnabled, boolean confidenceEnabled, boolean contentHashEnabled, boolean driftDetect, boolean emitSourceRoot)
      Creates a new output emitter bound to the supplied writer.
      Parameters:
      out - writer to which all records are emitted
      aiEnabled - whether AI enrichment columns should be included
      confidenceEnabled - whether the ai_confidence column should be included; only meaningful when aiEnabled is true
      contentHashEnabled - whether the content_hash column should be included
      driftDetect - whether the tag_ai_drift column should be included; only meaningful when aiEnabled is true
      emitSourceRoot - whether a source_root column (CSV) or SRCROOT= token (plain) should be included; enable with -emit-source-root when scanning a multi-root project where the same FQCN can appear under different source trees
  • Method Details

    • emitMetadata

      public void emitMetadata(String version, String scanTimestamp, String taxonomyInfo)
      Emits # key: value metadata comment lines before the CSV header.
      Parameters:
      version - tool version string, e.g. 1.2.3 or dev
      scanTimestamp - ISO-8601 timestamp of the scan start
      taxonomyInfo - human-readable taxonomy descriptor
    • emitCsvHeader

      public void emitCsvHeader(OutputMode mode)
      Emits the CSV header line when OutputMode.CSV is selected.

      Does nothing when plain-text mode is active.

      Parameters:
      mode - selected output mode
    • emit

      public void emit(OutputMode mode, String fqcn, String method, int loc, String contentHash, List<String> tags, String displayName, AiMethodSuggestion suggestion, String sourceRoot)
      Emits a single test method record in the configured output mode.
      Parameters:
      mode - selected output mode
      fqcn - fully qualified class name containing the method
      method - test method name
      loc - inclusive line count of the method declaration
      contentHash - SHA-256 fingerprint of the enclosing class source, or null when -content-hash is not enabled
      tags - source-level tags extracted from the method
      displayName - text from an existing display-name annotation on the method, or an empty string if absent; null is treated as absent
      suggestion - AI suggestion for the method, or null if none
      sourceRoot - CWD-relative path of the scan root, or null when -emit-source-root is not enabled
    • csvEscape

      public static String csvEscape(String value)
      Escapes a value for inclusion in a CSV field.

      If the value contains a comma, double quote, carriage return, or line feed, it is wrapped in double quotes and embedded quotes are doubled. Values that start with =, +, -, or @ are also quoted to prevent spreadsheet formula injection. A null input is converted to an empty field.

      Parameters:
      value - value to escape; may be null
      Returns:
      CSV-safe representation of value