Skip to content

Commit 210282f

Browse files
committed
remove / clarify usages of seqToNodeSeq
1 parent b167575 commit 210282f

File tree

11 files changed

+32
-31
lines changed

11 files changed

+32
-31
lines changed

jvm/src/test/scala/scala/xml/SerializationTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class SerializationTest {
2525
def implicitConversion(): Unit = {
2626
val parent: Elem = <parent><child></child><child/></parent>
2727
val children: Seq[Node] = parent.child
28-
val asNodeSeq: NodeSeq = children
28+
val asNodeSeq: NodeSeq = children // implicit seqToNodeSeq
2929
assertEquals(asNodeSeq, JavaByteSerialization.roundTrip(asNodeSeq))
3030
}
3131
}

shared/src/main/scala/scala/xml/Elem.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class Elem(
104104
scope: NamespaceBinding = this.scope,
105105
minimizeEmpty: Boolean = this.minimizeEmpty,
106106
child: Seq[Node] = this.child
107-
): Elem = Elem(prefix, label, attributes, scope, minimizeEmpty, child: _*)
107+
): Elem = Elem(prefix, label, attributes, scope, minimizeEmpty, child.toSeq: _*)
108108

109109
/**
110110
* Returns concatenation of `text(n)` for each child `n`.

shared/src/main/scala/scala/xml/MetaData.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ abstract class MetaData
183183
* Returns a Map containing the attributes stored as key/value pairs.
184184
*/
185185
def asAttrMap: Map[String, String] =
186-
iterator.map(x => (x.prefixedKey, x.value.text)).toMap
186+
iterator.map(x => (x.prefixedKey, NodeSeq.fromSeq(x.value).text)).toMap
187187

188188
/** returns Null or the next MetaData item */
189189
def next: MetaData

shared/src/main/scala/scala/xml/Utility.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import scala.annotation.tailrec
1717
import scala.collection.mutable
1818
import scala.language.implicitConversions
1919
import scala.collection.Seq
20+
import scala.collection.immutable.{Seq => ISeq}
2021

2122
/**
2223
* The `Utility` object provides utility functions for processing instances
@@ -51,12 +52,12 @@ object Utility extends AnyRef with parsing.TokenTests {
5152
*/
5253
def trim(x: Node): Node = x match {
5354
case Elem(pre, lab, md, scp, child@_*) =>
54-
val children: Seq[Node] = combineAdjacentTextNodes(child).flatMap(trimProper)
55+
val children = combineAdjacentTextNodes(child).flatMap(trimProper)
5556
Elem(pre, lab, md, scp, children.isEmpty, children: _*)
5657
}
5758

58-
private def combineAdjacentTextNodes(children: Seq[Node]): Seq[Node] =
59-
children.foldRight(Seq.empty[Node]) {
59+
private def combineAdjacentTextNodes(children: ISeq[Node]): ISeq[Node] =
60+
children.foldRight(ISeq.empty[Node]) {
6061
case (Text(left), Text(right) +: nodes) => Text(left + right) +: nodes
6162
case (n, nodes) => n +: nodes
6263
}
@@ -67,7 +68,7 @@ object Utility extends AnyRef with parsing.TokenTests {
6768
*/
6869
def trimProper(x: Node): Seq[Node] = x match {
6970
case Elem(pre, lab, md, scp, child@_*) =>
70-
val children: Seq[Node] = combineAdjacentTextNodes(child).flatMap(trimProper)
71+
val children = combineAdjacentTextNodes(child).flatMap(trimProper)
7172
Elem(pre, lab, md, scp, children.isEmpty, children: _*)
7273
case Text(s) =>
7374
new TextBuffer().append(s).toText
@@ -89,7 +90,7 @@ object Utility extends AnyRef with parsing.TokenTests {
8990
*/
9091
def sort(n: Node): Node = n match {
9192
case Elem(pre, lab, md, scp, child@_*) =>
92-
val children: Seq[Node] = child.map(sort)
93+
val children = child.map(sort)
9394
Elem(pre, lab, sort(md), scp, children.isEmpty, children: _*)
9495
case _ => n
9596
}

shared/src/main/scala/scala/xml/factory/XMLLoader.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ trait XMLLoader[T <: Node] {
5858

5959
// TODO remove
6060
def loadXML(inputSource: InputSource, parser: SAXParser): T = getDocElem(adapter.loadDocument(inputSource, parser.getXMLReader))
61-
def loadXMLNodes(inputSource: InputSource, parser: SAXParser): Seq[Node] = adapter.loadDocument(inputSource, parser.getXMLReader).children
61+
def loadXMLNodes(inputSource: InputSource, parser: SAXParser): Seq[Node] = adapter.loadDocument(inputSource, parser.getXMLReader).children.toSeq
6262
def adapter: parsing.FactoryAdapter = new parsing.NoBindingFactoryAdapter()
6363

6464
/** Loads XML Document. */
@@ -85,13 +85,13 @@ trait XMLLoader[T <: Node] {
8585
def loadString(string: String): T = getDocElem(loadStringDocument(string))
8686

8787
/** Load XML nodes, including comments and processing instructions that precede and follow the root element. */
88-
def loadNodes(inputSource: InputSource): Seq[Node] = loadDocument(inputSource).children
89-
def loadFileNodes(fileName: String): Seq[Node] = loadFileDocument(fileName).children
90-
def loadFileNodes(file: File): Seq[Node] = loadFileDocument(file).children
91-
def loadNodes(url: URL): Seq[Node] = loadDocument(url).children
92-
def loadNodes(sysId: String): Seq[Node] = loadDocument(sysId).children
93-
def loadFileNodes(fileDescriptor: FileDescriptor): Seq[Node] = loadFileDocument(fileDescriptor).children
94-
def loadNodes(inputStream: InputStream): Seq[Node] = loadDocument(inputStream).children
95-
def loadNodes(reader: Reader): Seq[Node] = loadDocument(reader).children
96-
def loadStringNodes(string: String): Seq[Node] = loadStringDocument(string).children
88+
def loadNodes(inputSource: InputSource): Seq[Node] = loadDocument(inputSource).children.toSeq
89+
def loadFileNodes(fileName: String): Seq[Node] = loadFileDocument(fileName).children.toSeq
90+
def loadFileNodes(file: File): Seq[Node] = loadFileDocument(file).children.toSeq
91+
def loadNodes(url: URL): Seq[Node] = loadDocument(url).children.toSeq
92+
def loadNodes(sysId: String): Seq[Node] = loadDocument(sysId).children.toSeq
93+
def loadFileNodes(fileDescriptor: FileDescriptor): Seq[Node] = loadFileDocument(fileDescriptor).children.toSeq
94+
def loadNodes(inputStream: InputStream): Seq[Node] = loadDocument(inputStream).children.toSeq
95+
def loadNodes(reader: Reader): Seq[Node] = loadDocument(reader).children.toSeq
96+
def loadStringNodes(string: String): Seq[Node] = loadStringDocument(string).children.toSeq
9797
}

shared/src/main/scala/scala/xml/parsing/NoBindingFactoryAdapter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class NoBindingFactoryAdapter extends FactoryAdapter with NodeFactory[Elem] {
2727

2828
/** From NodeFactory. Constructs an instance of scala.xml.Elem -- TODO: deprecate as in Elem */
2929
override protected def create(pre: String, label: String, attrs: MetaData, scope: NamespaceBinding, children: Seq[Node]): Elem =
30-
Elem(pre, label, attrs, scope, children.isEmpty, children: _*)
30+
Elem(pre, label, attrs, scope, children.isEmpty, children.toSeq: _*)
3131

3232
/** From FactoryAdapter. Creates a node. never creates the same node twice, using hash-consing.
3333
TODO: deprecate as in Elem, or forward to create?? */

shared/src/main/scala/scala/xml/transform/BasicTransformer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ abstract class BasicTransformer extends (Node => Node) {
4646
if (n.doTransform) n match {
4747
case Group(xs) => Group(transform(xs)) // un-group the hack Group tag
4848
case _ =>
49-
val ch: Seq[Node] = n.child
50-
val nch: Seq[Node] = transform(ch)
49+
val ch = n.child
50+
val nch = transform(ch)
5151

5252
if (ch.eq(nch)) n
53-
else Elem(n.prefix, n.label, n.attributes, n.scope, nch.isEmpty, nch: _*)
53+
else Elem(n.prefix, n.label, n.attributes, n.scope, nch.isEmpty, nch.toSeq: _*)
5454
}
5555
else n
5656

shared/src/test/scala/scala/xml/AttributeTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class AttributeTest {
167167

168168
@Test(expected=classOf[IllegalArgumentException])
169169
def invalidAttributeFailForMany(): Unit = {
170-
<x><y/><z/></x>.child \ "@"
170+
<x><y/><z/></x>.child \ "@" // implicit seqToNodeSeq
171171
}
172172

173173
@Test(expected=classOf[IllegalArgumentException])
@@ -177,6 +177,6 @@ class AttributeTest {
177177

178178
@Test(expected=classOf[IllegalArgumentException])
179179
def invalidEmptyAttributeFailForMany(): Unit = {
180-
<x><y/><z/></x>.child \@ ""
180+
<x><y/><z/></x>.child \@ "" // implicit seqToNodeSeq
181181
}
182182
}

shared/src/test/scala/scala/xml/NodeSeqTest.scala

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package scala.xml
22

3-
import scala.xml.NodeSeq.seqToNodeSeq
43
import org.junit.Test
54
import org.junit.Assert.assertEquals
65
import org.junit.Assert.fail
@@ -30,7 +29,7 @@ class NodeSeqTest {
3029
case res: Seq[Node] => assertEquals(2, res.size.toLong)
3130
case _: NodeSeq => fail("Should be Seq[Node] was NodeSeq") // Unreachable code?
3231
}
33-
val res: NodeSeq = a :+ b
32+
val res: NodeSeq = a :+ b // implicit seqToNodeSeq
3433
val exp: NodeSeq = NodeSeq.fromSeq(Seq(<a>Hello</a>, <b>Hi</b>))
3534
assertEquals(exp, res)
3635
}
@@ -59,23 +58,23 @@ class NodeSeqTest {
5958
case res: Seq[Node] => assertEquals(3, res.size.toLong)
6059
case _: NodeSeq => fail("Should be Seq[Node] was NodeSeq") // Unreachable code?
6160
}
62-
val res: NodeSeq = a ++: b ++: c
61+
val res: NodeSeq = a ++: b ++: c // implicit seqToNodeSeq
6362
val exp: NodeSeq = NodeSeq.fromSeq(Seq(<a>Hello</a>, <b>Hi</b>, <c>Hey</c>))
6463
assertEquals(exp, res)
6564
}
6665

6766
@Test
6867
def testMap(): Unit = {
6968
val a: NodeSeq = <a>Hello</a>
70-
val exp: NodeSeq = Seq(<b>Hi</b>)
69+
val exp: NodeSeq = Seq(<b>Hi</b>) // implicit seqToNodeSeq
7170
assertEquals(exp, a.map(_ => <b>Hi</b>))
7271
assertEquals(exp, for { _ <- a } yield { <b>Hi</b> })
7372
}
7473

7574
@Test
7675
def testFlatMap(): Unit = {
7776
val a: NodeSeq = <a>Hello</a>
78-
val exp: NodeSeq = Seq(<b>Hi</b>)
77+
val exp: NodeSeq = Seq(<b>Hi</b>) // implicit seqToNodeSeq
7978
assertEquals(exp, a.flatMap(_ => Seq(<b>Hi</b>)))
8079
assertEquals(exp, for { b <- a; _ <- b } yield { <b>Hi</b> })
8180
assertEquals(exp, for { b <- a; c <- b; _ <- c } yield { <b>Hi</b> })

shared/src/test/scala/scala/xml/ShouldCompile.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package scala.xml
55

66
import scala.collection._
77
import scala.collection.mutable.ArrayBuffer
8+
import scala.collection.immutable.{Seq => ISeq}
89

910
// t1761
1011
class Foo {
@@ -70,7 +71,7 @@ class Floozy {
7071

7172
object guardedMatch { // SI-3705
7273
// guard caused verifyerror in oldpatmat -- TODO: move this to compiler test suite
73-
def updateNodes(ns: Seq[Node]): Seq[Node] =
74+
def updateNodes(ns: ISeq[Node]): ISeq[Node] =
7475
for (subnode <- ns) yield subnode match {
7576
case <d>{ _ }</d> if true => <d>abc</d>
7677
case Elem(prefix, label, attribs, scope, children @ _*) =>

shared/src/test/scala/scala/xml/XMLTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ Ours is the portal of hope, come as you are."
521521
@UnitTest
522522
def i1976(): Unit = {
523523
val node: Elem = <node>{ "whatever " }</node>
524-
assertEquals("whatever ", node.child.text)
524+
assertEquals("whatever ", node.child.text) // implicit seqToNodeSeq
525525
}
526526

527527
@UnitTest

0 commit comments

Comments
 (0)