Documentation
¶
Overview ¶
Package gen contains the logic for generating the source code
Index ¶
- func FactoryName(typeName *types.Named) string
- func ProviderName(typeName *types.Named) string
- func SanitizeName(name *types.Named) string
- type Assignment
- func AssignmentForFieldType(componentReceiverName string, rawFieldType types.Type, ...) (Assignment, error)
- func NewFactoryAssignment(componentReceiverName string, typeName *types.Named) Assignment
- func NewProviderAssignment(componentReceiverName string, typeName *types.Named, castTo *types.Named) Assignment
- type GeneratedComponent
- type GeneratedFactory
- type GeneratedModuleProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FactoryName ¶
FactoryName returns the name of the factory function for the given name
func ProviderName ¶
ProviderName returns the name of the provider function for the given name
func SanitizeName ¶
SanitizeName returns a name that can be used as a Go identifier from the given name. The generated identifier should not clash with any other types.Named, unless the underlying named object is the same
Types ¶
type Assignment ¶
type Assignment interface { // CastTo returns the type this assignment should be cast to. If nil is returned, then // the assignment is not cast to any type. CastTo() *types.Named // GetSourceAssignment returns the assignment as a string of source code. GetSourceAssignment() string }
Assignment represents a way of getting a injected value, either by a provider or by an injectable factory method
func AssignmentForFieldType ¶
func AssignmentForFieldType( componentReceiverName string, rawFieldType types.Type, providers map[string]resolver.ResolvedType, bindings map[string]*types.Named, ) (Assignment, error)
AssignmentForFieldType returns an assignment for the given field type
func NewFactoryAssignment ¶
func NewFactoryAssignment( componentReceiverName string, typeName *types.Named, ) Assignment
NewFactoryAssignment returns a factory-method based assignment
func NewProviderAssignment ¶
func NewProviderAssignment( componentReceiverName string, typeName *types.Named, castTo *types.Named, ) Assignment
NewProviderAssignment returns a component provided assignment
type GeneratedComponent ¶
type GeneratedComponent struct {
// contains filtered or unexported fields
}
GeneratedComponent is the resolve of GenerateComponent and contains helper methods for converting this directly into source
func NewGeneratedComponent ¶
func NewGeneratedComponent( componentName string, targets []*resolver.InjectionTarget, providers map[string]resolver.ResolvedType, bindings map[string]*types.Named, ) (*GeneratedComponent, error)
NewGeneratedComponent generates the source for the given component
type GeneratedFactory ¶
type GeneratedFactory struct {
// contains filtered or unexported fields
}
GeneratedFactory contains information for generating a factory for an injected struct
The generated code from this factory looks something like this:
func TargetFactory(component *GeneratedComponent) *TargetType { target := &TargetType{} targetType.ProvidedType = component.provides_ProvidedType() targetType.InjectableType = InjectableFactory(component) return target }
func NewGeneratedFactoryIfNeeded ¶
func NewGeneratedFactoryIfNeeded( generatedComponentType string, generatedComponentReceiver string, targetName *types.Named, targetStruct *types.Struct, providers map[string]resolver.ResolvedType, bindings map[string]*types.Named, ) (*GeneratedFactory, error)
NewGeneratedFactoryIfNeeded generates a factory for the given struct. If a factory cannot be generated, e.g. if the struct is not injectable, nil is returned
func (*GeneratedFactory) ToSource ¶
func (g *GeneratedFactory) ToSource(componentPackage string) string
ToSource converts this generated factory into Go source code. The source should be treated as a separate source file in the generated component package
type GeneratedModuleProvider ¶
type GeneratedModuleProvider struct {
// contains filtered or unexported fields
}
GeneratedModuleProvider is a single generated provider method on the component from a module source
func NewGeneratedProvider ¶
func NewGeneratedProvider( generatedComponentType string, generatedComponentReceiver string, resolvedType *resolver.ModuleResolvedType, providers map[string]resolver.ResolvedType, bindings map[string]*types.Named, ) (*GeneratedModuleProvider, error)
NewGeneratedProvider generates a provider function for the given resolved type The generated function has the form:
func (generatedComponent *GeneratedComponent) provides_Name() *SomeType { return someModule.providerFunc( component.provides_ProvidedType(), InjectableFactory(component), ) }
func (*GeneratedModuleProvider) ToSource ¶
func (g *GeneratedModuleProvider) ToSource(componentPackage string) string
ToSource returns the source code for this provider.