Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java wrappers need not be case classes #10104

Merged
merged 1 commit into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions project/MimaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ object MimaFilters extends AutoPlugin {
// internal to wrappers
ProblemFilters.exclude[NewMixinForwarderProblem]("scala.collection.convert.JavaCollectionWrappers#JMapWrapperLike.getOrElseUpdate"),
ProblemFilters.exclude[NewMixinForwarderProblem]("scala.collection.convert.JavaCollectionWrappers#JMapWrapperLike.updateWith"),

// removing case classing from wrappers means synthetic methods and parent types and companions are missing
ProblemFilters.exclude[DirectMissingMethodProblem]("scala.collection.convert.JavaCollectionWrappers#*"),
ProblemFilters.exclude[MissingTypesProblem]("scala.collection.convert.JavaCollectionWrappers$*"),
ProblemFilters.exclude[MissingClassProblem]("scala.collection.convert.JavaCollectionWrappers$*"),
)

override val buildSettings = Seq(
Expand Down
78 changes: 39 additions & 39 deletions src/library/scala/collection/convert/AsJavaConverters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ trait AsJavaConverters {
* @return A Java `Iterator` view of the argument.
*/
def asJava[A](i: Iterator[A]): ju.Iterator[A] = i match {
case null => null
case JIteratorWrapper(wrapped) => wrapped.asInstanceOf[ju.Iterator[A]]
case _ => IteratorWrapper(i)
case null => null
case wrapper: JIteratorWrapper[A @uc] => wrapper.underlying
case _ => new IteratorWrapper(i)
}

/**
Expand All @@ -56,9 +56,9 @@ trait AsJavaConverters {
* @return A Java `Enumeration` view of the argument.
*/
def asJavaEnumeration[A](i: Iterator[A]): ju.Enumeration[A] = i match {
case null => null
case JEnumerationWrapper(wrapped) => wrapped.asInstanceOf[ju.Enumeration[A]]
case _ => IteratorWrapper(i)
case null => null
case wrapper: JEnumerationWrapper[A @uc] => wrapper.underlying
case _ => new IteratorWrapper(i)
}

/**
Expand All @@ -74,9 +74,9 @@ trait AsJavaConverters {
* @return A Java `Iterable` view of the argument.
*/
def asJava[A](i: Iterable[A]): jl.Iterable[A] = i match {
case null => null
case JIterableWrapper(wrapped) => wrapped.asInstanceOf[jl.Iterable[A]]
case _ => IterableWrapper(i)
case null => null
case wrapper: JIterableWrapper[A @uc] => wrapper.underlying
case _ => new IterableWrapper(i)
}

/**
Expand All @@ -89,9 +89,9 @@ trait AsJavaConverters {
* @return A Java `Collection` view of the argument.
*/
def asJavaCollection[A](i: Iterable[A]): ju.Collection[A] = i match {
case null => null
case JCollectionWrapper(wrapped) => wrapped.asInstanceOf[ju.Collection[A]]
case _ => IterableWrapper(i)
case null => null
case wrapper: JCollectionWrapper[A @uc] => wrapper.underlying
case _ => new IterableWrapper(i)
}

/**
Expand All @@ -107,9 +107,9 @@ trait AsJavaConverters {
* @return A Java `List` view of the argument.
*/
def asJava[A](b: mutable.Buffer[A]): ju.List[A] = b match {
case null => null
case JListWrapper(wrapped) => wrapped
case _ => MutableBufferWrapper(b)
case null => null
case wrapper: JListWrapper[A @uc] => wrapper.underlying
case _ => new MutableBufferWrapper(b)
}

/**
Expand All @@ -125,9 +125,9 @@ trait AsJavaConverters {
* @return A Java `List` view of the argument.
*/
def asJava[A](s: mutable.Seq[A]): ju.List[A] = s match {
case null => null
case JListWrapper(wrapped) => wrapped
case _ => MutableSeqWrapper(s)
case null => null
case wrapper: JListWrapper[A @uc] => wrapper.underlying
case _ => new MutableSeqWrapper(s)
}

/**
Expand All @@ -143,9 +143,9 @@ trait AsJavaConverters {
* @return A Java `List` view of the argument.
*/
def asJava[A](s: Seq[A]): ju.List[A] = s match {
case null => null
case JListWrapper(wrapped) => wrapped.asInstanceOf[ju.List[A]]
case _ => SeqWrapper(s)
case null => null
case wrapper: JListWrapper[A @uc] => wrapper.underlying
case _ => new SeqWrapper(s)
}

/**
Expand All @@ -161,9 +161,9 @@ trait AsJavaConverters {
* @return A Java `Set` view of the argument.
*/
def asJava[A](s: mutable.Set[A]): ju.Set[A] = s match {
case null => null
case JSetWrapper(wrapped) => wrapped
case _ => MutableSetWrapper(s)
case null => null
case wrapper: JSetWrapper[A @uc] => wrapper.underlying
case _ => new MutableSetWrapper(s)
}

/**
Expand All @@ -179,9 +179,9 @@ trait AsJavaConverters {
* @return A Java `Set` view of the argument.
*/
def asJava[A](s: Set[A]): ju.Set[A] = s match {
case null => null
case JSetWrapper(wrapped) => wrapped
case _ => new SetWrapper(s)
case null => null
case wrapper: JSetWrapper[A @uc] => wrapper.underlying
case _ => new SetWrapper(s)
}

/**
Expand All @@ -197,9 +197,9 @@ trait AsJavaConverters {
* @return A Java `Map` view of the argument.
*/
def asJava[K, V](m: mutable.Map[K, V]): ju.Map[K, V] = m match {
case null => null
case w: JMapWrapper[K @uc, V @uc] => w.underlying
case _ => MutableMapWrapper(m)
case null => null
case wrapper: JMapWrapper[K @uc, V @uc] => wrapper.underlying
case _ => new MutableMapWrapper(m)
}

/**
Expand All @@ -216,9 +216,9 @@ trait AsJavaConverters {
* @return A Java `Dictionary` view of the argument.
*/
def asJavaDictionary[K, V](m: mutable.Map[K, V]): ju.Dictionary[K, V] = m match {
case null => null
case JDictionaryWrapper(wrapped) => wrapped
case _ => DictionaryWrapper(m)
case null => null
case wrapper: JDictionaryWrapper[K @uc, V @uc] => wrapper.underlying
case _ => new DictionaryWrapper(m)
}

/**
Expand All @@ -234,9 +234,9 @@ trait AsJavaConverters {
* @return A Java `Map` view of the argument.
*/
def asJava[K, V](m: Map[K, V]): ju.Map[K, V] = m match {
case null => null
case w: JMapWrapper[K @uc, V @uc] => w.underlying
case _ => new MapWrapper(m)
case null => null
case wrapper: JMapWrapper[K @uc, V @uc] => wrapper.underlying
case _ => new MapWrapper(m)
}

/**
Expand All @@ -253,8 +253,8 @@ trait AsJavaConverters {
* @return A Java `ConcurrentMap` view of the argument.
*/
def asJava[K, V](m: concurrent.Map[K, V]): juc.ConcurrentMap[K, V] = m match {
case null => null
case JConcurrentMapWrapper(wrapped) => wrapped
case _ => new ConcurrentMapWrapper(m)
case null => null
case wrapper: JConcurrentMapWrapper[K @uc, V @uc] => wrapper.underlying
case _ => new ConcurrentMapWrapper(m)
}
}
62 changes: 32 additions & 30 deletions src/library/scala/collection/convert/AsScalaConverters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package convert
import java.util.{concurrent => juc}
import java.{lang => jl, util => ju}

import scala.{unchecked => uc}

/** Defines converter methods from Java to Scala collections.
* These methods are available through the [[scala.jdk.javaapi.CollectionConverters]] object.
*/
Expand All @@ -36,9 +38,9 @@ trait AsScalaConverters {
* @return A Scala `Iterator` view of the argument.
*/
def asScala[A](i: ju.Iterator[A]): Iterator[A] = i match {
case null => null
case IteratorWrapper(wrapped) => wrapped
case _ => JIteratorWrapper(i)
case null => null
case wrapper: IteratorWrapper[A @uc] => wrapper.underlying
case _ => new JIteratorWrapper(i)
}

/**
Expand All @@ -54,9 +56,9 @@ trait AsScalaConverters {
* @return A Scala `Iterator` view of the argument.
*/
def asScala[A](e: ju.Enumeration[A]): Iterator[A] = e match {
case null => null
case IteratorWrapper(wrapped) => wrapped
case _ => JEnumerationWrapper(e)
case null => null
case wrapper: IteratorWrapper[A @uc] => wrapper.underlying
case _ => new JEnumerationWrapper(e)
}

/**
Expand All @@ -72,9 +74,9 @@ trait AsScalaConverters {
* @return A Scala `Iterable` view of the argument.
*/
def asScala[A](i: jl.Iterable[A]): Iterable[A] = i match {
case null => null
case IterableWrapper(wrapped) => wrapped
case _ => JIterableWrapper(i)
case null => null
case wrapper: IterableWrapper[A @uc] => wrapper.underlying
case _ => new JIterableWrapper(i)
}

/**
Expand All @@ -87,9 +89,9 @@ trait AsScalaConverters {
* @return A Scala `Iterable` view of the argument.
*/
def asScala[A](c: ju.Collection[A]): Iterable[A] = c match {
case null => null
case IterableWrapper(wrapped) => wrapped
case _ => JCollectionWrapper(c)
case null => null
case wrapper: IterableWrapper[A @uc] => wrapper.underlying
case _ => new JCollectionWrapper(c)
}

/**
Expand All @@ -105,9 +107,9 @@ trait AsScalaConverters {
* @return A Scala mutable `Buffer` view of the argument.
*/
def asScala[A](l: ju.List[A]): mutable.Buffer[A] = l match {
case null => null
case MutableBufferWrapper(wrapped) => wrapped
case _ => new JListWrapper(l)
case null => null
case wrapper: MutableBufferWrapper[A @uc] => wrapper.underlying
case _ => new JListWrapper(l)
}

/**
Expand All @@ -123,9 +125,9 @@ trait AsScalaConverters {
* @return A Scala mutable `Set` view of the argument.
*/
def asScala[A](s: ju.Set[A]): mutable.Set[A] = s match {
case null => null
case MutableSetWrapper(wrapped) => wrapped
case _ => new JSetWrapper(s)
case null => null
case wrapper: MutableSetWrapper[A @uc] => wrapper.underlying
case _ => new JSetWrapper(s)
}

/**
Expand All @@ -145,10 +147,10 @@ trait AsScalaConverters {
* @param m The Java `Map` to be converted.
* @return A Scala mutable `Map` view of the argument.
*/
def asScala[A, B](m: ju.Map[A, B]): mutable.Map[A, B] = m match {
case null => null
case MutableMapWrapper(wrapped) => wrapped
case _ => new JMapWrapper(m)
def asScala[K, V](m: ju.Map[K, V]): mutable.Map[K, V] = m match {
case null => null
case wrapper: MutableMapWrapper[K @uc, V @uc] => wrapper.underlying
case _ => new JMapWrapper(m)
}

/**
Expand All @@ -164,10 +166,10 @@ trait AsScalaConverters {
* @param m The Java `ConcurrentMap` to be converted.
* @return A Scala mutable `ConcurrentMap` view of the argument.
*/
def asScala[A, B](m: juc.ConcurrentMap[A, B]): concurrent.Map[A, B] = m match {
case null => null
case cmw: ConcurrentMapWrapper[_, _] => cmw.underlying
case _ => new JConcurrentMapWrapper(m)
def asScala[K, V](m: juc.ConcurrentMap[K, V]): concurrent.Map[K, V] = m match {
case null => null
case wrapper: ConcurrentMapWrapper[K @uc, V @uc] => wrapper.underlyingConcurrentMap
case _ => new JConcurrentMapWrapper(m)
}

/**
Expand All @@ -182,10 +184,10 @@ trait AsScalaConverters {
* @param d The Java `Dictionary` to be converted.
* @return A Scala mutable `Map` view of the argument.
*/
def asScala[A, B](d: ju.Dictionary[A, B]): mutable.Map[A, B] = d match {
case null => null
case DictionaryWrapper(wrapped) => wrapped
case _ => new JDictionaryWrapper(d)
def asScala[K, V](d: ju.Dictionary[K, V]): mutable.Map[K, V] = d match {
case null => null
case wrapper: DictionaryWrapper[K @uc, V @uc] => wrapper.underlying
case _ => new JDictionaryWrapper(d)
}

/**
Expand Down
Loading