当前位置: 首页>>代码示例>>Java>>正文


Java Constants类代码示例

本文整理汇总了Java中com.sun.org.apache.bcel.internal.Constants的典型用法代码示例。如果您正苦于以下问题:Java Constants类的具体用法?Java Constants怎么用?Java Constants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Constants类属于com.sun.org.apache.bcel.internal包,在下文中一共展示了Constants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createInvoke

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/** Create an invoke instruction.
 *
 * @param class_name name of the called class
 * @param name name of the called method
 * @param ret_type return type of method
 * @param arg_types argument types of method
 * @param kind how to invoke, i.e., INVOKEINTERFACE, INVOKESTATIC, INVOKEVIRTUAL,
 * or INVOKESPECIAL
 * @see Constants
 */
public InvokeInstruction createInvoke(String class_name, String name, Type ret_type,
                                      Type[] arg_types, short kind) {
  int    index;
  int    nargs      = 0;
  String signature  = Type.getMethodSignature(ret_type, arg_types);

  for(int i=0; i < arg_types.length; i++) // Count size of arguments
    nargs += arg_types[i].getSize();

  if(kind == Constants.INVOKEINTERFACE)
    index = cp.addInterfaceMethodref(class_name, name, signature);
  else
    index = cp.addMethodref(class_name, name, signature);

  switch(kind) {
  case Constants.INVOKESPECIAL:   return new INVOKESPECIAL(index);
  case Constants.INVOKEVIRTUAL:   return new INVOKEVIRTUAL(index);
  case Constants.INVOKESTATIC:    return new INVOKESTATIC(index);
  case Constants.INVOKEINTERFACE: return new INVOKEINTERFACE(index, nargs + 1);
  default:
    throw new RuntimeException("Oops: Unknown invoke kind:" + kind);
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:34,代码来源:InstructionFactory.java

示例2: createAppend

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
public Instruction createAppend(Type type) {
  byte t = type.getType();

  if(isString(type))
    return createInvoke(append_mos[0], Constants.INVOKEVIRTUAL);

  switch(t) {
  case Constants.T_BOOLEAN:
  case Constants.T_CHAR:
  case Constants.T_FLOAT:
  case Constants.T_DOUBLE:
  case Constants.T_BYTE:
  case Constants.T_SHORT:
  case Constants.T_INT:
  case Constants.T_LONG
    :   return createInvoke(append_mos[t], Constants.INVOKEVIRTUAL);
  case Constants.T_ARRAY:
  case Constants.T_OBJECT:
    return createInvoke(append_mos[1], Constants.INVOKEVIRTUAL);
  default:
    throw new RuntimeException("Oops: No append for this type? " + type);
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:InstructionFactory.java

示例3: createFieldAccess

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/** Create a field instruction.
 *
 * @param class_name name of the accessed class
 * @param name name of the referenced field
 * @param type  type of field
 * @param kind how to access, i.e., GETFIELD, PUTFIELD, GETSTATIC, PUTSTATIC
 * @see Constants
 */
public FieldInstruction createFieldAccess(String class_name, String name, Type type, short kind) {
  int    index;
  String signature  = type.getSignature();

  index = cp.addFieldref(class_name, name, signature);

  switch(kind) {
  case Constants.GETFIELD:  return new GETFIELD(index);
  case Constants.PUTFIELD:  return new PUTFIELD(index);
  case Constants.GETSTATIC: return new GETSTATIC(index);
  case Constants.PUTSTATIC: return new PUTSTATIC(index);

  default:
    throw new RuntimeException("Oops: Unknown getfield kind:" + kind);
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:InstructionFactory.java

示例4: createStore

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/**
 * @param index index of local variable
 */
public static LocalVariableInstruction createStore(Type type, int index) {
  switch(type.getType()) {
  case Constants.T_BOOLEAN:
  case Constants.T_CHAR:
  case Constants.T_BYTE:
  case Constants.T_SHORT:
  case Constants.T_INT:    return new ISTORE(index);
  case Constants.T_FLOAT:  return new FSTORE(index);
  case Constants.T_DOUBLE: return new DSTORE(index);
  case Constants.T_LONG:   return new LSTORE(index);
  case Constants.T_ARRAY:
  case Constants.T_OBJECT: return new ASTORE(index);
  default:       throw new RuntimeException("Invalid type " + type);
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:InstructionFactory.java

示例5: createLoad

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/**
 * @param index index of local variable
 */
public static LocalVariableInstruction createLoad(Type type, int index) {
  switch(type.getType()) {
  case Constants.T_BOOLEAN:
  case Constants.T_CHAR:
  case Constants.T_BYTE:
  case Constants.T_SHORT:
  case Constants.T_INT:    return new ILOAD(index);
  case Constants.T_FLOAT:  return new FLOAD(index);
  case Constants.T_DOUBLE: return new DLOAD(index);
  case Constants.T_LONG:   return new LLOAD(index);
  case Constants.T_ARRAY:
  case Constants.T_OBJECT: return new ALOAD(index);
  default:       throw new RuntimeException("Invalid type " + type);
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:InstructionFactory.java

示例6: createNull

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/** Create "null" value for reference types, 0 for basic types like int
 */
public static Instruction createNull(Type type) {
  switch(type.getType()) {
  case Constants.T_ARRAY:
  case Constants.T_OBJECT:  return ACONST_NULL;
  case Constants.T_INT:
  case Constants.T_SHORT:
  case Constants.T_BOOLEAN:
  case Constants.T_CHAR:
  case Constants.T_BYTE:    return ICONST_0;
  case Constants.T_FLOAT:   return FCONST_0;
  case Constants.T_DOUBLE:  return DCONST_0;
  case Constants.T_LONG:    return LCONST_0;
  case Constants.T_VOID:    return NOP;

  default:
    throw new RuntimeException("Invalid type: " + type);
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:InstructionFactory.java

示例7: pattern2string

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
private static final String pattern2string(String pattern, boolean make_string) {
  StringBuffer buf = new StringBuffer();

  for(int i=0; i < pattern.length(); i++) {
    char ch = pattern.charAt(i);

    if(ch >= OFFSET) {
      if(make_string)
        buf.append(Constants.OPCODE_NAMES[ch - OFFSET]);
      else
        buf.append((int)(ch - OFFSET));
    } else
      buf.append(ch);
  }

  return buf.toString();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:InstructionFinder.java

示例8: accessToString

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/**
 * Convert bit field of flags into string such as `static final'.
 *
 * Special case: Classes compiled with new compilers and with the
 * `ACC_SUPER' flag would be said to be "synchronized". This is
 * because SUN used the same value for the flags `ACC_SUPER' and
 * `ACC_SYNCHRONIZED'.
 *
 * @param  access_flags Access flags
 * @param  for_class access flags are for class qualifiers ?
 * @return String representation of flags
 */
public static final String accessToString(int access_flags,
                                          boolean for_class)
{
  StringBuffer buf = new StringBuffer();

  int p = 0;
  for(int i=0; p < Constants.MAX_ACC_FLAG; i++) { // Loop through known flags
    p = pow2(i);

    if((access_flags & p) != 0) {
      /* Special case: Classes compiled with new compilers and with the
       * `ACC_SUPER' flag would be said to be "synchronized". This is
       * because SUN used the same value for the flags `ACC_SUPER' and
       * `ACC_SYNCHRONIZED'.
       */
      if(for_class && ((p == Constants.ACC_SUPER) || (p == Constants.ACC_INTERFACE)))
        continue;

      buf.append(Constants.ACCESS_NAMES[i] + " ");
    }
  }

  return buf.toString().trim();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:Utility.java

示例9: getType

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
public static final BasicType getType(byte type) {
  switch(type) {
  case Constants.T_VOID:    return VOID;
  case Constants.T_BOOLEAN: return BOOLEAN;
  case Constants.T_BYTE:    return BYTE;
  case Constants.T_SHORT:   return SHORT;
  case Constants.T_CHAR:    return CHAR;
  case Constants.T_INT:     return INT;
  case Constants.T_LONG:    return LONG;
  case Constants.T_DOUBLE:  return DOUBLE;
  case Constants.T_FLOAT:   return FLOAT;

  default:
    throw new ClassGenException("Invalid type: " + type);
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:BasicType.java

示例10: getType

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/** @return type associated with the instruction
 */
public Type getType(ConstantPoolGen cp) {
  switch(opcode) {
  case Constants.D2I: case Constants.F2I: case Constants.L2I:
    return Type.INT;
  case Constants.D2F: case Constants.I2F: case Constants.L2F:
    return Type.FLOAT;
  case Constants.D2L: case Constants.F2L: case Constants.I2L:
    return Type.LONG;
  case Constants.F2D:  case Constants.I2D: case Constants.L2D:
      return Type.DOUBLE;
  case Constants.I2B:
    return Type.BYTE;
  case Constants.I2C:
    return Type.CHAR;
  case Constants.I2S:
    return Type.SHORT;

  default: // Never reached
    throw new ClassGenException("Unknown type " + opcode);
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:ConversionInstruction.java

示例11: initFromFile

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/**
  * Read needed data (e.g. index) from file.
  * PRE: (ILOAD <= tag <= ALOAD_3) || (ISTORE <= tag <= ASTORE_3)
  */
 protected void initFromFile(ByteSequence bytes, boolean wide)
   throws IOException
 {
   if(wide) {
     n         = bytes.readUnsignedShort();
     length    = 4;
   } else if(((opcode >= Constants.ILOAD) &&
              (opcode <= Constants.ALOAD)) ||
             ((opcode >= Constants.ISTORE) &&
              (opcode <= Constants.ASTORE))) {
     n      = bytes.readUnsignedByte();
     length = 2;
   } else if(opcode <= Constants.ALOAD_3) { // compact load instruction such as ILOAD_2
     n      = (opcode - Constants.ILOAD_0) % 4;
     length = 1;
   } else { // Assert ISTORE_0 <= tag <= ASTORE_3
     n      = (opcode - Constants.ISTORE_0) % 4;
     length = 1;
   }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:LocalVariableInstruction.java

示例12: setIndex

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/**
 * Set the local variable index
 */
public void setIndex(int n) {
  if((n < 0) || (n > Constants.MAX_SHORT))
    throw new ClassGenException("Illegal value: " + n);

  this.n = n;

  if(n >= 0 && n <= 3) { // Use more compact instruction xLOAD_n
    opcode = (short)(c_tag + n);
    length = 1;
  } else {
    opcode = canon_tag;

    if(wide()) // Need WIDE prefix ?
      length = 4;
    else
      length = 2;
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:LocalVariableInstruction.java

示例13: printFlags

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
static String printFlags(int flags, boolean for_class) {
  if(flags == 0)
    return "0";

  StringBuffer buf = new StringBuffer();
  for(int i=0, pow=1; i <= Constants.MAX_ACC_FLAG; i++) {
    if((flags & pow) != 0) {
      if((pow == Constants.ACC_SYNCHRONIZED) && for_class)
        buf.append("ACC_SUPER | ");
      else
        buf.append("ACC_" + Constants.ACCESS_NAMES[i].toUpperCase() + " | ");
    }

    pow <<= 1;
  }

  String str = buf.toString();
  return str.substring(0, str.length() - 3);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:BCELifier.java

示例14: printType

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
static String printType(String signature) {
  Type type = Type.getType(signature);
  byte t    = type.getType();

  if(t <= Constants.T_VOID) {
    return "Type." + Constants.TYPE_NAMES[t].toUpperCase();
  } else if(type.toString().equals("java.lang.String")) {
    return "Type.STRING";
  } else if(type.toString().equals("java.lang.Object")) {
    return "Type.OBJECT";
  } else if(type.toString().equals("java.lang.StringBuffer")) {
    return "Type.STRINGBUFFER";
  } else if(type instanceof ArrayType) {
    ArrayType at = (ArrayType)type;

    return "new ArrayType(" + printType(at.getBasicType()) +
      ", " + at.getDimensions() + ")";
  } else {
    return "new ObjectType(\"" + Utility.signatureToString(signature, false) +
      "\")";
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:BCELifier.java

示例15: readConstant

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/**
 * Read one constant from the given file, the type depends on a tag byte.
 *
 * @param file Input stream
 * @return Constant object
 */
static final Constant readConstant(DataInputStream file)
  throws IOException, ClassFormatException
{
  byte b = file.readByte(); // Read tag byte

  switch(b) {
  case Constants.CONSTANT_Class:              return new ConstantClass(file);
  case Constants.CONSTANT_Fieldref:           return new ConstantFieldref(file);
  case Constants.CONSTANT_Methodref:          return new ConstantMethodref(file);
  case Constants.CONSTANT_InterfaceMethodref: return new
                                      ConstantInterfaceMethodref(file);
  case Constants.CONSTANT_String:             return new ConstantString(file);
  case Constants.CONSTANT_Integer:            return new ConstantInteger(file);
  case Constants.CONSTANT_Float:              return new ConstantFloat(file);
  case Constants.CONSTANT_Long:               return new ConstantLong(file);
  case Constants.CONSTANT_Double:             return new ConstantDouble(file);
  case Constants.CONSTANT_NameAndType:        return new ConstantNameAndType(file);
  case Constants.CONSTANT_Utf8:               return new ConstantUtf8(file);
  default:
    throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:Constant.java


注:本文中的com.sun.org.apache.bcel.internal.Constants类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。