use of com.datatorrent.stram.webapp.asm.Type.ParameterizedTypeNode 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++]);
}
}
}
use of com.datatorrent.stram.webapp.asm.Type.ParameterizedTypeNode 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;
}
use of com.datatorrent.stram.webapp.asm.Type.ParameterizedTypeNode 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);
}
}
}
}
use of com.datatorrent.stram.webapp.asm.Type.ParameterizedTypeNode in project apex-core by apache.
the class BaseSignatureVisitor method visitTypeArgument.
@Override
public SignatureVisitor visitTypeArgument(char typeArg) {
TypeNode t = (TypeNode) visitingStack.pop();
if (t instanceof ParameterizedTypeNode) {
visitingStack.push(t);
} else {
ParameterizedTypeNode pt = new ParameterizedTypeNode();
pt.setObjByteCode(t.getObjByteCode());
visitingStack.push(pt);
}
if (typeArg == SignatureVisitor.INSTANCEOF) {
return this;
}
WildcardTypeNode wtn = new WildcardTypeNode();
wtn.boundChar = typeArg;
visitingStack.push(wtn);
return this;
}
Aggregations