Skip to content

Minor cleanup #649

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

Closed
wants to merge 1 commit into from
Closed
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
19 changes: 17 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,22 @@ lazy val xml = crossProject(JSPlatform, JVMPlatform, NativePlatform)

// necessitated by the introduction of new abstract methods in FactoryAdapter:
exclude[ReversedMissingMethodProblem]("scala.xml.parsing.FactoryAdapter.createComment"), // see #549
exclude[ReversedMissingMethodProblem]("scala.xml.parsing.FactoryAdapter.createPCData") // see #558
exclude[ReversedMissingMethodProblem]("scala.xml.parsing.FactoryAdapter.createPCData"), // see #558

// adding type annotations with types different from those inferred by (some versions of) the Scala compiler
exclude[DirectAbstractMethodProblem]("scala.xml.Node.child"),
exclude[DirectAbstractMethodProblem]("scala.xml.MetaData.value"),
exclude[DirectAbstractMethodProblem]("scala.xml.MetaData.apply"),
exclude[IncompatibleSignatureProblem]("scala.xml.Node.unapplySeq"),
exclude[IncompatibleSignatureProblem]("scala.xml.Elem.unapplySeq"),
exclude[IncompatibleResultTypeProblem]("scala.xml.Null.apply"),
exclude[IncompatibleResultTypeProblem]("scala.xml.Null.getNamespace"),
exclude[IncompatibleResultTypeProblem]("scala.xml.Null.key"),
exclude[IncompatibleResultTypeProblem]("scala.xml.Null.next"),
exclude[IncompatibleResultTypeProblem]("scala.xml.Null.remove"),
exclude[IncompatibleResultTypeProblem]("scala.xml.Null.value"),
exclude[IncompatibleResultTypeProblem]("scala.xml.dtd.NoExternalID.publicId"),
exclude[IncompatibleResultTypeProblem]("scala.xml.dtd.NoExternalID.systemId")
)
},
// Mima signature checking stopped working after 3.0.2 upgrade, see #557
Expand Down Expand Up @@ -150,7 +165,7 @@ lazy val xml = crossProject(JSPlatform, JVMPlatform, NativePlatform)
retrieveDir,
log
)
.fold(w => throw w.resolveException, identity(_))
.fold(w => throw w.resolveException, identity)
val jarPath = cp
.find(_.toString.contains("junit-plugin"))
.getOrElse(throw new Exception("Can't find Scala Native junit-plugin jar"))
Expand Down
5 changes: 2 additions & 3 deletions jvm/src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class XMLTestJVM {
def equality(): Unit = {
val c: Node = new Node {
override def label: String = "hello"
override def hashCode(): Int =
override def hashCode: Int =
Utility.hashCode(prefix, label, this.attributes.hashCode(), scope.hashCode(), child)
override def child: Seq[Node] = Elem(null, "world", e, sc)
//def attributes = e
Expand All @@ -54,7 +54,6 @@ class XMLTestJVM {
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"))), x2p)

}

@UnitTest
Expand Down Expand Up @@ -640,7 +639,7 @@ class XMLTestJVM {
parserFactory.setNamespaceAware(namespaceAware)
parserFactory.setXIncludeAware(namespaceAware)

assertEquals(xml, XML.withSAXParser(parserFactory.newSAXParser).loadString(xml).toString())
assertEquals(xml, XML.withSAXParser(parserFactory.newSAXParser).loadString(xml).toString)
}

@UnitTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@

package scala.xml

import scala.collection.SeqLike
import scala.collection.{SeqLike, mutable}
import scala.collection.generic.CanBuildFrom

private[xml] object ScalaVersionSpecific {
import NodeSeq.Coll
type CBF[-From, -A, +C] = CanBuildFrom[From, A, C]
object NodeSeqCBF extends CanBuildFrom[Coll, Node, NodeSeq] {
override def apply(from: Coll) /* TODO type annotation */ = NodeSeq.newBuilder
override def apply() /* TODO type annotation */ = NodeSeq.newBuilder
override def apply(from: Coll): mutable.Builder[Node, Coll] = NodeSeq.newBuilder
override def apply(): mutable.Builder[Node, Coll] = NodeSeq.newBuilder
}
}

private[xml] trait ScalaVersionSpecificNodeSeq extends SeqLike[Node, NodeSeq] { self: NodeSeq =>
/** Creates a list buffer as builder for this class */
override protected[this] def newBuilder /* TODO type annotation */ = NodeSeq.newBuilder
override protected[this] def newBuilder: mutable.Builder[Node, NodeSeq] = NodeSeq.newBuilder
}

private[xml] trait ScalaVersionSpecificNodeBuffer { self: NodeBuffer =>
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/Attribute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import scala.collection.Seq
* @author Burak Emir
*/
object Attribute {
def unapply(x: Attribute) /* TODO type annotation */ = x match {
def unapply(x: Attribute): Option[(String, Seq[Node], MetaData)] = x match {
case PrefixedAttribute(_, key, value, next) => Some((key, value, next))
case UnprefixedAttribute(key, value, next) => Some((key, value, next))
case _ => None
Expand Down
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 @@ -26,7 +26,7 @@ object Elem {
def apply(prefix: String, label: String, attributes: MetaData, scope: NamespaceBinding, minimizeEmpty: Boolean, child: Node*): Elem =
new Elem(prefix, label, attributes, scope, minimizeEmpty, child: _*)

def unapplySeq(n: Node) /* TODO type annotation */ = n match {
def unapplySeq(n: Node): Option[(String, String, MetaData, NamespaceBinding, scala.collection.immutable.Seq[scala.xml.Node])] = n match {
case _: SpecialNode | _: Group => None
case _ => Some((n.prefix, n.label, n.attributes, n.scope, n.child.toSeq))
}
Expand Down
4 changes: 2 additions & 2 deletions shared/src/main/scala/scala/xml/Equality.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ trait Equality extends scala.Equals {
* which heads off a lot of inconsistency up front.
*/
override def canEqual(other: Any): Boolean = other match {
case x: Equality => true
case _: Equality => true
case _ => false
}

Expand All @@ -96,7 +96,7 @@ trait Equality extends scala.Equals {
* are final since clearly individual classes cannot be trusted
* to maintain a semblance of order.
*/
override def hashCode(): Int = basisForHashCode.##
override def hashCode: Int = basisForHashCode.##
override def equals(other: Any): Boolean = doComparison(other, blithe = false)
final def xml_==(other: Any): Boolean = doComparison(other, blithe = true)
final def xml_!=(other: Any): Boolean = !xml_==(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 @@ -24,7 +24,7 @@ final case class Group(nodes: Seq[Node]) extends Node {
override def theSeq: Seq[Node] = nodes

override def canEqual(other: Any): Boolean = other match {
case x: Group => true
case _: Group => true
case _ => false
}

Expand All @@ -44,6 +44,6 @@ final case class Group(nodes: Seq[Node]) extends Node {
override def label: Nothing = fail("label")
override def attributes: Nothing = fail("attributes")
override def namespace: Nothing = fail("namespace")
override def child /* TODO type annotation */ = fail("child")
override def child: Nothing = fail("child")
def buildString(sb: StringBuilder): Nothing = fail("toString(StringBuilder)")
}
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/MetaData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ abstract class MetaData
// appends string representations of single attribute to StringBuilder
protected def toString1(sb: StringBuilder): Unit

override def toString(): String = sbToString(buildString)
override def toString: String = sbToString(buildString)

def buildString(sb: StringBuilder): StringBuilder = {
sb append ' '
Expand Down
10 changes: 5 additions & 5 deletions shared/src/main/scala/scala/xml/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Node {
/** the empty namespace */
val EmptyNamespace: String = ""

def unapplySeq(n: Node) /* TODO type annotation */ = Some((n.label, n.attributes, n.child.toSeq))
def unapplySeq(n: Node): Some[(String, MetaData, Seq[Node])] = Some((n.label, n.attributes, n.child.toSeq))
}

/**
Expand Down Expand Up @@ -140,8 +140,8 @@ abstract class Node extends NodeSeq {
def descendant_or_self: List[Node] = this :: descendant

override def canEqual(other: Any): Boolean = other match {
case x: Group => false
case x: Node => true
case _: Group => false
case _: Node => true
case _ => false
}

Expand Down Expand Up @@ -178,7 +178,7 @@ abstract class Node extends NodeSeq {
/**
* Same as `toString('''false''')`.
*/
override def toString(): String = buildString(stripComments = false)
override def toString: String = buildString(stripComments = false)

/**
* Appends qualified name of this node to `StringBuilder`.
Expand All @@ -194,7 +194,7 @@ abstract class Node extends NodeSeq {
/**
* Returns a type symbol (e.g. DTD, XSD), default `'''null'''`.
*/
def xmlType(): TypeSymbol = null
def xmlType: TypeSymbol = null

/**
* Returns a text representation of this node. Note that this is not equivalent to
Expand Down
4 changes: 2 additions & 2 deletions shared/src/main/scala/scala/xml/NodeSeq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
else if (that(1) == '{') {
val i: Int = that indexOf '}'
if (i == -1) fail
val (uri: String, key: String) = (that.substring(2, i), that.substring(i + 1, that.length()))
val (uri: String, key: String) = (that.substring(2, i), that.substring(i + 1, that.length))
if (uri == "" || key == "") fail
else y.attribute(uri, key)
} else y.attribute(that drop 1)
Expand Down Expand Up @@ -159,7 +159,7 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
*/
def \@(attributeName: String): String = (this \ ("@" + attributeName)).text

override def toString(): String = theSeq.mkString
override def toString: String = theSeq.mkString

def text: String = (this map (_.text)).mkString
}
20 changes: 10 additions & 10 deletions shared/src/main/scala/scala/xml/Null.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ import scala.collection.Seq
* @author Burak Emir
*/
case object Null extends MetaData {
override def iterator /* TODO type annotation */ = Iterator.empty
override def iterator: Iterator[Nothing] = Iterator.empty
override def size: Int = 0
override def append(m: MetaData, scope: NamespaceBinding = TopScope): MetaData = m
override def filter(f: MetaData => Boolean): MetaData = this

override def copy(next: MetaData): MetaData = next
override def getNamespace(owner: Node) /* TODO type annotation */ = null
override def getNamespace(owner: Node): scala.Null = null

override def hasNext: Boolean = false
override def next /* TODO type annotation */ = null
override def key /* TODO type annotation */ = null
override def value /* TODO type annotation */ = null
override def next: scala.Null = null
override def key: scala.Null = null
override def value: scala.Null = null
override def isPrefixed: Boolean = false

override def length: Int = 0
Expand All @@ -48,20 +48,20 @@ case object Null extends MetaData {
}
override protected def basisForHashCode: Seq[Any] = Nil

override def apply(namespace: String, scope: NamespaceBinding, key: String) /* TODO type annotation */ = null
override def apply(key: String) /* TODO type annotation */ =
override def apply(namespace: String, scope: NamespaceBinding, key: String): scala.Null = null
override def apply(key: String): scala.Null =
if (isNameStart(key.head)) null
else throw new IllegalArgumentException("not a valid attribute name '" + key + "', so can never match !")

override protected def toString1(sb: StringBuilder): Unit = ()
override protected def toString1(): String = ""

override def toString(): String = ""
override def toString: String = ""

override def buildString(sb: StringBuilder): StringBuilder = sb

override def wellformed(scope: NamespaceBinding): Boolean = true

override def remove(key: String) /* TODO type annotation */ = this
override def remove(namespace: String, scope: NamespaceBinding, key: String) /* TODO type annotation */ = this
override def remove(key: String): Null.type = this
override def remove(namespace: String, scope: NamespaceBinding, key: String): Null.type = this
}
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/PrefixedAttribute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ class PrefixedAttribute(
}

object PrefixedAttribute {
def unapply(x: PrefixedAttribute) /* TODO type annotation */ = Some((x.pre, x.key, x.value, x.next))
def unapply(x: PrefixedAttribute): Some[(String, String, Seq[Node], MetaData)] = Some((x.pre, x.key, x.value, x.next))
}
6 changes: 3 additions & 3 deletions shared/src/main/scala/scala/xml/PrettyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) {

protected def traverse(node: Node, pscope: NamespaceBinding, ind: Int): Unit = node match {

case Text(s) if s.trim() == "" =>
case Text(s) if s.trim == "" =>

case _: Atom[_] | _: Comment | _: EntityRef | _: ProcInstr =>
makeBox(ind, node.toString().trim())
case g@Group(xs) =>
makeBox(ind, node.toString.trim)
case Group(xs) =>
traverse(xs.iterator, pscope, ind)
case _ =>
val test: String = {
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/QNode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ package xml
* @author Burak Emir
*/
object QNode {
def unapplySeq(n: Node) /* TODO type annotation */ = Some((n.scope.getURI(n.prefix), n.label, n.attributes, n.child.toSeq))
def unapplySeq(n: Node): Some[(String, String, MetaData, Seq[Node])] = Some((n.scope.getURI(n.prefix), n.label, n.attributes, n.child.toSeq))
}
4 changes: 2 additions & 2 deletions shared/src/main/scala/scala/xml/SpecialNode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ abstract class SpecialNode extends Node {
/** always empty */
final override def attributes: Null.type = Null

/** always Node.EmptyNamespace */
/** always Node.EmptyNamespace - TODO not really: Node.EmptyNamespace is "", but this is null. */
final override def namespace: scala.Null = null

/** always empty */
final override def child /* TODO type annotation */ = Nil
final override def child: Nil.type = Nil

/** Append string representation to the given string buffer argument. */
def buildString(sb: StringBuilder): StringBuilder
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/TopScope.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object TopScope extends NamespaceBinding(null, null, null) {
override def getPrefix(uri1: String): String =
if (uri1 == namespace) xml else null

override def toString(): String = ""
override def toString: String = ""

override def buildString(stop: NamespaceBinding): String = ""
override def buildString(sb: StringBuilder, ignore: NamespaceBinding): Unit = ()
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/UnprefixedAttribute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ class UnprefixedAttribute(
next(namespace, scope, key)
}
object UnprefixedAttribute {
def unapply(x: UnprefixedAttribute) /* TODO type annotation */ = Some((x.key, x.value, x.next))
def unapply(x: UnprefixedAttribute): Some[(String, Seq[Node], MetaData)] = Some((x.key, x.value, x.next))
}
25 changes: 14 additions & 11 deletions shared/src/main/scala/scala/xml/Utility.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object Utility extends AnyRef with parsing.TokenTests {

// [Martin] This looks dubious. We don't convert StringBuilders to
// Strings anywhere else, why do it here?
implicit def implicitSbToString(sb: StringBuilder): String = sb.toString()
implicit def implicitSbToString(sb: StringBuilder): String = sb.toString

// helper for the extremely oft-repeated sequence of creating a
// StringBuilder, passing it around, and then grabbing its String.
Expand All @@ -50,7 +50,7 @@ object Utility extends AnyRef with parsing.TokenTests {
*/
def trim(x: Node): Node = x match {
case Elem(pre, lab, md, scp, child@_*) =>
val children: Seq[Node] = combineAdjacentTextNodes(child) flatMap trimProper
val children: Seq[Node] = combineAdjacentTextNodes(child).flatMap(trimProper)
Elem(pre, lab, md, scp, children.isEmpty, children: _*)
}

Expand All @@ -67,7 +67,7 @@ object Utility extends AnyRef with parsing.TokenTests {
*/
def trimProper(x: Node): Seq[Node] = x match {
case Elem(pre, lab, md, scp, child@_*) =>
val children: Seq[Node] = combineAdjacentTextNodes(child) flatMap trimProper
val children: Seq[Node] = combineAdjacentTextNodes(child).flatMap(trimProper)
Elem(pre, lab, md, scp, children.isEmpty, children: _*)
case Text(s) =>
new TextBuffer().append(s).toText
Expand Down Expand Up @@ -173,7 +173,7 @@ object Utility extends AnyRef with parsing.TokenTests {
// minimizeTags: Boolean = false): String =
// {
// toXMLsb(x, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags)
// sb.toString()
// sb.toString
// }

/**
Expand Down Expand Up @@ -263,13 +263,16 @@ object Utility extends AnyRef with parsing.TokenTests {
} else children foreach { serialize(_, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) }
}

def splitName(name: String): (Option[String], String) = {
val colon: Int = name.indexOf(':')
if (colon < 0) (None, name)
else (Some(name.take(colon)), name.drop(colon + 1))
}

/**
* Returns prefix of qualified name if any.
*/
final def prefix(name: String): Option[String] = name.indexOf(':') match {
case -1 => None
case i => Some(name.substring(0, i))
}
final def prefix(name: String): Option[String] = splitName(name)._1

/**
* Returns a hashcode for the given constituents of a node
Expand Down Expand Up @@ -357,12 +360,12 @@ object Utility extends AnyRef with parsing.TokenTests {
rfb.append(c)
c = it.next()
}
val ref: String = rfb.toString()
val ref: String = rfb.toString
rfb.clear()
unescape(ref, sb) match {
case null =>
if (sb.nonEmpty) { // flush buffer
nb += Text(sb.toString())
nb += Text(sb.toString)
sb.clear()
}
nb += EntityRef(ref) // add entityref
Expand All @@ -372,7 +375,7 @@ object Utility extends AnyRef with parsing.TokenTests {
} else sb append c
}
if (sb.nonEmpty) { // flush buffer
val x: Text = Text(sb.toString())
val x: Text = Text(sb.toString)
if (nb.isEmpty)
return x
else
Expand Down
Loading