From 2c5f1e8b027ef3ed360e5c73f14c3833a40b8d09 Mon Sep 17 00:00:00 2001 From: michelou Date: Thu, 8 Sep 2011 19:45:24 +0000 Subject: added missing getExcludedFiles in Ant ... added missing getExcludedFiles in Ant task (same change is pending for Ant task). A new starr is needed for that features to work in build.xml (and other Ant scripts). --- src/compiler/scala/tools/ant/Scalac.scala | 32 +++++++--- src/library/scala/xml/Atom.scala | 14 +++-- src/library/scala/xml/Attribute.scala | 25 +++++--- src/library/scala/xml/Comment.scala | 6 +- src/library/scala/xml/Elem.scala | 17 ++--- src/library/scala/xml/Equality.scala | 3 +- src/library/scala/xml/Group.scala | 5 +- src/library/scala/xml/MetaData.scala | 10 +-- src/library/scala/xml/NamespaceBinding.scala | 6 +- src/library/scala/xml/Node.scala | 13 ++-- src/library/scala/xml/NodeSeq.scala | 5 +- src/library/scala/xml/Null.scala | 22 +++---- src/library/scala/xml/PCData.scala | 41 +++++++++--- src/library/scala/xml/PrettyPrinter.scala | 22 +++---- src/library/scala/xml/QNode.scala | 10 ++- src/library/scala/xml/SpecialNode.scala | 10 +-- src/library/scala/xml/Text.scala | 16 +++-- src/library/scala/xml/TopScope.scala | 5 +- src/library/scala/xml/Unparsed.scala | 24 ++++--- src/library/scala/xml/dtd/Decl.scala | 73 ++++++++++------------ src/library/scala/xml/parsing/MarkupParser.scala | 37 +++++------ .../scala/xml/parsing/MarkupParserCommon.scala | 4 +- src/library/scala/xml/pull/XMLEventReader.scala | 7 ++- 23 files changed, 234 insertions(+), 173 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala index 01e35ac70a..d6e78fb68e 100644 --- a/src/compiler/scala/tools/ant/Scalac.scala +++ b/src/compiler/scala/tools/ant/Scalac.scala @@ -168,7 +168,7 @@ class Scalac extends ScalaMatchingTask with ScalacShared { } private def createNewPath(getter: () => Option[Path], setter: (Option[Path]) => Unit) = { if (getter().isEmpty) - setter(Some(new Path(getProject()))) + setter(Some(new Path(getProject))) getter().get.createPath() } @@ -381,7 +381,7 @@ class Scalac extends ScalaMatchingTask with ScalacShared { * @return The destination as a file. */ protected def getDestination: File = if (destination.isEmpty) buildError("Member 'destination' is empty.") - else existing(getProject().resolveFile(destination.get.toString)) + else existing(getProject resolveFile destination.get.toString) /** Gets the value of the `sourcepath` attribute in a * Scala-friendly form. @@ -416,14 +416,14 @@ class Scalac extends ScalaMatchingTask with ScalacShared { * @param name A relative or absolute path to the file as a string. * @return A file created from the name. */ protected def nameToFile(name: String): File = - existing(getProject().resolveFile(name)) + existing(getProject resolveFile name) /** Tests if a file exists and prints a warning in case it doesn't. Always * returns the file, even if it doesn't exist. * @param file A file to test for existance. * @return The same file. */ protected def existing(file: File): File = { - if (!file.exists()) + if (!file.exists) log("Element '" + file.toString + "' does not exist.", Project.MSG_WARN) file @@ -433,7 +433,7 @@ class Scalac extends ScalaMatchingTask with ScalacShared { * @param path A path to convert. * @return A string-representation of the path like `a.jar:b.jar`. */ protected def asString(path: List[File]): String = - path.map(asString).mkString(File.pathSeparator) + path.map(asString) mkString File.pathSeparator /** Transforms a file into a Scalac-readable string. * @param path A file to convert. @@ -447,10 +447,10 @@ class Scalac extends ScalaMatchingTask with ScalacShared { protected def newSettings(error: String=>Unit): Settings = new Settings(error) + protected def newGlobal(settings: Settings, reporter: Reporter) = new Global(settings, reporter) - /*============================================================================*\ ** The big execute method ** \*============================================================================*/ @@ -473,14 +473,26 @@ class Scalac extends ScalaMatchingTask with ScalacShared { var javaOnly = true def getOriginFiles(originDir: File) = { - val includedFiles = getDirectoryScanner(originDir).getIncludedFiles() - val javaFiles = includedFiles filter (_ endsWith ".java") - val scalaFiles = { + val scanner = getDirectoryScanner(originDir) + val includedFiles = scanner.getIncludedFiles + val includedJavaFiles = includedFiles filter (_ endsWith ".java") + val includedScalaFiles = { val xs = includedFiles filter (_ endsWith ".scala") if (force) xs else new SourceFileScanner(this).restrict(xs, originDir, destination.get, mapper) } + val excludedFiles = scanner.getExcludedFiles + val excludedJavaFiles = excludedFiles filter (_ endsWith ".java") + val excludedScalaFiles = { + val xs = excludedFiles filter (_ endsWith ".scala") + if (force) xs + else new SourceFileScanner(this).restrict(xs, originDir, destination.get, mapper) + } + + val javaFiles = includedJavaFiles diff excludedJavaFiles + val scalaFiles = includedScalaFiles diff excludedScalaFiles + javaOnly = javaOnly && (scalaFiles.length == 0) val list = (scalaFiles ++ javaFiles).toList @@ -590,7 +602,7 @@ class Scalac extends ScalaMatchingTask with ScalacShared { // Write all settings to a temporary file def writeSettings() : File = { - def escapeArgument(arg : String) = if(arg.matches(".*\\s.*")) ('"' + arg + '"') else arg + def escapeArgument(arg : String) = if (arg matches ".*\\s.*") '"' + arg + '"' else arg val file = File.createTempFile("scalac-ant-",".args") file.deleteOnExit() val out = new PrintWriter(new BufferedWriter(new FileWriter(file))) diff --git a/src/library/scala/xml/Atom.scala b/src/library/scala/xml/Atom.scala index d48e451b3c..72572fb5e4 100644 --- a/src/library/scala/xml/Atom.scala +++ b/src/library/scala/xml/Atom.scala @@ -12,17 +12,19 @@ package scala.xml * It is used in both non-bound and bound XML representations. * * @author Burak Emir - * @param text the text contained in this node, may not be `'''null'''`. + * @param data the text contained in this node, may not be `'''null'''`. */ class Atom[+A](val data: A) extends SpecialNode with Serializable { if (data == null) - throw new IllegalArgumentException("cannot construct Atom(null)") + throw new IllegalArgumentException("cannot construct "+getClass.getSimpleName+" with null") + + override protected def basisForHashCode: Seq[Any] = Seq(data) - override def basisForHashCode: Seq[Any] = Seq(data) override def strict_==(other: Equality) = other match { case x: Atom[_] => data == x.data case _ => false } + override def canEqual(other: Any) = other match { case _: Atom[_] => true case _ => false @@ -39,9 +41,9 @@ class Atom[+A](val data: A) extends SpecialNode with Serializable { * @param sb ... * @return ... */ - def buildString(sb: StringBuilder) = - Utility.escape(data.toString(), sb) + def buildString(sb: StringBuilder): StringBuilder = + Utility.escape(data.toString, sb) - override def text: String = data.toString() + override def text: String = data.toString } diff --git a/src/library/scala/xml/Attribute.scala b/src/library/scala/xml/Attribute.scala index bce3ffe60d..9523891a9c 100644 --- a/src/library/scala/xml/Attribute.scala +++ b/src/library/scala/xml/Attribute.scala @@ -6,13 +6,14 @@ ** |/ ** \* */ - package scala.xml -/** Attribute defines the interface shared by both - * PrefixedAttribute and UnprefixedAttribute +/** This singleton object contains the `apply` and `unapply` methods for + * convenient construction and deconstruction. + * + * @author Burak Emir + * @version 1.0 */ - object Attribute { def unapply(x: Attribute) = x match { case PrefixedAttribute(_, key, value, next) => Some((key, value, next)) @@ -34,11 +35,17 @@ object Attribute { def apply(pre: Option[String], key: String, value: Seq[Node], next: MetaData): Attribute = pre match { - case None => new UnprefixedAttribute(key, value, next) - case Some(p) => new PrefixedAttribute(p, key, value, next) + case None => new UnprefixedAttribute(key, value, next) + case Some(p) => new PrefixedAttribute(p, key, value, next) } } +/** The `Attribute` trait defines the interface shared by both + * [[scala.xml.PrefixedAttribute]] and [[scala.xml.UnprefixedAttribute]]. + * + * @author Burak Emir + * @version 1.0 + */ abstract trait Attribute extends MetaData { def pre: String // will be null if unprefixed val key: String @@ -58,7 +65,9 @@ abstract trait Attribute extends MetaData { else next.remove(namespace, scope, key) def isPrefixed: Boolean = pre != null + def getNamespace(owner: Node): String + def wellformed(scope: NamespaceBinding): Boolean = { val arg = if (isPrefixed) scope getURI pre else null (next(arg, scope, key) == null) && (next wellformed scope) @@ -66,7 +75,7 @@ abstract trait Attribute extends MetaData { /** Appends string representation of only this attribute to stringbuffer. */ - def toString1(sb: StringBuilder) { + protected def toString1(sb: StringBuilder) { if (value == null) return if (isPrefixed) @@ -75,6 +84,6 @@ abstract trait Attribute extends MetaData { sb append key append '=' val sb2 = new StringBuilder() Utility.sequenceToXML(value, TopScope, sb2, true) - Utility.appendQuoted(sb2.toString(), sb) + Utility.appendQuoted(sb2.toString, sb) } } diff --git a/src/library/scala/xml/Comment.scala b/src/library/scala/xml/Comment.scala index ecaec4ba6b..014cead47c 100644 --- a/src/library/scala/xml/Comment.scala +++ b/src/library/scala/xml/Comment.scala @@ -13,8 +13,8 @@ package scala.xml * @author Burak Emir * @param text the text contained in this node, may not contain "--" */ -case class Comment(commentText: String) extends SpecialNode -{ +case class Comment(commentText: String) extends SpecialNode { + def label = "#REM" override def text = "" final override def doCollectNamespaces = false @@ -26,5 +26,5 @@ case class Comment(commentText: String) extends SpecialNode /** Appends "" to this string buffer. */ override def buildString(sb: StringBuilder) = - sb append ("") + sb append "" } diff --git a/src/library/scala/xml/Elem.scala b/src/library/scala/xml/Elem.scala index a522cdab20..127e6e0ab7 100644 --- a/src/library/scala/xml/Elem.scala +++ b/src/library/scala/xml/Elem.scala @@ -8,18 +8,17 @@ package scala.xml -/** This singleton object contains the apply and unapplySeq methods for +/** This singleton object contains the `apply` and `unapplySeq` methods for * convenient construction and deconstruction. It is possible to deconstruct * any `Node` instance (that is not a `SpecialNode` or a `Group`) using the * syntax `case Elem(prefix, label, attribs, scope, child @ _*) => ...` * * Copyright 2008 Google Inc. All Rights Reserved. - * * @author Burak Emir */ object Elem { def apply(prefix: String,label: String, attributes: MetaData, scope: NamespaceBinding, child: Node*) = - new Elem(prefix,label,attributes,scope,child:_*) + new Elem(prefix, label, attributes, scope, child:_*) def unapplySeq(n: Node) = n match { case _: SpecialNode | _: Group => None @@ -36,8 +35,8 @@ object Elem { * @param scope the scope containing the namespace bindings * @param child the children of this node * - * Copyright 2008 Google Inc. All Rights Reserved. - * @author Burak Emir + * Copyright 2008 Google Inc. All Rights Reserved. + * @author Burak Emir */ class Elem( override val prefix: String, @@ -60,10 +59,12 @@ extends Node with Serializable // setting namespace scope if necessary // cleaning adjacent text nodes if necessary - override def basisForHashCode: Seq[Any] = prefix :: label :: attributes :: child.toList + override protected def basisForHashCode: Seq[Any] = + prefix :: label :: attributes :: child.toList - /** Returns a new element with updated attributes, resolving namespace uris from this element's scope. - * See MetaData.update for details. + /** Returns a new element with updated attributes, resolving namespace uris + * from this element's scope. See MetaData.update for details. + * * @param updates MetaData with new and updated attributes * @return a new symbol with updated attributes */ diff --git a/src/library/scala/xml/Equality.scala b/src/library/scala/xml/Equality.scala index cc31c6eaa7..07651adb90 100644 --- a/src/library/scala/xml/Equality.scala +++ b/src/library/scala/xml/Equality.scala @@ -66,7 +66,8 @@ object Equality { import Equality._ trait Equality extends scala.Equals { - def basisForHashCode: Seq[Any] + protected def basisForHashCode: Seq[Any] + def strict_==(other: Equality): Boolean def strict_!=(other: Equality) = !strict_==(other) diff --git a/src/library/scala/xml/Group.scala b/src/library/scala/xml/Group.scala index 3018e053b1..8526eac543 100644 --- a/src/library/scala/xml/Group.scala +++ b/src/library/scala/xml/Group.scala @@ -6,7 +6,6 @@ ** |/ ** \* */ - package scala.xml /** A hack to group XML nodes in one node for output. @@ -21,11 +20,13 @@ final case class Group(val nodes: Seq[Node]) extends Node { case x: Group => true case _ => false } + override def strict_==(other: Equality) = other match { case Group(xs) => nodes sameElements xs case _ => false } - override def basisForHashCode = nodes + + override protected def basisForHashCode = nodes /** Since Group is very much a hack it throws an exception if you * try to do anything with it. diff --git a/src/library/scala/xml/MetaData.scala b/src/library/scala/xml/MetaData.scala index cbfb076004..9c603141d5 100644 --- a/src/library/scala/xml/MetaData.scala +++ b/src/library/scala/xml/MetaData.scala @@ -139,7 +139,7 @@ abstract class MetaData extends Iterable[MetaData] with Equality with Serializab case m: MetaData => this.asAttrMap == m.asAttrMap case _ => false } - def basisForHashCode: Seq[Any] = List(this.asAttrMap) + protected def basisForHashCode: Seq[Any] = List(this.asAttrMap) /** Returns an iterator on attributes */ def iterator: Iterator[MetaData] = Iterator.single(this) ++ next.iterator @@ -194,17 +194,17 @@ abstract class MetaData extends Iterable[MetaData] with Equality with Serializab final def get(uri: String, scope: NamespaceBinding, key: String): Option[Seq[Node]] = Option(apply(uri, scope, key)) - def toString1(): String = sbToString(toString1) + protected def toString1(): String = sbToString(toString1) // appends string representations of single attribute to StringBuilder - def toString1(sb: StringBuilder): Unit + protected def toString1(sb: StringBuilder): Unit override def toString(): String = sbToString(buildString) def buildString(sb: StringBuilder): StringBuilder = { - sb.append(' ') + sb append ' ' toString1(sb) - next.buildString(sb) + next buildString sb } /** diff --git a/src/library/scala/xml/NamespaceBinding.scala b/src/library/scala/xml/NamespaceBinding.scala index f284a6e407..a35fc0e130 100644 --- a/src/library/scala/xml/NamespaceBinding.scala +++ b/src/library/scala/xml/NamespaceBinding.scala @@ -37,18 +37,22 @@ case class NamespaceBinding(prefix: String, uri: String, parent: NamespaceBindin if (_uri == uri) prefix else parent getPrefix _uri override def toString(): String = sbToString(buildString(_, TopScope)) + override def canEqual(other: Any) = other match { case _: NamespaceBinding => true case _ => false } + override def strict_==(other: Equality) = other match { case x: NamespaceBinding => (prefix == x.prefix) && (uri == x.uri) && (parent == x.parent) case _ => false } + def basisForHashCode: Seq[Any] = List(prefix, uri, parent) def buildString(stop: NamespaceBinding): String = sbToString(buildString(_, stop)) - def buildString(sb: StringBuilder, stop: NamespaceBinding): Unit = { + + def buildString(sb: StringBuilder, stop: NamespaceBinding) { if (this eq stop) return // contains? val s = " xmlns%s=\"%s\"".format( diff --git a/src/library/scala/xml/Node.scala b/src/library/scala/xml/Node.scala index f219b73d81..2ead18fe08 100644 --- a/src/library/scala/xml/Node.scala +++ b/src/library/scala/xml/Node.scala @@ -8,11 +8,11 @@ package scala.xml -/** - * This object provides methods ... +/** This singleton object contains the `unapplySeq` method for + * convenient deconstruction. * - * @author Burak Emir - * @version 1.0 + * @author Burak Emir + * @version 1.0 */ object Node { /** the constant empty attribute sequence */ @@ -129,7 +129,10 @@ abstract class Node extends NodeSeq { case x: Node => true case _ => false } - override def basisForHashCode: Seq[Any] = prefix :: label :: attributes :: nonEmptyChildren.toList + + override protected def basisForHashCode: Seq[Any] = + prefix :: label :: attributes :: nonEmptyChildren.toList + override def strict_==(other: Equality) = other match { case _: Group => false case x: Node => diff --git a/src/library/scala/xml/NodeSeq.scala b/src/library/scala/xml/NodeSeq.scala index 2732223e19..1a28b2489e 100644 --- a/src/library/scala/xml/NodeSeq.scala +++ b/src/library/scala/xml/NodeSeq.scala @@ -60,11 +60,14 @@ abstract class NodeSeq extends immutable.Seq[Node] with SeqLike[Node, NodeSeq] w !these.hasNext && !those.hasNext } - def basisForHashCode: Seq[Any] = theSeq + + protected def basisForHashCode: Seq[Any] = theSeq + override def canEqual(other: Any) = other match { case _: NodeSeq => true case _ => false } + override def strict_==(other: Equality) = other match { case x: NodeSeq => (length == x.length) && (theSeq sameElements x.theSeq) case _ => false diff --git a/src/library/scala/xml/Null.scala b/src/library/scala/xml/Null.scala index 0b527c91bd..0db4a074c5 100644 --- a/src/library/scala/xml/Null.scala +++ b/src/library/scala/xml/Null.scala @@ -6,16 +6,17 @@ ** |/ ** \* */ - - package scala.xml -import Utility.{ isNameStart } +import Utility.isNameStart import scala.collection.Iterator /** Essentially, every method in here is a dummy, returning Zero[T]. * It provides a backstop for the unusual collection defined by MetaData, * sort of a linked list of tails. + * + * @author Burak Emir + * @version 1.0 */ case object Null extends MetaData { override def iterator = Iterator.empty @@ -38,21 +39,20 @@ case object Null extends MetaData { case x: MetaData => x.length == 0 case _ => false } - override def basisForHashCode: Seq[Any] = Nil + override protected def basisForHashCode: Seq[Any] = Nil def apply(namespace: String, scope: NamespaceBinding, key: String) = null - def apply(key: String) = { - if (!isNameStart(key.head)) - throw new IllegalArgumentException("not a valid attribute name '"+key+"', so can never match !") + def apply(key: String) = + if (isNameStart(key.head)) null + else throw new IllegalArgumentException("not a valid attribute name '"+key+"', so can never match !") - null - } + protected def toString1(sb: StringBuilder) = () + override protected def toString1(): String = "" - def toString1(sb: StringBuilder) = () - override def toString1(): String = "" override def toString(): String = "" override def buildString(sb: StringBuilder): StringBuilder = sb + override def wellformed(scope: NamespaceBinding) = true def remove(key: String) = this diff --git a/src/library/scala/xml/PCData.scala b/src/library/scala/xml/PCData.scala index 330ad897f9..44152d7f90 100644 --- a/src/library/scala/xml/PCData.scala +++ b/src/library/scala/xml/PCData.scala @@ -1,20 +1,43 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2011, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ package scala.xml -/** This class (which is not used by all XML parsers, but always used by the XHTML one) - * represents parseable character data, which appeared as CDATA sections in the input - * and is to be preserved as CDATA section in the output. +/** This class (which is not used by all XML parsers, but always used by the + * XHTML one) represents parseable character data, which appeared as CDATA + * sections in the input and is to be preserved as CDATA section in the output. + * + * @author Burak Emir + * @version 1.0 */ -case class PCData(_data: String) extends Atom[String](_data) { - if (null == data) - throw new IllegalArgumentException("tried to construct PCData with null") +class PCData(data: String) extends Atom[String](data) { /** Returns text, with some characters escaped according to the XML * specification. * - * @param sb ... - * @return ... + * @param sb the input string buffer associated to some XML element + * @return the input string buffer with the formatted CDATA section */ - override def buildString(sb: StringBuilder) = + override def buildString(sb: StringBuilder): StringBuilder = sb append "".format(data) } + +/** This singleton object contains the `apply`and `unapply` methods for + * convenient construction and deconstruction. + * + * @author Burak Emir + * @version 1.0 + */ +object PCData { + def apply(data: String) = new PCData(data) + def unapply(other: Any): Option[String] = other match { + case x: PCData => Some(x.data) + case _ => None + } +} + diff --git a/src/library/scala/xml/PrettyPrinter.scala b/src/library/scala/xml/PrettyPrinter.scala index 89742f9480..ea39b51352 100644 --- a/src/library/scala/xml/PrettyPrinter.scala +++ b/src/library/scala/xml/PrettyPrinter.scala @@ -6,7 +6,6 @@ ** |/ ** \* */ - package scala.xml import Utility.sbToString @@ -53,7 +52,7 @@ class PrettyPrinter(width: Int, step: Int) { if (s.length <= tmp) return List(Box(ind, s)) val sb = new StringBuilder() - var i = s.indexOf(' ') + var i = s indexOf ' ' if (i > tmp || i == -1) throw new BrokenException() // cannot break var last: List[Int] = Nil @@ -156,7 +155,7 @@ class PrettyPrinter(width: Int, step: Int) { case Text(s) if s.trim() == "" => ; case _:Atom[_] | _:Comment | _:EntityRef | _:ProcInstr => - makeBox( ind, node.toString().trim() ) + makeBox( ind, node.toString.trim() ) case g @ Group(xs) => traverse(xs.iterator, pscope, ind) case _ => @@ -164,7 +163,7 @@ class PrettyPrinter(width: Int, step: Int) { val sb = new StringBuilder() Utility.toXML(node, pscope, sb, false) if (doPreserve(node)) sb.toString - else TextBuffer.fromString(sb.toString()).toText(0).data + else TextBuffer.fromString(sb.toString).toText(0).data } if (childrenAreLeaves(node) && fits(test)) { makeBox(ind, test) @@ -214,10 +213,11 @@ class PrettyPrinter(width: Int, step: Int) { * @param pmap the namespace to prefix mapping * @param sb the stringbuffer to append to */ - def format(n: Node, sb: StringBuilder ): Unit = // entry point + def format(n: Node, sb: StringBuilder) { // entry point format(n, null, sb) + } - def format(n: Node, pscope: NamespaceBinding, sb: StringBuilder): Unit = { // entry point + def format(n: Node, pscope: NamespaceBinding, sb: StringBuilder) { // entry point var lastwasbreak = false reset() traverse(n, pscope, 0) @@ -227,21 +227,21 @@ class PrettyPrinter(width: Int, step: Int) { if (!lastwasbreak) sb.append('\n') // on windows: \r\n ? lastwasbreak = true cur = 0 -// while( cur < last ) { -// sb.append(' '); -// cur = cur + 1; +// while (cur < last) { +// sb append ' ' +// cur += 1 // } case Box(i, s) => lastwasbreak = false while (cur < i) { - sb.append(' ') + sb append ' ' cur += 1 } sb.append(s) case Para( s ) => lastwasbreak = false - sb.append(s) + sb append s } } diff --git a/src/library/scala/xml/QNode.scala b/src/library/scala/xml/QNode.scala index 52fed9a472..dde432cea4 100644 --- a/src/library/scala/xml/QNode.scala +++ b/src/library/scala/xml/QNode.scala @@ -6,15 +6,13 @@ ** |/ ** \* */ - - package scala.xml -/** - * This object provides an extractor method to match a qualified node with its namespace URI +/** This object provides an extractor method to match a qualified node with + * its namespace URI * - * @author Burak Emir - * @version 1.0 + * @author Burak Emir + * @version 1.0 */ object QNode { def unapplySeq(n: Node) = Some((n.scope.getURI(n.prefix), n.label, n.attributes, n.child)) diff --git a/src/library/scala/xml/SpecialNode.scala b/src/library/scala/xml/SpecialNode.scala index 758b018a13..b120d0d13f 100644 --- a/src/library/scala/xml/SpecialNode.scala +++ b/src/library/scala/xml/SpecialNode.scala @@ -6,18 +6,18 @@ ** |/ ** \* */ - package scala.xml /** `SpecialNode` is a special XML node which represents either text * `(PCDATA)`, a comment, a `PI`, or an entity ref. * - * SpecialNodes also play the role of XMLEvents for pull-parsing. + * `SpecialNode`s also play the role of [[scala.xml.pull.XMLEvent]]s for + * pull-parsing. * * @author Burak Emir */ -abstract class SpecialNode extends Node with pull.XMLEvent -{ +abstract class SpecialNode extends Node with pull.XMLEvent { + /** always empty */ final override def attributes = Null @@ -27,6 +27,6 @@ abstract class SpecialNode extends Node with pull.XMLEvent /** always empty */ final def child = Nil - /** Append string representation to the given stringbuffer argument. */ + /** Append string representation to the given string buffer argument. */ def buildString(sb: StringBuilder): StringBuilder } diff --git a/src/library/scala/xml/Text.scala b/src/library/scala/xml/Text.scala index 52d344329d..5982c4a26d 100644 --- a/src/library/scala/xml/Text.scala +++ b/src/library/scala/xml/Text.scala @@ -12,23 +12,27 @@ package scala.xml * It is used in both non-bound and bound XML representations. * * @author Burak Emir - * @param text the text contained in this node, may not be null. + * @param data the text contained in this node, may not be null. */ class Text(data: String) extends Atom[String](data) { - if (data == null) - throw new IllegalArgumentException("tried to construct Text with null") /** Returns text, with some characters escaped according to the XML * specification. */ - override def buildString(sb: StringBuilder) = + override def buildString(sb: StringBuilder): StringBuilder = Utility.escape(data, sb) } +/** This singleton object contains the `apply`and `unapply` methods for + * convenient construction and deconstruction. + * + * @author Burak Emir + * @version 1.0 + */ object Text { def apply(data: String) = new Text(data) def unapply(other: Any): Option[String] = other match { - case x: Text => Some(x.data) - case _ => None + case x: Text => Some(x.data) + case _ => None } } diff --git a/src/library/scala/xml/TopScope.scala b/src/library/scala/xml/TopScope.scala index 3356101b57..6af132252f 100644 --- a/src/library/scala/xml/TopScope.scala +++ b/src/library/scala/xml/TopScope.scala @@ -13,8 +13,8 @@ package scala.xml * for the "xml" prefix which is bound to * "http://www.w3.org/XML/1998/namespace" */ -object TopScope extends NamespaceBinding(null, null, null) -{ +object TopScope extends NamespaceBinding(null, null, null) { + import XML.{ xml, namespace } override def getURI(prefix1: String): String = @@ -24,6 +24,7 @@ object TopScope extends NamespaceBinding(null, null, null) if (uri1 == namespace) xml else null override def toString() = "" + override def buildString(stop: NamespaceBinding) = "" override def buildString(sb: StringBuilder, ignore: NamespaceBinding) = {} } diff --git a/src/library/scala/xml/Unparsed.scala b/src/library/scala/xml/Unparsed.scala index 6186d2b676..3852306aef 100644 --- a/src/library/scala/xml/Unparsed.scala +++ b/src/library/scala/xml/Unparsed.scala @@ -6,25 +6,29 @@ ** |/ ** \* */ - - package scala.xml /** An XML node for unparsed content. It will be output verbatim, all bets * are off regarding wellformedness etc. * - * @author Burak Emir - * @param data content in this node, may not be null. + * @author Burak Emir + * @param data content in this node, may not be null. */ -class Unparsed(data: String) extends Atom[String](data) -{ - if (null == data) - throw new IllegalArgumentException("tried to construct Unparsed with null") +class Unparsed(data: String) extends Atom[String](data) { - /** returns text, with some characters escaped according to XML spec */ - override def buildString(sb: StringBuilder) = sb append data + /** Returns text, with some characters escaped according to XML + * specification. + */ + override def buildString(sb: StringBuilder): StringBuilder = + sb append data } +/** This singleton object contains the `apply`and `unapply` methods for + * convenient construction and deconstruction. + * + * @author Burak Emir + * @version 1.0 + */ object Unparsed { def apply(data: String) = new Unparsed(data) def unapply(x: Unparsed) = Some(x.data) diff --git a/src/library/scala/xml/dtd/Decl.scala b/src/library/scala/xml/dtd/Decl.scala index ffb3701af6..7bd13448b1 100644 --- a/src/library/scala/xml/dtd/Decl.scala +++ b/src/library/scala/xml/dtd/Decl.scala @@ -6,7 +6,6 @@ ** |/ ** \* */ - package scala.xml package dtd @@ -21,27 +20,19 @@ abstract class MarkupDecl extends Decl { /** an element declaration */ case class ElemDecl(name: String, contentModel: ContentModel) -extends MarkupDecl -{ +extends MarkupDecl { override def buildString(sb: StringBuilder): StringBuilder = { - sb - .append("'); + ContentModel.buildString(contentModel, sb) + sb append '>' } } case class AttListDecl(name: String, attrs:List[AttrDecl]) extends MarkupDecl { override def buildString(sb: StringBuilder): StringBuilder = { - sb - .append("")); + sb append "") } } @@ -53,8 +44,8 @@ case class AttrDecl(name: String, tpe: String, default: DefaultDecl) { override def toString(): String = sbToString(buildString) def buildString(sb: StringBuilder): StringBuilder = { - sb.append(" ").append(name).append(' ').append(tpe).append(' '); - default.buildString(sb) + sb append " " append name append ' ' append tpe append ' ' + default buildString sb } } @@ -65,31 +56,31 @@ abstract class EntityDecl extends MarkupDecl /** a parsed general entity declaration */ case class ParsedEntityDecl(name: String, entdef: EntityDef) extends EntityDecl { override def buildString(sb: StringBuilder): StringBuilder = { - sb.append("') + sb append "' } } /** a parameter entity declaration */ case class ParameterEntityDecl(name: String, entdef: EntityDef) extends EntityDecl { override def buildString(sb: StringBuilder): StringBuilder = { - sb.append("') + sb append "' } } /** an unparsed entity declaration */ case class UnparsedEntityDecl( name:String, extID:ExternalID, notation:String ) extends EntityDecl { override def buildString(sb: StringBuilder): StringBuilder = { - sb.append("'); + sb append "' } } /** a notation declaration */ case class NotationDecl( name:String, extID:ExternalID ) extends MarkupDecl { override def buildString(sb: StringBuilder): StringBuilder = { - sb.append(" // todo: fix entities, shouldn't be "special" reportSyntaxError("no entity references allowed here"); case s:SpecialNode => - if (s.toString().trim().length > 0) //non-empty text nodes not allowed + if (s.toString.trim().length > 0) //non-empty text nodes not allowed elemCount += 2 case m:Node => elemCount += 1 @@ -266,7 +266,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests } /** append Unicode character to name buffer*/ - protected def putChar(c: Char) = cbuf.append(c) + protected def putChar(c: Char) = cbuf append c /** As the current code requires you to call nextch once manually * after construction, this method formalizes that suboptimal reality. @@ -276,14 +276,15 @@ trait MarkupParser extends MarkupParserCommon with TokenTests this } - def ch_returning_nextch = { val res = ch ; nextch ; res } - def mkProcInstr(position: Int, name: String, text: String): NodeSeq = - handle.procInstr(position, name, text) + protected def ch_returning_nextch: Char = { val res = ch; nextch(); res } - def mkAttributes(name: String, pscope: NamespaceBinding) = + def mkAttributes(name: String, pscope: NamespaceBinding): AttributesType = if (isNameStart (ch)) xAttributes(pscope) else (Null, pscope) + def mkProcInstr(position: Int, name: String, text: String): ElementType = + handle.procInstr(position, name, text) + /** this method tells ch to get the next character when next called */ def nextch() { // Read current ch if needed @@ -577,17 +578,17 @@ trait MarkupParser extends MarkupParserCommon with TokenTests * * precondition: `xEmbeddedBlock == false` (we are not in a scala block) */ - def xText: String = { - var exit = false; + private def xText: String = { + var exit = false while (! exit) { - putChar(ch); - val opos = pos; - nextch; + putChar(ch) + val opos = pos + nextch exit = eof || ( ch == '<' ) || ( ch == '&' ) } - val str = cbuf.toString(); - cbuf.length = 0; + val str = cbuf.toString + cbuf.length = 0 str } @@ -627,7 +628,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests nextch } nextch - val str = cbuf.toString() + val str = cbuf.toString cbuf.length = 0 str } @@ -796,7 +797,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests cbuf.append(ch) nextch } - val atpe = cbuf.toString() + val atpe = cbuf.toString cbuf.length = 0 val defdecl: DefaultDecl = ch match { @@ -880,7 +881,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests val notat = xName xSpace val extID = if (ch == 'S') { - externalID(); + externalID() } else if (ch == 'P') { /** PublicID (without system, only used in NOTATION) */ @@ -893,7 +894,7 @@ trait MarkupParser extends MarkupParserCommon with TokenTests systemLiteral() else null; - new PublicID(pubID, sysID); + new PublicID(pubID, sysID) } else { reportSyntaxError("PUBLIC or SYSTEM expected"); sys.error("died parsing notationdecl") diff --git a/src/library/scala/xml/parsing/MarkupParserCommon.scala b/src/library/scala/xml/parsing/MarkupParserCommon.scala index 096b2c910d..c6da4bb546 100644 --- a/src/library/scala/xml/parsing/MarkupParserCommon.scala +++ b/src/library/scala/xml/parsing/MarkupParserCommon.scala @@ -176,7 +176,7 @@ private[scala] trait MarkupParserCommon extends TokenTests { */ def ch: Char def nextch(): Unit - def ch_returning_nextch: Char + protected def ch_returning_nextch: Char def eof: Boolean // def handle: HandleType @@ -212,7 +212,7 @@ private[scala] trait MarkupParserCommon extends TokenTests { else xHandleError(ch, "whitespace expected") /** Apply a function and return the passed value */ - def returning[T](x: T)(f: T => Unit): T = { f(x) ; x } + def returning[T](x: T)(f: T => Unit): T = { f(x); x } /** Execute body with a variable saved and restored after execution */ def saving[A, B](getter: A, setter: A => Unit)(body: => B): B = { diff --git a/src/library/scala/xml/pull/XMLEventReader.scala b/src/library/scala/xml/pull/XMLEventReader.scala index 8b7137eed1..e22f064d79 100755 --- a/src/library/scala/xml/pull/XMLEventReader.scala +++ b/src/library/scala/xml/pull/XMLEventReader.scala @@ -75,7 +75,8 @@ class XMLEventReader(src: Source) extends ProducerConsumerIterator[XMLEvent] { } // this is a dummy to satisfy MarkupHandler's API - // memory usage optimization return one for top level to satisfy MarkupParser.document() otherwise NodeSeq.Empty + // memory usage optimization return one for top level to satisfy + // MarkupParser.document() otherwise NodeSeq.Empty private var ignoreWritten = false final def elem(pos: Int, pre: String, label: String, attrs: MetaData, pscope: NamespaceBinding, nodes: NodeSeq): NodeSeq = if (level == 1 && !ignoreWritten) {ignoreWritten = true; } else NodeSeq.Empty @@ -111,7 +112,7 @@ trait ProducerConsumerIterator[T >: Null] extends Iterator[T] { val MaxQueueSize = -1 def interruptibly[T](body: => T): Option[T] = try Some(body) catch { - case _: InterruptedException => Thread.currentThread.interrupt() ; None + case _: InterruptedException => Thread.currentThread.interrupt(); None case _: ClosedChannelException => None } @@ -133,12 +134,14 @@ trait ProducerConsumerIterator[T >: Null] extends Iterator[T] { // consumer/iterator interface - we need not synchronize access to buffer // because we required there to be only one consumer. def hasNext = !eos && (buffer != null || fillBuffer) + def next() = { if (eos) throw new NoSuchElementException("ProducerConsumerIterator") if (buffer == null) fillBuffer drainBuffer } + def available() = isElement(buffer) || isElement(queue.peek) private def drainBuffer() = { -- cgit v1.2.3