Search in sources :

Example 1 with FieldNode

use of org.apache.xbean.asm5.tree.FieldNode 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);
}
Also used : FieldNode(org.apache.xbean.asm5.tree.FieldNode)

Example 2 with FieldNode

use of org.apache.xbean.asm5.tree.FieldNode in project apex-core by apache.

the class CompactUtil method updateCompactClassPortInfo.

public static void updateCompactClassPortInfo(ClassNode cn, CompactClassNode ccn) {
    List<FieldNode> fields = ASMUtil.getPorts(cn);
    List<CompactFieldNode> ports = new LinkedList<>();
    for (FieldNode fn : fields) {
        ports.add(compactFieldNode(fn));
    }
    ccn.setPorts(ports);
}
Also used : FieldNode(org.apache.xbean.asm5.tree.FieldNode) LinkedList(java.util.LinkedList)

Example 3 with FieldNode

use of org.apache.xbean.asm5.tree.FieldNode in project apex-malhar by apache.

the class BeanClassGenerator method addDateFields.

/**
 * Date field is explicitly handled and provided with 3 variants of types of same data.
 * 1. java.util.Date format
 * 2. long - Epoc time in ms
 * 3. int - Epoc time in sec rounded to date
 *
 * This is purposefully done because SQL operations on Date etc happens on long or int based on whether its a SQL DATE
 * field OR SQL TIMESTAMP field. Hence to cater to that 2 more variant of the same data is added to the POJO.
 */
@SuppressWarnings("unchecked")
private static void addDateFields(ClassNode classNode, String fieldName, String fieldNameForMethods, String type) {
    FieldNode fieldNodeSec = new FieldNode(Opcodes.ACC_PRIVATE, fieldName + "Sec", getJavaType("java.lang.Integer"), null, null);
    classNode.fields.add(fieldNodeSec);
    FieldNode fieldNodeMs = new FieldNode(Opcodes.ACC_PRIVATE, fieldName + "Ms", getJavaType("java.lang.Long"), null, null);
    classNode.fields.add(fieldNodeMs);
    // Create getter for Date
    MethodNode getterNodeDate = new MethodNode(Opcodes.ACC_PUBLIC, "get" + fieldNameForMethods, "()L" + type + ";", null, null);
    getterNodeDate.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    getterNodeDate.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, classNode.name, fieldName, "L" + type + ";"));
    getterNodeDate.instructions.add(new InsnNode(Opcodes.ARETURN));
    classNode.methods.add(getterNodeDate);
    // Create getter for Sec
    MethodNode getterNodeSec = new MethodNode(Opcodes.ACC_PUBLIC, "get" + fieldNameForMethods + "Sec", "()Ljava/lang/Integer;", null, null);
    getterNodeSec.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    getterNodeSec.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, classNode.name, fieldName + "Sec", "Ljava/lang/Integer;"));
    getterNodeSec.instructions.add(new InsnNode(Opcodes.ARETURN));
    classNode.methods.add(getterNodeSec);
    // Create getter for Ms
    MethodNode getterNodeMs = new MethodNode(Opcodes.ACC_PUBLIC, "get" + fieldNameForMethods + "Ms", "()Ljava/lang/Long;", null, null);
    getterNodeMs.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    getterNodeMs.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, classNode.name, fieldName + "Ms", "Ljava/lang/Long;"));
    getterNodeMs.instructions.add(new InsnNode(Opcodes.ARETURN));
    classNode.methods.add(getterNodeMs);
    // Create setter for Date
    MethodNode setterNodeDate = new MethodNode(Opcodes.ACC_PUBLIC, "set" + fieldNameForMethods, "(L" + type + ";)V", null, null);
    setterNodeDate.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    setterNodeDate.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
    setterNodeDate.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, fieldName, "L" + type + ";"));
    setterNodeDate.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    setterNodeDate.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
    setterNodeDate.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, type, "getTime", "()J", false));
    setterNodeDate.instructions.add(new LdcInsnNode(new Long(1000)));
    setterNodeDate.instructions.add(new InsnNode(Opcodes.LDIV));
    setterNodeDate.instructions.add(new InsnNode(Opcodes.L2I));
    setterNodeDate.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false));
    setterNodeDate.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, fieldName + "Sec", "Ljava/lang/Integer;"));
    setterNodeDate.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    setterNodeDate.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
    setterNodeDate.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, type, "getTime", "()J", false));
    setterNodeDate.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false));
    setterNodeDate.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, fieldName + "Ms", "Ljava/lang/Long;"));
    setterNodeDate.instructions.add(new InsnNode(Opcodes.RETURN));
    classNode.methods.add(setterNodeDate);
    // Create setter for Sec
    MethodNode setterNodeSec = new MethodNode(Opcodes.ACC_PUBLIC, "set" + fieldNameForMethods + "Sec", "(Ljava/lang/Integer;)V", null, null);
    setterNodeSec.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    setterNodeSec.instructions.add(new TypeInsnNode(Opcodes.NEW, type));
    setterNodeSec.instructions.add(new InsnNode(Opcodes.DUP));
    setterNodeSec.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
    setterNodeSec.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false));
    setterNodeSec.instructions.add(new InsnNode(Opcodes.I2L));
    setterNodeSec.instructions.add(new LdcInsnNode(new Long(1000)));
    setterNodeSec.instructions.add(new InsnNode(Opcodes.LMUL));
    setterNodeSec.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/Date", "<init>", "(J)V", false));
    setterNodeSec.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, fieldName, "L" + type + ";"));
    setterNodeSec.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    setterNodeSec.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
    setterNodeSec.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, fieldName + "Sec", "Ljava/lang/Integer;"));
    setterNodeSec.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    setterNodeSec.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/lang/Long"));
    setterNodeSec.instructions.add(new InsnNode(Opcodes.DUP));
    setterNodeSec.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
    setterNodeSec.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false));
    setterNodeSec.instructions.add(new InsnNode(Opcodes.I2L));
    setterNodeSec.instructions.add(new LdcInsnNode(new Long(1000)));
    setterNodeSec.instructions.add(new InsnNode(Opcodes.LMUL));
    setterNodeSec.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/Long", "<init>", "(J)V", false));
    setterNodeSec.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, fieldName + "Ms", "Ljava/lang/Long;"));
    setterNodeSec.instructions.add(new InsnNode(Opcodes.RETURN));
    classNode.methods.add(setterNodeSec);
    // Create setter for Ms
    MethodNode setterNodeMs = new MethodNode(Opcodes.ACC_PUBLIC, "set" + fieldNameForMethods + "Ms", "(Ljava/lang/Long;)V", null, null);
    setterNodeMs.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    setterNodeMs.instructions.add(new TypeInsnNode(Opcodes.NEW, type));
    setterNodeMs.instructions.add(new InsnNode(Opcodes.DUP));
    setterNodeMs.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
    setterNodeMs.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false));
    setterNodeMs.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/util/Date", "<init>", "(J)V", false));
    setterNodeMs.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, fieldName, "L" + type + ";"));
    setterNodeMs.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    setterNodeMs.instructions.add(new TypeInsnNode(Opcodes.NEW, "java/lang/Integer"));
    setterNodeMs.instructions.add(new InsnNode(Opcodes.DUP));
    setterNodeMs.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
    setterNodeMs.instructions.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false));
    setterNodeMs.instructions.add(new LdcInsnNode(new Long(1000)));
    setterNodeMs.instructions.add(new InsnNode(Opcodes.LDIV));
    setterNodeMs.instructions.add(new InsnNode(Opcodes.L2I));
    setterNodeMs.instructions.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "java/lang/Integer", "<init>", "(I)V", false));
    setterNodeMs.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, fieldName + "Sec", "Ljava/lang/Integer;"));
    setterNodeMs.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
    setterNodeMs.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
    setterNodeMs.instructions.add(new FieldInsnNode(Opcodes.PUTFIELD, classNode.name, fieldName + "Ms", "Ljava/lang/Long;"));
    setterNodeMs.instructions.add(new InsnNode(Opcodes.RETURN));
    classNode.methods.add(setterNodeMs);
}
Also used : FieldInsnNode(org.apache.xbean.asm5.tree.FieldInsnNode) JumpInsnNode(org.apache.xbean.asm5.tree.JumpInsnNode) TypeInsnNode(org.apache.xbean.asm5.tree.TypeInsnNode) InsnNode(org.apache.xbean.asm5.tree.InsnNode) VarInsnNode(org.apache.xbean.asm5.tree.VarInsnNode) MethodInsnNode(org.apache.xbean.asm5.tree.MethodInsnNode) IntInsnNode(org.apache.xbean.asm5.tree.IntInsnNode) LdcInsnNode(org.apache.xbean.asm5.tree.LdcInsnNode) LdcInsnNode(org.apache.xbean.asm5.tree.LdcInsnNode) FieldNode(org.apache.xbean.asm5.tree.FieldNode) MethodNode(org.apache.xbean.asm5.tree.MethodNode) MethodInsnNode(org.apache.xbean.asm5.tree.MethodInsnNode) FieldInsnNode(org.apache.xbean.asm5.tree.FieldInsnNode) TypeInsnNode(org.apache.xbean.asm5.tree.TypeInsnNode) VarInsnNode(org.apache.xbean.asm5.tree.VarInsnNode)

Example 4 with FieldNode

use of org.apache.xbean.asm5.tree.FieldNode 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;
}
Also used : FieldNode(org.apache.xbean.asm5.tree.FieldNode) LinkedList(java.util.LinkedList)

Example 5 with FieldNode

use of org.apache.xbean.asm5.tree.FieldNode in project apex-core by apache.

the class CompactUtil method setAnnotationNode.

private static void setAnnotationNode(FieldNode fn, CompactFieldNode cfn) {
    List<CompactAnnotationNode> annotations = new LinkedList<>();
    for (Object visibleAnnotation : fn.visibleAnnotations) {
        CompactAnnotationNode node = new CompactAnnotationNode();
        Map<String, Object> annotationMap = new HashMap<>();
        if (visibleAnnotation instanceof AnnotationNode) {
            AnnotationNode annotation = (AnnotationNode) visibleAnnotation;
            if (annotation.desc.contains("InputPortFieldAnnotation") || annotation.desc.contains("OutputPortFieldAnnotation")) {
                List<Object> annotationValues = annotation.values;
                if (annotationValues != null) {
                    int index = 0;
                    while (index <= annotationValues.size() - 2) {
                        String key = (String) annotationValues.get(index++);
                        Object value = annotationValues.get(index++);
                        annotationMap.put(key, value);
                    }
                    node.setAnnotations(annotationMap);
                    annotations.add(node);
                }
            }
        }
        cfn.setVisibleAnnotations(annotations);
    }
}
Also used : HashMap(java.util.HashMap) AnnotationNode(org.apache.xbean.asm5.tree.AnnotationNode) LinkedList(java.util.LinkedList)

Aggregations

FieldNode (org.apache.xbean.asm5.tree.FieldNode)4 LinkedList (java.util.LinkedList)3 HashMap (java.util.HashMap)1 AnnotationNode (org.apache.xbean.asm5.tree.AnnotationNode)1 FieldInsnNode (org.apache.xbean.asm5.tree.FieldInsnNode)1 InsnNode (org.apache.xbean.asm5.tree.InsnNode)1 IntInsnNode (org.apache.xbean.asm5.tree.IntInsnNode)1 JumpInsnNode (org.apache.xbean.asm5.tree.JumpInsnNode)1 LdcInsnNode (org.apache.xbean.asm5.tree.LdcInsnNode)1 MethodInsnNode (org.apache.xbean.asm5.tree.MethodInsnNode)1 MethodNode (org.apache.xbean.asm5.tree.MethodNode)1 TypeInsnNode (org.apache.xbean.asm5.tree.TypeInsnNode)1 VarInsnNode (org.apache.xbean.asm5.tree.VarInsnNode)1