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


Java Opcodes类代码示例

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


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

示例1: subclass

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
public static File subclass(final Class<?> parent, final String subclassName) throws Exception {
    final String subclassNameInternal = subclassName.replace('.', '/');

    final byte[] bytes;
    {
        final ClassWriter cw = new ClassWriter(0);
        final String parentClassNameInternal = parent.getName().replace('.', '/');

        cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + ACC_SUPER, subclassNameInternal, null, parentClassNameInternal, null);

        final MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
        mv.visitCode();
        mv.visitVarInsn(ALOAD, 0);
        mv.visitMethodInsn(INVOKESPECIAL, parentClassNameInternal, "<init>", "()V", false);
        mv.visitInsn(RETURN);
        mv.visitMaxs(1, 1);
        mv.visitEnd();
        cw.visitEnd();

        bytes = cw.toByteArray();
    }

    return Archive.archive().add(subclassNameInternal + ".class", bytes).asJar();
}
 
开发者ID:apache,项目名称:tomee,代码行数:25,代码来源:ServiceClasspathTest.java

示例2: addDefaultConstructor

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
/**
 * Add Default constructor for POJO
 * @param classNode ClassNode which needs to be populated with constructor
 */
@SuppressWarnings("unchecked")
private static void addDefaultConstructor(ClassNode classNode)
{
  MethodNode constructorNode = new MethodNode(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
  constructorNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
  constructorNode.instructions
      .add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false));
  constructorNode.instructions.add(new InsnNode(Opcodes.RETURN));
  classNode.methods.add(constructorNode);
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:15,代码来源:BeanClassGenerator.java

示例3: addPrivateField

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
/**
 * Add private field to the class
 * @param classNode ClassNode which needs to be populated with private field.
 * @param fieldName Name of the field
 * @param fieldJavaType Java ASM type of the field
 */
@SuppressWarnings("unchecked")
private static void addPrivateField(ClassNode classNode, String fieldName, String fieldJavaType)
{
  FieldNode fieldNode = new FieldNode(Opcodes.ACC_PRIVATE, fieldName, fieldJavaType, null, null);
  classNode.fields.add(fieldNode);
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:13,代码来源:BeanClassGenerator.java

示例4: addGetter

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
/**
 * Add public getter method for given field
 * @param classNode ClassNode which needs to be populated with public getter.
 * @param fieldName Name of the field for which public getter needs to be added.
 * @param fieldNameForMethods Suffix of the getter method, Prefix "is" or "get" is added by this method.
 * @param fieldJavaType Java ASM type of the field
 */
@SuppressWarnings("unchecked")
private static void addGetter(ClassNode classNode, String fieldName, String fieldNameForMethods, String fieldJavaType)
{
  String getterSignature = "()" + fieldJavaType;
  MethodNode getterNode = new MethodNode(Opcodes.ACC_PUBLIC,
      (fieldJavaType.equals(typeIdentifierBoolean) ? "is" : "get") + fieldNameForMethods,
      getterSignature, null, null);
  getterNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
  getterNode.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, classNode.name, fieldName, fieldJavaType));

  int returnOpCode;
  if (fieldJavaType.equals(Character.toString(typeIdentifierBoolean)) ||
      fieldJavaType.equals(Character.toString(typeIdentifierByte))    ||
      fieldJavaType.equals(Character.toString(typeIdentifierChar))    ||
      fieldJavaType.equals(Character.toString(typeIdentifierShort))   ||
      fieldJavaType.equals(Character.toString(typeIdentifierInt))) {
    returnOpCode = Opcodes.IRETURN;
  } else if (fieldJavaType.equals(Character.toString(typeIdentifierLong))) {
    returnOpCode = Opcodes.LRETURN;
  } else if (fieldJavaType.equals(Character.toString(typeIdentifierFloat))) {
    returnOpCode = Opcodes.FRETURN;
  } else if (fieldJavaType.equals(Character.toString(typeIdentifierDouble))) {
    returnOpCode = Opcodes.DRETURN;
  } else {
    returnOpCode = Opcodes.ARETURN;
  }
  getterNode.instructions.add(new InsnNode(returnOpCode));

  classNode.methods.add(getterNode);
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:38,代码来源:BeanClassGenerator.java

示例5: addSetter

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
/**
 * Add public setter for given field
 * @param classNode ClassNode which needs to be populated with public setter
 * @param fieldName Name of the field for which setter needs to be added
 * @param fieldNameForMethods Suffix for setter method. Prefix "set" is added by this method
 * @param fieldJavaType Java ASM type of the field
 */
@SuppressWarnings("unchecked")
private static void addSetter(ClassNode classNode, String fieldName, String fieldNameForMethods, String fieldJavaType)
{
  String setterSignature = '(' + fieldJavaType + ')' + 'V';
  MethodNode setterNode = new MethodNode(Opcodes.ACC_PUBLIC, "set" + fieldNameForMethods, setterSignature, null,
      null);
  setterNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));

  int loadOpCode;
  if (fieldJavaType.equals(Character.toString(typeIdentifierBoolean)) ||
      fieldJavaType.equals(Character.toString(typeIdentifierByte))    ||
      fieldJavaType.equals(Character.toString(typeIdentifierChar))    ||
      fieldJavaType.equals(Character.toString(typeIdentifierShort))   ||
      fieldJavaType.equals(Character.toString(typeIdentifierInt))) {
    loadOpCode = Opcodes.ILOAD;
  } else if (fieldJavaType.equals(Character.toString(typeIdentifierLong))) {
    loadOpCode = Opcodes.LLOAD;
  } else if (fieldJavaType.equals(Character.toString(typeIdentifierFloat))) {
    loadOpCode = Opcodes.FLOAD;
  } else if (fieldJavaType.equals(Character.toString(typeIdentifierDouble))) {
    loadOpCode = Opcodes.DLOAD;
  } else {
    loadOpCode = Opcodes.ALOAD;
  }
  setterNode.instructions.add(new VarInsnNode(loadOpCode, 1));

  setterNode.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, fieldName, fieldJavaType));
  setterNode.instructions.add(new InsnNode(Opcodes.RETURN));
  classNode.methods.add(setterNode);
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:38,代码来源:BeanClassGenerator.java

示例6: FieldNode

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
public FieldNode(int access, String name, String desc, String signature, Object value)
{
  super(Opcodes.ASM5, access, name, desc, signature, value);
}
 
开发者ID:apache,项目名称:apex-core,代码行数:5,代码来源:FieldNode.java

示例7: readConstantPool

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
/**
 * read and index the constant pool section for getting class metadata later
 */
private void readConstantPool()
{
  // checks the class version
  if (readShort(6) > Opcodes.V1_8) {
    throw new IllegalArgumentException();
  }
  // parses the constant pool
  items = new int[readUnsignedShort(8)];
  int n = items.length;
  int index = 10;
  for (int i = 1; i < n; ++i) {
    items[i] = index + 1;
    int size;
    switch (b[index]) {
      case FIELD:
      case METH:
      case IMETH:
      case INT:
      case FLOAT:
      case NAME_TYPE:
      case INDY:
        size = 5;
        break;
      case LONG:
      case DOUBLE:
        size = 9;
        ++i;
        break;
      case UTF8:
        size = 3 + readUnsignedShort(index + 1);
        break;
      case HANDLE:
        size = 4;
        break;
      // case ClassWriter.CLASS:
      // case ClassWriter.STR:
      // case ClassWriter.MTYPE
      default:
        size = 3;
        break;
    }
    index += size;
  }
  // the class header information starts just after the constant pool
  header = index;
}
 
开发者ID:apache,项目名称:apex-core,代码行数:50,代码来源:FastClassIndexReader.java

示例8: isEnum

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
public boolean isEnum()
{
  return (access & Opcodes.ACC_ENUM) == Opcodes.ACC_ENUM;
}
 
开发者ID:apache,项目名称:apex-core,代码行数:5,代码来源:CompactClassNode.java

示例9: isEnum

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
public static boolean isEnum(ClassNode cn)
{
  return (cn.access & Opcodes.ACC_ENUM) == Opcodes.ACC_ENUM;
}
 
开发者ID:apache,项目名称:apex-core,代码行数:5,代码来源:ASMUtil.java

示例10: isEnumValue

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
public static boolean isEnumValue(FieldNode fn)
{
  return (fn.access & Opcodes.ACC_ENUM) == Opcodes.ACC_ENUM;
}
 
开发者ID:apache,项目名称:apex-core,代码行数:5,代码来源:ASMUtil.java

示例11: isPublic

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
public static boolean isPublic(int opCode)
{
  return (opCode & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC;
}
 
开发者ID:apache,项目名称:apex-core,代码行数:5,代码来源:ASMUtil.java

示例12: isAbstract

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
public static boolean isAbstract(int opCode)
{
  return (opCode & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT;
}
 
开发者ID:apache,项目名称:apex-core,代码行数:5,代码来源:ASMUtil.java

示例13: isTransient

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
public static boolean isTransient(int opCode)
{
  return (opCode & Opcodes.ACC_TRANSIENT) == Opcodes.ACC_TRANSIENT;
}
 
开发者ID:apache,项目名称:apex-core,代码行数:5,代码来源:ASMUtil.java

示例14: isFinal

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
public static boolean isFinal(int opCode)
{
  return (opCode & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL;
}
 
开发者ID:apache,项目名称:apex-core,代码行数:5,代码来源:ASMUtil.java

示例15: MethodNode

import org.apache.xbean.asm5.Opcodes; //导入依赖的package包/类
public MethodNode(int access, String name, String desc, String signature, String[] exceptions)
{
  super(Opcodes.ASM5, access, name, desc, signature, exceptions);
}
 
开发者ID:apache,项目名称:apex-core,代码行数:5,代码来源:MethodNode.java


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