Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7df7fb0d authored by Paul Duffin's avatar Paul Duffin
Browse files

Improve documentation of defaults mechanism

Also, removes unnecessary cast from DefaultableModule to Defaultable.

Bug: 130796911
Test: m nothing
Change-Id: I01d8f5186927215a1aa6b7431558041f427d7381
parent 8f7a3fc6
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -42,9 +42,16 @@ func (d *DefaultableModuleBase) setProperties(props []interface{}) {
	d.defaultableProperties = props
}

// Interface that must be supported by any module to which defaults can be applied.
type Defaultable interface {
	// Get a pointer to the struct containing the Defaults property.
	defaults() *defaultsProperties

	// Set the property structures into which defaults will be added.
	setProperties([]interface{})

	// Apply defaults from the supplied Defaults to the property structures supplied to
	// setProperties(...).
	applyDefaults(TopDownMutatorContext, []Defaults)
}

@@ -56,7 +63,7 @@ type DefaultableModule interface {
var _ Defaultable = (*DefaultableModuleBase)(nil)

func InitDefaultableModule(module DefaultableModule) {
	module.(Defaultable).setProperties(module.(Module).GetProperties())
	module.setProperties(module.(Module).GetProperties())

	module.AddProperties(module.defaults())
}
@@ -87,7 +94,12 @@ type DefaultsModuleBase struct {
// rather than disabling the defaults module itself.
type Defaults interface {
	Defaultable

	// Although this function is unused it is actually needed to ensure that only modules that embed
	// DefaultsModuleBase will type-assert to the Defaults interface.
	isDefaults() bool

	// Get the structures containing the properties for which defaults can be provided.
	properties() []interface{}
}

@@ -111,6 +123,7 @@ func InitDefaultsModule(module DefaultableModule) {
	InitArchModule(module)
	InitDefaultableModule(module)

	// Add properties that will not have defaults applied to them.
	module.AddProperties(&module.base().nameProperties)

	module.base().module = module