From 237b80eb227d9f7d768882f960a581dd4223ddf3 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Tue, 13 Nov 2012 14:52:33 -0500 Subject: [PATCH] Transition to all camelCase key labels. 1. Hyphenated labels are still accepted when parsing scoped keys (so 'sbt test-only' still works) There is currently no timeline for removing this support for hyphenated keys. 2. Only camelCase is shown for tab completion. 3. AttributeKey.rawLabel provides the unnormalized label. This should only be used to implement support for accepting hyphenated keys as input for compatibility. 4. AttributeKey.normLabel provides the normalized label (hyphenated converted to camelCase) --- util/collection/Attributes.scala | 6 +++++- util/collection/Util.scala | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/util/collection/Attributes.scala b/util/collection/Attributes.scala index 0376ca76c..227e2fdd7 100644 --- a/util/collection/Attributes.scala +++ b/util/collection/Attributes.scala @@ -11,6 +11,8 @@ import scala.reflect.Manifest // a single AttributeKey instance cannot conform to AttributeKey[T] for different Ts sealed trait AttributeKey[T] { def manifest: Manifest[T] + @deprecated("Should only be used for compatibility during the transition from hyphenated labels to camelCase labels.", "0.13.0") + def rawLabel: String def label: String def description: Option[String] def extend: Seq[AttributeKey[_]] @@ -48,13 +50,15 @@ object AttributeKey private[this] def make[T](name: String, description0: Option[String], extend0: Seq[AttributeKey[_]], rank0: Int)(implicit mf: Manifest[T]): AttributeKey[T] = new SharedAttributeKey[T] { def manifest = mf - def label = name + def rawLabel = name + val label = Util.hyphenToCamel(name) def description = description0 def extend = extend0 def rank = rank0 } private[sbt] def local[T](implicit mf: Manifest[T]): AttributeKey[T] = new AttributeKey[T] { def manifest = mf + def rawLabel = LocalLabel def label = LocalLabel def description = None def extend = Nil diff --git a/util/collection/Util.scala b/util/collection/Util.scala index 5aede5f0d..f4f6fbb50 100644 --- a/util/collection/Util.scala +++ b/util/collection/Util.scala @@ -26,8 +26,14 @@ object Util def pairID[A,B] = (a: A, b: B) => (a,b) private[this] lazy val Hypen = """-(\p{javaLowerCase})""".r - def hypenToCamel(s: String): String = - Hypen.replaceAllIn(s, _.group(1).toUpperCase) + def hasHyphen(s: String): Boolean = s.indexOf('-') >= 0 + @deprecated("Use the properly spelled version: hyphenToCamel", "0.13.0") + def hypenToCamel(s: String): String = hyphenToCamel(s) + def hyphenToCamel(s: String): String = + if(hasHyphen(s)) + Hypen.replaceAllIn(s, _.group(1).toUpperCase) + else + s private[this] lazy val Camel = """(\p{javaLowerCase})(\p{javaUpperCase})""".r def camelToHypen(s: String): String =