• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Constants类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ArrayType

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/**
 * Constructor for array of given type
 *
 * @param type type of array (may be an array itself)
 */
public ArrayType(Type type, int dimensions) {
  super(Constants.T_ARRAY, "<dummy>");

  if((dimensions < 1) || (dimensions > Constants.MAX_BYTE))
    throw new ClassGenException("Invalid number of dimensions: " + dimensions);

  switch(type.getType()) {
  case Constants.T_ARRAY:
    ArrayType array = (ArrayType)type;
    this.dimensions = dimensions + array.dimensions;
    basic_type      = array.basic_type;
    break;

  case Constants.T_VOID:
    throw new ClassGenException("Invalid type: void[]");

  default: // Basic type or reference
    this.dimensions = dimensions;
    basic_type = type;
    break;
  }

  StringBuffer buf = new StringBuffer();
  for(int i=0; i < this.dimensions; i++)
    buf.append('[');

  buf.append(basic_type.getSignature());

  signature = buf.toString();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:ArrayType.java


示例17: visitFieldInstruction

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
public void visitFieldInstruction(FieldInstruction i) {
  short  opcode = i.getOpcode();

  String class_name = i.getClassName(_cp);
  String field_name = i.getFieldName(_cp);
  Type   type       = i.getFieldType(_cp);

  _out.println("il.append(_factory.createFieldAccess(\"" +
               class_name + "\", \"" + field_name + "\", " +
               BCELifier.printType(type) + ", " +
               "Constants." + Constants.OPCODE_NAMES[opcode].toUpperCase() +
               "));");
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:14,代码来源:BCELFactory.java


示例18: addLocalVariable

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/**
 * Adds a local variable to this method.
 *
 * @param name variable name
 * @param type variable type
 * @param slot the index of the local variable, if type is long or double, the next available
 * index is slot+2
 * @param start from where the variable is valid
 * @param end until where the variable is valid
 * @return new local variable object
 * @see LocalVariable
 */
public LocalVariableGen addLocalVariable(String name, Type type, int slot,
                                         InstructionHandle start,
                                         InstructionHandle end) {
  byte t = type.getType();

  if(t != Constants.T_ADDRESS) {
    int  add = type.getSize();

    if(slot + add > max_locals)
      max_locals = slot + add;

    LocalVariableGen l = new LocalVariableGen(slot, name, type, start, end);
    int i;

    if((i = variable_vec.indexOf(l)) >= 0) // Overwrite if necessary
      variable_vec.set(i, l);
    else
      variable_vec.add(l);

    return l;
  } else {
    throw new IllegalArgumentException("Can not use " + type +
                                       " as type for local variable");

  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:MethodGen.java


示例19: addLocalVariableType

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/**
 * Adds a local variable type to this method.
 *
 * @param name variable name
 * @param type variable type
 * @param slot the index of the local variable, if type is long or double, the next available
 * index is slot+2
 * @param start from where the variable is valid
 * @param end until where the variable is valid
 * @return new local variable object
 * @see LocalVariable
 */
private LocalVariableGen addLocalVariableType(String name, Type type, int slot,
                                         InstructionHandle start,
                                         InstructionHandle end) {
  byte t = type.getType();

  if(t != Constants.T_ADDRESS) {
    int  add = type.getSize();

    if(slot + add > max_locals)
      max_locals = slot + add;

    LocalVariableGen l = new LocalVariableGen(slot, name, type, start, end);
    int i;

    if((i = type_vec.indexOf(l)) >= 0) // Overwrite if necessary
      type_vec.set(i, l);
    else
      type_vec.add(l);

    return l;
  } else {
    throw new IllegalArgumentException("Can not use " + type +
                                       " as type for local variable");

  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:MethodGen.java


示例20: toString

import com.sun.org.apache.bcel.internal.Constants; //导入依赖的package包/类
/**
 * Return string representation close to declaration format,
 * `public static void _main(String[] args) throws IOException', e.g.
 *
 * @return String representation of the method.
 */
public final String toString() {
  ConstantUtf8  c;
  String        name, signature, access; // Short cuts to constant pool
  StringBuffer  buf;

  access = Utility.accessToString(access_flags);

  // Get name and signature from constant pool
  c = (ConstantUtf8)constant_pool.getConstant(signature_index,
                                              Constants.CONSTANT_Utf8);
  signature = c.getBytes();

  c = (ConstantUtf8)constant_pool.getConstant(name_index, Constants.CONSTANT_Utf8);
  name = c.getBytes();

  signature = Utility.methodSignatureToString(signature, name, access, true,
                                              getLocalVariableTable());
  buf = new StringBuffer(signature);

  for(int i=0; i < attributes_count; i++) {
    Attribute a = attributes[i];

    if(!((a instanceof Code) || (a instanceof ExceptionTable)))
      buf.append(" [" + a.toString() + "]");
  }

  ExceptionTable e = getExceptionTable();
  if(e != null) {
    String str = e.toString();
    if(!str.equals(""))
      buf.append("\n\t\tthrows " + str);
  }

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IScoreCriteria类代码示例发布时间:2022-05-22
下一篇:
Java GenericRowMapper类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap