Rename Evaluate() to Get() and add GetDefault()

Part of the design of property structs is that they were easy to access.
In keeping with that spirit, use a shorter and easier to spell name
for the getter, and add GetDefault() so that you don't need to pass
the result of Get() to one of the
proptools.StringDefault/BoolDefault/etc functions.

Bug: 323382414
Test: m nothing --no-skip-soong-tests
Change-Id: Ib9a69dcf2ab56a758935a461f37fe46bc0e17e27
This commit is contained in:
Cole Faust 2024-04-04 10:53:07 -07:00
parent 2437d5edb9
commit 09fe90e407

View file

@ -83,33 +83,34 @@ type appendWrapper[T ConfigurableElements] struct {
replace bool
}
func (c *Configurable[T]) GetType() parser.SelectType {
return c.typ
}
func (c *Configurable[T]) GetCondition() string {
return c.condition
}
// Evaluate returns the final value for the configurable property.
// A configurable property may be unset, in which case Evaluate will return nil.
func (c *Configurable[T]) Evaluate(evaluator ConfigurableEvaluator) *T {
// Get returns the final value for the configurable property.
// A configurable property may be unset, in which case Get will return nil.
func (c *Configurable[T]) Get(evaluator ConfigurableEvaluator) *T {
if c == nil || c.appendWrapper == nil {
return nil
}
if c.appendWrapper.replace {
return replaceConfiguredValues(
c.evaluateNonTransitive(evaluator),
c.appendWrapper.append.Evaluate(evaluator),
c.appendWrapper.append.Get(evaluator),
)
} else {
return appendConfiguredValues(
c.evaluateNonTransitive(evaluator),
c.appendWrapper.append.Evaluate(evaluator),
c.appendWrapper.append.Get(evaluator),
)
}
}
// GetOrDefault is the same as Get, but will return the provided default value if the property was unset.
func (c *Configurable[T]) GetOrDefault(evaluator ConfigurableEvaluator, defaultValue T) T {
result := c.Get(evaluator)
if result != nil {
return *result
}
return defaultValue
}
func (c *Configurable[T]) evaluateNonTransitive(evaluator ConfigurableEvaluator) *T {
if c.typ == parser.SelectTypeUnconfigured {
if len(c.cases) == 0 {