diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/LazilyLoadedCtor.java b/mozilla/js/rhino/src/org/mozilla/javascript/LazilyLoadedCtor.java index 69b6e9ab790..d6df9e297a6 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/LazilyLoadedCtor.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/LazilyLoadedCtor.java @@ -104,8 +104,7 @@ public final class LazilyLoadedCtor implements java.io.Serializable { private Object buildValue() { - Class cl = - (Class)Kit.classOrNull(className); + Class cl = cast(Kit.classOrNull(className)); if (cl != null) { try { Object value = ScriptableObject.buildClassCtor(scope, cl, @@ -133,5 +132,10 @@ public final class LazilyLoadedCtor implements java.io.Serializable { } return Scriptable.NOT_FOUND; } + + @SuppressWarnings({"unchecked"}) + private Class cast(Class cl) { + return (Class)cl; + } } diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/Parser.java b/mozilla/js/rhino/src/org/mozilla/javascript/Parser.java index 2f20f0250f8..8aada84620f 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/Parser.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/Parser.java @@ -48,7 +48,8 @@ package org.mozilla.javascript; import java.io.Reader; import java.io.IOException; -import java.util.Hashtable; +import java.util.HashMap; +import java.util.Map; /** * This class implements the JavaScript parser. @@ -93,7 +94,7 @@ public class Parser ScriptOrFnNode currentScriptOrFn; Node.Scope currentScope; private int nestingOfWith; - private Hashtable labelSet; // map of label names into nodes + private Map labelSet; // map of label names into nodes private ObjArray loopSet; private ObjArray loopAndSwitchSet; private boolean hasReturnValue; @@ -542,7 +543,7 @@ public class Parser currentScope = fnNode; int savedNestingOfWith = nestingOfWith; nestingOfWith = 0; - Hashtable savedLabelSet = labelSet; + Map savedLabelSet = labelSet; labelSet = null; ObjArray savedLoopSet = loopSet; loopSet = null; @@ -691,7 +692,7 @@ public class Parser String name = ts.getString(); decompiler.addName(name); if (labelSet != null) { - label = (Node)labelSet.get(name); + label = labelSet.get(name); } if (label == null) { reportError("msg.undef.label"); @@ -1212,7 +1213,7 @@ public class Parser decompiler.addEOL(Token.COLON); if (labelSet == null) { - labelSet = new Hashtable(); + labelSet = new HashMap(); } else if (labelSet.containsKey(name)) { reportError("msg.dup.label"); } diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/ScriptOrFnNode.java b/mozilla/js/rhino/src/org/mozilla/javascript/ScriptOrFnNode.java index 76d4ca71136..47afa022788 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/ScriptOrFnNode.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/ScriptOrFnNode.java @@ -46,7 +46,7 @@ public class ScriptOrFnNode extends Node.Scope { public ScriptOrFnNode(int nodeType) { super(nodeType); - symbols = new ArrayList(4); + symbols = new ArrayList(4); setParent(null); } @@ -170,7 +170,7 @@ public class ScriptOrFnNode extends Node.Scope { */ void flattenSymbolTable(boolean flattenAllTables) { if (!flattenAllTables) { - ArrayList newSymbols = new ArrayList(); + ArrayList newSymbols = new ArrayList(); if (this.symbolTable != null) { // Just replace "symbols" with the symbols in this object's // symbol table. Can't just work from symbolTable map since @@ -220,7 +220,7 @@ public class ScriptOrFnNode extends Node.Scope { private ObjArray functions; private ObjArray regexps; - private ArrayList symbols; + private ArrayList symbols; private int paramCount = 0; private String[] variableNames; private boolean[] isConsts; diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/serialize/ScriptableInputStream.java b/mozilla/js/rhino/src/org/mozilla/javascript/serialize/ScriptableInputStream.java index 476ff69c536..13015b01825 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/serialize/ScriptableInputStream.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/serialize/ScriptableInputStream.java @@ -75,7 +75,7 @@ public class ScriptableInputStream extends ObjectInputStream { } } - protected Class resolveClass(ObjectStreamClass desc) + protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { String name = desc.getName(); diff --git a/mozilla/js/rhino/src/org/mozilla/javascript/serialize/ScriptableOutputStream.java b/mozilla/js/rhino/src/org/mozilla/javascript/serialize/ScriptableOutputStream.java index 5ba0d741682..927f9770e0d 100644 --- a/mozilla/js/rhino/src/org/mozilla/javascript/serialize/ScriptableOutputStream.java +++ b/mozilla/js/rhino/src/org/mozilla/javascript/serialize/ScriptableOutputStream.java @@ -39,7 +39,8 @@ package org.mozilla.javascript.serialize; -import java.util.Hashtable; +import java.util.Map; +import java.util.HashMap; import java.util.StringTokenizer; import java.io.*; @@ -78,7 +79,7 @@ public class ScriptableOutputStream extends ObjectOutputStream { { super(out); this.scope = scope; - table = new Hashtable(31); + table = new HashMap(); table.put(scope, ""); enableReplaceObject(true); excludeStandardObjectNames(); @@ -203,5 +204,5 @@ public class ScriptableOutputStream extends ObjectOutputStream { } private Scriptable scope; - private Hashtable table; + private Map table; } diff --git a/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/Namespace.java b/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/Namespace.java index a4cf585bce9..2bcae6d1eba 100644 --- a/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/Namespace.java +++ b/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/Namespace.java @@ -83,6 +83,7 @@ class Namespace extends IdScriptableObject return ns.getPrefix(); } + @Override public String toString() { return uri(); } @@ -95,22 +96,26 @@ class Namespace extends IdScriptableObject return uri().equals(n.uri()); } + @Override public boolean equals(Object obj) { if (!(obj instanceof Namespace)) return false; return equals((Namespace)obj); } + @Override protected Object equivalentValues(Object value) { if (!(value instanceof Namespace)) return Scriptable.NOT_FOUND; boolean result = equals((Namespace)value); return result ? Boolean.TRUE : Boolean.FALSE; } + @Override public String getClassName() { return "Namespace"; } - public Object getDefaultValue(Class hint) { + @Override + public Object getDefaultValue(Class hint) { return uri(); } @@ -120,11 +125,13 @@ class Namespace extends IdScriptableObject Id_uri = 2, MAX_INSTANCE_ID = 2; + @Override protected int getMaxInstanceId() { return super.getMaxInstanceId() + MAX_INSTANCE_ID; } + @Override protected int findInstanceIdInfo(String s) { int id; @@ -152,6 +159,7 @@ class Namespace extends IdScriptableObject } // #/string_id_map# + @Override protected String getInstanceIdName(int id) { switch (id - super.getMaxInstanceId()) { @@ -161,6 +169,7 @@ class Namespace extends IdScriptableObject return super.getInstanceIdName(id); } + @Override protected Object getInstanceIdValue(int id) { switch (id - super.getMaxInstanceId()) { @@ -181,6 +190,7 @@ class Namespace extends IdScriptableObject Id_toSource = 3, MAX_PROTOTYPE_ID = 3; + @Override protected int findPrototypeId(String s) { int id; @@ -201,6 +211,7 @@ class Namespace extends IdScriptableObject } // #/string_id_map# + @Override protected void initPrototypeId(int id) { String s; @@ -214,6 +225,7 @@ class Namespace extends IdScriptableObject initPrototypeMethod(NAMESPACE_TAG, id, s, arity); } + @Override public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, diff --git a/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/QName.java b/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/QName.java index 90a18cb1e38..71967d06342 100644 --- a/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/QName.java +++ b/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/QName.java @@ -80,6 +80,7 @@ final class QName extends IdScriptableObject exportAsJSClass(MAX_PROTOTYPE_ID, getParentScope(), sealed); } + @Override public String toString() { // ECMA357 13.3.4.2 if (delegate.getNamespace() == null) { @@ -97,12 +98,10 @@ final class QName extends IdScriptableObject return delegate.getLocalName(); } - /** - @deprecated - - This property is supposed to be invisible and I think we can make it private at some point, though Namespace - might need it - */ + /* + * TODO This property is supposed to be invisible and I think we can + * make it private at some point, though Namespace might need it + */ String prefix() { if (delegate.getNamespace() == null) return null; return delegate.getNamespace().getPrefix(); @@ -122,11 +121,13 @@ final class QName extends IdScriptableObject return delegate; } + @Override public boolean equals(Object obj) { if(!(obj instanceof QName)) return false; return equals((QName)obj); } + @Override protected Object equivalentValues(Object value) { if(!(value instanceof QName)) return Scriptable.NOT_FOUND; @@ -138,11 +139,13 @@ final class QName extends IdScriptableObject return this.delegate.isEqualTo(q.delegate); } + @Override public String getClassName() { return "QName"; } - public Object getDefaultValue(Class hint) { + @Override + public Object getDefaultValue(Class hint) { return toString(); } @@ -152,11 +155,13 @@ final class QName extends IdScriptableObject Id_uri = 2, MAX_INSTANCE_ID = 2; + @Override protected int getMaxInstanceId() { return super.getMaxInstanceId() + MAX_INSTANCE_ID; } + @Override protected int findInstanceIdInfo(String s) { int id; @@ -184,6 +189,7 @@ final class QName extends IdScriptableObject } // #/string_id_map# + @Override protected String getInstanceIdName(int id) { switch (id - super.getMaxInstanceId()) { @@ -193,6 +199,7 @@ final class QName extends IdScriptableObject return super.getInstanceIdName(id); } + @Override protected Object getInstanceIdValue(int id) { switch (id - super.getMaxInstanceId()) { @@ -209,6 +216,7 @@ final class QName extends IdScriptableObject Id_toSource = 3, MAX_PROTOTYPE_ID = 3; + @Override protected int findPrototypeId(String s) { int id; @@ -229,6 +237,7 @@ final class QName extends IdScriptableObject } // #/string_id_map# + @Override protected void initPrototypeId(int id) { String s; @@ -242,6 +251,7 @@ final class QName extends IdScriptableObject initPrototypeMethod(QNAME_TAG, id, s, arity); } + @Override public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, diff --git a/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XML.java b/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XML.java index 090ae1a8f12..cd7e411d3d3 100644 --- a/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XML.java +++ b/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XML.java @@ -59,6 +59,7 @@ class XML extends XMLObjectImpl { this.node.setXml(this); } + @Override final XML getXML() { return this; } @@ -74,7 +75,7 @@ class XML extends XMLObjectImpl { } } - /** @deprecated I would love to encapsulate this somehow. */ + /* TODO: needs encapsulation. */ XML makeXmlFromString(XMLName name, String value) { try { return newTextElementXML(this.node, name.toQname(), value.toString()); @@ -83,7 +84,7 @@ class XML extends XMLObjectImpl { } } - /** @deprecated Rename this, at the very least. But it's not clear it's even necessary */ + /* TODO: Rename this, at the very least. But it's not clear it's even necessary */ XmlNode getAnnotation() { return node; } @@ -94,6 +95,7 @@ class XML extends XMLObjectImpl { // TODO Either cross-reference this next comment with the specification or delete it and change the behavior // The comment: XML[0] should return this, all other indexes are Undefined + @Override public Object get(int index, Scriptable start) { if (index == 0) { return this; @@ -102,16 +104,19 @@ class XML extends XMLObjectImpl { } } + @Override public boolean has(int index, Scriptable start) { return (index == 0); } + @Override public void put(int index, Scriptable start, Object value) { // TODO Clarify the following comment and add a reference to the spec // The comment: Spec says assignment to indexed XML object should return type error throw ScriptRuntime.typeError("Assignment to indexed XML is not allowed"); } + @Override public Object[] getIds() { if (isPrototype()) { return new Object[0]; @@ -121,6 +126,7 @@ class XML extends XMLObjectImpl { } // TODO This is how I found it but I am not sure it makes sense + @Override public void delete(int index) { if (index == 0) { this.remove(); @@ -131,6 +137,7 @@ class XML extends XMLObjectImpl { // Methods from XMLObjectImpl // + @Override boolean hasXMLProperty(XMLName xmlName) { if (isPrototype()) { return getMethod(xmlName.localName()) != NOT_FOUND; @@ -139,6 +146,7 @@ class XML extends XMLObjectImpl { } } + @Override Object getXMLProperty(XMLName xmlName) { if (isPrototype()) { return getMethod(xmlName.localName()); @@ -181,6 +189,7 @@ class XML extends XMLObjectImpl { return name.getMyValueOn(this); } + @Override void deleteXMLProperty(XMLName name) { XMLList list = getPropertyList(name); for (int i=0; i 1) { - throw ScriptRuntime.typeError("Assignment to lists with more than one item is not supported"); + throw ScriptRuntime.typeError( + "Assignment to lists with more than one item is not supported"); } else if (length() == 0) { // Secret sauce for super-expandos. // We set an element here, and then add ourselves to our target. - if (targetObject != null && targetProperty != null && targetProperty.getLocalName() != null) { - // Add an empty element with our targetProperty name and then set it. + if (targetObject != null && targetProperty != null && + targetProperty.getLocalName() != null) + { + // Add an empty element with our targetProperty name and + // then set it. XML xmlValue = newTextElementXML(null, targetProperty, null); addToList(xmlValue); @@ -176,10 +187,13 @@ class XMLList extends XMLObjectImpl implements Function { } // Now add us to our parent - XMLName name2 = XMLName.formProperty(targetProperty.getUri(), targetProperty.getLocalName()); + XMLName name2 = XMLName.formProperty( + targetProperty.getNamespace().getUri(), + targetProperty.getLocalName()); targetObject.putXMLProperty(name2, this); } else { - throw ScriptRuntime.typeError("Assignment to empty XMLList without targets not supported"); + throw ScriptRuntime.typeError( + "Assignment to empty XMLList without targets not supported"); } } else if(xmlName.isAttributeName()) { setAttribute(xmlName, value); @@ -192,6 +206,7 @@ class XMLList extends XMLObjectImpl implements Function { } } + @Override Object getXMLProperty(XMLName name) { return getPropertyList(name); } @@ -200,6 +215,7 @@ class XMLList extends XMLObjectImpl implements Function { xml.replaceWith(with); } + @Override public void put(int index, Scriptable start, Object value) { Object parent = Undefined.instance; // Convert text into XML if needed. @@ -294,7 +310,7 @@ class XMLList extends XMLObjectImpl implements Function { } } - private XML getXML(XmlNode.List _annos, int index) { + private XML getXML(XmlNode.InternalList _annos, int index) { if (index >= 0 && index < length()) { return xmlFromNode(_annos.item(index)); } else { @@ -302,6 +318,7 @@ class XMLList extends XMLObjectImpl implements Function { } } + @Override void deleteXMLProperty(XMLName name) { for (int i = 0; i < length(); i++) { XML xml = getXmlFromAnnotation(i); @@ -312,6 +329,7 @@ class XMLList extends XMLObjectImpl implements Function { } } + @Override public void delete(int index) { if (index >= 0 && index < length()) { XML xml = getXmlFromAnnotation(index); @@ -322,6 +340,7 @@ class XMLList extends XMLObjectImpl implements Function { } } + @Override public Object[] getIds() { Object enumObjs[]; @@ -377,6 +396,7 @@ class XMLList extends XMLObjectImpl implements Function { // // + @Override XMLList child(int index) { XMLList result = newXMLList(); @@ -387,6 +407,7 @@ class XMLList extends XMLObjectImpl implements Function { return result; } + @Override XMLList child(XMLName xmlName) { XMLList result = newXMLList(); @@ -397,14 +418,16 @@ class XMLList extends XMLObjectImpl implements Function { return result; } + @Override void addMatches(XMLList rv, XMLName name) { for (int i=0; i list = new ArrayList(); for (int i = 0; i < length(); i++) { XML xml = getXmlFromAnnotation(i); @@ -416,22 +439,23 @@ class XMLList extends XMLObjectImpl implements Function { int cChildren = childList.length(); for (int j = 0; j < cChildren; j++) { - v.addElement(childList.item(j)); + list.add(childList.item(j)); } } } } XMLList allChildren = newXMLList(); - int sz = v.size(); + int sz = list.size(); for (int i = 0; i < sz; i++) { - allChildren.addToList(v.get(i)); + allChildren.addToList(list.get(i)); } return allChildren; } + @Override XMLList comments() { XMLList result = newXMLList(); @@ -443,6 +467,7 @@ class XMLList extends XMLObjectImpl implements Function { return result; } + @Override XMLList elements(XMLName name) { XMLList rv = newXMLList(); for (int i=0; i hint) { return this.toString(); } + @Override public final boolean hasInstance(Scriptable scriptable) { return super.hasInstance(scriptable); } @@ -220,6 +230,7 @@ abstract class XMLObjectImpl extends XMLObject { abstract XMLList processingInstructions(XMLName xmlName); abstract boolean propertyIsEnumerable(Object member); abstract XMLList text(); + @Override public abstract String toString(); abstract String toXMLString(); abstract Object valueOf(); @@ -241,6 +252,7 @@ abstract class XMLObjectImpl extends XMLObject { * never returns {@link Scriptable#NOT_FOUND} for them but rather * calls equivalentXml(value) and wrap the result as Boolean. */ + @Override protected final Object equivalentValues(Object value) { boolean result = equivalentXml(value); return result ? Boolean.TRUE : Boolean.FALSE; @@ -255,6 +267,7 @@ abstract class XMLObjectImpl extends XMLObject { /** * Implementation of ECMAScript [[Has]] */ + @Override public final boolean ecmaHas(Context cx, Object id) { if (cx == null) cx = Context.getCurrentContext(); XMLName xmlName = lib.toXMLNameOrIndex(cx, id); @@ -269,6 +282,7 @@ abstract class XMLObjectImpl extends XMLObject { /** * Implementation of ECMAScript [[Get]] */ + @Override public final Object ecmaGet(Context cx, Object id) { if (cx == null) cx = Context.getCurrentContext(); XMLName xmlName = lib.toXMLNameOrIndex(cx, id); @@ -287,6 +301,7 @@ abstract class XMLObjectImpl extends XMLObject { /** * Implementation of ECMAScript [[Put]] */ + @Override public final void ecmaPut(Context cx, Object id, Object value) { if (cx == null) cx = Context.getCurrentContext(); XMLName xmlName = lib.toXMLNameOrIndex(cx, id); @@ -302,6 +317,7 @@ abstract class XMLObjectImpl extends XMLObject { /** * Implementation of ECMAScript [[Delete]]. */ + @Override public final boolean ecmaDelete(Context cx, Object id) { if (cx == null) cx = Context.getCurrentContext(); XMLName xmlName = lib.toXMLNameOrIndex(cx, id); @@ -316,6 +332,7 @@ abstract class XMLObjectImpl extends XMLObject { } // TODO Can this be made more strongly typed? + @Override public Ref memberRef(Context cx, Object elem, int memberTypeFlags) { boolean attribute = (memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0; boolean descendants = (memberTypeFlags & Node.DESCENDANTS_FLAG) != 0; @@ -334,24 +351,31 @@ abstract class XMLObjectImpl extends XMLObject { /** * Generic reference to implement x::ns, x.@ns::y, x..@ns::y etc. */ - public Ref memberRef(Context cx, Object namespace, Object elem, int memberTypeFlags) { + @Override + public Ref memberRef(Context cx, Object namespace, Object elem, + int memberTypeFlags) + { boolean attribute = (memberTypeFlags & Node.ATTRIBUTE_FLAG) != 0; boolean descendants = (memberTypeFlags & Node.DESCENDANTS_FLAG) != 0; - XMLName rv = XMLName.create(lib.toNodeQName(cx, namespace, elem), attribute, descendants); + XMLName rv = XMLName.create(lib.toNodeQName(cx, namespace, elem), + attribute, descendants); rv.initXMLObject(this); return rv; } + @Override public NativeWith enterWith(Scriptable scope) { return new XMLWithScope(lib, scope, this); } + @Override public NativeWith enterDotQuery(Scriptable scope) { XMLWithScope xws = new XMLWithScope(lib, scope, this); xws.initAsDotQuery(); return xws; } + @Override public final Object addValues(Context cx, boolean thisIsLeft, Object value) { if (value instanceof XMLObject) { @@ -430,6 +454,7 @@ abstract class XMLObjectImpl extends XMLObject { MAX_PROTOTYPE_ID = 40; + @Override protected int findPrototypeId(String s) { int id; // #generated# Last update: 2007-08-20 09:04:06 EDT @@ -507,6 +532,7 @@ abstract class XMLObjectImpl extends XMLObject { } // #/string_id_map# + @Override protected void initPrototypeId(int id) { String s; int arity; @@ -582,7 +608,10 @@ abstract class XMLObjectImpl extends XMLObject { throw ScriptRuntime.notFunctionError(object, name); } - public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { + @Override + public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, + Scriptable thisObj, Object[] args) + { if (!f.hasTag(XMLOBJECT_TAG)) { return super.execIdCall(f, cx, scope, thisObj, args); } @@ -791,7 +820,7 @@ abstract class XMLObjectImpl extends XMLObject { return lib.newTextElementXML(reference, qname, value); } - /** @deprecated Hopefully this can be replaced with ecmaToXml below. */ + /* TODO: Hopefully this can be replaced with ecmaToXml below. */ final XML newXMLFromJs(Object inputObject) { return lib.newXMLFromJs(inputObject); } diff --git a/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XMLWithScope.java b/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XMLWithScope.java index fbeb45ea7c7..365ea5714c6 100644 --- a/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XMLWithScope.java +++ b/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XMLWithScope.java @@ -82,6 +82,7 @@ final class XMLWithScope extends NativeWith _xmlList = lib.newXMLList(); } + @Override protected Object updateDotQuery(boolean value) { // Return null to continue looping diff --git a/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XmlNode.java b/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XmlNode.java index 06955d09efd..e0608d3fddc 100644 --- a/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XmlNode.java +++ b/mozilla/js/rhino/xmlimplsrc/org/mozilla/javascript/xmlimpl/XmlNode.java @@ -87,7 +87,7 @@ class XmlNode { document = processor.newDocument(); } Node referenceDom = (reference != null) ? reference.dom : null; - Element e = document.createElementNS(qname.getUri(), qname.qualify(referenceDom)); + Element e = document.createElementNS(qname.getNamespace().getUri(), qname.qualify(referenceDom)); if (value != null) { e.appendChild(document.createTextNode(value)); } @@ -139,6 +139,7 @@ class XmlNode { return raw.ecmaToXmlString(this.dom); } + @Override public String toString() { return "XmlNode: type=" + dom.getNodeType() + " dom=" + dom.toString(); } @@ -329,8 +330,8 @@ class XmlNode { } private static class Namespaces { - private HashMap map = new HashMap(); - private HashMap uriToPrefix = new HashMap(); + private Map map = new HashMap(); + private Map uriToPrefix = new HashMap(); Namespaces() { } @@ -348,26 +349,24 @@ class XmlNode { Namespace getNamespaceByUri(String uri) { if (uriToPrefix.get(uri) == null) return null; - return Namespace.create(uri, (String)uriToPrefix.get(uri)); + return Namespace.create(uri, uriToPrefix.get(uri)); } Namespace getNamespace(String prefix) { if (map.get(prefix) == null) return null; - return Namespace.create(prefix, (String)map.get(prefix)); + return Namespace.create(prefix, map.get(prefix)); } Namespace[] getNamespaces() { - Iterator i = map.keySet().iterator(); - ArrayList rv = new ArrayList(); - while(i.hasNext()) { - String prefix = (String)i.next(); - String uri = (String)map.get(prefix); + ArrayList rv = new ArrayList(); + for (String prefix: map.keySet()) { + String uri = map.get(prefix); Namespace n = Namespace.create(prefix, uri); if (!n.isEmpty()) { - rv.add( n ); + rv.add(n); } } - return (Namespace[])rv.toArray(new Namespace[0]); + return rv.toArray(new Namespace[rv.size()]); } } @@ -401,7 +400,7 @@ class XmlNode { } final void renameNode(QName qname) { - this.dom = dom.getOwnerDocument().renameNode(dom, qname.getUri(), qname.qualify(dom)); + this.dom = dom.getOwnerDocument().renameNode(dom, qname.getNamespace().getUri(), qname.qualify(dom)); } void invalidateNamespacePrefix() { @@ -526,15 +525,15 @@ class XmlNode { } XmlNode[] getMatchingChildren(Filter filter) { - ArrayList rv = new ArrayList(); + ArrayList rv = new ArrayList(); NodeList nodes = this.dom.getChildNodes(); for (int i=0; i list; - List() { - v = new java.util.Vector(); + InternalList() { + list = new ArrayList(); } private void _add(XmlNode n) { - v.add(n); + list.add(n); } XmlNode item(int index) { - return (XmlNode)(v.get(index)); + return list.get(index); } void remove(int index) { - v.remove(index); + list.remove(index); } - void add(List other) { + void add(InternalList other) { for (int i=0; i list, Node node) { if (node instanceof ProcessingInstruction) { - v.add(node); + list.add(node); } if (node.getChildNodes() != null) { for (int i=0; i list, Node node) { if (node instanceof Comment) { - v.add(node); + list.add(node); } if (node.getChildNodes() != null) { for (int i=0; i toRemove, Node node) { if (node instanceof Text) { Text text = (Text)node; boolean BUG_369394_IS_VALID = false; @@ -237,18 +239,16 @@ class XmlProcessor { builder = getDocumentBuilderFromPool(); Document document = builder.parse( new org.xml.sax.InputSource(new java.io.StringReader(syntheticXml)) ); if (ignoreProcessingInstructions) { - java.util.Vector v = new java.util.Vector(); - addProcessingInstructionsTo(v, document); - for (int i=0; i list = new java.util.ArrayList(); + addProcessingInstructionsTo(list, document); + for (Node node: list) { node.getParentNode().removeChild(node); } } if (ignoreComments) { - java.util.Vector v = new java.util.Vector(); - addCommentsTo(v, document); - for (int i=0; i list = new java.util.ArrayList(); + addCommentsTo(list, document); + for (Node node: list) { node.getParentNode().removeChild(node); } } @@ -258,10 +258,9 @@ class XmlProcessor { // so that it would know which whitespace to ignore. // Instead we will try to delete it ourselves. - java.util.Vector v = new java.util.Vector(); - addTextNodesToRemoveAndTrim(v, document); - for (int i=0; i list = new java.util.ArrayList(); + addTextNodesToRemoveAndTrim(list, document); + for (Node node: list) { node.getParentNode().removeChild(node); } } @@ -417,7 +416,7 @@ class XmlProcessor { // We "mark" all the nodes first; if we tried to do this loop otherwise, it would behave unexpectedly (the inserted nodes // would contribute to the length and it might never terminate). - java.util.Vector toIndent = new java.util.Vector(); + ArrayList toIndent = new ArrayList(); boolean indentChildren = false; for (int i=0; i list = new ArrayList(); + for (int i=0; i < nodes.getLength(); i++) { if (nodes.item(i) instanceof Element) { - v.add( nodes.item(i) ); + list.add((Element)nodes.item(i)); } } - for (int i=0; i