Search in sources :

Example 1 with TypeVariableNode

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

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

the class BaseSignatureVisitor method visitFormalTypeParameter.

@Override
public void visitFormalTypeParameter(String typeVariable) {
    if (stage == VISIT_FORMAL_TYPE && !visitingStack.isEmpty()) {
        visitingStack.pop();
    }
    stage = VISIT_FORMAL_TYPE;
    TypeVariableNode tvn = new TypeVariableNode();
    tvn.typeLiteral = typeVariable;
    visitingStack.push(tvn);
    typeV.add(tvn);
}
Also used : TypeVariableNode(com.datatorrent.stram.webapp.asm.Type.TypeVariableNode)

Example 3 with TypeVariableNode

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

Example 4 with TypeVariableNode

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

the class BaseSignatureVisitor method visitTypeVariable.

@Override
public void visitTypeVariable(String typeVariable) {
    boolean found = false;
    for (TypeVariableNode typeVariableNode : typeV) {
        if (typeVariableNode.typeLiteral.equals(typeVariable)) {
            visitingStack.push(typeVariableNode);
            found = true;
            break;
        }
    }
    if (!found) {
        TypeNode tn = new TypeNode();
        tn.setObjByteCode("T" + typeVariable + ";");
        visitingStack.push(tn);
    }
    resolveStack();
}
Also used : TypeVariableNode(com.datatorrent.stram.webapp.asm.Type.TypeVariableNode) TypeNode(com.datatorrent.stram.webapp.asm.Type.TypeNode) WildcardTypeNode(com.datatorrent.stram.webapp.asm.Type.WildcardTypeNode) ArrayTypeNode(com.datatorrent.stram.webapp.asm.Type.ArrayTypeNode) ParameterizedTypeNode(com.datatorrent.stram.webapp.asm.Type.ParameterizedTypeNode)

Aggregations

TypeVariableNode (com.datatorrent.stram.webapp.asm.Type.TypeVariableNode)4 ParameterizedTypeNode (com.datatorrent.stram.webapp.asm.Type.ParameterizedTypeNode)3 ClassNodeType (com.datatorrent.stram.webapp.asm.ClassNodeType)2 Type (com.datatorrent.stram.webapp.asm.Type)2 ArrayTypeNode (com.datatorrent.stram.webapp.asm.Type.ArrayTypeNode)2 TypeNode (com.datatorrent.stram.webapp.asm.Type.TypeNode)2 WildcardTypeNode (com.datatorrent.stram.webapp.asm.Type.WildcardTypeNode)2 JSONArray (org.codehaus.jettison.json.JSONArray)1 JSONObject (org.codehaus.jettison.json.JSONObject)1