mirror of https://github.com/sbt/sbt.git
Avoid wrapping KeyedInitialize in GetValue
This commit is contained in:
parent
f997553a89
commit
b63aa36601
|
|
@ -40,7 +40,10 @@ abstract class EvaluateSettings[ScopeType]:
|
||||||
private val transform: [A] => Initialize[A] => INode[A] = [A] =>
|
private val transform: [A] => Initialize[A] => INode[A] = [A] =>
|
||||||
(fa: Initialize[A]) =>
|
(fa: Initialize[A]) =>
|
||||||
fa match
|
fa match
|
||||||
case k: Keyed[s, A] => single(getStatic(k.scopedKey), k.transform)
|
case g: GetValue[s, A] => single(getStatic(g.scopedKey), g.transform)
|
||||||
|
case k: KeyedInitialize[A] =>
|
||||||
|
// TODO create a Single node with no transform?
|
||||||
|
single(getStatic(k.scopedKey), identity)
|
||||||
case u: Uniform[s, A] => UniformNode(u.inputs.map(transform[s]), u.f)
|
case u: Uniform[s, A] => UniformNode(u.inputs.map(transform[s]), u.f)
|
||||||
case a: Apply[k, A] =>
|
case a: Apply[k, A] =>
|
||||||
MixedNode[k, A](TupleMapExtension.transform(a.inputs)(transform), a.f)
|
MixedNode[k, A](TupleMapExtension.transform(a.inputs)(transform), a.f)
|
||||||
|
|
|
||||||
|
|
@ -811,9 +811,13 @@ trait Init[ScopeType]:
|
||||||
*/
|
*/
|
||||||
sealed trait Keyed[S, A1] extends Initialize[A1]:
|
sealed trait Keyed[S, A1] extends Initialize[A1]:
|
||||||
def scopedKey: ScopedKey[S]
|
def scopedKey: ScopedKey[S]
|
||||||
def transform: S => A1
|
|
||||||
|
|
||||||
override final def dependencies = scopedKey :: Nil
|
override final def dependencies = scopedKey :: Nil
|
||||||
|
private[sbt] override def processAttributes[A2](init: A2)(f: (A2, AttributeMap) => A2): A2 =
|
||||||
|
init
|
||||||
|
end Keyed
|
||||||
|
|
||||||
|
final class GetValue[S, A1](val scopedKey: ScopedKey[S], val transform: S => A1)
|
||||||
|
extends Keyed[S, A1]:
|
||||||
override final def apply[A2](g: A1 => A2): Initialize[A2] =
|
override final def apply[A2](g: A1 => A2): Initialize[A2] =
|
||||||
GetValue(scopedKey, g compose transform)
|
GetValue(scopedKey, g compose transform)
|
||||||
override final def evaluate(ss: Settings[ScopeType]): A1 = transform(getValue(ss, scopedKey))
|
override final def evaluate(ss: Settings[ScopeType]): A1 = transform(getValue(ss, scopedKey))
|
||||||
|
|
@ -829,20 +833,27 @@ trait Init[ScopeType]:
|
||||||
g(scopedKey) match
|
g(scopedKey) match
|
||||||
case None => this
|
case None => this
|
||||||
case Some(const) => Value(() => transform(const))
|
case Some(const) => Value(() => transform(const))
|
||||||
|
end GetValue
|
||||||
private[sbt] override def processAttributes[A2](init: A2)(f: (A2, AttributeMap) => A2): A2 =
|
|
||||||
init
|
|
||||||
end Keyed
|
|
||||||
|
|
||||||
private final class GetValue[S, A1](val scopedKey: ScopedKey[S], val transform: S => A1)
|
|
||||||
extends Keyed[S, A1]
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A `Keyed` where the type of the value and the associated `ScopedKey` are the same.
|
* A `Keyed` where the type of the value and the associated `ScopedKey` are the same.
|
||||||
* @tparam A1 the type of both the value this `Initialize` defines and the type of the associated `ScopedKey`.
|
* @tparam A1 the type of both the value this `Initialize` defines and the type of the associated `ScopedKey`.
|
||||||
*/
|
*/
|
||||||
trait KeyedInitialize[A1] extends Keyed[A1, A1]:
|
trait KeyedInitialize[A1] extends Keyed[A1, A1]:
|
||||||
final val transform = identity[A1]
|
override final def apply[A2](g: A1 => A2): Initialize[A2] =
|
||||||
|
GetValue(scopedKey, g)
|
||||||
|
override final def evaluate(ss: Settings[ScopeType]): A1 = getValue(ss, scopedKey)
|
||||||
|
override final def mapReferenced(g: MapScoped): Initialize[A1] = g(scopedKey)
|
||||||
|
|
||||||
|
private[sbt] override final def validateKeyReferenced(g: ValidateKeyRef): ValidatedInit[A1] =
|
||||||
|
g(scopedKey, false) match
|
||||||
|
case Left(un) => Left(un :: Nil)
|
||||||
|
case Right(nk) => Right(nk)
|
||||||
|
|
||||||
|
override final def mapConstant(g: MapConstant): Initialize[A1] =
|
||||||
|
g(scopedKey) match
|
||||||
|
case None => this
|
||||||
|
case Some(const) => Value(() => const)
|
||||||
end KeyedInitialize
|
end KeyedInitialize
|
||||||
|
|
||||||
private[sbt] final class TransformCapture(val f: [x] => Initialize[x] => Initialize[x])
|
private[sbt] final class TransformCapture(val f: [x] => Initialize[x] => Initialize[x])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue