1.1 --- a/emul/src/main/java/java/lang/Class.java Sat Dec 01 12:15:12 2012 +0100
1.2 +++ b/emul/src/main/java/java/lang/Class.java Sat Dec 01 12:35:30 2012 +0100
1.3 @@ -447,40 +447,57 @@
1.4 * @since 1.5
1.5 */
1.6 public String getSimpleName() {
1.7 - throw new UnsupportedOperationException();
1.8 -//// if (isArray())
1.9 -//// return getComponentType().getSimpleName()+"[]";
1.10 -////
1.11 -//// String simpleName = getSimpleBinaryName();
1.12 -//// if (simpleName == null) { // top level class
1.13 -//// simpleName = getName();
1.14 -//// return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
1.15 -//// }
1.16 -//// // According to JLS3 "Binary Compatibility" (13.1) the binary
1.17 -//// // name of non-package classes (not top level) is the binary
1.18 -//// // name of the immediately enclosing class followed by a '$' followed by:
1.19 -//// // (for nested and inner classes): the simple name.
1.20 -//// // (for local classes): 1 or more digits followed by the simple name.
1.21 -//// // (for anonymous classes): 1 or more digits.
1.22 -////
1.23 -//// // Since getSimpleBinaryName() will strip the binary name of
1.24 -//// // the immediatly enclosing class, we are now looking at a
1.25 -//// // string that matches the regular expression "\$[0-9]*"
1.26 -//// // followed by a simple name (considering the simple of an
1.27 -//// // anonymous class to be the empty string).
1.28 -////
1.29 -//// // Remove leading "\$[0-9]*" from the name
1.30 -//// int length = simpleName.length();
1.31 -//// if (length < 1 || simpleName.charAt(0) != '$')
1.32 -//// throw new InternalError("Malformed class name");
1.33 -//// int index = 1;
1.34 -//// while (index < length && isAsciiDigit(simpleName.charAt(index)))
1.35 -//// index++;
1.36 -//// // Eventually, this is the empty string iff this is an anonymous class
1.37 -//// return simpleName.substring(index);
1.38 + if (isArray())
1.39 + return getComponentType().getSimpleName()+"[]";
1.40 +
1.41 + String simpleName = getSimpleBinaryName();
1.42 + if (simpleName == null) { // top level class
1.43 + simpleName = getName();
1.44 + return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
1.45 + }
1.46 + // According to JLS3 "Binary Compatibility" (13.1) the binary
1.47 + // name of non-package classes (not top level) is the binary
1.48 + // name of the immediately enclosing class followed by a '$' followed by:
1.49 + // (for nested and inner classes): the simple name.
1.50 + // (for local classes): 1 or more digits followed by the simple name.
1.51 + // (for anonymous classes): 1 or more digits.
1.52 +
1.53 + // Since getSimpleBinaryName() will strip the binary name of
1.54 + // the immediatly enclosing class, we are now looking at a
1.55 + // string that matches the regular expression "\$[0-9]*"
1.56 + // followed by a simple name (considering the simple of an
1.57 + // anonymous class to be the empty string).
1.58 +
1.59 + // Remove leading "\$[0-9]*" from the name
1.60 + int length = simpleName.length();
1.61 + if (length < 1 || simpleName.charAt(0) != '$')
1.62 + throw new IllegalStateException("Malformed class name");
1.63 + int index = 1;
1.64 + while (index < length && isAsciiDigit(simpleName.charAt(index)))
1.65 + index++;
1.66 + // Eventually, this is the empty string iff this is an anonymous class
1.67 + return simpleName.substring(index);
1.68 }
1.69
1.70 /**
1.71 + * Returns the "simple binary name" of the underlying class, i.e.,
1.72 + * the binary name without the leading enclosing class name.
1.73 + * Returns {@code null} if the underlying class is a top level
1.74 + * class.
1.75 + */
1.76 + private String getSimpleBinaryName() {
1.77 + Class<?> enclosingClass = null; // XXX getEnclosingClass();
1.78 + if (enclosingClass == null) // top level class
1.79 + return null;
1.80 + // Otherwise, strip the enclosing class' name
1.81 + try {
1.82 + return getName().substring(enclosingClass.getName().length());
1.83 + } catch (IndexOutOfBoundsException ex) {
1.84 + throw new IllegalStateException("Malformed class name");
1.85 + }
1.86 + }
1.87 +
1.88 + /**
1.89 * Character.isDigit answers {@code true} to some non-ascii
1.90 * digits. This one does not.
1.91 */
2.1 --- a/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js Sat Dec 01 12:15:12 2012 +0100
2.2 +++ b/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js Sat Dec 01 12:35:30 2012 +0100
2.3 @@ -71,6 +71,22 @@
2.4 return arg0.toString().indexOf(ch, from);
2.5 }
2.6
2.7 +function java_lang_String_lastIndexOfII(arg0,ch) {
2.8 + if (typeof ch === 'number') ch = String.fromCharCode(ch);
2.9 + return arg0.toString().lastIndexOf(ch);
2.10 +}
2.11 +function java_lang_String_lastIndexOfIII(arg0,ch,from) {
2.12 + if (typeof ch === 'number') ch = String.fromCharCode(ch);
2.13 + return arg0.toString().lastIndexOf(ch, from);
2.14 +}
2.15 +function java_lang_String_lastIndexOfILjava_lang_String(arg0,s) {
2.16 + return arg0.toString().lastIndexOf(s.toString());
2.17 +}
2.18 +function java_lang_String_lastIndexOfILjava_lang_StringI(arg0,s,from) {
2.19 + return arg0.toString().lastIndexOf(s.toString(), from);
2.20 +}
2.21 +
2.22 +
2.23 function java_lang_String_getCharsVACI(self, arr, to) {
2.24 var s = self.toString();
2.25 for (var i = 0; i < s.length; i++) {
2.26 @@ -434,6 +450,10 @@
2.27 String.prototype.endsWithZLjava_lang_String=java_lang_String_endsWithZLjava_lang_String;
2.28 String.prototype.indexOfII=java_lang_String_indexOfII;
2.29 String.prototype.indexOfIII=java_lang_String_indexOfIII;
2.30 +String.prototype.lastIndexOfII=java_lang_String_lastIndexOfII;
2.31 +String.prototype.lastIndexOfIII=java_lang_String_lastIndexOfIII;
2.32 +String.prototype.lastIndexOfILjava_lang_String=java_lang_String_lastIndexOfILjava_lang_String;
2.33 +String.prototype.lastIndexOfILjava_lang_StringI=java_lang_String_lastIndexOfILjava_lang_StringI;
2.34
2.35 String.prototype.$instOf_java_lang_String = true;
2.36 String.prototype.$instOf_java_io_Serializable = true;
2.37 @@ -1893,121 +1913,6 @@
2.38 case 14: return stack.pop(); // 172
2.39 }
2.40 }
2.41 -function java_lang_String_lastIndexOfII(arg0,arg1) {
2.42 - var arg2;
2.43 -;
2.44 - var stack = new Array(4);
2.45 - var gt = 0;
2.46 - for(;;) switch(gt) {
2.47 - case 0: stack.push(arg0); // 42
2.48 - case 1: stack.push(arg1); // 27
2.49 - case 2: stack.push(arg0); // 42
2.50 - case 3: stack.push(stack.pop().count); // 180 1 97
2.51 - case 6: stack.push(1); // 4
2.52 - case 7: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
2.53 - case 8: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.lastIndexOfIII(self, v0, v1)); } // 182 1 136
2.54 - case 11: return stack.pop(); // 172
2.55 - }
2.56 -}
2.57 -function java_lang_String_lastIndexOfIII(arg0,arg1,arg2) {
2.58 - var arg3;
2.59 - var arg4;
2.60 - var arg5;
2.61 - var arg6;
2.62 - var arg7;
2.63 - var arg8;
2.64 -;
2.65 - var stack = new Array(3);
2.66 - var gt = 0;
2.67 - for(;;) switch(gt) {
2.68 - case 0: stack.push(arg0); // 42
2.69 - case 1: stack.push(stack.pop().offset); // 180 1 99
2.70 - case 4: arg3 = stack.pop(); // 62
2.71 - case 5: stack.push(arg0); // 42
2.72 - case 6: stack.push(stack.pop().value); // 180 1 100
2.73 - case 9: arg4 = stack.pop() // 58 4
2.74 - case 11: stack.push(arg0); // 42
2.75 - case 12: stack.push(stack.pop().offset); // 180 1 99
2.76 - case 15: stack.push(arg2); // 28
2.77 - case 16: stack.push(arg0); // 42
2.78 - case 17: stack.push(stack.pop().count); // 180 1 97
2.79 - case 20: if (stack.pop() > stack.pop()) { gt = 32; continue; } // 161 0 12
2.80 - case 23: stack.push(arg0); // 42
2.81 - case 24: stack.push(stack.pop().count); // 180 1 97
2.82 - case 27: stack.push(1); // 4
2.83 - case 28: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
2.84 - case 29: gt = 33; continue; // 167 0 4
2.85 - case 32: stack.push(arg2); // 28
2.86 - case 33: stack.push(stack.pop() + stack.pop()); // 96
2.87 - case 34: arg5 = stack.pop() // 54 5
2.88 - case 36: stack.push(arg1); // 27
2.89 - case 37: stack.push(65536); // 18 3
2.90 - case 39: if (stack.pop() <= stack.pop()) { gt = 73; continue; } // 162 0 34
2.91 - case 42: stack.push(arg5); // 21 5
2.92 - case 44: stack.push(arg3); // 29
2.93 - case 45: if (stack.pop() > stack.pop()) { gt = 71; continue; } // 161 0 26
2.94 - case 48: stack.push(arg4); // 25 4
2.95 - case 50: stack.push(arg5); // 21 5
2.96 - case 52: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
2.97 - case 53: stack.push(arg1); // 27
2.98 - case 54: if (stack.pop() != stack.pop()) { gt = 65; continue; } // 160 0 11
2.99 - case 57: stack.push(arg5); // 21 5
2.100 - case 59: stack.push(arg0); // 42
2.101 - case 60: stack.push(stack.pop().offset); // 180 1 99
2.102 - case 63: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
2.103 - case 64: return stack.pop(); // 172
2.104 - case 65: arg5 += 255; // 132 5 255
2.105 - case 68: gt = 42; continue; // 167 255 230
2.106 - case 71: // 2
2.107 - case 72: return stack.pop(); // 172
2.108 - case 73: stack.push(arg0); // 42
2.109 - case 74: stack.push(stack.pop().offset); // 180 1 99
2.110 - case 77: stack.push(arg0); // 42
2.111 - case 78: stack.push(stack.pop().count); // 180 1 97
2.112 - case 81: stack.push(stack.pop() + stack.pop()); // 96
2.113 - case 82: arg6 = stack.pop() // 54 6
2.114 - case 84: stack.push(arg1); // 27
2.115 - case 85: stack.push(1114111); // 18 4
2.116 - case 87: if (stack.pop() < stack.pop()) { gt = 154; continue; } // 163 0 67
2.117 - case 90: stack.push(arg1); // 27
2.118 - case 91: { var v0 = stack.pop(); stack.push(java_lang_Character_toCharsACI(v0)); } // 184 1 109
2.119 - case 94: arg7 = stack.pop() // 58 7
2.120 - case 96: stack.push(arg5); // 21 5
2.121 - case 98: stack.push(arg3); // 29
2.122 - case 99: if (stack.pop() > stack.pop()) { gt = 154; continue; } // 161 0 55
2.123 - case 102: stack.push(arg4); // 25 4
2.124 - case 104: stack.push(arg5); // 21 5
2.125 - case 106: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
2.126 - case 107: stack.push(arg7); // 25 7
2.127 - case 109: stack.push(0); // 3
2.128 - case 110: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
2.129 - case 111: if (stack.pop() != stack.pop()) { gt = 148; continue; } // 160 0 37
2.130 - case 114: stack.push(arg5); // 21 5
2.131 - case 116: stack.push(1); // 4
2.132 - case 117: stack.push(stack.pop() + stack.pop()); // 96
2.133 - case 118: stack.push(arg6); // 21 6
2.134 - case 120: if (stack.pop() != stack.pop()) { gt = 126; continue; } // 160 0 6
2.135 - case 123: gt = 154; continue; // 167 0 31
2.136 - case 126: stack.push(arg4); // 25 4
2.137 - case 128: stack.push(arg5); // 21 5
2.138 - case 130: stack.push(1); // 4
2.139 - case 131: stack.push(stack.pop() + stack.pop()); // 96
2.140 - case 132: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
2.141 - case 133: stack.push(arg7); // 25 7
2.142 - case 135: stack.push(1); // 4
2.143 - case 136: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
2.144 - case 137: if (stack.pop() != stack.pop()) { gt = 148; continue; } // 160 0 11
2.145 - case 140: stack.push(arg5); // 21 5
2.146 - case 142: stack.push(arg0); // 42
2.147 - case 143: stack.push(stack.pop().offset); // 180 1 99
2.148 - case 146: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
2.149 - case 147: return stack.pop(); // 172
2.150 - case 148: arg5 += 255; // 132 5 255
2.151 - case 151: gt = 96; continue; // 167 255 201
2.152 - case 154: // 2
2.153 - case 155: return stack.pop(); // 172
2.154 - }
2.155 -}
2.156 function java_lang_String_indexOfILjava_lang_String(arg0,arg1) {
2.157 var arg2;
2.158 ;
2.159 @@ -2146,43 +2051,6 @@
2.160 case 165: return stack.pop(); // 172
2.161 }
2.162 }
2.163 -function java_lang_String_lastIndexOfILjava_lang_String(arg0,arg1) {
2.164 - var arg2;
2.165 -;
2.166 - var stack = new Array(3);
2.167 - var gt = 0;
2.168 - for(;;) switch(gt) {
2.169 - case 0: stack.push(arg0); // 42
2.170 - case 1: stack.push(arg1); // 43
2.171 - case 2: stack.push(arg0); // 42
2.172 - case 3: stack.push(stack.pop().count); // 180 1 97
2.173 - case 6: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.lastIndexOfILjava_lang_StringI(self, v0, v1)); } // 182 1 151
2.174 - case 9: return stack.pop(); // 172
2.175 - }
2.176 -}
2.177 -function java_lang_String_lastIndexOfILjava_lang_StringI(arg0,arg1,arg2) {
2.178 - var arg3;
2.179 -;
2.180 - var stack = new Array(7);
2.181 - var gt = 0;
2.182 - for(;;) switch(gt) {
2.183 - case 0: stack.push(arg0); // 42
2.184 - case 1: stack.push(stack.pop().value); // 180 1 100
2.185 - case 4: stack.push(arg0); // 42
2.186 - case 5: stack.push(stack.pop().offset); // 180 1 99
2.187 - case 8: stack.push(arg0); // 42
2.188 - case 9: stack.push(stack.pop().count); // 180 1 97
2.189 - case 12: stack.push(arg1); // 43
2.190 - case 13: stack.push(stack.pop().value); // 180 1 100
2.191 - case 16: stack.push(arg1); // 43
2.192 - case 17: stack.push(stack.pop().offset); // 180 1 99
2.193 - case 20: stack.push(arg1); // 43
2.194 - case 21: stack.push(stack.pop().count); // 180 1 97
2.195 - case 24: stack.push(arg2); // 28
2.196 - case 25: { var v6 = stack.pop(); var v5 = stack.pop(); var v4 = stack.pop(); var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_String_lastIndexOfAIACAIAIACAIAIAI(v0, v1, v2, v3, v4, v5, v6)); } // 184 1 145
2.197 - case 28: return stack.pop(); // 172
2.198 - }
2.199 -}
2.200 function java_lang_String_lastIndexOfIACIIACIII(arg0,arg1,arg2,arg3,arg4,arg5,arg6) {
2.201 var arg7;
2.202 var arg8;