本文整理汇总了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);
}
示例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);
}
示例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);
}
示例4: isPublic
public static boolean isPublic(int opCode)
{
return (opCode & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC;
}
示例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;
}
示例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);
}