Search in sources :

Example 1 with Type

use of com.datatorrent.stram.webapp.asm.Type 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 Type

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

the class TypeGraph method addReplacement.

private void addReplacement(Type superT, Map<Type, Type> typeReplacement) {
    if (superT != null && superT instanceof ParameterizedTypeNode) {
        Type[] actualTypes = ((ParameterizedTypeNode) superT).getActualTypeArguments();
        List<TypeVariableNode> tvs = typeGraph.get(((ParameterizedTypeNode) superT).getTypeObj().getClassName()).getOrLoadClassNode().getCsv().getTypeV();
        int i = 0;
        for (TypeVariableNode typeVariableNode : tvs) {
            typeReplacement.put(typeVariableNode, actualTypes[i++]);
        }
    }
}
Also used : ClassNodeType(com.datatorrent.stram.webapp.asm.ClassNodeType) Type(com.datatorrent.stram.webapp.asm.Type) TypeVariableNode(com.datatorrent.stram.webapp.asm.Type.TypeVariableNode) ParameterizedTypeNode(com.datatorrent.stram.webapp.asm.Type.ParameterizedTypeNode)

Example 3 with Type

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

the class TypeGraph method findTypeArgument.

private Type findTypeArgument(TypeGraphVertex tgv, Map<Type, Type> typeReplacement) {
    if (tgv == null) {
        return null;
    }
    ClassSignatureVisitor csv = tgv.getOrLoadClassNode().getCsv();
    Type superC = csv.getSuperClass();
    addReplacement(superC, typeReplacement);
    Type t = getParameterizedTypeArgument(superC);
    if (t != null) {
        return t;
    }
    if (csv.getInterfaces() != null) {
        for (Type it : csv.getInterfaces()) {
            addReplacement(it, typeReplacement);
            t = getParameterizedTypeArgument(it);
            if (t != null) {
                return t;
            }
        }
    }
    for (TypeGraphVertex ancestor : tgv.ancestors) {
        return findTypeArgument(ancestor, typeReplacement);
    }
    return null;
}
Also used : ClassNodeType(com.datatorrent.stram.webapp.asm.ClassNodeType) Type(com.datatorrent.stram.webapp.asm.Type) ClassSignatureVisitor(com.datatorrent.stram.webapp.asm.ClassSignatureVisitor)

Example 4 with Type

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

the class TypeGraph method getPortTypeInfo.

private Collection<JSONObject> getPortTypeInfo(String clazzName, Map<Type, Type> typeReplacement, List<CompactFieldNode> ports) throws JSONException {
    TypeGraphVertex tgv = typeGraph.get(clazzName);
    if (tgv == null) {
        return null;
    }
    Collection<JSONObject> portInfo = new ArrayList<>();
    for (CompactFieldNode port : ports) {
        Type fieldType = port.getFieldSignatureNode().getFieldType();
        Type t = fieldType;
        if (fieldType instanceof ParameterizedTypeNode) {
            // TODO: Right now getPortInfo assumes a single parameterized type
            t = ((ParameterizedTypeNode) fieldType).getActualTypeArguments()[0];
        } else {
            // TODO: Check behavior for Ports not using Default Input/output ports
            TypeGraphVertex portVertex = typeGraph.get(port.getDescription());
            t = findTypeArgument(portVertex, typeReplacement);
            LOG.debug("Field is of type {}", fieldType.getClass());
        }
        JSONObject meta = new JSONObject();
        try {
            meta.put("name", port.getName());
            setTypes(meta, t, typeReplacement);
            portInfo.add(meta);
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
    return portInfo;
}
Also used : ClassNodeType(com.datatorrent.stram.webapp.asm.ClassNodeType) Type(com.datatorrent.stram.webapp.asm.Type) JSONObject(org.codehaus.jettison.json.JSONObject) ParameterizedTypeNode(com.datatorrent.stram.webapp.asm.Type.ParameterizedTypeNode) ArrayList(java.util.ArrayList) CompactFieldNode(com.datatorrent.stram.webapp.asm.CompactFieldNode) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException)

Example 5 with Type

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

the class TypeGraph method setTypes.

private void setTypes(JSONObject propJ, Type rawType, Map<Type, Type> typeReplacement, Set<Type> visitedType) throws JSONException {
    boolean stopRecursive = visitedType.contains(rawType);
    visitedType.add(rawType);
    // type could be replaced
    Type t = resolveType(rawType, typeReplacement);
    if (propJ == null) {
        return;
    } else {
        if (t instanceof WildcardTypeNode) {
            propJ.put("type", "?");
        } else if (t instanceof TypeNode) {
            TypeNode tn = (TypeNode) t;
            String typeS = tn.getTypeObj().getClassName();
            propJ.put("type", typeS);
            UI_TYPE uiType = UI_TYPE.getEnumFor(typeS, typeGraph);
            if (uiType != null) {
                switch(uiType) {
                    case FLOAT:
                    case LONG:
                    case INT:
                    case DOUBLE:
                    case BYTE:
                    case SHORT:
                    case STRING:
                        propJ.put("type", uiType.getName());
                        break;
                    default:
                        propJ.put("uiType", uiType.getName());
                }
            }
            if (t instanceof ParameterizedTypeNode) {
                JSONArray jArray = new JSONArray();
                for (Type ttn : ((ParameterizedTypeNode) t).getActualTypeArguments()) {
                    JSONObject objJ = new JSONObject();
                    if (!stopRecursive) {
                        setTypes(objJ, ttn, typeReplacement, visitedType);
                    }
                    jArray.put(objJ);
                }
                propJ.put("typeArgs", jArray);
            }
        }
        if (t instanceof WildcardTypeNode) {
            JSONObject typeBounds = new JSONObject();
            JSONArray jArray = new JSONArray();
            Type[] bounds = ((WildcardTypeNode) t).getUpperBounds();
            if (bounds != null) {
                for (Type type : bounds) {
                    jArray.put(type.toString());
                }
            }
            typeBounds.put("upper", jArray);
            bounds = ((WildcardTypeNode) t).getLowerBounds();
            jArray = new JSONArray();
            if (bounds != null) {
                for (Type type : bounds) {
                    jArray.put(type.toString());
                }
            }
            typeBounds.put("lower", jArray);
            propJ.put("typeBounds", typeBounds);
        }
        if (t instanceof ArrayTypeNode) {
            propJ.put("type", t.getByteString());
            propJ.put("uiType", UI_TYPE.LIST.getName());
            JSONObject jObj = new JSONObject();
            if (!stopRecursive) {
                setTypes(jObj, ((ArrayTypeNode) t).getActualArrayType(), typeReplacement, visitedType);
            }
            propJ.put("itemType", jObj);
        }
        if (t instanceof TypeVariableNode) {
            propJ.put("typeLiteral", ((TypeVariableNode) t).getTypeLiteral());
            if (!stopRecursive) {
                setTypes(propJ, ((TypeVariableNode) t).getRawTypeBound(), typeReplacement, visitedType);
            }
        }
    }
}
Also used : ClassNodeType(com.datatorrent.stram.webapp.asm.ClassNodeType) Type(com.datatorrent.stram.webapp.asm.Type) TypeVariableNode(com.datatorrent.stram.webapp.asm.Type.TypeVariableNode) WildcardTypeNode(com.datatorrent.stram.webapp.asm.Type.WildcardTypeNode) ParameterizedTypeNode(com.datatorrent.stram.webapp.asm.Type.ParameterizedTypeNode) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) ArrayTypeNode(com.datatorrent.stram.webapp.asm.Type.ArrayTypeNode) TypeNode(com.datatorrent.stram.webapp.asm.Type.TypeNode) ArrayTypeNode(com.datatorrent.stram.webapp.asm.Type.ArrayTypeNode) WildcardTypeNode(com.datatorrent.stram.webapp.asm.Type.WildcardTypeNode) ParameterizedTypeNode(com.datatorrent.stram.webapp.asm.Type.ParameterizedTypeNode)

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