use of org.apache.xbean.asm5.tree.ClassNode in project apex-malhar by apache.
the class BeanClassGenerator method addPrivateField.
/**
* 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);
}
use of org.apache.xbean.asm5.tree.ClassNode in project apex-core by apache.
the class CompactUtil method compactClassNode.
public static CompactClassNode compactClassNode(ClassNode cn) {
if (cn == null) {
return null;
}
CompactClassNode ccn = new CompactClassNode();
ccn.setAccess(cn.access);
ccn.setDefaultConstructor(compactMethodNode(ASMUtil.getPublicDefaultConstructor(cn)));
List<CompactMethodNode> cmns = new LinkedList<>();
for (MethodNode mn : ASMUtil.getPublicGetter(cn)) {
cmns.add(compactMethodNode(mn));
}
ccn.setGetterMethods(cmns);
cmns = new LinkedList<>();
for (MethodNode mn : ASMUtil.getPublicSetter(cn)) {
cmns.add(compactMethodNode(mn));
}
ccn.setSetterMethods(cmns);
ccn.setPorts(new LinkedList<CompactFieldNode>());
ccn.setName(cn.name);
List<CompactClassNode> ccns = new LinkedList<>();
for (Object icn : cn.innerClasses) {
CompactClassNode inner = new CompactClassNode();
inner.setName(((InnerClassNode) icn).name);
inner.setAccess(((InnerClassNode) icn).access);
}
ccn.setInnerClasses(ccns);
if (ASMUtil.isEnum(cn)) {
ccn.setEnumValues(ASMUtil.getEnumValues(cn));
}
if (cn instanceof ClassNodeType) {
ccn.setCsv(((ClassNodeType) cn).csv);
}
// }
return ccn;
}
use of org.apache.xbean.asm5.tree.ClassNode in project apex-core by apache.
the class ASMUtil method getPublicSetter.
/**
* Get a list of setter methods from classnode asmNode
* @param asmNode
* @return empty list if there is no setter method
*/
public static List<MethodNode> getPublicSetter(ClassNode asmNode) {
List<MethodNode> result = new LinkedList<>();
@SuppressWarnings("unchecked") List<MethodNode> mList = asmNode.methods;
for (MethodNode methodNode : mList) {
if (methodNode.name.startsWith("set") && isPublic(methodNode.access) && Type.getArgumentTypes(methodNode.desc).length == 1 && Type.getReturnType(methodNode.desc) == Type.VOID_TYPE) {
result.add(methodNode);
}
}
return result;
}
use of org.apache.xbean.asm5.tree.ClassNode in project apex-core by apache.
the class ASMUtil method getPorts.
public static List<FieldNode> getPorts(ClassNode asmNode) {
List<FieldNode> result = new LinkedList<>();
List<FieldNode> fields = asmNode.fields;
for (FieldNode fn : fields) {
// 'L' represents <class>, ignore primitive types
if (fn.desc.charAt(0) == 'L') {
result.add(fn);
}
}
return result;
}
use of org.apache.xbean.asm5.tree.ClassNode in project apex-malhar by apache.
the class BeanClassGenerator method 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);
}
Aggregations