當前位置: 首頁>>代碼示例>>Java>>正文


Java Opcodes.ACC_PUBLIC屬性代碼示例

本文整理匯總了Java中org.apache.xbean.asm5.Opcodes.ACC_PUBLIC屬性的典型用法代碼示例。如果您正苦於以下問題:Java Opcodes.ACC_PUBLIC屬性的具體用法?Java Opcodes.ACC_PUBLIC怎麽用?Java Opcodes.ACC_PUBLIC使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在org.apache.xbean.asm5.Opcodes的用法示例。


在下文中一共展示了Opcodes.ACC_PUBLIC屬性的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addDefaultConstructor

/**
 * 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,代碼行數:14,代碼來源:BeanClassGenerator.java

示例2: addGetter

/**
 * 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,代碼行數:37,代碼來源:BeanClassGenerator.java

示例3: addSetter

/**
 * 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,代碼行數:37,代碼來源:BeanClassGenerator.java

示例4: isPublic

public static boolean isPublic(int opCode)
{
  return (opCode & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC;
}
 
開發者ID:apache,項目名稱:apex-core,代碼行數:4,代碼來源:ASMUtil.java

示例5: createAndWriteBeanClass

/**
 * Creates a class from given field information and writes it to the output stream. Also returns byte[] of compiled
 * class
 *
 * @param fqcn         fully qualified class name
 * @param fieldList    field list describing the class
 * @param outputStream stream to which the class is persisted
 * @throws JSONException
 * @throws IOException
 */
public static byte[] createAndWriteBeanClass(String fqcn, List<TupleSchemaRegistry.SQLFieldInfo> fieldList,
    FSDataOutputStream outputStream) throws JSONException, IOException
{
  ClassNode classNode = new ClassNode();

  classNode.version = Opcodes.V1_7;  //generated class will only run on JRE 1.7 or above
  classNode.access = Opcodes.ACC_PUBLIC;

  classNode.name = fqcn.replace('.', '/');
  classNode.superName = "java/lang/Object";

  // add default constructor
  addDefaultConstructor(classNode);

  //for each field in json add a field to this class and a getter and setter for it.

  for (TupleSchemaRegistry.SQLFieldInfo fieldInfo : fieldList) {
    String fieldName = fieldInfo.getColumnName();
    String fieldType = fieldInfo.getType().getJavaType().getName();
    String fieldJavaType = getJavaType(fieldType);

    addPrivateField(classNode, fieldName, fieldJavaType);

    String fieldNameForMethods = Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);

    if (fieldJavaType.equals(getJavaType("java.util.Date"))) {
      addDateFields(classNode, fieldName, fieldNameForMethods, "java/util/Date");
    } else {
      addGetter(classNode, fieldName, fieldNameForMethods, fieldJavaType);
      addSetter(classNode, fieldName, fieldNameForMethods, fieldJavaType);
    }
  }

  addToStringMethod(classNode, fieldList);
  addHashCodeMethod(classNode, fieldList);
  addEqualsMethod(classNode, fieldList);

  //Write the class
  ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
  classNode.accept(cw);
  cw.visitEnd();

  byte[] classBytes = cw.toByteArray();

  if (outputStream != null) {
    outputStream.write(classBytes);
    outputStream.close();
  }

  return classBytes;
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:61,代碼來源:BeanClassGenerator.java

示例6: addToStringMethod

/**
 * Adds a toString method to underlying class. Uses StringBuilder to generate the final string.
 *
 * @param classNode
 * @param fieldList
 * @throws JSONException
 */
@SuppressWarnings("unchecked")
private static void addToStringMethod(ClassNode classNode, List<TupleSchemaRegistry.SQLFieldInfo> fieldList)
  throws JSONException
{
  MethodNode toStringNode = new MethodNode(Opcodes.ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
  toStringNode.visitAnnotation("Ljava/lang/Override;", true);

  toStringNode.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/lang/StringBuilder"));
  toStringNode.instructions.add(new InsnNode(Opcodes.DUP));
  toStringNode.instructions.add(new LdcInsnNode(classNode.name + "{"));
  toStringNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder",
      "<init>", "(Ljava/lang/String;)V", false));
  toStringNode.instructions.add(new VarInsnNode(Opcodes.ASTORE, 1));
  toStringNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));

  for (int i = 0; i < fieldList.size(); i++) {
    TupleSchemaRegistry.SQLFieldInfo info = fieldList.get(i);
    String fieldName = info.getColumnName();
    String fieldType = info.getType().getJavaType().getName();
    String fieldJavaType = getJavaType(fieldType);

    if (i != 0) {
      toStringNode.instructions.add(new LdcInsnNode(", "));
      toStringNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
          "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false));
    }

    toStringNode.instructions.add(new LdcInsnNode(fieldName + "="));
    toStringNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
        "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false));
    toStringNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    toStringNode.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, classNode.name, fieldName, fieldJavaType));

    // There is no StringBuilder.append method for short and byte. It takes it as int.
    if (fieldJavaType.equals(Character.toString(typeIdentifierShort)) ||
        fieldJavaType.equals(Character.toString(typeIdentifierByte))) {
      fieldJavaType = "I";
    }

    Character pchar = PRIMITIVE_TYPES.get(fieldType);
    if (pchar == null) {
      // It's not a primitive type. StringBuilder.append method signature takes Object type.
      fieldJavaType = "Ljava/lang/Object;";
    }

    toStringNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
        "(" + fieldJavaType + ")Ljava/lang/StringBuilder;", false));
  }

  toStringNode.instructions.add(new LdcInsnNode("}"));
  toStringNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append",
      "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false));

  toStringNode.instructions.add(new InsnNode(Opcodes.POP));
  toStringNode.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
  toStringNode.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString",
      "()Ljava/lang/String;", false));
  toStringNode.instructions.add(new InsnNode(Opcodes.ARETURN));

  classNode.methods.add(toStringNode);
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:68,代碼來源:BeanClassGenerator.java


注:本文中的org.apache.xbean.asm5.Opcodes.ACC_PUBLIC屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。