< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassFile.java

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.jvm;
  27 



  28 import com.sun.tools.javac.util.Name;
  29 
  30 
  31 /** A JVM class file.
  32  *
  33  *  <p>Generic Java classfiles have one additional attribute for classes,
  34  *  methods and fields:
  35  *  <pre>
  36  *   "Signature" (u4 attr-length, u2 signature-index)
  37  *  </pre>
  38  *
  39  *  <p>A signature gives the full Java type of a method or field. When
  40  *  used as a class attribute, it indicates type parameters, followed
  41  *  by supertype, followed by all interfaces.
  42  *  <pre>
  43  *     methodOrFieldSignature ::= type
  44  *     classSignature         ::= [ typeparams ] supertype { interfacetype }
  45  *  </pre>
  46  *  <p>The type syntax in signatures is extended as follows:
  47  *  <pre>{@literal


 168      * which defines "internal name" to be the form using "/" instead of "."
 169      */
 170     public static byte[] externalize(byte[] buf, int offset, int len) {
 171         byte[] translated = new byte[len];
 172         for (int j = 0; j < len; j++) {
 173             byte b = buf[offset + j];
 174             if (b == '.') translated[j] = (byte) '/';
 175             else translated[j] = b;
 176         }
 177         return translated;
 178     }
 179 
 180     /**
 181      * Return external representation of given name, converting '/' to '.'.
 182      *
 183      * Note: the naming is the inverse of that used by JVMS 4.2 The Internal Form Of Names,
 184      * which defines "internal name" to be the form using "/" instead of "."
 185      */
 186     public static byte[] externalize(Name name) {
 187         return externalize(name.getByteArray(), name.getByteOffset(), name.getByteLength());


































 188     }
 189 }


   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.jvm;
  27 
  28 import com.sun.tools.javac.code.Type;
  29 import com.sun.tools.javac.code.Types;
  30 import com.sun.tools.javac.code.Types.UniqueType;
  31 import com.sun.tools.javac.util.Name;
  32 
  33 
  34 /** A JVM class file.
  35  *
  36  *  <p>Generic Java classfiles have one additional attribute for classes,
  37  *  methods and fields:
  38  *  <pre>
  39  *   "Signature" (u4 attr-length, u2 signature-index)
  40  *  </pre>
  41  *
  42  *  <p>A signature gives the full Java type of a method or field. When
  43  *  used as a class attribute, it indicates type parameters, followed
  44  *  by supertype, followed by all interfaces.
  45  *  <pre>
  46  *     methodOrFieldSignature ::= type
  47  *     classSignature         ::= [ typeparams ] supertype { interfacetype }
  48  *  </pre>
  49  *  <p>The type syntax in signatures is extended as follows:
  50  *  <pre>{@literal


 171      * which defines "internal name" to be the form using "/" instead of "."
 172      */
 173     public static byte[] externalize(byte[] buf, int offset, int len) {
 174         byte[] translated = new byte[len];
 175         for (int j = 0; j < len; j++) {
 176             byte b = buf[offset + j];
 177             if (b == '.') translated[j] = (byte) '/';
 178             else translated[j] = b;
 179         }
 180         return translated;
 181     }
 182 
 183     /**
 184      * Return external representation of given name, converting '/' to '.'.
 185      *
 186      * Note: the naming is the inverse of that used by JVMS 4.2 The Internal Form Of Names,
 187      * which defines "internal name" to be the form using "/" instead of "."
 188      */
 189     public static byte[] externalize(Name name) {
 190         return externalize(name.getByteArray(), name.getByteOffset(), name.getByteLength());
 191     }
 192 
 193 /************************************************************************
 194  * Name-and-type
 195  ***********************************************************************/
 196 
 197     /** A class for the name-and-type signature of a method or field.
 198      */
 199     public static class NameAndType {
 200         Name name;
 201         UniqueType uniqueType;
 202         Types types;
 203 
 204         NameAndType(Name name, Type type, Types types) {
 205             this.name = name;
 206             this.uniqueType = new UniqueType(type, types);
 207             this.types = types;
 208         }
 209 
 210         void setType(Type type) {
 211             this.uniqueType = new UniqueType(type, types);
 212         }
 213 
 214         @Override
 215         public boolean equals(Object other) {
 216             return (other instanceof NameAndType &&
 217                     name == ((NameAndType) other).name &&
 218                         uniqueType.equals(((NameAndType) other).uniqueType));
 219         }
 220 
 221         @Override
 222         public int hashCode() {
 223             return name.hashCode() * uniqueType.hashCode();
 224         }
 225     }
 226 }
< prev index next >