Skip to content

Commit

Permalink
Merge pull request #654 from dubinsky/very-minor-cleanup
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
dubinsky authored Mar 28, 2023
2 parents d93eb46 + 16374df commit cf5763e
Show file tree
Hide file tree
Showing 31 changed files with 131 additions and 146 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,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
12 changes: 6 additions & 6 deletions shared/src/main/scala/scala/xml/Attribute.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ trait Attribute extends MetaData {

override def remove(key: String): MetaData =
if (!isPrefixed && this.key == key) next
else copy(next remove key)
else copy(next.remove(key))

override def remove(namespace: String, scope: NamespaceBinding, key: String): MetaData =
if (this.key == key && (scope getURI pre) == namespace) next
if (this.key == key && scope.getURI(pre) == namespace) next
else copy(next.remove(namespace, scope, key))

override def isPrefixed: Boolean = pre != null

override def getNamespace(owner: Node): String

override def wellformed(scope: NamespaceBinding): Boolean = {
val arg: String = if (isPrefixed) scope getURI pre else null
(next(arg, scope, key) == null) && (next wellformed scope)
val arg: String = if (isPrefixed) scope.getURI(pre) else null
(next(arg, scope, key) == null) && next.wellformed(scope)
}

/** Returns an iterator on attributes */
Expand All @@ -98,9 +98,9 @@ trait Attribute extends MetaData {
if (value == null)
return
if (isPrefixed)
sb append pre append ':'
sb.append(pre).append(':')

sb append key append '='
sb.append(key).append('=')
val sb2: StringBuilder = new StringBuilder()
Utility.sequenceToXML(value, TopScope, sb2, stripComments = true)
Utility.appendQuoted(sb2.toString, sb)
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
2 changes: 1 addition & 1 deletion 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 Down
8 changes: 4 additions & 4 deletions shared/src/main/scala/scala/xml/MetaData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ object MetaData {
* attributes. Every instance of this class is either
* - an instance of `UnprefixedAttribute key,value` or
* - an instance of `PrefixedAttribute namespace_prefix,key,value` or
* - `Null, the empty attribute list.
* - `Null`, the empty attribute list.
*
* Namespace URIs are obtained by using the namespace scope of the element
* owning this attribute (see `getNamespace`).
Expand Down Expand Up @@ -204,17 +204,17 @@ abstract class MetaData
* @param uri namespace of key
* @param scope a namespace scp (usually of the element owning this attribute list)
* @param key to be looked fore
* @return value as Some[Seq[Node]] if key is found, None otherwise
* @return value as `Some[Seq[Node]]` if key is found, None otherwise
*/
final def get(uri: String, scope: NamespaceBinding, key: String): Option[Seq[Node]] =
Option(apply(uri, scope, key))

protected def toString1(): String = sbToString(toString1)
protected def toString1: String = sbToString(toString1)

// 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
8 changes: 4 additions & 4 deletions shared/src/main/scala/scala/xml/Node.scala
Original file line number Diff line number Diff line change
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
6 changes: 3 additions & 3 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 All @@ -128,7 +128,7 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S
/**
* Projection function, which returns elements of `this` sequence and of
* all its subsequences, based on the string `that`. Use:
* - `this \\ "foo" to get a list of all elements that are labelled with `"foo"`,
* - `this \\ "foo"` to get a list of all elements that are labelled with "foo"`,
* including `this`;
* - `this \\ "_"` to get a list of all elements (wildcard), including `this`;
* - `this \\ "@foo"` to get all unprefixed attributes `"foo"`;
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
}
7 changes: 3 additions & 4 deletions shared/src/main/scala/scala/xml/Null.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package scala
package xml

import Utility.isNameStart
import scala.collection.Iterator
import scala.collection.Seq

Expand Down Expand Up @@ -50,13 +49,13 @@ case object Null extends MetaData {

override def apply(namespace: String, scope: NamespaceBinding, key: String) /* TODO type annotation */ = null
override def apply(key: String) /* TODO type annotation */ =
if (isNameStart(key.head)) null
if (Utility.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 protected def toString1: String = ""

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

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

Expand Down
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/SpecialNode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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 */
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
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
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/XML.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ object XML extends XMLLoader[Elem] {
final def write(w: java.io.Writer, node: Node, enc: String, xmlDecl: Boolean, doctype: dtd.DocType, minimizeTags: MinimizeMode.Value = MinimizeMode.Default): Unit = {
/* TODO: optimize by giving writer parameter to toXML*/
if (xmlDecl) w.write("<?xml version='1.0' encoding='" + enc + "'?>\n")
if (doctype ne null) w.write(doctype.toString() + "\n")
if (doctype ne null) w.write(doctype.toString + "\n")
w.write(Utility.serialize(node, minimizeTags = minimizeTags).toString)
}
}
8 changes: 4 additions & 4 deletions shared/src/main/scala/scala/xml/dtd/Decl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,22 @@ case class PEReference(ent: String) extends MarkupDecl {
// default declarations for attributes

sealed abstract class DefaultDecl {
override def toString(): String
def toString: String
def buildString(sb: StringBuilder): StringBuilder
}

case object REQUIRED extends DefaultDecl {
override def toString(): String = "#REQUIRED"
override def toString: String = "#REQUIRED"
override def buildString(sb: StringBuilder): StringBuilder = sb append "#REQUIRED"
}

case object IMPLIED extends DefaultDecl {
override def toString(): String = "#IMPLIED"
override def toString: String = "#IMPLIED"
override def buildString(sb: StringBuilder): StringBuilder = sb append "#IMPLIED"
}

case class DEFAULT(fixed: Boolean, attValue: String) extends DefaultDecl {
override def toString(): String = sbToString(buildString)
override def toString: String = sbToString(buildString)
override def buildString(sb: StringBuilder): StringBuilder = {
if (fixed) sb append "#FIXED "
Utility.appendEscapedQuoted(attValue, sb)
Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/dtd/DocType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ case class DocType(name: String, extID: ExternalID, intSubset: Seq[dtd.Decl]) {
if (intSubset.isEmpty) ""
else intSubset.mkString("[", "", "]")

"""<!DOCTYPE %s %s%s>""".format(name, extID.toString(), intString)
"""<!DOCTYPE %s %s%s>""".format(name, extID.toString, intString)
}
}

Expand Down
2 changes: 1 addition & 1 deletion shared/src/main/scala/scala/xml/dtd/ExternalID.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ sealed abstract class ExternalID extends parsing.TokenTests {
(if (systemId == null) "" else " " + quotedSystemLiteral)
}
def buildString(sb: StringBuilder): StringBuilder =
sb.append(this.toString())
sb.append(this.toString)

def systemId: String
def publicId: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object MakeValidationException {
val sb: StringBuilder = new StringBuilder("missing value for REQUIRED attribute")
if (allKeys.size > 1) sb.append('s')
allKeys foreach (k => sb append "'%s'".format(k))
ValidationException(sb.toString())
ValidationException(sb.toString)
}

def fromMissingAttribute(key: String, tpe: String): ValidationException =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import scala.collection.Seq

/**
* This class turns a regular expression over `A` into a
* [[scala.util.automata.NondetWordAutom]] over `A` using the celebrated
* [[scala.xml.dtd.impl.NondetWordAutom]] over `A` using the celebrated
* position automata construction (also called ''Berry-Sethi'' or ''Glushkov'').
*/
@deprecated("This class will be removed", "2.10.0")
Expand Down
Loading

0 comments on commit cf5763e

Please sign in to comment.