Documentation
¶
Index ¶
- Constants
- func ExpectedPackage(filePath string, sourceRoot string) string
- func FormatSurface(entries []APIEntry) string
- func HashAbiSignatures(sigs []AbiSignature) string
- func ImportBreadth(file *scanner.File) int
- func SymbolFanIn(index *scanner.CodeIndex) map[string]int
- type APIDiff
- type APIEntry
- type AbiParam
- type AbiSignature
- type BroadFile
- type Drift
- type Hotspot
- type Layer
- type LayerConfig
- type LayerViolation
- type LeakyClass
Constants ¶
const ( ChangeAdded = "added" ChangeRemoved = "removed" )
APIChange values for APIDiff.Change.
const AbiHashVersion uint32 = 1
AbiHashVersion is mixed into the hash input. Bump when the canonical signature encoding changes so consumers invalidate cached hashes on krit upgrade.
Variables ¶
This section is empty.
Functions ¶
func ExpectedPackage ¶
ExpectedPackage derives the expected Kotlin/Java package name from a file's path relative to a source root. For example:
filePath="/project/app/src/main/kotlin/com/example/feature/Foo.kt" sourceRoot="/project/app/src/main/kotlin" returns "com.example.feature"
func FormatSurface ¶
FormatSurface produces a deterministic text representation of an API surface. Entries should already be sorted (ExtractSurface guarantees this); if passed arbitrary input, callers should sort first.
func HashAbiSignatures ¶
func HashAbiSignatures(sigs []AbiSignature) string
HashAbiSignatures returns the 16-character hex hash described in the abi-hash spec (first 8 bytes of SHA-256 over the canonical form, salted by AbiHashVersion).
func ImportBreadth ¶
ImportBreadth counts the number of distinct packages imported by a file. It parses the file's Lines for "import" declarations and extracts parent packages.
Types ¶
type APIDiff ¶
APIDiff represents a change between two API surfaces.
func DiffSurfaces ¶
DiffSurfaces compares old and new API surfaces, returning additions and removals.
type APIEntry ¶
type APIEntry struct {
Kind string // "class", "interface", "object", "function", "property"
Name string // fully qualified or simple name
Signature string // e.g., "fun getUser(id: String): User"
File string
Line int
}
APIEntry represents a single public API element.
func ExtractSurface ¶
ExtractSurface extracts the public API surface from parsed files. Returns public/protected declarations sorted by kind+name for determinism.
func ParseSurface ¶
ParseSurface parses a text surface (produced by FormatSurface) back into entries.
type AbiParam ¶
AbiParam captures parameter type and default-presence; names and default values are intentionally excluded.
type AbiSignature ¶
type AbiSignature struct {
Kind string // class | interface | object | function | property
FQN string // package + container chain + name
Modifiers []string // sorted, ABI-relevant modifiers only
TypeParams []string // raw text per type parameter, in declaration order
Params []AbiParam
ReturnType string
Annotations []string // sorted, allowlisted annotation names only
}
AbiSignature is one declaration's normalized contribution to the ABI.
func ExtractAbiSignatures ¶
func ExtractAbiSignatures(files []*scanner.File) []AbiSignature
ExtractAbiSignatures walks the public/protected declarations in files and returns deterministic, name-keyed signature records.
type Drift ¶
Drift represents a mismatch between a file's declared package and its expected package.
type Hotspot ¶
type Hotspot struct {
Name string
Kind string // "class", "function", etc.
FanIn int // count of distinct files referencing this symbol
File string
Line int
}
Hotspot represents a symbol with high fan-in.
type LayerConfig ¶
type LayerConfig struct {
Layers []Layer
Allowed map[string][]string // layer name -> allowed dependency layers
}
LayerConfig holds the full layer dependency configuration.
func ParseLayerConfig ¶
func ParseLayerConfig(cfg *config.Config) *LayerConfig
ParseLayerConfig extracts layer configuration from a krit Config. The config structure is nested under architecture.LayerDependencyViolation. Returns nil if no layer config is present.
func (*LayerConfig) LayerForModule ¶
func (lc *LayerConfig) LayerForModule(modulePath string) string
LayerForModule returns the layer name for a given module path, or "" if the module doesn't match any layer.
type LayerViolation ¶
type LayerViolation struct {
SourceModule string
TargetModule string
SourceLayer string
TargetLayer string
}
LayerViolation represents a dependency that crosses an unauthorized layer boundary.
func ValidateLayers ¶
func ValidateLayers(cfg *LayerConfig, graph *module.Graph) []LayerViolation
ValidateLayers checks all module dependencies against the layer config. Returns violations where a module in one layer depends on a module in a layer that is not in the allowed list.
type LeakyClass ¶
type LeakyClass struct {
ClassName string
WrappedType string
Line int
DelegationRatio float64 // 0.0-1.0, fraction of methods that delegate
TotalMethods int
DelegatingMethods int
}
LeakyClass represents a public class that appears to be a thin wrapper.
func DetectLeakyAbstractions ¶
func DetectLeakyAbstractions(lines []string, threshold float64) []LeakyClass
DetectLeakyAbstractions scans a file for public classes that are thin wrappers delegating to a single private/internal field.
Heuristic: 1. Find public class declarations with a single constructor parameter 2. Check if the parameter is stored as a private/internal property 3. Count public methods that are single-expression delegations to that property 4. If delegation ratio > threshold, flag as leaky