diff options
author | Antonio Cunei <antonio.cunei@epfl.ch> | 2010-09-02 11:54:06 +0000 |
---|---|---|
committer | Antonio Cunei <antonio.cunei@epfl.ch> | 2010-09-02 11:54:06 +0000 |
commit | 918fb944b611ee08b5f5596c2fbc5123d2f09917 (patch) | |
tree | b16a64b472f021b0f169ebf688b65f8492943691 /src/library | |
parent | 13387444da947f6a9fa3770ec2acb227333da6cf (diff) | |
download | scala-918fb944b611ee08b5f5596c2fbc5123d2f09917.tar.gz scala-918fb944b611ee08b5f5596c2fbc5123d2f09917.tar.bz2 scala-918fb944b611ee08b5f5596c2fbc5123d2f09917.zip |
Merged revisions 22108,22176-22177,22318,22589-...
Merged revisions
22108,22176-22177,22318,22589-22590,22595,22644,22657-22658,22723,22725,
22737-22738,22833-22835,22846,22858-22860,22872 via svnmerge from
https://lampsvn.epfl.ch/svn-repos/scala/scala/trunk
........
r22108 | odersky | 2010-05-31 19:23:38 +0200 (Mon, 31 May 2010) | 1 line
made hashset more robust for concurrent access to reduce eclipse race
conditions. ........ r22176 | odersky | 2010-06-06 09:46:43 +0200 (Sun,
06 Jun 2010) | 2 lines
Overwrote copyToArray for efficiency.
........
r22177 | odersky | 2010-06-06 09:47:21 +0200 (Sun, 06 Jun 2010) | 2 lines
Fixed a typo in a use case
........
r22318 | odersky | 2010-06-16 17:36:08 +0200 (Wed, 16 Jun 2010) | 1 line
Imporved printing of private[C] in TreePrinters. No review. ........
r22589 | odersky | 2010-07-19 15:55:09 +0200 (Mon, 19 Jul 2010) | 1 line
new test files.
........
r22590 | odersky | 2010-07-19 15:56:03 +0200 (Mon, 19 Jul 2010) | 1 line
Added `ask` method to compiler control to do fast trunaround
computations on presentation compiler thread. ........ r22595 | odersky
| 2010-07-19 17:19:45 +0200 (Mon, 19 Jul 2010) | 1 line
added missing file.
........
r22644 | odersky | 2010-07-28 18:33:16 +0200 (Wed, 28 Jul 2010) | 1 line
Fixes #3679. Review by milessabin.
........
r22657 | odersky | 2010-08-02 15:53:16 +0200 (Mon, 02 Aug 2010) | 1 line
Revamped ScalaConversions. Fixes #3688. Also added JavaConverters
object which allows for explicit asJava/asScala conversions in the
scalaj style. Review by milessabin. ........ r22658 | odersky |
2010-08-02 15:53:58 +0200 (Mon, 02 Aug 2010) | 1 line
Fixed some typoes/errors in doc comments. No review. ........ r22723 |
odersky | 2010-08-10 17:47:15 +0200 (Tue, 10 Aug 2010) | 1 line
Removed duplicate classes. No review.
........
r22725 | odersky | 2010-08-10 19:38:32 +0200 (Tue, 10 Aug 2010) | 1 line
Added missing file for last checkin.
........
r22737 | odersky | 2010-08-12 11:02:46 +0200 (Thu, 12 Aug 2010) | 1 line
Changes in docs and layout. No review.
........
r22738 | odersky | 2010-08-12 11:03:30 +0200 (Thu, 12 Aug 2010) | 1 line
Fixed type soundness problem someone raised on hackers news. Test in
override.scala. Review by moors. ........ r22833 | odersky | 2010-08-24
16:59:13 +0200 (Tue, 24 Aug 2010) | 1 line
Fixes #3780. No review.
........
r22834 | odersky | 2010-08-24 16:59:54 +0200 (Tue, 24 Aug 2010) | 1 line
new tests. No review.
........
r22835 | odersky | 2010-08-24 17:48:09 +0200 (Tue, 24 Aug 2010) | 1 line
Closes #3776. No review.
........
r22846 | moors | 2010-08-26 18:16:54 +0200 (Thu, 26 Aug 2010) | 1 line
this should fix our achy breaky build. no review
........
r22858 | odersky | 2010-08-30 17:56:13 +0200 (Mon, 30 Aug 2010) | 1 line
added doc comment which makes things clearer when seen from Map or
Set. ........ r22859 | odersky | 2010-08-30 17:59:05 +0200 (Mon, 30 Aug
2010) | 1 line
removed author attribution, since no code from Stepan remains here.
........ r22860 | odersky | 2010-08-30 18:02:34 +0200 (Mon, 30 Aug 2010)
| 1 line
New wider interface of presentation compiler. Allows for partial
responses and improves cancelling. See Response.scala for a usage
example. ........ r22872 | odersky | 2010-08-31 17:37:55 +0200 (Tue, 31
Aug 2010) | 1 line
Partial fix for #3774. The crash is gone but the program is rejected.
A full fix will have to wait until a re-implementation of LUB/GLB along
the lines of the DOT system. ........
Diffstat (limited to 'src/library')
8 files changed, 593 insertions, 44 deletions
diff --git a/src/library/scala/collection/JavaConversions.scala b/src/library/scala/collection/JavaConversions.scala index 80fc28e234..bbd3976490 100644 --- a/src/library/scala/collection/JavaConversions.scala +++ b/src/library/scala/collection/JavaConversions.scala @@ -70,11 +70,14 @@ object JavaConversions { * @param i The <code>Iterator</code> to be converted. * @return A Java <code>Iterator</code> view of the argument. */ - implicit def asIterator[A](i : Iterator[A]): ju.Iterator[A] = i match { + implicit def asJavaIterator[A](i : Iterator[A]): ju.Iterator[A] = i match { case JIteratorWrapper(wrapped) => wrapped case _ => IteratorWrapper(i) } + @deprecated("use asJavaIterator instead") + def asIterator[A](i : Iterator[A]): ju.Iterator[A] = asJavaIterator[A](i) + /** * Implicitly converts a Scala <code>Iterator</code> to a Java <code>Enumeration</code>. * The returned Java <code>Enumeration</code> is backed by the provided Scala @@ -88,11 +91,14 @@ object JavaConversions { * @param i The <code>Iterator</code> to be converted. * @return A Java <code>Enumeration</code> view of the argument. */ - implicit def asEnumeration[A](i : Iterator[A]): ju.Enumeration[A] = i match { + implicit def asJavaEnumeration[A](i : Iterator[A]): ju.Enumeration[A] = i match { case JEnumerationWrapper(wrapped) => wrapped case _ => IteratorWrapper(i) } + @deprecated("use asJavaEnmeration instead") + def asEnumeration[A](i : Iterator[A]): ju.Enumeration[A] = asJavaEnumeration[A](i) + /** * Implicitly converts a Scala <code>Iterable</code> to a Java <code>Iterable</code>. * The returned Java <code>Iterable</code> is backed by the provided Scala @@ -106,11 +112,14 @@ object JavaConversions { * @param i The <code>Iterable</code> to be converted. * @return A Java <code>Iterable</code> view of the argument. */ - implicit def asIterable[A](i : Iterable[A]): jl.Iterable[A] = i match { + implicit def asJavaIterable[A](i : Iterable[A]): jl.Iterable[A] = i match { case JIterableWrapper(wrapped) => wrapped case _ => IterableWrapper(i) } + @deprecated("use asJavaIterable instead") + def asIterable[A](i : Iterable[A]): jl.Iterable[A] = asJavaIterable[A](i) + /** * Implicitly converts a Scala <code>Iterable</code> to an immutable Java * <code>Collection</code>. @@ -122,11 +131,14 @@ object JavaConversions { * @param i The <code>SizedIterable</code> to be converted. * @return A Java <code>Collection</code> view of the argument. */ - implicit def asCollection[A](i : Iterable[A]): ju.Collection[A] = i match { + implicit def asJavaCollection[A](i : Iterable[A]): ju.Collection[A] = i match { case JCollectionWrapper(wrapped) => wrapped case _ => new IterableWrapper(i) } + @deprecated("use asJavaCollection instead") + def asCollection[A](i : Iterable[A]): ju.Collection[A] = asJavaCollection[A](i) + /** * Implicitly converts a Scala mutable <code>Buffer</code> to a Java <code>List</code>. * The returned Java <code>List</code> is backed by the provided Scala @@ -140,11 +152,14 @@ object JavaConversions { * @param b The <code>Buffer</code> to be converted. * @return A Java <code>List</code> view of the argument. */ - implicit def asList[A](b : mutable.Buffer[A]): ju.List[A] = b match { + implicit def asJavaList[A](b : mutable.Buffer[A]): ju.List[A] = b match { case JListWrapper(wrapped) => wrapped case _ => new MutableBufferWrapper(b) } + @deprecated("use asJavaList instead") + def asList[A](b : mutable.Buffer[A]): ju.List[A] = asJavaList[A](b) + /** * Implicitly converts a Scala mutable <code>Seq</code> to a Java <code>List</code>. * The returned Java <code>List</code> is backed by the provided Scala @@ -158,11 +173,14 @@ object JavaConversions { * @param b The <code>Seq</code> to be converted. * @return A Java <code>List</code> view of the argument. */ - implicit def asList[A](b : mutable.Seq[A]): ju.List[A] = b match { + implicit def asJavaList[A](b : mutable.Seq[A]): ju.List[A] = b match { case JListWrapper(wrapped) => wrapped case _ => new MutableSeqWrapper(b) } + @deprecated("use asJavaList instead") + def asList[A](b : mutable.Seq[A]): ju.List[A] = asJavaList[A](b) + /** * Implicitly converts a Scala <code>Seq</code> to a Java <code>List</code>. * The returned Java <code>List</code> is backed by the provided Scala @@ -174,14 +192,16 @@ object JavaConversions { * Java <code>List</code> will be returned. * * @param b The <code>Seq</code> to be converted. - * @return A Java <code>List</co * -de> view of the argument. + * @return A Java <code>List</code> view of the argument. */ - implicit def asList[A](b : Seq[A]): ju.List[A] = b match { + implicit def asJavaList[A](b : Seq[A]): ju.List[A] = b match { case JListWrapper(wrapped) => wrapped case _ => new SeqWrapper(b) } + @deprecated("use asJavaList instead") + def asList[A](b : Seq[A]): ju.List[A] = asJavaList[A](b) + /** * Implicitly converts a Scala mutable <code>Set</code> to a Java <code>Set</code>. * The returned Java <code>Set</code> is backed by the provided Scala @@ -195,11 +215,14 @@ de> view of the argument. * @param s The <code>Set</code> to be converted. * @return A Java <code>Set</code> view of the argument. */ - implicit def asSet[A](s : mutable.Set[A]): ju.Set[A] = s match { + implicit def asJavaSet[A](s : mutable.Set[A]): ju.Set[A] = s match { case JSetWrapper(wrapped) => wrapped case _ => new MutableSetWrapper(s) } + @deprecated("use asJavaSet instead") + def asSet[A](s : mutable.Set[A]): ju.Set[A] = asJavaSet[A](s) + /** * Implicitly converts a Scala <code>Set</code> to a Java <code>Set</code>. * The returned Java <code>Set</code> is backed by the provided Scala @@ -213,11 +236,14 @@ de> view of the argument. * @param s The <code>Set</code> to be converted. * @return A Java <code>Set</code> view of the argument. */ - implicit def asSet[A](s: Set[A]): ju.Set[A] = s match { + implicit def asJavaSet[A](s: Set[A]): ju.Set[A] = s match { case JSetWrapper(wrapped) => wrapped case _ => new SetWrapper(s) } + @deprecated("use asJavaSet instead") + def asSet[A](s : Set[A]): ju.Set[A] = asJavaSet[A](s) + /** * Implicitly converts a Scala mutable <code>Map</code> to a Java <code>Map</code>. * The returned Java <code>Map</code> is backed by the provided Scala @@ -231,12 +257,15 @@ de> view of the argument. * @param m The <code>Map</code> to be converted. * @return A Java <code>Map</code> view of the argument. */ - implicit def asMap[A, B](m : mutable.Map[A, B]): ju.Map[A, B] = m match { + implicit def asJavaMap[A, B](m : mutable.Map[A, B]): ju.Map[A, B] = m match { //case JConcurrentMapWrapper(wrapped) => wrapped case JMapWrapper(wrapped) => wrapped case _ => new MutableMapWrapper(m) } + @deprecated("use asJavaMap instead") + def asMap[A, B](m : mutable.Map[A, B]): ju.Map[A, B] = asJavaMap[A, B](m) + /** * Implicitly converts a Scala mutable <code>Map</code> to a Java <code>Dictionary</code>. * The returned Java <code>Dictionary</code> is backed by the provided Scala @@ -250,24 +279,14 @@ de> view of the argument. * @param m The <code>Map</code> to be converted. * @return A Java <code>Dictionary</code> view of the argument. */ - implicit def asDictionary[A, B](m : mutable.Map[A, B]): ju.Dictionary[A, B] = m match { + implicit def asJavaDictionary[A, B](m : mutable.Map[A, B]): ju.Dictionary[A, B] = m match { //case JConcurrentMapWrapper(wrapped) => wrapped case JDictionaryWrapper(wrapped) => wrapped case _ => new DictionaryWrapper(m) } - /** - * Implicitly converts a Java <code>Properties</code> to a Scala mutable <code>Map[String, String]</code>. - * The returned Scala <code>Map[String, String]</code> is backed by the provided Java - * <code>Properties</code> and any side-effects of using it via the Scala interface will - * be visible via the Java interface and vice versa. - * - * @param m The <code>Properties</code> to be converted. - * @return A Scala mutable <code>Map[String, String]</code> view of the argument. - */ - implicit def asMap(p: ju.Properties): mutable.Map[String, String] = p match { - case _ => new JPropertiesWrapper(p) - } + @deprecated("use asJavaDictionary instead") + def asDictionary[A, B](m : mutable.Map[A, B]): ju.Dictionary[A, B] = asJavaDictionary[A, B](m) /** * Implicitly converts a Scala <code>Map</code> to a Java <code>Map</code>. @@ -282,12 +301,15 @@ de> view of the argument. * @param m The <code>Map</code> to be converted. * @return A Java <code>Map</code> view of the argument. */ - implicit def asMap[A, B](m : Map[A, B]): ju.Map[A, B] = m match { + implicit def asJavaMap[A, B](m : Map[A, B]): ju.Map[A, B] = m match { //case JConcurrentMapWrapper(wrapped) => wrapped case JMapWrapper(wrapped) => wrapped case _ => new MapWrapper(m) } + @deprecated("use asJavaMap instead") + def asMap[A, B](m : Map[A, B]): ju.Map[A, B] = asJavaMap[A, B](m) + /** * Implicitly converts a Scala mutable `ConcurrentMap` to a Java `ConcurrentMap`. * The returned Java `ConcurrentMap` is backed by the provided Scala `ConcurrentMap` @@ -297,12 +319,18 @@ de> view of the argument. * If the Scala <code>ConcurrentMap</code> was previously obtained from an implicit or * explicit call of <code>asConcurrentMap(java.util.concurrect.ConcurrentMap)</code> then the original * Java <code>ConcurrentMap</code> will be returned. + * + * @param m The <code>ConcurrentMap</code> to be converted. + * @return A Java <code>ConcurrentMap</code> view of the argument. */ - implicit def asConcurrentMap[A, B](m: mutable.ConcurrentMap[A, B]): juc.ConcurrentMap[A, B] = m match { + implicit def asJavaConcurrentMap[A, B](m: mutable.ConcurrentMap[A, B]): juc.ConcurrentMap[A, B] = m match { case JConcurrentMapWrapper(wrapped) => wrapped case _ => new ConcurrentMapWrapper(m) } + @deprecated("use asJavaConcurrentMap instead") + def asConcurrentMap[A, B](m: mutable.ConcurrentMap[A, B]): juc.ConcurrentMap[A, B] = asJavaConcurrentMap[A, B](m) + // Java => Scala /** @@ -318,11 +346,14 @@ de> view of the argument. * @param i The <code>Iterator</code> to be converted. * @return A Scala <code>Iterator</code> view of the argument. */ - implicit def asIterator[A](i : ju.Iterator[A]): Iterator[A] = i match { + implicit def asScalaIterator[A](i : ju.Iterator[A]): Iterator[A] = i match { case IteratorWrapper(wrapped) => wrapped case _ => JIteratorWrapper(i) } + @deprecated("use asScalaIterator instead") + def asIterator[A](i : ju.Iterator[A]): Iterator[A] = asScalaIterator[A](i) + /** * Implicitly converts a Java <code>Enumeration</code> to a Scala <code>Iterator</code>. * The returned Scala <code>Iterator</code> is backed by the provided Java @@ -336,11 +367,14 @@ de> view of the argument. * @param i The <code>Enumeration</code> to be converted. * @return A Scala <code>Iterator</code> view of the argument. */ - implicit def asIterator[A](i : ju.Enumeration[A]): Iterator[A] = i match { + implicit def enumerationAsScalaIterator[A](i : ju.Enumeration[A]): Iterator[A] = i match { case IteratorWrapper(wrapped) => wrapped case _ => JEnumerationWrapper(i) } + @deprecated("use enumerationAsScalaIterator instead") + def asIterator[A](i : ju.Enumeration[A]): Iterator[A] = enumerationAsScalaIterator[A](i) + /** * Implicitly converts a Java <code>Iterable</code> to a Scala <code>Iterable</code>. * The returned Scala <code>Iterable</code> is backed by the provided Java @@ -354,11 +388,14 @@ de> view of the argument. * @param i The <code>Iterable</code> to be converted. * @return A Scala <code>Iterable</code> view of the argument. */ - implicit def asIterable[A](i : jl.Iterable[A]): Iterable[A] = i match { + implicit def asScalaIterable[A](i : jl.Iterable[A]): Iterable[A] = i match { case IterableWrapper(wrapped) => wrapped case _ => JIterableWrapper(i) } + @deprecated("use asScalaIterable instead") + def asIterable[A](i : jl.Iterable[A]): Iterable[A] = asScalaIterable[A](i) + /** * Implicitly converts a Java <code>Collection</code> to an Scala <code>Iterable</code>. * <p> @@ -369,11 +406,14 @@ de> view of the argument. * @param i The <code>Collection</code> to be converted. * @return A Scala <code>SizedIterable</code> view of the argument. */ - implicit def asIterable[A](i : ju.Collection[A]): Iterable[A] = i match { + implicit def asScalaIterable[A](i : ju.Collection[A]): Iterable[A] = i match { case IterableWrapper(wrapped) => wrapped case _ => JCollectionWrapper(i) } + @deprecated("use asScalaIterable instead") + def asIterable[A](i : ju.Collection[A]): Iterable[A] = asScalaIterable[A](i) + /** * Implicitly converts a Java <code>List</code> to a Scala mutable <code>Buffer</code>. * The returned Scala <code>Buffer</code> is backed by the provided Java @@ -387,11 +427,14 @@ de> view of the argument. * @param l The <code>List</code> to be converted. * @return A Scala mutable <code>Buffer</code> view of the argument. */ - implicit def asBuffer[A](l : ju.List[A]): mutable.Buffer[A] = l match { + implicit def asScalaBuffer[A](l : ju.List[A]): mutable.Buffer[A] = l match { case MutableBufferWrapper(wrapped) => wrapped case _ =>new JListWrapper(l) } + @deprecated("use asScalaBuffer instead") + def asBuffer[A](l : ju.List[A]): mutable.Buffer[A] = asScalaBuffer[A](l) + /** * Implicitly converts a Java <code>Set</code> to a Scala mutable <code>Set</code>. * The returned Scala <code>Set</code> is backed by the provided Java @@ -405,11 +448,14 @@ de> view of the argument. * @param s The <code>Set</code> to be converted. * @return A Scala mutable <code>Set</code> view of the argument. */ - implicit def asSet[A](s : ju.Set[A]): mutable.Set[A] = s match { + implicit def asScalaSet[A](s : ju.Set[A]): mutable.Set[A] = s match { case MutableSetWrapper(wrapped) => wrapped case _ =>new JSetWrapper(s) } + @deprecated("use asScalaSet instead") + def asSet[A](s : ju.Set[A]): mutable.Set[A] = asScalaSet[A](s) + /** * Implicitly converts a Java <code>Map</code> to a Scala mutable <code>Map</code>. * The returned Scala <code>Map</code> is backed by the provided Java @@ -423,12 +469,15 @@ de> view of the argument. * @param m The <code>Map</code> to be converted. * @return A Scala mutable <code>Map</code> view of the argument. */ - implicit def asMap[A, B](m : ju.Map[A, B]): mutable.Map[A, B] = m match { + implicit def asScalaMap[A, B](m : ju.Map[A, B]): mutable.Map[A, B] = m match { //case ConcurrentMapWrapper(wrapped) => wrapped case MutableMapWrapper(wrapped) => wrapped case _ => new JMapWrapper(m) } + @deprecated("use asScalaMap instead") + def asMap[A, B](m : ju.Map[A, B]): mutable.Map[A, B] = asScalaMap[A, B](m) + /** * Implicitly converts a Java <code>ConcurrentMap</code> to a Scala mutable <code>ConcurrentMap</code>. * The returned Scala <code>ConcurrentMap</code> is backed by the provided Java @@ -442,11 +491,14 @@ de> view of the argument. * @param m The <code>ConcurrentMap</code> to be converted. * @return A Scala mutable <code>ConcurrrentMap</code> view of the argument. */ - implicit def asConcurrentMap[A, B](m: juc.ConcurrentMap[A, B]): mutable.ConcurrentMap[A, B] = m match { + implicit def asScalaConcurrentMap[A, B](m: juc.ConcurrentMap[A, B]): mutable.ConcurrentMap[A, B] = m match { case cmw: ConcurrentMapWrapper[a, b] => cmw.underlying case _ => new JConcurrentMapWrapper(m) } + @deprecated("use asScalaConcurrentMap instead") + def asConcurrentMap[A, B](m: juc.ConcurrentMap[A, B]): mutable.ConcurrentMap[A, B] = asScalaConcurrentMap[A, B](m) + /** * Implicitly converts a Java <code>Dictionary</code> to a Scala mutable <code>Map[String, String]</code>. * The returned Scala <code>Map[String, String]</code> is backed by the provided Java @@ -456,12 +508,31 @@ de> view of the argument. * @param m The <code>Dictionary</code> to be converted. * @return A Scala mutable <code>Map[String, String]</code> view of the argument. */ - implicit def asMap[A, B](p: ju.Dictionary[A, B]): mutable.Map[A, B] = p match { + implicit def dictionaryAsScalaMap[A, B](p: ju.Dictionary[A, B]): mutable.Map[A, B] = p match { case DictionaryWrapper(wrapped) => wrapped case _ => new JDictionaryWrapper(p) } - // Private implementations ... + @deprecated("use dictionaryAsScalaMap instead") + def asMap[A, B](p: ju.Dictionary[A, B]): mutable.Map[A, B] = dictionaryAsScalaMap[A, B](p) + + /** + * Implicitly converts a Java <code>Properties</code> to a Scala mutable <code>Map[String, String]</code>. + * The returned Scala <code>Map[String, String]</code> is backed by the provided Java + * <code>Properties</code> and any side-effects of using it via the Scala interface will + * be visible via the Java interface and vice versa. + * + * @param m The <code>Properties</code> to be converted. + * @return A Scala mutable <code>Map[String, String]</code> view of the argument. + */ + implicit def asScalaMap(p: ju.Properties): mutable.Map[String, String] = p match { + case _ => new JPropertiesWrapper(p) + } + + @deprecated("use asScalaMap instead") + def asMap(p: ju.Properties): mutable.Map[String, String] = asScalaMap(p) + + // Private implementations (shared by JavaConverters) ... case class IteratorWrapper[A](underlying : Iterator[A]) extends ju.Iterator[A] with ju.Enumeration[A] { def hasNext = underlying.hasNext @@ -471,6 +542,10 @@ de> view of the argument. def remove = throw new UnsupportedOperationException } + class ToIteratorWrapper[A](underlying : Iterator[A]) { + def asJava = new IteratorWrapper(underlying) + } + case class JIteratorWrapper[A](underlying : ju.Iterator[A]) extends Iterator[A] { def hasNext = underlying.hasNext def next = underlying.next @@ -751,8 +826,8 @@ de> view of the argument. extends ju.Dictionary[A, B] { def size: Int = underlying.size def isEmpty: Boolean = underlying.isEmpty - def keys: ju.Enumeration[A] = asEnumeration(underlying.keysIterator) - def elements: ju.Enumeration[B] = asEnumeration(underlying.valuesIterator) + def keys: ju.Enumeration[A] = asJavaEnumeration(underlying.keysIterator) + def elements: ju.Enumeration[B] = asJavaEnumeration(underlying.valuesIterator) def get(key: AnyRef) = try { underlying.get(key.asInstanceOf[A]) match { case None => null.asInstanceOf[B] @@ -800,7 +875,7 @@ de> view of the argument. if (r != null) Some(r) else None } - def iterator = asIterator(underlying.keys) map (k => (k, underlying get k)) + def iterator = enumerationAsScalaIterator(underlying.keys) map (k => (k, underlying get k)) override def clear() = underlying.clear() } diff --git a/src/library/scala/collection/JavaConverters.scala b/src/library/scala/collection/JavaConverters.scala new file mode 100755 index 0000000000..cb4c56fd59 --- /dev/null +++ b/src/library/scala/collection/JavaConverters.scala @@ -0,0 +1,456 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2010, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://www.scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + + + +package scala.collection + +/** <p> + * A collection of decorators that allow to convert between + * Scala and Java collections using `asScala` and `asJava` methods. + * </p> + * <p> + * The following conversions are supported via `asJava`, `asScala` + * </p> + * <ul> + * <li><code>scala.collection.Iterable</code> <=> <code>java.lang.Iterable</code></li> + * <li><code>scala.collection.Iterator</code> <=> <code>java.util.Iterator</code></li> + * <li><code>scala.collection.mutable.Buffer</code> <=> <code>java.util.List</code></li> + * <li><code>scala.collection.mutable.Set</code> <=> <code>java.util.Set</code></li> + * <li><code>scala.collection.mutable.Map</code> <=> <code>java.util.Map</code></li> + * <li><code>scala.collection.mutable.ConcurrentMap</code> <=> <code>java.util.concurrent.ConcurrentMap</code></li> + * </ul> + * <p> + * In all cases, converting from a source type to a target type and back + * again will return the original source object, e.g. + * </p> + * <pre> + * <b>import</b> scala.collection.JavaConverters._ + * + * <b>val</b> sl = <b>new</b> scala.collection.mutable.ListBuffer[Int] + * <b>val</b> jl : java.util.List[Int] = sl.asJava + * <b>val</b> sl2 : scala.collection.mutable.Buffer[Int] = jl.asScala + * assert(sl eq sl2)g</pre> + * <p> + * <p> + * The following conversions also are supported, but the + * direction Scala to Java is done my a more specifically named method: + * `asJavaCollection`, `asJavaEnumeration`, `asJavaDictionary`. + * </p> + * <ul> + * <li><code>scala.collection.Iterable</code> <=> <code>java.util.Collection</code></li> + * <li><code>scala.collection.Iterator</code> <=> <code>java.util.Enumeration</code></li> + * <li><code>scala.collection.mutable.Map</code> <=> <code>java.util.Dictionary</code></li> + * </ul> + * In addition, the following one way conversions are provided via `asJava`: + * </p> + * <ul> + * <li><code>scala.collection.Seq => <code>java.util.List }</code></li> + * <li><code>scala.collection.mutable.Seq => <code>java.util.List</code></li> + * <li><code>scala.collection.Set</code> => <code>java.util.Set</code></li> + * <li><code>scala.collection.Map</code> => <code>java.util.Map</code></li> + * </ul> + * + * @author Martin Odersky + * @since 2.8.1 + */ +object JavaConverters { + import java.{ lang => jl, util => ju } + import java.util.{ concurrent => juc } + import JavaConversions._ + + // Conversion decorator classes + + /** Generic class containing the `asJava` converter method */ + class AsJava[C](op: => C) { + /** Converts a Scala collection to the corresponding Java collection */ + def asJava: C = op + } + + /** Generic class containing the `asScala` converter method */ + class AsScala[C](op: => C) { + /** Converts a Java collection to the corresponding Scala collection */ + def asScala: C = op + } + + /** Generic class containing the `asJavaCollection` converter method */ + class AsJavaCollection[A](i: Iterable[A]) { + /** Converts a Scala `Iterable` to a Java `Collection` */ + def asJavaCollection: ju.Collection[A] = JavaConversions.asJavaCollection(i) + } + + /** Generic class containing the `asJavaEnumeration` converter method */ + class AsJavaEnumeration[A](i: Iterator[A]) { + /** Converts a Scala `Iterator` to a Java `Enumeration` */ + def asJavaEnumeration: ju.Enumeration[A] = JavaConversions.asJavaEnumeration(i) + } + + /** Generic class containing the `asJavaDictionary` converter method */ + class AsJavaDictionary[A, B](m : mutable.Map[A, B]) { + /** Converts a Scala `Map` to a Java `Dictionary` */ + def asJavaDictionary: ju.Dictionary[A, B] = JavaConversions.asJavaDictionary(m) + } + + // Scala => Java + + /** + * Adds an `asJava` method that implicitly converts a Scala <code>Iterator</code> to a Java <code>Iterator</code>. + * The returned Java <code>Iterator</code> is backed by the provided Scala + * <code>Iterator</code> and any side-effects of using it via the Java interface will + * be visible via the Scala interface and vice versa. + * <p> + * If the Scala <code>Iterator</code> was previously obtained from an implicit or + * explicit call of <code>asIterator(java.util.Iterator)</code> then the original + * Java <code>Iterator</code> will be returned by the `asJava` method. + * + * @param i The <code>Iterator</code> to be converted. + * @return An object with an `asJava` method that returns a Java <code>Iterator</code> view of the argument. + */ + implicit def asJavaIteratorConverter[A](i : Iterator[A]): AsJava[ju.Iterator[A]] = + new AsJava(asJavaIterator(i)) + + /** + * Adds an `asJavaEnumeration` method that implicitly converts a Scala <code>Iterator</code> to a Java <code>Enumeration</code>. + * The returned Java <code>Enumeration</code> is backed by the provided Scala + * <code>Iterator</code> and any side-effects of using it via the Java interface will + * be visible via the Scala interface and vice versa. + * <p> + * If the Scala <code>Iterator</code> was previously obtained from an implicit or + * explicit call of <code>asIterator(java.util.Enumeration)</code> then the + * original Java <code>Enumeration</code> will be returned. + * + * @param i The <code>Iterator</code> to be converted. + * @return An object with an `asJavaEnumeration` method that returns a Java <code>Enumeration</code> view of the argument. + */ + implicit def asJavaEnumerationConverter[A](i : Iterator[A]): AsJavaEnumeration[A] = + new AsJavaEnumeration(i) + + /** + * Adds an `asJava` method that implicitly converts a Scala <code>Iterable</code> to a Java <code>Iterable</code>. + * The returned Java <code>Iterable</code> is backed by the provided Scala + * <code>Iterable</code> and any side-effects of using it via the Java interface will + * be visible via the Scala interface and vice versa. + * <p> + * If the Scala <code>Iterable</code> was previously obtained from an implicit or + * explicit call of <code>asIterable(java.lang.Iterable)</code> then the original + * Java <code>Iterable</code> will be returned. + * + * @param i The <code>Iterable</code> to be converted. + * @return An object with an `asJavaCollection` method that returns a Java <code>Iterable</code> view of the argument. + */ + implicit def asJavaIterableConverter[A](i : Iterable[A]): AsJava[jl.Iterable[A]] = + new AsJava(asJavaIterable(i)) + + /** + * Adds an `asJavaCollection` method that implicitly converts a Scala <code>Iterable</code> to an immutable Java + * <code>Collection</code>. + * <p> + * If the Scala <code>Iterable</code> was previously obtained from an implicit or + * explicit call of <code>asSizedIterable(java.util.Collection)</code> then the original + * Java <code>Collection</code> will be returned. + * + * @param i The <code>SizedIterable</code> to be converted. + * @return An object with an `asJava` method that returns a Java <code>Collection</code> view of the argument. + */ + implicit def asJavaCollectionConverter[A](i : Iterable[A]): AsJavaCollection[A] = + new AsJavaCollection(i) + + /** + * Adds an `asJava` method that implicitly converts a Scala mutable <code>Buffer</code> to a Java <code>List</code>. + * The returned Java <code>List</code> is backed by the provided Scala + * <code>Buffer</code> and any side-effects of using it via the Java interface will + * be visible via the Scala interface and vice versa. + * <p> + * If the Scala <code>Buffer</code> was previously obtained from an implicit or + * explicit call of <code>asBuffer(java.util.List)</code> then the original + * Java <code>List</code> will be returned. + * + * @param b The <code>Buffer</code> to be converted. + * @return An object with an `asJava` method that returns a Java <code>List</code> view of the argument. + */ + implicit def asJavaListConverter[A](b : mutable.Buffer[A]): AsJava[ju.List[A]] = + new AsJava(asJavaList(b)) + + /** + * Adds an `asJava` method that implicitly converts a Scala mutable <code>Seq</code> to a Java <code>List</code>. + * The returned Java <code>List</code> is backed by the provided Scala + * <code>Seq</code> and any side-effects of using it via the Java interface will + * be visible via the Scala interface and vice versa. + * <p> + * If the Scala <code>Seq</code> was previously obtained from an implicit or + * explicit call of <code>asSeq(java.util.List)</code> then the original + * Java <code>List</code> will be returned. + * + * @param b The <code>Seq</code> to be converted. + * @return An object with an `asJava` method that returns a Java <code>List</code> view of the argument. + */ + implicit def asJavaListConverter[A](b : mutable.Seq[A]): AsJava[ju.List[A]] = + new AsJava(asJavaList(b)) + + /** + * Adds an `asJava` method that implicitly converts a Scala <code>Seq</code> to a Java <code>List</code>. + * The returned Java <code>List</code> is backed by the provided Scala + * <code>Seq</code> and any side-effects of using it via the Java interface will + * be visible via the Scala interface and vice versa. + * <p> + * If the Scala <code>Seq</code> was previously obtained from an implicit or + * explicit call of <code>asSeq(java.util.List)</code> then the original + * Java <code>List</code> will be returned. + * + * @param b The <code>Seq</code> to be converted. + * @return An object with an `asJava` method that returns a Java <code>List</code> view of the argument. + */ + implicit def asJavaListConverter[A](b : Seq[A]): AsJava[ju.List[A]] = + new AsJava(asJavaList(b)) + + /** + * Adds an `asJava` method that implicitly converts a Scala mutable <code>Set</code> to a Java <code>Set</code>. + * The returned Java <code>Set</code> is backed by the provided Scala + * <code>Set</code> and any side-effects of using it via the Java interface will + * be visible via the Scala interface and vice versa. + * <p> + * If the Scala <code>Set</code> was previously obtained from an implicit or + * explicit call of <code>asSet(java.util.Set)</code> then the original + * Java <code>Set</code> will be returned. + * + * @param s The <code>Set</code> to be converted. + * @return An object with an `asJava` method that returns a Java <code>Set</code> view of the argument. + */ + implicit def asJavaSetConverter[A](s : mutable.Set[A]): AsJava[ju.Set[A]] = + new AsJava(asJavaSet(s)) + + /** + * Adds an `asJava` method that implicitly converts a Scala <code>Set</code> to a Java <code>Set</code>. + * The returned Java <code>Set</code> is backed by the provided Scala + * <code>Set</code> and any side-effects of using it via the Java interface will + * be visible via the Scala interface and vice versa. + * <p> + * If the Scala <code>Set</code> was previously obtained from an implicit or + * explicit call of <code>asSet(java.util.Set)</code> then the original + * Java <code>Set</code> will be returned. + * + * @param s The <code>Set</code> to be converted. + * @return An object with an `asJava` method that returns a Java <code>Set</code> view of the argument. + */ + implicit def asJavaSetConverter[A](s : Set[A]): AsJava[ju.Set[A]] = + new AsJava(asJavaSet(s)) + + /** + * Adds an `asJava` method that implicitly converts a Scala mutable <code>Map</code> to a Java <code>Map</code>. + * The returned Java <code>Map</code> is backed by the provided Scala + * <code>Map</code> and any side-effects of using it via the Java interface will + * be visible via the Scala interface and vice versa. + * <p> + * If the Scala <code>Map</code> was previously obtained from an implicit or + * explicit call of <code>asMap(java.util.Map)</code> then the original + * Java <code>Map</code> will be returned. + * + * @param m The <code>Map</code> to be converted. + * @return An object with an `asJava` method that returns a Java <code>Map</code> view of the argument. + */ + implicit def asJavaMapConverter[A, B](m : mutable.Map[A, B]): AsJava[ju.Map[A, B]] = + new AsJava(asJavaMap(m)) + + /** + * Adds an `asJavaDictionary` method that implicitly converts a Scala mutable <code>Map</code> to a Java <code>Dictionary</code>. + * The returned Java <code>Dictionary</code> is backed by the provided Scala + * <code>Dictionary</code> and any side-effects of using it via the Java interface will + * be visible via the Scala interface and vice versa. + * <p> + * If the Scala <code>Dictionary</code> was previously obtained from an implicit or + * explicit call of <code>asMap(java.util.Dictionary)</code> then the original + * Java <code>Dictionary</code> will be returned. + * + * @param m The <code>Map</code> to be converted. + * @return An object with an `asJavaDictionary` method that returns a Java <code>Dictionary</code> view of the argument. + */ + implicit def asJavaDictionaryConverter[A, B](m : mutable.Map[A, B]): AsJavaDictionary[A, B] = + new AsJavaDictionary(m) + + /** + * Adds an `asJava` method that implicitly converts a Scala <code>Map</code> to a Java <code>Map</code>. + * The returned Java <code>Map</code> is backed by the provided Scala + * <code>Map</code> and any side-effects of using it via the Java interface will + * be visible via the Scala interface and vice versa. + * <p> + * If the Scala <code>Map</code> was previously obtained from an implicit or + * explicit call of <code>asMap(java.util.Map)</code> then the original + * Java <code>Map</code> will be returned. + * + * @param m The <code>Map</code> to be converted. + * @return An object with an `asJava` method that returns a Java <code>Map</code> view of the argument. + */ + implicit def asJavaMapConverter[A, B](m : Map[A, B]): AsJava[ju.Map[A, B]] = + new AsJava(asJavaMap(m)) + + /** + * Adds an `asJava` method that implicitly converts a Scala mutable `ConcurrentMap` to a Java `ConcurrentMap`. + * The returned Java `ConcurrentMap` is backed by the provided Scala `ConcurrentMap` + * and any side-effects of using it via the Java interface will be visible + * via the Scala interface and vice versa. + * <p> + * If the Scala <code>ConcurrentMap</code> was previously obtained from an implicit or + * explicit call of <code>asConcurrentMap(java.util.concurrect.ConcurrentMap)</code> then the original + * Java <code>ConcurrentMap</code> will be returned. + * + * @param m The <code>ConcurrentMap</code> to be converted. + * @return An object with an `asJava` method that returns a Java <code>ConcurrentMap</code> view of the argument. + */ + implicit def asJavaConcurrentMapConverter[A, B](m: mutable.ConcurrentMap[A, B]): AsJava[juc.ConcurrentMap[A, B]] = + new AsJava(asJavaConcurrentMap(m)) + + /** + * Adds an `asScala` method that implicitly converts a Java <code>Iterator</code> to a Scala <code>Iterator</code>. + * The returned Scala <code>Iterator</code> is backed by the provided Java + * <code>Iterator</code> and any side-effects of using it via the Scala interface will + * be visible via the Java interface and vice versa. + * <p> + * If the Java <code>Iterator</code> was previously obtained from an implicit or + * explicit call of <code>asIterator(scala.collection.Iterator)</code> then the original + * Scala <code>Iterator</code> will be returned. + * + * @param i The <code>Iterator</code> to be converted. + * @return An object with an `asScala` method that returns a Scala <code>Iterator</code> view of the argument. + */ + implicit def asScalaIteratorConverter[A](i : ju.Iterator[A]): AsScala[Iterator[A]] = + new AsScala(asScalaIterator(i)) + + /** + * Adds an `asScala` method that implicitly converts a Java <code>Enumeration</code> to a Scala <code>Iterator</code>. + * The returned Scala <code>Iterator</code> is backed by the provided Java + * <code>Enumeration</code> and any side-effects of using it via the Scala interface will + * be visible via the Java interface and vice versa. + * <p> + * If the Java <code>Enumeration</code> was previously obtained from an implicit or + * explicit call of <code>asEnumeration(scala.collection.Iterator)</code> then the + * original Scala <code>Iterator</code> will be returned. + * + * @param i The <code>Enumeration</code> to be converted. + * @return An object with an `asScala` method that returns a Scala <code>Iterator</code> view of the argument. + */ + implicit def enumerationAsScalaIteratorConverter[A](i : ju.Enumeration[A]): AsScala[Iterator[A]] = + new AsScala(enumerationAsScalaIterator(i)) + + /** + * Adds an `asScala` method that implicitly converts a Java <code>Iterable</code> to a Scala <code>Iterable</code>. + * The returned Scala <code>Iterable</code> is backed by the provided Java + * <code>Iterable</code> and any side-effects of using it via the Scala interface will + * be visible via the Java interface and vice versa. + * <p> + * If the Java <code>Iterable</code> was previously obtained from an implicit or + * explicit call of <code>asIterable(scala.collection.Iterable)</code> then the original + * Scala <code>Iterable</code> will be returned. + * + * @param i The <code>Iterable</code> to be converted. + * @return An object with an `asScala` method that returns a Scala <code>Iterable</code> view of the argument. + */ + implicit def asScalaIterableConverter[A](i : jl.Iterable[A]): AsScala[Iterable[A]] = + new AsScala(asScalaIterable(i)) + + /** + * Adds an `asScala` method that implicitly converts a Java <code>Collection</code> to an Scala <code>Iterable</code>. + * <p> + * If the Java <code>Collection</code> was previously obtained from an implicit or + * explicit call of <code>asCollection(scala.collection.SizedIterable)</code> then + * the original Scala <code>SizedIterable</code> will be returned. + * + * @param i The <code>Collection</code> to be converted. + * @return An object with an `asScala` method that returns a Scala <code>SizedIterable</code> view of the argument. + */ + implicit def asScalaIterableConverter[A](i : ju.Collection[A]): AsScala[Iterable[A]] = + new AsScala(asScalaIterable(i)) + + /** + * Adds an `asScala` method that implicitly converts a Java <code>List</code> to a Scala mutable <code>Buffer</code>. + * The returned Scala <code>Buffer</code> is backed by the provided Java + * <code>List</code> and any side-effects of using it via the Scala interface will + * be visible via the Java interface and vice versa. + * <p> + * If the Java <code>List</code> was previously obtained from an implicit or + * explicit call of <code>asList(scala.collection.mutable.Buffer)</code> then the original + * Scala <code>Buffer</code> will be returned. + * + * @param l The <code>List</code> to be converted. + * @return An object with an `asScala` method that returns a Scala mutable <code>Buffer</code> view of the argument. + */ + implicit def asScalaBufferConverter[A](l : ju.List[A]): AsScala[mutable.Buffer[A]] = + new AsScala(asScalaBuffer(l)) + + /** + * Adds an `asScala` method that implicitly converts a Java <code>Set</code> to a Scala mutable <code>Set</code>. + * The returned Scala <code>Set</code> is backed by the provided Java + * <code>Set</code> and any side-effects of using it via the Scala interface will + * be visible via the Java interface and vice versa. + * <p> + * If the Java <code>Set</code> was previously obtained from an implicit or + * explicit call of <code>asSet(scala.collection.mutable.Set)</code> then the original + * ScalaThe reported problems have to do with dependent method types, which is currently an experimental feature in Scala and is still under development. We emphasize that these problems are related to type-inference and, as stated in the paper, it is possible to run and type-check the programs with additional annotations. <code>Set</code> will be returned. + * + * @param s The <code>Set</code> to be converted. + * @return An object with an `asScala` method that returns a Scala mutable <code>Set</code> view of the argument. + */ + implicit def asScalaSetConverter[A](s : ju.Set[A]): AsScala[mutable.Set[A]] = + new AsScala(asScalaSet(s)) + + /** + * Adds an `asScala` method that implicitly converts a Java <code>Map</code> to a Scala mutable <code>Map</code>. + * The returned Scala <code>Map</code> is backed by the provided Java + * <code>Map</code> and any side-effects of using it via the Scala interface will + * be visible via the Java interface and vice versa. + * <p> + * If the Java <code>Map</code> was previously obtained from an implicit or + * explicit call of <code>asMap(scala.collection.mutable.Map)</code> then the original + * Scala <code>Map</code> will be returned. + * + * @param m The <code>Map</code> to be converted. + * @return An object with an `asScala` method that returns a Scala mutable <code>Map</code> view of the argument. + */ + implicit def asScalaMapConverter[A, B](m : ju.Map[A, B]): AsScala[mutable.Map[A, B]] = + new AsScala(asScalaMap(m)) + + /** + * Adds an `asScala` method that implicitly converts a Java <code>ConcurrentMap</code> to a Scala mutable <code>ConcurrentMap</code>. + * The returned Scala <code>ConcurrentMap</code> is backed by the provided Java + * <code>ConcurrentMap</code> and any side-effects of using it via the Scala interface will + * be visible via the Java interface and vice versa. + * <p> + * If the Java <code>ConcurrentMap</code> was previously obtained from an implicit or + * explicit call of <code>asConcurrentMap(scala.collection.mutable.ConcurrentMap)</code> then the original + * Scala <code>ConcurrentMap</code> will be returned. + * + * @param m The <code>ConcurrentMap</code> to be converted. + * @return An object with an `asScala` method that returns a Scala mutable <code>ConcurrrentMap</code> view of the argument. + */ + implicit def asScalaConcurrentMapConverter[A, B](m: juc.ConcurrentMap[A, B]): AsScala[mutable.ConcurrentMap[A, B]] = + new AsScala(asScalaConcurrentMap(m)) + + /** + * Adds an `asScala` method that implicitly converts a Java <code>Dictionary</code> to a Scala mutable <code>Map[String, String]</code>. + * The returned Scala <code>Map[String, String]</code> is backed by the provided Java + * <code>Dictionary</code> and any side-effects of using it via the Scala interface will + * be visible via the Java interface and vice versa. + * + * @param m The <code>Dictionary</code> to be converted. + * @return An object with an `asScala` method that returns a Scala mutable <code>Map[String, String]</code> view of the argument. + */ + implicit def dictionaryAsScalaMapConverter[A, B](p: ju.Dictionary[A, B]): AsScala[mutable.Map[A, B]] = + new AsScala(dictionaryAsScalaMap(p)) + + /** + * Adds an `asScala` method that implicitly converts a Java <code>Properties</code> to a Scala mutable <code>Map[String, String]</code>. + * The returned Scala <code>Map[String, String]</code> is backed by the provided Java + * <code>Properties</code> and any side-effects of using it via the Scala interface will + * be visible via the Java interface and vice versa. + * + * @param m The <code>Properties</code> to be converted. + * @return An object with an `asScala` method that returns a Scala mutable <code>Map[String, String]</code> view of the argument. + */ + implicit def asScalaMapConverter(p: ju.Properties): AsScala[mutable.Map[String, String]] = + new AsScala(asScalaMap(p)) + +} diff --git a/src/library/scala/collection/TraversableOnce.scala b/src/library/scala/collection/TraversableOnce.scala index b6c0ce146e..6656b05083 100644 --- a/src/library/scala/collection/TraversableOnce.scala +++ b/src/library/scala/collection/TraversableOnce.scala @@ -277,7 +277,7 @@ trait TraversableOnce[+A] { * @tparam B the result type of the `+` operator. * @return the sum of all elements of this $coll with respect to the `+` operator in `num`. * - * @usecase def sum: Int + * @usecase def sum: A * * @return the sum of all elements in this $coll of numbers of type `Int`. * Instead of `Int`, any other type `T` with an implicit `Numeric[T]` implementation @@ -294,7 +294,7 @@ trait TraversableOnce[+A] { * @tparam B the result type of the `*` operator. * @return the product of all elements of this $coll with respect to the `*` operator in `num`. * - * @usecase def product: Int + * @usecase def product: A * * @return the product of all elements in this $coll of numbers of type `Int`. * Instead of `Int`, any other type `T` with an implicit `Numeric[T]` implementation @@ -442,6 +442,9 @@ trait TraversableOnce[+A] { * is undefined. * $willNotTerminateInf * @return a map containing all elements of this $coll. + * @usecase def toMap: Map[K, V] + * @return a map of type `immutable.Map[K, V]` + * containing all key/value pairs of type `(K, V)` of this $coll. */ def toMap[T, U](implicit ev: A <:< (T, U)): immutable.Map[T, U] = { val b = immutable.Map.newBuilder[T, U] diff --git a/src/library/scala/collection/generic/GenericTraversableTemplate.scala b/src/library/scala/collection/generic/GenericTraversableTemplate.scala index 54f4a07c10..5f009b6742 100644 --- a/src/library/scala/collection/generic/GenericTraversableTemplate.scala +++ b/src/library/scala/collection/generic/GenericTraversableTemplate.scala @@ -51,6 +51,7 @@ trait GenericTraversableTemplate[+A, +CC[X] <: Traversable[X]] extends HasNewBui def isEmpty: Boolean /** The factory companion object that builds instances of class $Coll. + * (or its `Iterable` superclass where class $Coll is not a `Seq`.) */ def companion: GenericCompanion[CC] diff --git a/src/library/scala/collection/mutable/ArrayOps.scala b/src/library/scala/collection/mutable/ArrayOps.scala index d7072c0661..00e8697b53 100644 --- a/src/library/scala/collection/mutable/ArrayOps.scala +++ b/src/library/scala/collection/mutable/ArrayOps.scala @@ -10,6 +10,7 @@ package scala.collection package mutable +import compat.Platform.arraycopy import scala.reflect.ClassManifest @@ -38,6 +39,13 @@ abstract class ArrayOps[T] extends ArrayLike[T, Array[T]] { ClassManifest.fromClass( repr.getClass.getComponentType.getComponentType.asInstanceOf[Predef.Class[U]])) + override def copyToArray[U >: T](xs: Array[U], start: Int, len: Int) { + var l = len + if (repr.length < l) l = repr.length + if (xs.length - start < l) l = xs.length - start max 0 + Array.copy(repr, 0, xs, start, l) + } + override def toArray[U >: T : ClassManifest]: Array[U] = if (implicitly[ClassManifest[U]].erasure eq repr.getClass.getComponentType) repr.asInstanceOf[Array[U]] diff --git a/src/library/scala/concurrent/SyncVar.scala b/src/library/scala/concurrent/SyncVar.scala index 46dc415e1f..dce770ce43 100644 --- a/src/library/scala/concurrent/SyncVar.scala +++ b/src/library/scala/concurrent/SyncVar.scala @@ -13,7 +13,7 @@ package scala.concurrent /** The class <code>SyncVar</code> ... * - * @author Martin Odersky, Stepan Koltsov + * @author Martin Odersky * @version 1.0, 10/03/2003 */ class SyncVar[A] { diff --git a/src/library/scala/reflect/generic/UnPickler.scala b/src/library/scala/reflect/generic/UnPickler.scala index ee021446bc..54ac1acc3d 100755 --- a/src/library/scala/reflect/generic/UnPickler.scala +++ b/src/library/scala/reflect/generic/UnPickler.scala @@ -42,7 +42,7 @@ abstract class UnPickler { } } - /** To ne implemented in subclasses. Like `unpickle` but without the catch-all error handling. + /** To be implemented in subclasses. Like `unpickle` but without the catch-all error handling. */ def scan(bytes: Array[Byte], offset: Int, classRoot: Symbol, moduleRoot: Symbol, filename: String) diff --git a/src/library/scala/runtime/TraitSetter.java b/src/library/scala/runtime/TraitSetter.java new file mode 100755 index 0000000000..d9907c0ac0 --- /dev/null +++ b/src/library/scala/runtime/TraitSetter.java @@ -0,0 +1,6 @@ +package scala.runtime; + +/** A marker annotation to tag a setter of a mutable variable in a trait + */ +public @interface TraitSetter { +}
\ No newline at end of file |