diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-05-16 17:45:25 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2013-05-16 17:45:25 -0700 |
commit | 13b4628aabb8e7a293a382dcab6db5848f672f94 (patch) | |
tree | a2a4ee9a1c33d3629a392fedab426427fae53b89 | |
parent | 1f4a52b4ed9457863e00fe16d18705b6c6cd5db9 (diff) | |
parent | 135cfa88814ea5391c50bdeb2b2aaadfebd6da67 (diff) | |
download | scala-13b4628aabb8e7a293a382dcab6db5848f672f94.tar.gz scala-13b4628aabb8e7a293a382dcab6db5848f672f94.tar.bz2 scala-13b4628aabb8e7a293a382dcab6db5848f672f94.zip |
Merge pull request #2519 from som-snytt/issue/regex-revert
SI-6406 Restore deprecated API
-rw-r--r-- | src/library/scala/util/matching/Regex.scala | 14 | ||||
-rw-r--r-- | test/files/neg/t6406-regextract.check | 9 |
2 files changed, 18 insertions, 5 deletions
diff --git a/src/library/scala/util/matching/Regex.scala b/src/library/scala/util/matching/Regex.scala index 8d135ecf02..8eac0a2520 100644 --- a/src/library/scala/util/matching/Regex.scala +++ b/src/library/scala/util/matching/Regex.scala @@ -205,6 +205,20 @@ class Regex private[matching](val pattern: Pattern, groupNames: String*) extends else if (m.matcher.pattern == this.pattern) Some(1 to m.groupCount map m.group) else unapplySeq(m.matched) + /** Tries to match target. + * @param target The string to match + * @return The matches + */ + @deprecated("Extracting a match result from anything but a CharSequence or Match is deprecated", "2.11.0") + def unapplySeq(target: Any): Option[List[String]] = target match { + case s: CharSequence => + val m = pattern matcher s + if (runMatcher(m)) Some((1 to m.groupCount).toList map m.group) + else None + case m: Match => unapplySeq(m.matched) + case _ => None + } + // @see UnanchoredRegex protected def runMatcher(m: Matcher) = m.matches() diff --git a/test/files/neg/t6406-regextract.check b/test/files/neg/t6406-regextract.check index 4fea66f760..19425a68b0 100644 --- a/test/files/neg/t6406-regextract.check +++ b/test/files/neg/t6406-regextract.check @@ -1,7 +1,6 @@ -t6406-regextract.scala:4: error: cannot resolve overloaded unapply +t6406-regextract.scala:4: warning: method unapplySeq in class Regex is deprecated: Extracting a match result from anything but a CharSequence or Match is deprecated List(1) collect { case r(i) => i } ^ -t6406-regextract.scala:4: error: not found: value i - List(1) collect { case r(i) => i } - ^ -two errors found +error: No warnings can be incurred under -Xfatal-warnings. +one warning found +one error found |