Search in sources :

Example 6 with ClassNode

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

Example 7 with ClassNode

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

Example 8 with ClassNode

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

Example 9 with ClassNode

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

Example 10 with ClassNode

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);
}
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) MethodNode(org.apache.xbean.asm5.tree.MethodNode) FieldInsnNode(org.apache.xbean.asm5.tree.FieldInsnNode) VarInsnNode(org.apache.xbean.asm5.tree.VarInsnNode)

Aggregations

MethodNode (org.apache.xbean.asm5.tree.MethodNode)10 FieldInsnNode (org.apache.xbean.asm5.tree.FieldInsnNode)7 InsnNode (org.apache.xbean.asm5.tree.InsnNode)7 IntInsnNode (org.apache.xbean.asm5.tree.IntInsnNode)7 JumpInsnNode (org.apache.xbean.asm5.tree.JumpInsnNode)7 LdcInsnNode (org.apache.xbean.asm5.tree.LdcInsnNode)7 MethodInsnNode (org.apache.xbean.asm5.tree.MethodInsnNode)7 TypeInsnNode (org.apache.xbean.asm5.tree.TypeInsnNode)7 VarInsnNode (org.apache.xbean.asm5.tree.VarInsnNode)7 LinkedList (java.util.LinkedList)5 TupleSchemaRegistry (org.apache.apex.malhar.sql.schema.TupleSchemaRegistry)4 FieldNode (org.apache.xbean.asm5.tree.FieldNode)4 LabelNode (org.apache.xbean.asm5.tree.LabelNode)2 ClassWriter (org.apache.xbean.asm5.ClassWriter)1 ClassNode (org.apache.xbean.asm5.tree.ClassNode)1