librarymodel

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LatestStableKotlinVersion   = "2.2"
	LatestStableKSPVersion      = "2.2"
	LatestStableAGPVersion      = "8.13"
	LatestStableCompileSDK      = "36"
	LatestStableTargetSDK       = "36"
	LatestStableJavaVersion     = "21"
	LatestStableKotlinJvmTarget = "21"
)
View Source
const FingerprintVersion = 1

FingerprintVersion bumps the schema for Facts fingerprints. Bump this when adding fields whose absence would let stale cache entries silently apply.

Variables

This section is empty.

Functions

func FindVersionCatalogPathForGradlePath

func FindVersionCatalogPathForGradlePath(gradlePath string) (string, bool)

func FindVersionCatalogPathsForGradlePath

func FindVersionCatalogPathsForGradlePath(gradlePath string) ([]string, bool)

func ProjectProfileCacheDir

func ProjectProfileCacheDir(repoDir string) string

ProjectProfileCacheDir returns the repository-local cache root for Gradle library model profiles.

func SaveProjectProfileCache

func SaveProjectProfileCache(cacheDir string, paths []string, profile ProjectProfile) error

SaveProjectProfileCache persists the profile plus every discovered catalog input so warm runs can avoid repeating settings/build-logic discovery.

Types

type AndroidProfile

type AndroidProfile struct {
	AGP        VersionedPresence
	CompileSDK VersionedPresence
	TargetSDK  VersionedPresence
	MinSDK     VersionedPresence
}

func (AndroidProfile) EffectiveAGPVersion

func (a AndroidProfile) EffectiveAGPVersion() string

func (AndroidProfile) EffectiveCompileSDK

func (a AndroidProfile) EffectiveCompileSDK() string

func (AndroidProfile) EffectiveMinSDK

func (a AndroidProfile) EffectiveMinSDK() string

func (AndroidProfile) EffectiveTargetSDK

func (a AndroidProfile) EffectiveTargetSDK() string

type CatalogAliasKind

type CatalogAliasKind string
const (
	CatalogAliasPlugin  CatalogAliasKind = "plugin"
	CatalogAliasVersion CatalogAliasKind = "version"
	CatalogAliasLibrary CatalogAliasKind = "library"
	CatalogAliasBundle  CatalogAliasKind = "bundle"
)

type CatalogCompleteness

type CatalogCompleteness int
const (
	CatalogCompletenessNone CatalogCompleteness = iota
	CatalogCompletenessStandardTOML
	CatalogCompletenessMergedTOML
	CatalogCompletenessSettingsTOML
	CatalogCompletenessSettingsProgrammatic
)

type CatalogLibrary

type CatalogLibrary struct {
	Group   string
	Name    string
	Version string
}

type CatalogPlugin

type CatalogPlugin struct {
	ID      string
	Version string
}

type CatalogSource

type CatalogSource struct {
	Path string
	Kind CatalogSourceKind
}

func FindVersionCatalogSourcesForGradlePath

func FindVersionCatalogSourcesForGradlePath(gradlePath string) ([]CatalogSource, bool)

type CatalogSourceKind

type CatalogSourceKind string
const (
	CatalogSourceStandardTOML         CatalogSourceKind = "standard_toml"
	CatalogSourceMergedTOML           CatalogSourceKind = "merged_toml"
	CatalogSourceSettingsTOML         CatalogSourceKind = "settings_toml"
	CatalogSourceSettingsProgrammatic CatalogSourceKind = "settings_programmatic"
)

type Coordinate

type Coordinate struct {
	Group string
	Name  string
}

type DatabaseFacts

type DatabaseFacts struct {
	SQLite     SQLiteFacts
	Room       RoomFacts
	SQLDelight SQLDelightFacts
}

func (DatabaseFacts) IsSQLiteBlockingMethod

func (d DatabaseFacts) IsSQLiteBlockingMethod(name string) bool

type Dependency

type Dependency struct {
	Group         string
	Name          string
	Version       string
	Configuration string
	Source        string
}

Dependency is a normalized external library coordinate discovered from a target repository's build files.

type Facts

type Facts struct {
	Profile  ProjectProfile
	Database DatabaseFacts
	Java     JavaTypeProfile
}

Facts is the version/profile-aware semantic model consumed by rules.

func DefaultFacts

func DefaultFacts() *Facts

DefaultFacts returns conservative built-in facts for contexts where Krit has no project profile. This preserves behavior for single-file editor/LSP use and unit tests while allowing repository scans to narrow facts from Gradle.

func EnsureFacts

func EnsureFacts(facts *Facts) *Facts

func FactsForProfile

func FactsForProfile(profile ProjectProfile) *Facts

FactsForProfile builds library facts from a project profile.

func (*Facts) DatabaseFacts

func (f *Facts) DatabaseFacts() DatabaseFacts

func (*Facts) Fingerprint

func (f *Facts) Fingerprint() string

Fingerprint returns a stable hex digest of the semantic content of f. Callers use this as part of cache keys for project-level analysis whose findings depend on library facts (Android phase, library-aware Kotlin rules). nil and zero-value Facts are distinguished from non-empty Facts by the version prefix.

type JVMProfile

type JVMProfile struct {
	ToolchainLanguageVersion VersionedPresence
	SourceCompatibility      VersionedPresence
	TargetCompatibility      VersionedPresence
	KotlinJvmTarget          VersionedPresence
}

func (JVMProfile) EffectiveTargetBytecode

func (j JVMProfile) EffectiveTargetBytecode() string

type JavaKnownType

type JavaKnownType struct {
	FQN        string
	Supertypes []string
}

type JavaSourceProfile

type JavaSourceProfile struct {
	SourceRoots             []string
	TestSourceRoots         []string
	AndroidTestSourceRoots  []string
	GeneratedSourceRoots    []string
	ClasspathCandidates     []string
	BootClasspathCandidates []string
	ClasspathComplete       bool
}

func JavaSourceProfileFromGradleContent

func JavaSourceProfileFromGradleContent(path, content string, cfg *android.BuildConfig) JavaSourceProfile

func (JavaSourceProfile) JavacClasspathArg

func (p JavaSourceProfile) JavacClasspathArg() string

func (JavaSourceProfile) JavacClasspathCandidates

func (p JavaSourceProfile) JavacClasspathCandidates() []string

func (JavaSourceProfile) SourceRootsForScan

func (p JavaSourceProfile) SourceRootsForScan(includeTests, includeAndroidTests, includeGenerated bool) []string

type JavaTypeProfile

type JavaTypeProfile struct {
	KnownTypes        map[string]JavaKnownType
	MethodReturns     map[string]string
	AnnotationAliases map[string]string
}

func DefaultJavaTypeProfile

func DefaultJavaTypeProfile() JavaTypeProfile

func (JavaTypeProfile) AnnotationImplies

func (p JavaTypeProfile) AnnotationImplies(annotation, implied string) bool

func (JavaTypeProfile) IsKnownFrameworkType

func (p JavaTypeProfile) IsKnownFrameworkType(candidate string) bool

func (JavaTypeProfile) IsSubtypeCandidate

func (p JavaTypeProfile) IsSubtypeCandidate(supertype, candidate string) bool

func (JavaTypeProfile) MethodReturn

func (p JavaTypeProfile) MethodReturn(owner, method string, arity int) string

type KSPProfile

type KSPProfile struct {
	Tool       VersionedPresence
	Processors []Dependency
}

func (KSPProfile) EffectiveVersion

func (k KSPProfile) EffectiveVersion() string

type KotlinProfile

type KotlinProfile struct {
	Compiler        VersionedPresence
	LanguageVersion VersionedPresence
	APIVersion      VersionedPresence
	K2              Presence
}

func (KotlinProfile) EffectiveAPIVersion

func (k KotlinProfile) EffectiveAPIVersion() string

func (KotlinProfile) EffectiveCompilerVersion

func (k KotlinProfile) EffectiveCompilerVersion() string

func (KotlinProfile) EffectiveLanguageVersion

func (k KotlinProfile) EffectiveLanguageVersion() string

type Presence

type Presence int
const (
	PresenceUnknown Presence = iota
	PresenceAbsent
	PresencePresent
)

type ProjectProfile

type ProjectProfile struct {
	MinSdkVersion     int
	TargetSdkVersion  int
	CompileSdkVersion int

	Kotlin  KotlinProfile
	KSP     KSPProfile
	Android AndroidProfile
	JVM     JVMProfile
	Java    JavaSourceProfile

	Dependencies []Dependency

	CatalogSources      []CatalogSource
	CatalogCompleteness CatalogCompleteness

	UnresolvedCatalogAliases []UnresolvedCatalogAlias

	// HasGradle is true when at least one Gradle file was parsed.
	HasGradle bool
	// DependencyExtractionComplete is true only when parsed Gradle files use
	// dependency forms this lightweight parser can treat as a complete-enough
	// graph for absence decisions.
	DependencyExtractionComplete bool
	// HasUnresolvedDependencyRefs is true when a build file uses unresolved
	// aliases, convention plugins, apply-from scripts, or other dependency
	// forms this parser cannot resolve yet. In that case models stay
	// conservative.
	HasUnresolvedDependencyRefs bool
}

ProjectProfile contains project-wide library and platform facts. It is intentionally small: rules should consume derived Facts instead of parsing Gradle files or version catalogs themselves.

func LoadProjectProfileCache

func LoadProjectProfileCache(cacheDir string, paths []string) (ProjectProfile, bool)

LoadProjectProfileCache loads a profile only when all known Gradle/catalog inputs still match. New standard catalog or settings files in ancestor dirs also change the fingerprint and force a miss.

func ProfileFromBuildConfig

func ProfileFromBuildConfig(source string, cfg *android.BuildConfig) ProjectProfile

ProfileFromBuildConfig converts an android.BuildConfig into a library profile fragment.

func ProfileFromGradleContent

func ProfileFromGradleContent(path, content string) ProjectProfile

ProfileFromGradleContent parses one Gradle file into a profile fragment.

func ProfileFromGradleContentWithCatalog

func ProfileFromGradleContentWithCatalog(path, content string, catalog VersionCatalog) ProjectProfile

func ProfileFromGradlePaths

func ProfileFromGradlePaths(paths []string) ProjectProfile

ProfileFromGradlePaths reads Gradle build files and returns a merged project profile. Unreadable or unparsable files are ignored so library models remain best-effort and never block analysis.

func (ProjectProfile) HasAnyDependency

func (p ProjectProfile) HasAnyDependency(coords ...Coordinate) bool

func (ProjectProfile) HasDependency

func (p ProjectProfile) HasDependency(group, name string) bool

func (ProjectProfile) HasDependencyGroup

func (p ProjectProfile) HasDependencyGroup(group string) bool

func (ProjectProfile) MayUseAnyDependency

func (p ProjectProfile) MayUseAnyDependency(coords ...Coordinate) bool

func (*ProjectProfile) Merge

func (p *ProjectProfile) Merge(other ProjectProfile)

Merge adds another profile fragment into p.

func (ProjectProfile) ProvesDependencyAbsent

func (p ProjectProfile) ProvesDependencyAbsent(coords ...Coordinate) bool

ProvesDependencyAbsent returns true only when the parsed dependency graph is complete enough to use absence as evidence. Unknown or partial profiles stay conservative.

type RoomFacts

type RoomFacts struct {
	Enabled              bool
	DaoAnnotations       []string
	OperationAnnotations []string
	AsyncReturnTypeHints []string
	LoadAllMethodNames   []string
	LoadOneTerminalNames []string
	QueryAnnotationNames []string
}

func (RoomFacts) HasDaoAnnotation

func (r RoomFacts) HasDaoAnnotation(name string) bool

func (RoomFacts) HasOperationAnnotation

func (r RoomFacts) HasOperationAnnotation(name string) bool

func (RoomFacts) HasQueryAnnotation

func (r RoomFacts) HasQueryAnnotation(name string) bool

func (RoomFacts) IsAsyncReturnType

func (r RoomFacts) IsAsyncReturnType(header string) bool

func (RoomFacts) IsLoadAllMethod

func (r RoomFacts) IsLoadAllMethod(name string) bool

func (RoomFacts) IsLoadOneTerminal

func (r RoomFacts) IsLoadOneTerminal(name string) bool

type SQLDelightFacts

type SQLDelightFacts struct {
	Enabled                  bool
	BlockingExecutionMethods []string
}

func (SQLDelightFacts) IsBlockingExecutionMethod

func (s SQLDelightFacts) IsBlockingExecutionMethod(name string) bool

type SQLiteFacts

type SQLiteFacts struct {
	BlockingMethods []string
}

type UnresolvedCatalogAlias

type UnresolvedCatalogAlias struct {
	Kind   CatalogAliasKind
	Alias  string
	Source string
}

type VersionCatalog

type VersionCatalog struct {
	Versions  map[string]string
	Plugins   map[string]CatalogPlugin
	Libraries map[string]CatalogLibrary
	Bundles   map[string][]string

	Sources      []CatalogSource
	Completeness CatalogCompleteness
}

VersionCatalog is a best-effort Gradle version-catalog model. It is not a general TOML or Gradle evaluator; it intentionally supports the catalog forms needed by the library model and records source/completeness metadata so callers can stay conservative when discovery is partial.

func LoadVersionCatalogForGradlePath

func LoadVersionCatalogForGradlePath(gradlePath string) (VersionCatalog, bool)

func ParseSettingsVersionCatalogContent

func ParseSettingsVersionCatalogContent(content string) VersionCatalog

func ParseVersionCatalogContent

func ParseVersionCatalogContent(content string) VersionCatalog

func (VersionCatalog) Empty

func (c VersionCatalog) Empty() bool

func (*VersionCatalog) Merge

func (c *VersionCatalog) Merge(other VersionCatalog)

func (VersionCatalog) PluginByIDOrAlias

func (c VersionCatalog) PluginByIDOrAlias(idOrAlias string) (CatalogPlugin, bool)

type VersionPolicy

type VersionPolicy int
const (
	VersionUnknown VersionPolicy = iota
	VersionKnown
	VersionAssumeLatestStable
)

type VersionedPresence

type VersionedPresence struct {
	Presence      Presence
	Version       string
	VersionPolicy VersionPolicy
}

func KnownVersion

func KnownVersion(version string) VersionedPresence

func PresentAssumeLatestStable

func PresentAssumeLatestStable() VersionedPresence

func (VersionedPresence) EffectiveVersion

func (v VersionedPresence) EffectiveVersion(latestStable string) string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL