aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCole Faust <colefaust@google.com>2024-04-04 10:53:07 -0700
committerCole Faust <colefaust@google.com>2024-04-04 14:46:15 -0700
commit09fe90e407fcc2ac93b1641792cff5c95d2f8318 (patch)
tree3ea39e04b4a1874384ac9aff776463cf12fc0bb8
parent2437d5edb9d20f0de4b90eabcac2f43030b7da10 (diff)
downloadblueprint-09fe90e407fcc2ac93b1641792cff5c95d2f8318.tar.gz
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
-rw-r--r--proptools/configurable.go27
1 files changed, 14 insertions, 13 deletions
diff --git a/proptools/configurable.go b/proptools/configurable.go
index b42afc7..6d88fae 100644
--- a/proptools/configurable.go
+++ b/proptools/configurable.go
@@ -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 {