Search in sources :

Example 1 with CompactClassNode

use of com.datatorrent.stram.webapp.asm.CompactClassNode in project apex-core by apache.

the class TypeGraph method getPublicSetterGetterAndPorts.

private void getPublicSetterGetterAndPorts(TypeGraphVertex tgv, List<CompactMethodNode> setters, List<CompactMethodNode> getters, Map<Type, Type> typeReplacement, List<CompactFieldNode> ports) {
    CompactClassNode exClass = null;
    // check if the class needs to be excluded
    for (String e : EXCLUDE_CLASSES) {
        if (e.equals(tgv.getOrLoadClassNode().getName())) {
            exClass = tgv.getOrLoadClassNode();
            break;
        }
    }
    if (exClass != null) {
        // So the setter/getter methods in Operater, Object, Class won't be counted
        for (CompactMethodNode compactMethodNode : exClass.getGetterMethods()) {
            for (Iterator<CompactMethodNode> iterator = getters.iterator(); iterator.hasNext(); ) {
                CompactMethodNode cmn = iterator.next();
                if (cmn.getName().equals(compactMethodNode.getName())) {
                    iterator.remove();
                }
            }
        }
        for (CompactMethodNode compactMethodNode : exClass.getSetterMethods()) {
            for (Iterator<CompactMethodNode> iterator = setters.iterator(); iterator.hasNext(); ) {
                CompactMethodNode cmn = iterator.next();
                if (cmn.getName().equals(compactMethodNode.getName())) {
                    iterator.remove();
                }
            }
        }
    } else {
        if (tgv.getOrLoadClassNode().getSetterMethods() != null) {
            setters.addAll(tgv.getOrLoadClassNode().getSetterMethods());
        }
        if (tgv.getOrLoadClassNode().getGetterMethods() != null) {
            getters.addAll(tgv.getOrLoadClassNode().getGetterMethods());
        }
    }
    TypeGraphVertex portVertex = typeGraph.get(Operator.Port.class.getName());
    List<CompactFieldNode> fields = tgv.getOrLoadClassNode().getPorts();
    if (fields != null) {
        for (CompactFieldNode field : fields) {
            TypeGraphVertex fieldVertex = typeGraph.get(field.getDescription());
            if (isAncestor(portVertex, fieldVertex) && !isNodeInList(ports, field)) {
                ports.add(field);
            }
        }
    }
    ClassSignatureVisitor csv = tgv.getOrLoadClassNode().getCsv();
    Type superC = csv.getSuperClass();
    addReplacement(superC, typeReplacement);
    if (csv.getInterfaces() != null) {
        for (Type it : csv.getInterfaces()) {
            addReplacement(it, typeReplacement);
        }
    }
    for (TypeGraphVertex ancestor : tgv.ancestors) {
        getPublicSetterGetterAndPorts(ancestor, setters, getters, typeReplacement, ports);
    }
}
Also used : CompactClassNode(com.datatorrent.stram.webapp.asm.CompactClassNode) ClassNodeType(com.datatorrent.stram.webapp.asm.ClassNodeType) Type(com.datatorrent.stram.webapp.asm.Type) CompactFieldNode(com.datatorrent.stram.webapp.asm.CompactFieldNode) ClassSignatureVisitor(com.datatorrent.stram.webapp.asm.ClassSignatureVisitor) CompactMethodNode(com.datatorrent.stram.webapp.asm.CompactMethodNode)

Example 2 with CompactClassNode

use of com.datatorrent.stram.webapp.asm.CompactClassNode in project apex-core by apache.

the class TypeGraph method describeClass.

public JSONObject describeClass(String clazzName) throws JSONException {
    JSONObject desc = new JSONObject();
    desc.put("name", clazzName);
    TypeGraphVertex tgv = typeGraph.get(clazzName);
    if (tgv == null) {
        return desc;
    }
    CompactClassNode cn = tgv.getOrLoadClassNode();
    if (cn.isEnum()) {
        List<String> enumNames = cn.getEnumValues();
        desc.put("enum", enumNames);
        desc.put("uiType", UI_TYPE.ENUM.getName());
    }
    UI_TYPE uType = UI_TYPE.getEnumFor(tgv.typeName, typeGraph);
    if (uType != null) {
        desc.put("uiType", uType.getName());
    }
    addClassPropertiesAndPorts(clazzName, desc);
    if (tgv.hasResource()) {
        desc.put("hasResource", "true");
    } else {
        desc.put("hasResource", "false");
    }
    return desc;
}
Also used : CompactClassNode(com.datatorrent.stram.webapp.asm.CompactClassNode) JSONObject(org.codehaus.jettison.json.JSONObject)

Aggregations

CompactClassNode (com.datatorrent.stram.webapp.asm.CompactClassNode)2 ClassNodeType (com.datatorrent.stram.webapp.asm.ClassNodeType)1 ClassSignatureVisitor (com.datatorrent.stram.webapp.asm.ClassSignatureVisitor)1 CompactFieldNode (com.datatorrent.stram.webapp.asm.CompactFieldNode)1 CompactMethodNode (com.datatorrent.stram.webapp.asm.CompactMethodNode)1 Type (com.datatorrent.stram.webapp.asm.Type)1 JSONObject (org.codehaus.jettison.json.JSONObject)1