diff --git a/jvm/src/test/scala/scala/xml/XMLTest.scala b/jvm/src/test/scala/scala/xml/XMLTest.scala index 9d14219b..a978e4bf 100644 --- a/jvm/src/test/scala/scala/xml/XMLTest.scala +++ b/jvm/src/test/scala/scala/xml/XMLTest.scala @@ -2,8 +2,8 @@ package scala.xml import org.junit.{Test => UnitTest} import org.junit.Assert.{assertEquals, assertFalse, assertNull, assertThrows, assertTrue} -import java.io.StringWriter -import java.io.ByteArrayOutputStream +import java.io.{ByteArrayInputStream, ByteArrayOutputStream, InputStreamReader, IOException, ObjectInputStream, + ObjectOutputStream, OutputStreamWriter, PrintStream, StringWriter} import java.net.URL import scala.xml.dtd.{DocType, PublicID} import scala.xml.parsing.ConstructingParser @@ -177,26 +177,26 @@ class XMLTestJVM { """, f("a,b,c").toString) object Serialize { - @throws(classOf[java.io.IOException]) + @throws(classOf[IOException]) def write[A](o: A): Array[Byte] = { val ba: ByteArrayOutputStream = new ByteArrayOutputStream(512) - val out: java.io.ObjectOutputStream = new java.io.ObjectOutputStream(ba) + val out: ObjectOutputStream = new ObjectOutputStream(ba) out.writeObject(o) out.close() ba.toByteArray } - @throws(classOf[java.io.IOException]) + @throws(classOf[IOException]) @throws(classOf[ClassNotFoundException]) def read[A](buffer: Array[Byte]): A = { - val in: java.io.ObjectInputStream = - new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(buffer)) + val in: ObjectInputStream = + new ObjectInputStream(new ByteArrayInputStream(buffer)) in.readObject().asInstanceOf[A] } def check[A, B](x: A, y: B): Unit = { // 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)) + // println("x == y: " + (x == y) + ", y == x: " + (y == x)) + assertTrue(x == y && y == x) // println() } } @@ -296,14 +296,14 @@ class XMLTestJVM { // scala.xml.XML.save("foo.xml", xml) // scala.xml.XML.loadFile("foo.xml").toString - val outputStream: java.io.ByteArrayOutputStream = new java.io.ByteArrayOutputStream - val streamWriter: java.io.OutputStreamWriter = new java.io.OutputStreamWriter(outputStream, "UTF-8") + val outputStream: ByteArrayOutputStream = new ByteArrayOutputStream + val streamWriter: OutputStreamWriter = new OutputStreamWriter(outputStream, "UTF-8") XML.write(streamWriter, xml, XML.encoding, xmlDecl = false, null) streamWriter.flush() - val inputStream: java.io.ByteArrayInputStream = new java.io.ByteArrayInputStream(outputStream.toByteArray) - val streamReader: java.io.InputStreamReader = new java.io.InputStreamReader(inputStream, XML.encoding) + val inputStream: ByteArrayInputStream = new ByteArrayInputStream(outputStream.toByteArray) + val streamReader: InputStreamReader = new InputStreamReader(inputStream, XML.encoding) assertEquals(xml.toString, XML.load(streamReader).toString) } @@ -492,8 +492,6 @@ class XMLTestJVM { @UnitTest def dontLoop(): Unit = { - import java.io.{ Console => _, _ } - val xml: String = " " val sink: PrintStream = new PrintStream(new ByteArrayOutputStream()) Console.withOut(sink) { @@ -1026,7 +1024,7 @@ class XMLTestJVM { def toSource(s: String): scala.io.Source = new scala.io.Source { override val iter: Iterator[Char] = s.iterator - override def reportError(pos: Int, msg: String, out: java.io.PrintStream = Console.err): Unit = () + override def reportError(pos: Int, msg: String, out: PrintStream = Console.err): Unit = () } @UnitTest diff --git a/shared/src/main/scala/scala/xml/Attribute.scala b/shared/src/main/scala/scala/xml/Attribute.scala index cb2b2d97..97457ab7 100644 --- a/shared/src/main/scala/scala/xml/Attribute.scala +++ b/shared/src/main/scala/scala/xml/Attribute.scala @@ -81,15 +81,13 @@ trait Attribute extends MetaData { } /** Returns an iterator on attributes */ - override def iterator: Iterator[MetaData] = { + override def iterator: Iterator[MetaData] = if (value == null) next.iterator else Iterator.single(this) ++ next.iterator - } - override def size: Int = { + override def size: Int = if (value == null) next.size else 1 + next.size - } /** * Appends string representation of only this attribute to stringbuffer. diff --git a/shared/src/main/scala/scala/xml/Comment.scala b/shared/src/main/scala/scala/xml/Comment.scala index aee8dc07..6c27a025 100644 --- a/shared/src/main/scala/scala/xml/Comment.scala +++ b/shared/src/main/scala/scala/xml/Comment.scala @@ -29,12 +29,11 @@ case class Comment(commentText: String) extends SpecialNode { final override def doCollectNamespaces: Boolean = false final override def doTransform: Boolean = false - if (commentText.contains("--")) { + if (commentText.contains("--")) throw new IllegalArgumentException(s"""text contains "--"""") - } - if (commentText.nonEmpty && commentText.charAt(commentText.length - 1) == '-') { + + if (commentText.nonEmpty && commentText.charAt(commentText.length - 1) == '-') throw new IllegalArgumentException("The final character of a XML comment may not be '-'. See https://www.w3.org/TR/xml11//#IDA5CES") - } /** * Appends "" to this string buffer. diff --git a/shared/src/main/scala/scala/xml/Equality.scala b/shared/src/main/scala/scala/xml/Equality.scala index d2b6e8ca..3b48b282 100644 --- a/shared/src/main/scala/scala/xml/Equality.scala +++ b/shared/src/main/scala/scala/xml/Equality.scala @@ -61,18 +61,13 @@ object Equality { case x: NodeSeq if x.length == 1 => x2 == x(0) case _ => false } - def compareBlithely(x1: AnyRef, x2: AnyRef): Boolean = { - if (x1 == null || x2 == null) - return x1.eq(x2) - - x2 match { + def compareBlithely(x1: AnyRef, x2: AnyRef): Boolean = + if (x1 == null || x2 == null) x1 == null && x2 == null else x2 match { case s: String => compareBlithely(x1, s) case n: Node => compareBlithely(x1, n) case _ => false } - } } -import Equality._ trait Equality extends scala.Equals { protected def basisForHashCode: Seq[Any] @@ -109,10 +104,10 @@ 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 x: Equality => x.canEqual(this) && this.strict_==(x) case _ => false } - strictlyEqual || (blithe && compareBlithely(this, asRef(other))) + strictlyEqual || (blithe && Equality.compareBlithely(this, Equality.asRef(other))) } } diff --git a/shared/src/main/scala/scala/xml/MetaData.scala b/shared/src/main/scala/scala/xml/MetaData.scala index b55b3187..97931133 100644 --- a/shared/src/main/scala/scala/xml/MetaData.scala +++ b/shared/src/main/scala/scala/xml/MetaData.scala @@ -29,7 +29,7 @@ object MetaData { */ @tailrec def concatenate(attribs: MetaData, new_tail: MetaData): MetaData = - if (attribs.eq(Null)) new_tail + if (attribs.isNull) new_tail else concatenate(attribs.next, attribs.copy(new_tail)) /** @@ -37,20 +37,19 @@ object MetaData { * 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)) { + def iterate(md: MetaData, normalized_attribs: MetaData, set: Set[String]): MetaData = + if (md.isNull) { normalized_attribs - } else if (md.value.eq(null)) { + } else if (md.value == null) iterate(md.next, normalized_attribs, set) - } else { + else { val key: String = getUniversalKey(md, scope) - if (set(key)) { + if (set(key)) iterate(md.next, normalized_attribs, set) - } else { + else md.copy(iterate(md.next, normalized_attribs, set + key)) - } } - } + iterate(attribs, Null, Set()) } @@ -85,7 +84,9 @@ abstract class MetaData extends AbstractIterable[MetaData] with Iterable[MetaData] with Equality - with Serializable { + with Serializable +{ + private[xml] def isNull: Boolean = this.eq(Null) /** * Updates this MetaData with the MetaData given as argument. All attributes that occur in updates diff --git a/shared/src/main/scala/scala/xml/NamespaceBinding.scala b/shared/src/main/scala/scala/xml/NamespaceBinding.scala index 7e851eda..8efe27d7 100644 --- a/shared/src/main/scala/scala/xml/NamespaceBinding.scala +++ b/shared/src/main/scala/scala/xml/NamespaceBinding.scala @@ -29,8 +29,8 @@ case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBindin if (prefix == "") throw new IllegalArgumentException("zero length prefix not allowed") - def getURI(_prefix: String): String = - if (prefix == _prefix) uri else parent.getURI(_prefix) + def getURI(prefix: String): String = + if (this.prefix == prefix) uri else parent.getURI(prefix) /** * Returns some prefix that is mapped to the URI. @@ -39,8 +39,8 @@ case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBindin * @return the prefix that is mapped to the input URI, or null * if no prefix is mapped to the URI. */ - def getPrefix(_uri: String): String = - if (_uri == uri) prefix else parent.getPrefix(_uri) + def getPrefix(uri: String): String = + if (uri == this.uri) prefix else parent.getPrefix(uri) override def toString: String = Utility.sbToString(buildString(_, TopScope)) @@ -72,9 +72,8 @@ case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBindin def buildString(stop: NamespaceBinding): String = Utility.sbToString(buildString(_, stop)) - def buildString(sb: StringBuilder, stop: NamespaceBinding): Unit = { + def buildString(sb: StringBuilder, stop: NamespaceBinding): Unit = shadowRedefined(stop).doBuildString(sb, stop) - } private def doBuildString(sb: StringBuilder, stop: NamespaceBinding): Unit = { if (List(null, stop, TopScope).contains(this)) return diff --git a/shared/src/main/scala/scala/xml/Node.scala b/shared/src/main/scala/scala/xml/Node.scala index ff719ec4..f5337eee 100755 --- a/shared/src/main/scala/scala/xml/Node.scala +++ b/shared/src/main/scala/scala/xml/Node.scala @@ -82,7 +82,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 == null) null else scope.getURI(pre) /** * Convenience method, looks up an unprefixed attribute in attributes of this node. @@ -125,7 +125,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.isEmpty) /** * Descendant axis (all descendants of this node, not including node itself) diff --git a/shared/src/main/scala/scala/xml/NodeSeq.scala b/shared/src/main/scala/scala/xml/NodeSeq.scala index cbb5b047..bdf316f9 100644 --- a/shared/src/main/scala/scala/xml/NodeSeq.scala +++ b/shared/src/main/scala/scala/xml/NodeSeq.scala @@ -103,7 +103,7 @@ abstract class NodeSeq extends AbstractSeq[Node] with immutable.Seq[Node] with S val i: Int = that.indexOf('}') if (i == -1) fail val (uri: String, key: String) = (that.substring(2, i), that.substring(i + 1, that.length)) - if (uri == "" || key == "") fail + if (uri.isEmpty || key.isEmpty) fail else y.attribute(uri, key) } else y.attribute(that.drop(1)) diff --git a/shared/src/main/scala/scala/xml/PrefixedAttribute.scala b/shared/src/main/scala/scala/xml/PrefixedAttribute.scala index bba655d5..3a3985fe 100644 --- a/shared/src/main/scala/scala/xml/PrefixedAttribute.scala +++ b/shared/src/main/scala/scala/xml/PrefixedAttribute.scala @@ -28,13 +28,15 @@ class PrefixedAttribute( override val pre: String, override val key: String, override val value: Seq[Node], - val next1: MetaData) - extends Attribute { - override val next: MetaData = if (value.ne(null)) next1 else next1.remove(key) + val next1: MetaData +) + extends Attribute +{ + override val next: MetaData = if (value != null) next1 else next1.remove(key) /** same as this(pre, key, Text(value), next), or no attribute if value is null */ def this(pre: String, key: String, value: String, next: MetaData) = - this(pre, key, if (value.ne(null)) Text(value) else null: NodeSeq, next) + this(pre, key, if (value != null) Text(value) else null: NodeSeq, next) /** same as this(pre, key, value.get, next), or no attribute if value is None */ def this(pre: String, key: String, value: Option[Seq[Node]], next: MetaData) = @@ -56,12 +58,11 @@ class PrefixedAttribute( /** * gets attribute value of qualified (prefixed) attribute with given key */ - override def apply(namespace: String, scope: NamespaceBinding, key: String): Seq[Node] = { + override def apply(namespace: String, scope: NamespaceBinding, key: String): Seq[Node] = if (key == this.key && scope.getURI(pre) == namespace) value else next(namespace, scope, key) - } } object PrefixedAttribute { diff --git a/shared/src/main/scala/scala/xml/PrettyPrinter.scala b/shared/src/main/scala/scala/xml/PrettyPrinter.scala index dbc3d811..e1e35c3c 100755 --- a/shared/src/main/scala/scala/xml/PrettyPrinter.scala +++ b/shared/src/main/scala/scala/xml/PrettyPrinter.scala @@ -150,7 +150,7 @@ 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.isEmpty => case _: Atom[_] | _: Comment | _: EntityRef | _: ProcInstr => makeBox(ind, node.toString.trim) @@ -163,18 +163,17 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) { if (doPreserve(node)) sb.toString else TextBuffer.fromString(sb.toString).toText(0).data } - if (childrenAreLeaves(node) && fits(test)) { + if (childrenAreLeaves(node) && fits(test)) makeBox(ind, test) - } else { + else { val ((stg: String, len2: Int), etg: String) = if (node.child.isEmpty && minimizeEmpty) { // force the tag to be self-closing val firstAttribute: Int = test.indexOf(' ') val firstBreak: Int = if (firstAttribute != -1) firstAttribute else test.lastIndexOf('/') ((test, firstBreak), "") - } else { + } else (startTag(node, pscope), endTag(node)) - } if (stg.length < width - cur) { // start tag fits makeBox(ind, stg) @@ -221,9 +220,7 @@ class PrettyPrinter(width: Int, step: Int, minimizeEmpty: Boolean) { * @param n the node to be serialized * @param sb the stringbuffer to append to */ - def format(n: Node, sb: StringBuilder): Unit = { // entry point - format(n, TopScope, sb) - } + def format(n: Node, sb: StringBuilder): Unit = format(n, TopScope, sb) // entry point def format(n: Node, pscope: NamespaceBinding, sb: StringBuilder): Unit = { // entry point var lastwasbreak: Boolean = false diff --git a/shared/src/main/scala/scala/xml/ProcInstr.scala b/shared/src/main/scala/scala/xml/ProcInstr.scala index 4d09b373..f12bc4a6 100644 --- a/shared/src/main/scala/scala/xml/ProcInstr.scala +++ b/shared/src/main/scala/scala/xml/ProcInstr.scala @@ -39,8 +39,6 @@ case class ProcInstr(target: String, proctext: String) extends SpecialNode { * appends "<?" target (" "+text)?+"?>" * to this stringbuffer. */ - override def buildString(sb: StringBuilder): StringBuilder = { - val textStr: String = if (proctext == "") "" else s" $proctext" - sb.append(s"") - } + override def buildString(sb: StringBuilder): StringBuilder = + sb.append(s"") } diff --git a/shared/src/main/scala/scala/xml/TopScope.scala b/shared/src/main/scala/scala/xml/TopScope.scala index 2dc77139..0b82e4b6 100644 --- a/shared/src/main/scala/scala/xml/TopScope.scala +++ b/shared/src/main/scala/scala/xml/TopScope.scala @@ -20,13 +20,11 @@ package xml */ object TopScope extends NamespaceBinding(null, null, null) { - import XML.{xml, namespace} - override def getURI(prefix1: String): String = - if (prefix1 == xml) namespace else null + if (prefix1 == XML.xml) XML.namespace else null override def getPrefix(uri1: String): String = - if (uri1 == namespace) xml else null + if (uri1 == XML.namespace) XML.xml else null override def toString: String = "" diff --git a/shared/src/main/scala/scala/xml/UnprefixedAttribute.scala b/shared/src/main/scala/scala/xml/UnprefixedAttribute.scala index 86cf538e..0f044680 100644 --- a/shared/src/main/scala/scala/xml/UnprefixedAttribute.scala +++ b/shared/src/main/scala/scala/xml/UnprefixedAttribute.scala @@ -24,14 +24,16 @@ import scala.collection.Seq class UnprefixedAttribute( override val key: String, override val value: Seq[Node], - next1: MetaData) - extends Attribute { + next1: MetaData +) + extends Attribute +{ final override val pre: scala.Null = null - override val next: MetaData = if (value.ne(null)) next1 else next1.remove(key) + override val next: MetaData = if (value != null) next1 else next1.remove(key) /** same as this(key, Text(value), next), or no attribute if value is null */ def this(key: String, value: String, next: MetaData) = - this(key, if (value.ne(null)) Text(value) else null: NodeSeq, next) + this(key, if (value != null) Text(value) else null: NodeSeq, next) /** same as this(key, value.get, next), or no attribute if value is None */ def this(key: String, value: Option[Seq[Node]], next: MetaData) = diff --git a/shared/src/main/scala/scala/xml/Utility.scala b/shared/src/main/scala/scala/xml/Utility.scala index ab3592f2..ff8a2fb4 100755 --- a/shared/src/main/scala/scala/xml/Utility.scala +++ b/shared/src/main/scala/scala/xml/Utility.scala @@ -55,12 +55,11 @@ object Utility extends AnyRef with parsing.TokenTests { Elem(pre, lab, md, scp, children.isEmpty, children: _*) } - private def combineAdjacentTextNodes(children: Seq[Node]): Seq[Node] = { + private def combineAdjacentTextNodes(children: Seq[Node]): Seq[Node] = children.foldRight(Seq.empty[Node]) { case (Text(left), Text(right) +: nodes) => Text(left + right) +: nodes case (n, nodes) => n +: nodes } - } /** * trim a child of an element. `Attribute` values and `Atom` nodes that @@ -77,7 +76,7 @@ object Utility extends AnyRef with parsing.TokenTests { } /** returns a sorted attribute list */ - def sort(md: MetaData): MetaData = if (md.eq(Null) || md.next.eq(Null)) md else { + def sort(md: MetaData): MetaData = if (md.isNull || md.next.isNull) md else { val key: String = md.key val smaller: MetaData = sort(md.filter { m => m.key < key }) val greater: MetaData = sort(md.filter { m => m.key > key }) @@ -120,7 +119,7 @@ object Utility extends AnyRef with parsing.TokenTests { /** * Appends escaped string to `s`. */ - final def escape(text: String, s: StringBuilder): StringBuilder = { + final def escape(text: String, s: StringBuilder): StringBuilder = // Implemented per XML spec: // http://www.w3.org/International/questions/qa-controls text.iterator.foldLeft(s) { (s, c) => @@ -130,7 +129,6 @@ object Utility extends AnyRef with parsing.TokenTests { case _ => s // noop } } - } /** * Appends unescaped string to `s`, `amp` becomes `&`, @@ -151,7 +149,7 @@ object Utility extends AnyRef with parsing.TokenTests { /** * Adds all namespaces in node to set. */ - def collectNamespaces(n: Node, set: mutable.Set[String]): Unit = { + def collectNamespaces(n: Node, set: mutable.Set[String]): Unit = if (n.doCollectNamespaces) { set += n.namespace for (a <- n.attributes) a match { @@ -162,7 +160,6 @@ object Utility extends AnyRef with parsing.TokenTests { for (i <- n.child) collectNamespaces(i, set) } - } // def toXML( // x: Node, @@ -251,7 +248,7 @@ object Utility extends AnyRef with parsing.TokenTests { case e: Elem => sb.append('<') e.nameToString(sb) - if (e.attributes.ne(null)) e.attributes.buildString(sb) + if (e.attributes != null) e.attributes.buildString(sb) e.scope.buildString(sb, pscopes.head) if (e.child.isEmpty && (minimizeTags == MinimizeMode.Always || @@ -325,14 +322,12 @@ object Utility extends AnyRef with parsing.TokenTests { sb.append('"') } - def getName(s: String, index: Int): String = { - if (index >= s.length) null - else { + def getName(s: String, index: Int): String = + if (index >= s.length) null else { val xs: String = s.drop(index) if (xs.nonEmpty && isNameStart(xs.head)) xs.takeWhile(isNameChar) else "" } - } /** * Returns `'''null'''` if the value is a correct attribute value, @@ -346,7 +341,7 @@ object Utility extends AnyRef with parsing.TokenTests { return "< not allowed in attribute value" case '&' => val n: String = getName(value, i + 1) - if (n.eq(null)) + if (n == null) return s"malformed entity reference in attribute value [$value]" i = i + n.length + 1 if (i >= value.length || value.charAt(i) != ';') @@ -374,7 +369,7 @@ object Utility extends AnyRef with parsing.TokenTests { val theChar: String = parseCharRef ({ () => c }, { () => c = it.next() }, { s => throw new RuntimeException(s) }, { s => throw new RuntimeException(s) }) sb.append(theChar) } else { - if (rfb.eq(null)) rfb = new StringBuilder() + if (rfb == null) rfb = new StringBuilder() rfb.append(c) c = it.next() while (c != ';') { diff --git a/shared/src/main/scala/scala/xml/XML.scala b/shared/src/main/scala/scala/xml/XML.scala index 9cf06d13..3dfe36b2 100755 --- a/shared/src/main/scala/scala/xml/XML.scala +++ b/shared/src/main/scala/scala/xml/XML.scala @@ -126,7 +126,7 @@ object XML extends XMLLoader[Elem] { ): Unit = { /* TODO: optimize by giving writer parameter to toXML*/ if (xmlDecl) w.write(s"\n") - if (doctype.ne(null)) w.write(s"$doctype\n") + if (doctype != null) w.write(s"$doctype\n") w.write(Utility.serialize(node, minimizeTags = minimizeTags).toString) } } diff --git a/shared/src/main/scala/scala/xml/Xhtml.scala b/shared/src/main/scala/scala/xml/Xhtml.scala index b30175ee..a7ce99d0 100644 --- a/shared/src/main/scala/scala/xml/Xhtml.scala +++ b/shared/src/main/scala/scala/xml/Xhtml.scala @@ -70,7 +70,7 @@ object Xhtml { case _ => sb.append('<') x.nameToString(sb) - if (x.attributes.ne(null)) x.attributes.buildString(sb) + if (x.attributes != null) x.attributes.buildString(sb) x.scope.buildString(sb, pscope) if (shortForm) sb.append(" />") @@ -95,10 +95,7 @@ object Xhtml { decodeEntities: Boolean = false, preserveWhitespace: Boolean = false, minimizeTags: Boolean = true - ): Unit = { - if (children.isEmpty) - return - + ): Unit = if (children.nonEmpty) { val doSpaces: Boolean = children.forall(isAtomAndNotText) // interleave spaces for (c <- children.take(children.length - 1)) { toXhtml(c, pscope, sb, stripComments, decodeEntities, preserveWhitespace, minimizeTags) diff --git a/shared/src/main/scala/scala/xml/dtd/Decl.scala b/shared/src/main/scala/scala/xml/dtd/Decl.scala index 570669dc..c2cf53e1 100644 --- a/shared/src/main/scala/scala/xml/dtd/Decl.scala +++ b/shared/src/main/scala/scala/xml/dtd/Decl.scala @@ -37,8 +37,7 @@ sealed abstract class MarkupDecl extends Decl { /** * an element declaration */ -case class ElemDecl(name: String, contentModel: ContentModel) - extends MarkupDecl { +case class ElemDecl(name: String, contentModel: ContentModel) extends MarkupDecl { override def buildString(sb: StringBuilder): StringBuilder = { sb.append(s"") } diff --git a/shared/src/main/scala/scala/xml/include/sax/XIncludeFilter.scala b/shared/src/main/scala/scala/xml/include/sax/XIncludeFilter.scala index 9c70136b..b82414d6 100644 --- a/shared/src/main/scala/scala/xml/include/sax/XIncludeFilter.scala +++ b/shared/src/main/scala/scala/xml/include/sax/XIncludeFilter.scala @@ -134,7 +134,7 @@ class XIncludeFilter extends XMLFilterImpl { } bases push currentBase - if (uri.equals(XINCLUDE_NAMESPACE) && localName.equals("include")) { + if (uri == XINCLUDE_NAMESPACE && localName == "include") { // include external document val href: String = atts.getValue("href") // Verify that there is an href attribute @@ -145,16 +145,13 @@ class XIncludeFilter extends XMLFilterImpl { var parse: String = atts.getValue("parse") if (parse == null) parse = "xml" - if (parse.equals("text")) { - val encoding: String = atts.getValue("encoding") - includeTextDocument(href, encoding) - } else if (parse.equals("xml")) { + if (parse == "text") + includeTextDocument(href, atts.getValue("encoding")) + else if (parse == "xml") includeXMLDocument(href) - } // Need to check this also in DOM and JDOM???? - else { - throw new SAXException( - s"Illegal value for parse attribute: $parse") - } + // Need to check this also in DOM and JDOM???? + else + throw new SAXException(s"Illegal value for parse attribute: $parse") level += 1 } else { if (atRoot) { @@ -171,8 +168,7 @@ class XIncludeFilter extends XMLFilterImpl { } override def endElement(uri: String, localName: String, qName: String): Unit = { - if (uri.equals(XINCLUDE_NAMESPACE) - && localName.equals("include")) { + if (uri == XINCLUDE_NAMESPACE && localName == "include") { level -= 1 } else if (level == 0) { bases.pop() @@ -253,7 +249,7 @@ class XIncludeFilter extends XMLFilterImpl { */ private def includeTextDocument(url: String, encoding1: String): Unit = { var encoding: String = encoding1 - if (encoding == null || encoding.trim.equals("")) encoding = "UTF-8" + if (encoding == null || encoding.trim.isEmpty) encoding = "UTF-8" var source: URL = null try { val base: URL = bases.peek @@ -278,8 +274,8 @@ class XIncludeFilter extends XMLFilterImpl { // Java may be picking this up from file URL if (contentType != null) { contentType = contentType.toLowerCase - if (contentType.equals("text/xml") - || contentType.equals("application/xml") + if (contentType == "text/xml" + || contentType == "application/xml" || (contentType.startsWith("text/") && contentType.endsWith("+xml")) || (contentType.startsWith("application/") && contentType.endsWith("+xml"))) { encoding = EncodingHeuristics.readEncodingFromStream(in) diff --git a/shared/src/main/scala/scala/xml/parsing/ElementContentModel.scala b/shared/src/main/scala/scala/xml/parsing/ElementContentModel.scala index 832297c5..cb7316d6 100644 --- a/shared/src/main/scala/scala/xml/parsing/ElementContentModel.scala +++ b/shared/src/main/scala/scala/xml/parsing/ElementContentModel.scala @@ -105,7 +105,7 @@ private[parsing] object ElementContentModel { val string: String = removeParentheses(parenthesized) if (occurrence == Occurrence.Once && string == PCData.value) PCData else if (occurrence == Occurrence.RepeatOptional) { val choice: List[String] = Elements.Choice.split(string) - if (choice.length > 1 && choice.head == PCData.value) Mixed(choice.tail.map(Elements.Element)) + if (choice.length > 1 && choice.head == PCData.value) Mixed(choice.tail.map(Elements.Element.apply)) else Children.parse(string, occurrence) } else Children.parse(string, occurrence) } diff --git a/shared/src/main/scala/scala/xml/parsing/MarkupParser.scala b/shared/src/main/scala/scala/xml/parsing/MarkupParser.scala index f76520da..2ca4773c 100755 --- a/shared/src/main/scala/scala/xml/parsing/MarkupParser.scala +++ b/shared/src/main/scala/scala/xml/parsing/MarkupParser.scala @@ -523,7 +523,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests { */ def parseDTD(): Unit = { // dirty but fast var extID: ExternalID = null - if (this.dtd.ne(null)) + if (dtd != null) reportSyntaxError("unexpected character (DOCTYPE already defined") xToken("DOCTYPE") xSpace() @@ -562,7 +562,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests { /*override val */ decls = handle.decls.reverse } //this.dtd.initializeEntities(); - if (doc.ne(null)) + if (doc != null) doc.dtd = this.dtd handle.endDTD(n) diff --git a/shared/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala b/shared/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala index 8179b8a7..be88269d 100644 --- a/shared/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala +++ b/shared/src/main/scala/scala/xml/parsing/MarkupParserCommon.scala @@ -120,8 +120,7 @@ private[scala] trait MarkupParserCommon extends TokenTests { val buf: StringBuilder = new StringBuilder - while ({ buf.append(ch_returning_nextch) - ; isNameChar(ch)}) () + while ({ buf.append(ch_returning_nextch); isNameChar(ch)}) () if (buf.last == ':') { reportSyntaxError("name cannot end in ':'") diff --git a/shared/src/main/scala/scala/xml/transform/BasicTransformer.scala b/shared/src/main/scala/scala/xml/transform/BasicTransformer.scala index 999fe4b7..7ad543b4 100644 --- a/shared/src/main/scala/scala/xml/transform/BasicTransformer.scala +++ b/shared/src/main/scala/scala/xml/transform/BasicTransformer.scala @@ -42,7 +42,7 @@ abstract class BasicTransformer extends (Node => Node) { else ns } - def transform(n: Node): Seq[Node] = { + def transform(n: Node): Seq[Node] = if (n.doTransform) n match { case Group(xs) => Group(transform(xs)) // un-group the hack Group tag case _ => @@ -53,7 +53,6 @@ abstract class BasicTransformer extends (Node => Node) { else Elem(n.prefix, n.label, n.attributes, n.scope, nch.isEmpty, nch: _*) } else n - } override def apply(n: Node): Node = { val seq: Seq[Node] = transform(n) diff --git a/shared/src/main/scala/scala/xml/transform/NestingTransformer.scala b/shared/src/main/scala/scala/xml/transform/NestingTransformer.scala index f0b7d69b..52ee1997 100644 --- a/shared/src/main/scala/scala/xml/transform/NestingTransformer.scala +++ b/shared/src/main/scala/scala/xml/transform/NestingTransformer.scala @@ -17,7 +17,6 @@ package transform import scala.collection.Seq class NestingTransformer(rule: RewriteRule) extends BasicTransformer { - override def transform(n: Node): Seq[Node] = { + override def transform(n: Node): Seq[Node] = rule.transform(super.transform(n)) - } } diff --git a/shared/src/main/scala/scala/xml/transform/RuleTransformer.scala b/shared/src/main/scala/scala/xml/transform/RuleTransformer.scala index 657b1b73..60288fb0 100644 --- a/shared/src/main/scala/scala/xml/transform/RuleTransformer.scala +++ b/shared/src/main/scala/scala/xml/transform/RuleTransformer.scala @@ -18,8 +18,8 @@ import scala.collection.Seq class RuleTransformer(rules: RewriteRule*) extends BasicTransformer { private val transformers: Seq[NestingTransformer] = rules.map(new NestingTransformer(_)) - override def transform(n: Node): Seq[Node] = { + + override def transform(n: Node): Seq[Node] = if (transformers.isEmpty) n else transformers.tail.foldLeft(transformers.head.transform(n)) { (res, transformer) => transformer.transform(res) } - } } diff --git a/shared/src/test/scala/scala/xml/AttributeTest.scala b/shared/src/test/scala/scala/xml/AttributeTest.scala index 90804266..5f1a6134 100644 --- a/shared/src/test/scala/scala/xml/AttributeTest.scala +++ b/shared/src/test/scala/scala/xml/AttributeTest.scala @@ -21,7 +21,7 @@ class AttributeTest { var appended: MetaData = x.append(x).append(x).append(x) var len: Int = 0 - while (appended.ne(Null)) { + while (!appended.isNull) { appended = appended.next len = len + 1 }