scalarule

package
v0.0.0-...-2e562ea Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Rel is the relative directory of this rule config
	Rel string
	// Config is the parent gazelle Config
	Config *config.Config
	// Deps is a mapping from label to +/- intent.
	Deps map[string]bool
	// Attr is a mapping from string to intent map.
	Attrs map[string]map[string]bool
	// Options is a generic key -> value string mapping.  Various rule
	// implementations are free to document/interpret options in an
	// implementation-dependenct manner.
	Options map[string]bool
	// Enabled is a flag that marks language generation as enabled or not
	Enabled bool
	// Implementation is the registry identifier for the provider
	Implementation string
	// Provider is the actual implementation
	Provider Provider
	// Name is the name of the Rule config
	Name string
}

Config carries metadata about a rule and its dependencies.

func NewConfig

func NewConfig(config *config.Config, name string) *Config

NewConfig returns a pointer to a new Config config with the 'Enabled' bit set to true.

func (*Config) Clone

func (c *Config) Clone() *Config

Clone copies this config to a new one

func (*Config) GetAttr

func (c *Config) GetAttr(name string) []string

GetAttr returns the positive-intent attr values under the given key.

func (*Config) GetDeps

func (c *Config) GetDeps() []string

GetDeps returns the sorted list of dependencies

func (*Config) GetOptions

func (c *Config) GetOptions() []string

GetOptions returns the rule options.

func (*Config) ParseDirective

func (c *Config) ParseDirective(d, param, value string) error

ParseDirective parses the directive string or returns error.

type Package

type Package interface {
	// ParseRule parses the given rule from the named attr (typically 'srcs').
	ParseRule(r *grule.Rule, attrName string) (Rule, error)
}

Package is responsible for instantiating a Rule interface for the given gazelle.Rule, parsing the attribute name given (typically 'srcs').

type Provider

type Provider interface {
	// Name returns the name of the rule
	Name() string
	// LoadInfo returns the gazelle LoadInfo.
	LoadInfo() grule.LoadInfo
	// KindInfo returns the gazelle KindInfo.
	KindInfo() grule.KindInfo
	// ProvideRule takes the given configuration and compilation and emits a
	// RuleProvider.  If the state of the ScalaConfiguration is such that the
	// rule should not be emitted, implementation should return nil.
	ProvideRule(rc *Config, pkg Package) RuleProvider
}

Provider is factory pattern capable of taking a config and package and returning a Provider.

type ProviderRegistry

type ProviderRegistry interface {
	// ProviderNames returns a sorted list of rule names.
	ProviderNames() []string
	// LookupProvider returns the implementation under the given name.  If the
	// rule is not found, false is returned.
	LookupProvider(name string) (Provider, bool)
	// RegisterProvider installs a Provider implementation under the given name
	// in the global rule registry.  Error will occur if the same rule is
	// registered multiple times.
	RegisterProvider(name string, provider Provider) error
}

ProviderRegistry represents a library of rule provider implementations.

func GlobalProviderRegistry

func GlobalProviderRegistry() ProviderRegistry

GlobalProviderRegistry returns a reference to the global ProviderRegistry implementation.

type ProviderRegistryMap

type ProviderRegistryMap struct {
	// contains filtered or unexported fields
}

ProviderRegistryMap implements ProviderRegistry using a map.

func NewProviderRegistryMap

func NewProviderRegistryMap() *ProviderRegistryMap

func (*ProviderRegistryMap) LookupProvider

func (p *ProviderRegistryMap) LookupProvider(name string) (Provider, bool)

LookupProvider implements part of the RuleRegistry interface.

func (*ProviderRegistryMap) ProviderNames

func (p *ProviderRegistryMap) ProviderNames() []string

ProviderNames implements part of the ProviderRegistry interface.

func (*ProviderRegistryMap) RegisterProvider

func (p *ProviderRegistryMap) RegisterProvider(name string, provider Provider) error

RegisterProvider implements part of the ProviderRegistry interface.

type ResolveContext

type ResolveContext struct {
	Config    *config.Config
	RuleIndex *resolve.RuleIndex
	Rule      *rule.Rule
	From      label.Label
}

ResolveContext carries context about a rule during rule provider import resolution.

type Rule

type Rule interface {
	// Exports returns the list of provided symbols that are importable by other
	// rules.
	Provides() []resolve.ImportSpec
	// Import returns the list of required imports for the rule.
	Imports() resolver.ImportMap
	// Import returns the list of required exports for the rule.
	Exports() resolver.ImportMap
}

Rule represents a collection of files with their imports and exports.

type RuleProvider

type RuleProvider interface {
	// Kind of rule e.g. 'scala_library'
	Kind() string
	// Name of the rule.
	Name() string
	// Rule provides the gazelle rule implementation.
	Rule() *rule.Rule
	// Resolve performs deps resolution, similar to the gazelle Resolver
	// interface.
	Resolve(ctx *ResolveContext, importsRaw interface{})
	// Imports implements part of the resolve.Resolver interface.
	Imports(c *config.Config, r *rule.Rule, file *rule.File) []resolve.ImportSpec
}

RuleProvider implementations are capable of providing a rule and import list to the gazelle GenerateArgs response.

type RuleResolver

type RuleResolver interface {
	// ResolveRule takes the given configuration emits a RuleProvider. If the
	// state of the package is such that the rule should not managed, return nil.
	ResolveRule(rc *Config, pkg Package, existing *rule.Rule) RuleProvider
}

RuleResolver is an optional interface for a RuleInfo implementation. This is a mechanism for rule implementations to only modify an existing rule rather than having to create one from scratch.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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