harrah/xsbt — pull request #276 by eed3si9n (2011-11-24 01:01:28+00:00)
Title: refactored scoped key manifest extraction to ScopedKeyData

This is continuation from #274...

@harrah wrote:

> The second is that the manifest checking code should be factored out so that there aren't two very similar copies. The factored out method should return the discovered task/input task/value in an appropriate data type.

> Extracted should be for commonly used methods that need State or BuildStructure. This needs BuildStructure, but I don't think it qualifies as commonly used. Perhaps put it in Project.

This patch adds a method to `Project` that creates `ScopedKeyData` case class.

```scala
def scopedKeyData(structure: BuildStructure, scope: Scope, key: AttributeKey[_]): Option[ScopedKeyData[_]] =
structure.data.get(scope, key) map { v => ScopedKeyData(ScopedKey(scope, key), v) }
```

All of the manifest extraction is done in `ScopedKeyData`, but the details are tucked inside the simple `fold` method, which is used as follows:

```scala
def typeName: String = fold("Task[%s]" format _, "InputTask[%s]" format _, key.manifest.toString)
def settingValue: Option[Any] = fold(_ => None, _ => None, Some(value))
def description: String = fold("Task: %s" format _, "Input task: %s" format _,
"Setting: %s = %s" format (key.manifest.toString, value.toString))
```