Skip to content

scala.collection.mutable.Stack deprecated #147

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 3 commits 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
16 changes: 8 additions & 8 deletions jvm/src/test/scala/scala/xml/XMLTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class XMLTestJVM {
override def text = ""
}

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

Expand All @@ -50,10 +50,10 @@ class XMLTestJVM {
val i = new InputSource(new StringReader(x2))
val x2p = scala.xml.XML.load(i)

assertTrue(x2p == Elem(null, "book", e, sc,
assertEquals(Elem(null, "book", e, sc,
Elem(null, "author", e, sc, Text("Peter Buneman")),
Elem(null, "author", e, sc, Text("Dan Suciu")),
Elem(null, "title", e, sc, Text("Data on ze web"))))
Elem(null, "title", e, sc, Text("Data on ze web"))), x2p)

}

Expand Down Expand Up @@ -431,16 +431,16 @@ class XMLTestJVM {
@UnitTest
def t6939 = {
val foo = <x:foo xmlns:x="http://foo.com/"><x:bar xmlns:x="http://bar.com/"><x:baz/></x:bar></x:foo>
assertTrue(foo.child.head.scope.toString == """ xmlns:x="http://bar.com/"""")
assertEquals(foo.child.head.scope.toString, """ xmlns:x="http://bar.com/"""")

val fooDefault = <foo xmlns="http://foo.com/"><bar xmlns="http://bar.com/"><baz/></bar></foo>
assertTrue(fooDefault.child.head.scope.toString == """ xmlns="http://bar.com/"""")
assertEquals(fooDefault.child.head.scope.toString, """ xmlns="http://bar.com/"""")

val foo2 = scala.xml.XML.loadString("""<x:foo xmlns:x="http://foo.com/"><x:bar xmlns:x="http://bar.com/"><x:baz/></x:bar></x:foo>""")
assertTrue(foo2.child.head.scope.toString == """ xmlns:x="http://bar.com/"""")
assertEquals(foo2.child.head.scope.toString, """ xmlns:x="http://bar.com/"""")

val foo2Default = scala.xml.XML.loadString("""<foo xmlns="http://foo.com/"><bar xmlns="http://bar.com/"><baz/></bar></foo>""")
assertTrue(foo2Default.child.head.scope.toString == """ xmlns="http://bar.com/"""")
assertEquals(foo2Default.child.head.scope.toString, """ xmlns="http://bar.com/"""")
}

@UnitTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T])
val delta = new mutable.HashMap[immutable.BitSet, mutable.HashMap[T, immutable.BitSet]]
var deftrans = mutable.Map(q0 -> sink, sink -> sink) // initial transitions
var finals: mutable.Map[immutable.BitSet, Int] = mutable.Map()
val rest = new mutable.Stack[immutable.BitSet]
var rest = immutable.List.empty[immutable.BitSet]

rest.push(sink, q0)
rest = q0 :: sink :: rest

def addFinal(q: immutable.BitSet) {
if (nfa containsFinal q)
Expand All @@ -43,15 +43,16 @@ private[dtd] class SubsetConstruction[T <: AnyRef](val nfa: NondetWordAutom[T])
def add(Q: immutable.BitSet) {
if (!states(Q)) {
states += Q
rest push Q
rest = Q :: rest
addFinal(Q)
}
}

addFinal(q0) // initial state may also be a final state

while (!rest.isEmpty) {
val P = rest.pop()
val P = rest.head
rest = rest.tail
// assign a number to this bitset
indexMap = indexMap.updated(P, ix)
invIndexMap = invIndexMap.updated(ix, P)
Expand Down
4 changes: 2 additions & 2 deletions shared/src/main/scala/scala/xml/factory/XMLLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ trait XMLLoader[T <: Node] {
def loadXML(source: InputSource, parser: SAXParser): T = {
val newAdapter = adapter

newAdapter.scopeStack push TopScope
newAdapter.scopes = TopScope :: newAdapter.scopes
parser.parse(source, newAdapter)
newAdapter.scopeStack.pop()
newAdapter.scopes = newAdapter.scopes.tail

newAdapter.rootElem.asInstanceOf[T]
}
Expand Down
11 changes: 5 additions & 6 deletions shared/src/main/scala/scala/xml/include/sax/XIncluder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package scala
package xml
package include.sax

import scala.collection.mutable
import org.xml.sax.{ ContentHandler, Locator, Attributes }
import org.xml.sax.ext.LexicalHandler
import java.io.{ OutputStream, OutputStreamWriter, IOException }
Expand Down Expand Up @@ -126,7 +125,7 @@ class XIncluder(outs: OutputStream, encoding: String) extends ContentHandler wit

// LexicalHandler methods
private var inDTD: Boolean = false
private val entities = new mutable.Stack[String]()
private var entities = List.empty[String]

def startDTD(name: String, publicID: String, systemID: String) {
inDTD = true
Expand All @@ -145,12 +144,12 @@ class XIncluder(outs: OutputStream, encoding: String) extends ContentHandler wit
}
def endDTD() {}

def startEntity(name: String) {
entities push name
def startEntity(name: String): Unit = {
entities = name :: entities
}

def endEntity(name: String) {
entities.pop()
def endEntity(name: String): Unit = {
entities = entities.tail
}

def startCDATA() {}
Expand Down
49 changes: 31 additions & 18 deletions shared/src/main/scala/scala/xml/parsing/FactoryAdapter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package scala
package xml
package parsing

import scala.collection.{ mutable, Iterator }
import scala.collection.mutable
import org.xml.sax.Attributes
import org.xml.sax.helpers.DefaultHandler

Expand Down Expand Up @@ -39,10 +39,16 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
var rootElem: Node = null

val buffer = new StringBuilder()
val attribStack = new mutable.Stack[MetaData]
val hStack = new mutable.Stack[Node] // [ element ] contains siblings
val tagStack = new mutable.Stack[String]
var scopeStack = new mutable.Stack[NamespaceBinding]
var attribs = List.empty[MetaData]
var nodes = List.empty[Node] // [ element ] contains siblings
var tags = List.empty[String]
var scopes = List.empty[NamespaceBinding]

// Fix compatability issues. Add MiMa exclusion rules, instead?
var attribStack = mutable.Stack(attribs)
var hStack = mutable.Stack(nodes)
var tagStack = mutable.Stack(tags)
var scopeStack = mutable.Stack(scopes)

var curTag: String = null
var capture: Boolean = false
Expand Down Expand Up @@ -122,17 +128,17 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
attributes: Attributes): Unit =
{
captureText()
tagStack push curTag
tags = curTag :: tags
curTag = qname

val localName = splitName(qname)._2
capture = nodeContainsText(localName)

hStack push null
nodes = null :: nodes
var m: MetaData = Null
var scpe: NamespaceBinding =
if (scopeStack.isEmpty) TopScope
else scopeStack.top
if (scopes.isEmpty) TopScope
else scopes.head

for (i <- 0 until attributes.getLength()) {
val qname = attributes getQName i
Expand All @@ -147,16 +153,16 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
m = Attribute(Option(pre), key, Text(value), m)
}

scopeStack push scpe
attribStack push m
scopes = scpe :: scopes
attribs = m :: attribs
}

/**
* captures text, possibly normalizing whitespace
*/
def captureText(): Unit = {
if (capture && buffer.length > 0)
hStack push createText(buffer.toString)
nodes = createText(buffer.toString) :: nodes

buffer.clear()
}
Expand All @@ -170,17 +176,24 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
*/
override def endElement(uri: String, _localName: String, qname: String): Unit = {
captureText()
val metaData = attribStack.pop()
val metaData = attribs.head
attribs = attribs.tail

// reverse order to get it right
val v = (Iterator continually hStack.pop takeWhile (_ != null)).toList.reverse
val v = nodes.takeWhile(_ != null).reverse
nodes = nodes.dropWhile(_ != null) match {
case null :: hs => hs
case hs => hs
}
val (pre, localName) = splitName(qname)
val scp = scopeStack.pop()
val scp = scopes.head
scopes = scopes.tail

// create element
rootElem = createNode(pre, localName, metaData, scp, v)
hStack push rootElem
curTag = tagStack.pop()
nodes = rootElem :: nodes
curTag = tags.head
tags = tags.tail
capture = curTag != null && nodeContainsText(curTag) // root level
}

Expand All @@ -189,6 +202,6 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
*/
override def processingInstruction(target: String, data: String) {
captureText()
hStack pushAll createProcInstr(target, data)
nodes = nodes.reverse_:::(createProcInstr(target, data).toList)
}
}