001package gudusoft.gsqlparser.lineage2.contract; 002 003/** 004 * Contract {@code Diagnostic} (lineage2-contract.md §8). Codes come from 005 * the Semantic IR {@code DiagnosticCode} contract plus the 006 * {@code LINEAGE2_*} namespace for engine-level codes; codes are 007 * append-only and consumers never string-match messages. 008 * 009 * <p>Internal API: not part of the public gsqlparser surface. 010 */ 011public final class ContractDiagnostic { 012 013 private final String code; 014 private final DiagnosticSeverity severity; 015 private final String message; 016 private final Integer statementIndex; 017 private final SourceLocation sourceLocation; 018 019 public ContractDiagnostic(String code, DiagnosticSeverity severity, 020 String message, Integer statementIndex, 021 SourceLocation sourceLocation) { 022 if (code == null || severity == null || message == null) { 023 throw new IllegalArgumentException( 024 "code, severity, and message must not be null"); 025 } 026 this.code = code; 027 this.severity = severity; 028 this.message = message; 029 this.statementIndex = statementIndex; 030 this.sourceLocation = sourceLocation; 031 } 032 033 public String getCode() { 034 return code; 035 } 036 037 public DiagnosticSeverity getSeverity() { 038 return severity; 039 } 040 041 public String getMessage() { 042 return message; 043 } 044 045 /** Nullable — unit-level diagnostics carry no statement index. */ 046 public Integer getStatementIndex() { 047 return statementIndex; 048 } 049 050 /** Nullable. */ 051 public SourceLocation getSourceLocation() { 052 return sourceLocation; 053 } 054}