MCPcopy
hub / github.com/MadAppGang/dingo / generateElseBlock

Method generateElseBlock

pkg/codegen/guard.go:144–163  ·  view source on GitHub ↗

generateElseBlock generates the else block content.

()

Source from the content-addressed store, hash-verified

142
143// generateElseBlock generates the else block content.
144func (g *GuardGenerator) generateElseBlock() {
145 // If we have source bytes, extract the actual else block content
146 if g.SourceBytes != nil && g.Location.ElseStart >= 0 && g.Location.ElseEnd > g.Location.ElseStart {
147 elseContent := string(g.SourceBytes[g.Location.ElseStart:g.Location.ElseEnd])
148 // Indent each line, preserving blank lines and original formatting
149 lines := strings.Split(elseContent, "\n")
150 for i, line := range lines {
151 g.Write("\t")
152 g.Write(line)
153 // Don't add extra newline after last line (already has it from split)
154 if i < len(lines)-1 || len(line) > 0 {
155 g.WriteByte('\n')
156 }
157 }
158 } else {
159 // Placeholder for when source bytes are not available (e.g., in unit tests)
160 g.Write("\t// GUARD_LET_ELSE_BLOCK\n")
161 g.Write("\treturn\n")
162 }
163}
164
165// generateBindings generates variable bindings for the success case.
166func (g *GuardGenerator) generateBindings(tmpVar string) {

Callers 1

generateCheckMethod · 0.95

Calls 2

WriteByteMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected