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

Change infix method calls o m a to o.m(a). #672

Merged
merged 1 commit into from
Jun 15, 2023
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
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ lazy val xml = crossProject(JSPlatform, JVMPlatform, NativePlatform)
file(jarPath)
-> url("http://docs.oracle.com/javase/8/docs/api")
)
} getOrElse {
}.getOrElse {
// If everything fails, jam in Java 11 modules.
Map(
file("/modules/java.base")
Expand Down
6 changes: 3 additions & 3 deletions jvm/src/test/scala-2.x/scala/xml/CompilerErrors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,12 @@ class CompilerTesting {

def expectXmlError(msg: String, code: String): Unit = {
val errors: List[String] = xmlErrorMessages(msg, code)
assert(errors exists (_ contains msg), errors mkString "\n")
assert(errors.exists(_.contains(msg)), errors.mkString("\n"))
}

def expectXmlErrors(msgCount: Int, msg: String, code: String): Unit = {
val errors: List[String] = xmlErrorMessages(msg, code)
val errorCount: Int = errors.count(_ contains msg)
assert(errorCount == msgCount, s"$errorCount occurrences of \'$msg\' found -- expected $msgCount in:\n${errors mkString "\n"}")
val errorCount: Int = errors.count(_.contains(msg))
assert(errorCount == msgCount, s"$errorCount occurrences of \'$msg\' found -- expected $msgCount in:\n${errors.mkString("\n")}")
}
}
6 changes: 3 additions & 3 deletions jvm/src/test/scala/scala/xml/ReuseNodesTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object ReuseNodesTest {

class OriginalTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) {
override def transform(ns: Seq[Node]): Seq[Node] = {
val xs: Seq[Seq[Node]] = ns.toStream map transform
val xs: Seq[Seq[Node]] = ns.toStream.map(transform)
val (xs1: Seq[(Seq[Node], Node)], xs2: Seq[(Seq[Node], Node)]) = xs.zip(ns).span { case (x, n) => unchanged(n, x) }

if (xs2.isEmpty) ns
Expand All @@ -30,7 +30,7 @@ object ReuseNodesTest {

class ModifiedTranformr(rules: RewriteRule*) extends RuleTransformer(rules:_*) {
override def transform(ns: Seq[Node]): Seq[Node] = {
val changed: Seq[Node] = ns flatMap transform
val changed: Seq[Node] = ns.flatMap(transform)

if (changed.length != ns.length || changed.zip(ns).exists(p => p._1 != p._2)) changed
else ns
Expand Down Expand Up @@ -93,7 +93,7 @@ class ReuseNodesTest {
recursiveAssert(original.child,transformed.child)
case _ =>
assertSame(original, transformed)
// No need to check for children, node being immuatable
// No need to check for children, node being immutable
// children can't be different if parents are referentially equal
}
}
Expand Down
41 changes: 20 additions & 21 deletions jvm/src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package scala.xml

import language.postfixOps
import org.junit.{Test => UnitTest}
import org.junit.Assert.{assertEquals, assertFalse, assertTrue}
import java.io.StringWriter
Expand Down Expand Up @@ -38,8 +37,8 @@ class XMLTestJVM {

assertEquals(c, parsedxml11)
assertEquals(parsedxml1, parsedxml11)
assertTrue(List(parsedxml1) sameElements List(parsedxml11))
assertTrue(Array(parsedxml1).toList sameElements List(parsedxml11))
assertTrue(List(parsedxml1).sameElements(List(parsedxml11)))
assertTrue(Array(parsedxml1).toList.sameElements(List(parsedxml11)))

val x2: String = "<book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book>"
val x2p: Elem = XML.loadString(x2)
Expand All @@ -52,66 +51,66 @@ class XMLTestJVM {

@UnitTest
def xpath(): Unit = {
assertTrue(parsedxml1 \ "_" sameElements List(Elem(null, "world", e, sc)))
assertTrue((parsedxml1 \ "_").sameElements(List(Elem(null, "world", e, sc))))

assertTrue(parsedxml1 \ "world" sameElements List(Elem(null, "world", e, sc)))
assertTrue((parsedxml1 \ "world").sameElements(List(Elem(null, "world", e, sc))))

assertTrue(
(parsedxml2 \ "_") sameElements List(
(parsedxml2 \ "_").sameElements(List(
Elem(null, "book", e, sc,
Elem(null, "author", e, sc, Text("Peter Buneman")),
Elem(null, "author", e, sc, Text("Dan Suciu")),
Elem(null, "title", e, sc, Text("Data on ze web"))),
Elem(null, "book", e, sc,
Elem(null, "author", e, sc, Text("John Mitchell")),
Elem(null, "title", e, sc, Text("Foundations of Programming Languages")))))
Elem(null, "title", e, sc, Text("Foundations of Programming Languages"))))))
assertTrue((parsedxml2 \ "author").isEmpty)

assertTrue(
(parsedxml2 \ "book") sameElements List(
(parsedxml2 \ "book").sameElements(List(
Elem(null, "book", e, sc,
Elem(null, "author", e, sc, Text("Peter Buneman")),
Elem(null, "author", e, sc, Text("Dan Suciu")),
Elem(null, "title", e, sc, Text("Data on ze web"))),
Elem(null, "book", e, sc,
Elem(null, "author", e, sc, Text("John Mitchell")),
Elem(null, "title", e, sc, Text("Foundations of Programming Languages")))))
Elem(null, "title", e, sc, Text("Foundations of Programming Languages"))))))

assertTrue(
(parsedxml2 \ "_" \ "_") sameElements List(
(parsedxml2 \ "_" \ "_").sameElements(List(
Elem(null, "author", e, sc, Text("Peter Buneman")),
Elem(null, "author", e, sc, Text("Dan Suciu")),
Elem(null, "title", e, sc, Text("Data on ze web")),
Elem(null, "author", e, sc, Text("John Mitchell")),
Elem(null, "title", e, sc, Text("Foundations of Programming Languages"))))
Elem(null, "title", e, sc, Text("Foundations of Programming Languages")))))

assertTrue(
(parsedxml2 \ "_" \ "author") sameElements List(
(parsedxml2 \ "_" \ "author").sameElements(List(
Elem(null, "author", e, sc, Text("Peter Buneman")),
Elem(null, "author", e, sc, Text("Dan Suciu")),
Elem(null, "author", e, sc, Text("John Mitchell"))))
Elem(null, "author", e, sc, Text("John Mitchell")))))

assertTrue((parsedxml2 \ "_" \ "_" \ "author").isEmpty)
}

@UnitTest
def xpathDESCENDANTS(): Unit = {
assertTrue(
(parsedxml2 \\ "author") sameElements List(
(parsedxml2 \\ "author").sameElements(List(
Elem(null, "author", e, sc, Text("Peter Buneman")),
Elem(null, "author", e, sc, Text("Dan Suciu")),
Elem(null, "author", e, sc, Text("John Mitchell"))))
Elem(null, "author", e, sc, Text("John Mitchell")))))

assertTrue(
(parsedxml2 \\ "title") sameElements List(
(parsedxml2 \\ "title").sameElements(List(
Elem(null, "title", e, sc, Text("Data on ze web")),
Elem(null, "title", e, sc, Text("Foundations of Programming Languages"))))
Elem(null, "title", e, sc, Text("Foundations of Programming Languages")))))

assertEquals("<book><author>Peter Buneman</author><author>Dan Suciu</author><title>Data on ze web</title></book>",
(parsedxml2 \\ "book") { (n: Node) => (n \ "title") xml_== "Data on ze web" }.toString)

assertTrue(
(NodeSeq.fromSeq(List(parsedxml2)) \\ "_") sameElements List(
(NodeSeq.fromSeq(List(parsedxml2)) \\ "_").sameElements(List(
Elem(null, "bib", e, sc,
Elem(null, "book", e, sc,
Elem(null, "author", e, sc, Text("Peter Buneman")),
Expand All @@ -131,7 +130,7 @@ class XMLTestJVM {
Elem(null, "author", e, sc, Text("John Mitchell")),
Elem(null, "title", e, sc, Text("Foundations of Programming Languages"))),
Elem(null, "author", e, sc, Text("John Mitchell")),
Elem(null, "title", e, sc, Text("Foundations of Programming Languages"))))
Elem(null, "title", e, sc, Text("Foundations of Programming Languages")))))
}

@UnitTest
Expand Down Expand Up @@ -196,7 +195,7 @@ class XMLTestJVM {
// println("x = " + x)
// println("y = " + y)
// println("x equals y: " + (x equals y) + ", y equals x: " + (y equals x))
assertTrue((x equals y) && (y equals x))
assertTrue(x.equals(y) && y.equals(x))
// println()
}
}
Expand Down Expand Up @@ -659,7 +658,7 @@ class XMLTestJVM {
val parent: org.xml.sax.XMLReader = xercesInternal.newSAXParser.getXMLReader
val filter: org.xml.sax.XMLFilter = new org.xml.sax.helpers.XMLFilterImpl(parent) {
override def characters(ch: Array[Char], start: Int, length: Int): Unit = {
for (i <- 0 until length) if (ch(start+i) == 'a') ch(start+i) = 'b'
for (i <- 0.until(length)) if (ch(start+i) == 'a') ch(start+i) = 'b'
super.characters(ch, start, length)
}
}
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/Comment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ case class Comment(commentText: String) extends SpecialNode {
* Appends &quot;<!-- text -->&quot; to this string buffer.
*/
override def buildString(sb: StringBuilder): StringBuilder =
sb append "<!--" append commentText append "-->"
sb.append("<!--").append(commentText).append("-->")
}
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/Elem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,5 @@ class Elem(
/**
* Returns concatenation of `text(n)` for each child `n`.
*/
override def text: String = (child map (_.text)).mkString
override def text: String = child.map(_.text).mkString
}
8 changes: 4 additions & 4 deletions shared/src/main/scala/scala/xml/Equality.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ object Equality {
}
def compareBlithely(x1: AnyRef, x2: AnyRef): Boolean = {
if (x1 == null || x2 == null)
return x1 eq x2
return x1.eq(x2)

x2 match {
case s: String => compareBlithely(x1, s)
Expand Down Expand Up @@ -108,9 +108,9 @@ trait Equality extends scala.Equals {
*/
private def doComparison(other: Any, blithe: Boolean): Boolean = {
val strictlyEqual: Boolean = other match {
case x: AnyRef if this eq x => true
case x: Equality => (x canEqual this) && (this strict_== x)
case _ => false
case x: AnyRef if this.eq(x) => true
case x: Equality => (x canEqual this) && (this strict_== x)
case _ => false
}

strictlyEqual || (blithe && compareBlithely(this, asRef(other)))
Expand Down
4 changes: 2 additions & 2 deletions shared/src/main/scala/scala/xml/Group.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final case class Group(nodes: Seq[Node]) extends Node {
}

override def strict_==(other: Equality): Boolean = other match {
case Group(xs) => nodes sameElements xs
case Group(xs) => nodes.sameElements(xs)
case _ => false
}

Expand All @@ -39,7 +39,7 @@ final case class Group(nodes: Seq[Node]) extends Node {
* Since Group is very much a hack it throws an exception if you
* try to do anything with it.
*/
private def fail(msg: String): Nothing = throw new UnsupportedOperationException("class Group does not support method '%s'" format msg)
private def fail(msg: String): Nothing = throw new UnsupportedOperationException("class Group does not support method '%s'".format(msg))

override def label: Nothing = fail("label")
override def attributes: Nothing = fail("attributes")
Expand Down
20 changes: 10 additions & 10 deletions shared/src/main/scala/scala/xml/MetaData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ object MetaData {
*/
@tailrec
def concatenate(attribs: MetaData, new_tail: MetaData): MetaData =
if (attribs eq Null) new_tail
else concatenate(attribs.next, attribs copy new_tail)
if (attribs.eq(Null)) new_tail
else concatenate(attribs.next, attribs.copy(new_tail))

/**
* returns normalized MetaData, with all duplicates removed and namespace prefixes resolved to
* namespace URIs via the given scope.
*/
def normalize(attribs: MetaData, scope: NamespaceBinding): MetaData = {
def iterate(md: MetaData, normalized_attribs: MetaData, set: Set[String]): MetaData = {
if (md eq Null) {
if (md.eq(Null)) {
normalized_attribs
} else if (md.value eq null) {
} else if (md.value.eq(null)) {
iterate(md.next, normalized_attribs, set)
} else {
val key: String = getUniversalKey(md, scope)
if (set(key)) {
iterate(md.next, normalized_attribs, set)
} else {
md copy iterate(md.next, normalized_attribs, set + key)
md.copy(iterate(md.next, normalized_attribs, set + key))
}
}
}
Expand Down Expand Up @@ -154,8 +154,8 @@ abstract class MetaData

/** filters this sequence of meta data */
override def filter(f: MetaData => Boolean): MetaData =
if (f(this)) copy(next filter f)
else next filter f
if (f(this)) copy(next.filter(f))
else next.filter(f)

def reverse: MetaData =
foldLeft(Null: MetaData) { (x, xs) =>
Expand All @@ -181,7 +181,7 @@ abstract class MetaData
* Returns a Map containing the attributes stored as key/value pairs.
*/
def asAttrMap: Map[String, String] =
(iterator map (x => (x.prefixedKey, x.value.text))).toMap
iterator.map(x => (x.prefixedKey, x.value.text)).toMap

/** returns Null or the next MetaData item */
def next: MetaData
Expand Down Expand Up @@ -217,9 +217,9 @@ abstract class MetaData
override def toString: String = sbToString(buildString)

def buildString(sb: StringBuilder): StringBuilder = {
sb append ' '
sb.append(' ')
toString1(sb)
next buildString sb
next.buildString(sb)
}

/**
Expand Down
13 changes: 6 additions & 7 deletions shared/src/main/scala/scala/xml/NamespaceBinding.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ package scala
package xml

import scala.collection.Seq
import Utility.sbToString

/**
* The class `NamespaceBinding` represents namespace bindings
Expand All @@ -30,7 +29,7 @@ case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBindin
throw new IllegalArgumentException("zero length prefix not allowed")

def getURI(_prefix: String): String =
if (prefix == _prefix) uri else parent getURI _prefix
if (prefix == _prefix) uri else parent.getURI(_prefix)

/**
* Returns some prefix that is mapped to the URI.
Expand All @@ -40,13 +39,13 @@ case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBindin
* if no prefix is mapped to the URI.
*/
def getPrefix(_uri: String): String =
if (_uri == uri) prefix else parent getPrefix _uri
if (_uri == uri) prefix else parent.getPrefix(_uri)

override def toString: String = sbToString(buildString(_, TopScope))
override def toString: String = Utility.sbToString(buildString(_, TopScope))

private def shadowRedefined(stop: NamespaceBinding): NamespaceBinding = {
def prefixList(x: NamespaceBinding): List[String] =
if ((x == null) || (x eq stop)) Nil
if ((x == null) || x.eq(stop)) Nil
else x.prefix :: prefixList(x.parent)
def fromPrefixList(l: List[String]): NamespaceBinding = l match {
case Nil => stop
Expand All @@ -70,7 +69,7 @@ case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBindin

override def basisForHashCode: Seq[Any] = List(prefix, uri, parent)

def buildString(stop: NamespaceBinding): String = sbToString(buildString(_, stop))
def buildString(stop: NamespaceBinding): String = Utility.sbToString(buildString(_, stop))

def buildString(sb: StringBuilder, stop: NamespaceBinding): Unit = {
shadowRedefined(stop).doBuildString(sb, stop)
Expand All @@ -83,6 +82,6 @@ case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBindin
if (prefix != null) ":" + prefix else "",
if (uri != null) uri else ""
)
parent.doBuildString(sb append s, stop) // copy(ignore)
parent.doBuildString(sb.append(s), stop) // copy(ignore)
}
}
12 changes: 6 additions & 6 deletions shared/src/main/scala/scala/xml/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ abstract class Node extends NodeSeq {
* @return the namespace if `scope != null` and prefix was
* found, else `null`
*/
def getNamespace(pre: String): String = if (scope eq null) null else scope.getURI(pre)
def getNamespace(pre: String): String = if (scope.eq(null)) null else scope.getURI(pre)

/**
* Convenience method, looks up an unprefixed attribute in attributes of this node.
Expand Down Expand Up @@ -124,7 +124,7 @@ abstract class Node extends NodeSeq {
/**
* Children which do not stringify to "" (needed for equality)
*/
def nonEmptyChildren: Seq[Node] = child filterNot (_.toString == "")
def nonEmptyChildren: Seq[Node] = child.filterNot(_.toString == "")

/**
* Descendant axis (all descendants of this node, not including node itself)
Expand Down Expand Up @@ -155,7 +155,7 @@ abstract class Node extends NodeSeq {
(label == x.label) &&
(attributes == x.attributes) &&
// (scope == x.scope) // note - original code didn't compare scopes so I left it as is.
(nonEmptyChildren sameElements x.nonEmptyChildren)
nonEmptyChildren.sameElements(x.nonEmptyChildren)
case _ =>
false
}
Expand Down Expand Up @@ -185,10 +185,10 @@ abstract class Node extends NodeSeq {
*/
def nameToString(sb: StringBuilder): StringBuilder = {
if (null != prefix) {
sb append prefix
sb append ':'
sb.append(prefix)
sb.append(':')
}
sb append label
sb.append(label)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/NodeBuffer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NodeBuffer extends scala.collection.mutable.ArrayBuffer[Node] with ScalaVe
def &+(o: Any): NodeBuffer = {
o match {
case null | _: Unit | Text("") => // ignore
case it: Iterator[_] => it foreach &+
case it: Iterator[_] => it.foreach(&+)
case n: Node => super.+=(n)
case ns: Iterable[_] => this &+ ns.iterator
case ns: Array[_] => this &+ ns.iterator
Expand Down
Loading