package gw.rating.flow.domain uses com.guidewire.rating.flow.domain.util.CalcRoutineCodeGeneratorFactory uses com.google.common.base.Joiner uses gw.api.system.PCLoggerCategory uses gw.lang.parser.ISymbolTable uses gw.lang.parser.ITypeUsesMap uses gw.lang.reflect.IType uses gw.rating.worksheet.WorksheetCodeGenHelper uses gw.util.Pair uses gw.validation.PCValidationContext class GenerationContext { final static var _logger = PCLoggerCategory.RATEFLOW var _context: PCValidationContext as readonly Context var _varMap : Map as readonly VarMap var _useMap : ITypeUsesMap as readonly UseMap var _table : ISymbolTable as readonly Table var _addLocalVarDecls : boolean as AddLocalVarDecls = true var _codegenStrategy : CalcRoutineCodeGeneratorFactory.CodegenStrategy as CodegenStrategy = CalcRoutineCodeGeneratorFactory.DefaultCodegenStrategy final var _stringLiteralJoiner = Joiner.on("\", \"") final var _generatedCode = new StringBuilder() public var PatternCode : String var _lineCount : int var _columnCount: int var _lastCharIsNewline: boolean = false var _worksheetsEnabled : boolean as readonly WorksheetsEnabled var _worksheetHelper : WorksheetCodeGenHelper as readonly WorksheetHelper internal construct() { this(false) } internal construct(codegenStrategy: CalcRoutineCodeGeneratorFactory.CodegenStrategy) { this(false) _codegenStrategy = codegenStrategy } internal construct(worksheets: boolean) { this(null, null, null, 0, null, worksheets) } internal construct(codegenStrategy: CalcRoutineCodeGeneratorFactory.CodegenStrategy, worksheets: boolean) { this(worksheets) _codegenStrategy = codegenStrategy } construct( aContext : PCValidationContext, aTable : ISymbolTable, usesMap : ITypeUsesMap, lineCount : int, aPatternCode : String, worksheets : boolean) { _context = aContext _varMap = {} _useMap = usesMap _table = aTable _lineCount = lineCount _columnCount = 0 PatternCode = aPatternCode _worksheetsEnabled = worksheets _worksheetHelper = new WorksheetCodeGenHelper(this) } function beginCodeGen() : Pair { return new Pair(_lineCount, _columnCount) } function endCodeGen() : Pair { return new Pair(_lineCount, _columnCount) } property get GeneratedCode() : String { return _generatedCode.toString() } private function incrementLineCount(i : int) { _lineCount+=i if (i > 0) { _columnCount = 0 } } private function incrementColumnCount(cnt: int) { _columnCount += cnt } function appendCommaSeparatedStringLiterals(stringLiterals : Iterable) : GenerationContext { _generatedCode.append('"') _stringLiteralJoiner.appendTo(_generatedCode, stringLiterals) _generatedCode.append('"') return this } function append(c: char) : GenerationContext { _generatedCode.append(c) if (c == '\n') { incrementLineCount(1) _lastCharIsNewline = true } return this } function append(s: String) : GenerationContext { if (s == null) return this _generatedCode.append(s) incrementLineCount(s.countMatches("\n")) if (s.endsWith("\n")) { _lastCharIsNewline = true } else { _lastCharIsNewline = false // incrementColumnCount(s.split("\n").last().length) var n = s.lastIndexOf('\n') if (n == -1) { incrementColumnCount(s.length()) } else { incrementColumnCount(s.length() - n) } } return this } function appendNewlineIfNeeded(): GenerationContext { if (not _lastCharIsNewline) { append('\n') } return this } function prepend(s: String): GenerationContext { if (s == null) return this _generatedCode.insert(0, s) incrementLineCount(s.countMatches("\n")) return this } function replace(s: String): GenerationContext { if (not s?.HasContent) { return this } // Because the prettyprinted code ends with a newline. appendNewlineIfNeeded() if (_generatedCode.toString().countMatches('\n') != s.countMatches('\n')) { // Cowardly refuse to replace _logger.warn("Mismatch in number of lines between generated code and prettyprinted version.") return this } _generatedCode.replace(0, _generatedCode.length(), s) _lineCount = s.countMatches("\n") if (s.endsWith("\n")) { _columnCount = 0 } else { _columnCount = s.split("\n").last().length() } return this } }