package languages import ( "bytes" "encoding/xml" "io" "path" "strings" "github.com/zzet/gortex/internal/graph" "github.com/zzet/gortex/internal/parser" ) // MyBatisExtractor indexes MyBatis mapper XML — the SQL-mapping layer of // a Java/MyBatis application. A mapper file binds a Java DAO/Mapper // interface (named by the `` FQCN) to a set of SQL // statements, one per `"), []byte(""), []byte(""), []byte(""), []byte(""), []byte(""), []byte(""), []byte(""), } { if i := bytes.Index(rest, ct); i >= 0 && (endRel < 0 || i < endRel) { endRel = i } } if endRel < 0 { endRel = len(rest) } body := rest[:endRel] return normaliseMyBatisSQL(body) } // normaliseMyBatisSQL strips nested XML tags from a statement body and // collapses whitespace so the stored SQL is a single readable string. func normaliseMyBatisSQL(body []byte) string { var out []byte depth := 0 // inside a nested <…> tag for i := 0; i < len(body); i++ { c := body[i] switch { case c == '<': depth++ case c == '>' && depth > 0: depth-- case depth == 0: out = append(out, c) } } return strings.Join(strings.Fields(string(out)), " ") }