Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

58 lines
2.1 KiB
Go

package contracts
import (
"github.com/zzet/gortex/internal/graph"
"github.com/zzet/gortex/internal/parser"
)
// Extractor analyses source files and produces Contract values.
type Extractor interface {
// Extract scans the source of a single file and returns any contracts found.
// nodes and edges provide graph context so the extractor can resolve the
// nearest enclosing symbol for each match.
Extract(filePath string, src []byte, nodes []*graph.Node, edges []*graph.Edge) []Contract
// SupportedLanguages returns the set of languages this extractor handles.
SupportedLanguages() []string
}
// TreeAwareExtractor is an optional capability extractors implement
// when they want to consume the file's tree-sitter parse tree (for
// AST-based handler-body enrichment) instead of regex over source
// bytes. The orchestrator type-asserts and dispatches to ExtractWithTree
// when both the extractor and the parse tree are available.
//
// Phase 1 of spec-contract-extraction.md ships only HTTPExtractor as
// tree-aware. Other extractors fall back to Extract() unchanged.
type TreeAwareExtractor interface {
Extractor
ExtractWithTree(
filePath string,
src []byte,
nodes []*graph.Node,
edges []*graph.Edge,
tree *parser.ParseTree,
) []Contract
}
// StoreAwareExtractor is an optional capability an extractor implements when it
// can resolve constant / composite endpoint arguments graph-wide using the
// graph's constant store. The orchestrator type-asserts and dispatches to
// ExtractWithStore — in preference to ExtractWithTree / Extract — passing the
// store and the repo prefix so the extractor can scope graph-wide const
// lookups. A nil store is allowed (const dereference is then disabled and the
// extractor behaves like its tree-aware path). Extractors that don't implement
// it fall back to ExtractWithTree / Extract unchanged.
type StoreAwareExtractor interface {
Extractor
ExtractWithStore(
filePath string,
src []byte,
nodes []*graph.Node,
edges []*graph.Edge,
tree *parser.ParseTree,
store EndpointConstStore,
repoPrefix string,
) []Contract
}