Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 30 lines (28 sloc) 0.988 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/* sbt -- Simple Build Tool
* Copyright 2008,2009 David MacIver, Mark Harrah
*/
package xsbt.boot

import Pre._
import scala.collection.immutable.List

class Enumeration
{
def elements: List[Value] = members
private lazy val members: List[Value] =
{
val c = getClass
val correspondingFields = ListMap( c.getDeclaredFields.map(f => (f.getName, f)) : _*)
c.getMethods.toList flatMap { method =>
if(method.getParameterTypes.length == 0 && classOf[Value].isAssignableFrom(method.getReturnType))
{
for(field <- correspondingFields.get(method.getName) if field.getType == method.getReturnType) yield
method.invoke(this).asInstanceOf[Value]
}
else
Nil
}
}
def value(s: String) = new Value(s, 0)
def value(s: String, i: Int) = new Value(s, i)
final class Value(override val toString: String, val id: Int)
def toValue(s: String): Value = elements.find(_.toString == s).getOrElse(error("Expected one of " + elements.mkString(",") + " (got: " + s + ")"))
}
Something went wrong with that request. Please try again.