Documentation
¶
Overview ¶
Package base frontend.go provides shared helpers for frontend component detectors (Angular, React, Vue). Mirrors the Java FrontendDetectorHelper.
Anchor helpers — Plan §1.2 follow-on.
Many regex detectors emit cross-file "imports" / "depends_on" edges using the source file path and the imported name as endpoints. Both endpoints were free-form strings with no matching CodeNode, so every such edge got dropped at GraphBuilder.Snapshot's phantom filter.
EnsureFileAnchor and EnsureExternalAnchor materialize anchor nodes so the edges survive. The GraphBuilder dedup map collapses the per-file and per-external nodes across files at zero extra cost (every Python file importing "requests" gets one shared py:external:requests node).
Package base provides shared helpers for detector implementations. Mirrors the Java Abstract* detector hierarchy collapsed for tree-sitter.
Package base structured.go provides shared helpers for structured-data detectors (YAML / JSON / TOML / INI / properties). Mirrors the Java AbstractStructuredDetector helpers.
Index ¶
- Constants
- func AddKeyNode(fileID, fp, key, format string, ctx *detector.Context, ...)
- func AsMap(obj any) map[string]any
- func BuildFileNode(ctx *detector.Context, format string) *model.CodeNode
- func CreateComponentNode(framework, filePath, idType, name string, kind model.NodeKind, line int) *model.CodeNode
- func EnsureExternalAnchor(name, idPrefix, detectorName string, conf model.Confidence, ...) string
- func EnsureFileAnchor(ctx *detector.Context, langPrefix, detectorName string, conf model.Confidence, ...) string
- func FileName(path string) string
- func FindAllByType(root *sitter.Node, t string) []*sitter.Node
- func FindFirstByType(root *sitter.Node, t string) *sitter.Node
- func FindLineNumber(text string, offset int) int
- func GetList(container any, key string) []any
- func GetMap(container any, key string) map[string]any
- func GetString(container any, key string) string
- func GetStringOrDefault(container any, key, fallback string) string
- func LineAt(text string, offset int) int
- func Walk(root *sitter.Node, visit func(*sitter.Node) bool)
Constants ¶
const RegexDetectorDefaultConfidence = model.ConfidenceLexical
RegexDetectorDefaultConfidence is the floor for regex-only detectors. Java equivalent: AbstractRegexDetector.defaultConfidence() = LEXICAL.
const StructuredDetectorDefaultConfidence = model.ConfidenceSyntactic
StructuredDetectorDefaultConfidence is the floor for structured detectors. Structured parsing produces a parsed shape, not just a regex match, so the confidence floor is SYNTACTIC (matches Java AbstractStructuredDetector.defaultConfidence()).
const TreeSitterDetectorDefaultConfidence = model.ConfidenceSyntactic
TreeSitterDetectorDefaultConfidence is the floor for AST-backed detectors. Java equivalent: AbstractJavaParserDetector.defaultConfidence() = SYNTACTIC.
Variables ¶
This section is empty.
Functions ¶
func AddKeyNode ¶
func AddKeyNode(fileID, fp, key, format string, ctx *detector.Context, nodes *[]*model.CodeNode, edges *[]*model.CodeEdge)
AddKeyNode appends a CONFIG_KEY node and a CONTAINS edge from fileID to it. Mirrors Java addKeyNode.
func AsMap ¶
AsMap returns obj coerced to map[string]any. Returns nil when obj is nil or not a map. Used by structured detectors to navigate parsed data.
func BuildFileNode ¶
BuildFileNode constructs a CONFIG_FILE node for ctx's file. Mirrors the Java buildFileNode helper; callers append the returned node themselves.
func CreateComponentNode ¶
func CreateComponentNode(framework, filePath, idType, name string, kind model.NodeKind, line int) *model.CodeNode
CreateComponentNode constructs a frontend component / hook / service node with the standard fields populated. Equivalent to Java FrontendDetectorHelper.createComponentNode.
framework e.g. "angular", "react", "vue"
filePath source file path (forward-slash, relative to repo root)
idType namespace segment for the ID ("component", "hook", "service")
name component / class / function name
kind model.NodeComponent | NodeHook | NodeMiddleware
line 1-based line number
func EnsureExternalAnchor ¶
func EnsureExternalAnchor(name, idPrefix, detectorName string, conf model.Confidence, nodes *[]*model.CodeNode, seen map[string]bool) string
EnsureExternalAnchor returns the canonical ID of an external module / package / image target and appends it to nodes once per unique name. idPrefix scopes the namespace ("py:external", "rust:external", "docker:image", etc.).
func EnsureFileAnchor ¶
func EnsureFileAnchor(ctx *detector.Context, langPrefix, detectorName string, conf model.Confidence, nodes *[]*model.CodeNode, seen map[string]bool) string
EnsureFileAnchor returns the canonical ID of the file-as-module anchor node for ctx.FilePath and appends the node to nodes once. Caller must pass the same `seen` map across invocations within a single detector run (or nil for one-shot calls).
langPrefix scopes the anchor namespace ("py" for Python, "ts" for TypeScript, etc.) so cross-language detectors don't collide on the same path.
Detector source/confidence are stamped onto the anchor — pick a confidence that's at-or-below the actual emission detector so the merge rule (higher wins) doesn't accidentally demote a high-confidence emission later.
func FileName ¶
FileName extracts just the filename component of a path (after the last '/' or '\\'). Mirrors Java AbstractRegexDetector.fileName().
func FindAllByType ¶
FindAllByType returns every descendant whose type matches t (pre-order DFS).
func FindFirstByType ¶
FindFirstByType returns the first descendant whose type matches t (pre-order DFS). Returns nil when not found.
func FindLineNumber ¶
FindLineNumber returns the 1-based line number for a character offset in text. Offsets past the end clamp to the last line; empty input returns 1. Mirrors Java's findLineNumber helper used throughout the regex detectors.
func GetList ¶
GetList returns the nested list at key in container. Returns nil when key is missing or the value is not a list.
func GetMap ¶
GetMap returns the nested map at key in container. Returns nil when key is missing or the value is not a map.
func GetString ¶
GetString returns the string at key in container. Returns "" when the key is missing or the value is not a string.
func GetStringOrDefault ¶
GetStringOrDefault returns the string at key or fallback when missing or non-string.
Types ¶
This section is empty.