javap branch achieved its goal: ByteCodeToJavaScript can be executed in bck2brwsr VM. Merging to main branch.
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 18 Nov 2012 22:03:15 +0100
changeset 1896a56c2381b0f
parent 159 d0aad97dfd2e
parent 188 51d08c49e9b6
child 190 6060d43a323a
javap branch achieved its goal: ByteCodeToJavaScript can be executed in bck2brwsr VM. Merging to main branch.
javaquery/demo-calculator/pom.xml
mojo/pom.xml
vm/pom.xml
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/emul/src/main/java/java/io/ByteArrayInputStream.java	Sun Nov 18 22:03:15 2012 +0100
     1.3 @@ -0,0 +1,283 @@
     1.4 +/*
     1.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package java.io;
    1.30 +
    1.31 +/**
    1.32 + * A <code>ByteArrayInputStream</code> contains
    1.33 + * an internal buffer that contains bytes that
    1.34 + * may be read from the stream. An internal
    1.35 + * counter keeps track of the next byte to
    1.36 + * be supplied by the <code>read</code> method.
    1.37 + * <p>
    1.38 + * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
    1.39 + * this class can be called after the stream has been closed without
    1.40 + * generating an <tt>IOException</tt>.
    1.41 + *
    1.42 + * @author  Arthur van Hoff
    1.43 + * @see     java.io.StringBufferInputStream
    1.44 + * @since   JDK1.0
    1.45 + */
    1.46 +public
    1.47 +class ByteArrayInputStream extends InputStream {
    1.48 +
    1.49 +    /**
    1.50 +     * An array of bytes that was provided
    1.51 +     * by the creator of the stream. Elements <code>buf[0]</code>
    1.52 +     * through <code>buf[count-1]</code> are the
    1.53 +     * only bytes that can ever be read from the
    1.54 +     * stream;  element <code>buf[pos]</code> is
    1.55 +     * the next byte to be read.
    1.56 +     */
    1.57 +    protected byte buf[];
    1.58 +
    1.59 +    /**
    1.60 +     * The index of the next character to read from the input stream buffer.
    1.61 +     * This value should always be nonnegative
    1.62 +     * and not larger than the value of <code>count</code>.
    1.63 +     * The next byte to be read from the input stream buffer
    1.64 +     * will be <code>buf[pos]</code>.
    1.65 +     */
    1.66 +    protected int pos;
    1.67 +
    1.68 +    /**
    1.69 +     * The currently marked position in the stream.
    1.70 +     * ByteArrayInputStream objects are marked at position zero by
    1.71 +     * default when constructed.  They may be marked at another
    1.72 +     * position within the buffer by the <code>mark()</code> method.
    1.73 +     * The current buffer position is set to this point by the
    1.74 +     * <code>reset()</code> method.
    1.75 +     * <p>
    1.76 +     * If no mark has been set, then the value of mark is the offset
    1.77 +     * passed to the constructor (or 0 if the offset was not supplied).
    1.78 +     *
    1.79 +     * @since   JDK1.1
    1.80 +     */
    1.81 +    protected int mark = 0;
    1.82 +
    1.83 +    /**
    1.84 +     * The index one greater than the last valid character in the input
    1.85 +     * stream buffer.
    1.86 +     * This value should always be nonnegative
    1.87 +     * and not larger than the length of <code>buf</code>.
    1.88 +     * It  is one greater than the position of
    1.89 +     * the last byte within <code>buf</code> that
    1.90 +     * can ever be read  from the input stream buffer.
    1.91 +     */
    1.92 +    protected int count;
    1.93 +
    1.94 +    /**
    1.95 +     * Creates a <code>ByteArrayInputStream</code>
    1.96 +     * so that it  uses <code>buf</code> as its
    1.97 +     * buffer array.
    1.98 +     * The buffer array is not copied.
    1.99 +     * The initial value of <code>pos</code>
   1.100 +     * is <code>0</code> and the initial value
   1.101 +     * of  <code>count</code> is the length of
   1.102 +     * <code>buf</code>.
   1.103 +     *
   1.104 +     * @param   buf   the input buffer.
   1.105 +     */
   1.106 +    public ByteArrayInputStream(byte buf[]) {
   1.107 +        this.buf = buf;
   1.108 +        this.pos = 0;
   1.109 +        this.count = buf.length;
   1.110 +    }
   1.111 +
   1.112 +    /**
   1.113 +     * Creates <code>ByteArrayInputStream</code>
   1.114 +     * that uses <code>buf</code> as its
   1.115 +     * buffer array. The initial value of <code>pos</code>
   1.116 +     * is <code>offset</code> and the initial value
   1.117 +     * of <code>count</code> is the minimum of <code>offset+length</code>
   1.118 +     * and <code>buf.length</code>.
   1.119 +     * The buffer array is not copied. The buffer's mark is
   1.120 +     * set to the specified offset.
   1.121 +     *
   1.122 +     * @param   buf      the input buffer.
   1.123 +     * @param   offset   the offset in the buffer of the first byte to read.
   1.124 +     * @param   length   the maximum number of bytes to read from the buffer.
   1.125 +     */
   1.126 +    public ByteArrayInputStream(byte buf[], int offset, int length) {
   1.127 +        this.buf = buf;
   1.128 +        this.pos = offset;
   1.129 +        this.count = Math.min(offset + length, buf.length);
   1.130 +        this.mark = offset;
   1.131 +    }
   1.132 +
   1.133 +    /**
   1.134 +     * Reads the next byte of data from this input stream. The value
   1.135 +     * byte is returned as an <code>int</code> in the range
   1.136 +     * <code>0</code> to <code>255</code>. If no byte is available
   1.137 +     * because the end of the stream has been reached, the value
   1.138 +     * <code>-1</code> is returned.
   1.139 +     * <p>
   1.140 +     * This <code>read</code> method
   1.141 +     * cannot block.
   1.142 +     *
   1.143 +     * @return  the next byte of data, or <code>-1</code> if the end of the
   1.144 +     *          stream has been reached.
   1.145 +     */
   1.146 +    public synchronized int read() {
   1.147 +        return (pos < count) ? (buf[pos++] & 0xff) : -1;
   1.148 +    }
   1.149 +
   1.150 +    /**
   1.151 +     * Reads up to <code>len</code> bytes of data into an array of bytes
   1.152 +     * from this input stream.
   1.153 +     * If <code>pos</code> equals <code>count</code>,
   1.154 +     * then <code>-1</code> is returned to indicate
   1.155 +     * end of file. Otherwise, the  number <code>k</code>
   1.156 +     * of bytes read is equal to the smaller of
   1.157 +     * <code>len</code> and <code>count-pos</code>.
   1.158 +     * If <code>k</code> is positive, then bytes
   1.159 +     * <code>buf[pos]</code> through <code>buf[pos+k-1]</code>
   1.160 +     * are copied into <code>b[off]</code>  through
   1.161 +     * <code>b[off+k-1]</code> in the manner performed
   1.162 +     * by <code>System.arraycopy</code>. The
   1.163 +     * value <code>k</code> is added into <code>pos</code>
   1.164 +     * and <code>k</code> is returned.
   1.165 +     * <p>
   1.166 +     * This <code>read</code> method cannot block.
   1.167 +     *
   1.168 +     * @param   b     the buffer into which the data is read.
   1.169 +     * @param   off   the start offset in the destination array <code>b</code>
   1.170 +     * @param   len   the maximum number of bytes read.
   1.171 +     * @return  the total number of bytes read into the buffer, or
   1.172 +     *          <code>-1</code> if there is no more data because the end of
   1.173 +     *          the stream has been reached.
   1.174 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
   1.175 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
   1.176 +     * <code>len</code> is negative, or <code>len</code> is greater than
   1.177 +     * <code>b.length - off</code>
   1.178 +     */
   1.179 +    public synchronized int read(byte b[], int off, int len) {
   1.180 +        if (b == null) {
   1.181 +            throw new NullPointerException();
   1.182 +        } else if (off < 0 || len < 0 || len > b.length - off) {
   1.183 +            throw new IndexOutOfBoundsException();
   1.184 +        }
   1.185 +
   1.186 +        if (pos >= count) {
   1.187 +            return -1;
   1.188 +        }
   1.189 +
   1.190 +        int avail = count - pos;
   1.191 +        if (len > avail) {
   1.192 +            len = avail;
   1.193 +        }
   1.194 +        if (len <= 0) {
   1.195 +            return 0;
   1.196 +        }
   1.197 +        PushbackInputStream.arraycopy(buf, pos, b, off, len);
   1.198 +        pos += len;
   1.199 +        return len;
   1.200 +    }
   1.201 +
   1.202 +    /**
   1.203 +     * Skips <code>n</code> bytes of input from this input stream. Fewer
   1.204 +     * bytes might be skipped if the end of the input stream is reached.
   1.205 +     * The actual number <code>k</code>
   1.206 +     * of bytes to be skipped is equal to the smaller
   1.207 +     * of <code>n</code> and  <code>count-pos</code>.
   1.208 +     * The value <code>k</code> is added into <code>pos</code>
   1.209 +     * and <code>k</code> is returned.
   1.210 +     *
   1.211 +     * @param   n   the number of bytes to be skipped.
   1.212 +     * @return  the actual number of bytes skipped.
   1.213 +     */
   1.214 +    public synchronized long skip(long n) {
   1.215 +        long k = count - pos;
   1.216 +        if (n < k) {
   1.217 +            k = n < 0 ? 0 : n;
   1.218 +        }
   1.219 +
   1.220 +        pos += k;
   1.221 +        return k;
   1.222 +    }
   1.223 +
   1.224 +    /**
   1.225 +     * Returns the number of remaining bytes that can be read (or skipped over)
   1.226 +     * from this input stream.
   1.227 +     * <p>
   1.228 +     * The value returned is <code>count&nbsp;- pos</code>,
   1.229 +     * which is the number of bytes remaining to be read from the input buffer.
   1.230 +     *
   1.231 +     * @return  the number of remaining bytes that can be read (or skipped
   1.232 +     *          over) from this input stream without blocking.
   1.233 +     */
   1.234 +    public synchronized int available() {
   1.235 +        return count - pos;
   1.236 +    }
   1.237 +
   1.238 +    /**
   1.239 +     * Tests if this <code>InputStream</code> supports mark/reset. The
   1.240 +     * <code>markSupported</code> method of <code>ByteArrayInputStream</code>
   1.241 +     * always returns <code>true</code>.
   1.242 +     *
   1.243 +     * @since   JDK1.1
   1.244 +     */
   1.245 +    public boolean markSupported() {
   1.246 +        return true;
   1.247 +    }
   1.248 +
   1.249 +    /**
   1.250 +     * Set the current marked position in the stream.
   1.251 +     * ByteArrayInputStream objects are marked at position zero by
   1.252 +     * default when constructed.  They may be marked at another
   1.253 +     * position within the buffer by this method.
   1.254 +     * <p>
   1.255 +     * If no mark has been set, then the value of the mark is the
   1.256 +     * offset passed to the constructor (or 0 if the offset was not
   1.257 +     * supplied).
   1.258 +     *
   1.259 +     * <p> Note: The <code>readAheadLimit</code> for this class
   1.260 +     *  has no meaning.
   1.261 +     *
   1.262 +     * @since   JDK1.1
   1.263 +     */
   1.264 +    public void mark(int readAheadLimit) {
   1.265 +        mark = pos;
   1.266 +    }
   1.267 +
   1.268 +    /**
   1.269 +     * Resets the buffer to the marked position.  The marked position
   1.270 +     * is 0 unless another position was marked or an offset was specified
   1.271 +     * in the constructor.
   1.272 +     */
   1.273 +    public synchronized void reset() {
   1.274 +        pos = mark;
   1.275 +    }
   1.276 +
   1.277 +    /**
   1.278 +     * Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
   1.279 +     * this class can be called after the stream has been closed without
   1.280 +     * generating an <tt>IOException</tt>.
   1.281 +     * <p>
   1.282 +     */
   1.283 +    public void close() throws IOException {
   1.284 +    }
   1.285 +
   1.286 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/emul/src/main/java/java/io/DataInput.java	Sun Nov 18 22:03:15 2012 +0100
     2.3 @@ -0,0 +1,635 @@
     2.4 +/*
     2.5 + * Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.  Oracle designates this
    2.11 + * particular file as subject to the "Classpath" exception as provided
    2.12 + * by Oracle in the LICENSE file that accompanied this code.
    2.13 + *
    2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.17 + * version 2 for more details (a copy is included in the LICENSE file that
    2.18 + * accompanied this code).
    2.19 + *
    2.20 + * You should have received a copy of the GNU General Public License version
    2.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.23 + *
    2.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.25 + * or visit www.oracle.com if you need additional information or have any
    2.26 + * questions.
    2.27 + */
    2.28 +
    2.29 +package java.io;
    2.30 +
    2.31 +/**
    2.32 + * The <code>DataInput</code> interface provides
    2.33 + * for reading bytes from a binary stream and
    2.34 + * reconstructing from them data in any of
    2.35 + * the Java primitive types. There is also
    2.36 + * a
    2.37 + * facility for reconstructing a <code>String</code>
    2.38 + * from data in
    2.39 + * <a href="#modified-utf-8">modified UTF-8</a>
    2.40 + * format.
    2.41 + * <p>
    2.42 + * It is generally true of all the reading
    2.43 + * routines in this interface that if end of
    2.44 + * file is reached before the desired number
    2.45 + * of bytes has been read, an <code>EOFException</code>
    2.46 + * (which is a kind of <code>IOException</code>)
    2.47 + * is thrown. If any byte cannot be read for
    2.48 + * any reason other than end of file, an <code>IOException</code>
    2.49 + * other than <code>EOFException</code> is
    2.50 + * thrown. In particular, an <code>IOException</code>
    2.51 + * may be thrown if the input stream has been
    2.52 + * closed.
    2.53 + *
    2.54 + * <h4><a name="modified-utf-8">Modified UTF-8</a></h4>
    2.55 + * <p>
    2.56 + * Implementations of the DataInput and DataOutput interfaces represent
    2.57 + * Unicode strings in a format that is a slight modification of UTF-8.
    2.58 + * (For information regarding the standard UTF-8 format, see section
    2.59 + * <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version
    2.60 + * 4.0</i>).
    2.61 + * Note that in the following tables, the most significant bit appears in the
    2.62 + * far left-hand column.
    2.63 + * <p>
    2.64 + * All characters in the range <code>'&#92;u0001'</code> to
    2.65 + * <code>'&#92;u007F'</code> are represented by a single byte:
    2.66 + *
    2.67 + * <blockquote>
    2.68 + *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
    2.69 + *          summary="Bit values and bytes">
    2.70 + *     <tr>
    2.71 + *       <td></td>
    2.72 + *       <th id="bit">Bit Values</th>
    2.73 + *     </tr>
    2.74 + *     <tr>
    2.75 + *       <th id="byte1">Byte 1</th>
    2.76 + *       <td>
    2.77 + *         <table border="1" cellspacing="0" width="100%">
    2.78 + *           <tr>
    2.79 + *             <td width="12%"><center>0</center>
    2.80 + *             <td colspan="7"><center>bits 6-0</center>
    2.81 + *           </tr>
    2.82 + *         </table>
    2.83 + *       </td>
    2.84 + *     </tr>
    2.85 + *   </table>
    2.86 + * </blockquote>
    2.87 + *
    2.88 + * <p>
    2.89 + * The null character <code>'&#92;u0000'</code> and characters in the
    2.90 + * range <code>'&#92;u0080'</code> to <code>'&#92;u07FF'</code> are
    2.91 + * represented by a pair of bytes:
    2.92 + *
    2.93 + * <blockquote>
    2.94 + *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
    2.95 + *          summary="Bit values and bytes">
    2.96 + *     <tr>
    2.97 + *       <td></td>
    2.98 + *       <th id="bit">Bit Values</th>
    2.99 + *     </tr>
   2.100 + *     <tr>
   2.101 + *       <th id="byte1">Byte 1</th>
   2.102 + *       <td>
   2.103 + *         <table border="1" cellspacing="0" width="100%">
   2.104 + *           <tr>
   2.105 + *             <td width="12%"><center>1</center>
   2.106 + *             <td width="13%"><center>1</center>
   2.107 + *             <td width="12%"><center>0</center>
   2.108 + *             <td colspan="5"><center>bits 10-6</center>
   2.109 + *           </tr>
   2.110 + *         </table>
   2.111 + *       </td>
   2.112 + *     </tr>
   2.113 + *     <tr>
   2.114 + *       <th id="byte2">Byte 2</th>
   2.115 + *       <td>
   2.116 + *         <table border="1" cellspacing="0" width="100%">
   2.117 + *           <tr>
   2.118 + *             <td width="12%"><center>1</center>
   2.119 + *             <td width="13%"><center>0</center>
   2.120 + *             <td colspan="6"><center>bits 5-0</center>
   2.121 + *           </tr>
   2.122 + *         </table>
   2.123 + *       </td>
   2.124 + *     </tr>
   2.125 + *   </table>
   2.126 + *  </blockquote>
   2.127 + *
   2.128 + * <br>
   2.129 + * <code>char</code> values in the range <code>'&#92;u0800'</code> to
   2.130 + * <code>'&#92;uFFFF'</code> are represented by three bytes:
   2.131 + *
   2.132 + * <blockquote>
   2.133 + *   <table border="1" cellspacing="0" cellpadding="8" width="50%"
   2.134 + *          summary="Bit values and bytes">
   2.135 + *     <tr>
   2.136 + *       <td></td>
   2.137 + *       <th id="bit">Bit Values</th>
   2.138 + *     </tr>
   2.139 + *     <tr>
   2.140 + *       <th id="byte1">Byte 1</th>
   2.141 + *       <td>
   2.142 + *         <table border="1" cellspacing="0" width="100%">
   2.143 + *           <tr>
   2.144 + *             <td width="12%"><center>1</center>
   2.145 + *             <td width="13%"><center>1</center>
   2.146 + *             <td width="12%"><center>1</center>
   2.147 + *             <td width="13%"><center>0</center>
   2.148 + *             <td colspan="4"><center>bits 15-12</center>
   2.149 + *           </tr>
   2.150 + *         </table>
   2.151 + *       </td>
   2.152 + *     </tr>
   2.153 + *     <tr>
   2.154 + *       <th id="byte2">Byte 2</th>
   2.155 + *       <td>
   2.156 + *         <table border="1" cellspacing="0" width="100%">
   2.157 + *           <tr>
   2.158 + *             <td width="12%"><center>1</center>
   2.159 + *             <td width="13%"><center>0</center>
   2.160 + *             <td colspan="6"><center>bits 11-6</center>
   2.161 + *           </tr>
   2.162 + *         </table>
   2.163 + *       </td>
   2.164 + *     </tr>
   2.165 + *     <tr>
   2.166 + *       <th id="byte3">Byte 3</th>
   2.167 + *       <td>
   2.168 + *         <table border="1" cellspacing="0" width="100%">
   2.169 + *           <tr>
   2.170 + *             <td width="12%"><center>1</center>
   2.171 + *             <td width="13%"><center>0</center>
   2.172 + *             <td colspan="6"><center>bits 5-0</center>
   2.173 + *           </tr>
   2.174 + *         </table>
   2.175 + *       </td>
   2.176 + *     </tr>
   2.177 + *   </table>
   2.178 + *  </blockquote>
   2.179 + *
   2.180 + * <p>
   2.181 + * The differences between this format and the
   2.182 + * standard UTF-8 format are the following:
   2.183 + * <ul>
   2.184 + * <li>The null byte <code>'&#92;u0000'</code> is encoded in 2-byte format
   2.185 + *     rather than 1-byte, so that the encoded strings never have
   2.186 + *     embedded nulls.
   2.187 + * <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
   2.188 + * <li><a href="../lang/Character.html#unicode">Supplementary characters</a>
   2.189 + *     are represented in the form of surrogate pairs.
   2.190 + * </ul>
   2.191 + * @author  Frank Yellin
   2.192 + * @see     java.io.DataInputStream
   2.193 + * @see     java.io.DataOutput
   2.194 + * @since   JDK1.0
   2.195 + */
   2.196 +public
   2.197 +interface DataInput {
   2.198 +    /**
   2.199 +     * Reads some bytes from an input
   2.200 +     * stream and stores them into the buffer
   2.201 +     * array <code>b</code>. The number of bytes
   2.202 +     * read is equal
   2.203 +     * to the length of <code>b</code>.
   2.204 +     * <p>
   2.205 +     * This method blocks until one of the
   2.206 +     * following conditions occurs:<p>
   2.207 +     * <ul>
   2.208 +     * <li><code>b.length</code>
   2.209 +     * bytes of input data are available, in which
   2.210 +     * case a normal return is made.
   2.211 +     *
   2.212 +     * <li>End of
   2.213 +     * file is detected, in which case an <code>EOFException</code>
   2.214 +     * is thrown.
   2.215 +     *
   2.216 +     * <li>An I/O error occurs, in
   2.217 +     * which case an <code>IOException</code> other
   2.218 +     * than <code>EOFException</code> is thrown.
   2.219 +     * </ul>
   2.220 +     * <p>
   2.221 +     * If <code>b</code> is <code>null</code>,
   2.222 +     * a <code>NullPointerException</code> is thrown.
   2.223 +     * If <code>b.length</code> is zero, then
   2.224 +     * no bytes are read. Otherwise, the first
   2.225 +     * byte read is stored into element <code>b[0]</code>,
   2.226 +     * the next one into <code>b[1]</code>, and
   2.227 +     * so on.
   2.228 +     * If an exception is thrown from
   2.229 +     * this method, then it may be that some but
   2.230 +     * not all bytes of <code>b</code> have been
   2.231 +     * updated with data from the input stream.
   2.232 +     *
   2.233 +     * @param     b   the buffer into which the data is read.
   2.234 +     * @exception  EOFException  if this stream reaches the end before reading
   2.235 +     *               all the bytes.
   2.236 +     * @exception  IOException   if an I/O error occurs.
   2.237 +     */
   2.238 +    void readFully(byte b[]) throws IOException;
   2.239 +
   2.240 +    /**
   2.241 +     *
   2.242 +     * Reads <code>len</code>
   2.243 +     * bytes from
   2.244 +     * an input stream.
   2.245 +     * <p>
   2.246 +     * This method
   2.247 +     * blocks until one of the following conditions
   2.248 +     * occurs:<p>
   2.249 +     * <ul>
   2.250 +     * <li><code>len</code> bytes
   2.251 +     * of input data are available, in which case
   2.252 +     * a normal return is made.
   2.253 +     *
   2.254 +     * <li>End of file
   2.255 +     * is detected, in which case an <code>EOFException</code>
   2.256 +     * is thrown.
   2.257 +     *
   2.258 +     * <li>An I/O error occurs, in
   2.259 +     * which case an <code>IOException</code> other
   2.260 +     * than <code>EOFException</code> is thrown.
   2.261 +     * </ul>
   2.262 +     * <p>
   2.263 +     * If <code>b</code> is <code>null</code>,
   2.264 +     * a <code>NullPointerException</code> is thrown.
   2.265 +     * If <code>off</code> is negative, or <code>len</code>
   2.266 +     * is negative, or <code>off+len</code> is
   2.267 +     * greater than the length of the array <code>b</code>,
   2.268 +     * then an <code>IndexOutOfBoundsException</code>
   2.269 +     * is thrown.
   2.270 +     * If <code>len</code> is zero,
   2.271 +     * then no bytes are read. Otherwise, the first
   2.272 +     * byte read is stored into element <code>b[off]</code>,
   2.273 +     * the next one into <code>b[off+1]</code>,
   2.274 +     * and so on. The number of bytes read is,
   2.275 +     * at most, equal to <code>len</code>.
   2.276 +     *
   2.277 +     * @param     b   the buffer into which the data is read.
   2.278 +     * @param off  an int specifying the offset into the data.
   2.279 +     * @param len  an int specifying the number of bytes to read.
   2.280 +     * @exception  EOFException  if this stream reaches the end before reading
   2.281 +     *               all the bytes.
   2.282 +     * @exception  IOException   if an I/O error occurs.
   2.283 +     */
   2.284 +    void readFully(byte b[], int off, int len) throws IOException;
   2.285 +
   2.286 +    /**
   2.287 +     * Makes an attempt to skip over
   2.288 +     * <code>n</code> bytes
   2.289 +     * of data from the input
   2.290 +     * stream, discarding the skipped bytes. However,
   2.291 +     * it may skip
   2.292 +     * over some smaller number of
   2.293 +     * bytes, possibly zero. This may result from
   2.294 +     * any of a
   2.295 +     * number of conditions; reaching
   2.296 +     * end of file before <code>n</code> bytes
   2.297 +     * have been skipped is
   2.298 +     * only one possibility.
   2.299 +     * This method never throws an <code>EOFException</code>.
   2.300 +     * The actual
   2.301 +     * number of bytes skipped is returned.
   2.302 +     *
   2.303 +     * @param      n   the number of bytes to be skipped.
   2.304 +     * @return     the number of bytes actually skipped.
   2.305 +     * @exception  IOException   if an I/O error occurs.
   2.306 +     */
   2.307 +    int skipBytes(int n) throws IOException;
   2.308 +
   2.309 +    /**
   2.310 +     * Reads one input byte and returns
   2.311 +     * <code>true</code> if that byte is nonzero,
   2.312 +     * <code>false</code> if that byte is zero.
   2.313 +     * This method is suitable for reading
   2.314 +     * the byte written by the <code>writeBoolean</code>
   2.315 +     * method of interface <code>DataOutput</code>.
   2.316 +     *
   2.317 +     * @return     the <code>boolean</code> value read.
   2.318 +     * @exception  EOFException  if this stream reaches the end before reading
   2.319 +     *               all the bytes.
   2.320 +     * @exception  IOException   if an I/O error occurs.
   2.321 +     */
   2.322 +    boolean readBoolean() throws IOException;
   2.323 +
   2.324 +    /**
   2.325 +     * Reads and returns one input byte.
   2.326 +     * The byte is treated as a signed value in
   2.327 +     * the range <code>-128</code> through <code>127</code>,
   2.328 +     * inclusive.
   2.329 +     * This method is suitable for
   2.330 +     * reading the byte written by the <code>writeByte</code>
   2.331 +     * method of interface <code>DataOutput</code>.
   2.332 +     *
   2.333 +     * @return     the 8-bit value read.
   2.334 +     * @exception  EOFException  if this stream reaches the end before reading
   2.335 +     *               all the bytes.
   2.336 +     * @exception  IOException   if an I/O error occurs.
   2.337 +     */
   2.338 +    byte readByte() throws IOException;
   2.339 +
   2.340 +    /**
   2.341 +     * Reads one input byte, zero-extends
   2.342 +     * it to type <code>int</code>, and returns
   2.343 +     * the result, which is therefore in the range
   2.344 +     * <code>0</code>
   2.345 +     * through <code>255</code>.
   2.346 +     * This method is suitable for reading
   2.347 +     * the byte written by the <code>writeByte</code>
   2.348 +     * method of interface <code>DataOutput</code>
   2.349 +     * if the argument to <code>writeByte</code>
   2.350 +     * was intended to be a value in the range
   2.351 +     * <code>0</code> through <code>255</code>.
   2.352 +     *
   2.353 +     * @return     the unsigned 8-bit value read.
   2.354 +     * @exception  EOFException  if this stream reaches the end before reading
   2.355 +     *               all the bytes.
   2.356 +     * @exception  IOException   if an I/O error occurs.
   2.357 +     */
   2.358 +    int readUnsignedByte() throws IOException;
   2.359 +
   2.360 +    /**
   2.361 +     * Reads two input bytes and returns
   2.362 +     * a <code>short</code> value. Let <code>a</code>
   2.363 +     * be the first byte read and <code>b</code>
   2.364 +     * be the second byte. The value
   2.365 +     * returned
   2.366 +     * is:
   2.367 +     * <p><pre><code>(short)((a &lt;&lt; 8) | (b &amp; 0xff))
   2.368 +     * </code></pre>
   2.369 +     * This method
   2.370 +     * is suitable for reading the bytes written
   2.371 +     * by the <code>writeShort</code> method of
   2.372 +     * interface <code>DataOutput</code>.
   2.373 +     *
   2.374 +     * @return     the 16-bit value read.
   2.375 +     * @exception  EOFException  if this stream reaches the end before reading
   2.376 +     *               all the bytes.
   2.377 +     * @exception  IOException   if an I/O error occurs.
   2.378 +     */
   2.379 +    short readShort() throws IOException;
   2.380 +
   2.381 +    /**
   2.382 +     * Reads two input bytes and returns
   2.383 +     * an <code>int</code> value in the range <code>0</code>
   2.384 +     * through <code>65535</code>. Let <code>a</code>
   2.385 +     * be the first byte read and
   2.386 +     * <code>b</code>
   2.387 +     * be the second byte. The value returned is:
   2.388 +     * <p><pre><code>(((a &amp; 0xff) &lt;&lt; 8) | (b &amp; 0xff))
   2.389 +     * </code></pre>
   2.390 +     * This method is suitable for reading the bytes
   2.391 +     * written by the <code>writeShort</code> method
   2.392 +     * of interface <code>DataOutput</code>  if
   2.393 +     * the argument to <code>writeShort</code>
   2.394 +     * was intended to be a value in the range
   2.395 +     * <code>0</code> through <code>65535</code>.
   2.396 +     *
   2.397 +     * @return     the unsigned 16-bit value read.
   2.398 +     * @exception  EOFException  if this stream reaches the end before reading
   2.399 +     *               all the bytes.
   2.400 +     * @exception  IOException   if an I/O error occurs.
   2.401 +     */
   2.402 +    int readUnsignedShort() throws IOException;
   2.403 +
   2.404 +    /**
   2.405 +     * Reads two input bytes and returns a <code>char</code> value.
   2.406 +     * Let <code>a</code>
   2.407 +     * be the first byte read and <code>b</code>
   2.408 +     * be the second byte. The value
   2.409 +     * returned is:
   2.410 +     * <p><pre><code>(char)((a &lt;&lt; 8) | (b &amp; 0xff))
   2.411 +     * </code></pre>
   2.412 +     * This method
   2.413 +     * is suitable for reading bytes written by
   2.414 +     * the <code>writeChar</code> method of interface
   2.415 +     * <code>DataOutput</code>.
   2.416 +     *
   2.417 +     * @return     the <code>char</code> value read.
   2.418 +     * @exception  EOFException  if this stream reaches the end before reading
   2.419 +     *               all the bytes.
   2.420 +     * @exception  IOException   if an I/O error occurs.
   2.421 +     */
   2.422 +    char readChar() throws IOException;
   2.423 +
   2.424 +    /**
   2.425 +     * Reads four input bytes and returns an
   2.426 +     * <code>int</code> value. Let <code>a-d</code>
   2.427 +     * be the first through fourth bytes read. The value returned is:
   2.428 +     * <p><pre>
   2.429 +     * <code>
   2.430 +     * (((a &amp; 0xff) &lt;&lt; 24) | ((b &amp; 0xff) &lt;&lt; 16) |
   2.431 +     * &#32;((c &amp; 0xff) &lt;&lt; 8) | (d &amp; 0xff))
   2.432 +     * </code></pre>
   2.433 +     * This method is suitable
   2.434 +     * for reading bytes written by the <code>writeInt</code>
   2.435 +     * method of interface <code>DataOutput</code>.
   2.436 +     *
   2.437 +     * @return     the <code>int</code> value read.
   2.438 +     * @exception  EOFException  if this stream reaches the end before reading
   2.439 +     *               all the bytes.
   2.440 +     * @exception  IOException   if an I/O error occurs.
   2.441 +     */
   2.442 +    int readInt() throws IOException;
   2.443 +
   2.444 +    /**
   2.445 +     * Reads eight input bytes and returns
   2.446 +     * a <code>long</code> value. Let <code>a-h</code>
   2.447 +     * be the first through eighth bytes read.
   2.448 +     * The value returned is:
   2.449 +     * <p><pre> <code>
   2.450 +     * (((long)(a &amp; 0xff) &lt;&lt; 56) |
   2.451 +     *  ((long)(b &amp; 0xff) &lt;&lt; 48) |
   2.452 +     *  ((long)(c &amp; 0xff) &lt;&lt; 40) |
   2.453 +     *  ((long)(d &amp; 0xff) &lt;&lt; 32) |
   2.454 +     *  ((long)(e &amp; 0xff) &lt;&lt; 24) |
   2.455 +     *  ((long)(f &amp; 0xff) &lt;&lt; 16) |
   2.456 +     *  ((long)(g &amp; 0xff) &lt;&lt;  8) |
   2.457 +     *  ((long)(h &amp; 0xff)))
   2.458 +     * </code></pre>
   2.459 +     * <p>
   2.460 +     * This method is suitable
   2.461 +     * for reading bytes written by the <code>writeLong</code>
   2.462 +     * method of interface <code>DataOutput</code>.
   2.463 +     *
   2.464 +     * @return     the <code>long</code> value read.
   2.465 +     * @exception  EOFException  if this stream reaches the end before reading
   2.466 +     *               all the bytes.
   2.467 +     * @exception  IOException   if an I/O error occurs.
   2.468 +     */
   2.469 +    long readLong() throws IOException;
   2.470 +
   2.471 +    /**
   2.472 +     * Reads four input bytes and returns
   2.473 +     * a <code>float</code> value. It does this
   2.474 +     * by first constructing an <code>int</code>
   2.475 +     * value in exactly the manner
   2.476 +     * of the <code>readInt</code>
   2.477 +     * method, then converting this <code>int</code>
   2.478 +     * value to a <code>float</code> in
   2.479 +     * exactly the manner of the method <code>Float.intBitsToFloat</code>.
   2.480 +     * This method is suitable for reading
   2.481 +     * bytes written by the <code>writeFloat</code>
   2.482 +     * method of interface <code>DataOutput</code>.
   2.483 +     *
   2.484 +     * @return     the <code>float</code> value read.
   2.485 +     * @exception  EOFException  if this stream reaches the end before reading
   2.486 +     *               all the bytes.
   2.487 +     * @exception  IOException   if an I/O error occurs.
   2.488 +     */
   2.489 +    float readFloat() throws IOException;
   2.490 +
   2.491 +    /**
   2.492 +     * Reads eight input bytes and returns
   2.493 +     * a <code>double</code> value. It does this
   2.494 +     * by first constructing a <code>long</code>
   2.495 +     * value in exactly the manner
   2.496 +     * of the <code>readlong</code>
   2.497 +     * method, then converting this <code>long</code>
   2.498 +     * value to a <code>double</code> in exactly
   2.499 +     * the manner of the method <code>Double.longBitsToDouble</code>.
   2.500 +     * This method is suitable for reading
   2.501 +     * bytes written by the <code>writeDouble</code>
   2.502 +     * method of interface <code>DataOutput</code>.
   2.503 +     *
   2.504 +     * @return     the <code>double</code> value read.
   2.505 +     * @exception  EOFException  if this stream reaches the end before reading
   2.506 +     *               all the bytes.
   2.507 +     * @exception  IOException   if an I/O error occurs.
   2.508 +     */
   2.509 +    double readDouble() throws IOException;
   2.510 +
   2.511 +    /**
   2.512 +     * Reads the next line of text from the input stream.
   2.513 +     * It reads successive bytes, converting
   2.514 +     * each byte separately into a character,
   2.515 +     * until it encounters a line terminator or
   2.516 +     * end of
   2.517 +     * file; the characters read are then
   2.518 +     * returned as a <code>String</code>. Note
   2.519 +     * that because this
   2.520 +     * method processes bytes,
   2.521 +     * it does not support input of the full Unicode
   2.522 +     * character set.
   2.523 +     * <p>
   2.524 +     * If end of file is encountered
   2.525 +     * before even one byte can be read, then <code>null</code>
   2.526 +     * is returned. Otherwise, each byte that is
   2.527 +     * read is converted to type <code>char</code>
   2.528 +     * by zero-extension. If the character <code>'\n'</code>
   2.529 +     * is encountered, it is discarded and reading
   2.530 +     * ceases. If the character <code>'\r'</code>
   2.531 +     * is encountered, it is discarded and, if
   2.532 +     * the following byte converts &#32;to the
   2.533 +     * character <code>'\n'</code>, then that is
   2.534 +     * discarded also; reading then ceases. If
   2.535 +     * end of file is encountered before either
   2.536 +     * of the characters <code>'\n'</code> and
   2.537 +     * <code>'\r'</code> is encountered, reading
   2.538 +     * ceases. Once reading has ceased, a <code>String</code>
   2.539 +     * is returned that contains all the characters
   2.540 +     * read and not discarded, taken in order.
   2.541 +     * Note that every character in this string
   2.542 +     * will have a value less than <code>&#92;u0100</code>,
   2.543 +     * that is, <code>(char)256</code>.
   2.544 +     *
   2.545 +     * @return the next line of text from the input stream,
   2.546 +     *         or <CODE>null</CODE> if the end of file is
   2.547 +     *         encountered before a byte can be read.
   2.548 +     * @exception  IOException  if an I/O error occurs.
   2.549 +     */
   2.550 +    String readLine() throws IOException;
   2.551 +
   2.552 +    /**
   2.553 +     * Reads in a string that has been encoded using a
   2.554 +     * <a href="#modified-utf-8">modified UTF-8</a>
   2.555 +     * format.
   2.556 +     * The general contract of <code>readUTF</code>
   2.557 +     * is that it reads a representation of a Unicode
   2.558 +     * character string encoded in modified
   2.559 +     * UTF-8 format; this string of characters
   2.560 +     * is then returned as a <code>String</code>.
   2.561 +     * <p>
   2.562 +     * First, two bytes are read and used to
   2.563 +     * construct an unsigned 16-bit integer in
   2.564 +     * exactly the manner of the <code>readUnsignedShort</code>
   2.565 +     * method . This integer value is called the
   2.566 +     * <i>UTF length</i> and specifies the number
   2.567 +     * of additional bytes to be read. These bytes
   2.568 +     * are then converted to characters by considering
   2.569 +     * them in groups. The length of each group
   2.570 +     * is computed from the value of the first
   2.571 +     * byte of the group. The byte following a
   2.572 +     * group, if any, is the first byte of the
   2.573 +     * next group.
   2.574 +     * <p>
   2.575 +     * If the first byte of a group
   2.576 +     * matches the bit pattern <code>0xxxxxxx</code>
   2.577 +     * (where <code>x</code> means "may be <code>0</code>
   2.578 +     * or <code>1</code>"), then the group consists
   2.579 +     * of just that byte. The byte is zero-extended
   2.580 +     * to form a character.
   2.581 +     * <p>
   2.582 +     * If the first byte
   2.583 +     * of a group matches the bit pattern <code>110xxxxx</code>,
   2.584 +     * then the group consists of that byte <code>a</code>
   2.585 +     * and a second byte <code>b</code>. If there
   2.586 +     * is no byte <code>b</code> (because byte
   2.587 +     * <code>a</code> was the last of the bytes
   2.588 +     * to be read), or if byte <code>b</code> does
   2.589 +     * not match the bit pattern <code>10xxxxxx</code>,
   2.590 +     * then a <code>UTFDataFormatException</code>
   2.591 +     * is thrown. Otherwise, the group is converted
   2.592 +     * to the character:<p>
   2.593 +     * <pre><code>(char)(((a&amp; 0x1F) &lt;&lt; 6) | (b &amp; 0x3F))
   2.594 +     * </code></pre>
   2.595 +     * If the first byte of a group
   2.596 +     * matches the bit pattern <code>1110xxxx</code>,
   2.597 +     * then the group consists of that byte <code>a</code>
   2.598 +     * and two more bytes <code>b</code> and <code>c</code>.
   2.599 +     * If there is no byte <code>c</code> (because
   2.600 +     * byte <code>a</code> was one of the last
   2.601 +     * two of the bytes to be read), or either
   2.602 +     * byte <code>b</code> or byte <code>c</code>
   2.603 +     * does not match the bit pattern <code>10xxxxxx</code>,
   2.604 +     * then a <code>UTFDataFormatException</code>
   2.605 +     * is thrown. Otherwise, the group is converted
   2.606 +     * to the character:<p>
   2.607 +     * <pre><code>
   2.608 +     * (char)(((a &amp; 0x0F) &lt;&lt; 12) | ((b &amp; 0x3F) &lt;&lt; 6) | (c &amp; 0x3F))
   2.609 +     * </code></pre>
   2.610 +     * If the first byte of a group matches the
   2.611 +     * pattern <code>1111xxxx</code> or the pattern
   2.612 +     * <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code>
   2.613 +     * is thrown.
   2.614 +     * <p>
   2.615 +     * If end of file is encountered
   2.616 +     * at any time during this entire process,
   2.617 +     * then an <code>EOFException</code> is thrown.
   2.618 +     * <p>
   2.619 +     * After every group has been converted to
   2.620 +     * a character by this process, the characters
   2.621 +     * are gathered, in the same order in which
   2.622 +     * their corresponding groups were read from
   2.623 +     * the input stream, to form a <code>String</code>,
   2.624 +     * which is returned.
   2.625 +     * <p>
   2.626 +     * The <code>writeUTF</code>
   2.627 +     * method of interface <code>DataOutput</code>
   2.628 +     * may be used to write data that is suitable
   2.629 +     * for reading by this method.
   2.630 +     * @return     a Unicode string.
   2.631 +     * @exception  EOFException            if this stream reaches the end
   2.632 +     *               before reading all the bytes.
   2.633 +     * @exception  IOException             if an I/O error occurs.
   2.634 +     * @exception  UTFDataFormatException  if the bytes do not represent a
   2.635 +     *               valid modified UTF-8 encoding of a string.
   2.636 +     */
   2.637 +    String readUTF() throws IOException;
   2.638 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/emul/src/main/java/java/io/DataInputStream.java	Sun Nov 18 22:03:15 2012 +0100
     3.3 @@ -0,0 +1,704 @@
     3.4 +/*
     3.5 + * Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.  Oracle designates this
    3.11 + * particular file as subject to the "Classpath" exception as provided
    3.12 + * by Oracle in the LICENSE file that accompanied this code.
    3.13 + *
    3.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.17 + * version 2 for more details (a copy is included in the LICENSE file that
    3.18 + * accompanied this code).
    3.19 + *
    3.20 + * You should have received a copy of the GNU General Public License version
    3.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.23 + *
    3.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.25 + * or visit www.oracle.com if you need additional information or have any
    3.26 + * questions.
    3.27 + */
    3.28 +
    3.29 +package java.io;
    3.30 +
    3.31 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
    3.32 +
    3.33 +/**
    3.34 + * A data input stream lets an application read primitive Java data
    3.35 + * types from an underlying input stream in a machine-independent
    3.36 + * way. An application uses a data output stream to write data that
    3.37 + * can later be read by a data input stream.
    3.38 + * <p>
    3.39 + * DataInputStream is not necessarily safe for multithreaded access.
    3.40 + * Thread safety is optional and is the responsibility of users of
    3.41 + * methods in this class.
    3.42 + *
    3.43 + * @author  Arthur van Hoff
    3.44 + * @see     java.io.DataOutputStream
    3.45 + * @since   JDK1.0
    3.46 + */
    3.47 +public
    3.48 +class DataInputStream extends FilterInputStream implements DataInput {
    3.49 +
    3.50 +    /**
    3.51 +     * Creates a DataInputStream that uses the specified
    3.52 +     * underlying InputStream.
    3.53 +     *
    3.54 +     * @param  in   the specified input stream
    3.55 +     */
    3.56 +    public DataInputStream(InputStream in) {
    3.57 +        super(in);
    3.58 +    }
    3.59 +
    3.60 +    /**
    3.61 +     * working arrays initialized on demand by readUTF
    3.62 +     */
    3.63 +    private byte bytearr[] = new byte[80];
    3.64 +    private char chararr[] = new char[80];
    3.65 +
    3.66 +    /**
    3.67 +     * Reads some number of bytes from the contained input stream and
    3.68 +     * stores them into the buffer array <code>b</code>. The number of
    3.69 +     * bytes actually read is returned as an integer. This method blocks
    3.70 +     * until input data is available, end of file is detected, or an
    3.71 +     * exception is thrown.
    3.72 +     *
    3.73 +     * <p>If <code>b</code> is null, a <code>NullPointerException</code> is
    3.74 +     * thrown. If the length of <code>b</code> is zero, then no bytes are
    3.75 +     * read and <code>0</code> is returned; otherwise, there is an attempt
    3.76 +     * to read at least one byte. If no byte is available because the
    3.77 +     * stream is at end of file, the value <code>-1</code> is returned;
    3.78 +     * otherwise, at least one byte is read and stored into <code>b</code>.
    3.79 +     *
    3.80 +     * <p>The first byte read is stored into element <code>b[0]</code>, the
    3.81 +     * next one into <code>b[1]</code>, and so on. The number of bytes read
    3.82 +     * is, at most, equal to the length of <code>b</code>. Let <code>k</code>
    3.83 +     * be the number of bytes actually read; these bytes will be stored in
    3.84 +     * elements <code>b[0]</code> through <code>b[k-1]</code>, leaving
    3.85 +     * elements <code>b[k]</code> through <code>b[b.length-1]</code>
    3.86 +     * unaffected.
    3.87 +     *
    3.88 +     * <p>The <code>read(b)</code> method has the same effect as:
    3.89 +     * <blockquote><pre>
    3.90 +     * read(b, 0, b.length)
    3.91 +     * </pre></blockquote>
    3.92 +     *
    3.93 +     * @param      b   the buffer into which the data is read.
    3.94 +     * @return     the total number of bytes read into the buffer, or
    3.95 +     *             <code>-1</code> if there is no more data because the end
    3.96 +     *             of the stream has been reached.
    3.97 +     * @exception  IOException if the first byte cannot be read for any reason
    3.98 +     * other than end of file, the stream has been closed and the underlying
    3.99 +     * input stream does not support reading after close, or another I/O
   3.100 +     * error occurs.
   3.101 +     * @see        java.io.FilterInputStream#in
   3.102 +     * @see        java.io.InputStream#read(byte[], int, int)
   3.103 +     */
   3.104 +    public final int read(byte b[]) throws IOException {
   3.105 +        return in.read(b, 0, b.length);
   3.106 +    }
   3.107 +
   3.108 +    /**
   3.109 +     * Reads up to <code>len</code> bytes of data from the contained
   3.110 +     * input stream into an array of bytes.  An attempt is made to read
   3.111 +     * as many as <code>len</code> bytes, but a smaller number may be read,
   3.112 +     * possibly zero. The number of bytes actually read is returned as an
   3.113 +     * integer.
   3.114 +     *
   3.115 +     * <p> This method blocks until input data is available, end of file is
   3.116 +     * detected, or an exception is thrown.
   3.117 +     *
   3.118 +     * <p> If <code>len</code> is zero, then no bytes are read and
   3.119 +     * <code>0</code> is returned; otherwise, there is an attempt to read at
   3.120 +     * least one byte. If no byte is available because the stream is at end of
   3.121 +     * file, the value <code>-1</code> is returned; otherwise, at least one
   3.122 +     * byte is read and stored into <code>b</code>.
   3.123 +     *
   3.124 +     * <p> The first byte read is stored into element <code>b[off]</code>, the
   3.125 +     * next one into <code>b[off+1]</code>, and so on. The number of bytes read
   3.126 +     * is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
   3.127 +     * bytes actually read; these bytes will be stored in elements
   3.128 +     * <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
   3.129 +     * leaving elements <code>b[off+</code><i>k</i><code>]</code> through
   3.130 +     * <code>b[off+len-1]</code> unaffected.
   3.131 +     *
   3.132 +     * <p> In every case, elements <code>b[0]</code> through
   3.133 +     * <code>b[off]</code> and elements <code>b[off+len]</code> through
   3.134 +     * <code>b[b.length-1]</code> are unaffected.
   3.135 +     *
   3.136 +     * @param      b     the buffer into which the data is read.
   3.137 +     * @param off the start offset in the destination array <code>b</code>
   3.138 +     * @param      len   the maximum number of bytes read.
   3.139 +     * @return     the total number of bytes read into the buffer, or
   3.140 +     *             <code>-1</code> if there is no more data because the end
   3.141 +     *             of the stream has been reached.
   3.142 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
   3.143 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
   3.144 +     * <code>len</code> is negative, or <code>len</code> is greater than
   3.145 +     * <code>b.length - off</code>
   3.146 +     * @exception  IOException if the first byte cannot be read for any reason
   3.147 +     * other than end of file, the stream has been closed and the underlying
   3.148 +     * input stream does not support reading after close, or another I/O
   3.149 +     * error occurs.
   3.150 +     * @see        java.io.FilterInputStream#in
   3.151 +     * @see        java.io.InputStream#read(byte[], int, int)
   3.152 +     */
   3.153 +    public final int read(byte b[], int off, int len) throws IOException {
   3.154 +        return in.read(b, off, len);
   3.155 +    }
   3.156 +
   3.157 +    /**
   3.158 +     * See the general contract of the <code>readFully</code>
   3.159 +     * method of <code>DataInput</code>.
   3.160 +     * <p>
   3.161 +     * Bytes
   3.162 +     * for this operation are read from the contained
   3.163 +     * input stream.
   3.164 +     *
   3.165 +     * @param      b   the buffer into which the data is read.
   3.166 +     * @exception  EOFException  if this input stream reaches the end before
   3.167 +     *             reading all the bytes.
   3.168 +     * @exception  IOException   the stream has been closed and the contained
   3.169 +     *             input stream does not support reading after close, or
   3.170 +     *             another I/O error occurs.
   3.171 +     * @see        java.io.FilterInputStream#in
   3.172 +     */
   3.173 +    public final void readFully(byte b[]) throws IOException {
   3.174 +        readFully(b, 0, b.length);
   3.175 +    }
   3.176 +
   3.177 +    /**
   3.178 +     * See the general contract of the <code>readFully</code>
   3.179 +     * method of <code>DataInput</code>.
   3.180 +     * <p>
   3.181 +     * Bytes
   3.182 +     * for this operation are read from the contained
   3.183 +     * input stream.
   3.184 +     *
   3.185 +     * @param      b     the buffer into which the data is read.
   3.186 +     * @param      off   the start offset of the data.
   3.187 +     * @param      len   the number of bytes to read.
   3.188 +     * @exception  EOFException  if this input stream reaches the end before
   3.189 +     *               reading all the bytes.
   3.190 +     * @exception  IOException   the stream has been closed and the contained
   3.191 +     *             input stream does not support reading after close, or
   3.192 +     *             another I/O error occurs.
   3.193 +     * @see        java.io.FilterInputStream#in
   3.194 +     */
   3.195 +    public final void readFully(byte b[], int off, int len) throws IOException {
   3.196 +        if (len < 0)
   3.197 +            throw new IndexOutOfBoundsException();
   3.198 +        int n = 0;
   3.199 +        while (n < len) {
   3.200 +            int count = in.read(b, off + n, len - n);
   3.201 +            if (count < 0)
   3.202 +                throw new EOFException();
   3.203 +            n += count;
   3.204 +        }
   3.205 +    }
   3.206 +
   3.207 +    /**
   3.208 +     * See the general contract of the <code>skipBytes</code>
   3.209 +     * method of <code>DataInput</code>.
   3.210 +     * <p>
   3.211 +     * Bytes for this operation are read from the contained
   3.212 +     * input stream.
   3.213 +     *
   3.214 +     * @param      n   the number of bytes to be skipped.
   3.215 +     * @return     the actual number of bytes skipped.
   3.216 +     * @exception  IOException  if the contained input stream does not support
   3.217 +     *             seek, or the stream has been closed and
   3.218 +     *             the contained input stream does not support
   3.219 +     *             reading after close, or another I/O error occurs.
   3.220 +     */
   3.221 +    public final int skipBytes(int n) throws IOException {
   3.222 +        int total = 0;
   3.223 +        int cur = 0;
   3.224 +
   3.225 +        while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
   3.226 +            total += cur;
   3.227 +        }
   3.228 +
   3.229 +        return total;
   3.230 +    }
   3.231 +
   3.232 +    /**
   3.233 +     * See the general contract of the <code>readBoolean</code>
   3.234 +     * method of <code>DataInput</code>.
   3.235 +     * <p>
   3.236 +     * Bytes for this operation are read from the contained
   3.237 +     * input stream.
   3.238 +     *
   3.239 +     * @return     the <code>boolean</code> value read.
   3.240 +     * @exception  EOFException  if this input stream has reached the end.
   3.241 +     * @exception  IOException   the stream has been closed and the contained
   3.242 +     *             input stream does not support reading after close, or
   3.243 +     *             another I/O error occurs.
   3.244 +     * @see        java.io.FilterInputStream#in
   3.245 +     */
   3.246 +    public final boolean readBoolean() throws IOException {
   3.247 +        int ch = in.read();
   3.248 +        if (ch < 0)
   3.249 +            throw new EOFException();
   3.250 +        return (ch != 0);
   3.251 +    }
   3.252 +
   3.253 +    /**
   3.254 +     * See the general contract of the <code>readByte</code>
   3.255 +     * method of <code>DataInput</code>.
   3.256 +     * <p>
   3.257 +     * Bytes
   3.258 +     * for this operation are read from the contained
   3.259 +     * input stream.
   3.260 +     *
   3.261 +     * @return     the next byte of this input stream as a signed 8-bit
   3.262 +     *             <code>byte</code>.
   3.263 +     * @exception  EOFException  if this input stream has reached the end.
   3.264 +     * @exception  IOException   the stream has been closed and the contained
   3.265 +     *             input stream does not support reading after close, or
   3.266 +     *             another I/O error occurs.
   3.267 +     * @see        java.io.FilterInputStream#in
   3.268 +     */
   3.269 +    public final byte readByte() throws IOException {
   3.270 +        int ch = in.read();
   3.271 +        if (ch < 0)
   3.272 +            throw new EOFException();
   3.273 +        return (byte)(ch);
   3.274 +    }
   3.275 +
   3.276 +    /**
   3.277 +     * See the general contract of the <code>readUnsignedByte</code>
   3.278 +     * method of <code>DataInput</code>.
   3.279 +     * <p>
   3.280 +     * Bytes
   3.281 +     * for this operation are read from the contained
   3.282 +     * input stream.
   3.283 +     *
   3.284 +     * @return     the next byte of this input stream, interpreted as an
   3.285 +     *             unsigned 8-bit number.
   3.286 +     * @exception  EOFException  if this input stream has reached the end.
   3.287 +     * @exception  IOException   the stream has been closed and the contained
   3.288 +     *             input stream does not support reading after close, or
   3.289 +     *             another I/O error occurs.
   3.290 +     * @see         java.io.FilterInputStream#in
   3.291 +     */
   3.292 +    public final int readUnsignedByte() throws IOException {
   3.293 +        int ch = in.read();
   3.294 +        if (ch < 0)
   3.295 +            throw new EOFException();
   3.296 +        return ch;
   3.297 +    }
   3.298 +
   3.299 +    /**
   3.300 +     * See the general contract of the <code>readShort</code>
   3.301 +     * method of <code>DataInput</code>.
   3.302 +     * <p>
   3.303 +     * Bytes
   3.304 +     * for this operation are read from the contained
   3.305 +     * input stream.
   3.306 +     *
   3.307 +     * @return     the next two bytes of this input stream, interpreted as a
   3.308 +     *             signed 16-bit number.
   3.309 +     * @exception  EOFException  if this input stream reaches the end before
   3.310 +     *               reading two bytes.
   3.311 +     * @exception  IOException   the stream has been closed and the contained
   3.312 +     *             input stream does not support reading after close, or
   3.313 +     *             another I/O error occurs.
   3.314 +     * @see        java.io.FilterInputStream#in
   3.315 +     */
   3.316 +    public final short readShort() throws IOException {
   3.317 +        int ch1 = in.read();
   3.318 +        int ch2 = in.read();
   3.319 +        if ((ch1 | ch2) < 0)
   3.320 +            throw new EOFException();
   3.321 +        return (short)((ch1 << 8) + (ch2 << 0));
   3.322 +    }
   3.323 +
   3.324 +    /**
   3.325 +     * See the general contract of the <code>readUnsignedShort</code>
   3.326 +     * method of <code>DataInput</code>.
   3.327 +     * <p>
   3.328 +     * Bytes
   3.329 +     * for this operation are read from the contained
   3.330 +     * input stream.
   3.331 +     *
   3.332 +     * @return     the next two bytes of this input stream, interpreted as an
   3.333 +     *             unsigned 16-bit integer.
   3.334 +     * @exception  EOFException  if this input stream reaches the end before
   3.335 +     *             reading two bytes.
   3.336 +     * @exception  IOException   the stream has been closed and the contained
   3.337 +     *             input stream does not support reading after close, or
   3.338 +     *             another I/O error occurs.
   3.339 +     * @see        java.io.FilterInputStream#in
   3.340 +     */
   3.341 +    public final int readUnsignedShort() throws IOException {
   3.342 +        int ch1 = in.read();
   3.343 +        int ch2 = in.read();
   3.344 +        if ((ch1 | ch2) < 0)
   3.345 +            throw new EOFException();
   3.346 +        return (ch1 << 8) + (ch2 << 0);
   3.347 +    }
   3.348 +
   3.349 +    /**
   3.350 +     * See the general contract of the <code>readChar</code>
   3.351 +     * method of <code>DataInput</code>.
   3.352 +     * <p>
   3.353 +     * Bytes
   3.354 +     * for this operation are read from the contained
   3.355 +     * input stream.
   3.356 +     *
   3.357 +     * @return     the next two bytes of this input stream, interpreted as a
   3.358 +     *             <code>char</code>.
   3.359 +     * @exception  EOFException  if this input stream reaches the end before
   3.360 +     *               reading two bytes.
   3.361 +     * @exception  IOException   the stream has been closed and the contained
   3.362 +     *             input stream does not support reading after close, or
   3.363 +     *             another I/O error occurs.
   3.364 +     * @see        java.io.FilterInputStream#in
   3.365 +     */
   3.366 +    public final char readChar() throws IOException {
   3.367 +        int ch1 = in.read();
   3.368 +        int ch2 = in.read();
   3.369 +        if ((ch1 | ch2) < 0)
   3.370 +            throw new EOFException();
   3.371 +        return (char)((ch1 << 8) + (ch2 << 0));
   3.372 +    }
   3.373 +
   3.374 +    /**
   3.375 +     * See the general contract of the <code>readInt</code>
   3.376 +     * method of <code>DataInput</code>.
   3.377 +     * <p>
   3.378 +     * Bytes
   3.379 +     * for this operation are read from the contained
   3.380 +     * input stream.
   3.381 +     *
   3.382 +     * @return     the next four bytes of this input stream, interpreted as an
   3.383 +     *             <code>int</code>.
   3.384 +     * @exception  EOFException  if this input stream reaches the end before
   3.385 +     *               reading four bytes.
   3.386 +     * @exception  IOException   the stream has been closed and the contained
   3.387 +     *             input stream does not support reading after close, or
   3.388 +     *             another I/O error occurs.
   3.389 +     * @see        java.io.FilterInputStream#in
   3.390 +     */
   3.391 +    public final int readInt() throws IOException {
   3.392 +        int ch1 = in.read();
   3.393 +        int ch2 = in.read();
   3.394 +        int ch3 = in.read();
   3.395 +        int ch4 = in.read();
   3.396 +        if ((ch1 | ch2 | ch3 | ch4) < 0)
   3.397 +            throw new EOFException();
   3.398 +        return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
   3.399 +    }
   3.400 +
   3.401 +    private byte readBuffer[] = new byte[8];
   3.402 +
   3.403 +    /**
   3.404 +     * See the general contract of the <code>readLong</code>
   3.405 +     * method of <code>DataInput</code>.
   3.406 +     * <p>
   3.407 +     * Bytes
   3.408 +     * for this operation are read from the contained
   3.409 +     * input stream.
   3.410 +     *
   3.411 +     * @return     the next eight bytes of this input stream, interpreted as a
   3.412 +     *             <code>long</code>.
   3.413 +     * @exception  EOFException  if this input stream reaches the end before
   3.414 +     *               reading eight bytes.
   3.415 +     * @exception  IOException   the stream has been closed and the contained
   3.416 +     *             input stream does not support reading after close, or
   3.417 +     *             another I/O error occurs.
   3.418 +     * @see        java.io.FilterInputStream#in
   3.419 +     */
   3.420 +    public final long readLong() throws IOException {
   3.421 +        readFully(readBuffer, 0, 8);
   3.422 +        return (((long)readBuffer[0] << 56) +
   3.423 +                ((long)(readBuffer[1] & 255) << 48) +
   3.424 +                ((long)(readBuffer[2] & 255) << 40) +
   3.425 +                ((long)(readBuffer[3] & 255) << 32) +
   3.426 +                ((long)(readBuffer[4] & 255) << 24) +
   3.427 +                ((readBuffer[5] & 255) << 16) +
   3.428 +                ((readBuffer[6] & 255) <<  8) +
   3.429 +                ((readBuffer[7] & 255) <<  0));
   3.430 +    }
   3.431 +
   3.432 +    /**
   3.433 +     * See the general contract of the <code>readFloat</code>
   3.434 +     * method of <code>DataInput</code>.
   3.435 +     * <p>
   3.436 +     * Bytes
   3.437 +     * for this operation are read from the contained
   3.438 +     * input stream.
   3.439 +     *
   3.440 +     * @return     the next four bytes of this input stream, interpreted as a
   3.441 +     *             <code>float</code>.
   3.442 +     * @exception  EOFException  if this input stream reaches the end before
   3.443 +     *               reading four bytes.
   3.444 +     * @exception  IOException   the stream has been closed and the contained
   3.445 +     *             input stream does not support reading after close, or
   3.446 +     *             another I/O error occurs.
   3.447 +     * @see        java.io.DataInputStream#readInt()
   3.448 +     * @see        java.lang.Float#intBitsToFloat(int)
   3.449 +     */
   3.450 +    public final float readFloat() throws IOException {
   3.451 +        return Float.intBitsToFloat(readInt());
   3.452 +    }
   3.453 +
   3.454 +    /**
   3.455 +     * See the general contract of the <code>readDouble</code>
   3.456 +     * method of <code>DataInput</code>.
   3.457 +     * <p>
   3.458 +     * Bytes
   3.459 +     * for this operation are read from the contained
   3.460 +     * input stream.
   3.461 +     *
   3.462 +     * @return     the next eight bytes of this input stream, interpreted as a
   3.463 +     *             <code>double</code>.
   3.464 +     * @exception  EOFException  if this input stream reaches the end before
   3.465 +     *               reading eight bytes.
   3.466 +     * @exception  IOException   the stream has been closed and the contained
   3.467 +     *             input stream does not support reading after close, or
   3.468 +     *             another I/O error occurs.
   3.469 +     * @see        java.io.DataInputStream#readLong()
   3.470 +     * @see        java.lang.Double#longBitsToDouble(long)
   3.471 +     */
   3.472 +    public final double readDouble() throws IOException {
   3.473 +        int hi = readInt();
   3.474 +        int low = readInt();
   3.475 +        return toDouble(hi, low);
   3.476 +    }
   3.477 +    
   3.478 +    @JavaScriptBody(args={ "hi", "low" },
   3.479 +        body=
   3.480 +          "if (low == 0) {\n"
   3.481 +        + "  if (hi === 0x7ff00000) return Number.POSITIVE_INFINITY;\n"
   3.482 +        + "  if (hi === 0xfff00000) return Number.NEGATIVE_INFINITY;\n"
   3.483 +        + "}\n"
   3.484 +        + "if (hi >= 0x7ff00000 && hi <= 0x7fffffff) return Number.NaN;\n"
   3.485 +        + "if (hi >= 0xfff00000 && hi <= 0xffffffff) return Number.NaN;\n"
   3.486 +        + "var s = (hi & 0x80000000) === 0 ? 1 : -1;\n"
   3.487 +        + "var e = (hi >> 20) & 0x7ff;\n"
   3.488 +        + "var to32 = low >> 0;\n"
   3.489 +        + "if (e === 0) {\n"
   3.490 +        + "  if (to32 & 0x80000000) {\n"
   3.491 +        + "    hi = hi << 1 + 1; low = low << 1;\n"
   3.492 +        + "  } else {\n"
   3.493 +        + "    hi = hi << 1; low = low << 1;\n"
   3.494 +        + "  }\n" 
   3.495 +        + "} else {\n"
   3.496 +        + "    hi = (hi & 0xfffff) | 0x100000;\n"
   3.497 +        + "}\n"
   3.498 +        + "to32 = low >> 0;\n"
   3.499 +        + "var m = Math.pow(2.0, 32) * hi + to32;\n"
   3.500 +        + "var r = s * m * Math.pow(2.0, e - 1075);\n"
   3.501 +        + "//throw 'exp: ' + e + ' sign: ' + s + ' hi:' + hi + ' low: ' + low + ' m: ' + m + ' r: ' + r;\n"
   3.502 +        + "return r;\n"
   3.503 +    )
   3.504 +    private static double toDouble(int hi, int low) {
   3.505 +        long both = hi;
   3.506 +        both = (both << 32) & low;
   3.507 +        return Double.doubleToLongBits(both);
   3.508 +    }
   3.509 +
   3.510 +    private char lineBuffer[];
   3.511 +
   3.512 +    /**
   3.513 +     * See the general contract of the <code>readLine</code>
   3.514 +     * method of <code>DataInput</code>.
   3.515 +     * <p>
   3.516 +     * Bytes
   3.517 +     * for this operation are read from the contained
   3.518 +     * input stream.
   3.519 +     *
   3.520 +     * @deprecated This method does not properly convert bytes to characters.
   3.521 +     * As of JDK&nbsp;1.1, the preferred way to read lines of text is via the
   3.522 +     * <code>BufferedReader.readLine()</code> method.  Programs that use the
   3.523 +     * <code>DataInputStream</code> class to read lines can be converted to use
   3.524 +     * the <code>BufferedReader</code> class by replacing code of the form:
   3.525 +     * <blockquote><pre>
   3.526 +     *     DataInputStream d =&nbsp;new&nbsp;DataInputStream(in);
   3.527 +     * </pre></blockquote>
   3.528 +     * with:
   3.529 +     * <blockquote><pre>
   3.530 +     *     BufferedReader d
   3.531 +     *          =&nbsp;new&nbsp;BufferedReader(new&nbsp;InputStreamReader(in));
   3.532 +     * </pre></blockquote>
   3.533 +     *
   3.534 +     * @return     the next line of text from this input stream.
   3.535 +     * @exception  IOException  if an I/O error occurs.
   3.536 +     * @see        java.io.BufferedReader#readLine()
   3.537 +     * @see        java.io.FilterInputStream#in
   3.538 +     */
   3.539 +    @Deprecated
   3.540 +    public final String readLine() throws IOException {
   3.541 +        char buf[] = lineBuffer;
   3.542 +
   3.543 +        if (buf == null) {
   3.544 +            buf = lineBuffer = new char[128];
   3.545 +        }
   3.546 +
   3.547 +        int room = buf.length;
   3.548 +        int offset = 0;
   3.549 +        int c;
   3.550 +
   3.551 +loop:   while (true) {
   3.552 +            switch (c = in.read()) {
   3.553 +              case -1:
   3.554 +              case '\n':
   3.555 +                break loop;
   3.556 +
   3.557 +              case '\r':
   3.558 +                int c2 = in.read();
   3.559 +                if ((c2 != '\n') && (c2 != -1)) {
   3.560 +                    if (!(in instanceof PushbackInputStream)) {
   3.561 +                        this.in = new PushbackInputStream(in);
   3.562 +                    }
   3.563 +                    ((PushbackInputStream)in).unread(c2);
   3.564 +                }
   3.565 +                break loop;
   3.566 +
   3.567 +              default:
   3.568 +                if (--room < 0) {
   3.569 +                    buf = new char[offset + 128];
   3.570 +                    room = buf.length - offset - 1;
   3.571 +                    arraycopy(lineBuffer, 0, buf, 0, offset);
   3.572 +                    lineBuffer = buf;
   3.573 +                }
   3.574 +                buf[offset++] = (char) c;
   3.575 +                break;
   3.576 +            }
   3.577 +        }
   3.578 +        if ((c == -1) && (offset == 0)) {
   3.579 +            return null;
   3.580 +        }
   3.581 +        return String.copyValueOf(buf, 0, offset);
   3.582 +    }
   3.583 +
   3.584 +    /**
   3.585 +     * See the general contract of the <code>readUTF</code>
   3.586 +     * method of <code>DataInput</code>.
   3.587 +     * <p>
   3.588 +     * Bytes
   3.589 +     * for this operation are read from the contained
   3.590 +     * input stream.
   3.591 +     *
   3.592 +     * @return     a Unicode string.
   3.593 +     * @exception  EOFException  if this input stream reaches the end before
   3.594 +     *               reading all the bytes.
   3.595 +     * @exception  IOException   the stream has been closed and the contained
   3.596 +     *             input stream does not support reading after close, or
   3.597 +     *             another I/O error occurs.
   3.598 +     * @exception  UTFDataFormatException if the bytes do not represent a valid
   3.599 +     *             modified UTF-8 encoding of a string.
   3.600 +     * @see        java.io.DataInputStream#readUTF(java.io.DataInput)
   3.601 +     */
   3.602 +    public final String readUTF() throws IOException {
   3.603 +        return readUTF(this);
   3.604 +    }
   3.605 +
   3.606 +    /**
   3.607 +     * Reads from the
   3.608 +     * stream <code>in</code> a representation
   3.609 +     * of a Unicode  character string encoded in
   3.610 +     * <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
   3.611 +     * this string of characters is then returned as a <code>String</code>.
   3.612 +     * The details of the modified UTF-8 representation
   3.613 +     * are  exactly the same as for the <code>readUTF</code>
   3.614 +     * method of <code>DataInput</code>.
   3.615 +     *
   3.616 +     * @param      in   a data input stream.
   3.617 +     * @return     a Unicode string.
   3.618 +     * @exception  EOFException            if the input stream reaches the end
   3.619 +     *               before all the bytes.
   3.620 +     * @exception  IOException   the stream has been closed and the contained
   3.621 +     *             input stream does not support reading after close, or
   3.622 +     *             another I/O error occurs.
   3.623 +     * @exception  UTFDataFormatException  if the bytes do not represent a
   3.624 +     *               valid modified UTF-8 encoding of a Unicode string.
   3.625 +     * @see        java.io.DataInputStream#readUnsignedShort()
   3.626 +     */
   3.627 +    public final static String readUTF(DataInput in) throws IOException {
   3.628 +        int utflen = in.readUnsignedShort();
   3.629 +        byte[] bytearr = null;
   3.630 +        char[] chararr = null;
   3.631 +        if (in instanceof DataInputStream) {
   3.632 +            DataInputStream dis = (DataInputStream)in;
   3.633 +            if (dis.bytearr.length < utflen){
   3.634 +                dis.bytearr = new byte[utflen*2];
   3.635 +                dis.chararr = new char[utflen*2];
   3.636 +            }
   3.637 +            chararr = dis.chararr;
   3.638 +            bytearr = dis.bytearr;
   3.639 +        } else {
   3.640 +            bytearr = new byte[utflen];
   3.641 +            chararr = new char[utflen];
   3.642 +        }
   3.643 +
   3.644 +        int c, char2, char3;
   3.645 +        int count = 0;
   3.646 +        int chararr_count=0;
   3.647 +
   3.648 +        in.readFully(bytearr, 0, utflen);
   3.649 +
   3.650 +        while (count < utflen) {
   3.651 +            c = (int) bytearr[count] & 0xff;
   3.652 +            if (c > 127) break;
   3.653 +            count++;
   3.654 +            chararr[chararr_count++]=(char)c;
   3.655 +        }
   3.656 +
   3.657 +        while (count < utflen) {
   3.658 +            c = (int) bytearr[count] & 0xff;
   3.659 +            switch (c >> 4) {
   3.660 +                case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
   3.661 +                    /* 0xxxxxxx*/
   3.662 +                    count++;
   3.663 +                    chararr[chararr_count++]=(char)c;
   3.664 +                    break;
   3.665 +                case 12: case 13:
   3.666 +                    /* 110x xxxx   10xx xxxx*/
   3.667 +                    count += 2;
   3.668 +                    if (count > utflen)
   3.669 +                        throw new UTFDataFormatException(
   3.670 +                            "malformed input: partial character at end");
   3.671 +                    char2 = (int) bytearr[count-1];
   3.672 +                    if ((char2 & 0xC0) != 0x80)
   3.673 +                        throw new UTFDataFormatException(
   3.674 +                            "malformed input around byte " + count);
   3.675 +                    chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
   3.676 +                                                    (char2 & 0x3F));
   3.677 +                    break;
   3.678 +                case 14:
   3.679 +                    /* 1110 xxxx  10xx xxxx  10xx xxxx */
   3.680 +                    count += 3;
   3.681 +                    if (count > utflen)
   3.682 +                        throw new UTFDataFormatException(
   3.683 +                            "malformed input: partial character at end");
   3.684 +                    char2 = (int) bytearr[count-2];
   3.685 +                    char3 = (int) bytearr[count-1];
   3.686 +                    if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
   3.687 +                        throw new UTFDataFormatException(
   3.688 +                            "malformed input around byte " + (count-1));
   3.689 +                    chararr[chararr_count++]=(char)(((c     & 0x0F) << 12) |
   3.690 +                                                    ((char2 & 0x3F) << 6)  |
   3.691 +                                                    ((char3 & 0x3F) << 0));
   3.692 +                    break;
   3.693 +                default:
   3.694 +                    /* 10xx xxxx,  1111 xxxx */
   3.695 +                    throw new UTFDataFormatException(
   3.696 +                        "malformed input around byte " + count);
   3.697 +            }
   3.698 +        }
   3.699 +        // The number of chars produced may be less than utflen
   3.700 +        return new String(chararr, 0, chararr_count);
   3.701 +    }
   3.702 +    static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
   3.703 +        while (count-- > 0) {
   3.704 +            dst[dstBegin++] = value[srcBegin++];
   3.705 +        }
   3.706 +    }
   3.707 +}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/emul/src/main/java/java/io/EOFException.java	Sun Nov 18 22:03:15 2012 +0100
     4.3 @@ -0,0 +1,65 @@
     4.4 +/*
     4.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.  Oracle designates this
    4.11 + * particular file as subject to the "Classpath" exception as provided
    4.12 + * by Oracle in the LICENSE file that accompanied this code.
    4.13 + *
    4.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.17 + * version 2 for more details (a copy is included in the LICENSE file that
    4.18 + * accompanied this code).
    4.19 + *
    4.20 + * You should have received a copy of the GNU General Public License version
    4.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.23 + *
    4.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    4.25 + * or visit www.oracle.com if you need additional information or have any
    4.26 + * questions.
    4.27 + */
    4.28 +
    4.29 +package java.io;
    4.30 +
    4.31 +/**
    4.32 + * Signals that an end of file or end of stream has been reached
    4.33 + * unexpectedly during input.
    4.34 + * <p>
    4.35 + * This exception is mainly used by data input streams to signal end of
    4.36 + * stream. Note that many other input operations return a special value on
    4.37 + * end of stream rather than throwing an exception.
    4.38 + * <p>
    4.39 + *
    4.40 + * @author  Frank Yellin
    4.41 + * @see     java.io.DataInputStream
    4.42 + * @see     java.io.IOException
    4.43 + * @since   JDK1.0
    4.44 + */
    4.45 +public
    4.46 +class EOFException extends IOException {
    4.47 +    private static final long serialVersionUID = 6433858223774886977L;
    4.48 +
    4.49 +    /**
    4.50 +     * Constructs an <code>EOFException</code> with <code>null</code>
    4.51 +     * as its error detail message.
    4.52 +     */
    4.53 +    public EOFException() {
    4.54 +        super();
    4.55 +    }
    4.56 +
    4.57 +    /**
    4.58 +     * Constructs an <code>EOFException</code> with the specified detail
    4.59 +     * message. The string <code>s</code> may later be retrieved by the
    4.60 +     * <code>{@link java.lang.Throwable#getMessage}</code> method of class
    4.61 +     * <code>java.lang.Throwable</code>.
    4.62 +     *
    4.63 +     * @param   s   the detail message.
    4.64 +     */
    4.65 +    public EOFException(String s) {
    4.66 +        super(s);
    4.67 +    }
    4.68 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/emul/src/main/java/java/io/FilterInputStream.java	Sun Nov 18 22:03:15 2012 +0100
     5.3 @@ -0,0 +1,245 @@
     5.4 +/*
     5.5 + * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.  Oracle designates this
    5.11 + * particular file as subject to the "Classpath" exception as provided
    5.12 + * by Oracle in the LICENSE file that accompanied this code.
    5.13 + *
    5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.17 + * version 2 for more details (a copy is included in the LICENSE file that
    5.18 + * accompanied this code).
    5.19 + *
    5.20 + * You should have received a copy of the GNU General Public License version
    5.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.23 + *
    5.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.25 + * or visit www.oracle.com if you need additional information or have any
    5.26 + * questions.
    5.27 + */
    5.28 +
    5.29 +package java.io;
    5.30 +
    5.31 +/**
    5.32 + * A <code>FilterInputStream</code> contains
    5.33 + * some other input stream, which it uses as
    5.34 + * its  basic source of data, possibly transforming
    5.35 + * the data along the way or providing  additional
    5.36 + * functionality. The class <code>FilterInputStream</code>
    5.37 + * itself simply overrides all  methods of
    5.38 + * <code>InputStream</code> with versions that
    5.39 + * pass all requests to the contained  input
    5.40 + * stream. Subclasses of <code>FilterInputStream</code>
    5.41 + * may further override some of  these methods
    5.42 + * and may also provide additional methods
    5.43 + * and fields.
    5.44 + *
    5.45 + * @author  Jonathan Payne
    5.46 + * @since   JDK1.0
    5.47 + */
    5.48 +public
    5.49 +class FilterInputStream extends InputStream {
    5.50 +    /**
    5.51 +     * The input stream to be filtered.
    5.52 +     */
    5.53 +    protected volatile InputStream in;
    5.54 +
    5.55 +    /**
    5.56 +     * Creates a <code>FilterInputStream</code>
    5.57 +     * by assigning the  argument <code>in</code>
    5.58 +     * to the field <code>this.in</code> so as
    5.59 +     * to remember it for later use.
    5.60 +     *
    5.61 +     * @param   in   the underlying input stream, or <code>null</code> if
    5.62 +     *          this instance is to be created without an underlying stream.
    5.63 +     */
    5.64 +    protected FilterInputStream(InputStream in) {
    5.65 +        this.in = in;
    5.66 +    }
    5.67 +
    5.68 +    /**
    5.69 +     * Reads the next byte of data from this input stream. The value
    5.70 +     * byte is returned as an <code>int</code> in the range
    5.71 +     * <code>0</code> to <code>255</code>. If no byte is available
    5.72 +     * because the end of the stream has been reached, the value
    5.73 +     * <code>-1</code> is returned. This method blocks until input data
    5.74 +     * is available, the end of the stream is detected, or an exception
    5.75 +     * is thrown.
    5.76 +     * <p>
    5.77 +     * This method
    5.78 +     * simply performs <code>in.read()</code> and returns the result.
    5.79 +     *
    5.80 +     * @return     the next byte of data, or <code>-1</code> if the end of the
    5.81 +     *             stream is reached.
    5.82 +     * @exception  IOException  if an I/O error occurs.
    5.83 +     * @see        java.io.FilterInputStream#in
    5.84 +     */
    5.85 +    public int read() throws IOException {
    5.86 +        return in.read();
    5.87 +    }
    5.88 +
    5.89 +    /**
    5.90 +     * Reads up to <code>byte.length</code> bytes of data from this
    5.91 +     * input stream into an array of bytes. This method blocks until some
    5.92 +     * input is available.
    5.93 +     * <p>
    5.94 +     * This method simply performs the call
    5.95 +     * <code>read(b, 0, b.length)</code> and returns
    5.96 +     * the  result. It is important that it does
    5.97 +     * <i>not</i> do <code>in.read(b)</code> instead;
    5.98 +     * certain subclasses of  <code>FilterInputStream</code>
    5.99 +     * depend on the implementation strategy actually
   5.100 +     * used.
   5.101 +     *
   5.102 +     * @param      b   the buffer into which the data is read.
   5.103 +     * @return     the total number of bytes read into the buffer, or
   5.104 +     *             <code>-1</code> if there is no more data because the end of
   5.105 +     *             the stream has been reached.
   5.106 +     * @exception  IOException  if an I/O error occurs.
   5.107 +     * @see        java.io.FilterInputStream#read(byte[], int, int)
   5.108 +     */
   5.109 +    public int read(byte b[]) throws IOException {
   5.110 +        return read(b, 0, b.length);
   5.111 +    }
   5.112 +
   5.113 +    /**
   5.114 +     * Reads up to <code>len</code> bytes of data from this input stream
   5.115 +     * into an array of bytes. If <code>len</code> is not zero, the method
   5.116 +     * blocks until some input is available; otherwise, no
   5.117 +     * bytes are read and <code>0</code> is returned.
   5.118 +     * <p>
   5.119 +     * This method simply performs <code>in.read(b, off, len)</code>
   5.120 +     * and returns the result.
   5.121 +     *
   5.122 +     * @param      b     the buffer into which the data is read.
   5.123 +     * @param      off   the start offset in the destination array <code>b</code>
   5.124 +     * @param      len   the maximum number of bytes read.
   5.125 +     * @return     the total number of bytes read into the buffer, or
   5.126 +     *             <code>-1</code> if there is no more data because the end of
   5.127 +     *             the stream has been reached.
   5.128 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
   5.129 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
   5.130 +     * <code>len</code> is negative, or <code>len</code> is greater than
   5.131 +     * <code>b.length - off</code>
   5.132 +     * @exception  IOException  if an I/O error occurs.
   5.133 +     * @see        java.io.FilterInputStream#in
   5.134 +     */
   5.135 +    public int read(byte b[], int off, int len) throws IOException {
   5.136 +        return in.read(b, off, len);
   5.137 +    }
   5.138 +
   5.139 +    /**
   5.140 +     * Skips over and discards <code>n</code> bytes of data from the
   5.141 +     * input stream. The <code>skip</code> method may, for a variety of
   5.142 +     * reasons, end up skipping over some smaller number of bytes,
   5.143 +     * possibly <code>0</code>. The actual number of bytes skipped is
   5.144 +     * returned.
   5.145 +     * <p>
   5.146 +     * This method simply performs <code>in.skip(n)</code>.
   5.147 +     *
   5.148 +     * @param      n   the number of bytes to be skipped.
   5.149 +     * @return     the actual number of bytes skipped.
   5.150 +     * @exception  IOException  if the stream does not support seek,
   5.151 +     *                          or if some other I/O error occurs.
   5.152 +     */
   5.153 +    public long skip(long n) throws IOException {
   5.154 +        return in.skip(n);
   5.155 +    }
   5.156 +
   5.157 +    /**
   5.158 +     * Returns an estimate of the number of bytes that can be read (or
   5.159 +     * skipped over) from this input stream without blocking by the next
   5.160 +     * caller of a method for this input stream. The next caller might be
   5.161 +     * the same thread or another thread.  A single read or skip of this
   5.162 +     * many bytes will not block, but may read or skip fewer bytes.
   5.163 +     * <p>
   5.164 +     * This method returns the result of {@link #in in}.available().
   5.165 +     *
   5.166 +     * @return     an estimate of the number of bytes that can be read (or skipped
   5.167 +     *             over) from this input stream without blocking.
   5.168 +     * @exception  IOException  if an I/O error occurs.
   5.169 +     */
   5.170 +    public int available() throws IOException {
   5.171 +        return in.available();
   5.172 +    }
   5.173 +
   5.174 +    /**
   5.175 +     * Closes this input stream and releases any system resources
   5.176 +     * associated with the stream.
   5.177 +     * This
   5.178 +     * method simply performs <code>in.close()</code>.
   5.179 +     *
   5.180 +     * @exception  IOException  if an I/O error occurs.
   5.181 +     * @see        java.io.FilterInputStream#in
   5.182 +     */
   5.183 +    public void close() throws IOException {
   5.184 +        in.close();
   5.185 +    }
   5.186 +
   5.187 +    /**
   5.188 +     * Marks the current position in this input stream. A subsequent
   5.189 +     * call to the <code>reset</code> method repositions this stream at
   5.190 +     * the last marked position so that subsequent reads re-read the same bytes.
   5.191 +     * <p>
   5.192 +     * The <code>readlimit</code> argument tells this input stream to
   5.193 +     * allow that many bytes to be read before the mark position gets
   5.194 +     * invalidated.
   5.195 +     * <p>
   5.196 +     * This method simply performs <code>in.mark(readlimit)</code>.
   5.197 +     *
   5.198 +     * @param   readlimit   the maximum limit of bytes that can be read before
   5.199 +     *                      the mark position becomes invalid.
   5.200 +     * @see     java.io.FilterInputStream#in
   5.201 +     * @see     java.io.FilterInputStream#reset()
   5.202 +     */
   5.203 +    public synchronized void mark(int readlimit) {
   5.204 +        in.mark(readlimit);
   5.205 +    }
   5.206 +
   5.207 +    /**
   5.208 +     * Repositions this stream to the position at the time the
   5.209 +     * <code>mark</code> method was last called on this input stream.
   5.210 +     * <p>
   5.211 +     * This method
   5.212 +     * simply performs <code>in.reset()</code>.
   5.213 +     * <p>
   5.214 +     * Stream marks are intended to be used in
   5.215 +     * situations where you need to read ahead a little to see what's in
   5.216 +     * the stream. Often this is most easily done by invoking some
   5.217 +     * general parser. If the stream is of the type handled by the
   5.218 +     * parse, it just chugs along happily. If the stream is not of
   5.219 +     * that type, the parser should toss an exception when it fails.
   5.220 +     * If this happens within readlimit bytes, it allows the outer
   5.221 +     * code to reset the stream and try another parser.
   5.222 +     *
   5.223 +     * @exception  IOException  if the stream has not been marked or if the
   5.224 +     *               mark has been invalidated.
   5.225 +     * @see        java.io.FilterInputStream#in
   5.226 +     * @see        java.io.FilterInputStream#mark(int)
   5.227 +     */
   5.228 +    public synchronized void reset() throws IOException {
   5.229 +        in.reset();
   5.230 +    }
   5.231 +
   5.232 +    /**
   5.233 +     * Tests if this input stream supports the <code>mark</code>
   5.234 +     * and <code>reset</code> methods.
   5.235 +     * This method
   5.236 +     * simply performs <code>in.markSupported()</code>.
   5.237 +     *
   5.238 +     * @return  <code>true</code> if this stream type supports the
   5.239 +     *          <code>mark</code> and <code>reset</code> method;
   5.240 +     *          <code>false</code> otherwise.
   5.241 +     * @see     java.io.FilterInputStream#in
   5.242 +     * @see     java.io.InputStream#mark(int)
   5.243 +     * @see     java.io.InputStream#reset()
   5.244 +     */
   5.245 +    public boolean markSupported() {
   5.246 +        return in.markSupported();
   5.247 +    }
   5.248 +}
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/emul/src/main/java/java/io/PushbackInputStream.java	Sun Nov 18 22:03:15 2012 +0100
     6.3 @@ -0,0 +1,388 @@
     6.4 +/*
     6.5 + * Copyright (c) 1994, 2011, Oracle and/or its affiliates. All rights reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.  Oracle designates this
    6.11 + * particular file as subject to the "Classpath" exception as provided
    6.12 + * by Oracle in the LICENSE file that accompanied this code.
    6.13 + *
    6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.17 + * version 2 for more details (a copy is included in the LICENSE file that
    6.18 + * accompanied this code).
    6.19 + *
    6.20 + * You should have received a copy of the GNU General Public License version
    6.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.23 + *
    6.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.25 + * or visit www.oracle.com if you need additional information or have any
    6.26 + * questions.
    6.27 + */
    6.28 +
    6.29 +package java.io;
    6.30 +
    6.31 +/**
    6.32 + * A <code>PushbackInputStream</code> adds
    6.33 + * functionality to another input stream, namely
    6.34 + * the  ability to "push back" or "unread"
    6.35 + * one byte. This is useful in situations where
    6.36 + * it is  convenient for a fragment of code
    6.37 + * to read an indefinite number of data bytes
    6.38 + * that  are delimited by a particular byte
    6.39 + * value; after reading the terminating byte,
    6.40 + * the  code fragment can "unread" it, so that
    6.41 + * the next read operation on the input stream
    6.42 + * will reread the byte that was pushed back.
    6.43 + * For example, bytes representing the  characters
    6.44 + * constituting an identifier might be terminated
    6.45 + * by a byte representing an  operator character;
    6.46 + * a method whose job is to read just an identifier
    6.47 + * can read until it  sees the operator and
    6.48 + * then push the operator back to be re-read.
    6.49 + *
    6.50 + * @author  David Connelly
    6.51 + * @author  Jonathan Payne
    6.52 + * @since   JDK1.0
    6.53 + */
    6.54 +public
    6.55 +class PushbackInputStream extends FilterInputStream {
    6.56 +    /**
    6.57 +     * The pushback buffer.
    6.58 +     * @since   JDK1.1
    6.59 +     */
    6.60 +    protected byte[] buf;
    6.61 +
    6.62 +    /**
    6.63 +     * The position within the pushback buffer from which the next byte will
    6.64 +     * be read.  When the buffer is empty, <code>pos</code> is equal to
    6.65 +     * <code>buf.length</code>; when the buffer is full, <code>pos</code> is
    6.66 +     * equal to zero.
    6.67 +     *
    6.68 +     * @since   JDK1.1
    6.69 +     */
    6.70 +    protected int pos;
    6.71 +
    6.72 +    /**
    6.73 +     * Check to make sure that this stream has not been closed
    6.74 +     */
    6.75 +    private void ensureOpen() throws IOException {
    6.76 +        if (in == null)
    6.77 +            throw new IOException("Stream closed");
    6.78 +    }
    6.79 +
    6.80 +    /**
    6.81 +     * Creates a <code>PushbackInputStream</code>
    6.82 +     * with a pushback buffer of the specified <code>size</code>,
    6.83 +     * and saves its  argument, the input stream
    6.84 +     * <code>in</code>, for later use. Initially,
    6.85 +     * there is no pushed-back byte  (the field
    6.86 +     * <code>pushBack</code> is initialized to
    6.87 +     * <code>-1</code>).
    6.88 +     *
    6.89 +     * @param  in    the input stream from which bytes will be read.
    6.90 +     * @param  size  the size of the pushback buffer.
    6.91 +     * @exception IllegalArgumentException if size is <= 0
    6.92 +     * @since  JDK1.1
    6.93 +     */
    6.94 +    public PushbackInputStream(InputStream in, int size) {
    6.95 +        super(in);
    6.96 +        if (size <= 0) {
    6.97 +            throw new IllegalArgumentException("size <= 0");
    6.98 +        }
    6.99 +        this.buf = new byte[size];
   6.100 +        this.pos = size;
   6.101 +    }
   6.102 +
   6.103 +    /**
   6.104 +     * Creates a <code>PushbackInputStream</code>
   6.105 +     * and saves its  argument, the input stream
   6.106 +     * <code>in</code>, for later use. Initially,
   6.107 +     * there is no pushed-back byte  (the field
   6.108 +     * <code>pushBack</code> is initialized to
   6.109 +     * <code>-1</code>).
   6.110 +     *
   6.111 +     * @param   in   the input stream from which bytes will be read.
   6.112 +     */
   6.113 +    public PushbackInputStream(InputStream in) {
   6.114 +        this(in, 1);
   6.115 +    }
   6.116 +
   6.117 +    /**
   6.118 +     * Reads the next byte of data from this input stream. The value
   6.119 +     * byte is returned as an <code>int</code> in the range
   6.120 +     * <code>0</code> to <code>255</code>. If no byte is available
   6.121 +     * because the end of the stream has been reached, the value
   6.122 +     * <code>-1</code> is returned. This method blocks until input data
   6.123 +     * is available, the end of the stream is detected, or an exception
   6.124 +     * is thrown.
   6.125 +     *
   6.126 +     * <p> This method returns the most recently pushed-back byte, if there is
   6.127 +     * one, and otherwise calls the <code>read</code> method of its underlying
   6.128 +     * input stream and returns whatever value that method returns.
   6.129 +     *
   6.130 +     * @return     the next byte of data, or <code>-1</code> if the end of the
   6.131 +     *             stream has been reached.
   6.132 +     * @exception  IOException  if this input stream has been closed by
   6.133 +     *             invoking its {@link #close()} method,
   6.134 +     *             or an I/O error occurs.
   6.135 +     * @see        java.io.InputStream#read()
   6.136 +     */
   6.137 +    public int read() throws IOException {
   6.138 +        ensureOpen();
   6.139 +        if (pos < buf.length) {
   6.140 +            return buf[pos++] & 0xff;
   6.141 +        }
   6.142 +        return super.read();
   6.143 +    }
   6.144 +
   6.145 +    /**
   6.146 +     * Reads up to <code>len</code> bytes of data from this input stream into
   6.147 +     * an array of bytes.  This method first reads any pushed-back bytes; after
   6.148 +     * that, if fewer than <code>len</code> bytes have been read then it
   6.149 +     * reads from the underlying input stream. If <code>len</code> is not zero, the method
   6.150 +     * blocks until at least 1 byte of input is available; otherwise, no
   6.151 +     * bytes are read and <code>0</code> is returned.
   6.152 +     *
   6.153 +     * @param      b     the buffer into which the data is read.
   6.154 +     * @param      off   the start offset in the destination array <code>b</code>
   6.155 +     * @param      len   the maximum number of bytes read.
   6.156 +     * @return     the total number of bytes read into the buffer, or
   6.157 +     *             <code>-1</code> if there is no more data because the end of
   6.158 +     *             the stream has been reached.
   6.159 +     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
   6.160 +     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
   6.161 +     * <code>len</code> is negative, or <code>len</code> is greater than
   6.162 +     * <code>b.length - off</code>
   6.163 +     * @exception  IOException  if this input stream has been closed by
   6.164 +     *             invoking its {@link #close()} method,
   6.165 +     *             or an I/O error occurs.
   6.166 +     * @see        java.io.InputStream#read(byte[], int, int)
   6.167 +     */
   6.168 +    public int read(byte[] b, int off, int len) throws IOException {
   6.169 +        ensureOpen();
   6.170 +        if (b == null) {
   6.171 +            throw new NullPointerException();
   6.172 +        } else if (off < 0 || len < 0 || len > b.length - off) {
   6.173 +            throw new IndexOutOfBoundsException();
   6.174 +        } else if (len == 0) {
   6.175 +            return 0;
   6.176 +        }
   6.177 +
   6.178 +        int avail = buf.length - pos;
   6.179 +        if (avail > 0) {
   6.180 +            if (len < avail) {
   6.181 +                avail = len;
   6.182 +            }
   6.183 +            arraycopy(buf, pos, b, off, avail);
   6.184 +            pos += avail;
   6.185 +            off += avail;
   6.186 +            len -= avail;
   6.187 +        }
   6.188 +        if (len > 0) {
   6.189 +            len = super.read(b, off, len);
   6.190 +            if (len == -1) {
   6.191 +                return avail == 0 ? -1 : avail;
   6.192 +            }
   6.193 +            return avail + len;
   6.194 +        }
   6.195 +        return avail;
   6.196 +    }
   6.197 +
   6.198 +    /**
   6.199 +     * Pushes back a byte by copying it to the front of the pushback buffer.
   6.200 +     * After this method returns, the next byte to be read will have the value
   6.201 +     * <code>(byte)b</code>.
   6.202 +     *
   6.203 +     * @param      b   the <code>int</code> value whose low-order
   6.204 +     *                  byte is to be pushed back.
   6.205 +     * @exception IOException If there is not enough room in the pushback
   6.206 +     *            buffer for the byte, or this input stream has been closed by
   6.207 +     *            invoking its {@link #close()} method.
   6.208 +     */
   6.209 +    public void unread(int b) throws IOException {
   6.210 +        ensureOpen();
   6.211 +        if (pos == 0) {
   6.212 +            throw new IOException("Push back buffer is full");
   6.213 +        }
   6.214 +        buf[--pos] = (byte)b;
   6.215 +    }
   6.216 +
   6.217 +    /**
   6.218 +     * Pushes back a portion of an array of bytes by copying it to the front
   6.219 +     * of the pushback buffer.  After this method returns, the next byte to be
   6.220 +     * read will have the value <code>b[off]</code>, the byte after that will
   6.221 +     * have the value <code>b[off+1]</code>, and so forth.
   6.222 +     *
   6.223 +     * @param b the byte array to push back.
   6.224 +     * @param off the start offset of the data.
   6.225 +     * @param len the number of bytes to push back.
   6.226 +     * @exception IOException If there is not enough room in the pushback
   6.227 +     *            buffer for the specified number of bytes,
   6.228 +     *            or this input stream has been closed by
   6.229 +     *            invoking its {@link #close()} method.
   6.230 +     * @since     JDK1.1
   6.231 +     */
   6.232 +    public void unread(byte[] b, int off, int len) throws IOException {
   6.233 +        ensureOpen();
   6.234 +        if (len > pos) {
   6.235 +            throw new IOException("Push back buffer is full");
   6.236 +        }
   6.237 +        pos -= len;
   6.238 +        arraycopy(b, off, buf, pos, len);
   6.239 +    }
   6.240 +
   6.241 +    /**
   6.242 +     * Pushes back an array of bytes by copying it to the front of the
   6.243 +     * pushback buffer.  After this method returns, the next byte to be read
   6.244 +     * will have the value <code>b[0]</code>, the byte after that will have the
   6.245 +     * value <code>b[1]</code>, and so forth.
   6.246 +     *
   6.247 +     * @param b the byte array to push back
   6.248 +     * @exception IOException If there is not enough room in the pushback
   6.249 +     *            buffer for the specified number of bytes,
   6.250 +     *            or this input stream has been closed by
   6.251 +     *            invoking its {@link #close()} method.
   6.252 +     * @since     JDK1.1
   6.253 +     */
   6.254 +    public void unread(byte[] b) throws IOException {
   6.255 +        unread(b, 0, b.length);
   6.256 +    }
   6.257 +
   6.258 +    /**
   6.259 +     * Returns an estimate of the number of bytes that can be read (or
   6.260 +     * skipped over) from this input stream without blocking by the next
   6.261 +     * invocation of a method for this input stream. The next invocation might be
   6.262 +     * the same thread or another thread.  A single read or skip of this
   6.263 +     * many bytes will not block, but may read or skip fewer bytes.
   6.264 +     *
   6.265 +     * <p> The method returns the sum of the number of bytes that have been
   6.266 +     * pushed back and the value returned by {@link
   6.267 +     * java.io.FilterInputStream#available available}.
   6.268 +     *
   6.269 +     * @return     the number of bytes that can be read (or skipped over) from
   6.270 +     *             the input stream without blocking.
   6.271 +     * @exception  IOException  if this input stream has been closed by
   6.272 +     *             invoking its {@link #close()} method,
   6.273 +     *             or an I/O error occurs.
   6.274 +     * @see        java.io.FilterInputStream#in
   6.275 +     * @see        java.io.InputStream#available()
   6.276 +     */
   6.277 +    public int available() throws IOException {
   6.278 +        ensureOpen();
   6.279 +        int n = buf.length - pos;
   6.280 +        int avail = super.available();
   6.281 +        return n > (Integer.MAX_VALUE - avail)
   6.282 +                    ? Integer.MAX_VALUE
   6.283 +                    : n + avail;
   6.284 +    }
   6.285 +
   6.286 +    /**
   6.287 +     * Skips over and discards <code>n</code> bytes of data from this
   6.288 +     * input stream. The <code>skip</code> method may, for a variety of
   6.289 +     * reasons, end up skipping over some smaller number of bytes,
   6.290 +     * possibly zero.  If <code>n</code> is negative, no bytes are skipped.
   6.291 +     *
   6.292 +     * <p> The <code>skip</code> method of <code>PushbackInputStream</code>
   6.293 +     * first skips over the bytes in the pushback buffer, if any.  It then
   6.294 +     * calls the <code>skip</code> method of the underlying input stream if
   6.295 +     * more bytes need to be skipped.  The actual number of bytes skipped
   6.296 +     * is returned.
   6.297 +     *
   6.298 +     * @param      n  {@inheritDoc}
   6.299 +     * @return     {@inheritDoc}
   6.300 +     * @exception  IOException  if the stream does not support seek,
   6.301 +     *            or the stream has been closed by
   6.302 +     *            invoking its {@link #close()} method,
   6.303 +     *            or an I/O error occurs.
   6.304 +     * @see        java.io.FilterInputStream#in
   6.305 +     * @see        java.io.InputStream#skip(long n)
   6.306 +     * @since      1.2
   6.307 +     */
   6.308 +    public long skip(long n) throws IOException {
   6.309 +        ensureOpen();
   6.310 +        if (n <= 0) {
   6.311 +            return 0;
   6.312 +        }
   6.313 +
   6.314 +        long pskip = buf.length - pos;
   6.315 +        if (pskip > 0) {
   6.316 +            if (n < pskip) {
   6.317 +                pskip = n;
   6.318 +            }
   6.319 +            pos += pskip;
   6.320 +            n -= pskip;
   6.321 +        }
   6.322 +        if (n > 0) {
   6.323 +            pskip += super.skip(n);
   6.324 +        }
   6.325 +        return pskip;
   6.326 +    }
   6.327 +
   6.328 +    /**
   6.329 +     * Tests if this input stream supports the <code>mark</code> and
   6.330 +     * <code>reset</code> methods, which it does not.
   6.331 +     *
   6.332 +     * @return   <code>false</code>, since this class does not support the
   6.333 +     *           <code>mark</code> and <code>reset</code> methods.
   6.334 +     * @see     java.io.InputStream#mark(int)
   6.335 +     * @see     java.io.InputStream#reset()
   6.336 +     */
   6.337 +    public boolean markSupported() {
   6.338 +        return false;
   6.339 +    }
   6.340 +
   6.341 +    /**
   6.342 +     * Marks the current position in this input stream.
   6.343 +     *
   6.344 +     * <p> The <code>mark</code> method of <code>PushbackInputStream</code>
   6.345 +     * does nothing.
   6.346 +     *
   6.347 +     * @param   readlimit   the maximum limit of bytes that can be read before
   6.348 +     *                      the mark position becomes invalid.
   6.349 +     * @see     java.io.InputStream#reset()
   6.350 +     */
   6.351 +    public synchronized void mark(int readlimit) {
   6.352 +    }
   6.353 +
   6.354 +    /**
   6.355 +     * Repositions this stream to the position at the time the
   6.356 +     * <code>mark</code> method was last called on this input stream.
   6.357 +     *
   6.358 +     * <p> The method <code>reset</code> for class
   6.359 +     * <code>PushbackInputStream</code> does nothing except throw an
   6.360 +     * <code>IOException</code>.
   6.361 +     *
   6.362 +     * @exception  IOException  if this method is invoked.
   6.363 +     * @see     java.io.InputStream#mark(int)
   6.364 +     * @see     java.io.IOException
   6.365 +     */
   6.366 +    public synchronized void reset() throws IOException {
   6.367 +        throw new IOException("mark/reset not supported");
   6.368 +    }
   6.369 +
   6.370 +    /**
   6.371 +     * Closes this input stream and releases any system resources
   6.372 +     * associated with the stream.
   6.373 +     * Once the stream has been closed, further read(), unread(),
   6.374 +     * available(), reset(), or skip() invocations will throw an IOException.
   6.375 +     * Closing a previously closed stream has no effect.
   6.376 +     *
   6.377 +     * @exception  IOException  if an I/O error occurs.
   6.378 +     */
   6.379 +    public synchronized void close() throws IOException {
   6.380 +        if (in == null)
   6.381 +            return;
   6.382 +        in.close();
   6.383 +        in = null;
   6.384 +        buf = null;
   6.385 +    }
   6.386 +    static void arraycopy(byte[] value, int srcBegin, byte[] dst, int dstBegin, int count) {
   6.387 +        while (count-- > 0) {
   6.388 +            dst[dstBegin++] = value[srcBegin++];
   6.389 +        }
   6.390 +    }
   6.391 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/emul/src/main/java/java/io/UTFDataFormatException.java	Sun Nov 18 22:03:15 2012 +0100
     7.3 @@ -0,0 +1,69 @@
     7.4 +/*
     7.5 + * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + *
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.  Oracle designates this
    7.11 + * particular file as subject to the "Classpath" exception as provided
    7.12 + * by Oracle in the LICENSE file that accompanied this code.
    7.13 + *
    7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.17 + * version 2 for more details (a copy is included in the LICENSE file that
    7.18 + * accompanied this code).
    7.19 + *
    7.20 + * You should have received a copy of the GNU General Public License version
    7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.23 + *
    7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    7.25 + * or visit www.oracle.com if you need additional information or have any
    7.26 + * questions.
    7.27 + */
    7.28 +
    7.29 +package java.io;
    7.30 +
    7.31 +/**
    7.32 + * Signals that a malformed string in
    7.33 + * <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
    7.34 + * format has been read in a data
    7.35 + * input stream or by any class that implements the data input
    7.36 + * interface.
    7.37 + * See the
    7.38 + * <a href="DataInput.html#modified-utf-8"><code>DataInput</code></a>
    7.39 + * class description for the format in
    7.40 + * which modified UTF-8 strings are read and written.
    7.41 + *
    7.42 + * @author  Frank Yellin
    7.43 + * @see     java.io.DataInput
    7.44 + * @see     java.io.DataInputStream#readUTF(java.io.DataInput)
    7.45 + * @see     java.io.IOException
    7.46 + * @since   JDK1.0
    7.47 + */
    7.48 +public
    7.49 +class UTFDataFormatException extends IOException {
    7.50 +    private static final long serialVersionUID = 420743449228280612L;
    7.51 +
    7.52 +    /**
    7.53 +     * Constructs a <code>UTFDataFormatException</code> with
    7.54 +     * <code>null</code> as its error detail message.
    7.55 +     */
    7.56 +    public UTFDataFormatException() {
    7.57 +        super();
    7.58 +    }
    7.59 +
    7.60 +    /**
    7.61 +     * Constructs a <code>UTFDataFormatException</code> with the
    7.62 +     * specified detail message. The string <code>s</code> can be
    7.63 +     * retrieved later by the
    7.64 +     * <code>{@link java.lang.Throwable#getMessage}</code>
    7.65 +     * method of class <code>java.lang.Throwable</code>.
    7.66 +     *
    7.67 +     * @param   s   the detail message.
    7.68 +     */
    7.69 +    public UTFDataFormatException(String s) {
    7.70 +        super(s);
    7.71 +    }
    7.72 +}
     8.1 --- a/emul/src/main/java/java/lang/AbstractStringBuilder.java	Tue Nov 13 07:56:02 2012 +0100
     8.2 +++ b/emul/src/main/java/java/lang/AbstractStringBuilder.java	Sun Nov 18 22:03:15 2012 +0100
     8.3 @@ -1417,7 +1417,7 @@
     8.4  
     8.5      static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
     8.6          while (count-- > 0) {
     8.7 -            dst[dstBegin++] = value[srcBegin++];
     8.8 +            dst[dstBegin + count] = value[srcBegin + count];
     8.9          }
    8.10      }
    8.11  
     9.1 --- a/emul/src/main/java/java/lang/Double.java	Tue Nov 13 07:56:02 2012 +0100
     9.2 +++ b/emul/src/main/java/java/lang/Double.java	Sun Nov 18 22:03:15 2012 +0100
     9.3 @@ -190,7 +190,9 @@
     9.4       * @param   d   the {@code double} to be converted.
     9.5       * @return a string representation of the argument.
     9.6       */
     9.7 -    @JavaScriptBody(args="d", body="return d.toString();")
     9.8 +    @JavaScriptBody(args="d", body="var r = d.toString();"
     9.9 +        + "if (r.indexOf('.') === -1) r = r + '.0';"
    9.10 +        + "return r;")
    9.11      public static String toString(double d) {
    9.12          throw new UnsupportedOperationException();
    9.13      }
    10.1 --- a/emul/src/main/java/java/lang/Float.java	Tue Nov 13 07:56:02 2012 +0100
    10.2 +++ b/emul/src/main/java/java/lang/Float.java	Sun Nov 18 22:03:15 2012 +0100
    10.3 @@ -192,10 +192,8 @@
    10.4       * @param   f   the float to be converted.
    10.5       * @return a string representation of the argument.
    10.6       */
    10.7 -    @JavaScriptBody(args="d", body="return d.toString();")
    10.8      public static String toString(float f) {
    10.9 -        throw new UnsupportedOperationException();
   10.10 -//        return new FloatingDecimal(f).toJavaFormatString();
   10.11 +        return Double.toString(f);
   10.12      }
   10.13  
   10.14      /**
   10.15 @@ -819,6 +817,18 @@
   10.16       * @return  the {@code float} floating-point value with the same bit
   10.17       *          pattern.
   10.18       */
   10.19 +    @JavaScriptBody(args = "bits",
   10.20 +        body = 
   10.21 +          "if (bits === 0x7f800000) return Number.POSITIVE_INFINITY;\n"
   10.22 +        + "if (bits === 0xff800000) return Number.NEGATIVE_INFINITY;\n"
   10.23 +        + "if (bits >= 0x7f800001 && bits <= 0xffffffff) return Number.NaN;\n"
   10.24 +        + "var s = ((bits >> 31) == 0) ? 1 : -1;\n"
   10.25 +        + "var e = ((bits >> 23) & 0xff);\n"
   10.26 +        + "var m = (e == 0) ?\n"
   10.27 +        + "  (bits & 0x7fffff) << 1 :\n"
   10.28 +        + "  (bits & 0x7fffff) | 0x800000;\n"
   10.29 +        + "return s * m * Math.pow(2.0, e - 150);\n"
   10.30 +    )
   10.31      public static native float intBitsToFloat(int bits);
   10.32  
   10.33      /**
    11.1 --- a/emul/src/main/java/java/lang/Integer.java	Tue Nov 13 07:56:02 2012 +0100
    11.2 +++ b/emul/src/main/java/java/lang/Integer.java	Sun Nov 18 22:03:15 2012 +0100
    11.3 @@ -324,13 +324,14 @@
    11.4       * @param   i   an integer to be converted.
    11.5       * @return  a string representation of the argument in base&nbsp;10.
    11.6       */
    11.7 +    @JavaScriptBody(args = "i", body = "return i.toString();")
    11.8      public static String toString(int i) {
    11.9          if (i == Integer.MIN_VALUE)
   11.10              return "-2147483648";
   11.11          int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
   11.12          char[] buf = new char[size];
   11.13          getChars(i, size, buf);
   11.14 -        return new String(0, size, buf);
   11.15 +        return new String(buf, 0, size);
   11.16      }
   11.17  
   11.18      /**
    12.1 --- a/emul/src/main/java/java/lang/Long.java	Tue Nov 13 07:56:02 2012 +0100
    12.2 +++ b/emul/src/main/java/java/lang/Long.java	Sun Nov 18 22:03:15 2012 +0100
    12.3 @@ -25,6 +25,8 @@
    12.4  
    12.5  package java.lang;
    12.6  
    12.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
    12.8 +
    12.9  /**
   12.10   * The {@code Long} class wraps a value of the primitive type {@code
   12.11   * long} in an object. An object of type {@code Long} contains a
   12.12 @@ -260,13 +262,14 @@
   12.13       * @param   i   a {@code long} to be converted.
   12.14       * @return  a string representation of the argument in base&nbsp;10.
   12.15       */
   12.16 +    @JavaScriptBody(args = "i", body = "return i.toString();")
   12.17      public static String toString(long i) {
   12.18          if (i == Long.MIN_VALUE)
   12.19              return "-9223372036854775808";
   12.20          int size = (i < 0) ? stringSize(-i) + 1 : stringSize(i);
   12.21          char[] buf = new char[size];
   12.22          getChars(i, size, buf);
   12.23 -        return new String(0, size, buf);
   12.24 +        return new String(buf, 0, size);
   12.25      }
   12.26  
   12.27      /**
    13.1 --- a/emul/src/main/java/java/lang/String.java	Tue Nov 13 07:56:02 2012 +0100
    13.2 +++ b/emul/src/main/java/java/lang/String.java	Sun Nov 18 22:03:15 2012 +0100
    13.3 @@ -641,14 +641,6 @@
    13.4          this.offset = result.offset;
    13.5      }
    13.6  
    13.7 -
    13.8 -    // Package private constructor which shares value array for speed.
    13.9 -    String(int offset, int count, char value[]) {
   13.10 -        this.value = value;
   13.11 -        this.offset = offset;
   13.12 -        this.count = count;
   13.13 -    }
   13.14 -
   13.15      /**
   13.16       * Returns the length of this string.
   13.17       * The length is equal to the number of <a href="Character.html#unicode">Unicode
   13.18 @@ -1966,7 +1958,7 @@
   13.19              throw new StringIndexOutOfBoundsException(endIndex - beginIndex);
   13.20          }
   13.21          return ((beginIndex == 0) && (endIndex == count)) ? this :
   13.22 -            new String(offset + beginIndex, endIndex - beginIndex, value);
   13.23 +            new String(value, offset + beginIndex, endIndex - beginIndex);
   13.24      }
   13.25  
   13.26      /**
   13.27 @@ -2029,7 +2021,7 @@
   13.28          char buf[] = new char[count + otherLen];
   13.29          getChars(0, count, buf, 0);
   13.30          str.getChars(0, otherLen, buf, count);
   13.31 -        return new String(0, count + otherLen, buf);
   13.32 +        return new String(buf, 0, count + otherLen);
   13.33      }
   13.34  
   13.35      /**
   13.36 @@ -2083,7 +2075,7 @@
   13.37                      buf[i] = (c == oldChar) ? newChar : c;
   13.38                      i++;
   13.39                  }
   13.40 -                return new String(0, len, buf);
   13.41 +                return new String(buf, 0, len);
   13.42              }
   13.43          }
   13.44          return this;
   13.45 @@ -2951,7 +2943,7 @@
   13.46       */
   13.47      public static String valueOf(char c) {
   13.48          char data[] = {c};
   13.49 -        return new String(0, 1, data);
   13.50 +        return new String(data, 0, 1);
   13.51      }
   13.52  
   13.53      /**
    14.1 --- a/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js	Tue Nov 13 07:56:02 2012 +0100
    14.2 +++ b/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js	Sun Nov 18 22:03:15 2012 +0100
    14.3 @@ -1,16 +1,23 @@
    14.4  /* */
    14.5  
    14.6  
    14.7 -function java_lang_String_consVAC(arg0,arg1) {
    14.8 -    arg0.r = arg1.join("");
    14.9 +function java_lang_String_consVAC(self,charArr) {
   14.10 +    for (var i = 0; i < charArr.length; i++) {
   14.11 +        if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);
   14.12 +    }
   14.13 +    self.r = charArr.join("");
   14.14  }
   14.15  
   14.16  function java_lang_String_consVACII(self, charArr, off, cnt) {
   14.17 -    self.r = charArr.slice(off, off + cnt).join("");
   14.18 +    var up = off + cnt;
   14.19 +    for (var i = off; i < up; i++) {
   14.20 +        if (typeof charArr[i] === 'number') charArr[i] = String.fromCharCode(charArr[i]);
   14.21 +    }
   14.22 +    self.r = charArr.slice(off, up).join("");
   14.23  }
   14.24  
   14.25  function java_lang_String_charAtCI(arg0,arg1) {
   14.26 -    return arg0.toString().charAt(arg1);
   14.27 +    return arg0.toString().charCodeAt(arg1);
   14.28  }
   14.29  function java_lang_String_lengthI(arg0) {
   14.30      return arg0.toString().length;
   14.31 @@ -18,6 +25,42 @@
   14.32  function java_lang_String_isEmptyZ(arg0) {
   14.33      return arg0.toString().length === 0;
   14.34  }
   14.35 +function java_lang_String_valueOfLjava_lang_StringI(n) {
   14.36 +    return n.toString();
   14.37 +}
   14.38 +
   14.39 +function java_lang_String_startsWithZLjava_lang_StringI(self,find,from) {
   14.40 +    find = find.toString();
   14.41 +    return self.toString().substring(from, find.length) === find;
   14.42 +}
   14.43 +function java_lang_String_startsWithZLjava_lang_String(self,find) {
   14.44 +    find = find.toString();
   14.45 +    return self.toString().substring(0, find.length) === find;
   14.46 +}
   14.47 +function java_lang_String_endsWithZLjava_lang_String(self,find) {
   14.48 +    self = self.toString();
   14.49 +    find = find.toString();
   14.50 +    if (find.length > self.length) {
   14.51 +        return false;
   14.52 +    }
   14.53 +    return self.substring(self.length - find.length) === find;
   14.54 +}
   14.55 +
   14.56 +function java_lang_String_indexOfII(arg0,ch) {
   14.57 +    if (typeof ch === 'number') ch = String.fromCharCode(ch);
   14.58 +    return arg0.toString().indexOf(ch);
   14.59 +}
   14.60 +function java_lang_String_indexOfIII(arg0,ch,from) {
   14.61 +    if (typeof ch === 'number') ch = String.fromCharCode(ch);
   14.62 +    return arg0.toString().indexOf(ch, from);
   14.63 +}
   14.64 +
   14.65 +function java_lang_String_getCharsVACI(self, arr, to) {
   14.66 +    var s = self.toString();
   14.67 +    for (var i = 0; i < s.length; i++) {
   14.68 +        arr[to++] = s[i];
   14.69 +    }
   14.70 +}
   14.71  
   14.72  /*
   14.73  function java_lang_String_codePointAtII(arg0,arg1) {
   14.74 @@ -860,116 +903,6 @@
   14.75      case 63: return stack.pop(); // 172
   14.76    }
   14.77  }
   14.78 -function java_lang_String_indexOfII(arg0,arg1) {
   14.79 -  var arg2;
   14.80 -;
   14.81 -  var stack = new Array(3);
   14.82 -  var gt = 0;
   14.83 -  for(;;) switch(gt) {
   14.84 -    case 0: stack.push(arg0); // 42
   14.85 -    case 1: stack.push(arg1); // 27
   14.86 -    case 2: stack.push(0); // 3
   14.87 -    case 3: { var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); stack.push(self.indexOfIII(self, v0, v1)); } // 182 1 135
   14.88 -    case 6: return stack.pop(); // 172
   14.89 -  }
   14.90 -}
   14.91 -function java_lang_String_indexOfIII(arg0,arg1,arg2) {
   14.92 -  var arg3;
   14.93 -  var arg4;
   14.94 -  var arg5;
   14.95 -  var arg6;
   14.96 -  var arg7;
   14.97 -;
   14.98 -  var stack = new Array(3);
   14.99 -  var gt = 0;
  14.100 -  for(;;) switch(gt) {
  14.101 -    case 0: stack.push(arg0); // 42
  14.102 -    case 1: stack.push(stack.pop().offset); // 180 1 99
  14.103 -    case 4: stack.push(arg0); // 42
  14.104 -    case 5: stack.push(stack.pop().count); // 180 1 97
  14.105 -    case 8: stack.push(stack.pop() + stack.pop()); // 96
  14.106 -    case 9: arg3 = stack.pop(); // 62
  14.107 -    case 10: stack.push(arg0); // 42
  14.108 -    case 11: stack.push(stack.pop().value); // 180 1 100
  14.109 -    case 14: arg4 = stack.pop() // 58 4
  14.110 -    case 16: stack.push(arg2); // 28
  14.111 -    case 17: if (stack.pop() >= 0) { gt = 25; continue; } // 156 0 8
  14.112 -    case 20: stack.push(0); // 3
  14.113 -    case 21: arg2 = stack.pop(); // 61
  14.114 -    case 22: gt = 35; continue; // 167 0 13
  14.115 -    case 25: stack.push(arg2); // 28
  14.116 -    case 26: stack.push(arg0); // 42
  14.117 -    case 27: stack.push(stack.pop().count); // 180 1 97
  14.118 -    case 30: if (stack.pop() > stack.pop()) { gt = 35; continue; } // 161 0 5
  14.119 -    case 33:  // 2
  14.120 -    case 34: return stack.pop(); // 172
  14.121 -    case 35: stack.push(arg0); // 42
  14.122 -    case 36: stack.push(stack.pop().offset); // 180 1 99
  14.123 -    case 39: stack.push(arg2); // 28
  14.124 -    case 40: stack.push(stack.pop() + stack.pop()); // 96
  14.125 -    case 41: arg5 = stack.pop() // 54 5
  14.126 -    case 43: stack.push(arg1); // 27
  14.127 -    case 44: stack.push(65536); // 18 3
  14.128 -    case 46: if (stack.pop() <= stack.pop()) { gt = 80; continue; } // 162 0 34
  14.129 -    case 49: stack.push(arg5); // 21 5
  14.130 -    case 51: stack.push(arg3); // 29
  14.131 -    case 52: if (stack.pop() <= stack.pop()) { gt = 78; continue; } // 162 0 26
  14.132 -    case 55: stack.push(arg4); // 25 4
  14.133 -    case 57: stack.push(arg5); // 21 5
  14.134 -    case 59: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
  14.135 -    case 60: stack.push(arg1); // 27
  14.136 -    case 61: if (stack.pop() != stack.pop()) { gt = 72; continue; } // 160 0 11
  14.137 -    case 64: stack.push(arg5); // 21 5
  14.138 -    case 66: stack.push(arg0); // 42
  14.139 -    case 67: stack.push(stack.pop().offset); // 180 1 99
  14.140 -    case 70: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
  14.141 -    case 71: return stack.pop(); // 172
  14.142 -    case 72: arg5++; // 132 5 1
  14.143 -    case 75: gt = 49; continue; // 167 255 230
  14.144 -    case 78:  // 2
  14.145 -    case 79: return stack.pop(); // 172
  14.146 -    case 80: stack.push(arg1); // 27
  14.147 -    case 81: stack.push(1114111); // 18 4
  14.148 -    case 83: if (stack.pop() < stack.pop()) { gt = 149; continue; } // 163 0 66
  14.149 -    case 86: stack.push(arg1); // 27
  14.150 -    case 87: { var v0 = stack.pop(); stack.push(java_lang_Character_toCharsACI(v0)); } // 184 1 109
  14.151 -    case 90: arg6 = stack.pop() // 58 6
  14.152 -    case 92: stack.push(arg5); // 21 5
  14.153 -    case 94: stack.push(arg3); // 29
  14.154 -    case 95: if (stack.pop() <= stack.pop()) { gt = 149; continue; } // 162 0 54
  14.155 -    case 98: stack.push(arg4); // 25 4
  14.156 -    case 100: stack.push(arg5); // 21 5
  14.157 -    case 102: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
  14.158 -    case 103: stack.push(arg6); // 25 6
  14.159 -    case 105: stack.push(0); // 3
  14.160 -    case 106: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
  14.161 -    case 107: if (stack.pop() != stack.pop()) { gt = 143; continue; } // 160 0 36
  14.162 -    case 110: stack.push(arg5); // 21 5
  14.163 -    case 112: stack.push(1); // 4
  14.164 -    case 113: stack.push(stack.pop() + stack.pop()); // 96
  14.165 -    case 114: stack.push(arg3); // 29
  14.166 -    case 115: if (stack.pop() != stack.pop()) { gt = 121; continue; } // 160 0 6
  14.167 -    case 118: gt = 149; continue; // 167 0 31
  14.168 -    case 121: stack.push(arg4); // 25 4
  14.169 -    case 123: stack.push(arg5); // 21 5
  14.170 -    case 125: stack.push(1); // 4
  14.171 -    case 126: stack.push(stack.pop() + stack.pop()); // 96
  14.172 -    case 127: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
  14.173 -    case 128: stack.push(arg6); // 25 6
  14.174 -    case 130: stack.push(1); // 4
  14.175 -    case 131: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
  14.176 -    case 132: if (stack.pop() != stack.pop()) { gt = 143; continue; } // 160 0 11
  14.177 -    case 135: stack.push(arg5); // 21 5
  14.178 -    case 137: stack.push(arg0); // 42
  14.179 -    case 138: stack.push(stack.pop().offset); // 180 1 99
  14.180 -    case 141: { var tmp = stack.pop(); stack.push(stack.pop() - tmp); } // 100
  14.181 -    case 142: return stack.pop(); // 172
  14.182 -    case 143: arg5++; // 132 5 1
  14.183 -    case 146: gt = 92; continue; // 167 255 202
  14.184 -    case 149:  // 2
  14.185 -    case 150: return stack.pop(); // 172
  14.186 -  }
  14.187 -}
  14.188  function java_lang_String_lastIndexOfII(arg0,arg1) {
  14.189    var arg2;
  14.190  ;
  14.191 @@ -1367,6 +1300,23 @@
  14.192  function java_lang_String_substringLjava_lang_StringII(arg0,arg1,arg2) {
  14.193      return arg0.toString().substring(arg1, arg2);
  14.194  }
  14.195 +
  14.196 +function java_lang_String_replaceLjava_lang_StringCC(arg0,arg1,arg2) {
  14.197 +    if (typeof arg1 === 'number') arg1 = String.fromCharCode(arg1);
  14.198 +    if (typeof arg2 === 'number') arg2 = String.fromCharCode(arg2);
  14.199 +    var s = arg0.toString();
  14.200 +    for (;;) {
  14.201 +        var ret = s.replace(arg1, arg2);
  14.202 +        if (ret === s) {
  14.203 +            return ret;
  14.204 +        }
  14.205 +        s = ret;
  14.206 +    }
  14.207 +}
  14.208 +function java_lang_String_containsZLjava_lang_CharSequence(arg0,arg1) {
  14.209 +    return arg0.toString().indexOf(arg1.toString()) >= 0;
  14.210 +}
  14.211 +
  14.212  /*
  14.213  function java_lang_String_subSequenceLjava_lang_CharSequenceII(arg0,arg1,arg2) {
  14.214    var arg3;
  14.215 @@ -1428,96 +1378,6 @@
  14.216      case 57: return stack.pop(); // 176
  14.217    }
  14.218  }
  14.219 -function java_lang_String_replaceLjava_lang_StringCC(arg0,arg1,arg2) {
  14.220 -  var arg3;
  14.221 -  var arg4;
  14.222 -  var arg5;
  14.223 -  var arg6;
  14.224 -  var arg7;
  14.225 -  var arg8;
  14.226 -  var arg9;
  14.227 -;
  14.228 -  var stack = new Array(5);
  14.229 -  var gt = 0;
  14.230 -  for(;;) switch(gt) {
  14.231 -    case 0: stack.push(arg1); // 27
  14.232 -    case 1: stack.push(arg2); // 28
  14.233 -    case 2: if (stack.pop() == stack.pop()) { gt = 140; continue; } // 159 0 138
  14.234 -    case 5: stack.push(arg0); // 42
  14.235 -    case 6: stack.push(stack.pop().count); // 180 1 97
  14.236 -    case 9: arg3 = stack.pop(); // 62
  14.237 -    case 10:  // 2
  14.238 -    case 11: arg4 = stack.pop() // 54 4
  14.239 -    case 13: stack.push(arg0); // 42
  14.240 -    case 14: stack.push(stack.pop().value); // 180 1 100
  14.241 -    case 17: arg5 = stack.pop() // 58 5
  14.242 -    case 19: stack.push(arg0); // 42
  14.243 -    case 20: stack.push(stack.pop().offset); // 180 1 99
  14.244 -    case 23: arg6 = stack.pop() // 54 6
  14.245 -    case 25: arg4++; // 132 4 1
  14.246 -    case 28: stack.push(arg4); // 21 4
  14.247 -    case 30: stack.push(arg3); // 29
  14.248 -    case 31: if (stack.pop() <= stack.pop()) { gt = 49; continue; } // 162 0 18
  14.249 -    case 34: stack.push(arg5); // 25 5
  14.250 -    case 36: stack.push(arg6); // 21 6
  14.251 -    case 38: stack.push(arg4); // 21 4
  14.252 -    case 40: stack.push(stack.pop() + stack.pop()); // 96
  14.253 -    case 41: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
  14.254 -    case 42: stack.push(arg1); // 27
  14.255 -    case 43: if (stack.pop() != stack.pop()) { gt = 25; continue; } // 160 255 238
  14.256 -    case 46: gt = 49; continue; // 167 0 3
  14.257 -    case 49: stack.push(arg4); // 21 4
  14.258 -    case 51: stack.push(arg3); // 29
  14.259 -    case 52: if (stack.pop() <= stack.pop()) { gt = 140; continue; } // 162 0 88
  14.260 -    case 55: stack.push(arg3); // 29
  14.261 -    case 56: stack.push(new Array(stack.pop())); // 188 5
  14.262 -    case 58: arg7 = stack.pop() // 58 7
  14.263 -    case 60: stack.push(0); // 3
  14.264 -    case 61: arg8 = stack.pop() // 54 8
  14.265 -    case 63: stack.push(arg8); // 21 8
  14.266 -    case 65: stack.push(arg4); // 21 4
  14.267 -    case 67: if (stack.pop() <= stack.pop()) { gt = 89; continue; } // 162 0 22
  14.268 -    case 70: stack.push(arg7); // 25 7
  14.269 -    case 72: stack.push(arg8); // 21 8
  14.270 -    case 74: stack.push(arg5); // 25 5
  14.271 -    case 76: stack.push(arg6); // 21 6
  14.272 -    case 78: stack.push(arg8); // 21 8
  14.273 -    case 80: stack.push(stack.pop() + stack.pop()); // 96
  14.274 -    case 81: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
  14.275 -    case 82: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
  14.276 -    case 83: arg8++; // 132 8 1
  14.277 -    case 86: gt = 63; continue; // 167 255 233
  14.278 -    case 89: stack.push(arg4); // 21 4
  14.279 -    case 91: stack.push(arg3); // 29
  14.280 -    case 92: if (stack.pop() <= stack.pop()) { gt = 128; continue; } // 162 0 36
  14.281 -    case 95: stack.push(arg5); // 25 5
  14.282 -    case 97: stack.push(arg6); // 21 6
  14.283 -    case 99: stack.push(arg4); // 21 4
  14.284 -    case 101: stack.push(stack.pop() + stack.pop()); // 96
  14.285 -    case 102: { var indx = stack.pop(); stack.push(stack.pop()[indx]); } // 52
  14.286 -    case 103: arg8 = stack.pop() // 54 8
  14.287 -    case 105: stack.push(arg7); // 25 7
  14.288 -    case 107: stack.push(arg4); // 21 4
  14.289 -    case 109: stack.push(arg8); // 21 8
  14.290 -    case 111: stack.push(arg1); // 27
  14.291 -    case 112: if (stack.pop() != stack.pop()) { gt = 119; continue; } // 160 0 7
  14.292 -    case 115: stack.push(arg2); // 28
  14.293 -    case 116: gt = 121; continue; // 167 0 5
  14.294 -    case 119: stack.push(arg8); // 21 8
  14.295 -    case 121: { var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; } // 85
  14.296 -    case 122: arg4++; // 132 4 1
  14.297 -    case 125: gt = 89; continue; // 167 255 220
  14.298 -    case 128: stack.push(new java_lang_String); // 187 0 200
  14.299 -    case 131: stack.push(stack[stack.length - 1]); // 89
  14.300 -    case 132: stack.push(0); // 3
  14.301 -    case 133: stack.push(arg3); // 29
  14.302 -    case 134: stack.push(arg7); // 25 7
  14.303 -    case 136: { var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); java_lang_String_consVIIAC(stack.pop(), v0, v1, v2); } // 183 1 137
  14.304 -    case 139: return stack.pop(); // 176
  14.305 -    case 140: stack.push(arg0); // 42
  14.306 -    case 141: return stack.pop(); // 176
  14.307 -  }
  14.308 -}
  14.309  function java_lang_String_matchesZLjava_lang_String(arg0,arg1) {
  14.310    var arg2;
  14.311  ;
  14.312 @@ -1530,24 +1390,6 @@
  14.313      case 5: return stack.pop(); // 172
  14.314    }
  14.315  }
  14.316 -function java_lang_String_containsZLjava_lang_CharSequence(arg0,arg1) {
  14.317 -  var arg2;
  14.318 -;
  14.319 -  var stack = new Array(2);
  14.320 -  var gt = 0;
  14.321 -  for(;;) switch(gt) {
  14.322 -    case 0: stack.push(arg0); // 42
  14.323 -    case 1: stack.push(arg1); // 43
  14.324 -    case 2: { var self = stack.pop(); stack.push(self.toStringLjava_lang_String(self)); } // 182 1 132
  14.325 -    case 5: { var v0 = stack.pop(); var self = stack.pop(); stack.push(self.indexOfILjava_lang_String(self, v0)); } // 182 1 149
  14.326 -    case 8:  // 2
  14.327 -    case 9: if (stack.pop() >= stack.pop()) { gt = 16; continue; } // 164 0 7
  14.328 -    case 12: stack.push(1); // 4
  14.329 -    case 13: gt = 17; continue; // 167 0 4
  14.330 -    case 16: stack.push(0); // 3
  14.331 -    case 17: return stack.pop(); // 172
  14.332 -  }
  14.333 -}
  14.334  function java_lang_String_replaceFirstLjava_lang_StringLjava_lang_StringLjava_lang_String(arg0,arg1,arg2) {
  14.335    var arg3;
  14.336  ;
  14.337 @@ -2228,29 +2070,10 @@
  14.338  function java_lang_String_toStringLjava_lang_String(arg0) {
  14.339      return arg0.toString();
  14.340  }
  14.341 +function java_lang_String_toCharArrayAC(arg0) {
  14.342 +    return arg0.toString().split('');
  14.343 +}
  14.344  /*
  14.345 -function java_lang_String_toCharArrayAC(arg0) {
  14.346 -  var arg1;
  14.347 -  var arg2;
  14.348 -;
  14.349 -  var stack = new Array(5);
  14.350 -  var gt = 0;
  14.351 -  for(;;) switch(gt) {
  14.352 -    case 0: stack.push(arg0); // 42
  14.353 -    case 1: stack.push(stack.pop().count); // 180 1 97
  14.354 -    case 4: stack.push(new Array(stack.pop())); // 188 5
  14.355 -    case 6: arg1 = stack.pop(); // 76
  14.356 -    case 7: stack.push(arg0); // 42
  14.357 -    case 8: stack.push(0); // 3
  14.358 -    case 9: stack.push(arg0); // 42
  14.359 -    case 10: stack.push(stack.pop().count); // 180 1 97
  14.360 -    case 13: stack.push(arg1); // 43
  14.361 -    case 14: stack.push(0); // 3
  14.362 -    case 15: { var v3 = stack.pop(); var v2 = stack.pop(); var v1 = stack.pop(); var v0 = stack.pop(); var self = stack.pop(); self.getCharsVIIACAI(self, v0, v1, v2, v3); } // 182 1 138
  14.363 -    case 18: stack.push(arg1); // 43
  14.364 -    case 19: return stack.pop(); // 176
  14.365 -  }
  14.366 -}
  14.367  function java_lang_String_formatLjava_lang_StringLjava_lang_StringLjava_lang_Object(arg0,arg1) {
  14.368    var stack = new Array();
  14.369    var gt = 0;
  14.370 @@ -2375,16 +2198,6 @@
  14.371      case 18: return stack.pop(); // 176
  14.372    }
  14.373  }
  14.374 -function java_lang_String_valueOfLjava_lang_StringI(arg0) {
  14.375 -  var stack = new Array();
  14.376 -  var gt = 0;
  14.377 -  for(;;) switch(gt) {
  14.378 -    case 0: stack.push(arg0); // 26
  14.379 -    case 1: stack.push(10); // 16 10
  14.380 -    case 3: { var v1 = stack.pop(); var v0 = stack.pop(); stack.push(java_lang_Integer_toStringLjava_lang_StringII(v0, v1)); } // 184 1 125
  14.381 -    case 6: return stack.pop(); // 176
  14.382 -  }
  14.383 -}
  14.384  function java_lang_String_valueOfLjava_lang_StringJ(arg0) {
  14.385    var arg1;
  14.386    var stack = new Array();
  14.387 @@ -2471,10 +2284,21 @@
  14.388  String.prototype.lengthI = java_lang_String_lengthI;
  14.389  String.prototype.isEmptyZ = java_lang_String_isEmptyZ;
  14.390  String.prototype.getCharsVIIACI = java_lang_String_getCharsVIIACAI;
  14.391 +String.prototype.getCharsVACI = java_lang_String_getCharsVACI;
  14.392  String.prototype.toStringLjava_lang_String = java_lang_String_toStringLjava_lang_String;
  14.393  String.prototype.substringLjava_lang_StringI = java_lang_String_substringLjava_lang_StringI;
  14.394  String.prototype.substringLjava_lang_StringII = java_lang_String_substringLjava_lang_StringII;
  14.395 +String.prototype.replaceLjava_lang_StringCC = java_lang_String_replaceLjava_lang_StringCC;
  14.396 +String.prototype.containsZLjava_lang_CharSequence = java_lang_String_containsZLjava_lang_CharSequence;
  14.397  String.prototype.equalsZLjava_lang_Object = java_lang_String_equalsZLjava_lang_Object;
  14.398 +String.prototype.toCharArrayAC = java_lang_String_toCharArrayAC;
  14.399 +String.prototype.valueOfLjava_lang_StringI=java_lang_String_valueOfLjava_lang_StringI;
  14.400 +String.prototype.startsWithZLjava_lang_StringI = java_lang_String_startsWithZLjava_lang_StringI;
  14.401 +String.prototype.startsWithZLjava_lang_String=java_lang_String_startsWithZLjava_lang_String;
  14.402 +String.prototype.endsWithZLjava_lang_String=java_lang_String_endsWithZLjava_lang_String;
  14.403 +String.prototype.indexOfII=java_lang_String_indexOfII;
  14.404 +String.prototype.indexOfIII=java_lang_String_indexOfIII;
  14.405 +
  14.406  String.prototype.$instOf_java_lang_String = true;
  14.407  String.prototype.$instOf_java_io_Serializable = true;
  14.408  String.prototype.$instOf_java_lang_Comparable = true;
  14.409 @@ -2532,7 +2356,6 @@
  14.410    this.toUpperCaseLjava_lang_String = java_lang_String_toUpperCaseLjava_lang_String;
  14.411    this.trimLjava_lang_String = java_lang_String_trimLjava_lang_String;
  14.412    this.toStringLjava_lang_String = java_lang_String_toStringLjava_lang_String;
  14.413 -  this.toCharArrayAC = java_lang_String_toCharArrayAC;
  14.414    this.internLjava_lang_String = java_lang_String_internLjava_lang_String;
  14.415    this.compareToILjava_lang_Object = java_lang_String_compareToILjava_lang_Object;
  14.416   */
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/javap/pom.xml	Sun Nov 18 22:03:15 2012 +0100
    15.3 @@ -0,0 +1,41 @@
    15.4 +<?xml version="1.0"?>
    15.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    15.6 +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    15.7 +  <modelVersion>4.0.0</modelVersion>
    15.8 +  <parent>
    15.9 +    <groupId>org.apidesign</groupId>
   15.10 +    <artifactId>bck2brwsr</artifactId>
   15.11 +    <version>1.0-SNAPSHOT</version>
   15.12 +  </parent>
   15.13 +  <groupId>org.apidesign.bck2brwsr</groupId>
   15.14 +  <artifactId>javap</artifactId>
   15.15 +  <version>1.0-SNAPSHOT</version>
   15.16 +  <name>javap</name>
   15.17 +  <url>http://maven.apache.org</url>
   15.18 +  <properties>
   15.19 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   15.20 +  </properties>
   15.21 +  <build>
   15.22 +      <plugins>
   15.23 +          <plugin>
   15.24 +              <groupId>org.apache.maven.plugins</groupId>
   15.25 +              <artifactId>maven-compiler-plugin</artifactId>
   15.26 +              <version>2.5.1</version>
   15.27 +              <configuration>
   15.28 +                  <compilerArguments>
   15.29 +                      <!--<bootclasspath>non-existing</bootclasspath>-->
   15.30 +                  </compilerArguments>
   15.31 +                 <source>1.6</source>
   15.32 +                 <target>1.6</target>
   15.33 +              </configuration>
   15.34 +          </plugin>
   15.35 +      </plugins>
   15.36 +  </build>
   15.37 +  <dependencies>
   15.38 +    <dependency>
   15.39 +      <groupId>org.apidesign.bck2brwsr</groupId>
   15.40 +      <artifactId>emul</artifactId>
   15.41 +      <version>1.0-SNAPSHOT</version>
   15.42 +    </dependency>
   15.43 +  </dependencies>
   15.44 +</project>
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/javap/src/main/java/org/apidesign/javap/AnnotationParser.java	Sun Nov 18 22:03:15 2012 +0100
    16.3 @@ -0,0 +1,98 @@
    16.4 +/*
    16.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
    16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    16.7 + *
    16.8 + * This code is free software; you can redistribute it and/or modify it
    16.9 + * under the terms of the GNU General Public License version 2 only, as
   16.10 + * published by the Free Software Foundation.  Oracle designates this
   16.11 + * particular file as subject to the "Classpath" exception as provided
   16.12 + * by Oracle in the LICENSE file that accompanied this code.
   16.13 + *
   16.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   16.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   16.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   16.17 + * version 2 for more details (a copy is included in the LICENSE file that
   16.18 + * accompanied this code).
   16.19 + *
   16.20 + * You should have received a copy of the GNU General Public License version
   16.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   16.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   16.23 + *
   16.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   16.25 + * or visit www.oracle.com if you need additional information or have any
   16.26 + * questions.
   16.27 + */
   16.28 +package org.apidesign.javap;
   16.29 +
   16.30 +import java.io.ByteArrayInputStream;
   16.31 +import java.io.DataInputStream;
   16.32 +import java.io.IOException;
   16.33 +
   16.34 +/** An abstract parser for annotation definitions. Analyses the bytes and
   16.35 + * performs some callbacks to the overriden parser methods.
   16.36 + *
   16.37 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   16.38 + */
   16.39 +public class AnnotationParser {
   16.40 +    protected AnnotationParser() {
   16.41 +    }
   16.42 +
   16.43 +    protected void visitAttr(String type, String attr, String value) {
   16.44 +    }
   16.45 +    
   16.46 +    /** Initialize the parsing with constant pool from <code>cd</code>.
   16.47 +     * 
   16.48 +     * @param attr the attribute defining annotations
   16.49 +     * @param cd constant pool
   16.50 +     * @throws IOException in case I/O fails
   16.51 +     */
   16.52 +    public final void parse(byte[] attr, ClassData cd) throws IOException {
   16.53 +        ByteArrayInputStream is = new ByteArrayInputStream(attr);
   16.54 +        DataInputStream dis = new DataInputStream(is);
   16.55 +        try {
   16.56 +            read(dis, cd);
   16.57 +        } finally {
   16.58 +            is.close();
   16.59 +        }
   16.60 +    }
   16.61 +    
   16.62 +    private void read(DataInputStream dis, ClassData cd) throws IOException {
   16.63 +    	int cnt = dis.readUnsignedShort();
   16.64 +        for (int i = 0; i < cnt; i++) {
   16.65 +            readAnno(dis, cd);
   16.66 +        }
   16.67 +    }
   16.68 +
   16.69 +    private void readAnno(DataInputStream dis, ClassData cd) throws IOException {
   16.70 +        int type = dis.readUnsignedShort();
   16.71 +        String typeName = cd.StringValue(type);
   16.72 +    	int cnt = dis.readUnsignedShort();
   16.73 +    	for (int i = 0; i < cnt; i++) {
   16.74 +            String attrName = cd.StringValue(dis.readUnsignedShort());
   16.75 +            readValue(dis, cd, typeName, attrName);
   16.76 +        }
   16.77 +    }
   16.78 +
   16.79 +    private void readValue(DataInputStream dis, ClassData cd, String typeName, String attrName) 
   16.80 +    throws IOException {
   16.81 +        char type = (char)dis.readByte();
   16.82 +        if (type == '@') {
   16.83 +            readAnno(dis, cd);
   16.84 +        } else if ("CFJZsSIDB".indexOf(type) >= 0) { // NOI18N
   16.85 +            int primitive = dis.readUnsignedShort();
   16.86 +            visitAttr(typeName, attrName, cd.StringValue(primitive));
   16.87 +        } else if (type == 'c') {
   16.88 +            int cls = dis.readUnsignedShort();
   16.89 +        } else if (type == '[') {
   16.90 +            int cnt = dis.readUnsignedShort();
   16.91 +            for (int i = 0; i < cnt; i++) {
   16.92 +                readValue(dis, cd, typeName, attrName);
   16.93 +            }
   16.94 +        } else if (type == 'e') {
   16.95 +            int enumT = dis.readUnsignedShort();
   16.96 +            int enumN = dis.readUnsignedShort();
   16.97 +        } else {
   16.98 +            throw new IOException("Unknown type " + type);
   16.99 +        }
  16.100 +    }
  16.101 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/javap/src/main/java/org/apidesign/javap/AttrData.java	Sun Nov 18 22:03:15 2012 +0100
    17.3 @@ -0,0 +1,77 @@
    17.4 +/*
    17.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
    17.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    17.7 + *
    17.8 + * This code is free software; you can redistribute it and/or modify it
    17.9 + * under the terms of the GNU General Public License version 2 only, as
   17.10 + * published by the Free Software Foundation.  Oracle designates this
   17.11 + * particular file as subject to the "Classpath" exception as provided
   17.12 + * by Oracle in the LICENSE file that accompanied this code.
   17.13 + *
   17.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   17.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   17.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   17.17 + * version 2 for more details (a copy is included in the LICENSE file that
   17.18 + * accompanied this code).
   17.19 + *
   17.20 + * You should have received a copy of the GNU General Public License version
   17.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   17.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   17.23 + *
   17.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   17.25 + * or visit www.oracle.com if you need additional information or have any
   17.26 + * questions.
   17.27 + */
   17.28 +
   17.29 +
   17.30 +
   17.31 +package org.apidesign.javap;
   17.32 +
   17.33 +import java.io.*;
   17.34 +
   17.35 +/**
   17.36 + * Reads and stores attribute information.
   17.37 + *
   17.38 + * @author  Sucheta Dambalkar (Adopted code from jdis)
   17.39 + */
   17.40 +class AttrData {
   17.41 +    ClassData cls;
   17.42 +    int name_cpx;
   17.43 +    int datalen;
   17.44 +    byte data[];
   17.45 +
   17.46 +    public AttrData (ClassData cls) {
   17.47 +        this.cls=cls;
   17.48 +    }
   17.49 +
   17.50 +    /**
   17.51 +     * Reads unknown attribute.
   17.52 +     */
   17.53 +    public void read(int name_cpx, DataInputStream in) throws IOException {
   17.54 +        this.name_cpx=name_cpx;
   17.55 +        datalen=in.readInt();
   17.56 +        data=new byte[datalen];
   17.57 +        in.readFully(data);
   17.58 +    }
   17.59 +
   17.60 +    /**
   17.61 +     * Reads just the name of known attribute.
   17.62 +     */
   17.63 +    public void read(int name_cpx){
   17.64 +        this.name_cpx=name_cpx;
   17.65 +    }
   17.66 +
   17.67 +    /**
   17.68 +     * Returns attribute name.
   17.69 +     */
   17.70 +    public String getAttrName(){
   17.71 +        return cls.getString(name_cpx);
   17.72 +    }
   17.73 +
   17.74 +    /**
   17.75 +     * Returns attribute data.
   17.76 +     */
   17.77 +    public byte[] getData(){
   17.78 +        return data;
   17.79 +    }
   17.80 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/javap/src/main/java/org/apidesign/javap/CPX.java	Sun Nov 18 22:03:15 2012 +0100
    18.3 @@ -0,0 +1,40 @@
    18.4 +/*
    18.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
    18.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    18.7 + *
    18.8 + * This code is free software; you can redistribute it and/or modify it
    18.9 + * under the terms of the GNU General Public License version 2 only, as
   18.10 + * published by the Free Software Foundation.  Oracle designates this
   18.11 + * particular file as subject to the "Classpath" exception as provided
   18.12 + * by Oracle in the LICENSE file that accompanied this code.
   18.13 + *
   18.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   18.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   18.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   18.17 + * version 2 for more details (a copy is included in the LICENSE file that
   18.18 + * accompanied this code).
   18.19 + *
   18.20 + * You should have received a copy of the GNU General Public License version
   18.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   18.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   18.23 + *
   18.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   18.25 + * or visit www.oracle.com if you need additional information or have any
   18.26 + * questions.
   18.27 + */
   18.28 +
   18.29 +
   18.30 +package org.apidesign.javap;
   18.31 +
   18.32 +/**
   18.33 + * Stores constant pool entry information with one field.
   18.34 + *
   18.35 + * @author  Sucheta Dambalkar (Adopted code from jdis)
   18.36 + */
   18.37 +class CPX {
   18.38 +    int cpx;
   18.39 +
   18.40 +    CPX (int cpx) {
   18.41 +        this.cpx=cpx;
   18.42 +    }
   18.43 +}
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/javap/src/main/java/org/apidesign/javap/CPX2.java	Sun Nov 18 22:03:15 2012 +0100
    19.3 @@ -0,0 +1,41 @@
    19.4 +/*
    19.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
    19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    19.7 + *
    19.8 + * This code is free software; you can redistribute it and/or modify it
    19.9 + * under the terms of the GNU General Public License version 2 only, as
   19.10 + * published by the Free Software Foundation.  Oracle designates this
   19.11 + * particular file as subject to the "Classpath" exception as provided
   19.12 + * by Oracle in the LICENSE file that accompanied this code.
   19.13 + *
   19.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   19.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   19.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   19.17 + * version 2 for more details (a copy is included in the LICENSE file that
   19.18 + * accompanied this code).
   19.19 + *
   19.20 + * You should have received a copy of the GNU General Public License version
   19.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   19.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   19.23 + *
   19.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   19.25 + * or visit www.oracle.com if you need additional information or have any
   19.26 + * questions.
   19.27 + */
   19.28 +
   19.29 +
   19.30 +package org.apidesign.javap;
   19.31 +
   19.32 +/**
   19.33 + *  Stores constant pool entry information with two fields.
   19.34 + *
   19.35 + * @author  Sucheta Dambalkar (Adopted code from jdis)
   19.36 + */
   19.37 +class CPX2 {
   19.38 +    int cpx1,cpx2;
   19.39 +
   19.40 +    CPX2 (int cpx1, int cpx2) {
   19.41 +        this.cpx1=cpx1;
   19.42 +        this.cpx2=cpx2;
   19.43 +    }
   19.44 +}
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/javap/src/main/java/org/apidesign/javap/ClassData.java	Sun Nov 18 22:03:15 2012 +0100
    20.3 @@ -0,0 +1,699 @@
    20.4 +/*
    20.5 + * Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
    20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    20.7 + *
    20.8 + * This code is free software; you can redistribute it and/or modify it
    20.9 + * under the terms of the GNU General Public License version 2 only, as
   20.10 + * published by the Free Software Foundation.  Oracle designates this
   20.11 + * particular file as subject to the "Classpath" exception as provided
   20.12 + * by Oracle in the LICENSE file that accompanied this code.
   20.13 + *
   20.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   20.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   20.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   20.17 + * version 2 for more details (a copy is included in the LICENSE file that
   20.18 + * accompanied this code).
   20.19 + *
   20.20 + * You should have received a copy of the GNU General Public License version
   20.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   20.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20.23 + *
   20.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   20.25 + * or visit www.oracle.com if you need additional information or have any
   20.26 + * questions.
   20.27 + */
   20.28 +
   20.29 +
   20.30 +package org.apidesign.javap;
   20.31 +
   20.32 +import java.io.*;
   20.33 +
   20.34 +/**
   20.35 + * Central data repository of the Java Disassembler.
   20.36 + * Stores all the information in java class file.
   20.37 + *
   20.38 + * @author  Sucheta Dambalkar (Adopted code from jdis)
   20.39 + */
   20.40 +public final class ClassData implements RuntimeConstants {
   20.41 +
   20.42 +    private int magic;
   20.43 +    private int minor_version;
   20.44 +    private int major_version;
   20.45 +    private int cpool_count;
   20.46 +    private Object cpool[];
   20.47 +    private int access;
   20.48 +    private int this_class = 0;;
   20.49 +    private int super_class;
   20.50 +    private int interfaces_count;
   20.51 +    private int[] interfaces = new int[0];;
   20.52 +    private int fields_count;
   20.53 +    private FieldData[] fields;
   20.54 +    private int methods_count;
   20.55 +    private MethodData[] methods;
   20.56 +    private InnerClassData[] innerClasses;
   20.57 +    private int attributes_count;
   20.58 +    private AttrData[] attrs;
   20.59 +    private String classname;
   20.60 +    private String superclassname;
   20.61 +    private int source_cpx=0;
   20.62 +    private byte tags[];
   20.63 +    private Hashtable indexHashAscii = new Hashtable();
   20.64 +    private String pkgPrefix="";
   20.65 +    private int pkgPrefixLen=0;
   20.66 +
   20.67 +    /**
   20.68 +     * Read classfile to disassemble.
   20.69 +     */
   20.70 +    public ClassData(InputStream infile) throws IOException {
   20.71 +        this.read(new DataInputStream(infile));
   20.72 +    }
   20.73 +
   20.74 +    /**
   20.75 +     * Reads and stores class file information.
   20.76 +     */
   20.77 +    public void read(DataInputStream in) throws IOException {
   20.78 +        // Read the header
   20.79 +        magic = in.readInt();
   20.80 +        if (magic != JAVA_MAGIC) {
   20.81 +            throw new ClassFormatError("wrong magic: " +
   20.82 +                                       toHex(magic) + ", expected " +
   20.83 +                                       toHex(JAVA_MAGIC));
   20.84 +        }
   20.85 +        minor_version = in.readShort();
   20.86 +        major_version = in.readShort();
   20.87 +        if (major_version != JAVA_VERSION) {
   20.88 +        }
   20.89 +
   20.90 +        // Read the constant pool
   20.91 +        readCP(in);
   20.92 +        access = in.readUnsignedShort();
   20.93 +        this_class = in.readUnsignedShort();
   20.94 +        super_class = in.readUnsignedShort();
   20.95 +
   20.96 +        //Read interfaces.
   20.97 +        interfaces_count = in.readUnsignedShort();
   20.98 +        if(interfaces_count > 0){
   20.99 +            interfaces = new int[interfaces_count];
  20.100 +        }
  20.101 +        for (int i = 0; i < interfaces_count; i++) {
  20.102 +            interfaces[i]=in.readShort();
  20.103 +        }
  20.104 +
  20.105 +        // Read the fields
  20.106 +        readFields(in);
  20.107 +
  20.108 +        // Read the methods
  20.109 +        readMethods(in);
  20.110 +
  20.111 +        // Read the attributes
  20.112 +        attributes_count = in.readUnsignedShort();
  20.113 +        attrs=new AttrData[attributes_count];
  20.114 +        for (int k = 0; k < attributes_count; k++) {
  20.115 +            int name_cpx=in.readUnsignedShort();
  20.116 +            if (getTag(name_cpx)==CONSTANT_UTF8
  20.117 +                && getString(name_cpx).equals("SourceFile")
  20.118 +                ){      if (in.readInt()!=2)
  20.119 +                    throw new ClassFormatError("invalid attr length");
  20.120 +                source_cpx=in.readUnsignedShort();
  20.121 +                AttrData attr=new AttrData(this);
  20.122 +                attr.read(name_cpx);
  20.123 +                attrs[k]=attr;
  20.124 +
  20.125 +            } else if (getTag(name_cpx)==CONSTANT_UTF8
  20.126 +                       && getString(name_cpx).equals("InnerClasses")
  20.127 +                       ){       int length=in.readInt();
  20.128 +                       int num=in.readUnsignedShort();
  20.129 +                       if (2+num*8 != length)
  20.130 +                           throw new ClassFormatError("invalid attr length");
  20.131 +                       innerClasses=new InnerClassData[num];
  20.132 +                       for (int j = 0; j < num; j++) {
  20.133 +                           InnerClassData innerClass=new InnerClassData(this);
  20.134 +                           innerClass.read(in);
  20.135 +                           innerClasses[j]=innerClass;
  20.136 +                       }
  20.137 +                       AttrData attr=new AttrData(this);
  20.138 +                       attr.read(name_cpx);
  20.139 +                       attrs[k]=attr;
  20.140 +            } else {
  20.141 +                AttrData attr=new AttrData(this);
  20.142 +                attr.read(name_cpx, in);
  20.143 +                attrs[k]=attr;
  20.144 +            }
  20.145 +        }
  20.146 +        in.close();
  20.147 +    } // end ClassData.read()
  20.148 +
  20.149 +    /**
  20.150 +     * Reads and stores constant pool info.
  20.151 +     */
  20.152 +    void readCP(DataInputStream in) throws IOException {
  20.153 +        cpool_count = in.readUnsignedShort();
  20.154 +        tags = new byte[cpool_count];
  20.155 +        cpool = new Object[cpool_count];
  20.156 +        for (int i = 1; i < cpool_count; i++) {
  20.157 +            byte tag = in.readByte();
  20.158 +
  20.159 +            switch(tags[i] = tag) {
  20.160 +            case CONSTANT_UTF8:
  20.161 +                String str=in.readUTF();
  20.162 +                indexHashAscii.put(cpool[i] = str, new Integer(i));
  20.163 +                break;
  20.164 +            case CONSTANT_INTEGER:
  20.165 +                cpool[i] = new Integer(in.readInt());
  20.166 +                break;
  20.167 +            case CONSTANT_FLOAT:
  20.168 +                cpool[i] = new Float(in.readFloat());
  20.169 +                break;
  20.170 +            case CONSTANT_LONG:
  20.171 +                cpool[i++] = new Long(in.readLong());
  20.172 +                break;
  20.173 +            case CONSTANT_DOUBLE:
  20.174 +                cpool[i++] = new Double(in.readDouble());
  20.175 +                break;
  20.176 +            case CONSTANT_CLASS:
  20.177 +            case CONSTANT_STRING:
  20.178 +                cpool[i] = new CPX(in.readUnsignedShort());
  20.179 +                break;
  20.180 +
  20.181 +            case CONSTANT_FIELD:
  20.182 +            case CONSTANT_METHOD:
  20.183 +            case CONSTANT_INTERFACEMETHOD:
  20.184 +            case CONSTANT_NAMEANDTYPE:
  20.185 +                cpool[i] = new CPX2(in.readUnsignedShort(), in.readUnsignedShort());
  20.186 +                break;
  20.187 +
  20.188 +            case 0:
  20.189 +            default:
  20.190 +                throw new ClassFormatError("invalid constant type: " + (int)tags[i]);
  20.191 +            }
  20.192 +        }
  20.193 +    }
  20.194 +
  20.195 +    /**
  20.196 +     * Reads and strores field info.
  20.197 +     */
  20.198 +    protected void readFields(DataInputStream in) throws IOException {
  20.199 +        int fields_count = in.readUnsignedShort();
  20.200 +        fields=new FieldData[fields_count];
  20.201 +        for (int k = 0; k < fields_count; k++) {
  20.202 +            FieldData field=new FieldData(this);
  20.203 +            field.read(in);
  20.204 +            fields[k]=field;
  20.205 +        }
  20.206 +    }
  20.207 +
  20.208 +    /**
  20.209 +     * Reads and strores Method info.
  20.210 +     */
  20.211 +    protected void readMethods(DataInputStream in) throws IOException {
  20.212 +        int methods_count = in.readUnsignedShort();
  20.213 +        methods=new MethodData[methods_count];
  20.214 +        for (int k = 0; k < methods_count ; k++) {
  20.215 +            MethodData method=new MethodData(this);
  20.216 +            method.read(in);
  20.217 +            methods[k]=method;
  20.218 +        }
  20.219 +    }
  20.220 +
  20.221 +    /**
  20.222 +     * get a string
  20.223 +     */
  20.224 +    public String getString(int n) {
  20.225 +        if (n == 0) {
  20.226 +            return null; 
  20.227 +        } else {
  20.228 +            return (String)cpool[n];
  20.229 +        }
  20.230 +    }
  20.231 +
  20.232 +    /**
  20.233 +     * get the type of constant given an index
  20.234 +     */
  20.235 +    public byte getTag(int n) {
  20.236 +        try{
  20.237 +            return tags[n];
  20.238 +        } catch (ArrayIndexOutOfBoundsException e) {
  20.239 +            return (byte)100;
  20.240 +        }
  20.241 +    }
  20.242 +
  20.243 +    static final String hexString="0123456789ABCDEF";
  20.244 +
  20.245 +    public static char hexTable[]=hexString.toCharArray();
  20.246 +
  20.247 +    static String toHex(long val, int width) {
  20.248 +        StringBuffer s = new StringBuffer();
  20.249 +        for (int i=width-1; i>=0; i--)
  20.250 +            s.append(hexTable[((int)(val>>(4*i)))&0xF]);
  20.251 +        return "0x"+s.toString();
  20.252 +    }
  20.253 +
  20.254 +    static String toHex(long val) {
  20.255 +        int width;
  20.256 +        for (width=16; width>0; width--) {
  20.257 +            if ((val>>(width-1)*4)!=0) break;
  20.258 +        }
  20.259 +        return toHex(val, width);
  20.260 +    }
  20.261 +
  20.262 +    static String toHex(int val) {
  20.263 +        int width;
  20.264 +        for (width=8; width>0; width--) {
  20.265 +            if ((val>>(width-1)*4)!=0) break;
  20.266 +        }
  20.267 +        return toHex(val, width);
  20.268 +    }
  20.269 +
  20.270 +    /**
  20.271 +     * Returns the name of this class.
  20.272 +     */
  20.273 +    public String getClassName() {
  20.274 +        String res=null;
  20.275 +        if (this_class==0) {
  20.276 +            return res;
  20.277 +        }
  20.278 +        int tcpx;
  20.279 +        try {
  20.280 +            if (tags[this_class]!=CONSTANT_CLASS) {
  20.281 +                return res; //"<CP["+cpx+"] is not a Class> ";
  20.282 +            }
  20.283 +            tcpx=((CPX)cpool[this_class]).cpx;
  20.284 +        } catch (ArrayIndexOutOfBoundsException e) {
  20.285 +            return res; // "#"+cpx+"// invalid constant pool index";
  20.286 +        } catch (Throwable e) {
  20.287 +            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
  20.288 +        }
  20.289 +
  20.290 +        try {
  20.291 +            return (String)(cpool[tcpx]);
  20.292 +        } catch (ArrayIndexOutOfBoundsException e) {
  20.293 +            return  res; // "class #"+scpx+"// invalid constant pool index";
  20.294 +        } catch (ClassCastException e) {
  20.295 +            return  res; // "class #"+scpx+"// invalid constant pool reference";
  20.296 +        } catch (Throwable e) {
  20.297 +            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
  20.298 +        }
  20.299 +
  20.300 +    }
  20.301 +
  20.302 +    /**
  20.303 +     * Returns the name of class at perticular index.
  20.304 +     */
  20.305 +    public String getClassName(int cpx) {
  20.306 +        String res="#"+cpx;
  20.307 +        if (cpx==0) {
  20.308 +            return res;
  20.309 +        }
  20.310 +        int scpx;
  20.311 +        try {
  20.312 +            if (tags[cpx]!=CONSTANT_CLASS) {
  20.313 +                return res; //"<CP["+cpx+"] is not a Class> ";
  20.314 +            }
  20.315 +            scpx=((CPX)cpool[cpx]).cpx;
  20.316 +        } catch (ArrayIndexOutOfBoundsException e) {
  20.317 +            return res; // "#"+cpx+"// invalid constant pool index";
  20.318 +        } catch (Throwable e) {
  20.319 +            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
  20.320 +        }
  20.321 +        res="#"+scpx;
  20.322 +        try {
  20.323 +            return (String)(cpool[scpx]);
  20.324 +        } catch (ArrayIndexOutOfBoundsException e) {
  20.325 +            return  res; // "class #"+scpx+"// invalid constant pool index";
  20.326 +        } catch (ClassCastException e) {
  20.327 +            return  res; // "class #"+scpx+"// invalid constant pool reference";
  20.328 +        } catch (Throwable e) {
  20.329 +            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
  20.330 +        }
  20.331 +    }
  20.332 +
  20.333 +    /**
  20.334 +     * Returns true if it is a class
  20.335 +     */
  20.336 +    public boolean isClass() {
  20.337 +        if((access & ACC_INTERFACE) == 0) return true;
  20.338 +        return false;
  20.339 +    }
  20.340 +
  20.341 +    /**
  20.342 +     * Returns true if it is a interface.
  20.343 +     */
  20.344 +    public boolean isInterface(){
  20.345 +        if((access & ACC_INTERFACE) != 0) return true;
  20.346 +        return false;
  20.347 +    }
  20.348 +
  20.349 +    /**
  20.350 +     * Returns true if this member is public, false otherwise.
  20.351 +     */
  20.352 +    public boolean isPublic(){
  20.353 +        return (access & ACC_PUBLIC) != 0;
  20.354 +    }
  20.355 +
  20.356 +    /**
  20.357 +     * Returns the access of this class or interface.
  20.358 +     */
  20.359 +    public String[] getAccess(){
  20.360 +        Vector v = new Vector();
  20.361 +        if ((access & ACC_PUBLIC)   !=0) v.addElement("public");
  20.362 +        if ((access & ACC_FINAL)    !=0) v.addElement("final");
  20.363 +        if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
  20.364 +        String[] accflags = new String[v.size()];
  20.365 +        v.copyInto(accflags);
  20.366 +        return accflags;
  20.367 +    }
  20.368 +
  20.369 +    /**
  20.370 +     * Returns list of innerclasses.
  20.371 +     */
  20.372 +    public InnerClassData[] getInnerClasses(){
  20.373 +        return innerClasses;
  20.374 +    }
  20.375 +
  20.376 +    /**
  20.377 +     * Returns list of attributes.
  20.378 +     */
  20.379 +    final AttrData[] getAttributes(){
  20.380 +        return attrs;
  20.381 +    }
  20.382 +    
  20.383 +    public byte[] findAnnotationData(boolean classRetention) {
  20.384 +        String n = classRetention ?
  20.385 +            "RuntimeInvisibleAnnotations" : // NOI18N
  20.386 +            "RuntimeVisibleAnnotations"; // NOI18N
  20.387 +        return findAttr(n, attrs);
  20.388 +    }
  20.389 +
  20.390 +    /**
  20.391 +     * Returns true if superbit is set.
  20.392 +     */
  20.393 +    public boolean isSuperSet(){
  20.394 +        if ((access & ACC_SUPER)   !=0) return true;
  20.395 +        return false;
  20.396 +    }
  20.397 +
  20.398 +    /**
  20.399 +     * Returns super class name.
  20.400 +     */
  20.401 +    public String getSuperClassName(){
  20.402 +        String res=null;
  20.403 +        if (super_class==0) {
  20.404 +            return res;
  20.405 +        }
  20.406 +        int scpx;
  20.407 +        try {
  20.408 +            if (tags[super_class]!=CONSTANT_CLASS) {
  20.409 +                return res; //"<CP["+cpx+"] is not a Class> ";
  20.410 +            }
  20.411 +            scpx=((CPX)cpool[super_class]).cpx;
  20.412 +        } catch (ArrayIndexOutOfBoundsException e) {
  20.413 +            return res; // "#"+cpx+"// invalid constant pool index";
  20.414 +        } catch (Throwable e) {
  20.415 +            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
  20.416 +        }
  20.417 +
  20.418 +        try {
  20.419 +            return (String)(cpool[scpx]);
  20.420 +        } catch (ArrayIndexOutOfBoundsException e) {
  20.421 +            return  res; // "class #"+scpx+"// invalid constant pool index";
  20.422 +        } catch (ClassCastException e) {
  20.423 +            return  res; // "class #"+scpx+"// invalid constant pool reference";
  20.424 +        } catch (Throwable e) {
  20.425 +            return res; // "#"+cpx+"// ERROR IN DISASSEMBLER";
  20.426 +        }
  20.427 +    }
  20.428 +
  20.429 +    /**
  20.430 +     * Returns list of super interfaces.
  20.431 +     */
  20.432 +    public String[] getSuperInterfaces(){
  20.433 +        String interfacenames[] = new String[interfaces.length];
  20.434 +        int interfacecpx = -1;
  20.435 +        for(int i = 0; i < interfaces.length; i++){
  20.436 +            interfacecpx=((CPX)cpool[interfaces[i]]).cpx;
  20.437 +            interfacenames[i] = (String)(cpool[interfacecpx]);
  20.438 +        }
  20.439 +        return interfacenames;
  20.440 +    }
  20.441 +
  20.442 +    /**
  20.443 +     * Returns string at prticular constant pool index.
  20.444 +     */
  20.445 +    public String getStringValue(int cpoolx) {
  20.446 +        try {
  20.447 +            return ((String)cpool[cpoolx]);
  20.448 +        } catch (ArrayIndexOutOfBoundsException e) {
  20.449 +            return "//invalid constant pool index:"+cpoolx;
  20.450 +        } catch (ClassCastException e) {
  20.451 +            return "//invalid constant pool ref:"+cpoolx;
  20.452 +        }
  20.453 +    }
  20.454 +
  20.455 +    /**
  20.456 +     * Returns list of field info.
  20.457 +     */
  20.458 +    public  FieldData[] getFields(){
  20.459 +        return fields;
  20.460 +    }
  20.461 +
  20.462 +    /**
  20.463 +     * Returns list of method info.
  20.464 +     */
  20.465 +    public  MethodData[] getMethods(){
  20.466 +        return methods;
  20.467 +    }
  20.468 +
  20.469 +    /**
  20.470 +     * Returns constant pool entry at that index.
  20.471 +     */
  20.472 +    public CPX2 getCpoolEntry(int cpx){
  20.473 +        return ((CPX2)(cpool[cpx]));
  20.474 +    }
  20.475 +
  20.476 +    public Object getCpoolEntryobj(int cpx){
  20.477 +        return (cpool[cpx]);
  20.478 +    }
  20.479 +
  20.480 +    /**
  20.481 +     * Returns index of this class.
  20.482 +     */
  20.483 +    public int getthis_cpx(){
  20.484 +        return this_class;
  20.485 +    }
  20.486 +
  20.487 +    /**
  20.488 +     * Returns string at that index.
  20.489 +     */
  20.490 +    public String StringValue(int cpx) {
  20.491 +        return stringValue(cpx, false);
  20.492 +    }
  20.493 +    public String stringValue(int cpx, boolean textual) {
  20.494 +        if (cpx==0) return "#0";
  20.495 +        int tag;
  20.496 +        Object x;
  20.497 +        String suffix="";
  20.498 +        try {
  20.499 +            tag=tags[cpx];
  20.500 +            x=cpool[cpx];
  20.501 +        } catch (IndexOutOfBoundsException e) {
  20.502 +            return "<Incorrect CP index:"+cpx+">";
  20.503 +        }
  20.504 +
  20.505 +        if (x==null) return "<NULL>";
  20.506 +        switch (tag) {
  20.507 +        case CONSTANT_UTF8: {
  20.508 +            if (!textual) {
  20.509 +                return (String)x;
  20.510 +            }
  20.511 +            StringBuilder sb=new StringBuilder();
  20.512 +            String s=(String)x;
  20.513 +            for (int k=0; k<s.length(); k++) {
  20.514 +                char c=s.charAt(k);
  20.515 +                switch (c) {
  20.516 +                case '\\': sb.append('\\').append('\\'); break;
  20.517 +                case '\t': sb.append('\\').append('t'); break;
  20.518 +                case '\n': sb.append('\\').append('n'); break;
  20.519 +                case '\r': sb.append('\\').append('r'); break;
  20.520 +                case '\"': sb.append('\\').append('\"'); break;
  20.521 +                default: sb.append(c);
  20.522 +                }
  20.523 +            }
  20.524 +            return sb.toString();
  20.525 +        }
  20.526 +        case CONSTANT_DOUBLE: {
  20.527 +            Double d=(Double)x;
  20.528 +            String sd=d.toString();
  20.529 +            if (textual) {
  20.530 +                return sd;
  20.531 +            }
  20.532 +            return sd+"d";
  20.533 +        }
  20.534 +        case CONSTANT_FLOAT: {
  20.535 +            Float f=(Float)x;
  20.536 +            String sf=(f).toString();
  20.537 +            if (textual) {
  20.538 +                return sf;
  20.539 +            }
  20.540 +            return sf+"f";
  20.541 +        }
  20.542 +        case CONSTANT_LONG: {
  20.543 +            Long ln = (Long)x;
  20.544 +            if (textual) {
  20.545 +                return ln.toString();
  20.546 +            }
  20.547 +            return ln.toString()+'l';
  20.548 +        }
  20.549 +        case CONSTANT_INTEGER: {
  20.550 +            Integer in = (Integer)x;
  20.551 +            return in.toString();
  20.552 +        }
  20.553 +        case CONSTANT_CLASS:
  20.554 +            if (textual) {
  20.555 +                return "new java_lang_Class"; // XXX temporary JS
  20.556 +            }
  20.557 +            return javaName(getClassName(cpx));
  20.558 +        case CONSTANT_STRING:
  20.559 +            String sv = stringValue(((CPX)x).cpx, textual);
  20.560 +            if (textual) {
  20.561 +                return '"' + sv + '"';
  20.562 +            } else {
  20.563 +                return sv;
  20.564 +            }
  20.565 +        case CONSTANT_FIELD:
  20.566 +        case CONSTANT_METHOD:
  20.567 +        case CONSTANT_INTERFACEMETHOD:
  20.568 +            //return getShortClassName(((CPX2)x).cpx1)+"."+StringValue(((CPX2)x).cpx2);
  20.569 +             return javaName(getClassName(((CPX2)x).cpx1))+"."+StringValue(((CPX2)x).cpx2);
  20.570 +
  20.571 +        case CONSTANT_NAMEANDTYPE:
  20.572 +            return getName(((CPX2)x).cpx1)+":"+StringValue(((CPX2)x).cpx2);
  20.573 +        default:
  20.574 +            return "UnknownTag"; //TBD
  20.575 +        }
  20.576 +    }
  20.577 +
  20.578 +    /**
  20.579 +     * Returns resolved java type name.
  20.580 +     */
  20.581 +    public String javaName(String name) {
  20.582 +        if( name==null) return "null";
  20.583 +        int len=name.length();
  20.584 +        if (len==0) return "\"\"";
  20.585 +        int cc='/';
  20.586 +    fullname: { // xxx/yyy/zzz
  20.587 +            int cp;
  20.588 +            for (int k=0; k<len; k += Character.charCount(cp)) {
  20.589 +                cp=name.codePointAt(k);
  20.590 +                if (cc=='/') {
  20.591 +                    if (!isJavaIdentifierStart(cp)) break fullname;
  20.592 +                } else if (cp!='/') {
  20.593 +                    if (!isJavaIdentifierPart(cp)) break fullname;
  20.594 +                }
  20.595 +                cc=cp;
  20.596 +            }
  20.597 +            return name;
  20.598 +        }
  20.599 +        return "\""+name+"\"";
  20.600 +    }
  20.601 +
  20.602 +    public String getName(int cpx) {
  20.603 +        String res;
  20.604 +        try {
  20.605 +            return javaName((String)cpool[cpx]); //.replace('/','.');
  20.606 +        } catch (ArrayIndexOutOfBoundsException e) {
  20.607 +            return "<invalid constant pool index:"+cpx+">";
  20.608 +        } catch (ClassCastException e) {
  20.609 +            return "<invalid constant pool ref:"+cpx+">";
  20.610 +        }
  20.611 +    }
  20.612 +
  20.613 +    /**
  20.614 +     * Returns unqualified class name.
  20.615 +     */
  20.616 +    public String getShortClassName(int cpx) {
  20.617 +        String classname=javaName(getClassName(cpx));
  20.618 +        pkgPrefixLen=classname.lastIndexOf("/")+1;
  20.619 +        if (pkgPrefixLen!=0) {
  20.620 +            pkgPrefix=classname.substring(0,pkgPrefixLen);
  20.621 +            if (classname.startsWith(pkgPrefix)) {
  20.622 +                return classname.substring(pkgPrefixLen);
  20.623 +            }
  20.624 +        }
  20.625 +        return classname;
  20.626 +    }
  20.627 +
  20.628 +    /**
  20.629 +     * Returns source file name.
  20.630 +     */
  20.631 +    public String getSourceName(){
  20.632 +        return getName(source_cpx);
  20.633 +    }
  20.634 +
  20.635 +    /**
  20.636 +     * Returns package name.
  20.637 +     */
  20.638 +    public String getPkgName(){
  20.639 +        String classname=getClassName(this_class);
  20.640 +        pkgPrefixLen=classname.lastIndexOf("/")+1;
  20.641 +        if (pkgPrefixLen!=0) {
  20.642 +            pkgPrefix=classname.substring(0,pkgPrefixLen);
  20.643 +            return("package  "+pkgPrefix.substring(0,pkgPrefixLen-1)+";\n");
  20.644 +        }else return null;
  20.645 +    }
  20.646 +
  20.647 +    /**
  20.648 +     * Returns total constant pool entry count.
  20.649 +     */
  20.650 +    public int getCpoolCount(){
  20.651 +        return cpool_count;
  20.652 +    }
  20.653 +
  20.654 +    /**
  20.655 +     * Returns minor version of class file.
  20.656 +     */
  20.657 +    public int getMinor_version(){
  20.658 +        return minor_version;
  20.659 +    }
  20.660 +
  20.661 +    /**
  20.662 +     * Returns major version of class file.
  20.663 +     */
  20.664 +    public int getMajor_version(){
  20.665 +        return major_version;
  20.666 +    }
  20.667 +
  20.668 +    private boolean isJavaIdentifierStart(int cp) {
  20.669 +        return ('a' <= cp && cp <= 'z') || ('A' <= cp && cp <= 'Z');
  20.670 +    }
  20.671 +
  20.672 +    private boolean isJavaIdentifierPart(int cp) {
  20.673 +        return isJavaIdentifierStart(cp) || ('0' <= cp && cp <= '9');
  20.674 +    }
  20.675 +
  20.676 +    public String[] getNameAndType(int indx) {
  20.677 +        return getNameAndType(indx, 0, new String[2]);
  20.678 +    }
  20.679 +    
  20.680 +    private String[] getNameAndType(int indx, int at, String[] arr) {
  20.681 +        CPX2 c2 = getCpoolEntry(indx);
  20.682 +        arr[at] = StringValue(c2.cpx1);
  20.683 +        arr[at + 1] = StringValue(c2.cpx2);
  20.684 +        return arr;
  20.685 +    }
  20.686 +
  20.687 +    public String[] getFieldInfoName(int indx) {
  20.688 +        CPX2 c2 = getCpoolEntry(indx);
  20.689 +        String[] arr = new String[3];
  20.690 +        arr[0] = getClassName(c2.cpx1);
  20.691 +        return getNameAndType(c2.cpx2, 1, arr);
  20.692 +    }
  20.693 +
  20.694 +    static byte[] findAttr(String n, AttrData[] attrs) {
  20.695 +        for (AttrData ad : attrs) {
  20.696 +            if (n.equals(ad.getAttrName())) {
  20.697 +                return ad.getData();
  20.698 +            }
  20.699 +        }
  20.700 +        return null;
  20.701 +    }
  20.702 +}
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/javap/src/main/java/org/apidesign/javap/Constants.java	Sun Nov 18 22:03:15 2012 +0100
    21.3 @@ -0,0 +1,372 @@
    21.4 +/*
    21.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
    21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    21.7 + *
    21.8 + * This code is free software; you can redistribute it and/or modify it
    21.9 + * under the terms of the GNU General Public License version 2 only, as
   21.10 + * published by the Free Software Foundation.  Oracle designates this
   21.11 + * particular file as subject to the "Classpath" exception as provided
   21.12 + * by Oracle in the LICENSE file that accompanied this code.
   21.13 + *
   21.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   21.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   21.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   21.17 + * version 2 for more details (a copy is included in the LICENSE file that
   21.18 + * accompanied this code).
   21.19 + *
   21.20 + * You should have received a copy of the GNU General Public License version
   21.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   21.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   21.23 + *
   21.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   21.25 + * or visit www.oracle.com if you need additional information or have any
   21.26 + * questions.
   21.27 + */
   21.28 +
   21.29 +
   21.30 +
   21.31 +package org.apidesign.javap;
   21.32 +
   21.33 +/**
   21.34 + * This interface defines constant that are used
   21.35 + * throughout the compiler. It inherits from RuntimeConstants,
   21.36 + * which is an autogenerated class that contains contstants
   21.37 + * defined in the interpreter.
   21.38 + */
   21.39 +
   21.40 +public
   21.41 +interface Constants extends RuntimeConstants {
   21.42 +
   21.43 +     /**
   21.44 +     * End of input
   21.45 +     */
   21.46 +    public static final int EOF = -1;
   21.47 +
   21.48 +   /*
   21.49 +     * Flags
   21.50 +     */
   21.51 +    public static final int F_VERBOSE           = 1 << 0;
   21.52 +    public static final int F_DUMP              = 1 << 1;
   21.53 +    public static final int F_WARNINGS          = 1 << 2;
   21.54 +    public static final int F_DEBUG             = 1 << 3;
   21.55 +    public static final int F_OPTIMIZE          = 1 << 4;
   21.56 +    public static final int F_DEPENDENCIES      = 1 << 5;
   21.57 +
   21.58 +    /*
   21.59 +     * Type codes
   21.60 +     */
   21.61 +    public static final int TC_BOOLEAN   = 0;
   21.62 +    public static final int TC_BYTE      = 1;
   21.63 +    public static final int TC_CHAR      = 2;
   21.64 +    public static final int TC_SHORT     = 3;
   21.65 +    public static final int TC_INT       = 4;
   21.66 +    public static final int TC_LONG      = 5;
   21.67 +    public static final int TC_FLOAT     = 6;
   21.68 +    public static final int TC_DOUBLE    = 7;
   21.69 +    public static final int TC_NULL      = 8;
   21.70 +    public static final int TC_ARRAY     = 9;
   21.71 +    public static final int TC_CLASS     = 10;
   21.72 +    public static final int TC_VOID      = 11;
   21.73 +    public static final int TC_METHOD    = 12;
   21.74 +    public static final int TC_ERROR     = 13;
   21.75 +
   21.76 +    /*
   21.77 +     * Type Masks
   21.78 +     */
   21.79 +    public static final int TM_NULL      = 1 << TC_NULL;
   21.80 +    public static final int TM_VOID      = 1 << TC_VOID;
   21.81 +    public static final int TM_BOOLEAN   = 1 << TC_BOOLEAN;
   21.82 +    public static final int TM_BYTE      = 1 << TC_BYTE;
   21.83 +    public static final int TM_CHAR      = 1 << TC_CHAR;
   21.84 +    public static final int TM_SHORT     = 1 << TC_SHORT;
   21.85 +    public static final int TM_INT       = 1 << TC_INT;
   21.86 +    public static final int TM_LONG      = 1 << TC_LONG;
   21.87 +    public static final int TM_FLOAT     = 1 << TC_FLOAT;
   21.88 +    public static final int TM_DOUBLE    = 1 << TC_DOUBLE;
   21.89 +    public static final int TM_ARRAY     = 1 << TC_ARRAY;
   21.90 +    public static final int TM_CLASS     = 1 << TC_CLASS;
   21.91 +    public static final int TM_METHOD    = 1 << TC_METHOD;
   21.92 +    public static final int TM_ERROR     = 1 << TC_ERROR;
   21.93 +
   21.94 +    public static final int TM_INT32     = TM_BYTE | TM_SHORT | TM_CHAR | TM_INT;
   21.95 +    public static final int TM_NUM32     = TM_INT32 | TM_FLOAT;
   21.96 +    public static final int TM_NUM64     = TM_LONG | TM_DOUBLE;
   21.97 +    public static final int TM_INTEGER   = TM_INT32 | TM_LONG;
   21.98 +    public static final int TM_REAL      = TM_FLOAT | TM_DOUBLE;
   21.99 +    public static final int TM_NUMBER    = TM_INTEGER | TM_REAL;
  21.100 +    public static final int TM_REFERENCE = TM_ARRAY | TM_CLASS | TM_NULL;
  21.101 +
  21.102 +    /*
  21.103 +     * Class status
  21.104 +     */
  21.105 +    public static final int CS_UNDEFINED        = 0;
  21.106 +    public static final int CS_UNDECIDED        = 1;
  21.107 +    public static final int CS_BINARY           = 2;
  21.108 +    public static final int CS_SOURCE           = 3;
  21.109 +    public static final int CS_PARSED           = 4;
  21.110 +    public static final int CS_COMPILED         = 5;
  21.111 +    public static final int CS_NOTFOUND         = 6;
  21.112 +
  21.113 +    /*
  21.114 +     * Attributes
  21.115 +     */
  21.116 +    public static final int ATT_ALL             = -1;
  21.117 +    public static final int ATT_CODE            = 1;
  21.118 +
  21.119 +    /*
  21.120 +     * Number of bits used in file offsets
  21.121 +     */
  21.122 +    public static final int OFFSETBITS          = 19;
  21.123 +    public static final int MAXFILESIZE         = (1 << OFFSETBITS) - 1;
  21.124 +    public static final int MAXLINENUMBER       = (1 << (32 - OFFSETBITS)) - 1;
  21.125 +
  21.126 +    /*
  21.127 +     * Operators
  21.128 +     */
  21.129 +    public final int COMMA              = 0;
  21.130 +    public final int ASSIGN             = 1;
  21.131 +
  21.132 +    public final int ASGMUL             = 2;
  21.133 +    public final int ASGDIV             = 3;
  21.134 +    public final int ASGREM             = 4;
  21.135 +    public final int ASGADD             = 5;
  21.136 +    public final int ASGSUB             = 6;
  21.137 +    public final int ASGLSHIFT          = 7;
  21.138 +    public final int ASGRSHIFT          = 8;
  21.139 +    public final int ASGURSHIFT         = 9;
  21.140 +    public final int ASGBITAND          = 10;
  21.141 +    public final int ASGBITOR           = 11;
  21.142 +    public final int ASGBITXOR          = 12;
  21.143 +
  21.144 +    public final int COND               = 13;
  21.145 +    public final int OR                 = 14;
  21.146 +    public final int AND                = 15;
  21.147 +    public final int BITOR              = 16;
  21.148 +    public final int BITXOR             = 17;
  21.149 +    public final int BITAND             = 18;
  21.150 +    public final int NE                 = 19;
  21.151 +    public final int EQ                 = 20;
  21.152 +    public final int GE                 = 21;
  21.153 +    public final int GT                 = 22;
  21.154 +    public final int LE                 = 23;
  21.155 +    public final int LT                 = 24;
  21.156 +    public final int INSTANCEOF         = 25;
  21.157 +    public final int LSHIFT             = 26;
  21.158 +    public final int RSHIFT             = 27;
  21.159 +    public final int URSHIFT            = 28;
  21.160 +    public final int ADD                = 29;
  21.161 +    public final int SUB                = 30;
  21.162 +    public final int DIV                = 31;
  21.163 +    public final int REM                = 32;
  21.164 +    public final int MUL                = 33;
  21.165 +    public final int CAST               = 34;           // (x)y
  21.166 +    public final int POS                = 35;           // +x
  21.167 +    public final int NEG                = 36;           // -x
  21.168 +    public final int NOT                = 37;
  21.169 +    public final int BITNOT             = 38;
  21.170 +    public final int PREINC             = 39;           // ++x
  21.171 +    public final int PREDEC             = 40;           // --x
  21.172 +    public final int NEWARRAY           = 41;
  21.173 +    public final int NEWINSTANCE        = 42;
  21.174 +    public final int NEWFROMNAME        = 43;
  21.175 +    public final int POSTINC            = 44;           // x++
  21.176 +    public final int POSTDEC            = 45;           // x--
  21.177 +    public final int FIELD              = 46;
  21.178 +    public final int METHOD             = 47;           // x(y)
  21.179 +    public final int ARRAYACCESS        = 48;           // x[y]
  21.180 +    public final int NEW                = 49;
  21.181 +    public final int INC                = 50;
  21.182 +    public final int DEC                = 51;
  21.183 +
  21.184 +    public final int CONVERT            = 55;           // implicit conversion
  21.185 +    public final int EXPR               = 56;           // (x)
  21.186 +    public final int ARRAY              = 57;           // {x, y, ...}
  21.187 +    public final int GOTO               = 58;
  21.188 +
  21.189 +    /*
  21.190 +     * Value tokens
  21.191 +     */
  21.192 +    public final int IDENT              = 60;
  21.193 +    public final int BOOLEANVAL         = 61;
  21.194 +    public final int BYTEVAL            = 62;
  21.195 +    public final int CHARVAL            = 63;
  21.196 +    public final int SHORTVAL           = 64;
  21.197 +    public final int INTVAL                     = 65;
  21.198 +    public final int LONGVAL            = 66;
  21.199 +    public final int FLOATVAL           = 67;
  21.200 +    public final int DOUBLEVAL          = 68;
  21.201 +    public final int STRINGVAL          = 69;
  21.202 +
  21.203 +    /*
  21.204 +     * Type keywords
  21.205 +     */
  21.206 +    public final int BYTE               = 70;
  21.207 +    public final int CHAR               = 71;
  21.208 +    public final int SHORT              = 72;
  21.209 +    public final int INT                = 73;
  21.210 +    public final int LONG               = 74;
  21.211 +    public final int FLOAT              = 75;
  21.212 +    public final int DOUBLE             = 76;
  21.213 +    public final int VOID               = 77;
  21.214 +    public final int BOOLEAN            = 78;
  21.215 +
  21.216 +    /*
  21.217 +     * Expression keywords
  21.218 +     */
  21.219 +    public final int TRUE               = 80;
  21.220 +    public final int FALSE              = 81;
  21.221 +    public final int THIS               = 82;
  21.222 +    public final int SUPER              = 83;
  21.223 +    public final int NULL               = 84;
  21.224 +
  21.225 +    /*
  21.226 +     * Statement keywords
  21.227 +     */
  21.228 +    public final int IF                 = 90;
  21.229 +    public final int ELSE               = 91;
  21.230 +    public final int FOR                = 92;
  21.231 +    public final int WHILE              = 93;
  21.232 +    public final int DO                 = 94;
  21.233 +    public final int SWITCH             = 95;
  21.234 +    public final int CASE               = 96;
  21.235 +    public final int DEFAULT            = 97;
  21.236 +    public final int BREAK              = 98;
  21.237 +    public final int CONTINUE           = 99;
  21.238 +    public final int RETURN             = 100;
  21.239 +    public final int TRY                = 101;
  21.240 +    public final int CATCH              = 102;
  21.241 +    public final int FINALLY            = 103;
  21.242 +    public final int THROW              = 104;
  21.243 +    public final int STAT               = 105;
  21.244 +    public final int EXPRESSION         = 106;
  21.245 +    public final int DECLARATION        = 107;
  21.246 +    public final int VARDECLARATION     = 108;
  21.247 +
  21.248 +    /*
  21.249 +     * Declaration keywords
  21.250 +     */
  21.251 +    public final int IMPORT             = 110;
  21.252 +    public final int CLASS              = 111;
  21.253 +    public final int EXTENDS            = 112;
  21.254 +    public final int IMPLEMENTS         = 113;
  21.255 +    public final int INTERFACE          = 114;
  21.256 +    public final int PACKAGE            = 115;
  21.257 +
  21.258 +    /*
  21.259 +     * Modifier keywords
  21.260 +     */
  21.261 +    public final int PRIVATE    = 120;
  21.262 +    public final int PUBLIC             = 121;
  21.263 +    public final int PROTECTED  = 122;
  21.264 +    public final int CONST              = 123;
  21.265 +    public final int STATIC             = 124;
  21.266 +    public final int TRANSIENT          = 125;
  21.267 +    public final int SYNCHRONIZED       = 126;
  21.268 +    public final int NATIVE             = 127;
  21.269 +    public final int FINAL              = 128;
  21.270 +    public final int VOLATILE   = 129;
  21.271 +    public final int ABSTRACT   = 130;
  21.272 +    public final int STRICT             = 165;
  21.273 +
  21.274 +    /*
  21.275 +     * Punctuation
  21.276 +     */
  21.277 +    public final int SEMICOLON  = 135;
  21.278 +    public final int COLON              = 136;
  21.279 +    public final int QUESTIONMARK       = 137;
  21.280 +    public final int LBRACE             = 138;
  21.281 +    public final int RBRACE             = 139;
  21.282 +    public final int LPAREN             = 140;
  21.283 +    public final int RPAREN             = 141;
  21.284 +    public final int LSQBRACKET = 142;
  21.285 +    public final int RSQBRACKET = 143;
  21.286 +    public final int THROWS     = 144;
  21.287 +
  21.288 +    /*
  21.289 +     * Special tokens
  21.290 +     */
  21.291 +    public final int ERROR              = 145;          // an error
  21.292 +    public final int COMMENT    = 146;          // not used anymore.
  21.293 +    public final int TYPE               = 147;
  21.294 +    public final int LENGTH             = 148;
  21.295 +    public final int INLINERETURN       = 149;
  21.296 +    public final int INLINEMETHOD       = 150;
  21.297 +    public final int INLINENEWINSTANCE  = 151;
  21.298 +
  21.299 +    /*
  21.300 +     * Added for jasm
  21.301 +     */
  21.302 +        public final int METHODREF      = 152;
  21.303 +        public final int FIELDREF       = 153;
  21.304 +    public final int STACK              = 154;
  21.305 +    public final int LOCAL              = 155;
  21.306 +    public final int CPINDEX    = 156;
  21.307 +    public final int CPNAME             = 157;
  21.308 +    public final int SIGN               = 158;
  21.309 +    public final int BITS               = 159;
  21.310 +    public final int INF                = 160;
  21.311 +    public final int NAN                = 161;
  21.312 +    public final int INNERCLASS = 162;
  21.313 +    public final int OF         = 163;
  21.314 +    public final int SYNTHETIC          = 164;
  21.315 +// last used=165;
  21.316 +
  21.317 +   /*
  21.318 +     * Operator precedence
  21.319 +     */
  21.320 +    public static final int opPrecedence[] = {
  21.321 +        10,     11,     11,     11,     11,     11,     11,     11,     11,     11,
  21.322 +        11,     11,     11,     12,     13,     14,     15,     16,     17,     18,
  21.323 +        18,     19,     19,     19,     19,     19,     20,     20,     20,     21,
  21.324 +        21,     22,     22,     22,     23,     24,     24,     24,     24,     24,
  21.325 +        24,     25,     25,     26,     26,     26,     26,     26,     26
  21.326 +    };
  21.327 +
  21.328 +    /*
  21.329 +     * Operator names
  21.330 +     */
  21.331 +    public static final String opNames[] = {
  21.332 +        ",",            "=",            "*=",           "/=",           "%=",
  21.333 +        "+=",           "-=",           "<<=",          ">>=",          "<<<=",
  21.334 +        "&=",           "|=",           "^=",           "?:",           "||",
  21.335 +        "&&",           "|",            "^",            "&",            "!=",
  21.336 +        "==",           ">=",           ">",            "<=",           "<",
  21.337 +        "instanceof",   "<<",           ">>",           "<<<",          "+",
  21.338 +        "-",            "/",            "%",            "*",            "cast",
  21.339 +        "+",            "-",            "!",            "~",            "++",
  21.340 +        "--",           "new",          "new",          "new",          "++",
  21.341 +        "--",           "field",        "method",       "[]",           "new",
  21.342 +        "++",           "--",           null,           null,           null,
  21.343 +
  21.344 +        "convert",      "expr",         "array",        "goto",         null,
  21.345 +
  21.346 +        "Identifier",   "Boolean",      "Byte",         "Char",         "Short",
  21.347 +        "Integer",              "Long",         "Float",        "Double",       "String",
  21.348 +
  21.349 +        "byte",         "char",         "short",        "int",          "long",
  21.350 +        "float",        "double",       "void",         "boolean",      null,
  21.351 +
  21.352 +        "true",         "false",        "this",         "super",        "null",
  21.353 +        null,           null,           null,           null,           null,
  21.354 +
  21.355 +        "if",           "else",         "for",          "while",        "do",
  21.356 +        "switch",       "case",         "default",      "break",        "continue",
  21.357 +        "return",       "try",          "catch",        "finally",      "throw",
  21.358 +        "stat",         "expression",   "declaration",  "declaration",  null,
  21.359 +
  21.360 +        "import",       "class",        "extends",      "implements",   "interface",
  21.361 +        "package",      null,           null,           null,           null,
  21.362 +
  21.363 +        "private",      "public",       "protected",    "const",        "static",
  21.364 +        "transient",    "synchronized", "native",       "final",        "volatile",
  21.365 +        "abstract",     null,           null,           null,           null,
  21.366 +
  21.367 +        ";",            ":",            "?",            "{",            "}",
  21.368 +        "(",            ")",            "[",            "]",            "throws",
  21.369 +        "error",        "comment",      "type",         "length",       "inline-return",
  21.370 +        "inline-method", "inline-new",
  21.371 +        "method", "field", "stack", "locals", "CPINDEX", "CPName", "SIGN",
  21.372 +        "bits", "INF", "NaN", "InnerClass", "of", "synthetic"
  21.373 +    };
  21.374 +
  21.375 +}
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/javap/src/main/java/org/apidesign/javap/FieldData.java	Sun Nov 18 22:03:15 2012 +0100
    22.3 @@ -0,0 +1,166 @@
    22.4 +/*
    22.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
    22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    22.7 + *
    22.8 + * This code is free software; you can redistribute it and/or modify it
    22.9 + * under the terms of the GNU General Public License version 2 only, as
   22.10 + * published by the Free Software Foundation.  Oracle designates this
   22.11 + * particular file as subject to the "Classpath" exception as provided
   22.12 + * by Oracle in the LICENSE file that accompanied this code.
   22.13 + *
   22.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   22.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   22.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   22.17 + * version 2 for more details (a copy is included in the LICENSE file that
   22.18 + * accompanied this code).
   22.19 + *
   22.20 + * You should have received a copy of the GNU General Public License version
   22.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   22.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   22.23 + *
   22.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   22.25 + * or visit www.oracle.com if you need additional information or have any
   22.26 + * questions.
   22.27 + */
   22.28 +
   22.29 +
   22.30 +package org.apidesign.javap;
   22.31 +
   22.32 +import java.io.*;
   22.33 +
   22.34 +/**
   22.35 + * Strores field data informastion.
   22.36 + *
   22.37 + * @author  Sucheta Dambalkar (Adopted code from jdis)
   22.38 + */
   22.39 +
   22.40 +public class FieldData implements RuntimeConstants  {
   22.41 +
   22.42 +    ClassData cls;
   22.43 +    int access;
   22.44 +    int name_index;
   22.45 +    int descriptor_index;
   22.46 +    int attributes_count;
   22.47 +    int value_cpx=0;
   22.48 +    boolean isSynthetic=false;
   22.49 +    boolean isDeprecated=false;
   22.50 +    Vector attrs;
   22.51 +
   22.52 +    public FieldData(ClassData cls){
   22.53 +        this.cls=cls;
   22.54 +    }
   22.55 +
   22.56 +    /**
   22.57 +     * Read and store field info.
   22.58 +     */
   22.59 +    public void read(DataInputStream in) throws IOException {
   22.60 +        access = in.readUnsignedShort();
   22.61 +        name_index = in.readUnsignedShort();
   22.62 +        descriptor_index = in.readUnsignedShort();
   22.63 +        // Read the attributes
   22.64 +        int attributes_count = in.readUnsignedShort();
   22.65 +        attrs=new Vector(attributes_count);
   22.66 +        for (int i = 0; i < attributes_count; i++) {
   22.67 +            int attr_name_index=in.readUnsignedShort();
   22.68 +            if (cls.getTag(attr_name_index)!=CONSTANT_UTF8) continue;
   22.69 +            String attr_name=cls.getString(attr_name_index);
   22.70 +            if (attr_name.equals("ConstantValue")){
   22.71 +                if (in.readInt()!=2)
   22.72 +                    throw new ClassFormatError("invalid ConstantValue attr length");
   22.73 +                value_cpx=in.readUnsignedShort();
   22.74 +                AttrData attr=new AttrData(cls);
   22.75 +                attr.read(attr_name_index);
   22.76 +                attrs.addElement(attr);
   22.77 +            } else if (attr_name.equals("Synthetic")){
   22.78 +                if (in.readInt()!=0)
   22.79 +                    throw new ClassFormatError("invalid Synthetic attr length");
   22.80 +                isSynthetic=true;
   22.81 +                AttrData attr=new AttrData(cls);
   22.82 +                attr.read(attr_name_index);
   22.83 +                attrs.addElement(attr);
   22.84 +            } else if (attr_name.equals("Deprecated")){
   22.85 +                if (in.readInt()!=0)
   22.86 +                    throw new ClassFormatError("invalid Synthetic attr length");
   22.87 +                isDeprecated = true;
   22.88 +                AttrData attr=new AttrData(cls);
   22.89 +                attr.read(attr_name_index);
   22.90 +                attrs.addElement(attr);
   22.91 +            } else {
   22.92 +                AttrData attr=new AttrData(cls);
   22.93 +                attr.read(attr_name_index, in);
   22.94 +                attrs.addElement(attr);
   22.95 +            }
   22.96 +        }
   22.97 +
   22.98 +    }  // end read
   22.99 +
  22.100 +    public boolean isStatic() {
  22.101 +        return (access & ACC_STATIC) != 0;
  22.102 +    }
  22.103 +    
  22.104 +    /**
  22.105 +     * Returns access of a field.
  22.106 +     */
  22.107 +    public String[] getAccess(){
  22.108 +        Vector v = new Vector();
  22.109 +        if ((access & ACC_PUBLIC)   !=0) v.addElement("public");
  22.110 +        if ((access & ACC_PRIVATE)   !=0) v.addElement("private");
  22.111 +        if ((access & ACC_PROTECTED)   !=0) v.addElement("protected");
  22.112 +        if ((access & ACC_STATIC)   !=0) v.addElement("static");
  22.113 +        if ((access & ACC_FINAL)    !=0) v.addElement("final");
  22.114 +        if ((access & ACC_VOLATILE) !=0) v.addElement("volatile");
  22.115 +        if ((access & ACC_TRANSIENT) !=0) v.addElement("transient");
  22.116 +        String[] accflags = new String[v.size()];
  22.117 +        v.copyInto(accflags);
  22.118 +        return accflags;
  22.119 +    }
  22.120 +
  22.121 +    /**
  22.122 +     * Returns name of a field.
  22.123 +     */
  22.124 +    public String getName(){
  22.125 +        return cls.getStringValue(name_index);
  22.126 +    }
  22.127 +
  22.128 +    /**
  22.129 +     * Returns internal signature of a field
  22.130 +     */
  22.131 +    public String getInternalSig(){
  22.132 +        return cls.getStringValue(descriptor_index);
  22.133 +    }
  22.134 +
  22.135 +    /**
  22.136 +     * Returns java type signature of a field.
  22.137 +     */
  22.138 +    public String getType(){
  22.139 +        return new TypeSignature(getInternalSig()).getFieldType();
  22.140 +    }
  22.141 +
  22.142 +    /**
  22.143 +     * Returns true if field is synthetic.
  22.144 +     */
  22.145 +    public boolean isSynthetic(){
  22.146 +        return isSynthetic;
  22.147 +    }
  22.148 +
  22.149 +    /**
  22.150 +     * Returns true if field is deprecated.
  22.151 +     */
  22.152 +    public boolean isDeprecated(){
  22.153 +        return isDeprecated;
  22.154 +    }
  22.155 +
  22.156 +    /**
  22.157 +     * Returns index of constant value in cpool.
  22.158 +     */
  22.159 +    public int getConstantValueIndex(){
  22.160 +        return (value_cpx);
  22.161 +    }
  22.162 +
  22.163 +    /**
  22.164 +     * Returns list of attributes of field.
  22.165 +     */
  22.166 +    public Vector getAttributes(){
  22.167 +        return attrs;
  22.168 +    }
  22.169 +}
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/javap/src/main/java/org/apidesign/javap/Hashtable.java	Sun Nov 18 22:03:15 2012 +0100
    23.3 @@ -0,0 +1,81 @@
    23.4 +/*
    23.5 + * To change this template, choose Tools | Templates
    23.6 + * and open the template in the editor.
    23.7 + */
    23.8 +package org.apidesign.javap;
    23.9 +
   23.10 +/** A JavaScript optimized replacement for Hashtable.
   23.11 + *
   23.12 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   23.13 + */
   23.14 +final class Hashtable {
   23.15 +    private Object[] keys;
   23.16 +    private Object[] values;
   23.17 +
   23.18 +    Hashtable(int i) {
   23.19 +        this();
   23.20 +    }
   23.21 +
   23.22 +    Hashtable(int i, double d) {
   23.23 +        this();
   23.24 +    }
   23.25 +
   23.26 +    Hashtable() {
   23.27 +    }
   23.28 +
   23.29 +    synchronized void put(Object key, Object val) {
   23.30 +        int[] where = { -1, -1 };
   23.31 +        Object found = get(key, where);
   23.32 +        if (where[0] != -1) {
   23.33 +            // key exists
   23.34 +            values[where[0]] = val;
   23.35 +        } else {
   23.36 +            if (where[1] != -1) {
   23.37 +                // null found
   23.38 +                keys[where[1]] = key;
   23.39 +                values[where[1]] = val;
   23.40 +            } else {
   23.41 +                if (keys == null) {
   23.42 +                    keys = new Object[11];
   23.43 +                    values = new Object[11];
   23.44 +                    keys[0] = key;
   23.45 +                    values[0] = val;
   23.46 +                } else {
   23.47 +                    Object[] newKeys = new Object[keys.length * 2];
   23.48 +                    Object[] newValues = new Object[values.length * 2];
   23.49 +                    for (int i = 0; i < keys.length; i++) {
   23.50 +                        newKeys[i] = keys[i];
   23.51 +                        newValues[i] = values[i];
   23.52 +                    }
   23.53 +                    newKeys[keys.length] = key;
   23.54 +                    newValues[keys.length] = val;
   23.55 +                    keys = newKeys;
   23.56 +                    values = newValues;
   23.57 +                }
   23.58 +            }
   23.59 +        }
   23.60 +    }
   23.61 +
   23.62 +    Object get(Object key) {
   23.63 +        return get(key, null);
   23.64 +    }
   23.65 +    private synchronized Object get(Object key, int[] foundAndNull) {
   23.66 +        if (keys == null) {
   23.67 +            return null;
   23.68 +        }
   23.69 +        for (int i = 0; i < keys.length; i++) {
   23.70 +            if (keys[i] == null) {
   23.71 +                if (foundAndNull != null) {
   23.72 +                    foundAndNull[1] = i;
   23.73 +                }
   23.74 +            } else if (keys[i].equals(key)) {
   23.75 +                if (foundAndNull != null) {
   23.76 +                    foundAndNull[0] = i;
   23.77 +                }
   23.78 +                return values[i];
   23.79 +            }
   23.80 +        }
   23.81 +        return null;
   23.82 +    }
   23.83 +    
   23.84 +}
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/javap/src/main/java/org/apidesign/javap/InnerClassData.java	Sun Nov 18 22:03:15 2012 +0100
    24.3 @@ -0,0 +1,75 @@
    24.4 +/*
    24.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
    24.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    24.7 + *
    24.8 + * This code is free software; you can redistribute it and/or modify it
    24.9 + * under the terms of the GNU General Public License version 2 only, as
   24.10 + * published by the Free Software Foundation.  Oracle designates this
   24.11 + * particular file as subject to the "Classpath" exception as provided
   24.12 + * by Oracle in the LICENSE file that accompanied this code.
   24.13 + *
   24.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   24.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   24.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   24.17 + * version 2 for more details (a copy is included in the LICENSE file that
   24.18 + * accompanied this code).
   24.19 + *
   24.20 + * You should have received a copy of the GNU General Public License version
   24.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   24.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   24.23 + *
   24.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   24.25 + * or visit www.oracle.com if you need additional information or have any
   24.26 + * questions.
   24.27 + */
   24.28 +
   24.29 +
   24.30 +package org.apidesign.javap;
   24.31 +
   24.32 +import java.io.*;
   24.33 +import java.util.*;
   24.34 +
   24.35 +/**
   24.36 + * Strores InnerClass data informastion.
   24.37 + *
   24.38 + * @author  Sucheta Dambalkar (Adopted code from jdis)
   24.39 + */
   24.40 +class InnerClassData  implements RuntimeConstants {
   24.41 +    ClassData cls;
   24.42 +
   24.43 +
   24.44 +    int inner_class_info_index
   24.45 +        ,outer_class_info_index
   24.46 +        ,inner_name_index
   24.47 +        ,access
   24.48 +        ;
   24.49 +
   24.50 +    public InnerClassData(ClassData cls) {
   24.51 +        this.cls=cls;
   24.52 +
   24.53 +    }
   24.54 +
   24.55 +    /**
   24.56 +     * Read Innerclass attribute data.
   24.57 +     */
   24.58 +    public void read(DataInputStream in) throws IOException {
   24.59 +        inner_class_info_index = in.readUnsignedShort();
   24.60 +        outer_class_info_index = in.readUnsignedShort();
   24.61 +        inner_name_index = in.readUnsignedShort();
   24.62 +        access = in.readUnsignedShort();
   24.63 +    }  // end read
   24.64 +
   24.65 +    /**
   24.66 +     * Returns the access of this class or interface.
   24.67 +     */
   24.68 +    public String[] getAccess(){
   24.69 +        Vector v = new Vector();
   24.70 +        if ((access & ACC_PUBLIC)   !=0) v.addElement("public");
   24.71 +        if ((access & ACC_FINAL)    !=0) v.addElement("final");
   24.72 +        if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
   24.73 +        String[] accflags = new String[v.size()];
   24.74 +        v.copyInto(accflags);
   24.75 +        return accflags;
   24.76 +    }
   24.77 +
   24.78 +} // end InnerClassData
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/javap/src/main/java/org/apidesign/javap/LineNumData.java	Sun Nov 18 22:03:15 2012 +0100
    25.3 @@ -0,0 +1,50 @@
    25.4 +/*
    25.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
    25.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    25.7 + *
    25.8 + * This code is free software; you can redistribute it and/or modify it
    25.9 + * under the terms of the GNU General Public License version 2 only, as
   25.10 + * published by the Free Software Foundation.  Oracle designates this
   25.11 + * particular file as subject to the "Classpath" exception as provided
   25.12 + * by Oracle in the LICENSE file that accompanied this code.
   25.13 + *
   25.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   25.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   25.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   25.17 + * version 2 for more details (a copy is included in the LICENSE file that
   25.18 + * accompanied this code).
   25.19 + *
   25.20 + * You should have received a copy of the GNU General Public License version
   25.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   25.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   25.23 + *
   25.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   25.25 + * or visit www.oracle.com if you need additional information or have any
   25.26 + * questions.
   25.27 + */
   25.28 +
   25.29 +
   25.30 +package org.apidesign.javap;
   25.31 +
   25.32 +import java.util.*;
   25.33 +import java.io.*;
   25.34 +
   25.35 +/**
   25.36 + * Strores LineNumberTable data information.
   25.37 + *
   25.38 + * @author  Sucheta Dambalkar (Adopted code from jdis)
   25.39 + */
   25.40 +class LineNumData {
   25.41 +    short start_pc, line_number;
   25.42 +
   25.43 +    public LineNumData() {}
   25.44 +
   25.45 +    /**
   25.46 +     * Read LineNumberTable attribute.
   25.47 +     */
   25.48 +    public LineNumData(DataInputStream in) throws IOException {
   25.49 +        start_pc = in.readShort();
   25.50 +        line_number=in.readShort();
   25.51 +
   25.52 +    }
   25.53 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/javap/src/main/java/org/apidesign/javap/LocVarData.java	Sun Nov 18 22:03:15 2012 +0100
    26.3 @@ -0,0 +1,54 @@
    26.4 +/*
    26.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
    26.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    26.7 + *
    26.8 + * This code is free software; you can redistribute it and/or modify it
    26.9 + * under the terms of the GNU General Public License version 2 only, as
   26.10 + * published by the Free Software Foundation.  Oracle designates this
   26.11 + * particular file as subject to the "Classpath" exception as provided
   26.12 + * by Oracle in the LICENSE file that accompanied this code.
   26.13 + *
   26.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   26.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   26.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   26.17 + * version 2 for more details (a copy is included in the LICENSE file that
   26.18 + * accompanied this code).
   26.19 + *
   26.20 + * You should have received a copy of the GNU General Public License version
   26.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   26.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   26.23 + *
   26.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   26.25 + * or visit www.oracle.com if you need additional information or have any
   26.26 + * questions.
   26.27 + */
   26.28 +
   26.29 +
   26.30 +package org.apidesign.javap;
   26.31 +
   26.32 +import java.util.*;
   26.33 +import java.io.*;
   26.34 +
   26.35 +/**
   26.36 + * Strores LocalVariableTable data information.
   26.37 + *
   26.38 + * @author  Sucheta Dambalkar (Adopted code from jdis)
   26.39 + */
   26.40 +class LocVarData {
   26.41 +    short start_pc, length, name_cpx, sig_cpx, slot;
   26.42 +
   26.43 +    public LocVarData() {
   26.44 +    }
   26.45 +
   26.46 +    /**
   26.47 +     * Read LocalVariableTable attribute.
   26.48 +     */
   26.49 +    public LocVarData(DataInputStream in) throws IOException {
   26.50 +        start_pc = in.readShort();
   26.51 +        length=in.readShort();
   26.52 +        name_cpx=in.readShort();
   26.53 +        sig_cpx=in.readShort();
   26.54 +        slot=in.readShort();
   26.55 +
   26.56 +    }
   26.57 +}
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/javap/src/main/java/org/apidesign/javap/MethodData.java	Sun Nov 18 22:03:15 2012 +0100
    27.3 @@ -0,0 +1,425 @@
    27.4 +/*
    27.5 + * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
    27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    27.7 + *
    27.8 + * This code is free software; you can redistribute it and/or modify it
    27.9 + * under the terms of the GNU General Public License version 2 only, as
   27.10 + * published by the Free Software Foundation.  Oracle designates this
   27.11 + * particular file as subject to the "Classpath" exception as provided
   27.12 + * by Oracle in the LICENSE file that accompanied this code.
   27.13 + *
   27.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   27.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   27.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   27.17 + * version 2 for more details (a copy is included in the LICENSE file that
   27.18 + * accompanied this code).
   27.19 + *
   27.20 + * You should have received a copy of the GNU General Public License version
   27.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   27.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   27.23 + *
   27.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   27.25 + * or visit www.oracle.com if you need additional information or have any
   27.26 + * questions.
   27.27 + */
   27.28 +
   27.29 +package org.apidesign.javap;
   27.30 +
   27.31 +import java.io.*;
   27.32 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
   27.33 +
   27.34 +import static org.apidesign.javap.RuntimeConstants.*;
   27.35 +
   27.36 +/**
   27.37 + * Strores method data informastion.
   27.38 + *
   27.39 + * @author  Sucheta Dambalkar (Adopted code from jdis)
   27.40 + */
   27.41 +public class MethodData {
   27.42 +
   27.43 +    ClassData cls;
   27.44 +    int access;
   27.45 +    int name_index;
   27.46 +    int descriptor_index;
   27.47 +    int attributes_count;
   27.48 +    byte[] code;
   27.49 +    Vector exception_table = new Vector(0);
   27.50 +    Vector lin_num_tb = new Vector(0);
   27.51 +    Vector loc_var_tb = new Vector(0);
   27.52 +    StackMapTableData[] stackMapTable;
   27.53 +    StackMapData[] stackMap;
   27.54 +    int[] exc_index_table=null;
   27.55 +    Vector attrs=new Vector(0);
   27.56 +    Vector code_attrs=new Vector(0);
   27.57 +    int max_stack,  max_locals;
   27.58 +    boolean isSynthetic=false;
   27.59 +    boolean isDeprecated=false;
   27.60 +
   27.61 +    public MethodData(ClassData cls){
   27.62 +        this.cls=cls;
   27.63 +    }
   27.64 +
   27.65 +    /**
   27.66 +     * Read method info.
   27.67 +     */
   27.68 +    public void read(DataInputStream in) throws IOException {
   27.69 +        access = in.readUnsignedShort();
   27.70 +        name_index=in.readUnsignedShort();
   27.71 +        descriptor_index =in.readUnsignedShort();
   27.72 +        int attributes_count = in.readUnsignedShort();
   27.73 +        for (int i = 0; i < attributes_count; i++) {
   27.74 +            int attr_name_index=in.readUnsignedShort();
   27.75 +
   27.76 +        readAttr: {
   27.77 +                if (cls.getTag(attr_name_index)==CONSTANT_UTF8) {
   27.78 +                    String  attr_name=cls.getString(attr_name_index);
   27.79 +                    if ( attr_name.equals("Code")){
   27.80 +                        readCode (in);
   27.81 +                        AttrData attr=new AttrData(cls);
   27.82 +                        attr.read(attr_name_index);
   27.83 +                        attrs.addElement(attr);
   27.84 +                        break readAttr;
   27.85 +                    } else if ( attr_name.equals("Exceptions")){
   27.86 +                        readExceptions(in);
   27.87 +                        AttrData attr=new AttrData(cls);
   27.88 +                        attr.read(attr_name_index);
   27.89 +                        attrs.addElement(attr);
   27.90 +                        break readAttr;
   27.91 +                    } else if (attr_name.equals("Synthetic")){
   27.92 +                        if (in.readInt()!=0)
   27.93 +                            throw new ClassFormatError("invalid Synthetic attr length");
   27.94 +                        isSynthetic=true;
   27.95 +                        AttrData attr=new AttrData(cls);
   27.96 +                        attr.read(attr_name_index);
   27.97 +                        attrs.addElement(attr);
   27.98 +                        break readAttr;
   27.99 +                    } else if (attr_name.equals("Deprecated")){
  27.100 +                        if (in.readInt()!=0)
  27.101 +                            throw new ClassFormatError("invalid Synthetic attr length");
  27.102 +                        isDeprecated = true;
  27.103 +                        AttrData attr=new AttrData(cls);
  27.104 +                        attr.read(attr_name_index);
  27.105 +                        attrs.addElement(attr);
  27.106 +                        break readAttr;
  27.107 +                    }
  27.108 +                }
  27.109 +                AttrData attr=new AttrData(cls);
  27.110 +                attr.read(attr_name_index, in);
  27.111 +                attrs.addElement(attr);
  27.112 +            }
  27.113 +        }
  27.114 +    }
  27.115 +
  27.116 +    /**
  27.117 +     * Read code attribute info.
  27.118 +     */
  27.119 +    public void readCode(DataInputStream in) throws IOException {
  27.120 +
  27.121 +        int attr_length = in.readInt();
  27.122 +        max_stack=in.readUnsignedShort();
  27.123 +        max_locals=in.readUnsignedShort();
  27.124 +        int codelen=in.readInt();
  27.125 +
  27.126 +        code=new byte[codelen];
  27.127 +        int totalread = 0;
  27.128 +        while(totalread < codelen){
  27.129 +            totalread += in.read(code, totalread, codelen-totalread);
  27.130 +        }
  27.131 +        //      in.read(code, 0, codelen);
  27.132 +        int clen = 0;
  27.133 +        readExceptionTable(in);
  27.134 +        int code_attributes_count = in.readUnsignedShort();
  27.135 +
  27.136 +        for (int k = 0 ; k < code_attributes_count ; k++) {
  27.137 +            int table_name_index=in.readUnsignedShort();
  27.138 +            int table_name_tag=cls.getTag(table_name_index);
  27.139 +            AttrData attr=new AttrData(cls);
  27.140 +            if (table_name_tag==CONSTANT_UTF8) {
  27.141 +                String table_name_tstr=cls.getString(table_name_index);
  27.142 +                if (table_name_tstr.equals("LineNumberTable")) {
  27.143 +                    readLineNumTable(in);
  27.144 +                    attr.read(table_name_index);
  27.145 +                } else if (table_name_tstr.equals("LocalVariableTable")) {
  27.146 +                    readLocVarTable(in);
  27.147 +                    attr.read(table_name_index);
  27.148 +                } else if (table_name_tstr.equals("StackMapTable")) {
  27.149 +                    readStackMapTable(in);
  27.150 +                    attr.read(table_name_index);
  27.151 +                } else if (table_name_tstr.equals("StackMap")) {
  27.152 +                    readStackMap(in);
  27.153 +                    attr.read(table_name_index);
  27.154 +                } else {
  27.155 +                    attr.read(table_name_index, in);
  27.156 +                }
  27.157 +                code_attrs.addElement(attr);
  27.158 +                continue;
  27.159 +            }
  27.160 +
  27.161 +            attr.read(table_name_index, in);
  27.162 +            code_attrs.addElement(attr);
  27.163 +        }
  27.164 +    }
  27.165 +
  27.166 +    /**
  27.167 +     * Read exception table info.
  27.168 +     */
  27.169 +    void readExceptionTable (DataInputStream in) throws IOException {
  27.170 +        int exception_table_len=in.readUnsignedShort();
  27.171 +        exception_table=new Vector(exception_table_len);
  27.172 +        for (int l = 0; l < exception_table_len; l++) {
  27.173 +            exception_table.addElement(new TrapData(in, l));
  27.174 +        }
  27.175 +    }
  27.176 +
  27.177 +    /**
  27.178 +     * Read LineNumberTable attribute info.
  27.179 +     */
  27.180 +    void readLineNumTable (DataInputStream in) throws IOException {
  27.181 +        int attr_len = in.readInt(); // attr_length
  27.182 +        int lin_num_tb_len = in.readUnsignedShort();
  27.183 +        lin_num_tb=new Vector(lin_num_tb_len);
  27.184 +        for (int l = 0; l < lin_num_tb_len; l++) {
  27.185 +            lin_num_tb.addElement(new LineNumData(in));
  27.186 +        }
  27.187 +    }
  27.188 +
  27.189 +    /**
  27.190 +     * Read LocalVariableTable attribute info.
  27.191 +     */
  27.192 +    void readLocVarTable (DataInputStream in) throws IOException {
  27.193 +        int attr_len=in.readInt(); // attr_length
  27.194 +        int loc_var_tb_len = in.readUnsignedShort();
  27.195 +        loc_var_tb = new Vector(loc_var_tb_len);
  27.196 +        for (int l = 0; l < loc_var_tb_len; l++) {
  27.197 +            loc_var_tb.addElement(new LocVarData(in));
  27.198 +        }
  27.199 +    }
  27.200 +
  27.201 +    /**
  27.202 +     * Read Exception attribute info.
  27.203 +     */
  27.204 +    public void readExceptions(DataInputStream in) throws IOException {
  27.205 +        int attr_len=in.readInt(); // attr_length in prog
  27.206 +        int num_exceptions = in.readUnsignedShort();
  27.207 +        exc_index_table=new int[num_exceptions];
  27.208 +        for (int l = 0; l < num_exceptions; l++) {
  27.209 +            int exc=in.readShort();
  27.210 +            exc_index_table[l]=exc;
  27.211 +        }
  27.212 +    }
  27.213 +
  27.214 +    /**
  27.215 +     * Read StackMapTable attribute info.
  27.216 +     */
  27.217 +    void readStackMapTable(DataInputStream in) throws IOException {
  27.218 +        int attr_len = in.readInt();  //attr_length
  27.219 +        int stack_map_tb_len = in.readUnsignedShort();
  27.220 +        stackMapTable = new StackMapTableData[stack_map_tb_len];
  27.221 +        for (int i=0; i<stack_map_tb_len; i++) {
  27.222 +            stackMapTable[i] = StackMapTableData.getInstance(in, this);
  27.223 +        }
  27.224 +    }
  27.225 +
  27.226 +    /**
  27.227 +     * Read StackMap attribute info.
  27.228 +     */
  27.229 +    void readStackMap(DataInputStream in) throws IOException {
  27.230 +        int attr_len = in.readInt();  //attr_length
  27.231 +        int stack_map_len = in.readUnsignedShort();
  27.232 +        stackMap = new StackMapData[stack_map_len];
  27.233 +        for (int i = 0; i<stack_map_len; i++) {
  27.234 +            stackMap[i] = new StackMapData(in, this);
  27.235 +        }
  27.236 +    }
  27.237 +
  27.238 +    /**
  27.239 +     * Return access of the method.
  27.240 +     */
  27.241 +    public String[] getAccess(){
  27.242 +
  27.243 +        Vector v = new Vector();
  27.244 +        if ((access & ACC_PUBLIC)   !=0) v.addElement("public");
  27.245 +        if ((access & ACC_PRIVATE)   !=0) v.addElement("private");
  27.246 +        if ((access & ACC_PROTECTED)   !=0) v.addElement("protected");
  27.247 +        if ((access & ACC_STATIC)   !=0) v.addElement("static");
  27.248 +        if ((access & ACC_FINAL)    !=0) v.addElement("final");
  27.249 +        if ((access & ACC_SYNCHRONIZED) !=0) v.addElement("synchronized");
  27.250 +        if ((access & ACC_NATIVE) !=0) v.addElement("native");
  27.251 +        if ((access & ACC_ABSTRACT) !=0) v.addElement("abstract");
  27.252 +        if ((access & ACC_STRICT) !=0) v.addElement("strictfp");
  27.253 +
  27.254 +        String[] accflags = new String[v.size()];
  27.255 +        v.copyInto(accflags);
  27.256 +        return accflags;
  27.257 +    }
  27.258 +
  27.259 +    /**
  27.260 +     * Return name of the method.
  27.261 +     */
  27.262 +    public String getName(){
  27.263 +        return cls.getStringValue(name_index);
  27.264 +    }
  27.265 +
  27.266 +    /**
  27.267 +     * Return internal siganature of the method.
  27.268 +     */
  27.269 +    public String getInternalSig(){
  27.270 +        return cls.getStringValue(descriptor_index);
  27.271 +    }
  27.272 +
  27.273 +    /**
  27.274 +     * Return java return type signature of method.
  27.275 +     */
  27.276 +    public String getReturnType(){
  27.277 +
  27.278 +        String rttype = (new TypeSignature(getInternalSig())).getReturnType();
  27.279 +        return rttype;
  27.280 +    }
  27.281 +
  27.282 +    /**
  27.283 +     * Return java type parameter signature.
  27.284 +     */
  27.285 +    public String getParameters(){
  27.286 +        String ptype = (new TypeSignature(getInternalSig())).getParameters();
  27.287 +
  27.288 +        return ptype;
  27.289 +    }
  27.290 +
  27.291 +    /**
  27.292 +     * Return code attribute data of a method.
  27.293 +     */
  27.294 +    public byte[] getCode(){
  27.295 +        return code;
  27.296 +    }
  27.297 +
  27.298 +    /**
  27.299 +     * Return LineNumberTable size.
  27.300 +     */
  27.301 +    public int getnumlines(){
  27.302 +        return lin_num_tb.size();
  27.303 +    }
  27.304 +
  27.305 +    /**
  27.306 +     * Return LineNumberTable
  27.307 +     */
  27.308 +    public Vector getlin_num_tb(){
  27.309 +        return lin_num_tb;
  27.310 +    }
  27.311 +
  27.312 +    /**
  27.313 +     * Return LocalVariableTable size.
  27.314 +     */
  27.315 +    public int getloc_var_tbsize(){
  27.316 +        return loc_var_tb.size();
  27.317 +    }
  27.318 +
  27.319 +
  27.320 +    /**
  27.321 +     * Return LocalVariableTable.
  27.322 +     */
  27.323 +    public Vector getloc_var_tb(){
  27.324 +        return loc_var_tb;
  27.325 +    }
  27.326 +
  27.327 +    /**
  27.328 +     * Return StackMap.
  27.329 +     */
  27.330 +    public StackMapData[] getStackMap() {
  27.331 +        return stackMap;
  27.332 +    }
  27.333 +
  27.334 +    /**
  27.335 +     * Return StackMapTable.
  27.336 +     */
  27.337 +    public StackMapTableData[] getStackMapTable() {
  27.338 +        return stackMapTable;
  27.339 +    }
  27.340 +
  27.341 +    /**
  27.342 +     * Return number of arguments of that method.
  27.343 +     */
  27.344 +    public int getArgumentlength(){
  27.345 +        return new TypeSignature(getInternalSig()).getArgumentlength();
  27.346 +    }
  27.347 +
  27.348 +    /**
  27.349 +     * Return true if method is static
  27.350 +     */
  27.351 +    public boolean isStatic(){
  27.352 +        if ((access & ACC_STATIC)   !=0) return true;
  27.353 +        return false;
  27.354 +    }
  27.355 +
  27.356 +
  27.357 +    /**
  27.358 +     * Return max depth of operand stack.
  27.359 +     */
  27.360 +    public int getMaxStack(){
  27.361 +        return  max_stack;
  27.362 +    }
  27.363 +
  27.364 +
  27.365 +    /**
  27.366 +     * Return number of local variables.
  27.367 +     */
  27.368 +    public int getMaxLocals(){
  27.369 +        return max_locals;
  27.370 +    }
  27.371 +
  27.372 +
  27.373 +    /**
  27.374 +     * Return exception index table in Exception attribute.
  27.375 +     */
  27.376 +    public int []get_exc_index_table(){
  27.377 +        return  exc_index_table;
  27.378 +    }
  27.379 +
  27.380 +
  27.381 +    /**
  27.382 +     * Return exception table in code attributre.
  27.383 +     */
  27.384 +    public Vector getexception_table(){
  27.385 +        return exception_table;
  27.386 +    }
  27.387 +
  27.388 +
  27.389 +    /**
  27.390 +     * Return method attributes.
  27.391 +     */
  27.392 +    public Vector getAttributes(){
  27.393 +        return attrs;
  27.394 +    }
  27.395 +
  27.396 +
  27.397 +    /**
  27.398 +     * Return code attributes.
  27.399 +     */
  27.400 +    public Vector getCodeAttributes(){
  27.401 +        return code_attrs;
  27.402 +    }
  27.403 +
  27.404 +
  27.405 +    /**
  27.406 +     * Return true if method id synthetic.
  27.407 +     */
  27.408 +    public boolean isSynthetic(){
  27.409 +        return isSynthetic;
  27.410 +    }
  27.411 +
  27.412 +
  27.413 +    /**
  27.414 +     * Return true if method is deprecated.
  27.415 +     */
  27.416 +    public boolean isDeprecated(){
  27.417 +        return isDeprecated;
  27.418 +    }
  27.419 +
  27.420 +    public byte[] findAnnotationData(boolean classRetention) {
  27.421 +        String n = classRetention ?
  27.422 +            "RuntimeInvisibleAnnotations" : // NOI18N
  27.423 +            "RuntimeVisibleAnnotations"; // NOI18N
  27.424 +        AttrData[] arr = new AttrData[attrs.size()];
  27.425 +        attrs.copyInto(arr);
  27.426 +        return ClassData.findAttr(n, arr);
  27.427 +    }
  27.428 +}
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/javap/src/main/java/org/apidesign/javap/RuntimeConstants.java	Sun Nov 18 22:03:15 2012 +0100
    28.3 @@ -0,0 +1,787 @@
    28.4 +/*
    28.5 + * Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved.
    28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    28.7 + *
    28.8 + * This code is free software; you can redistribute it and/or modify it
    28.9 + * under the terms of the GNU General Public License version 2 only, as
   28.10 + * published by the Free Software Foundation.  Oracle designates this
   28.11 + * particular file as subject to the "Classpath" exception as provided
   28.12 + * by Oracle in the LICENSE file that accompanied this code.
   28.13 + *
   28.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   28.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   28.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   28.17 + * version 2 for more details (a copy is included in the LICENSE file that
   28.18 + * accompanied this code).
   28.19 + *
   28.20 + * You should have received a copy of the GNU General Public License version
   28.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   28.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   28.23 + *
   28.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   28.25 + * or visit www.oracle.com if you need additional information or have any
   28.26 + * questions.
   28.27 + */
   28.28 +
   28.29 +
   28.30 +package org.apidesign.javap;
   28.31 +
   28.32 +public interface RuntimeConstants {
   28.33 +
   28.34 +    /* Signature Characters */
   28.35 +    public static final char   SIGC_VOID                  = 'V';
   28.36 +    public static final String SIG_VOID                   = "V";
   28.37 +    public static final char   SIGC_BOOLEAN               = 'Z';
   28.38 +    public static final String SIG_BOOLEAN                = "Z";
   28.39 +    public static final char   SIGC_BYTE                  = 'B';
   28.40 +    public static final String SIG_BYTE                   = "B";
   28.41 +    public static final char   SIGC_CHAR                  = 'C';
   28.42 +    public static final String SIG_CHAR                   = "C";
   28.43 +    public static final char   SIGC_SHORT                 = 'S';
   28.44 +    public static final String SIG_SHORT                  = "S";
   28.45 +    public static final char   SIGC_INT                   = 'I';
   28.46 +    public static final String SIG_INT                    = "I";
   28.47 +    public static final char   SIGC_LONG                  = 'J';
   28.48 +    public static final String SIG_LONG                   = "J";
   28.49 +    public static final char   SIGC_FLOAT                 = 'F';
   28.50 +    public static final String SIG_FLOAT                  = "F";
   28.51 +    public static final char   SIGC_DOUBLE                = 'D';
   28.52 +    public static final String SIG_DOUBLE                 = "D";
   28.53 +    public static final char   SIGC_ARRAY                 = '[';
   28.54 +    public static final String SIG_ARRAY                  = "[";
   28.55 +    public static final char   SIGC_CLASS                 = 'L';
   28.56 +    public static final String SIG_CLASS                  = "L";
   28.57 +    public static final char   SIGC_METHOD                = '(';
   28.58 +    public static final String SIG_METHOD                 = "(";
   28.59 +    public static final char   SIGC_ENDCLASS              = ';';
   28.60 +    public static final String SIG_ENDCLASS               = ";";
   28.61 +    public static final char   SIGC_ENDMETHOD             = ')';
   28.62 +    public static final String SIG_ENDMETHOD              = ")";
   28.63 +    public static final char   SIGC_PACKAGE               = '/';
   28.64 +    public static final String SIG_PACKAGE                = "/";
   28.65 +
   28.66 +    /* Class File Constants */
   28.67 +    public static final int JAVA_MAGIC                   = 0xcafebabe;
   28.68 +    public static final int JAVA_VERSION                 = 45;
   28.69 +    public static final int JAVA_MINOR_VERSION           = 3;
   28.70 +
   28.71 +    /* Constant table */
   28.72 +    public static final int CONSTANT_UTF8                = 1;
   28.73 +    public static final int CONSTANT_UNICODE             = 2;
   28.74 +    public static final int CONSTANT_INTEGER             = 3;
   28.75 +    public static final int CONSTANT_FLOAT               = 4;
   28.76 +    public static final int CONSTANT_LONG                = 5;
   28.77 +    public static final int CONSTANT_DOUBLE              = 6;
   28.78 +    public static final int CONSTANT_CLASS               = 7;
   28.79 +    public static final int CONSTANT_STRING              = 8;
   28.80 +    public static final int CONSTANT_FIELD               = 9;
   28.81 +    public static final int CONSTANT_METHOD              = 10;
   28.82 +    public static final int CONSTANT_INTERFACEMETHOD     = 11;
   28.83 +    public static final int CONSTANT_NAMEANDTYPE         = 12;
   28.84 +
   28.85 +    /* Access Flags */
   28.86 +    public static final int ACC_PUBLIC                   = 0x00000001;
   28.87 +    public static final int ACC_PRIVATE                  = 0x00000002;
   28.88 +    public static final int ACC_PROTECTED                = 0x00000004;
   28.89 +    public static final int ACC_STATIC                   = 0x00000008;
   28.90 +    public static final int ACC_FINAL                    = 0x00000010;
   28.91 +    public static final int ACC_SYNCHRONIZED             = 0x00000020;
   28.92 +    public static final int ACC_SUPER                        = 0x00000020;
   28.93 +    public static final int ACC_VOLATILE                 = 0x00000040;
   28.94 +    public static final int ACC_TRANSIENT                = 0x00000080;
   28.95 +    public static final int ACC_NATIVE                   = 0x00000100;
   28.96 +    public static final int ACC_INTERFACE                = 0x00000200;
   28.97 +    public static final int ACC_ABSTRACT                 = 0x00000400;
   28.98 +    public static final int ACC_STRICT                   = 0x00000800;
   28.99 +    public static final int ACC_EXPLICIT                 = 0x00001000;
  28.100 +    public static final int ACC_SYNTHETIC                = 0x00010000; // actually, this is an attribute
  28.101 +
  28.102 +    /* Type codes */
  28.103 +    public static final int T_CLASS                      = 0x00000002;
  28.104 +    public static final int T_BOOLEAN                    = 0x00000004;
  28.105 +    public static final int T_CHAR                       = 0x00000005;
  28.106 +    public static final int T_FLOAT                      = 0x00000006;
  28.107 +    public static final int T_DOUBLE                     = 0x00000007;
  28.108 +    public static final int T_BYTE                       = 0x00000008;
  28.109 +    public static final int T_SHORT                      = 0x00000009;
  28.110 +    public static final int T_INT                        = 0x0000000a;
  28.111 +    public static final int T_LONG                       = 0x0000000b;
  28.112 +
  28.113 +    /* Type codes for StackMap attribute */
  28.114 +    public static final int ITEM_Bogus      =0; // an unknown or uninitialized value
  28.115 +    public static final int ITEM_Integer    =1; // a 32-bit integer
  28.116 +    public static final int ITEM_Float      =2; // not used
  28.117 +    public static final int ITEM_Double     =3; // not used
  28.118 +    public static final int ITEM_Long       =4; // a 64-bit integer
  28.119 +    public static final int ITEM_Null       =5; // the type of null
  28.120 +    public static final int ITEM_InitObject =6; // "this" in constructor
  28.121 +    public static final int ITEM_Object     =7; // followed by 2-byte index of class name
  28.122 +    public static final int ITEM_NewObject  =8; // followed by 2-byte ref to "new"
  28.123 +
  28.124 +    /* Constants used in StackMapTable attribute */
  28.125 +    public static final int SAME_FRAME_BOUND                  = 64;
  28.126 +    public static final int SAME_LOCALS_1_STACK_ITEM_BOUND    = 128;
  28.127 +    public static final int SAME_LOCALS_1_STACK_ITEM_EXTENDED = 247;
  28.128 +    public static final int SAME_FRAME_EXTENDED               = 251;
  28.129 +    public static final int FULL_FRAME                        = 255;
  28.130 +
  28.131 +    /* Opcodes */
  28.132 +    public static final int opc_dead                     = -2;
  28.133 +    public static final int opc_label                    = -1;
  28.134 +    public static final int opc_nop                      = 0;
  28.135 +    public static final int opc_aconst_null              = 1;
  28.136 +    public static final int opc_iconst_m1                = 2;
  28.137 +    public static final int opc_iconst_0                 = 3;
  28.138 +    public static final int opc_iconst_1                 = 4;
  28.139 +    public static final int opc_iconst_2                 = 5;
  28.140 +    public static final int opc_iconst_3                 = 6;
  28.141 +    public static final int opc_iconst_4                 = 7;
  28.142 +    public static final int opc_iconst_5                 = 8;
  28.143 +    public static final int opc_lconst_0                 = 9;
  28.144 +    public static final int opc_lconst_1                 = 10;
  28.145 +    public static final int opc_fconst_0                 = 11;
  28.146 +    public static final int opc_fconst_1                 = 12;
  28.147 +    public static final int opc_fconst_2                 = 13;
  28.148 +    public static final int opc_dconst_0                 = 14;
  28.149 +    public static final int opc_dconst_1                 = 15;
  28.150 +    public static final int opc_bipush                   = 16;
  28.151 +    public static final int opc_sipush                   = 17;
  28.152 +    public static final int opc_ldc                      = 18;
  28.153 +    public static final int opc_ldc_w                    = 19;
  28.154 +    public static final int opc_ldc2_w                   = 20;
  28.155 +    public static final int opc_iload                    = 21;
  28.156 +    public static final int opc_lload                    = 22;
  28.157 +    public static final int opc_fload                    = 23;
  28.158 +    public static final int opc_dload                    = 24;
  28.159 +    public static final int opc_aload                    = 25;
  28.160 +    public static final int opc_iload_0                  = 26;
  28.161 +    public static final int opc_iload_1                  = 27;
  28.162 +    public static final int opc_iload_2                  = 28;
  28.163 +    public static final int opc_iload_3                  = 29;
  28.164 +    public static final int opc_lload_0                  = 30;
  28.165 +    public static final int opc_lload_1                  = 31;
  28.166 +    public static final int opc_lload_2                  = 32;
  28.167 +    public static final int opc_lload_3                  = 33;
  28.168 +    public static final int opc_fload_0                  = 34;
  28.169 +    public static final int opc_fload_1                  = 35;
  28.170 +    public static final int opc_fload_2                  = 36;
  28.171 +    public static final int opc_fload_3                  = 37;
  28.172 +    public static final int opc_dload_0                  = 38;
  28.173 +    public static final int opc_dload_1                  = 39;
  28.174 +    public static final int opc_dload_2                  = 40;
  28.175 +    public static final int opc_dload_3                  = 41;
  28.176 +    public static final int opc_aload_0                  = 42;
  28.177 +    public static final int opc_aload_1                  = 43;
  28.178 +    public static final int opc_aload_2                  = 44;
  28.179 +    public static final int opc_aload_3                  = 45;
  28.180 +    public static final int opc_iaload                   = 46;
  28.181 +    public static final int opc_laload                   = 47;
  28.182 +    public static final int opc_faload                   = 48;
  28.183 +    public static final int opc_daload                   = 49;
  28.184 +    public static final int opc_aaload                   = 50;
  28.185 +    public static final int opc_baload                   = 51;
  28.186 +    public static final int opc_caload                   = 52;
  28.187 +    public static final int opc_saload                   = 53;
  28.188 +    public static final int opc_istore                   = 54;
  28.189 +    public static final int opc_lstore                   = 55;
  28.190 +    public static final int opc_fstore                   = 56;
  28.191 +    public static final int opc_dstore                   = 57;
  28.192 +    public static final int opc_astore                   = 58;
  28.193 +    public static final int opc_istore_0                 = 59;
  28.194 +    public static final int opc_istore_1                 = 60;
  28.195 +    public static final int opc_istore_2                 = 61;
  28.196 +    public static final int opc_istore_3                 = 62;
  28.197 +    public static final int opc_lstore_0                 = 63;
  28.198 +    public static final int opc_lstore_1                 = 64;
  28.199 +    public static final int opc_lstore_2                 = 65;
  28.200 +    public static final int opc_lstore_3                 = 66;
  28.201 +    public static final int opc_fstore_0                 = 67;
  28.202 +    public static final int opc_fstore_1                 = 68;
  28.203 +    public static final int opc_fstore_2                 = 69;
  28.204 +    public static final int opc_fstore_3                 = 70;
  28.205 +    public static final int opc_dstore_0                 = 71;
  28.206 +    public static final int opc_dstore_1                 = 72;
  28.207 +    public static final int opc_dstore_2                 = 73;
  28.208 +    public static final int opc_dstore_3                 = 74;
  28.209 +    public static final int opc_astore_0                 = 75;
  28.210 +    public static final int opc_astore_1                 = 76;
  28.211 +    public static final int opc_astore_2                 = 77;
  28.212 +    public static final int opc_astore_3                 = 78;
  28.213 +    public static final int opc_iastore                  = 79;
  28.214 +    public static final int opc_lastore                  = 80;
  28.215 +    public static final int opc_fastore                  = 81;
  28.216 +    public static final int opc_dastore                  = 82;
  28.217 +    public static final int opc_aastore                  = 83;
  28.218 +    public static final int opc_bastore                  = 84;
  28.219 +    public static final int opc_castore                  = 85;
  28.220 +    public static final int opc_sastore                  = 86;
  28.221 +    public static final int opc_pop                      = 87;
  28.222 +    public static final int opc_pop2                     = 88;
  28.223 +    public static final int opc_dup                      = 89;
  28.224 +    public static final int opc_dup_x1                   = 90;
  28.225 +    public static final int opc_dup_x2                   = 91;
  28.226 +    public static final int opc_dup2                     = 92;
  28.227 +    public static final int opc_dup2_x1                  = 93;
  28.228 +    public static final int opc_dup2_x2                  = 94;
  28.229 +    public static final int opc_swap                     = 95;
  28.230 +    public static final int opc_iadd                     = 96;
  28.231 +    public static final int opc_ladd                     = 97;
  28.232 +    public static final int opc_fadd                     = 98;
  28.233 +    public static final int opc_dadd                     = 99;
  28.234 +    public static final int opc_isub                     = 100;
  28.235 +    public static final int opc_lsub                     = 101;
  28.236 +    public static final int opc_fsub                     = 102;
  28.237 +    public static final int opc_dsub                     = 103;
  28.238 +    public static final int opc_imul                     = 104;
  28.239 +    public static final int opc_lmul                     = 105;
  28.240 +    public static final int opc_fmul                     = 106;
  28.241 +    public static final int opc_dmul                     = 107;
  28.242 +    public static final int opc_idiv                     = 108;
  28.243 +    public static final int opc_ldiv                     = 109;
  28.244 +    public static final int opc_fdiv                     = 110;
  28.245 +    public static final int opc_ddiv                     = 111;
  28.246 +    public static final int opc_irem                     = 112;
  28.247 +    public static final int opc_lrem                     = 113;
  28.248 +    public static final int opc_frem                     = 114;
  28.249 +    public static final int opc_drem                     = 115;
  28.250 +    public static final int opc_ineg                     = 116;
  28.251 +    public static final int opc_lneg                     = 117;
  28.252 +    public static final int opc_fneg                     = 118;
  28.253 +    public static final int opc_dneg                     = 119;
  28.254 +    public static final int opc_ishl                     = 120;
  28.255 +    public static final int opc_lshl                     = 121;
  28.256 +    public static final int opc_ishr                     = 122;
  28.257 +    public static final int opc_lshr                     = 123;
  28.258 +    public static final int opc_iushr                    = 124;
  28.259 +    public static final int opc_lushr                    = 125;
  28.260 +    public static final int opc_iand                     = 126;
  28.261 +    public static final int opc_land                     = 127;
  28.262 +    public static final int opc_ior                      = 128;
  28.263 +    public static final int opc_lor                      = 129;
  28.264 +    public static final int opc_ixor                     = 130;
  28.265 +    public static final int opc_lxor                     = 131;
  28.266 +    public static final int opc_iinc                     = 132;
  28.267 +    public static final int opc_i2l                      = 133;
  28.268 +    public static final int opc_i2f                      = 134;
  28.269 +    public static final int opc_i2d                      = 135;
  28.270 +    public static final int opc_l2i                      = 136;
  28.271 +    public static final int opc_l2f                      = 137;
  28.272 +    public static final int opc_l2d                      = 138;
  28.273 +    public static final int opc_f2i                      = 139;
  28.274 +    public static final int opc_f2l                      = 140;
  28.275 +    public static final int opc_f2d                      = 141;
  28.276 +    public static final int opc_d2i                      = 142;
  28.277 +    public static final int opc_d2l                      = 143;
  28.278 +    public static final int opc_d2f                      = 144;
  28.279 +    public static final int opc_i2b                      = 145;
  28.280 +    public static final int opc_int2byte                 = 145;
  28.281 +    public static final int opc_i2c                      = 146;
  28.282 +    public static final int opc_int2char                 = 146;
  28.283 +    public static final int opc_i2s                      = 147;
  28.284 +    public static final int opc_int2short                = 147;
  28.285 +    public static final int opc_lcmp                     = 148;
  28.286 +    public static final int opc_fcmpl                    = 149;
  28.287 +    public static final int opc_fcmpg                    = 150;
  28.288 +    public static final int opc_dcmpl                    = 151;
  28.289 +    public static final int opc_dcmpg                    = 152;
  28.290 +    public static final int opc_ifeq                     = 153;
  28.291 +    public static final int opc_ifne                     = 154;
  28.292 +    public static final int opc_iflt                     = 155;
  28.293 +    public static final int opc_ifge                     = 156;
  28.294 +    public static final int opc_ifgt                     = 157;
  28.295 +    public static final int opc_ifle                     = 158;
  28.296 +    public static final int opc_if_icmpeq                = 159;
  28.297 +    public static final int opc_if_icmpne                = 160;
  28.298 +    public static final int opc_if_icmplt                = 161;
  28.299 +    public static final int opc_if_icmpge                = 162;
  28.300 +    public static final int opc_if_icmpgt                = 163;
  28.301 +    public static final int opc_if_icmple                = 164;
  28.302 +    public static final int opc_if_acmpeq                = 165;
  28.303 +    public static final int opc_if_acmpne                = 166;
  28.304 +    public static final int opc_goto                     = 167;
  28.305 +    public static final int opc_jsr                      = 168;
  28.306 +    public static final int opc_ret                      = 169;
  28.307 +    public static final int opc_tableswitch              = 170;
  28.308 +    public static final int opc_lookupswitch             = 171;
  28.309 +    public static final int opc_ireturn                  = 172;
  28.310 +    public static final int opc_lreturn                  = 173;
  28.311 +    public static final int opc_freturn                  = 174;
  28.312 +    public static final int opc_dreturn                  = 175;
  28.313 +    public static final int opc_areturn                  = 176;
  28.314 +    public static final int opc_return                   = 177;
  28.315 +    public static final int opc_getstatic                = 178;
  28.316 +    public static final int opc_putstatic                = 179;
  28.317 +    public static final int opc_getfield                 = 180;
  28.318 +    public static final int opc_putfield                 = 181;
  28.319 +    public static final int opc_invokevirtual            = 182;
  28.320 +    public static final int opc_invokenonvirtual         = 183;
  28.321 +    public static final int opc_invokespecial            = 183;
  28.322 +    public static final int opc_invokestatic             = 184;
  28.323 +    public static final int opc_invokeinterface          = 185;
  28.324 +//    public static final int opc_xxxunusedxxx             = 186;
  28.325 +    public static final int opc_new                      = 187;
  28.326 +    public static final int opc_newarray                 = 188;
  28.327 +    public static final int opc_anewarray                = 189;
  28.328 +    public static final int opc_arraylength              = 190;
  28.329 +    public static final int opc_athrow                   = 191;
  28.330 +    public static final int opc_checkcast                = 192;
  28.331 +    public static final int opc_instanceof               = 193;
  28.332 +    public static final int opc_monitorenter             = 194;
  28.333 +    public static final int opc_monitorexit              = 195;
  28.334 +    public static final int opc_wide                     = 196;
  28.335 +    public static final int opc_multianewarray           = 197;
  28.336 +    public static final int opc_ifnull                   = 198;
  28.337 +    public static final int opc_ifnonnull                = 199;
  28.338 +    public static final int opc_goto_w                   = 200;
  28.339 +    public static final int opc_jsr_w                    = 201;
  28.340 +        /* Pseudo-instructions */
  28.341 +    public static final int opc_bytecode                 = 203;
  28.342 +    public static final int opc_try                      = 204;
  28.343 +    public static final int opc_endtry                   = 205;
  28.344 +    public static final int opc_catch                    = 206;
  28.345 +    public static final int opc_var                      = 207;
  28.346 +    public static final int opc_endvar                   = 208;
  28.347 +    public static final int opc_localsmap                = 209;
  28.348 +    public static final int opc_stackmap                 = 210;
  28.349 +        /* PicoJava prefixes */
  28.350 +    public static final int opc_nonpriv                  = 254;
  28.351 +    public static final int opc_priv                     = 255;
  28.352 +
  28.353 +        /* Wide instructions */
  28.354 +    public static final int opc_iload_w         = (opc_wide<<8)|opc_iload;
  28.355 +    public static final int opc_lload_w         = (opc_wide<<8)|opc_lload;
  28.356 +    public static final int opc_fload_w         = (opc_wide<<8)|opc_fload;
  28.357 +    public static final int opc_dload_w         = (opc_wide<<8)|opc_dload;
  28.358 +    public static final int opc_aload_w         = (opc_wide<<8)|opc_aload;
  28.359 +    public static final int opc_istore_w        = (opc_wide<<8)|opc_istore;
  28.360 +    public static final int opc_lstore_w        = (opc_wide<<8)|opc_lstore;
  28.361 +    public static final int opc_fstore_w        = (opc_wide<<8)|opc_fstore;
  28.362 +    public static final int opc_dstore_w        = (opc_wide<<8)|opc_dstore;
  28.363 +    public static final int opc_astore_w        = (opc_wide<<8)|opc_astore;
  28.364 +    public static final int opc_ret_w           = (opc_wide<<8)|opc_ret;
  28.365 +    public static final int opc_iinc_w          = (opc_wide<<8)|opc_iinc;
  28.366 +
  28.367 +    /* Opcode Names */
  28.368 +  public static final String opcNamesTab[] = {
  28.369 +        "nop",
  28.370 +        "aconst_null",
  28.371 +        "iconst_m1",
  28.372 +        "iconst_0",
  28.373 +        "iconst_1",
  28.374 +        "iconst_2",
  28.375 +        "iconst_3",
  28.376 +        "iconst_4",
  28.377 +        "iconst_5",
  28.378 +        "lconst_0",
  28.379 +        "lconst_1",
  28.380 +        "fconst_0",
  28.381 +        "fconst_1",
  28.382 +        "fconst_2",
  28.383 +        "dconst_0",
  28.384 +        "dconst_1",
  28.385 +        "bipush",
  28.386 +        "sipush",
  28.387 +        "ldc",
  28.388 +        "ldc_w",
  28.389 +        "ldc2_w",
  28.390 +        "iload",
  28.391 +        "lload",
  28.392 +        "fload",
  28.393 +        "dload",
  28.394 +        "aload",
  28.395 +        "iload_0",
  28.396 +        "iload_1",
  28.397 +        "iload_2",
  28.398 +        "iload_3",
  28.399 +        "lload_0",
  28.400 +        "lload_1",
  28.401 +        "lload_2",
  28.402 +        "lload_3",
  28.403 +        "fload_0",
  28.404 +        "fload_1",
  28.405 +        "fload_2",
  28.406 +        "fload_3",
  28.407 +        "dload_0",
  28.408 +        "dload_1",
  28.409 +        "dload_2",
  28.410 +        "dload_3",
  28.411 +        "aload_0",
  28.412 +        "aload_1",
  28.413 +        "aload_2",
  28.414 +        "aload_3",
  28.415 +        "iaload",
  28.416 +        "laload",
  28.417 +        "faload",
  28.418 +        "daload",
  28.419 +        "aaload",
  28.420 +        "baload",
  28.421 +        "caload",
  28.422 +        "saload",
  28.423 +        "istore",
  28.424 +        "lstore",
  28.425 +        "fstore",
  28.426 +        "dstore",
  28.427 +        "astore",
  28.428 +        "istore_0",
  28.429 +        "istore_1",
  28.430 +        "istore_2",
  28.431 +        "istore_3",
  28.432 +        "lstore_0",
  28.433 +        "lstore_1",
  28.434 +        "lstore_2",
  28.435 +        "lstore_3",
  28.436 +        "fstore_0",
  28.437 +        "fstore_1",
  28.438 +        "fstore_2",
  28.439 +        "fstore_3",
  28.440 +        "dstore_0",
  28.441 +        "dstore_1",
  28.442 +        "dstore_2",
  28.443 +        "dstore_3",
  28.444 +        "astore_0",
  28.445 +        "astore_1",
  28.446 +        "astore_2",
  28.447 +        "astore_3",
  28.448 +        "iastore",
  28.449 +        "lastore",
  28.450 +        "fastore",
  28.451 +        "dastore",
  28.452 +        "aastore",
  28.453 +        "bastore",
  28.454 +        "castore",
  28.455 +        "sastore",
  28.456 +        "pop",
  28.457 +        "pop2",
  28.458 +        "dup",
  28.459 +        "dup_x1",
  28.460 +        "dup_x2",
  28.461 +        "dup2",
  28.462 +        "dup2_x1",
  28.463 +        "dup2_x2",
  28.464 +        "swap",
  28.465 +        "iadd",
  28.466 +        "ladd",
  28.467 +        "fadd",
  28.468 +        "dadd",
  28.469 +        "isub",
  28.470 +        "lsub",
  28.471 +        "fsub",
  28.472 +        "dsub",
  28.473 +        "imul",
  28.474 +        "lmul",
  28.475 +        "fmul",
  28.476 +        "dmul",
  28.477 +        "idiv",
  28.478 +        "ldiv",
  28.479 +        "fdiv",
  28.480 +        "ddiv",
  28.481 +        "irem",
  28.482 +        "lrem",
  28.483 +        "frem",
  28.484 +        "drem",
  28.485 +        "ineg",
  28.486 +        "lneg",
  28.487 +        "fneg",
  28.488 +        "dneg",
  28.489 +        "ishl",
  28.490 +        "lshl",
  28.491 +        "ishr",
  28.492 +        "lshr",
  28.493 +        "iushr",
  28.494 +        "lushr",
  28.495 +        "iand",
  28.496 +        "land",
  28.497 +        "ior",
  28.498 +        "lor",
  28.499 +        "ixor",
  28.500 +        "lxor",
  28.501 +        "iinc",
  28.502 +        "i2l",
  28.503 +        "i2f",
  28.504 +        "i2d",
  28.505 +        "l2i",
  28.506 +        "l2f",
  28.507 +        "l2d",
  28.508 +        "f2i",
  28.509 +        "f2l",
  28.510 +        "f2d",
  28.511 +        "d2i",
  28.512 +        "d2l",
  28.513 +        "d2f",
  28.514 +        "i2b",
  28.515 +        "i2c",
  28.516 +        "i2s",
  28.517 +        "lcmp",
  28.518 +        "fcmpl",
  28.519 +        "fcmpg",
  28.520 +        "dcmpl",
  28.521 +        "dcmpg",
  28.522 +        "ifeq",
  28.523 +        "ifne",
  28.524 +        "iflt",
  28.525 +        "ifge",
  28.526 +        "ifgt",
  28.527 +        "ifle",
  28.528 +        "if_icmpeq",
  28.529 +        "if_icmpne",
  28.530 +        "if_icmplt",
  28.531 +        "if_icmpge",
  28.532 +        "if_icmpgt",
  28.533 +        "if_icmple",
  28.534 +        "if_acmpeq",
  28.535 +        "if_acmpne",
  28.536 +        "goto",
  28.537 +        "jsr",
  28.538 +        "ret",
  28.539 +        "tableswitch",
  28.540 +        "lookupswitch",
  28.541 +        "ireturn",
  28.542 +        "lreturn",
  28.543 +        "freturn",
  28.544 +        "dreturn",
  28.545 +        "areturn",
  28.546 +        "return",
  28.547 +        "getstatic",
  28.548 +        "putstatic",
  28.549 +        "getfield",
  28.550 +        "putfield",
  28.551 +        "invokevirtual",
  28.552 +        "invokespecial", //     was "invokenonvirtual",
  28.553 +        "invokestatic",
  28.554 +        "invokeinterface",
  28.555 +        "bytecode 186", //"xxxunusedxxx",
  28.556 +        "new",
  28.557 +        "newarray",
  28.558 +        "anewarray",
  28.559 +        "arraylength",
  28.560 +        "athrow",
  28.561 +        "checkcast",
  28.562 +        "instanceof",
  28.563 +        "monitorenter",
  28.564 +        "monitorexit",
  28.565 +         null, // "wide",
  28.566 +        "multianewarray",
  28.567 +        "ifnull",
  28.568 +        "ifnonnull",
  28.569 +        "goto_w",
  28.570 +        "jsr_w",
  28.571 +        "bytecode 202", // "breakpoint",
  28.572 +        "bytecode",
  28.573 +        "try",
  28.574 +        "endtry",
  28.575 +        "catch",
  28.576 +        "var",
  28.577 +        "endvar",
  28.578 +        "locals_map",
  28.579 +        "stack_map"
  28.580 +  };
  28.581 +
  28.582 +    /* Opcode Lengths */
  28.583 +  public static final int opcLengthsTab[] = {
  28.584 +        1,
  28.585 +        1,
  28.586 +        1,
  28.587 +        1,
  28.588 +        1,
  28.589 +        1,
  28.590 +        1,
  28.591 +        1,
  28.592 +        1,
  28.593 +        1,
  28.594 +        1,
  28.595 +        1,
  28.596 +        1,
  28.597 +        1,
  28.598 +        1,
  28.599 +        1,
  28.600 +        2,
  28.601 +        3,
  28.602 +        2,
  28.603 +        3,
  28.604 +        3,
  28.605 +        2,
  28.606 +        2,
  28.607 +        2,
  28.608 +        2,
  28.609 +        2,
  28.610 +        1,
  28.611 +        1,
  28.612 +        1,
  28.613 +        1,
  28.614 +        1,
  28.615 +        1,
  28.616 +        1,
  28.617 +        1,
  28.618 +        1,
  28.619 +        1,
  28.620 +        1,
  28.621 +        1,
  28.622 +        1,
  28.623 +        1,
  28.624 +        1,
  28.625 +        1,
  28.626 +        1,
  28.627 +        1,
  28.628 +        1,
  28.629 +        1,
  28.630 +        1,
  28.631 +        1,
  28.632 +        1,
  28.633 +        1,
  28.634 +        1,
  28.635 +        1,
  28.636 +        1,
  28.637 +        1,
  28.638 +        2,
  28.639 +        2,
  28.640 +        2,
  28.641 +        2,
  28.642 +        2,
  28.643 +        1,
  28.644 +        1,
  28.645 +        1,
  28.646 +        1,
  28.647 +        1,
  28.648 +        1,
  28.649 +        1,
  28.650 +        1,
  28.651 +        1,
  28.652 +        1,
  28.653 +        1,
  28.654 +        1,
  28.655 +        1,
  28.656 +        1,
  28.657 +        1,
  28.658 +        1,
  28.659 +        1,
  28.660 +        1,
  28.661 +        1,
  28.662 +        1,
  28.663 +        1,
  28.664 +        1,
  28.665 +        1,
  28.666 +        1,
  28.667 +        1,
  28.668 +        1,
  28.669 +        1,
  28.670 +        1,
  28.671 +        1,
  28.672 +        1,
  28.673 +        1,
  28.674 +        1,
  28.675 +        1,
  28.676 +        1,
  28.677 +        1,
  28.678 +        1,
  28.679 +        1,
  28.680 +        1,
  28.681 +        1,
  28.682 +        1,
  28.683 +        1,
  28.684 +        1,
  28.685 +        1,
  28.686 +        1,
  28.687 +        1,
  28.688 +        1,
  28.689 +        1,
  28.690 +        1,
  28.691 +        1,
  28.692 +        1,
  28.693 +        1,
  28.694 +        1,
  28.695 +        1,
  28.696 +        1,
  28.697 +        1,
  28.698 +        1,
  28.699 +        1,
  28.700 +        1,
  28.701 +        1,
  28.702 +        1,
  28.703 +        1,
  28.704 +        1,
  28.705 +        1,
  28.706 +        1,
  28.707 +        1,
  28.708 +        1,
  28.709 +        1,
  28.710 +        1,
  28.711 +        1,
  28.712 +        1,
  28.713 +        1,
  28.714 +        1,
  28.715 +        1,
  28.716 +        3,
  28.717 +        1,
  28.718 +        1,
  28.719 +        1,
  28.720 +        1,
  28.721 +        1,
  28.722 +        1,
  28.723 +        1,
  28.724 +        1,
  28.725 +        1,
  28.726 +        1,
  28.727 +        1,
  28.728 +        1,
  28.729 +        1,
  28.730 +        1,
  28.731 +        1,
  28.732 +        1,
  28.733 +        1,
  28.734 +        1,
  28.735 +        1,
  28.736 +        1,
  28.737 +        3,
  28.738 +        3,
  28.739 +        3,
  28.740 +        3,
  28.741 +        3,
  28.742 +        3,
  28.743 +        3,
  28.744 +        3,
  28.745 +        3,
  28.746 +        3,
  28.747 +        3,
  28.748 +        3,
  28.749 +        3,
  28.750 +        3,
  28.751 +        3,
  28.752 +        3,
  28.753 +        2,
  28.754 +        99,
  28.755 +        99,
  28.756 +        1,
  28.757 +        1,
  28.758 +        1,
  28.759 +        1,
  28.760 +        1,
  28.761 +        1,
  28.762 +        3,
  28.763 +        3,
  28.764 +        3,
  28.765 +        3,
  28.766 +        3,
  28.767 +        3,
  28.768 +        3,
  28.769 +        5,
  28.770 +        0,
  28.771 +        3,
  28.772 +        2,
  28.773 +        3,
  28.774 +        1,
  28.775 +        1,
  28.776 +        3,
  28.777 +        3,
  28.778 +        1,
  28.779 +        1,
  28.780 +        0, // wide
  28.781 +        4,
  28.782 +        3,
  28.783 +        3,
  28.784 +        5,
  28.785 +        5,
  28.786 +        1,
  28.787 +        1, 0, 0, 0, 0, 0 // pseudo
  28.788 +  };
  28.789 +
  28.790 +}
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/javap/src/main/java/org/apidesign/javap/StackMapData.java	Sun Nov 18 22:03:15 2012 +0100
    29.3 @@ -0,0 +1,71 @@
    29.4 +/*
    29.5 + * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
    29.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    29.7 + *
    29.8 + * This code is free software; you can redistribute it and/or modify it
    29.9 + * under the terms of the GNU General Public License version 2 only, as
   29.10 + * published by the Free Software Foundation.  Oracle designates this
   29.11 + * particular file as subject to the "Classpath" exception as provided
   29.12 + * by Oracle in the LICENSE file that accompanied this code.
   29.13 + *
   29.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   29.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   29.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   29.17 + * version 2 for more details (a copy is included in the LICENSE file that
   29.18 + * accompanied this code).
   29.19 + *
   29.20 + * You should have received a copy of the GNU General Public License version
   29.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   29.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   29.23 + *
   29.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   29.25 + * or visit www.oracle.com if you need additional information or have any
   29.26 + * questions.
   29.27 + */
   29.28 +
   29.29 +
   29.30 +package org.apidesign.javap;
   29.31 +
   29.32 +import java.util.*;
   29.33 +import java.io.*;
   29.34 +
   29.35 +import static org.apidesign.javap.RuntimeConstants.*;
   29.36 +
   29.37 +/* represents one entry of StackMap attribute
   29.38 + */
   29.39 +class StackMapData {
   29.40 +    final int offset;
   29.41 +    final int[] locals;
   29.42 +    final int[] stack;
   29.43 +
   29.44 +    StackMapData(int offset, int[] locals, int[] stack) {
   29.45 +        this.offset = offset;
   29.46 +        this.locals = locals;
   29.47 +        this.stack = stack;
   29.48 +    }
   29.49 +
   29.50 +    StackMapData(DataInputStream in, MethodData method) throws IOException {
   29.51 +        offset = in.readUnsignedShort();
   29.52 +        int local_size = in.readUnsignedShort();
   29.53 +        locals = readTypeArray(in, local_size, method);
   29.54 +        int stack_size = in.readUnsignedShort();
   29.55 +        stack = readTypeArray(in, stack_size, method);
   29.56 +    }
   29.57 +
   29.58 +    static final int[] readTypeArray(DataInputStream in, int length, MethodData method) throws IOException {
   29.59 +        int[] types = new int[length];
   29.60 +        for (int i=0; i<length; i++) {
   29.61 +            types[i] = readType(in, method);
   29.62 +        }
   29.63 +        return types;
   29.64 +    }
   29.65 +
   29.66 +    static final int readType(DataInputStream in, MethodData method) throws IOException {
   29.67 +        int type = in.readUnsignedByte();
   29.68 +        if (type == ITEM_Object || type == ITEM_NewObject) {
   29.69 +            type = type | (in.readUnsignedShort()<<8);
   29.70 +        }
   29.71 +        return type;
   29.72 +    }
   29.73 +
   29.74 +}
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/javap/src/main/java/org/apidesign/javap/StackMapTableData.java	Sun Nov 18 22:03:15 2012 +0100
    30.3 @@ -0,0 +1,126 @@
    30.4 +/*
    30.5 + * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
    30.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    30.7 + *
    30.8 + * This code is free software; you can redistribute it and/or modify it
    30.9 + * under the terms of the GNU General Public License version 2 only, as
   30.10 + * published by the Free Software Foundation.  Oracle designates this
   30.11 + * particular file as subject to the "Classpath" exception as provided
   30.12 + * by Oracle in the LICENSE file that accompanied this code.
   30.13 + *
   30.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   30.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   30.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   30.17 + * version 2 for more details (a copy is included in the LICENSE file that
   30.18 + * accompanied this code).
   30.19 + *
   30.20 + * You should have received a copy of the GNU General Public License version
   30.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   30.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   30.23 + *
   30.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   30.25 + * or visit www.oracle.com if you need additional information or have any
   30.26 + * questions.
   30.27 + */
   30.28 +
   30.29 +
   30.30 +package org.apidesign.javap;
   30.31 +
   30.32 +import java.io.*;
   30.33 +
   30.34 +import static org.apidesign.javap.RuntimeConstants.*;
   30.35 +
   30.36 +/* represents one entry of StackMapTable attribute
   30.37 + */
   30.38 +class StackMapTableData {
   30.39 +    final int frameType;
   30.40 +    int offsetDelta;
   30.41 +
   30.42 +    StackMapTableData(int frameType) {
   30.43 +        this.frameType = frameType;
   30.44 +    }
   30.45 +
   30.46 +    static class SameFrame extends StackMapTableData {
   30.47 +        SameFrame(int frameType, int offsetDelta) {
   30.48 +            super(frameType);
   30.49 +            this.offsetDelta = offsetDelta;
   30.50 +        }
   30.51 +    }
   30.52 +
   30.53 +    static class SameLocals1StackItem extends StackMapTableData {
   30.54 +        final int[] stack;
   30.55 +        SameLocals1StackItem(int frameType, int offsetDelta, int[] stack) {
   30.56 +            super(frameType);
   30.57 +            this.offsetDelta = offsetDelta;
   30.58 +            this.stack = stack;
   30.59 +        }
   30.60 +    }
   30.61 +
   30.62 +    static class ChopFrame extends StackMapTableData {
   30.63 +        ChopFrame(int frameType, int offsetDelta) {
   30.64 +            super(frameType);
   30.65 +            this.offsetDelta = offsetDelta;
   30.66 +        }
   30.67 +    }
   30.68 +
   30.69 +    static class AppendFrame extends StackMapTableData {
   30.70 +        final int[] locals;
   30.71 +        AppendFrame(int frameType, int offsetDelta, int[] locals) {
   30.72 +            super(frameType);
   30.73 +            this.offsetDelta = offsetDelta;
   30.74 +            this.locals = locals;
   30.75 +        }
   30.76 +    }
   30.77 +
   30.78 +    static class FullFrame extends StackMapTableData {
   30.79 +        final int[] locals;
   30.80 +        final int[] stack;
   30.81 +        FullFrame(int offsetDelta, int[] locals, int[] stack) {
   30.82 +            super(FULL_FRAME);
   30.83 +            this.offsetDelta = offsetDelta;
   30.84 +            this.locals = locals;
   30.85 +            this.stack = stack;
   30.86 +        }
   30.87 +    }
   30.88 +
   30.89 +    static StackMapTableData getInstance(DataInputStream in, MethodData method)
   30.90 +                  throws IOException {
   30.91 +        int frameType = in.readUnsignedByte();
   30.92 +
   30.93 +        if (frameType < SAME_FRAME_BOUND) {
   30.94 +            // same_frame
   30.95 +            return new SameFrame(frameType, frameType);
   30.96 +        } else if (SAME_FRAME_BOUND <= frameType && frameType < SAME_LOCALS_1_STACK_ITEM_BOUND) {
   30.97 +            // same_locals_1_stack_item_frame
   30.98 +            // read additional single stack element
   30.99 +            return new SameLocals1StackItem(frameType,
  30.100 +                                            (frameType - SAME_FRAME_BOUND),
  30.101 +                                            StackMapData.readTypeArray(in, 1, method));
  30.102 +        } else if (frameType == SAME_LOCALS_1_STACK_ITEM_EXTENDED) {
  30.103 +            // same_locals_1_stack_item_extended
  30.104 +            return new SameLocals1StackItem(frameType,
  30.105 +                                            in.readUnsignedShort(),
  30.106 +                                            StackMapData.readTypeArray(in, 1, method));
  30.107 +        } else if (SAME_LOCALS_1_STACK_ITEM_EXTENDED < frameType  && frameType < SAME_FRAME_EXTENDED) {
  30.108 +            // chop_frame or same_frame_extended
  30.109 +            return new ChopFrame(frameType, in.readUnsignedShort());
  30.110 +        } else if (frameType == SAME_FRAME_EXTENDED) {
  30.111 +            // chop_frame or same_frame_extended
  30.112 +            return new SameFrame(frameType, in.readUnsignedShort());
  30.113 +        } else if (SAME_FRAME_EXTENDED < frameType  && frameType < FULL_FRAME) {
  30.114 +            // append_frame
  30.115 +            return new AppendFrame(frameType, in.readUnsignedShort(),
  30.116 +                                   StackMapData.readTypeArray(in, frameType - SAME_FRAME_EXTENDED, method));
  30.117 +        } else if (frameType == FULL_FRAME) {
  30.118 +            // full_frame
  30.119 +            int offsetDelta = in.readUnsignedShort();
  30.120 +            int locals_size = in.readUnsignedShort();
  30.121 +            int[] locals = StackMapData.readTypeArray(in, locals_size, method);
  30.122 +            int stack_size = in.readUnsignedShort();
  30.123 +            int[] stack = StackMapData.readTypeArray(in, stack_size, method);
  30.124 +            return new FullFrame(offsetDelta, locals, stack);
  30.125 +        } else {
  30.126 +            throw new ClassFormatError("unrecognized frame_type in StackMapTable");
  30.127 +        }
  30.128 +    }
  30.129 +}
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/javap/src/main/java/org/apidesign/javap/TrapData.java	Sun Nov 18 22:03:15 2012 +0100
    31.3 @@ -0,0 +1,60 @@
    31.4 +/*
    31.5 + * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
    31.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    31.7 + *
    31.8 + * This code is free software; you can redistribute it and/or modify it
    31.9 + * under the terms of the GNU General Public License version 2 only, as
   31.10 + * published by the Free Software Foundation.  Oracle designates this
   31.11 + * particular file as subject to the "Classpath" exception as provided
   31.12 + * by Oracle in the LICENSE file that accompanied this code.
   31.13 + *
   31.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   31.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   31.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   31.17 + * version 2 for more details (a copy is included in the LICENSE file that
   31.18 + * accompanied this code).
   31.19 + *
   31.20 + * You should have received a copy of the GNU General Public License version
   31.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   31.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   31.23 + *
   31.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   31.25 + * or visit www.oracle.com if you need additional information or have any
   31.26 + * questions.
   31.27 + */
   31.28 +
   31.29 +
   31.30 +package org.apidesign.javap;
   31.31 +
   31.32 +import java.util.*;
   31.33 +import java.io.*;
   31.34 +
   31.35 +/**
   31.36 + * Stores exception table data in code attribute.
   31.37 + *
   31.38 + * @author  Sucheta Dambalkar (Adopted code from jdis)
   31.39 + */
   31.40 +class TrapData {
   31.41 +    short start_pc, end_pc, handler_pc, catch_cpx;
   31.42 +  int num;
   31.43 +
   31.44 +
   31.45 +    /**
   31.46 +     * Read and store exception table data in code attribute.
   31.47 +     */
   31.48 +    public TrapData(DataInputStream in, int num) throws IOException {
   31.49 +        this.num=num;
   31.50 +        start_pc = in.readShort();
   31.51 +        end_pc=in.readShort();
   31.52 +        handler_pc=in.readShort();
   31.53 +        catch_cpx=in.readShort();
   31.54 +    }
   31.55 +
   31.56 +    /**
   31.57 +     * returns recommended identifier
   31.58 +     */
   31.59 +    public String ident() {
   31.60 +        return "t"+num;
   31.61 +    }
   31.62 +
   31.63 +}
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/javap/src/main/java/org/apidesign/javap/TypeSignature.java	Sun Nov 18 22:03:15 2012 +0100
    32.3 @@ -0,0 +1,295 @@
    32.4 +/*
    32.5 + * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
    32.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    32.7 + *
    32.8 + * This code is free software; you can redistribute it and/or modify it
    32.9 + * under the terms of the GNU General Public License version 2 only, as
   32.10 + * published by the Free Software Foundation.  Oracle designates this
   32.11 + * particular file as subject to the "Classpath" exception as provided
   32.12 + * by Oracle in the LICENSE file that accompanied this code.
   32.13 + *
   32.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   32.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   32.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   32.17 + * version 2 for more details (a copy is included in the LICENSE file that
   32.18 + * accompanied this code).
   32.19 + *
   32.20 + * You should have received a copy of the GNU General Public License version
   32.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   32.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   32.23 + *
   32.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   32.25 + * or visit www.oracle.com if you need additional information or have any
   32.26 + * questions.
   32.27 + */
   32.28 +
   32.29 +
   32.30 +package org.apidesign.javap;
   32.31 +
   32.32 +import java.util.*;
   32.33 +import java.io.*;
   32.34 +
   32.35 +/**
   32.36 + * Returns java type signature.
   32.37 + *
   32.38 + * @author  Sucheta Dambalkar
   32.39 + */
   32.40 +public class TypeSignature {
   32.41 +
   32.42 +    String parameters = null;
   32.43 +    String returntype = null;
   32.44 +    String fieldtype = null;
   32.45 +    int argumentlength = 0;
   32.46 +
   32.47 +    public TypeSignature(String JVMSignature){
   32.48 +
   32.49 +        if(JVMSignature != null){
   32.50 +            if(JVMSignature.indexOf("(") == -1){
   32.51 +                //This is a field type.
   32.52 +                this.fieldtype = getFieldTypeSignature(JVMSignature);
   32.53 +            }else {
   32.54 +                String parameterdes = null;
   32.55 +                if((JVMSignature.indexOf(")")-1) > (JVMSignature.indexOf("("))){
   32.56 +                    //Get parameter signature.
   32.57 +                    parameterdes =
   32.58 +                        JVMSignature.substring(JVMSignature.indexOf("(")+1,
   32.59 +                                               JVMSignature.indexOf(")"));
   32.60 +                    this.parameters = getParametersHelper(parameterdes);
   32.61 +                }else this.parameters = "()";
   32.62 +                //Get return type signature.
   32.63 +                String returndes = JVMSignature.substring(JVMSignature.lastIndexOf(")")+1);
   32.64 +                this.returntype = getReturnTypeHelper(returndes);
   32.65 +            }
   32.66 +        }
   32.67 +    }
   32.68 +
   32.69 +    /**
   32.70 +     * Returns java type signature of a field.
   32.71 +     */
   32.72 +    public String getFieldTypeSignature(String fielddes){
   32.73 +        if(fielddes.startsWith("L")){
   32.74 +            return(getObjectType(fielddes));
   32.75 +        }else if(fielddes.startsWith("[")){
   32.76 +            return(getArrayType(fielddes));
   32.77 +        }else
   32.78 +            return(getBaseType(fielddes));
   32.79 +    }
   32.80 +
   32.81 +    /**
   32.82 +     * Returns java type signature of a parameter.
   32.83 +     */
   32.84 +    public String getParametersHelper(String parameterdes){
   32.85 +        Vector parameters = new Vector();
   32.86 +        int startindex = -1;
   32.87 +        int endindex = -1;
   32.88 +        String param = "";
   32.89 +
   32.90 +        while(parameterdes != null){
   32.91 +
   32.92 +            if(parameterdes.startsWith("L")){
   32.93 +                //parameter is a object.
   32.94 +                startindex = parameterdes.indexOf("L");
   32.95 +                endindex = parameterdes.indexOf(";");
   32.96 +                if(startindex < parameterdes.length()) {
   32.97 +                    if(endindex == parameterdes.length()-1) {
   32.98 +                        //last parameter
   32.99 +                        param = parameterdes.substring(startindex);
  32.100 +                        parameterdes = null;
  32.101 +                    }else if(endindex+1 < parameterdes.length()){
  32.102 +                        //rest parameters
  32.103 +                        param = parameterdes.substring(startindex, endindex+1);
  32.104 +                        parameterdes = parameterdes.substring(endindex+1);
  32.105 +
  32.106 +                    }
  32.107 +                    parameters.add(getObjectType(param));
  32.108 +                }
  32.109 +            }else if(parameterdes.startsWith("[")){
  32.110 +                //parameter is an array.
  32.111 +                String componentType = "";
  32.112 +                int enddim = -1;
  32.113 +                int st = 0;
  32.114 +                while(true){
  32.115 +                    if(st < parameterdes.length()){
  32.116 +                        if(parameterdes.charAt(st) == '['){
  32.117 +
  32.118 +                            enddim = st;
  32.119 +                            st++;
  32.120 +                        }
  32.121 +                        else break;
  32.122 +                    }
  32.123 +                    else break;
  32.124 +                }
  32.125 +
  32.126 +                if(enddim+1 < parameterdes.length()){
  32.127 +                    /* Array dimension.*/
  32.128 +                    param = parameterdes.substring(0,enddim+1);
  32.129 +
  32.130 +                }
  32.131 +
  32.132 +                int stotherparam = param.lastIndexOf("[")+1;
  32.133 +
  32.134 +                if(stotherparam < parameterdes.length()){
  32.135 +                    componentType =  parameterdes.substring(stotherparam);
  32.136 +                }
  32.137 +
  32.138 +                if(componentType.startsWith("L")){
  32.139 +                    //parameter is array of objects.
  32.140 +                    startindex = parameterdes.indexOf("L");
  32.141 +                    endindex = parameterdes.indexOf(";");
  32.142 +
  32.143 +                    if(endindex ==  parameterdes.length()-1){
  32.144 +                        //last parameter
  32.145 +                        param += parameterdes.substring(startindex);
  32.146 +                        parameterdes = null;
  32.147 +                    }else if(endindex+1 <  parameterdes.length()){
  32.148 +                        //rest parameters
  32.149 +                        param += parameterdes.substring(startindex, endindex+1);
  32.150 +                        parameterdes = parameterdes.substring(endindex+1);
  32.151 +                    }
  32.152 +                }else{
  32.153 +                    //parameter is array of base type.
  32.154 +                    if(componentType.length() == 1){
  32.155 +                        //last parameter.
  32.156 +                        param += componentType;
  32.157 +                        parameterdes = null;
  32.158 +                    }
  32.159 +                    else if (componentType.length() > 1) {
  32.160 +                        //rest parameters.
  32.161 +                        param += componentType.substring(0,1);
  32.162 +                        parameterdes = componentType.substring(1);
  32.163 +                    }
  32.164 +                }
  32.165 +                parameters.add(getArrayType(param));
  32.166 +
  32.167 +
  32.168 +            }else {
  32.169 +
  32.170 +                //parameter is of base type.
  32.171 +                if(parameterdes.length() == 1){
  32.172 +                    //last parameter
  32.173 +                    param = parameterdes;
  32.174 +                    parameterdes = null;
  32.175 +                }
  32.176 +                else if (parameterdes.length() > 1) {
  32.177 +                    //rest parameters.
  32.178 +                    param = parameterdes.substring(0,1);
  32.179 +                    parameterdes = parameterdes.substring(1);
  32.180 +                }
  32.181 +                parameters.add(getBaseType(param));
  32.182 +            }
  32.183 +        }
  32.184 +
  32.185 +        /* number of arguments of a method.*/
  32.186 +        argumentlength =  parameters.size();
  32.187 +
  32.188 +        /* java type signature.*/
  32.189 +        String parametersignature = "(";
  32.190 +        int i;
  32.191 +
  32.192 +        for(i = 0; i < parameters.size(); i++){
  32.193 +            parametersignature += (String)parameters.elementAt(i);
  32.194 +            if(i != parameters.size()-1){
  32.195 +                parametersignature += ", ";
  32.196 +            }
  32.197 +        }
  32.198 +        parametersignature += ")";
  32.199 +        return parametersignature;
  32.200 +    }
  32.201 +
  32.202 +    /**
  32.203 +     * Returns java type signature for a return type.
  32.204 +     */
  32.205 +    public String getReturnTypeHelper(String returndes){
  32.206 +        return getFieldTypeSignature(returndes);
  32.207 +    }
  32.208 +
  32.209 +    /**
  32.210 +     * Returns java type signature for a base type.
  32.211 +     */
  32.212 +    public String getBaseType(String baseType){
  32.213 +        if(baseType != null){
  32.214 +            if(baseType.equals("B")) return "byte";
  32.215 +            else if(baseType.equals("C")) return "char";
  32.216 +            else if(baseType.equals("D")) return "double";
  32.217 +            else if(baseType.equals("F")) return "float";
  32.218 +            else if(baseType.equals("I")) return "int";
  32.219 +            else if(baseType.equals("J")) return "long";
  32.220 +            else if(baseType.equals("S")) return "short";
  32.221 +            else if(baseType.equals("Z")) return "boolean";
  32.222 +            else if(baseType.equals("V")) return "void";
  32.223 +        }
  32.224 +        return null;
  32.225 +    }
  32.226 +
  32.227 +    /**
  32.228 +     * Returns java type signature for a object type.
  32.229 +     */
  32.230 +    public String getObjectType(String JVMobjectType) {
  32.231 +        String objectType = "";
  32.232 +        int startindex = JVMobjectType.indexOf("L")+1;
  32.233 +        int endindex =  JVMobjectType.indexOf(";");
  32.234 +        if((startindex != -1) && (endindex != -1)){
  32.235 +            if((startindex < JVMobjectType.length()) && (endindex < JVMobjectType.length())){
  32.236 +                objectType = JVMobjectType.substring(startindex, endindex);
  32.237 +            }
  32.238 +            objectType = objectType.replace('/','.');
  32.239 +            return objectType;
  32.240 +        }
  32.241 +        return null;
  32.242 +    }
  32.243 +
  32.244 +    /**
  32.245 +     * Returns java type signature for array type.
  32.246 +     */
  32.247 +    public String getArrayType(String arrayType) {
  32.248 +        if(arrayType != null){
  32.249 +            String dimention = "";
  32.250 +
  32.251 +            while(arrayType.indexOf("[") != -1){
  32.252 +                dimention += "[]";
  32.253 +
  32.254 +                int startindex = arrayType.indexOf("[")+1;
  32.255 +                if(startindex <= arrayType.length()){
  32.256 +                arrayType = arrayType.substring(startindex);
  32.257 +                }
  32.258 +            }
  32.259 +
  32.260 +            String componentType = "";
  32.261 +            if(arrayType.startsWith("L")){
  32.262 +                componentType = getObjectType(arrayType);
  32.263 +            }else {
  32.264 +                componentType = getBaseType(arrayType);
  32.265 +            }
  32.266 +            return componentType+dimention;
  32.267 +        }
  32.268 +        return null;
  32.269 +    }
  32.270 +
  32.271 +    /**
  32.272 +     * Returns java type signature for parameters.
  32.273 +     */
  32.274 +     public String getParameters(){
  32.275 +        return parameters;
  32.276 +    }
  32.277 +
  32.278 +    /**
  32.279 +     * Returns java type signature for return type.
  32.280 +     */
  32.281 +    public String getReturnType(){
  32.282 +        return returntype;
  32.283 +    }
  32.284 +
  32.285 +    /**
  32.286 +     * Returns java type signature for field type.
  32.287 +     */
  32.288 +    public String getFieldType(){
  32.289 +        return fieldtype;
  32.290 +    }
  32.291 +
  32.292 +    /**
  32.293 +     * Return number of arguments of a method.
  32.294 +     */
  32.295 +    public int getArgumentlength(){
  32.296 +        return argumentlength;
  32.297 +    }
  32.298 +}
    33.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    33.2 +++ b/javap/src/main/java/org/apidesign/javap/Vector.java	Sun Nov 18 22:03:15 2012 +0100
    33.3 @@ -0,0 +1,57 @@
    33.4 +/*
    33.5 + * To change this template, choose Tools | Templates
    33.6 + * and open the template in the editor.
    33.7 + */
    33.8 +package org.apidesign.javap;
    33.9 +
   33.10 +/** A JavaScript ready replacement for java.util.Vector
   33.11 + *
   33.12 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   33.13 + */
   33.14 +final class Vector {
   33.15 +    private Object[] arr;
   33.16 +    
   33.17 +    Vector() {
   33.18 +    }
   33.19 +
   33.20 +    Vector(int i) {
   33.21 +        this();
   33.22 +    }
   33.23 +
   33.24 +    void add(Object objectType) {
   33.25 +        addElement(objectType);
   33.26 +    }
   33.27 +    void addElement(Object obj) {
   33.28 +        final int s = size();
   33.29 +        setSize(s + 1);
   33.30 +        setElementAt(obj, s);
   33.31 +    }
   33.32 +
   33.33 +    int size() {
   33.34 +        return arr == null ? 0 : arr.length;
   33.35 +    }
   33.36 +
   33.37 +    void copyInto(Object[] newArr) {
   33.38 +        if (arr == null) {
   33.39 +            return;
   33.40 +        }
   33.41 +        int min = Math.min(newArr.length, arr.length);
   33.42 +        for (int i = 0; i < min; i++) {
   33.43 +            newArr[i] = arr[i];
   33.44 +        }
   33.45 +    }
   33.46 +
   33.47 +    Object elementAt(int index) {
   33.48 +        return arr[index];
   33.49 +    }
   33.50 +
   33.51 +    void setSize(int len) {
   33.52 +        Object[] newArr = new Object[len];
   33.53 +        copyInto(newArr);
   33.54 +        arr = newArr;
   33.55 +    }
   33.56 +
   33.57 +    void setElementAt(Object val, int index) {
   33.58 +        arr[index] = val;
   33.59 +    }
   33.60 +}
    34.1 --- a/mojo/pom.xml	Tue Nov 13 07:56:02 2012 +0100
    34.2 +++ b/mojo/pom.xml	Sun Nov 18 22:03:15 2012 +0100
    34.3 @@ -64,6 +64,12 @@
    34.4        <groupId>${project.groupId}</groupId>
    34.5        <artifactId>vm4brwsr</artifactId>
    34.6        <version>0.1-SNAPSHOT</version>
    34.7 +      <exclusions>
    34.8 +        <exclusion>
    34.9 +          <artifactId>emul</artifactId>
   34.10 +          <groupId>org.apidesign.bck2brwsr</groupId>
   34.11 +        </exclusion>
   34.12 +      </exclusions>
   34.13      </dependency>
   34.14      <dependency>
   34.15          <groupId>org.apache.maven</groupId>
    35.1 --- a/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Bck2BrswrMojo.java	Tue Nov 13 07:56:02 2012 +0100
    35.2 +++ b/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Bck2BrswrMojo.java	Sun Nov 18 22:03:15 2012 +0100
    35.3 @@ -74,10 +74,10 @@
    35.4              URLClassLoader url = buildClassLoader(classes, prj.getDependencyArtifacts());
    35.5              
    35.6              Class<?> c = Class.forName("org.apidesign.vm4brwsr.GenJS");
    35.7 -            Method m = c.getDeclaredMethod("compile", ClassLoader.class, Appendable.class, List.class);
    35.8 +            Method m = c.getDeclaredMethod("compile", ClassLoader.class, Appendable.class, String[].class);
    35.9              m.setAccessible(true);
   35.10              FileWriter w = new FileWriter(javascript);
   35.11 -            m.invoke(null, url, w, arr);
   35.12 +            m.invoke(null, url, w, arr.toArray(new String[0]));
   35.13              w.close();
   35.14          } catch (Exception ex) {
   35.15              throw new MojoExecutionException("Can't compile", ex);
    36.1 --- a/pom.xml	Tue Nov 13 07:56:02 2012 +0100
    36.2 +++ b/pom.xml	Sun Nov 18 22:03:15 2012 +0100
    36.3 @@ -12,6 +12,7 @@
    36.4      <module>core</module>
    36.5      <module>mojo</module>
    36.6      <module>javaquery</module>
    36.7 +    <module>javap</module>
    36.8    </modules>
    36.9    <licenses>
   36.10        <license>
   36.11 @@ -66,6 +67,7 @@
   36.12                    <strictCheck>true</strictCheck>
   36.13                    <excludes>
   36.14                         <exclude>emul/**</exclude>
   36.15 +                       <exclude>javap/**</exclude>
   36.16                         <exclude>*</exclude>
   36.17                         <exclude>.*/**</exclude>
   36.18                    </excludes>
   36.19 @@ -105,4 +107,4 @@
   36.20    <properties>
   36.21        <license>COPYING</license>
   36.22    </properties>
   36.23 -</project>
   36.24 \ No newline at end of file
   36.25 +</project>
    37.1 --- a/vm/pom.xml	Tue Nov 13 07:56:02 2012 +0100
    37.2 +++ b/vm/pom.xml	Sun Nov 18 22:03:15 2012 +0100
    37.3 @@ -83,11 +83,6 @@
    37.4        </exclusions>
    37.5      </dependency>
    37.6      <dependency>
    37.7 -      <groupId>org.netbeans.api</groupId>
    37.8 -      <artifactId>org-netbeans-modules-classfile</artifactId>
    37.9 -      <type>jar</type>
   37.10 -    </dependency>
   37.11 -    <dependency>
   37.12        <groupId>org.apidesign.bck2brwsr</groupId>
   37.13        <artifactId>core</artifactId>
   37.14        <version>1.0-SNAPSHOT</version>
   37.15 @@ -99,5 +94,10 @@
   37.16        <version>1.0-SNAPSHOT</version>
   37.17        <scope>test</scope>
   37.18      </dependency>
   37.19 +    <dependency>
   37.20 +      <groupId>${project.groupId}</groupId>
   37.21 +      <artifactId>javap</artifactId>
   37.22 +      <version>1.0-SNAPSHOT</version>
   37.23 +    </dependency>
   37.24    </dependencies>
   37.25  </project>
    38.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Tue Nov 13 07:56:02 2012 +0100
    38.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java	Sun Nov 18 22:03:15 2012 +0100
    38.3 @@ -19,104 +19,81 @@
    38.4  
    38.5  import java.io.IOException;
    38.6  import java.io.InputStream;
    38.7 -import java.util.ArrayList;
    38.8 -import java.util.Collection;
    38.9 -import java.util.List;
   38.10 -import org.apidesign.bck2brwsr.core.ExtraJavaScript;
   38.11  import org.apidesign.bck2brwsr.core.JavaScriptBody;
   38.12 -import org.netbeans.modules.classfile.Annotation;
   38.13 -import org.netbeans.modules.classfile.AnnotationComponent;
   38.14 -import org.netbeans.modules.classfile.ArrayElementValue;
   38.15 -import static org.netbeans.modules.classfile.ByteCodes.*;
   38.16 -import org.netbeans.modules.classfile.CPClassInfo;
   38.17 -import org.netbeans.modules.classfile.CPEntry;
   38.18 -import org.netbeans.modules.classfile.CPFieldInfo;
   38.19 -import org.netbeans.modules.classfile.CPMethodInfo;
   38.20 -import org.netbeans.modules.classfile.CPStringInfo;
   38.21 -import org.netbeans.modules.classfile.ClassFile;
   38.22 -import org.netbeans.modules.classfile.ClassName;
   38.23 -import org.netbeans.modules.classfile.Code;
   38.24 -import org.netbeans.modules.classfile.ElementValue;
   38.25 -import org.netbeans.modules.classfile.Method;
   38.26 -import org.netbeans.modules.classfile.Parameter;
   38.27 -import org.netbeans.modules.classfile.PrimitiveElementValue;
   38.28 -import org.netbeans.modules.classfile.Variable;
   38.29 +import org.apidesign.javap.AnnotationParser;
   38.30 +import org.apidesign.javap.ClassData;
   38.31 +import org.apidesign.javap.FieldData;
   38.32 +import org.apidesign.javap.MethodData;
   38.33 +import static org.apidesign.javap.RuntimeConstants.*;
   38.34  
   38.35  /** Translator of the code inside class files to JavaScript.
   38.36   *
   38.37   * @author Jaroslav Tulach <jtulach@netbeans.org>
   38.38   */
   38.39 -public final class ByteCodeToJavaScript {
   38.40 -    private final ClassFile jc;
   38.41 +public abstract class ByteCodeToJavaScript {
   38.42 +    private ClassData jc;
   38.43      private final Appendable out;
   38.44 -    private final Collection<? super String> references;
   38.45  
   38.46 -    private ByteCodeToJavaScript(
   38.47 -        ClassFile jc, Appendable out, Collection<? super String> references
   38.48 -    ) {
   38.49 -        this.jc = jc;
   38.50 +    protected ByteCodeToJavaScript(Appendable out) {
   38.51          this.out = out;
   38.52 -        this.references = references;
   38.53      }
   38.54 +    
   38.55 +    /* Collects additional required resources.
   38.56 +     * 
   38.57 +     * @param internalClassName classes that were referenced and should be loaded in order the
   38.58 +     *   generated JavaScript code works properly. The names are in internal 
   38.59 +     *   JVM form so String is <code>java/lang/String</code>. 
   38.60 +     */
   38.61 +    protected abstract boolean requireReference(String internalClassName);
   38.62 +    
   38.63 +    /*
   38.64 +     * @param resourcePath name of resources to read
   38.65 +     */
   38.66 +    protected abstract void requireScript(String resourcePath);
   38.67  
   38.68      /**
   38.69       * Converts a given class file to a JavaScript version.
   38.70       *
   38.71       * @param classFile input stream with code of the .class file
   38.72 -     * @param out a {@link StringBuilder} or similar to generate the output to
   38.73 -     * @param references a write only collection where the system adds list of
   38.74 -     *   other classes that were referenced and should be loaded in order the
   38.75 -     *   generated JavaScript code works properly. The names are in internal 
   38.76 -     *   JVM form so String is <code>java/lang/String</code>. Can be <code>null</code>
   38.77 -     *   if one is not interested in knowing references
   38.78 -     * @param scripts write only collection with names of resources to read
   38.79       * @return the initialization code for this class, if any. Otherwise <code>null</code>
   38.80       * 
   38.81       * @throws IOException if something goes wrong during read or write or translating
   38.82       */
   38.83      
   38.84 -    public static String compile(
   38.85 -        InputStream classFile, Appendable out,
   38.86 -        Collection<? super String> references,
   38.87 -        Collection<? super String> scripts
   38.88 -    ) throws IOException {
   38.89 -        ClassFile jc = new ClassFile(classFile, true);
   38.90 -        final ClassName extraAnn = ClassName.getClassName(ExtraJavaScript.class.getName().replace('.', '/'));
   38.91 -        Annotation a = jc.getAnnotation(extraAnn);
   38.92 -        if (a != null) {
   38.93 -            final ElementValue annVal = a.getComponent("resource").getValue();
   38.94 -            String res = ((PrimitiveElementValue)annVal).getValue().getValue().toString();
   38.95 -            scripts.add(res);
   38.96 -            final AnnotationComponent process = a.getComponent("processByteCode");
   38.97 -            if (process != null && "const=0".equals(process.getValue().toString())) {
   38.98 +    public String compile(InputStream classFile) throws IOException {
   38.99 +        this.jc = new ClassData(classFile);
  38.100 +        byte[] arrData = jc.findAnnotationData(true);
  38.101 +        String[] arr = findAnnotation(arrData, jc, 
  38.102 +            "org.apidesign.bck2brwsr.core.ExtraJavaScript", 
  38.103 +            "resource", "processByteCode"
  38.104 +        );
  38.105 +        if (arr != null) {
  38.106 +            requireScript(arr[0]);
  38.107 +            if ("0".equals(arr[1])) {
  38.108                  return null;
  38.109              }
  38.110          }
  38.111 -        
  38.112 -        ByteCodeToJavaScript compiler = new ByteCodeToJavaScript(
  38.113 -            jc, out, references
  38.114 -        );
  38.115 -        List<String> toInitilize = new ArrayList<String>();
  38.116 -        for (Method m : jc.getMethods()) {
  38.117 +        StringArray toInitilize = new StringArray();
  38.118 +        for (MethodData m : jc.getMethods()) {
  38.119              if (m.isStatic()) {
  38.120 -                compiler.generateStaticMethod(m, toInitilize);
  38.121 +                generateStaticMethod(m, toInitilize);
  38.122              } else {
  38.123 -                compiler.generateInstanceMethod(m);
  38.124 +                generateInstanceMethod(m);
  38.125              }
  38.126          }
  38.127 -        for (Variable v : jc.getVariables()) {
  38.128 +        for (FieldData v : jc.getFields()) {
  38.129              if (v.isStatic()) {
  38.130 -                compiler.generateStaticField(v);
  38.131 +                generateStaticField(v);
  38.132              }
  38.133          }
  38.134          
  38.135 -        final String className = jc.getName().getInternalName().replace('/', '_');
  38.136 +        final String className = className(jc);
  38.137          out.append("\nfunction ").append(className);
  38.138          out.append("() {");
  38.139 -        for (Variable v : jc.getVariables()) {
  38.140 +        for (FieldData v : jc.getFields()) {
  38.141              if (!v.isStatic()) {
  38.142                  out.append("\n  this.fld_").
  38.143 -                    append(v.getName()).append(" = 0;");
  38.144 +                    append(v.getName()).append(initField(v));
  38.145              }
  38.146          }
  38.147          out.append("\n}\n\nfunction ").append(className).append("_proto() {");
  38.148 @@ -124,112 +101,112 @@
  38.149              append(".prototype.$instOf_").append(className).append(") {");
  38.150          out.append("\n    return new ").append(className).append(";");
  38.151          out.append("\n  }");
  38.152 -        ClassName sc = jc.getSuperClass();
  38.153 +        // ClassName sc = jc.getSuperClass();
  38.154 +        String sc = jc.getSuperClassName(); // with _
  38.155          if (sc != null) {
  38.156              out.append("\n  var p = ").append(className)
  38.157                 .append(".prototype = ").
  38.158 -                append(sc.getInternalName().replace('/', '_')).append("_proto();");
  38.159 +                append(sc.replace('/', '_')).append("_proto();");
  38.160          } else {
  38.161              out.append("\n  var p = ").append(className).append(".prototype;");
  38.162          }
  38.163 -        for (Method m : jc.getMethods()) {
  38.164 +        for (MethodData m : jc.getMethods()) {
  38.165              if (!m.getName().contains("<init>") && !m.getName().contains("<cinit>")) {
  38.166 -                compiler.generateMethodReference("\n  p.", m);
  38.167 +                generateMethodReference("\n  p.", m);
  38.168              }
  38.169          }
  38.170          out.append("\n  p.$instOf_").append(className).append(" = true;");
  38.171 -        for (ClassName superInterface : jc.getInterfaces()) {
  38.172 -            out.append("\n  p.$instOf_").append(superInterface.getInternalName().replace('/', '_')).append(" = true;");
  38.173 +        for (String superInterface : jc.getSuperInterfaces()) {
  38.174 +            out.append("\n  p.$instOf_").append(superInterface.replace('/', '_')).append(" = true;");
  38.175          }
  38.176          out.append("\n  return new ").append(className).append(";");
  38.177          out.append("\n}");
  38.178          out.append("\n").append(className).append("_proto();");
  38.179          StringBuilder sb = new StringBuilder();
  38.180 -        for (String init : toInitilize) {
  38.181 +        for (String init : toInitilize.toArray()) {
  38.182              sb.append("\n").append(init).append("();");
  38.183          }
  38.184          return sb.toString();
  38.185      }
  38.186 -    private void generateStaticMethod(Method m, List<String> toInitilize) throws IOException {
  38.187 +    private void generateStaticMethod(MethodData m, StringArray toInitilize) throws IOException {
  38.188          if (javaScriptBody(m, true)) {
  38.189              return;
  38.190          }
  38.191 -        final String mn = findMethodName(m);
  38.192 +        StringBuilder argsCnt = new StringBuilder();
  38.193 +        final String mn = findMethodName(m, argsCnt);
  38.194          out.append("\nfunction ").append(
  38.195 -            jc.getName().getInternalName().replace('/', '_')
  38.196 +            className(jc)
  38.197          ).append('_').append(mn);
  38.198          if (mn.equals("classV")) {
  38.199 -            toInitilize.add(jc.getName().getInternalName().replace('/', '_') + '_' + mn);
  38.200 +            toInitilize.add(className(jc) + '_' + mn);
  38.201          }
  38.202          out.append('(');
  38.203          String space = "";
  38.204 -        List<Parameter> args = m.getParameters();
  38.205 -        for (int index = 0, i = 0; i < args.size(); i++) {
  38.206 +        for (int index = 0, i = 0; i < argsCnt.length(); i++) {
  38.207              out.append(space);
  38.208              out.append("arg").append(String.valueOf(index));
  38.209              space = ",";
  38.210 -            final String desc = findDescriptor(args.get(i).getDescriptor());
  38.211 -            if ("D".equals(desc) || "J".equals(desc)) {
  38.212 +            final String desc = null;// XXX findDescriptor(args.get(i).getDescriptor());
  38.213 +            if (argsCnt.charAt(i) == '1') {
  38.214                  index += 2;
  38.215              } else {
  38.216                  index++;
  38.217              }
  38.218          }
  38.219          out.append(") {").append("\n");
  38.220 -        final Code code = m.getCode();
  38.221 +        final byte[] code = m.getCode();
  38.222          if (code != null) {
  38.223 -            int len = code.getMaxLocals();
  38.224 -            for (int index = args.size(), i = args.size(); i < len; i++) {
  38.225 +            int len = m.getMaxLocals();
  38.226 +            for (int index = argsCnt.length(), i = argsCnt.length(); i < len; i++) {
  38.227                  out.append("  var ");
  38.228                  out.append("arg").append(String.valueOf(i)).append(";\n");
  38.229              }
  38.230              out.append("  var stack = new Array();\n");
  38.231 -            produceCode(code.getByteCodes());
  38.232 +            produceCode(code);
  38.233          } else {
  38.234 -            out.append("  /* no code found for ").append(m.getTypeSignature()).append(" */\n");
  38.235 +            out.append("  /* no code found for ").append(m.getInternalSig()).append(" */\n");
  38.236          }
  38.237          out.append("}");
  38.238      }
  38.239      
  38.240 -    private void generateMethodReference(String prefix, Method m) throws IOException {
  38.241 -        final String name = findMethodName(m);
  38.242 +    private void generateMethodReference(String prefix, MethodData m) throws IOException {
  38.243 +        final String name = findMethodName(m, new StringBuilder());
  38.244          out.append(prefix).append(name).append(" = ")
  38.245 -           .append(jc.getName().getInternalName().replace('/', '_'))
  38.246 +           .append(className(jc))
  38.247             .append('_').append(name).append(";");
  38.248      }
  38.249      
  38.250 -    private void generateInstanceMethod(Method m) throws IOException {
  38.251 +    private void generateInstanceMethod(MethodData m) throws IOException {
  38.252          if (javaScriptBody(m, false)) {
  38.253              return;
  38.254          }
  38.255 +        StringBuilder argsCnt = new StringBuilder();
  38.256          out.append("\nfunction ").append(
  38.257 -            jc.getName().getInternalName().replace('/', '_')
  38.258 -        ).append('_').append(findMethodName(m));
  38.259 +            className(jc)
  38.260 +        ).append('_').append(findMethodName(m, argsCnt));
  38.261          out.append("(arg0");
  38.262          String space = ",";
  38.263 -        List<Parameter> args = m.getParameters();
  38.264 -        for (int index = 1, i = 0; i < args.size(); i++) {
  38.265 +        for (int index = 1, i = 0; i < argsCnt.length(); i++) {
  38.266              out.append(space);
  38.267              out.append("arg").append(String.valueOf(index));
  38.268 -            final String desc = findDescriptor(args.get(i).getDescriptor());
  38.269 -            if ("D".equals(desc) || "J".equals(desc)) {
  38.270 +            if (argsCnt.charAt(i) == '1') {
  38.271                  index += 2;
  38.272              } else {
  38.273                  index++;
  38.274              }
  38.275          }
  38.276          out.append(") {").append("\n");
  38.277 -        final Code code = m.getCode();
  38.278 +        final byte[] code = m.getCode();
  38.279          if (code != null) {
  38.280 -            int len = code.getMaxLocals();
  38.281 -            for (int index = args.size(), i = args.size(); i < len; i++) {
  38.282 +            int len = m.getMaxLocals();
  38.283 +            for (int index = argsCnt.length(), i = argsCnt.length(); i < len; i++) {
  38.284                  out.append("  var ");
  38.285                  out.append("arg").append(String.valueOf(i + 1)).append(";\n");
  38.286              }
  38.287              out.append(";\n  var stack = new Array();\n");
  38.288 -            produceCode(code.getByteCodes());
  38.289 +            produceCode(code);
  38.290          } else {
  38.291 -            out.append("  /* no code found for ").append(m.getTypeSignature()).append(" */\n");
  38.292 +            out.append("  /* no code found for ").append(m.getInternalSig()).append(" */\n");
  38.293          }
  38.294          out.append("}");
  38.295      }
  38.296 @@ -241,137 +218,143 @@
  38.297              out.append("    case " + i).append(": ");
  38.298              final int c = readByte(byteCodes, i);
  38.299              switch (c) {
  38.300 -                case bc_aload_0:
  38.301 -                case bc_iload_0:
  38.302 -                case bc_lload_0:
  38.303 -                case bc_fload_0:
  38.304 -                case bc_dload_0:
  38.305 +                case opc_aload_0:
  38.306 +                case opc_iload_0:
  38.307 +                case opc_lload_0:
  38.308 +                case opc_fload_0:
  38.309 +                case opc_dload_0:
  38.310                      out.append("stack.push(arg0);");
  38.311                      break;
  38.312 -                case bc_aload_1:
  38.313 -                case bc_iload_1:
  38.314 -                case bc_lload_1:
  38.315 -                case bc_fload_1:
  38.316 -                case bc_dload_1:
  38.317 +                case opc_aload_1:
  38.318 +                case opc_iload_1:
  38.319 +                case opc_lload_1:
  38.320 +                case opc_fload_1:
  38.321 +                case opc_dload_1:
  38.322                      out.append("stack.push(arg1);");
  38.323                      break;
  38.324 -                case bc_aload_2:
  38.325 -                case bc_iload_2:
  38.326 -                case bc_lload_2:
  38.327 -                case bc_fload_2:
  38.328 -                case bc_dload_2:
  38.329 +                case opc_aload_2:
  38.330 +                case opc_iload_2:
  38.331 +                case opc_lload_2:
  38.332 +                case opc_fload_2:
  38.333 +                case opc_dload_2:
  38.334                      out.append("stack.push(arg2);");
  38.335                      break;
  38.336 -                case bc_aload_3:
  38.337 -                case bc_iload_3:
  38.338 -                case bc_lload_3:
  38.339 -                case bc_fload_3:
  38.340 -                case bc_dload_3:
  38.341 +                case opc_aload_3:
  38.342 +                case opc_iload_3:
  38.343 +                case opc_lload_3:
  38.344 +                case opc_fload_3:
  38.345 +                case opc_dload_3:
  38.346                      out.append("stack.push(arg3);");
  38.347                      break;
  38.348 -                case bc_iload:
  38.349 -                case bc_lload:
  38.350 -                case bc_fload:
  38.351 -                case bc_dload:
  38.352 -                case bc_aload: {
  38.353 +                case opc_iload:
  38.354 +                case opc_lload:
  38.355 +                case opc_fload:
  38.356 +                case opc_dload:
  38.357 +                case opc_aload: {
  38.358                      final int indx = readByte(byteCodes, ++i);
  38.359                      out.append("stack.push(arg").append(indx + ");");
  38.360                      break;
  38.361                  }
  38.362 -                case bc_istore:
  38.363 -                case bc_lstore:
  38.364 -                case bc_fstore:
  38.365 -                case bc_dstore:
  38.366 -                case bc_astore: {
  38.367 +                case opc_istore:
  38.368 +                case opc_lstore:
  38.369 +                case opc_fstore:
  38.370 +                case opc_dstore:
  38.371 +                case opc_astore: {
  38.372                      final int indx = readByte(byteCodes, ++i);
  38.373 -                    out.append("arg" + indx).append(" = stack.pop()");
  38.374 +                    out.append("arg" + indx).append(" = stack.pop();");
  38.375                      break;
  38.376                  }
  38.377 -                case bc_astore_0:
  38.378 -                case bc_istore_0:
  38.379 -                case bc_lstore_0:
  38.380 -                case bc_fstore_0:
  38.381 -                case bc_dstore_0:
  38.382 +                case opc_astore_0:
  38.383 +                case opc_istore_0:
  38.384 +                case opc_lstore_0:
  38.385 +                case opc_fstore_0:
  38.386 +                case opc_dstore_0:
  38.387                      out.append("arg0 = stack.pop();");
  38.388                      break;
  38.389 -                case bc_astore_1:
  38.390 -                case bc_istore_1:
  38.391 -                case bc_lstore_1:
  38.392 -                case bc_fstore_1:
  38.393 -                case bc_dstore_1:
  38.394 +                case opc_astore_1:
  38.395 +                case opc_istore_1:
  38.396 +                case opc_lstore_1:
  38.397 +                case opc_fstore_1:
  38.398 +                case opc_dstore_1:
  38.399                      out.append("arg1 = stack.pop();");
  38.400                      break;
  38.401 -                case bc_astore_2:
  38.402 -                case bc_istore_2:
  38.403 -                case bc_lstore_2:
  38.404 -                case bc_fstore_2:
  38.405 -                case bc_dstore_2:
  38.406 +                case opc_astore_2:
  38.407 +                case opc_istore_2:
  38.408 +                case opc_lstore_2:
  38.409 +                case opc_fstore_2:
  38.410 +                case opc_dstore_2:
  38.411                      out.append("arg2 = stack.pop();");
  38.412                      break;
  38.413 -                case bc_astore_3:
  38.414 -                case bc_istore_3:
  38.415 -                case bc_lstore_3:
  38.416 -                case bc_fstore_3:
  38.417 -                case bc_dstore_3:
  38.418 +                case opc_astore_3:
  38.419 +                case opc_istore_3:
  38.420 +                case opc_lstore_3:
  38.421 +                case opc_fstore_3:
  38.422 +                case opc_dstore_3:
  38.423                      out.append("arg3 = stack.pop();");
  38.424                      break;
  38.425 -                case bc_iadd:
  38.426 -                case bc_ladd:
  38.427 -                case bc_fadd:
  38.428 -                case bc_dadd:
  38.429 +                case opc_iadd:
  38.430 +                case opc_ladd:
  38.431 +                case opc_fadd:
  38.432 +                case opc_dadd:
  38.433                      out.append("stack.push(stack.pop() + stack.pop());");
  38.434                      break;
  38.435 -                case bc_isub:
  38.436 -                case bc_lsub:
  38.437 -                case bc_fsub:
  38.438 -                case bc_dsub:
  38.439 +                case opc_isub:
  38.440 +                case opc_lsub:
  38.441 +                case opc_fsub:
  38.442 +                case opc_dsub:
  38.443                      out.append("{ var tmp = stack.pop(); stack.push(stack.pop() - tmp); }");
  38.444                      break;
  38.445 -                case bc_imul:
  38.446 -                case bc_lmul:
  38.447 -                case bc_fmul:
  38.448 -                case bc_dmul:
  38.449 +                case opc_imul:
  38.450 +                case opc_lmul:
  38.451 +                case opc_fmul:
  38.452 +                case opc_dmul:
  38.453                      out.append("stack.push(stack.pop() * stack.pop());");
  38.454                      break;
  38.455 -                case bc_idiv:
  38.456 -                case bc_ldiv:
  38.457 +                case opc_idiv:
  38.458 +                case opc_ldiv:
  38.459                      out.append("{ var tmp = stack.pop(); stack.push(Math.floor(stack.pop() / tmp)); }");
  38.460                      break;
  38.461 -                case bc_fdiv:
  38.462 -                case bc_ddiv:
  38.463 +                case opc_fdiv:
  38.464 +                case opc_ddiv:
  38.465                      out.append("{ var tmp = stack.pop(); stack.push(stack.pop() / tmp); }");
  38.466                      break;
  38.467 -                case bc_iand:
  38.468 -                case bc_land:
  38.469 +                case opc_irem:
  38.470 +                case opc_lrem:
  38.471 +                case opc_frem:
  38.472 +                case opc_drem:
  38.473 +                    out.append("{ var d = stack.pop(); stack.push(stack.pop() % d); }");
  38.474 +                    break;
  38.475 +                case opc_iand:
  38.476 +                case opc_land:
  38.477                      out.append("stack.push(stack.pop() & stack.pop());");
  38.478                      break;
  38.479 -                case bc_ior:
  38.480 -                case bc_lor:
  38.481 +                case opc_ior:
  38.482 +                case opc_lor:
  38.483                      out.append("stack.push(stack.pop() | stack.pop());");
  38.484                      break;
  38.485 -                case bc_ixor:
  38.486 -                case bc_lxor:
  38.487 +                case opc_ixor:
  38.488 +                case opc_lxor:
  38.489                      out.append("stack.push(stack.pop() ^ stack.pop());");
  38.490                      break;
  38.491 -                case bc_ineg:
  38.492 -                case bc_lneg:
  38.493 -                case bc_fneg:
  38.494 -                case bc_dneg:
  38.495 +                case opc_ineg:
  38.496 +                case opc_lneg:
  38.497 +                case opc_fneg:
  38.498 +                case opc_dneg:
  38.499                      out.append("stack.push(- stack.pop());");
  38.500                      break;
  38.501 -                case bc_ishl:
  38.502 -                case bc_lshl:
  38.503 +                case opc_ishl:
  38.504 +                case opc_lshl:
  38.505                      out.append("{ var v = stack.pop(); stack.push(stack.pop() << v); }");
  38.506                      break;
  38.507 -                case bc_ishr:
  38.508 -                case bc_lshr:
  38.509 +                case opc_ishr:
  38.510 +                case opc_lshr:
  38.511                      out.append("{ var v = stack.pop(); stack.push(stack.pop() >> v); }");
  38.512                      break;
  38.513 -                case bc_iushr:
  38.514 -                case bc_lushr:
  38.515 +                case opc_iushr:
  38.516 +                case opc_lushr:
  38.517                      out.append("{ var v = stack.pop(); stack.push(stack.pop() >>> v); }");
  38.518                      break;
  38.519 -                case bc_iinc: {
  38.520 +                case opc_iinc: {
  38.521                      final int varIndx = readByte(byteCodes, ++i);
  38.522                      final int incrBy = byteCodes[++i];
  38.523                      if (incrBy == 1) {
  38.524 @@ -381,181 +364,179 @@
  38.525                      }
  38.526                      break;
  38.527                  }
  38.528 -                case bc_return:
  38.529 +                case opc_return:
  38.530                      out.append("return;");
  38.531                      break;
  38.532 -                case bc_ireturn:
  38.533 -                case bc_lreturn:
  38.534 -                case bc_freturn:
  38.535 -                case bc_dreturn:
  38.536 -                case bc_areturn:
  38.537 +                case opc_ireturn:
  38.538 +                case opc_lreturn:
  38.539 +                case opc_freturn:
  38.540 +                case opc_dreturn:
  38.541 +                case opc_areturn:
  38.542                      out.append("return stack.pop();");
  38.543                      break;
  38.544 -                case bc_i2l:
  38.545 -                case bc_i2f:
  38.546 -                case bc_i2d:
  38.547 -                case bc_l2i:
  38.548 +                case opc_i2l:
  38.549 +                case opc_i2f:
  38.550 +                case opc_i2d:
  38.551 +                case opc_l2i:
  38.552                      // max int check?
  38.553 -                case bc_l2f:
  38.554 -                case bc_l2d:
  38.555 -                case bc_f2d:
  38.556 -                case bc_d2f:
  38.557 +                case opc_l2f:
  38.558 +                case opc_l2d:
  38.559 +                case opc_f2d:
  38.560 +                case opc_d2f:
  38.561                      out.append("/* number conversion */");
  38.562                      break;
  38.563 -                case bc_f2i:
  38.564 -                case bc_f2l:
  38.565 -                case bc_d2i:
  38.566 -                case bc_d2l:
  38.567 +                case opc_f2i:
  38.568 +                case opc_f2l:
  38.569 +                case opc_d2i:
  38.570 +                case opc_d2l:
  38.571                      out.append("stack.push(Math.floor(stack.pop()));");
  38.572                      break;
  38.573 -                case bc_i2b:
  38.574 -                case bc_i2c:
  38.575 -                case bc_i2s:
  38.576 +                case opc_i2b:
  38.577 +                case opc_i2c:
  38.578 +                case opc_i2s:
  38.579                      out.append("/* number conversion */");
  38.580                      break;
  38.581 -                case bc_aconst_null:
  38.582 +                case opc_aconst_null:
  38.583                      out.append("stack.push(null);");
  38.584                      break;
  38.585 -                case bc_iconst_m1:
  38.586 +                case opc_iconst_m1:
  38.587                      out.append("stack.push(-1);");
  38.588                      break;
  38.589 -                case bc_iconst_0:
  38.590 -                case bc_dconst_0:
  38.591 -                case bc_lconst_0:
  38.592 -                case bc_fconst_0:
  38.593 +                case opc_iconst_0:
  38.594 +                case opc_dconst_0:
  38.595 +                case opc_lconst_0:
  38.596 +                case opc_fconst_0:
  38.597                      out.append("stack.push(0);");
  38.598                      break;
  38.599 -                case bc_iconst_1:
  38.600 -                case bc_lconst_1:
  38.601 -                case bc_fconst_1:
  38.602 -                case bc_dconst_1:
  38.603 +                case opc_iconst_1:
  38.604 +                case opc_lconst_1:
  38.605 +                case opc_fconst_1:
  38.606 +                case opc_dconst_1:
  38.607                      out.append("stack.push(1);");
  38.608                      break;
  38.609 -                case bc_iconst_2:
  38.610 -                case bc_fconst_2:
  38.611 +                case opc_iconst_2:
  38.612 +                case opc_fconst_2:
  38.613                      out.append("stack.push(2);");
  38.614                      break;
  38.615 -                case bc_iconst_3:
  38.616 +                case opc_iconst_3:
  38.617                      out.append("stack.push(3);");
  38.618                      break;
  38.619 -                case bc_iconst_4:
  38.620 +                case opc_iconst_4:
  38.621                      out.append("stack.push(4);");
  38.622                      break;
  38.623 -                case bc_iconst_5:
  38.624 +                case opc_iconst_5:
  38.625                      out.append("stack.push(5);");
  38.626                      break;
  38.627 -                case bc_ldc: {
  38.628 +                case opc_ldc: {
  38.629                      int indx = readByte(byteCodes, ++i);
  38.630 -                    CPEntry entry = jc.getConstantPool().get(indx);
  38.631 -                    String v = encodeConstant(entry);
  38.632 +                    String v = encodeConstant(indx);
  38.633                      out.append("stack.push(").append(v).append(");");
  38.634                      break;
  38.635                  }
  38.636 -                case bc_ldc_w:
  38.637 -                case bc_ldc2_w: {
  38.638 +                case opc_ldc_w:
  38.639 +                case opc_ldc2_w: {
  38.640                      int indx = readIntArg(byteCodes, i);
  38.641 -                    CPEntry entry = jc.getConstantPool().get(indx);
  38.642                      i += 2;
  38.643 -                    String v = encodeConstant(entry);
  38.644 +                    String v = encodeConstant(indx);
  38.645                      out.append("stack.push(").append(v).append(");");
  38.646                      break;
  38.647                  }
  38.648 -                case bc_lcmp:
  38.649 -                case bc_fcmpl:
  38.650 -                case bc_fcmpg:
  38.651 -                case bc_dcmpl:
  38.652 -                case bc_dcmpg: {
  38.653 +                case opc_lcmp:
  38.654 +                case opc_fcmpl:
  38.655 +                case opc_fcmpg:
  38.656 +                case opc_dcmpl:
  38.657 +                case opc_dcmpg: {
  38.658                      out.append("{ var delta = stack.pop() - stack.pop(); stack.push(delta < 0 ?-1 : (delta == 0 ? 0 : 1)); }");
  38.659                      break;
  38.660                  }
  38.661 -                case bc_if_acmpeq:
  38.662 +                case opc_if_acmpeq:
  38.663                      i = generateIf(byteCodes, i, "===");
  38.664                      break;
  38.665 -                case bc_if_acmpne:
  38.666 +                case opc_if_acmpne:
  38.667                      i = generateIf(byteCodes, i, "!=");
  38.668                      break;
  38.669 -                case bc_if_icmpeq: {
  38.670 +                case opc_if_icmpeq: {
  38.671                      i = generateIf(byteCodes, i, "==");
  38.672                      break;
  38.673                  }
  38.674 -                case bc_ifeq: {
  38.675 +                case opc_ifeq: {
  38.676                      int indx = i + readIntArg(byteCodes, i);
  38.677                      out.append("if (stack.pop() == 0) { gt = " + indx);
  38.678                      out.append("; continue; }");
  38.679                      i += 2;
  38.680                      break;
  38.681                  }
  38.682 -                case bc_ifne: {
  38.683 +                case opc_ifne: {
  38.684                      int indx = i + readIntArg(byteCodes, i);
  38.685                      out.append("if (stack.pop() != 0) { gt = " + indx);
  38.686                      out.append("; continue; }");
  38.687                      i += 2;
  38.688                      break;
  38.689                  }
  38.690 -                case bc_iflt: {
  38.691 +                case opc_iflt: {
  38.692                      int indx = i + readIntArg(byteCodes, i);
  38.693                      out.append("if (stack.pop() < 0) { gt = " + indx);
  38.694                      out.append("; continue; }");
  38.695                      i += 2;
  38.696                      break;
  38.697                  }
  38.698 -                case bc_ifle: {
  38.699 +                case opc_ifle: {
  38.700                      int indx = i + readIntArg(byteCodes, i);
  38.701                      out.append("if (stack.pop() <= 0) { gt = " + indx);
  38.702                      out.append("; continue; }");
  38.703                      i += 2;
  38.704                      break;
  38.705                  }
  38.706 -                case bc_ifgt: {
  38.707 +                case opc_ifgt: {
  38.708                      int indx = i + readIntArg(byteCodes, i);
  38.709                      out.append("if (stack.pop() > 0) { gt = " + indx);
  38.710                      out.append("; continue; }");
  38.711                      i += 2;
  38.712                      break;
  38.713                  }
  38.714 -                case bc_ifge: {
  38.715 +                case opc_ifge: {
  38.716                      int indx = i + readIntArg(byteCodes, i);
  38.717                      out.append("if (stack.pop() >= 0) { gt = " + indx);
  38.718                      out.append("; continue; }");
  38.719                      i += 2;
  38.720                      break;
  38.721                  }
  38.722 -                case bc_ifnonnull: {
  38.723 +                case opc_ifnonnull: {
  38.724                      int indx = i + readIntArg(byteCodes, i);
  38.725 -                    out.append("if (stack.pop()) { gt = " + indx);
  38.726 +                    out.append("if (stack.pop() !== null) { gt = " + indx);
  38.727                      out.append("; continue; }");
  38.728                      i += 2;
  38.729                      break;
  38.730                  }
  38.731 -                case bc_ifnull: {
  38.732 +                case opc_ifnull: {
  38.733                      int indx = i + readIntArg(byteCodes, i);
  38.734 -                    out.append("if (!stack.pop()) { gt = " + indx);
  38.735 +                    out.append("if (stack.pop() === null) { gt = " + indx);
  38.736                      out.append("; continue; }");
  38.737                      i += 2;
  38.738                      break;
  38.739                  }
  38.740 -                case bc_if_icmpne:
  38.741 +                case opc_if_icmpne:
  38.742                      i = generateIf(byteCodes, i, "!=");
  38.743                      break;
  38.744 -                case bc_if_icmplt:
  38.745 +                case opc_if_icmplt:
  38.746                      i = generateIf(byteCodes, i, ">");
  38.747                      break;
  38.748 -                case bc_if_icmple:
  38.749 +                case opc_if_icmple:
  38.750                      i = generateIf(byteCodes, i, ">=");
  38.751                      break;
  38.752 -                case bc_if_icmpgt:
  38.753 +                case opc_if_icmpgt:
  38.754                      i = generateIf(byteCodes, i, "<");
  38.755                      break;
  38.756 -                case bc_if_icmpge:
  38.757 +                case opc_if_icmpge:
  38.758                      i = generateIf(byteCodes, i, "<=");
  38.759                      break;
  38.760 -                case bc_goto: {
  38.761 +                case opc_goto: {
  38.762                      int indx = i + readIntArg(byteCodes, i);
  38.763                      out.append("gt = " + indx).append("; continue;");
  38.764                      i += 2;
  38.765                      break;
  38.766                  }
  38.767 -                case bc_lookupswitch: {
  38.768 +                case opc_lookupswitch: {
  38.769                      int table = i / 4 * 4 + 4;
  38.770                      int dflt = i + readInt4(byteCodes, table);
  38.771                      table += 4;
  38.772 @@ -573,7 +554,7 @@
  38.773                      i = table - 1;
  38.774                      break;
  38.775                  }
  38.776 -                case bc_tableswitch: {
  38.777 +                case opc_tableswitch: {
  38.778                      int table = i / 4 * 4 + 4;
  38.779                      int dflt = i + readInt4(byteCodes, table);
  38.780                      table += 4;
  38.781 @@ -592,50 +573,50 @@
  38.782                      i = table - 1;
  38.783                      break;
  38.784                  }
  38.785 -                case bc_invokeinterface: {
  38.786 +                case opc_invokeinterface: {
  38.787                      i = invokeVirtualMethod(byteCodes, i) + 2;
  38.788                      break;
  38.789                  }
  38.790 -                case bc_invokevirtual:
  38.791 +                case opc_invokevirtual:
  38.792                      i = invokeVirtualMethod(byteCodes, i);
  38.793                      break;
  38.794 -                case bc_invokespecial:
  38.795 +                case opc_invokespecial:
  38.796                      i = invokeStaticMethod(byteCodes, i, false);
  38.797                      break;
  38.798 -                case bc_invokestatic:
  38.799 +                case opc_invokestatic:
  38.800                      i = invokeStaticMethod(byteCodes, i, true);
  38.801                      break;
  38.802 -                case bc_new: {
  38.803 +                case opc_new: {
  38.804                      int indx = readIntArg(byteCodes, i);
  38.805 -                    CPClassInfo ci = jc.getConstantPool().getClass(indx);
  38.806 +                    String ci = jc.getClassName(indx);
  38.807                      out.append("stack.push(");
  38.808 -                    out.append("new ").append(ci.getClassName().getInternalName().replace('/','_'));
  38.809 +                    out.append("new ").append(ci.replace('/','_'));
  38.810                      out.append(");");
  38.811 -                    addReference(ci.getClassName().getInternalName());
  38.812 +                    addReference(ci);
  38.813                      i += 2;
  38.814                      break;
  38.815                  }
  38.816 -                case bc_newarray: {
  38.817 +                case opc_newarray: {
  38.818                      int type = byteCodes[i++];
  38.819 -                    out.append("stack.push(new Array(stack.pop()));");
  38.820 +                    out.append("stack.push(new Array(stack.pop()).fillNulls());");
  38.821                      break;
  38.822                  }
  38.823 -                case bc_anewarray: {
  38.824 +                case opc_anewarray: {
  38.825                      i += 2; // skip type of array
  38.826 -                    out.append("stack.push(new Array(stack.pop()));");
  38.827 +                    out.append("stack.push(new Array(stack.pop()).fillNulls());");
  38.828                      break;
  38.829                  }
  38.830 -                case bc_multianewarray: {
  38.831 +                case opc_multianewarray: {
  38.832                      i += 2;
  38.833                      int dim = readByte(byteCodes, ++i);
  38.834 -                    out.append("{ var a0 = new Array(stack.pop());");
  38.835 +                    out.append("{ var a0 = new Array(stack.pop()).fillNulls();");
  38.836                      for (int d = 1; d < dim; d++) {
  38.837                          out.append("\n  var l" + d).append(" = stack.pop();");
  38.838                          out.append("\n  for (var i" + d).append (" = 0; i" + d).
  38.839                              append(" < a" + (d - 1)).
  38.840                              append(".length; i" + d).append("++) {");
  38.841                          out.append("\n    var a" + d).
  38.842 -                            append (" = new Array(l" + d).append(");");
  38.843 +                            append (" = new Array(l" + d).append(").fillNulls();");
  38.844                          out.append("\n    a" + (d - 1)).append("[i" + d).append("] = a" + d).
  38.845                              append(";");
  38.846                      }
  38.847 @@ -645,86 +626,89 @@
  38.848                      out.append("\nstack.push(a0); }");
  38.849                      break;
  38.850                  }
  38.851 -                case bc_arraylength:
  38.852 +                case opc_arraylength:
  38.853                      out.append("stack.push(stack.pop().length);");
  38.854                      break;
  38.855 -                case bc_iastore:
  38.856 -                case bc_lastore:
  38.857 -                case bc_fastore:
  38.858 -                case bc_dastore:
  38.859 -                case bc_aastore:
  38.860 -                case bc_bastore:
  38.861 -                case bc_castore:
  38.862 -                case bc_sastore: {
  38.863 +                case opc_iastore:
  38.864 +                case opc_lastore:
  38.865 +                case opc_fastore:
  38.866 +                case opc_dastore:
  38.867 +                case opc_aastore:
  38.868 +                case opc_bastore:
  38.869 +                case opc_castore:
  38.870 +                case opc_sastore: {
  38.871                      out.append("{ var value = stack.pop(); var indx = stack.pop(); stack.pop()[indx] = value; }");
  38.872                      break;
  38.873                  }
  38.874 -                case bc_iaload:
  38.875 -                case bc_laload:
  38.876 -                case bc_faload:
  38.877 -                case bc_daload:
  38.878 -                case bc_aaload:
  38.879 -                case bc_baload:
  38.880 -                case bc_caload:
  38.881 -                case bc_saload: {
  38.882 +                case opc_iaload:
  38.883 +                case opc_laload:
  38.884 +                case opc_faload:
  38.885 +                case opc_daload:
  38.886 +                case opc_aaload:
  38.887 +                case opc_baload:
  38.888 +                case opc_caload:
  38.889 +                case opc_saload: {
  38.890                      out.append("{ var indx = stack.pop(); stack.push(stack.pop()[indx]); }");
  38.891                      break;
  38.892                  }
  38.893 -                case bc_pop2:
  38.894 +                case opc_pop2:
  38.895                      out.append("stack.pop();");
  38.896 -                case bc_pop:
  38.897 +                case opc_pop:
  38.898                      out.append("stack.pop();");
  38.899                      break;
  38.900 -                case bc_dup:
  38.901 +                case opc_dup:
  38.902                      out.append("stack.push(stack[stack.length - 1]);");
  38.903                      break;
  38.904 -                case bc_bipush:
  38.905 +                case opc_dup_x1:
  38.906 +                    out.append("{ var v1 = stack.pop(); var v2 = stack.pop(); stack.push(v1); stack.push(v2); stack.push(v1); }");
  38.907 +                    break;
  38.908 +                case opc_dup_x2:
  38.909 +                    out.append("{ var v1 = stack.pop(); var v2 = stack.pop(); var v3 = stack.pop(); stack.push(v1); stack.push(v3); stack.push(v2); stack.push(v1); }");
  38.910 +                    break;
  38.911 +                case opc_bipush:
  38.912                      out.append("stack.push(" + byteCodes[++i] + ");");
  38.913                      break;
  38.914 -                case bc_sipush:
  38.915 +                case opc_sipush:
  38.916                      out.append("stack.push(" + readIntArg(byteCodes, i) + ");");
  38.917                      i += 2;
  38.918                      break;
  38.919 -                case bc_getfield: {
  38.920 +                case opc_getfield: {
  38.921                      int indx = readIntArg(byteCodes, i);
  38.922 -                    CPFieldInfo fi = (CPFieldInfo) jc.getConstantPool().get(indx);
  38.923 +                    String[] fi = jc.getFieldInfoName(indx);
  38.924                      out.append("stack.push(stack.pop().fld_").
  38.925 -                        append(fi.getFieldName()).append(");");
  38.926 +                        append(fi[1]).append(");");
  38.927                      i += 2;
  38.928                      break;
  38.929                  }
  38.930 -                case bc_getstatic: {
  38.931 +                case opc_getstatic: {
  38.932                      int indx = readIntArg(byteCodes, i);
  38.933 -                    CPFieldInfo fi = (CPFieldInfo) jc.getConstantPool().get(indx);
  38.934 -                    final String in = fi.getClassName().getInternalName();
  38.935 -                    out.append("stack.push(").append(in.replace('/', '_'));
  38.936 -                    out.append('_').append(fi.getFieldName()).append(");");
  38.937 +                    String[] fi = jc.getFieldInfoName(indx);
  38.938 +                    out.append("stack.push(").append(fi[0].replace('/', '_'));
  38.939 +                    out.append('_').append(fi[1]).append(");");
  38.940                      i += 2;
  38.941 -                    addReference(in);
  38.942 +                    addReference(fi[0]);
  38.943                      break;
  38.944                  }
  38.945 -                case bc_putstatic: {
  38.946 +                case opc_putstatic: {
  38.947                      int indx = readIntArg(byteCodes, i);
  38.948 -                    CPFieldInfo fi = (CPFieldInfo) jc.getConstantPool().get(indx);
  38.949 -                    final String in = fi.getClassName().getInternalName();
  38.950 -                    out.append(in.replace('/', '_'));
  38.951 -                    out.append('_').append(fi.getFieldName()).append(" = stack.pop();");
  38.952 +                    String[] fi = jc.getFieldInfoName(indx);
  38.953 +                    out.append(fi[0].replace('/', '_'));
  38.954 +                    out.append('_').append(fi[1]).append(" = stack.pop();");
  38.955                      i += 2;
  38.956 -                    addReference(in);
  38.957 +                    addReference(fi[0]);
  38.958                      break;
  38.959                  }
  38.960 -                case bc_putfield: {
  38.961 +                case opc_putfield: {
  38.962                      int indx = readIntArg(byteCodes, i);
  38.963 -                    CPFieldInfo fi = (CPFieldInfo) jc.getConstantPool().get(indx);
  38.964 +                    String[] fi = jc.getFieldInfoName(indx);
  38.965                      out.append("{ var v = stack.pop(); stack.pop().fld_")
  38.966 -                       .append(fi.getFieldName()).append(" = v; }");
  38.967 +                       .append(fi[1]).append(" = v; }");
  38.968                      i += 2;
  38.969                      break;
  38.970                  }
  38.971 -                case bc_checkcast: {
  38.972 +                case opc_checkcast: {
  38.973                      int indx = readIntArg(byteCodes, i);
  38.974 -                    CPClassInfo ci = jc.getConstantPool().getClass(indx);
  38.975 -                    final String type = ci.getClassName().getType();
  38.976 +                    final String type = jc.getClassName(indx);
  38.977                      if (!type.startsWith("[")) {
  38.978                          // no way to check arrays right now
  38.979                          out.append("if(stack[stack.length - 1].$instOf_")
  38.980 @@ -734,16 +718,16 @@
  38.981                      i += 2;
  38.982                      break;
  38.983                  }
  38.984 -                case bc_instanceof: {
  38.985 +                case opc_instanceof: {
  38.986                      int indx = readIntArg(byteCodes, i);
  38.987 -                    CPClassInfo ci = jc.getConstantPool().getClass(indx);
  38.988 +                    final String type = jc.getClassName(indx);
  38.989                      out.append("stack.push(stack.pop().$instOf_")
  38.990 -                       .append(ci.getClassName().getInternalName().replace('/', '_'))
  38.991 +                       .append(type.replace('/', '_'))
  38.992                         .append(" ? 1 : 0);");
  38.993                      i += 2;
  38.994                      break;
  38.995                  }
  38.996 -                case bc_athrow: {
  38.997 +                case opc_athrow: {
  38.998                      out.append("{ var t = stack.pop(); stack = new Array(1); stack[0] = t; throw t; }");
  38.999                      break;
 38.1000                  }
 38.1001 @@ -786,8 +770,7 @@
 38.1002          return (byteCodes[offsetInstruction] + 256) % 256;
 38.1003      }
 38.1004      
 38.1005 -    private static int countArgs(String descriptor, boolean[] hasReturnType, StringBuilder sig) {
 38.1006 -        int cnt = 0;
 38.1007 +    private static void countArgs(String descriptor, boolean[] hasReturnType, StringBuilder sig, StringBuilder cnt) {
 38.1008          int i = 0;
 38.1009          Boolean count = null;
 38.1010          boolean array = false;
 38.1011 @@ -813,11 +796,15 @@
 38.1012                  case 'S': 
 38.1013                  case 'Z': 
 38.1014                      if (count) {
 38.1015 -                        cnt++;
 38.1016                          if (array) {
 38.1017                              sig.append('A');
 38.1018                          }
 38.1019                          sig.append(ch);
 38.1020 +                        if (ch == 'J' || ch == 'D') {
 38.1021 +                            cnt.append('1');
 38.1022 +                        } else {
 38.1023 +                            cnt.append('0');
 38.1024 +                        }
 38.1025                      } else {
 38.1026                          hasReturnType[0] = true;
 38.1027                          sig.insert(firstPos, ch);
 38.1028 @@ -835,12 +822,12 @@
 38.1029                  case 'L':
 38.1030                      int next = descriptor.indexOf(';', i);
 38.1031                      if (count) {
 38.1032 -                        cnt++;
 38.1033                          if (array) {
 38.1034                              sig.append('A');
 38.1035                          }
 38.1036                          sig.append(ch);
 38.1037                          sig.append(descriptor.substring(i, next).replace('/', '_'));
 38.1038 +                        cnt.append('0');
 38.1039                      } else {
 38.1040                          sig.insert(firstPos, descriptor.substring(i, next).replace('/', '_'));
 38.1041                          sig.insert(firstPos, ch);
 38.1042 @@ -858,18 +845,16 @@
 38.1043                      break; // invalid character
 38.1044              }
 38.1045          }
 38.1046 -        return cnt;
 38.1047      }
 38.1048  
 38.1049 -    private void generateStaticField(Variable v) throws IOException {
 38.1050 +    private void generateStaticField(FieldData v) throws IOException {
 38.1051          out.append("\nvar ")
 38.1052 -           .append(jc.getName().getInternalName().replace('/', '_'))
 38.1053 -           .append('_').append(v.getName()).append(" = 0;");
 38.1054 +           .append(className(jc))
 38.1055 +           .append('_').append(v.getName()).append(initField(v));
 38.1056      }
 38.1057  
 38.1058 -    private String findMethodName(Method m) {
 38.1059 +    private String findMethodName(MethodData m, StringBuilder cnt) {
 38.1060          StringBuilder name = new StringBuilder();
 38.1061 -        String descr = m.getDescriptor();
 38.1062          if ("<init>".equals(m.getName())) { // NOI18N
 38.1063              name.append("cons"); // NOI18N
 38.1064          } else if ("<clinit>".equals(m.getName())) { // NOI18N
 38.1065 @@ -879,38 +864,39 @@
 38.1066          } 
 38.1067          
 38.1068          boolean hasReturn[] = { false };
 38.1069 -        countArgs(findDescriptor(m.getDescriptor()), hasReturn, name);
 38.1070 +        countArgs(findDescriptor(m.getInternalSig()), hasReturn, name, cnt);
 38.1071          return name.toString();
 38.1072      }
 38.1073  
 38.1074 -    private String findMethodName(CPMethodInfo mi, int[] cnt, boolean[] hasReturn) {
 38.1075 +    private String findMethodName(String[] mi, StringBuilder cnt, boolean[] hasReturn) {
 38.1076          StringBuilder name = new StringBuilder();
 38.1077 -        String descr = mi.getDescriptor();
 38.1078 -        if ("<init>".equals(mi.getName())) { // NOI18N
 38.1079 +        String descr = mi[2];//mi.getDescriptor();
 38.1080 +        String nm= mi[1];
 38.1081 +        if ("<init>".equals(nm)) { // NOI18N
 38.1082              name.append("cons"); // NOI18N
 38.1083          } else {
 38.1084 -            name.append(mi.getName());
 38.1085 +            name.append(nm);
 38.1086          }
 38.1087 -        cnt[0] = countArgs(findDescriptor(mi.getDescriptor()), hasReturn, name);
 38.1088 +        countArgs(findDescriptor(descr), hasReturn, name, cnt);
 38.1089          return name.toString();
 38.1090      }
 38.1091  
 38.1092      private int invokeStaticMethod(byte[] byteCodes, int i, boolean isStatic)
 38.1093      throws IOException {
 38.1094          int methodIndex = readIntArg(byteCodes, i);
 38.1095 -        CPMethodInfo mi = (CPMethodInfo) jc.getConstantPool().get(methodIndex);
 38.1096 +        String[] mi = jc.getFieldInfoName(methodIndex);
 38.1097          boolean[] hasReturn = { false };
 38.1098 -        int[] cnt = { 0 };
 38.1099 +        StringBuilder cnt = new StringBuilder();
 38.1100          String mn = findMethodName(mi, cnt, hasReturn);
 38.1101          out.append("{ ");
 38.1102 -        for (int j = cnt[0] - 1; j >= 0; j--) {
 38.1103 +        for (int j = cnt.length() - 1; j >= 0; j--) {
 38.1104              out.append("var v" + j).append(" = stack.pop(); ");
 38.1105          }
 38.1106          
 38.1107          if (hasReturn[0]) {
 38.1108              out.append("stack.push(");
 38.1109          }
 38.1110 -        final String in = mi.getClassName().getInternalName();
 38.1111 +        final String in = mi[0];
 38.1112          out.append(in.replace('/', '_'));
 38.1113          if (isStatic) {
 38.1114              out.append(".prototype.");
 38.1115 @@ -924,7 +910,7 @@
 38.1116              out.append("stack.pop()");
 38.1117              sep = ", ";
 38.1118          }
 38.1119 -        for (int j = 0; j < cnt[0]; j++) {
 38.1120 +        for (int j = 0; j < cnt.length(); j++) {
 38.1121              out.append(sep);
 38.1122              out.append("v" + j);
 38.1123              sep = ", ";
 38.1124 @@ -941,12 +927,12 @@
 38.1125      private int invokeVirtualMethod(byte[] byteCodes, int i)
 38.1126      throws IOException {
 38.1127          int methodIndex = readIntArg(byteCodes, i);
 38.1128 -        CPMethodInfo mi = (CPMethodInfo) jc.getConstantPool().get(methodIndex);
 38.1129 +        String[] mi = jc.getFieldInfoName(methodIndex);
 38.1130          boolean[] hasReturn = { false };
 38.1131 -        int[] cnt = { 0 };
 38.1132 +        StringBuilder cnt = new StringBuilder();
 38.1133          String mn = findMethodName(mi, cnt, hasReturn);
 38.1134          out.append("{ ");
 38.1135 -        for (int j = cnt[0] - 1; j >= 0; j--) {
 38.1136 +        for (int j = cnt.length() - 1; j >= 0; j--) {
 38.1137              out.append("var v" + j).append(" = stack.pop(); ");
 38.1138          }
 38.1139          out.append("var self = stack.pop(); ");
 38.1140 @@ -957,7 +943,7 @@
 38.1141          out.append(mn);
 38.1142          out.append('(');
 38.1143          out.append("self");
 38.1144 -        for (int j = 0; j < cnt[0]; j++) {
 38.1145 +        for (int j = 0; j < cnt.length(); j++) {
 38.1146              out.append(", ");
 38.1147              out.append("v" + j);
 38.1148          }
 38.1149 @@ -971,10 +957,8 @@
 38.1150      }
 38.1151      
 38.1152      private void addReference(String cn) throws IOException {
 38.1153 -        if (references != null) {
 38.1154 -            if (references.add(cn)) {
 38.1155 -                out.append(" /* needs ").append(cn).append(" */");
 38.1156 -            }
 38.1157 +        if (requireReference(cn)) {
 38.1158 +            out.append(" /* needs ").append(cn).append(" */");
 38.1159          }
 38.1160      }
 38.1161  
 38.1162 @@ -992,67 +976,118 @@
 38.1163          }
 38.1164      }
 38.1165  
 38.1166 -    private String encodeConstant(CPEntry entry) {
 38.1167 -        final String v;
 38.1168 -        if (entry instanceof CPClassInfo) {
 38.1169 -            v = "new java_lang_Class";
 38.1170 -        } else if (entry instanceof CPStringInfo) {
 38.1171 -            v = "\"" + entry.getValue().toString().
 38.1172 -                replace("\\", "\\\\").
 38.1173 -                replace("\n", "\\n").
 38.1174 -                replace("\r", "\\r").
 38.1175 -                replace("\t", "\\t").
 38.1176 -                replace("\"", "\\\"")
 38.1177 -                + "\"";
 38.1178 -        } else {
 38.1179 -            v = entry.getValue().toString();
 38.1180 -        }
 38.1181 -        return v;
 38.1182 +    private String encodeConstant(int entryIndex) {
 38.1183 +        String s = jc.stringValue(entryIndex, true);
 38.1184 +        return s;
 38.1185      }
 38.1186  
 38.1187      private String findDescriptor(String d) {
 38.1188          return d.replace('[', 'A');
 38.1189      }
 38.1190  
 38.1191 -    private boolean javaScriptBody(Method m, boolean isStatic) throws IOException {
 38.1192 -        final ClassName extraAnn = ClassName.getClassName(JavaScriptBody.class.getName().replace('.', '/'));
 38.1193 -        Annotation a = m.getAnnotation(extraAnn);
 38.1194 -        if (a != null) {
 38.1195 -            final ElementValue annVal = a.getComponent("body").getValue();
 38.1196 -            String body = ((PrimitiveElementValue) annVal).getValue().getValue().toString();
 38.1197 +    private boolean javaScriptBody(MethodData m, boolean isStatic) throws IOException {
 38.1198 +        byte[] arr = m.findAnnotationData(true);
 38.1199 +        if (arr == null) {
 38.1200 +            return false;
 38.1201 +        }
 38.1202 +        final String jvmType = "L" + JavaScriptBody.class.getName().replace('.', '/') + ";";
 38.1203 +        class P extends AnnotationParser {
 38.1204 +            int cnt;
 38.1205 +            String[] args = new String[30];
 38.1206 +            String body;
 38.1207              
 38.1208 -            final ArrayElementValue arrVal = (ArrayElementValue) a.getComponent("args").getValue();
 38.1209 -            final int len = arrVal.getValues().length;
 38.1210 -            String[] names = new String[len];
 38.1211 -            for (int i = 0; i < len; i++) {
 38.1212 -                names[i] = ((PrimitiveElementValue) arrVal.getValues()[i]).getValue().getValue().toString();
 38.1213 +            @Override
 38.1214 +            protected void visitAttr(String type, String attr, String value) {
 38.1215 +                if (type.equals(jvmType)) {
 38.1216 +                    if ("body".equals(attr)) {
 38.1217 +                        body = value;
 38.1218 +                    } else if ("args".equals(attr)) {
 38.1219 +                        args[cnt++] = value;
 38.1220 +                    } else {
 38.1221 +                        throw new IllegalArgumentException(attr);
 38.1222 +                    }
 38.1223 +                }
 38.1224              }
 38.1225 -            out.append("\nfunction ").append(
 38.1226 -                jc.getName().getInternalName().replace('/', '_')).append('_').append(findMethodName(m));
 38.1227 -            out.append("(");
 38.1228 -            String space;
 38.1229 -            int index;
 38.1230 -            if (!isStatic) {                
 38.1231 -                out.append(names[0]);
 38.1232 -                space = ",";
 38.1233 -                index = 1;
 38.1234 -            } else {
 38.1235 -                space = "";
 38.1236 -                index = 0;
 38.1237 +        }
 38.1238 +        P p = new P();
 38.1239 +        p.parse(arr, jc);
 38.1240 +        if (p.body == null) {
 38.1241 +            return false;
 38.1242 +        }
 38.1243 +        StringBuilder cnt = new StringBuilder();
 38.1244 +        out.append("\nfunction ").append(className(jc)).append('_').
 38.1245 +            append(findMethodName(m, cnt));
 38.1246 +        out.append("(");
 38.1247 +        String space;
 38.1248 +        int index;
 38.1249 +        if (!isStatic) {                
 38.1250 +            out.append(p.args[0]);
 38.1251 +            space = ",";
 38.1252 +            index = 1;
 38.1253 +        } else {
 38.1254 +            space = "";
 38.1255 +            index = 0;
 38.1256 +        }
 38.1257 +        for (int i = 0; i < cnt.length(); i++) {
 38.1258 +            out.append(space);
 38.1259 +            out.append(p.args[index]);
 38.1260 +            index++;
 38.1261 +            space = ",";
 38.1262 +        }
 38.1263 +        out.append(") {").append("\n");
 38.1264 +        out.append(p.body);
 38.1265 +        out.append("\n}\n");
 38.1266 +        return true;
 38.1267 +    }
 38.1268 +    private static String className(ClassData jc) {
 38.1269 +        //return jc.getName().getInternalName().replace('/', '_');
 38.1270 +        return jc.getClassName().replace('/', '_');
 38.1271 +    }
 38.1272 +    
 38.1273 +    private static String[] findAnnotation(
 38.1274 +        byte[] arr, ClassData cd, final String className, 
 38.1275 +        final String... attrNames
 38.1276 +    ) throws IOException {
 38.1277 +        if (arr == null) {
 38.1278 +            return null;
 38.1279 +        }
 38.1280 +        final String[] values = new String[attrNames.length];
 38.1281 +        final boolean[] found = { false };
 38.1282 +        final String jvmType = "L" + className.replace('.', '/') + ";";
 38.1283 +        AnnotationParser ap = new AnnotationParser() {
 38.1284 +            @Override
 38.1285 +            protected void visitAttr(String type, String attr, String value) {
 38.1286 +                if (type.equals(jvmType)) {
 38.1287 +                    found[0] = true;
 38.1288 +                    for (int i = 0; i < attrNames.length; i++) {
 38.1289 +                        if (attrNames[i].equals(attr)) {
 38.1290 +                            values[i] = value;
 38.1291 +                        }
 38.1292 +                    }
 38.1293 +                }
 38.1294              }
 38.1295 -            List<Parameter> args = m.getParameters();
 38.1296 -            for (int i = 0; i < args.size(); i++) {
 38.1297 -                out.append(space);
 38.1298 -                out.append(names[index]);
 38.1299 -                final String desc = findDescriptor(args.get(i).getDescriptor());
 38.1300 -                index++;
 38.1301 -                space = ",";
 38.1302 +            
 38.1303 +        };
 38.1304 +        ap.parse(arr, cd);
 38.1305 +        return found[0] ? values : null;
 38.1306 +    }
 38.1307 +
 38.1308 +    private CharSequence initField(FieldData v) {
 38.1309 +        final String is = v.getInternalSig();
 38.1310 +        if (is.length() == 1) {
 38.1311 +            switch (is.charAt(0)) {
 38.1312 +                case 'S':
 38.1313 +                case 'J':
 38.1314 +                case 'B':
 38.1315 +                case 'Z':
 38.1316 +                case 'C':
 38.1317 +                case 'I': return " = 0;";
 38.1318 +                case 'F': 
 38.1319 +                case 'D': return " = 0.0;";
 38.1320 +                default:
 38.1321 +                    throw new IllegalStateException(is);
 38.1322              }
 38.1323 -            out.append(") {").append("\n");
 38.1324 -            out.append(body);
 38.1325 -            out.append("\n}\n");
 38.1326 -            return true;
 38.1327          }
 38.1328 -        return false;
 38.1329 +        return " = null;";
 38.1330      }
 38.1331  }
    39.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java	Tue Nov 13 07:56:02 2012 +0100
    39.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java	Sun Nov 18 22:03:15 2012 +0100
    39.3 @@ -20,49 +20,44 @@
    39.4  import java.io.IOException;
    39.5  import java.io.InputStream;
    39.6  import java.net.URL;
    39.7 -import java.util.ArrayList;
    39.8 -import java.util.Arrays;
    39.9 -import java.util.Collections;
   39.10  import java.util.Enumeration;
   39.11 -import java.util.HashMap;
   39.12 -import java.util.Iterator;
   39.13 -import java.util.LinkedHashSet;
   39.14 -import java.util.LinkedList;
   39.15 -import java.util.List;
   39.16 -import java.util.Map;
   39.17  
   39.18  /** Generator of JavaScript from bytecode of classes on classpath of the VM.
   39.19   *
   39.20   * @author Jaroslav Tulach <jtulach@netbeans.org>
   39.21   */
   39.22 -final class GenJS {
   39.23 -    private GenJS() {}
   39.24 +final class GenJS extends ByteCodeToJavaScript {
   39.25 +    public GenJS(Appendable out) {
   39.26 +        super(out);
   39.27 +    }
   39.28      
   39.29      static void compile(Appendable out, String... names) throws IOException {
   39.30 -        compile(out, Arrays.asList(names));
   39.31 +        compile(out, StringArray.asList(names));
   39.32      }
   39.33 -    static void compile(Appendable out, List<String> names) throws IOException {
   39.34 +    static void compile(ClassLoader l, Appendable out, String... names) throws IOException {
   39.35 +        compile(l, out, StringArray.asList(names));
   39.36 +    }
   39.37 +    static void compile(Appendable out, StringArray names) throws IOException {
   39.38          compile(GenJS.class.getClassLoader(), out, names);
   39.39      }
   39.40 -    static void compile(ClassLoader l, Appendable out, List<String> names) throws IOException {
   39.41 -        final Map<String,String> processed = new HashMap<String, String>();
   39.42 -        for (String baseClass : names) {
   39.43 -            LinkedHashSet<String> toProcess = new LinkedHashSet<String>() {
   39.44 -                @Override
   39.45 -                public boolean add(String e) {
   39.46 -                    if (processed.containsKey(e)) {
   39.47 -                        return false;
   39.48 -                    }
   39.49 -                    return super.add(e);
   39.50 -                }
   39.51 -            };
   39.52 -            toProcess.add(baseClass);
   39.53 +    static void compile(ClassLoader l, Appendable out, StringArray names) throws IOException {
   39.54 +        out.append("Array.prototype.fillNulls = function() {\n" +
   39.55 +             "  for(var i = 0; i < this.length; i++) {\n" +
   39.56 +             "    this[i] = null;\n" +
   39.57 +             "  }\n" +
   39.58 +             "  return this;\n" +
   39.59 +             "};");
   39.60 +        
   39.61 +        
   39.62 +        StringArray processed = new StringArray();
   39.63 +        StringArray initCode = new StringArray();
   39.64 +        for (String baseClass : names.toArray()) {
   39.65 +            GenJS js = new GenJS(out);
   39.66 +            js.references.add(baseClass);
   39.67              for (;;) {
   39.68                  String name = null;
   39.69 -                Iterator<String> it = toProcess.iterator();
   39.70 -                while (it.hasNext() && name == null) {
   39.71 -                    String n = it.next();
   39.72 -                    if (processed.get(n) != null) {
   39.73 +                for (String n : js.references.toArray()) {
   39.74 +                    if (processed.contains(n)) {
   39.75                          continue;
   39.76                      }
   39.77                      name = n;
   39.78 @@ -70,23 +65,19 @@
   39.79                  if (name == null) {
   39.80                      break;
   39.81                  }
   39.82 -                if (name.startsWith("sun/")) {
   39.83 -                    processed.put(name, "");
   39.84 -                    continue;
   39.85 -                }            
   39.86                  InputStream is = loadClass(l, name);
   39.87                  if (is == null) {
   39.88                      throw new IOException("Can't find class " + name); 
   39.89                  }
   39.90 -                LinkedList<String> scripts = new LinkedList<String>();
   39.91                  try {
   39.92 -                    String initCode = ByteCodeToJavaScript.compile(is, out, toProcess, scripts);
   39.93 -                    processed.put(name, initCode == null ? "" : initCode);
   39.94 +                    String ic = js.compile(is);
   39.95 +                    processed.add(name);
   39.96 +                    initCode.add(ic == null ? "" : ic);
   39.97                  } catch (RuntimeException ex) {
   39.98                      if (out instanceof CharSequence) {
   39.99                          CharSequence seq = (CharSequence)out;
  39.100                          int lastBlock = seq.length();
  39.101 -                        while (lastBlock-- >= 0) {
  39.102 +                        while (lastBlock-- > 0) {
  39.103                              if (seq.charAt(lastBlock) == '{') {
  39.104                                  break;
  39.105                              }
  39.106 @@ -100,7 +91,7 @@
  39.107                          );
  39.108                      }
  39.109                  }
  39.110 -                for (String resource : scripts) {
  39.111 +                for (String resource : js.scripts.toArray()) {
  39.112                      while (resource.startsWith("/")) {
  39.113                          resource = resource.substring(1);
  39.114                      }
  39.115 @@ -112,14 +103,14 @@
  39.116                  }
  39.117              }
  39.118  
  39.119 -            List<String> toInit = new ArrayList<String>(toProcess);
  39.120 -            Collections.reverse(toInit);
  39.121 +            StringArray toInit = StringArray.asList(js.references.toArray());
  39.122 +            toInit.reverse();
  39.123  
  39.124 -            for (String clazz : toInit) {
  39.125 -                String initCode = processed.get(clazz);
  39.126 -                if (initCode != null && !initCode.isEmpty()) {
  39.127 -                    out.append(initCode).append("\n");
  39.128 -                    processed.put(clazz, "");
  39.129 +            for (String ic : toInit.toArray()) {
  39.130 +                int indx = processed.indexOf(ic);
  39.131 +                if (indx >= 0) {
  39.132 +                    out.append(initCode.toArray()[indx]).append("\n");
  39.133 +                    initCode.toArray()[indx] = "";
  39.134                  }
  39.135              }
  39.136  
  39.137 @@ -180,6 +171,9 @@
  39.138          if (u == null) {
  39.139              throw new IOException("Can't find " + name);
  39.140          }
  39.141 +        if (u.toExternalForm().contains("rt.jar!")) {
  39.142 +            throw new IOException("No emulation for " + u);
  39.143 +        }
  39.144          return u.openStream();
  39.145      }
  39.146  
  39.147 @@ -188,4 +182,21 @@
  39.148          compile(sb, name);
  39.149          return sb.toString().toString();
  39.150      }
  39.151 +
  39.152 +    private StringArray scripts = new StringArray();
  39.153 +    private StringArray references = new StringArray();
  39.154 +    
  39.155 +    @Override
  39.156 +    protected boolean requireReference(String cn) {
  39.157 +        if (references.contains(cn)) {
  39.158 +            return false;
  39.159 +        }
  39.160 +        references.add(cn);
  39.161 +        return true;
  39.162 +    }
  39.163 +
  39.164 +    @Override
  39.165 +    protected void requireScript(String resourcePath) {
  39.166 +        scripts.add(resourcePath);
  39.167 +    }
  39.168  }
    40.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/Main.java	Tue Nov 13 07:56:02 2012 +0100
    40.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/Main.java	Sun Nov 18 22:03:15 2012 +0100
    40.3 @@ -21,8 +21,6 @@
    40.4  import java.io.FileWriter;
    40.5  import java.io.IOException;
    40.6  import java.io.Writer;
    40.7 -import java.util.Arrays;
    40.8 -import java.util.List;
    40.9  
   40.10  /** Generator of JavaScript from bytecode of classes on classpath of the VM
   40.11   * with a Main method.
   40.12 @@ -39,7 +37,8 @@
   40.13          }
   40.14          
   40.15          Writer w = new BufferedWriter(new FileWriter(args[0]));
   40.16 -        List<String> classes = Arrays.asList(args).subList(1, args.length);
   40.17 +        StringArray classes = StringArray.asList(args);
   40.18 +        classes.delete(0);
   40.19          GenJS.compile(w, classes);
   40.20          w.close();
   40.21      }
    41.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    41.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/StringArray.java	Sun Nov 18 22:03:15 2012 +0100
    41.3 @@ -0,0 +1,97 @@
    41.4 +/**
    41.5 + * Back 2 Browser Bytecode Translator
    41.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    41.7 + *
    41.8 + * This program is free software: you can redistribute it and/or modify
    41.9 + * it under the terms of the GNU General Public License as published by
   41.10 + * the Free Software Foundation, version 2 of the License.
   41.11 + *
   41.12 + * This program is distributed in the hope that it will be useful,
   41.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   41.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   41.15 + * GNU General Public License for more details.
   41.16 + *
   41.17 + * You should have received a copy of the GNU General Public License
   41.18 + * along with this program. Look for COPYING file in the top folder.
   41.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   41.20 + */
   41.21 +package org.apidesign.vm4brwsr;
   41.22 +
   41.23 +/**
   41.24 + *
   41.25 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   41.26 + */
   41.27 +class StringArray {
   41.28 +    private String[] arr;
   41.29 +
   41.30 +    public StringArray() {
   41.31 +    }
   41.32 +
   41.33 +    private StringArray(String[] arr) {
   41.34 +        this.arr = arr;
   41.35 +    }
   41.36 +    
   41.37 +    public void add(String s) {
   41.38 +        if (arr == null) {
   41.39 +            arr = new String[1];
   41.40 +        } else {
   41.41 +            String[] tmp = new String[arr.length + 1];
   41.42 +            for (int i = 0; i < arr.length; i++) {
   41.43 +                tmp[i] = arr[i];
   41.44 +            }
   41.45 +            arr = tmp;
   41.46 +        }
   41.47 +        arr[arr.length - 1] = s;
   41.48 +    }
   41.49 +    
   41.50 +    public String[] toArray() {
   41.51 +        return arr == null ? new String[0] : arr;
   41.52 +    }
   41.53 +    
   41.54 +    static StringArray asList(String[] names) {
   41.55 +        return new StringArray(names);
   41.56 +    }
   41.57 +
   41.58 +    void reverse() {
   41.59 +        for (int i = 0, j = arr.length; i < j; i++) {
   41.60 +            String s = arr[i];
   41.61 +            arr[i] = arr[--j];
   41.62 +            arr[j] = s;
   41.63 +        }
   41.64 +    }
   41.65 +
   41.66 +    boolean contains(String n) {
   41.67 +        if (arr == null) {
   41.68 +            return false;
   41.69 +        }
   41.70 +        for (int i = 0; i < arr.length; i++) {
   41.71 +            if (n.equals(arr[i])) {
   41.72 +                return true;
   41.73 +            }
   41.74 +        }
   41.75 +        return false;
   41.76 +    }
   41.77 +
   41.78 +    void delete(int indx) {
   41.79 +        if (arr == null) {
   41.80 +            return;
   41.81 +        }
   41.82 +        String[] tmp = new String[arr.length - 1];
   41.83 +        for (int i = 0, j = 0; i < arr.length; i++) {
   41.84 +            tmp[j] = arr[i];
   41.85 +            if (j == indx) {
   41.86 +                continue;
   41.87 +            }
   41.88 +        }
   41.89 +    }
   41.90 +
   41.91 +    int indexOf(String ic) {
   41.92 +        for (int i = 0; i < arr.length; i++) {
   41.93 +            if (ic.equals(arr[i])) {
   41.94 +                return i;
   41.95 +            }
   41.96 +        }
   41.97 +        return -1;
   41.98 +    }
   41.99 +    
  41.100 +}
    42.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java	Tue Nov 13 07:56:02 2012 +0100
    42.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java	Sun Nov 18 22:03:15 2012 +0100
    42.3 @@ -64,9 +64,9 @@
    42.4          try {
    42.5              ret = code.invokeFunction(methodName, args);
    42.6          } catch (ScriptException ex) {
    42.7 -            fail("Execution failed in\n" + codeSeq, ex);
    42.8 +            fail("Execution failed in\n" + StaticMethodTest.dumpJS(codeSeq), ex);
    42.9          } catch (NoSuchMethodException ex) {
   42.10 -            fail("Cannot find method in\n" + codeSeq, ex);
   42.11 +            fail("Cannot find method in\n" + StaticMethodTest.dumpJS(codeSeq), ex);
   42.12          }
   42.13          if (ret == null && expRes == null) {
   42.14              return;
    43.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Tue Nov 13 07:56:02 2012 +0100
    43.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Sun Nov 18 22:03:15 2012 +0100
    43.3 @@ -17,6 +17,11 @@
    43.4   */
    43.5  package org.apidesign.vm4brwsr;
    43.6  
    43.7 +import java.io.ByteArrayInputStream;
    43.8 +import java.io.ByteArrayOutputStream;
    43.9 +import java.io.DataInputStream;
   43.10 +import java.io.DataOutputStream;
   43.11 +import java.io.IOException;
   43.12  import javax.script.Invocable;
   43.13  import javax.script.ScriptException;
   43.14  import static org.testng.Assert.*;
   43.15 @@ -55,7 +60,94 @@
   43.16              Double.valueOf(3.0), 1000.0
   43.17          );
   43.18      }
   43.19 +    
   43.20 +    @Test public void javaRem() {
   43.21 +        assertEquals(3, Numbers.rem(303, 10));
   43.22 +    }
   43.23 +    @Test public void jsRem() throws Exception {
   43.24 +        assertExec("Should be three", "org_apidesign_vm4brwsr_Numbers_remIII", 
   43.25 +            Double.valueOf(3.0), 303, 10
   43.26 +        );
   43.27 +    }
   43.28 +    
   43.29 +    @Test public void deserializeInt() throws Exception {
   43.30 +        int exp = Numbers.deserInt();
   43.31 +        assertExec("Should be the same", "org_apidesign_vm4brwsr_Numbers_deserIntI", 
   43.32 +            Double.valueOf(exp)
   43.33 +        );
   43.34 +    }
   43.35  
   43.36 +    @Test public void deserializeSimpleLong() throws Exception {
   43.37 +        assertExec("Should be 3454", "org_apidesign_vm4brwsr_Numbers_deserLongJAB", 
   43.38 +            Double.valueOf(3454), 
   43.39 +            new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)13, (byte)126 }
   43.40 +        );
   43.41 +    }
   43.42 +    /* XXX: JavaScript cannot represent as big longs as Java. 
   43.43 +    @Test public void deserializeLargeLong() throws Exception {
   43.44 +        final byte[] arr = new byte[] {
   43.45 +            (byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0
   43.46 +        };
   43.47 +        long exp = Numbers.deserLong(arr);
   43.48 +        assertExec("Should be " + exp, "org_apidesign_vm4brwsr_Numbers_deserLongJAB", 
   43.49 +            Double.valueOf(exp), arr);
   43.50 +    }
   43.51 +    */
   43.52 +    
   43.53 +    @Test public void deserializeFloatInJava() throws Exception {
   43.54 +        float f = 54324.32423f;
   43.55 +        float r = Numbers.deserFloat();
   43.56 +        assertEquals(r, f, "Floats are the same");
   43.57 +    }
   43.58 +    
   43.59 +    @Test public void deserializeFloatInJS() throws Exception {
   43.60 +        float f = 54324.32423f;
   43.61 +        assertExec("Should be the same", "org_apidesign_vm4brwsr_Numbers_deserFloatF", 
   43.62 +            Double.valueOf(f)
   43.63 +        );
   43.64 +    }
   43.65 +
   43.66 +    @Test public void deserializeDoubleInJava() throws Exception {
   43.67 +        double f = 3.0;
   43.68 +        double r = Numbers.deserDouble();
   43.69 +        assertEquals(r, f, 0.001, "Doubles are the same");
   43.70 +    }
   43.71 +    
   43.72 +    @Test public void deserializeDoubleInJS() throws Exception {
   43.73 +        double f = 3.0;
   43.74 +        assertExec("Should be the same", "org_apidesign_vm4brwsr_Numbers_deserDoubleD", f);
   43.75 +    }
   43.76 +    /*
   43.77 +    @Test public void serDouble() throws IOException {
   43.78 +        double f = 3.0;
   43.79 +        ByteArrayOutputStream os = new ByteArrayOutputStream();
   43.80 +        DataOutputStream d = new DataOutputStream(os);
   43.81 +        d.writeLong(3454);
   43.82 +        d.close();
   43.83 +        
   43.84 +        StringBuilder sb = new StringBuilder();
   43.85 +        byte[] arr = os.toByteArray();
   43.86 +        for (int i = 0; i < arr.length; i++) {
   43.87 +            sb.append("(byte)").append(arr[i]).append(", ");
   43.88 +        }
   43.89 +        fail("" + sb);
   43.90 +    }
   43.91 +*/    
   43.92 +    @Test public void fiveInStringJS() throws Exception {
   43.93 +        String s = Numbers.intToString();
   43.94 +        assertExec("Should be the same: " + s, 
   43.95 +            "org_apidesign_vm4brwsr_Numbers_intToStringLjava_lang_String", 
   43.96 +            s
   43.97 +        );
   43.98 +    }
   43.99 +
  43.100 +    @Test public void sevenInStringJS() throws Exception {
  43.101 +        String s = Numbers.floatToString();
  43.102 +        assertExec("Should be the same: " + s, 
  43.103 +            "org_apidesign_vm4brwsr_Numbers_floatToStringLjava_lang_String", 
  43.104 +            s
  43.105 +        );
  43.106 +    }
  43.107      
  43.108      private static CharSequence codeSeq;
  43.109      private static Invocable code;
    44.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java	Tue Nov 13 07:56:02 2012 +0100
    44.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java	Sun Nov 18 22:03:15 2012 +0100
    44.3 @@ -17,6 +17,10 @@
    44.4   */
    44.5  package org.apidesign.vm4brwsr;
    44.6  
    44.7 +import java.io.ByteArrayInputStream;
    44.8 +import java.io.DataInputStream;
    44.9 +import java.io.IOException;
   44.10 +
   44.11  /**
   44.12   *
   44.13   * @author Jaroslav Tulach <jtulach@netbeans.org>
   44.14 @@ -28,4 +32,39 @@
   44.15      public static String autoboxDblToString() {
   44.16          return autoboxDbl().toString().toString();
   44.17      }
   44.18 +    public static int rem(int a, int b) {
   44.19 +        return a % b;
   44.20 +    }
   44.21 +
   44.22 +    static float deserFloat() throws IOException {
   44.23 +        byte[] arr = {(byte) 71, (byte) 84, (byte) 52, (byte) 83};
   44.24 +        ByteArrayInputStream is = new ByteArrayInputStream(arr);
   44.25 +        DataInputStream dis = new DataInputStream(is);
   44.26 +        float r = dis.readFloat();
   44.27 +        return r;
   44.28 +    }
   44.29 +    static double deserDouble() throws IOException {
   44.30 +        byte[] arr = {(byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0};
   44.31 +        ByteArrayInputStream is = new ByteArrayInputStream(arr);
   44.32 +        DataInputStream dis = new DataInputStream(is);
   44.33 +        return dis.readDouble();
   44.34 +    }
   44.35 +    static long deserLong(byte[] arr) throws IOException {
   44.36 +        ByteArrayInputStream is = new ByteArrayInputStream(arr);
   44.37 +        DataInputStream dis = new DataInputStream(is);
   44.38 +        return dis.readLong();
   44.39 +    }
   44.40 +    static int deserInt() throws IOException {
   44.41 +        byte[] arr = {(byte) 71, (byte) 84, (byte) 52, (byte) 83};
   44.42 +        ByteArrayInputStream is = new ByteArrayInputStream(arr);
   44.43 +        DataInputStream dis = new DataInputStream(is);
   44.44 +        return dis.readInt();
   44.45 +    }
   44.46 +
   44.47 +    static String intToString() {
   44.48 +        return new Integer(5).toString().toString();
   44.49 +    }
   44.50 +    static String floatToString() {
   44.51 +        return new Float(7.0).toString().toString();
   44.52 +    }
   44.53  }
    45.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java	Tue Nov 13 07:56:02 2012 +0100
    45.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethod.java	Sun Nov 18 22:03:15 2012 +0100
    45.3 @@ -25,6 +25,7 @@
    45.4   */
    45.5  public class StaticMethod {
    45.6      private static int cnt;
    45.7 +    private static Object NULL;
    45.8  
    45.9      public static int minusOne() {
   45.10          return -1;
   45.11 @@ -42,6 +43,10 @@
   45.12          return toRet;
   45.13      }
   45.14      
   45.15 +    public static boolean isNull() {
   45.16 +        return NULL == null;
   45.17 +    }
   45.18 +    
   45.19      public static int sum(int x, int y) {
   45.20          return x + y;
   45.21      }
   45.22 @@ -95,7 +100,7 @@
   45.23      }
   45.24      
   45.25      @JavaScriptBody(
   45.26 -        args={"i","j"}, body="return (i + j).toString();"
   45.27 +        args={"i","j"}, body="\n\r\treturn (i + j).toString();"
   45.28      )
   45.29      public static String i2s(int i, int j) {
   45.30          throw new IllegalStateException();
    46.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java	Tue Nov 13 07:56:02 2012 +0100
    46.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java	Sun Nov 18 22:03:15 2012 +0100
    46.3 @@ -42,6 +42,14 @@
    46.4          );
    46.5      }
    46.6  
    46.7 +    @Test public void checkReallyInitializedValues() throws Exception {
    46.8 +        assertExec(
    46.9 +            "Return true", 
   46.10 +            "org_apidesign_vm4brwsr_StaticMethod_isNullZ", 
   46.11 +            Double.valueOf(1)
   46.12 +        );
   46.13 +    }
   46.14 +
   46.15      @Test public void powerOfThree() throws Exception {
   46.16          assertExec(
   46.17              "Should be nine", 
   46.18 @@ -275,15 +283,17 @@
   46.19              return (Invocable)js;
   46.20          } catch (Exception ex) {
   46.21              if (sb.length() > 2000) {
   46.22 -                File f = File.createTempFile("execution", ".js");
   46.23 -                FileWriter w = new FileWriter(f);
   46.24 -                w.append(sb);
   46.25 -                w.close();
   46.26 -                sb.setLength(0);
   46.27 -                sb.append(f.getPath());
   46.28 +                dumpJS(sb);
   46.29              }
   46.30              fail("Could not compile:\n" + sb, ex);
   46.31              return null;
   46.32          }
   46.33      }
   46.34 +    static String dumpJS(CharSequence sb) throws IOException {
   46.35 +        File f = File.createTempFile("execution", ".js");
   46.36 +        FileWriter w = new FileWriter(f);
   46.37 +        w.append(sb);
   46.38 +        w.close();
   46.39 +        return f.getPath();
   46.40 +    }
   46.41  }
    47.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java	Tue Nov 13 07:56:02 2012 +0100
    47.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringSample.java	Sun Nov 18 22:03:15 2012 +0100
    47.3 @@ -44,6 +44,40 @@
    47.4          return new String(arr).toString();
    47.5      }
    47.6      
    47.7 +    public static String charsFromNumbers() {
    47.8 +        return chars((char)65, (char)66, (char)67);
    47.9 +    }
   47.10 +
   47.11 +    public static String charsFromChars() {
   47.12 +        return chars('A', 'B', 'C');
   47.13 +    }
   47.14 +
   47.15 +    public static String chars(char a, char b, char c) {
   47.16 +        return ("" + a + b +c).toString();
   47.17 +    }
   47.18 +    
   47.19 +    public static String replace(String s, char a, char b) {
   47.20 +        return s.replace(a, b);
   47.21 +    }
   47.22 +    
   47.23 +    public static String insertBuffer() {
   47.24 +        StringBuilder sb = new StringBuilder();
   47.25 +        sb.append("Jardo!");
   47.26 +        sb.insert(0, "Ahoj ");
   47.27 +        return sb.toString().toString();
   47.28 +    }
   47.29 +    
   47.30 +    public static int countAB(String txt) {
   47.31 +        int cnt = 0;
   47.32 +        for (int i = 0; i < txt.length(); i++) {
   47.33 +            switch (txt.charAt(i)) {
   47.34 +                case 'A': cnt++; break;
   47.35 +                case 'B': cnt += 2; break;
   47.36 +            }
   47.37 +        }
   47.38 +        return cnt;
   47.39 +    }
   47.40 +    
   47.41      public static String toStringTest(int howMuch) {
   47.42          counter = 0;
   47.43          StringSample ss = null;
    48.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java	Tue Nov 13 07:56:02 2012 +0100
    48.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java	Sun Nov 18 22:03:15 2012 +0100
    48.3 @@ -32,7 +32,7 @@
    48.4          assertExec(
    48.5              "First char in Hello is H",
    48.6              "org_apidesign_vm4brwsr_StringSample_sayHelloCI",
    48.7 -            "H", 0
    48.8 +            72, 0
    48.9          );
   48.10      }
   48.11  
   48.12 @@ -44,6 +44,30 @@
   48.13          );
   48.14      }
   48.15  
   48.16 +    @Test public void concatChars() throws Exception {
   48.17 +        assertExec(
   48.18 +            "Composing yields ABC",
   48.19 +            "org_apidesign_vm4brwsr_StringSample_charsLjava_lang_StringCCC",
   48.20 +            "ABC", 'A', 'B', 'C'
   48.21 +        );
   48.22 +    }
   48.23 +
   48.24 +    @Test public void concatCharsFromInts() throws Exception {
   48.25 +        assertExec(
   48.26 +            "Composing yields ABC",
   48.27 +            "org_apidesign_vm4brwsr_StringSample_charsFromNumbersLjava_lang_String",
   48.28 +            "ABC"
   48.29 +        );
   48.30 +    }
   48.31 +
   48.32 +    @Test public void concatCharsFromChars() throws Exception {
   48.33 +        assertExec(
   48.34 +            "Composing yields ABC",
   48.35 +            "org_apidesign_vm4brwsr_StringSample_charsFromCharsLjava_lang_String",
   48.36 +            "ABC"
   48.37 +        );
   48.38 +    }
   48.39 +
   48.40      @Test(timeOut=10000) public void toStringConcatenation() throws Exception {
   48.41          assertExec(
   48.42              "Five executions should generate 5Hello World!",
   48.43 @@ -63,13 +87,45 @@
   48.44          );
   48.45      }
   48.46  
   48.47 -    public void equalsAndSubstring() throws Exception {
   48.48 +    @Test public void equalsAndSubstring() throws Exception {
   48.49          assertExec(
   48.50              "Composes are OK",
   48.51              "org_apidesign_vm4brwsr_StringSample_equalToHelloZII",
   48.52 -            Double.valueOf(1), 0, 5
   48.53 +            true, 0, 5
   48.54          );
   48.55      }
   48.56 +    @Test public void replaceChars() throws Exception {
   48.57 +        assertExec(
   48.58 +            "Can replace slashes by underscores",
   48.59 +            "org_apidesign_vm4brwsr_StringSample_replaceLjava_lang_StringLjava_lang_StringCC",
   48.60 +            "x_y_z", "x/y/z", '/', '_'
   48.61 +        );
   48.62 +    }
   48.63 +    @Test public void replaceIntChars() throws Exception {
   48.64 +        assertExec(
   48.65 +            "Can replace slashes by underscores",
   48.66 +            "org_apidesign_vm4brwsr_StringSample_replaceLjava_lang_StringLjava_lang_StringCC",
   48.67 +            "x_y_z", "x/y/z", (int)'/', (int)'_'
   48.68 +        );
   48.69 +    }
   48.70 +
   48.71 +    @Test public void insertBuilder() throws Exception {
   48.72 +        assertExec(
   48.73 +            "Can insert something into a buffer?",
   48.74 +            "org_apidesign_vm4brwsr_StringSample_insertBufferLjava_lang_String",
   48.75 +            "Ahoj Jardo!"
   48.76 +        );
   48.77 +    }
   48.78 +    
   48.79 +    @Test public void countAB() throws Exception {
   48.80 +        assertEquals(StringSample.countAB("Ahoj Bedo!"), 3, "Verify Java code is sane");
   48.81 +        assertExec(
   48.82 +            "One A and one B adds to 3",
   48.83 +            "org_apidesign_vm4brwsr_StringSample_countABILjava_lang_String",
   48.84 +            Double.valueOf(3), "Ahoj Bedo!"
   48.85 +        );
   48.86 +        
   48.87 +    }
   48.88      
   48.89      private static CharSequence codeSeq;
   48.90      private static Invocable code;
    49.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    49.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMinVM.java	Sun Nov 18 22:03:15 2012 +0100
    49.3 @@ -0,0 +1,46 @@
    49.4 +/**
    49.5 + * Back 2 Browser Bytecode Translator
    49.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    49.7 + *
    49.8 + * This program is free software: you can redistribute it and/or modify
    49.9 + * it under the terms of the GNU General Public License as published by
   49.10 + * the Free Software Foundation, version 2 of the License.
   49.11 + *
   49.12 + * This program is distributed in the hope that it will be useful,
   49.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   49.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   49.15 + * GNU General Public License for more details.
   49.16 + *
   49.17 + * You should have received a copy of the GNU General Public License
   49.18 + * along with this program. Look for COPYING file in the top folder.
   49.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   49.20 + */
   49.21 +package org.apidesign.vm4brwsr;
   49.22 +
   49.23 +import java.io.ByteArrayInputStream;
   49.24 +import java.io.IOException;
   49.25 +
   49.26 +/**
   49.27 + *
   49.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   49.29 + */
   49.30 +class VMinVM extends ByteCodeToJavaScript {
   49.31 +    private VMinVM(Appendable out) {
   49.32 +        super(out);
   49.33 +    }
   49.34 +    
   49.35 +    static String toJavaScript(byte[] is) throws IOException {
   49.36 +        StringBuilder sb = new StringBuilder();
   49.37 +        new VMinVM(sb).compile(new ByteArrayInputStream(is));
   49.38 +        return sb.toString().toString();
   49.39 +    }
   49.40 +
   49.41 +    @Override
   49.42 +    protected boolean requireReference(String internalClassName) {
   49.43 +        return false;
   49.44 +    }
   49.45 +
   49.46 +    @Override
   49.47 +    protected void requireScript(String resourcePath) {
   49.48 +    }
   49.49 +}
    50.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    50.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java	Sun Nov 18 22:03:15 2012 +0100
    50.3 @@ -0,0 +1,92 @@
    50.4 +/**
    50.5 + * Back 2 Browser Bytecode Translator
    50.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
    50.7 + *
    50.8 + * This program is free software: you can redistribute it and/or modify
    50.9 + * it under the terms of the GNU General Public License as published by
   50.10 + * the Free Software Foundation, version 2 of the License.
   50.11 + *
   50.12 + * This program is distributed in the hope that it will be useful,
   50.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   50.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   50.15 + * GNU General Public License for more details.
   50.16 + *
   50.17 + * You should have received a copy of the GNU General Public License
   50.18 + * along with this program. Look for COPYING file in the top folder.
   50.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
   50.20 + */
   50.21 +package org.apidesign.vm4brwsr;
   50.22 +
   50.23 +import java.io.File;
   50.24 +import java.io.FileWriter;
   50.25 +import java.io.IOException;
   50.26 +import java.io.InputStream;
   50.27 +import static org.testng.Assert.*;
   50.28 +import javax.script.Invocable;
   50.29 +import org.testng.annotations.BeforeClass;
   50.30 +import org.testng.annotations.Test;
   50.31 +
   50.32 +/**
   50.33 + *
   50.34 + * @author Jaroslav Tulach <jtulach@netbeans.org>
   50.35 + */
   50.36 +public class VMinVMTest {
   50.37 +
   50.38 +    private static CharSequence codeSeq;
   50.39 +    private static Invocable code;
   50.40 +    
   50.41 +    @Test public void compareTheGeneratedCode() throws Exception {
   50.42 +        byte[] arr = readClass("/org/apidesign/vm4brwsr/Array.class");
   50.43 +        String ret1 = VMinVM.toJavaScript(arr);
   50.44 +        
   50.45 +        Object ret;
   50.46 +        try {
   50.47 +            ret = code.invokeFunction(
   50.48 +                "org_apidesign_vm4brwsr_VMinVM_toJavaScriptLjava_lang_StringAB",
   50.49 +                arr
   50.50 +            );
   50.51 +        } catch (Exception ex) {
   50.52 +            File f = File.createTempFile("execution", ".js");
   50.53 +            FileWriter w = new FileWriter(f);
   50.54 +            w.append("var byteCode = [\n  ");
   50.55 +            String sep = "";
   50.56 +            for (int i = 0; i < arr.length; i++) {
   50.57 +                w.append(sep).append(Integer.toString((arr[i] + 256) % 256));
   50.58 +                sep = ", ";
   50.59 +                if (i % 20 == 0) {
   50.60 +                    w.append("\n  ");
   50.61 +                }
   50.62 +            }
   50.63 +            w.append("\n];\n");
   50.64 +            w.append(codeSeq);
   50.65 +            w.close();
   50.66 +            throw new Exception(ex.getMessage() + " file: " + f, ex);
   50.67 +        }
   50.68 +
   50.69 +        
   50.70 +        assertTrue(ret instanceof String, "It is string: " + ret);
   50.71 +        
   50.72 +        assertEquals((String)ret, ret1.toString(), "The code is the same");
   50.73 +    }
   50.74 +    
   50.75 +    @BeforeClass
   50.76 +    public void compileTheCode() throws Exception {
   50.77 +        StringBuilder sb = new StringBuilder();
   50.78 +        code = StaticMethodTest.compileClass(sb, 
   50.79 +            "org/apidesign/vm4brwsr/VMinVM"
   50.80 +        );
   50.81 +        codeSeq = sb;
   50.82 +    }
   50.83 +    
   50.84 +    private static byte[] readClass(String res) throws IOException {
   50.85 +        InputStream is1 = VMinVMTest.class.getResourceAsStream(res);
   50.86 +        assertNotNull(is1, "Stream found");
   50.87 +        byte[] arr = new byte[is1.available()];
   50.88 +        int len = is1.read(arr);
   50.89 +        is1.close();
   50.90 +        if (len != arr.length) {
   50.91 +            throw new IOException("Wrong len " + len + " for arr: " + arr.length);
   50.92 +        }
   50.93 +        return arr;
   50.94 +    }
   50.95 +}