Resolving bug 256387: XML objects got toSource implementation

This commit is contained in:
igor%mir2.org 2004-08-21 12:26:43 +00:00
Родитель 1e0a67d725
Коммит 347734a288
7 изменённых файлов: 131 добавлений и 48 удалений

Просмотреть файл

@ -956,6 +956,8 @@ public class Parser
case Token.DEFAULT :
mustHaveXML();
decompiler.addToken(Token.DEFAULT);
int nsLine = ts.getLineno();
if (!(ts.matchToken(Token.NAME)

Просмотреть файл

@ -227,15 +227,20 @@ class Namespace extends IdScriptableObject
private static final int
Id_constructor = 1,
Id_toString = 2,
MAX_PROTOTYPE_ID = 2;
Id_toSource = 3,
MAX_PROTOTYPE_ID = 3;
protected int findPrototypeId(String s)
{
int id;
// #generated# Last update: 2004-07-20 19:45:27 CEST
L0: { id = 0; String X = null;
// #generated# Last update: 2004-08-21 12:07:01 CEST
L0: { id = 0; String X = null; int c;
int s_length = s.length();
if (s_length==8) { X="toString";id=Id_toString; }
if (s_length==8) {
c=s.charAt(3);
if (c=='o') { X="toSource";id=Id_toSource; }
else if (c=='t') { X="toString";id=Id_toString; }
}
else if (s_length==11) { X="constructor";id=Id_constructor; }
if (X!=null && X!=s && !X.equals(s)) id = 0;
}
@ -251,6 +256,7 @@ class Namespace extends IdScriptableObject
switch (id) {
case Id_constructor: arity=2; s="constructor"; break;
case Id_toString: arity=0; s="toString"; break;
case Id_toSource: arity=0; s="toSource"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(NAMESPACE_TAG, id, s, arity);
@ -267,10 +273,13 @@ class Namespace extends IdScriptableObject
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
if (id == Id_constructor) {
switch (id) {
case Id_constructor:
return jsConstructor(cx, (thisObj == null), args);
} else if(id == Id_toString) {
return realThis(thisObj, f).jsFunction_toString();
case Id_toString:
return realThis(thisObj, f).toString();
case Id_toSource:
return realThis(thisObj, f).js_toSource();
}
throw new IllegalArgumentException(String.valueOf(id));
}
@ -297,8 +306,29 @@ class Namespace extends IdScriptableObject
}
}
private String jsFunction_toString()
private String js_toSource()
{
return toString();
StringBuffer sb = new StringBuffer();
sb.append('(');
toSourceImpl(prefix, uri, sb);
sb.append(')');
return sb.toString();
}
static void toSourceImpl(String prefix, String uri, StringBuffer sb)
{
sb.append("new Namespace(");
if (uri.length() == 0) {
if (!"".equals(prefix)) throw new IllegalArgumentException(prefix);
} else {
sb.append('\'');
if (prefix != null) {
sb.append(ScriptRuntime.escapeString(prefix, '\''));
sb.append("', '");
}
sb.append(ScriptRuntime.escapeString(uri, '\''));
sb.append('\'');
}
sb.append(')');
}
}

Просмотреть файл

@ -52,7 +52,7 @@ final class QName extends IdScriptableObject
private String localName;
private String uri;
public QName(XMLLibImpl lib, String uri, String localName, String prefix)
QName(XMLLibImpl lib, String uri, String localName, String prefix)
{
super(lib.globalScope(), lib.qnamePrototype);
if (localName == null) throw new IllegalArgumentException();
@ -62,7 +62,7 @@ final class QName extends IdScriptableObject
this.localName = localName;
}
public void exportAsJSClass(boolean sealed)
void exportAsJSClass(boolean sealed)
{
exportAsJSClass(MAX_PROTOTYPE_ID, lib.globalScope(), sealed);
}
@ -96,12 +96,12 @@ final class QName extends IdScriptableObject
return localName;
}
public String prefix()
String prefix()
{
return (prefix == null) ? prefix : "";
}
public String uri()
String uri()
{
return uri;
}
@ -213,15 +213,20 @@ final class QName extends IdScriptableObject
private static final int
Id_constructor = 1,
Id_toString = 2,
MAX_PROTOTYPE_ID = 2;
Id_toSource = 3,
MAX_PROTOTYPE_ID = 3;
protected int findPrototypeId(String s)
{
int id;
// #generated# Last update: 2004-07-18 12:32:51 CEST
L0: { id = 0; String X = null;
// #generated# Last update: 2004-08-21 12:45:13 CEST
L0: { id = 0; String X = null; int c;
int s_length = s.length();
if (s_length==8) { X="toString";id=Id_toString; }
if (s_length==8) {
c=s.charAt(3);
if (c=='o') { X="toSource";id=Id_toSource; }
else if (c=='t') { X="toString";id=Id_toString; }
}
else if (s_length==11) { X="constructor";id=Id_constructor; }
if (X!=null && X!=s && !X.equals(s)) id = 0;
}
@ -237,6 +242,7 @@ final class QName extends IdScriptableObject
switch (id) {
case Id_constructor: arity=2; s="constructor"; break;
case Id_toString: arity=0; s="toString"; break;
case Id_toSource: arity=0; s="toSource"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
initPrototypeMethod(QNAME_TAG, id, s, arity);
@ -253,10 +259,13 @@ final class QName extends IdScriptableObject
return super.execIdCall(f, cx, scope, thisObj, args);
}
int id = f.methodId();
if (id == Id_constructor) {
switch (id) {
case Id_constructor:
return jsConstructor(cx, (thisObj == null), args);
} else if(id == Id_toString) {
return realThis(thisObj, f).jsFunction_toString();
case Id_toString:
return realThis(thisObj, f).toString();
case Id_toSource:
return realThis(thisObj, f).js_toSource();
}
throw new IllegalArgumentException(String.valueOf(id));
}
@ -282,9 +291,30 @@ final class QName extends IdScriptableObject
}
}
private String jsFunction_toString()
private String js_toSource()
{
return toString();
StringBuffer sb = new StringBuffer();
sb.append('(');
toSourceImpl(uri, localName, prefix, sb);
sb.append(')');
return sb.toString();
}
private static void toSourceImpl(String uri, String localName,
String prefix, StringBuffer sb)
{
sb.append("new QName(");
if (uri == null && prefix == null) {
if (!"*".equals(localName)) {
sb.append("null, ");
}
} else {
Namespace.toSourceImpl(prefix, uri, sb);
sb.append(", ");
}
sb.append('\'');
sb.append(ScriptRuntime.escapeString(localName, '\''));
sb.append("')");
}
}

Просмотреть файл

@ -266,7 +266,7 @@ class XML extends XMLObjectImpl
else if (inputObject instanceof XMLObjectImpl)
{
// todo: faster way for XMLObjects?
frag = ((XMLObjectImpl) inputObject).toXMLString();
frag = ((XMLObjectImpl) inputObject).toXMLString(0);
}
else
{
@ -2866,18 +2866,26 @@ todo need to handle namespace prefix not found in XML look for namespace type in
}
else
{
result = toXMLString();
result = toXMLString(0);
}
return result;
}
String toSource(int indent)
{
// XXX Does toXMLString always return valid XML literal?
return toXMLString(indent);
}
/**
*
* @return
*/
String toXMLString ()
String toXMLString(int indent)
{
// XXX indent is ignored
String result;
XmlCursor curs = newCursor();
@ -2977,7 +2985,7 @@ todo need to handle namespace prefix not found in XML look for namespace type in
// Old way of comparing by string.
// boolean orgPrettyPrinting = prototype.prettyPrinting;
// prototype.prettyPrinting = true;
// result = toXMLString().equals(otherXml.toXMLString());
// result = toXMLString(0).equals(otherXml.toXMLString(0));
// prototype.prettyPrinting = orgPrettyPrinting;
}
}

Просмотреть файл

@ -676,7 +676,7 @@ public final class XMLLibImpl extends XMLLib
public String escapeTextValue(Object value)
{
if (value instanceof XMLObjectImpl) {
return ((XMLObjectImpl)value).toXMLString();
return ((XMLObjectImpl)value).toXMLString(0);
}
String text = ScriptRuntime.toString(value);

Просмотреть файл

@ -1405,15 +1405,21 @@ class XMLList extends XMLObjectImpl implements Function
}
else
{
return toXMLString();
return toXMLString(0);
}
}
String toSource(int indent)
{
// XXX indent is ignored
return "<>"+toXMLString(0)+"</>";
}
/**
*
* @return
*/
String toXMLString()
String toXMLString(int indent)
{
StringBuffer sb = new StringBuffer();
@ -1421,13 +1427,10 @@ class XMLList extends XMLObjectImpl implements Function
{
if (i > 0)
{
// Add a line separator
String lineSeparator = System.getProperty("line.separator");
sb.append(lineSeparator);
sb.append('\n');
}
sb.append(getXmlFromAnnotation(i).toXMLString());
sb.append(getXmlFromAnnotation(i).toXMLString(indent));
}
return sb.toString();

Просмотреть файл

@ -127,7 +127,8 @@ abstract class XMLObjectImpl extends XMLObject
abstract void setNamespace(Namespace ns);
abstract XMLList text();
public abstract String toString();
abstract String toXMLString();
abstract String toSource(int indent);
abstract String toXMLString(int indent);
abstract Object valueOf();
protected abstract Object jsConstructor(Context cx, boolean inNewExpr,
@ -330,15 +331,16 @@ abstract class XMLObjectImpl extends XMLObject
Id_setNamespace = 35,
Id_text = 36,
Id_toString = 37,
Id_toXMLString = 38,
Id_valueOf = 39,
Id_toSource = 38,
Id_toXMLString = 39,
Id_valueOf = 40,
MAX_PROTOTYPE_ID = 39;
MAX_PROTOTYPE_ID = 40;
protected int findPrototypeId(String s)
{
int id;
// #generated# Last update: 2004-07-19 13:13:35 CEST
// #generated# Last update: 2004-08-21 11:02:57 CEST
L0: { id = 0; String X = null; int c;
L: switch (s.length()) {
case 4: c=s.charAt(0);
@ -356,12 +358,13 @@ abstract class XMLObjectImpl extends XMLObject
else if (c=='s') { X="setName";id=Id_setName; }
else if (c=='v') { X="valueOf";id=Id_valueOf; }
break L;
case 8: switch (s.charAt(2)) {
case 'S': X="toString";id=Id_toString; break L;
case 'd': X="nodeKind";id=Id_nodeKind; break L;
case 'i': X="children";id=Id_children; break L;
case 'm': X="comments";id=Id_comments; break L;
case 'n': X="contains";id=Id_contains; break L;
case 8: switch (s.charAt(4)) {
case 'K': X="nodeKind";id=Id_nodeKind; break L;
case 'a': X="contains";id=Id_contains; break L;
case 'd': X="children";id=Id_children; break L;
case 'e': X="comments";id=Id_comments; break L;
case 'r': X="toString";id=Id_toString; break L;
case 'u': X="toSource";id=Id_toSource; break L;
} break L;
case 9: switch (s.charAt(2)) {
case 'c': X="localName";id=Id_localName; break L;
@ -466,7 +469,8 @@ abstract class XMLObjectImpl extends XMLObject
case Id_setNamespace: arity=1; s="setNamespace"; break;
case Id_text: arity=0; s="text"; break;
case Id_toString: arity=0; s="toString"; break;
case Id_toXMLString: arity=0; s="toXMLString"; break;
case Id_toSource: arity=1; s="toSource"; break;
case Id_toXMLString: arity=1; s="toXMLString"; break;
case Id_valueOf: arity=0; s="valueOf"; break;
default: throw new IllegalArgumentException(String.valueOf(id));
}
@ -644,8 +648,14 @@ abstract class XMLObjectImpl extends XMLObject
return realThis(thisObj, f).text();
case Id_toString:
return realThis(thisObj, f).toString();
case Id_toXMLString:
return realThis(thisObj, f).toXMLString();
case Id_toSource: {
int indent = ScriptRuntime.toInt32(args, 0);
return realThis(thisObj, f).toSource(indent);
}
case Id_toXMLString: {
int indent = ScriptRuntime.toInt32(args, 0);
return realThis(thisObj, f).toXMLString(indent);
}
case Id_valueOf:
return realThis(thisObj, f).valueOf();
}