Search in sources :

Example 6 with Type

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

the class TypeGraph method addClassPropertiesAndPorts.

private void addClassPropertiesAndPorts(String clazzName, JSONObject desc) throws JSONException {
    TypeGraphVertex tgv = typeGraph.get(clazzName);
    if (tgv == null) {
        return;
    }
    Map<String, JSONObject> results = new TreeMap<>();
    List<CompactMethodNode> getters = new LinkedList<>();
    List<CompactMethodNode> setters = new LinkedList<>();
    Map<Type, Type> typeReplacement = new HashMap<>();
    List<CompactFieldNode> ports = new LinkedList<>();
    getPublicSetterGetterAndPorts(tgv, setters, getters, typeReplacement, ports);
    desc.put("portTypeInfo", getPortTypeInfo(clazzName, typeReplacement, ports));
    for (CompactMethodNode setter : setters) {
        String prop = WordUtils.uncapitalize(setter.getName().substring(3));
        JSONObject propJ = results.get(prop);
        if (propJ == null) {
            propJ = new JSONObject();
            propJ.put("name", prop);
            results.put(prop, propJ);
        }
        propJ.put("canSet", true);
        propJ.put("canGet", false);
        MethodSignatureVisitor msv = null;
        msv = setter.getMethodSignatureNode();
        if (msv == null) {
            continue;
        }
        List<Type> param = msv.getParameters();
        if (CollectionUtils.isEmpty(param)) {
            propJ.put("type", "UNKNOWN");
        } else {
            // only one param in setter method
            setTypes(propJ, param.get(0), typeReplacement);
        // propJ.put("type", param.getTypeObj().getClassName());
        }
    // propJ.put("type", typeString);
    }
    for (CompactMethodNode getter : getters) {
        int si = getter.getName().startsWith("is") ? 2 : 3;
        String prop = WordUtils.uncapitalize(getter.getName().substring(si));
        JSONObject propJ = results.get(prop);
        if (propJ == null) {
            propJ = new JSONObject();
            propJ.put("name", prop);
            results.put(prop, propJ);
            propJ.put("canSet", false);
            // propJ.put("type", Type.getReturnType(getter.desc).getClassName());
            MethodSignatureVisitor msv = null;
            msv = getter.getMethodSignatureNode();
            if (msv == null) {
                continue;
            }
            Type rt = msv.getReturnType();
            if (rt == null) {
                propJ.put("type", "UNKNOWN");
            } else {
                setTypes(propJ, rt, typeReplacement);
            // propJ.put("type", param.getTypeObj().getClassName());
            }
        }
        propJ.put("canGet", true);
    }
    desc.put("properties", results.values());
}
Also used : HashMap(java.util.HashMap) CompactFieldNode(com.datatorrent.stram.webapp.asm.CompactFieldNode) TreeMap(java.util.TreeMap) LinkedList(java.util.LinkedList) ClassNodeType(com.datatorrent.stram.webapp.asm.ClassNodeType) Type(com.datatorrent.stram.webapp.asm.Type) JSONObject(org.codehaus.jettison.json.JSONObject) MethodSignatureVisitor(com.datatorrent.stram.webapp.asm.MethodSignatureVisitor) CompactMethodNode(com.datatorrent.stram.webapp.asm.CompactMethodNode)

Aggregations

ClassNodeType (com.datatorrent.stram.webapp.asm.ClassNodeType)6 Type (com.datatorrent.stram.webapp.asm.Type)6 CompactFieldNode (com.datatorrent.stram.webapp.asm.CompactFieldNode)3 ParameterizedTypeNode (com.datatorrent.stram.webapp.asm.Type.ParameterizedTypeNode)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 ClassSignatureVisitor (com.datatorrent.stram.webapp.asm.ClassSignatureVisitor)2 CompactMethodNode (com.datatorrent.stram.webapp.asm.CompactMethodNode)2 TypeVariableNode (com.datatorrent.stram.webapp.asm.Type.TypeVariableNode)2 CompactClassNode (com.datatorrent.stram.webapp.asm.CompactClassNode)1 MethodSignatureVisitor (com.datatorrent.stram.webapp.asm.MethodSignatureVisitor)1 ArrayTypeNode (com.datatorrent.stram.webapp.asm.Type.ArrayTypeNode)1 TypeNode (com.datatorrent.stram.webapp.asm.Type.TypeNode)1 WildcardTypeNode (com.datatorrent.stram.webapp.asm.Type.WildcardTypeNode)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 TreeMap (java.util.TreeMap)1 JSONArray (org.codehaus.jettison.json.JSONArray)1 JSONException (org.codehaus.jettison.json.JSONException)1