emul/src/main/java/java/lang/String.java
branchUseFunctionCall
changeset 443 9359b006782b
parent 429 7c4442271367
child 501 dc07c9001184
     1.1 --- a/emul/src/main/java/java/lang/String.java	Sat Jan 12 15:39:33 2013 +0100
     1.2 +++ b/emul/src/main/java/java/lang/String.java	Mon Jan 14 11:30:56 2013 +0100
     1.3 @@ -169,11 +169,11 @@
     1.4       * @param  value
     1.5       *         The initial value of the string
     1.6       */
     1.7 -    @JavaScriptBody(args = { "self", "charArr" }, body=
     1.8 +    @JavaScriptBody(args = { "charArr" }, body=
     1.9          "for (var i = 0; i < charArr.length; i++) {\n"
    1.10        + "  if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n"
    1.11        + "}\n"
    1.12 -      + "self.fld_r = charArr.join('');\n"
    1.13 +      + "this.fld_r = charArr.join('');\n"
    1.14      )
    1.15      public String(char value[]) {
    1.16      }
    1.17 @@ -199,12 +199,12 @@
    1.18       *          If the {@code offset} and {@code count} arguments index
    1.19       *          characters outside the bounds of the {@code value} array
    1.20       */
    1.21 -    @JavaScriptBody(args = { "self", "charArr", "off", "cnt" }, body =
    1.22 +    @JavaScriptBody(args = { "charArr", "off", "cnt" }, body =
    1.23          "var up = off + cnt;\n" +
    1.24          "for (var i = off; i < up; i++) {\n" +
    1.25          "  if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);\n" +
    1.26          "}\n" +
    1.27 -        "self.fld_r = charArr.slice(off, up).join(\"\");\n"
    1.28 +        "this.fld_r = charArr.slice(off, up).join(\"\");\n"
    1.29      )
    1.30      public String(char value[], int offset, int count) {
    1.31      }
    1.32 @@ -618,7 +618,7 @@
    1.33       * @return  the length of the sequence of characters represented by this
    1.34       *          object.
    1.35       */
    1.36 -    @JavaScriptBody(args = "self", body = "return self.toString().length;")
    1.37 +    @JavaScriptBody(args = {}, body = "return this.toString().length;")
    1.38      public int length() {
    1.39          throw new UnsupportedOperationException();
    1.40      }
    1.41 @@ -631,7 +631,7 @@
    1.42       *
    1.43       * @since 1.6
    1.44       */
    1.45 -    @JavaScriptBody(args = "self", body="return self.toString().length === 0;")
    1.46 +    @JavaScriptBody(args = {}, body="return this.toString().length === 0;")
    1.47      public boolean isEmpty() {
    1.48          return length() == 0;
    1.49      }
    1.50 @@ -654,8 +654,8 @@
    1.51       *             argument is negative or not less than the length of this
    1.52       *             string.
    1.53       */
    1.54 -    @JavaScriptBody(args = { "self", "index" }, 
    1.55 -        body = "return self.toString().charCodeAt(index);"
    1.56 +    @JavaScriptBody(args = { "index" }, 
    1.57 +        body = "return this.toString().charCodeAt(index);"
    1.58      )
    1.59      public char charAt(int index) {
    1.60          throw new UnsupportedOperationException();
    1.61 @@ -780,8 +780,8 @@
    1.62       * Copy characters from this string into dst starting at dstBegin.
    1.63       * This method doesn't perform any range checking.
    1.64       */
    1.65 -    @JavaScriptBody(args = { "self", "arr", "to" }, body = 
    1.66 -        "var s = self.toString();\n" +
    1.67 +    @JavaScriptBody(args = { "arr", "to" }, body = 
    1.68 +        "var s = this.toString();\n" +
    1.69          "for (var i = 0; i < s.length; i++) {\n" +
    1.70          "   arr[to++] = s[i];\n" +
    1.71          "}"
    1.72 @@ -820,8 +820,8 @@
    1.73       *            <li><code>dstBegin+(srcEnd-srcBegin)</code> is larger than
    1.74       *                <code>dst.length</code></ul>
    1.75       */
    1.76 -    @JavaScriptBody(args = { "self", "beg", "end", "arr", "dst" }, body=
    1.77 -        "var s = self.toString();\n" +
    1.78 +    @JavaScriptBody(args = { "beg", "end", "arr", "dst" }, body=
    1.79 +        "var s = this.toString();\n" +
    1.80          "while (beg < end) {\n" +
    1.81          "  arr[dst++] = s[beg++];\n" +
    1.82          "}\n"
    1.83 @@ -993,9 +993,9 @@
    1.84       * @see  #compareTo(String)
    1.85       * @see  #equalsIgnoreCase(String)
    1.86       */
    1.87 -    @JavaScriptBody(args = { "self", "obj" }, body = 
    1.88 +    @JavaScriptBody(args = { "obj" }, body = 
    1.89          "return obj.$instOf_java_lang_String && "
    1.90 -        + "self.toString() === obj.toString();"
    1.91 +        + "this.toString() === obj.toString();"
    1.92      )
    1.93      public boolean equals(Object anObject) {
    1.94          if (this == anObject) {
    1.95 @@ -1420,9 +1420,9 @@
    1.96       *          this.substring(toffset).startsWith(prefix)
    1.97       *          </pre>
    1.98       */
    1.99 -    @JavaScriptBody(args = { "self", "find", "from" }, body=
   1.100 +    @JavaScriptBody(args = { "find", "from" }, body=
   1.101          "find = find.toString();\n" +
   1.102 -        "return self.toString().substring(from, from + find.length) === find;\n"
   1.103 +        "return this.toString().substring(from, from + find.length) === find;\n"
   1.104      )
   1.105      public boolean startsWith(String prefix, int toffset) {
   1.106          char ta[] = toCharArray();
   1.107 @@ -1570,9 +1570,9 @@
   1.108       *          than or equal to <code>fromIndex</code>, or <code>-1</code>
   1.109       *          if the character does not occur.
   1.110       */
   1.111 -    @JavaScriptBody(args = { "self", "ch", "from" }, body = 
   1.112 +    @JavaScriptBody(args = { "ch", "from" }, body = 
   1.113          "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
   1.114 -        "return self.toString().indexOf(ch, from);\n"
   1.115 +        "return this.toString().indexOf(ch, from);\n"
   1.116      )
   1.117      public int indexOf(int ch, int fromIndex) {
   1.118          if (fromIndex < 0) {
   1.119 @@ -1679,9 +1679,9 @@
   1.120       *          than or equal to <code>fromIndex</code>, or <code>-1</code>
   1.121       *          if the character does not occur before that point.
   1.122       */
   1.123 -    @JavaScriptBody(args = { "self", "ch", "from" }, body = 
   1.124 +    @JavaScriptBody(args = { "ch", "from" }, body = 
   1.125          "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
   1.126 -        "return self.toString().lastIndexOf(ch, from);"
   1.127 +        "return this.toString().lastIndexOf(ch, from);"
   1.128      )
   1.129      public int lastIndexOf(int ch, int fromIndex) {
   1.130          if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
   1.131 @@ -1754,8 +1754,8 @@
   1.132       *          starting at the specified index,
   1.133       *          or {@code -1} if there is no such occurrence.
   1.134       */
   1.135 -    @JavaScriptBody(args = { "self", "str", "fromIndex" }, body =
   1.136 -        "return self.toString().indexOf(str.toString(), fromIndex);"
   1.137 +    @JavaScriptBody(args = { "str", "fromIndex" }, body =
   1.138 +        "return this.toString().indexOf(str.toString(), fromIndex);"
   1.139      )
   1.140      public native int indexOf(String str, int fromIndex);
   1.141  
   1.142 @@ -1794,8 +1794,8 @@
   1.143       *          searching backward from the specified index,
   1.144       *          or {@code -1} if there is no such occurrence.
   1.145       */
   1.146 -    @JavaScriptBody(args = { "self", "s", "from" }, body = 
   1.147 -        "return self.toString().lastIndexOf(s.toString(), from);"
   1.148 +    @JavaScriptBody(args = { "s", "from" }, body = 
   1.149 +        "return this.toString().lastIndexOf(s.toString(), from);"
   1.150      )
   1.151      public int lastIndexOf(String str, int fromIndex) {
   1.152          return lastIndexOf(toCharArray(), offset(), length(), str.toCharArray(), str.offset(), str.length(), fromIndex);
   1.153 @@ -1903,8 +1903,8 @@
   1.154       *             <code>beginIndex</code> is larger than
   1.155       *             <code>endIndex</code>.
   1.156       */
   1.157 -    @JavaScriptBody(args = { "self", "beginIndex", "endIndex" }, body = 
   1.158 -        "return self.toString().substring(beginIndex, endIndex);"
   1.159 +    @JavaScriptBody(args = { "beginIndex", "endIndex" }, body = 
   1.160 +        "return this.toString().substring(beginIndex, endIndex);"
   1.161      )
   1.162      public String substring(int beginIndex, int endIndex) {
   1.163          if (beginIndex < 0) {
   1.164 @@ -2012,10 +2012,10 @@
   1.165       * @return  a string derived from this string by replacing every
   1.166       *          occurrence of <code>oldChar</code> with <code>newChar</code>.
   1.167       */
   1.168 -    @JavaScriptBody(args = { "self", "arg1", "arg2" }, body =
   1.169 +    @JavaScriptBody(args = { "arg1", "arg2" }, body =
   1.170          "if (typeof arg1 === 'number') arg1 = String.fromCharCode(arg1);\n" +
   1.171          "if (typeof arg2 === 'number') arg2 = String.fromCharCode(arg2);\n" +
   1.172 -        "var s = self.toString();\n" +
   1.173 +        "var s = this.toString();\n" +
   1.174          "for (;;) {\n" +
   1.175          "  var ret = s.replace(arg1, arg2);\n" +
   1.176          "  if (ret === s) {\n" +
   1.177 @@ -2078,8 +2078,8 @@
   1.178       * @since 1.4
   1.179       * @spec JSR-51
   1.180       */
   1.181 -    @JavaScriptBody(args = { "self", "regex" }, body = 
   1.182 -          "self = self.toString();\n"
   1.183 +    @JavaScriptBody(args = { "regex" }, body = 
   1.184 +          "var self = this.toString();\n"
   1.185          + "var re = new RegExp(regex.toString());\n"
   1.186          + "var r = re.exec(self);\n"
   1.187          + "return r != null && r.length > 0 && self.length == r[0].length;"
   1.188 @@ -2496,7 +2496,7 @@
   1.189       * @return  the <code>String</code>, converted to lowercase.
   1.190       * @see     java.lang.String#toLowerCase(Locale)
   1.191       */
   1.192 -    @JavaScriptBody(args = "self", body = "return self.toLowerCase();")
   1.193 +    @JavaScriptBody(args = {}, body = "return this.toLowerCase();")
   1.194      public String toLowerCase() {
   1.195          throw new UnsupportedOperationException("Should be supported but without connection to locale");
   1.196      }
   1.197 @@ -2662,7 +2662,7 @@
   1.198       * @return  the <code>String</code>, converted to uppercase.
   1.199       * @see     java.lang.String#toUpperCase(Locale)
   1.200       */
   1.201 -    @JavaScriptBody(args = "self", body = "return self.toUpperCase();")
   1.202 +    @JavaScriptBody(args = {}, body = "return this.toUpperCase();")
   1.203      public String toUpperCase() {
   1.204          throw new UnsupportedOperationException();
   1.205      }
   1.206 @@ -2718,7 +2718,7 @@
   1.207       *
   1.208       * @return  the string itself.
   1.209       */
   1.210 -    @JavaScriptBody(args = "self", body = "return self.toString();")
   1.211 +    @JavaScriptBody(args = {}, body = "return this.toString();")
   1.212      public String toString() {
   1.213          return this;
   1.214      }