MCPcopy Create free account
hub / github.com/apache/fory / generateCompileGuard

Function generateCompileGuard

go/fory/codegen/guard.go:31–46  ·  view source on GitHub ↗

generateCompileGuard generates compile-time checks to ensure struct definitions haven't changed since code generation. If a struct is modified, users must re-run go generate or compilation will fail.

(structs []StructInfo)

Source from the content-addressed store, hash-verified

29// haven't changed since code generation. If a struct is modified, users must
30// re-run go generate or compilation will fail.
31func generateCompileGuard(structs []StructInfo) string {
32 if len(structs) == 0 {
33 return ""
34 }
35
36 var buf bytes.Buffer
37
38 buf.WriteString("\n// Compile-time guards: These ensure struct definitions haven't changed\n")
39 buf.WriteString("// since code generation. If you modify structs, re-run go generate.\n\n")
40
41 for _, structInfo := range structs {
42 generateStructGuard(&buf, structInfo)
43 }
44
45 return buf.String()
46}
47
48func generateStructGuard(buf *bytes.Buffer, structInfo StructInfo) {
49 typeName := structInfo.Name

Callers 2

generateCodeForFileFunction · 0.85
generateCodeFunction · 0.85

Calls 3

generateStructGuardFunction · 0.85
WriteStringMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected