Home | History | Annotate | Download | only in instruction
      1 /*
      2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
      3  *             of Java bytecode.
      4  *
      5  * Copyright (c) 2002-2014 Eric Lafortune (eric (at) graphics.cornell.edu)
      6  *
      7  * This program is free software; you can redistribute it and/or modify it
      8  * under the terms of the GNU General Public License as published by the Free
      9  * Software Foundation; either version 2 of the License, or (at your option)
     10  * any later version.
     11  *
     12  * This program is distributed in the hope that it will be useful, but WITHOUT
     13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
     15  * more details.
     16  *
     17  * You should have received a copy of the GNU General Public License along
     18  * with this program; if not, write to the Free Software Foundation, Inc.,
     19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
     20  */
     21 package proguard.classfile.instruction;
     22 
     23 import proguard.classfile.ClassConstants;
     24 
     25 /**
     26  * Utility methods for converting between representations of names and
     27  * descriptions.
     28  *
     29  * @author Eric Lafortune
     30  */
     31 public class InstructionUtil
     32 {
     33     /**
     34      * Returns the internal type corresponding to the given 'newarray' type.
     35      * @param arrayType <code>InstructionConstants.ARRAY_T_BOOLEAN</code>,
     36      *                  <code>InstructionConstants.ARRAY_T_BYTE</code>,
     37      *                  <code>InstructionConstants.ARRAY_T_CHAR</code>,
     38      *                  <code>InstructionConstants.ARRAY_T_SHORT</code>,
     39      *                  <code>InstructionConstants.ARRAY_T_INT</code>,
     40      *                  <code>InstructionConstants.ARRAY_T_LONG</code>,
     41      *                  <code>InstructionConstants.ARRAY_T_FLOAT</code>, or
     42      *                  <code>InstructionConstants.ARRAY_T_DOUBLE</code>.
     43      * @return <code>ClassConstants.TYPE_BOOLEAN</code>,
     44      *         <code>ClassConstants.TYPE_BYTE</code>,
     45      *         <code>ClassConstants.TYPE_CHAR</code>,
     46      *         <code>ClassConstants.TYPE_SHORT</code>,
     47      *         <code>ClassConstants.TYPE_INT</code>,
     48      *         <code>ClassConstants.TYPE_LONG</code>,
     49      *         <code>ClassConstants.TYPE_FLOAT</code>, or
     50      *         <code>ClassConstants.TYPE_DOUBLE</code>.
     51      */
     52     public static char internalTypeFromArrayType(byte arrayType)
     53     {
     54         switch (arrayType)
     55         {
     56             case InstructionConstants.ARRAY_T_BOOLEAN: return ClassConstants.TYPE_BOOLEAN;
     57             case InstructionConstants.ARRAY_T_CHAR:    return ClassConstants.TYPE_CHAR;
     58             case InstructionConstants.ARRAY_T_FLOAT:   return ClassConstants.TYPE_FLOAT;
     59             case InstructionConstants.ARRAY_T_DOUBLE:  return ClassConstants.TYPE_DOUBLE;
     60             case InstructionConstants.ARRAY_T_BYTE:    return ClassConstants.TYPE_BYTE;
     61             case InstructionConstants.ARRAY_T_SHORT:   return ClassConstants.TYPE_SHORT;
     62             case InstructionConstants.ARRAY_T_INT:     return ClassConstants.TYPE_INT;
     63             case InstructionConstants.ARRAY_T_LONG:    return ClassConstants.TYPE_LONG;
     64             default: throw new IllegalArgumentException("Unknown array type ["+arrayType+"]");
     65         }
     66     }
     67 }
     68