本文整理汇总了Java中org.manifold.compiler.middle.Schematic.getNodeType方法的典型用法代码示例。如果您正苦于以下问题:Java Schematic.getNodeType方法的具体用法?Java Schematic.getNodeType怎么用?Java Schematic.getNodeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.manifold.compiler.middle.Schematic
的用法示例。
在下文中一共展示了Schematic.getNodeType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSerialize_DerivedNode
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testSerialize_DerivedNode() throws SchematicException {
// add a derived type to the test schematic
NodeTypeValue dNodeDerived = new NodeTypeValue(
new HashMap<>(), new HashMap<>(),
testSchematic.getNodeType(IN_NODE_NAME));
String derivedNodeName = IN_NODE_NAME + "Derived";
testSchematic.addNodeType(derivedNodeName, dNodeDerived);
// serializeAsAttr, deserialize, check that the type looks okay
JsonObject result = SchematicSerializer.serialize(testSchematic);
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(result.toString());
String prettyJsonString = gson.toJson(je);
System.out.println(prettyJsonString);
Schematic sch = new SchematicDeserializer().deserialize(result);
NodeTypeValue tBase = sch.getNodeType(IN_NODE_NAME);
NodeTypeValue tDerived = sch.getNodeType(derivedNodeName);
assertTrue(tDerived.isSubtypeOf(tBase));
}
示例2: testDeserialize_DerivedNode
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testDeserialize_DerivedNode()
throws JsonSyntaxException, IOException, UndeclaredIdentifierException {
URL url = Resources
.getResource("org/manifold/compiler/serialization/data/"
+ "deserialization-derived-node-test.json");
JsonObject json = new JsonParser().parse(
Resources.toString(url, Charsets.UTF_8)).getAsJsonObject();
Schematic sch = new SchematicDeserializer().deserialize(json);
final String BASE_NODE_NAME = "baseNode";
final String DERIVED_NODE_NAME = "derivedNode";
NodeTypeValue baseNode = sch.getNodeType(BASE_NODE_NAME);
NodeTypeValue derivedNode = sch.getNodeType(DERIVED_NODE_NAME);
assertTrue(derivedNode.isSubtypeOf(baseNode));
}
示例3: deserializeNodes
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
/**
* Node defn:
*
* <pre>
* nodes: {
* node_one: {
* type: node_type,
* attributes: { ... },
* portAttrs: {
* port1: { ... },
* port2: { ... },
* ...
* }
* },
* ...
* }
* </pre>
*/
private void deserializeNodes(Schematic sch, JsonObject in)
throws SchematicException {
if (in == null) {
// TODO warning?
return;
}
for (Entry<String, JsonElement> entry : in.entrySet()) {
JsonObject nodeDef = entry.getValue().getAsJsonObject();
NodeTypeValue nodeType = sch
.getNodeType(nodeDef.get(GlobalConsts.TYPE).getAsString());
Map<String, Value> attributeMap = getValueAttributes(sch, nodeType
.getAttributes(), nodeDef);
Map<String, Map<String, Value>> portAttrMap = new HashMap<>();
JsonObject portAttrJson = nodeDef.getAsJsonObject(NodeConsts.PORT_ATTRS);
for (Entry<String, JsonElement> p : portAttrJson.entrySet()) {
if (!(nodeType.getPorts().containsKey(p.getKey()))) {
throw new UndeclaredIdentifierException(p.getKey());
}
Map<String, TypeValue> expectedPortAttributes =
nodeType.getPorts().get(p.getKey()).getAttributes();
portAttrMap.put(p.getKey(), getValueAttributes(
sch,
// here we want the port attribute map
expectedPortAttributes,
p.getValue().getAsJsonObject()));
}
NodeValue node = new NodeValue(nodeType, attributeMap, portAttrMap);
compTable.put(entry.getKey(), node);
node.getPorts()
.forEach((key, port) -> compTable.put(key, port));
sch.addNode(entry.getKey(), node);
}
}
示例4: testGetNodeType
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testGetNodeType() throws SchematicException {
Schematic sch = new Schematic("test");
// add the first node type
String nodeTypeName = "TestNode";
Map<String, PortTypeValue> ports = new HashMap<>();
NodeTypeValue nv1 = new NodeTypeValue(attributes, ports);
sch.addNodeType(nodeTypeName, nv1);
NodeTypeValue actual = sch.getNodeType(nodeTypeName);
assertEquals(nv1, actual);
}
示例5: deserializeNodeTypes
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
private void deserializeNodeTypes(Schematic sch, JsonObject in)
throws JsonSyntaxException, MultipleDefinitionException,
UndeclaredIdentifierException {
if (in == null) {
// TODO warning?
return;
}
for (Entry<String, JsonElement> entry : in.entrySet()) {
Map<String, TypeValue> attributeMap = getTypeDefAttributes(sch,
entry.getValue().getAsJsonObject());
Map<String, PortTypeValue> portMap = new HashMap<>();
JsonObject portMapJson = entry.getValue().getAsJsonObject()
.getAsJsonObject(NodeTypeConsts.PORT_MAP);
for (Entry<String, JsonElement> portEntry : portMapJson.entrySet()) {
portMap.put(portEntry.getKey(), sch.getPortType(portEntry.getValue()
.getAsString()));
}
// get supertype if it exists
NodeTypeValue supertype = null;
if (entry.getValue().getAsJsonObject().has(SUPERTYPE)) {
String supertypeName = entry.getValue().getAsJsonObject()
.get(SUPERTYPE).getAsString();
supertype = sch.getNodeType(supertypeName);
}
NodeTypeValue nodeTypeValue;
if (supertype == null) {
nodeTypeValue = new NodeTypeValue(attributeMap, portMap);
} else {
nodeTypeValue = new NodeTypeValue(attributeMap, portMap, supertype);
}
compTable.put(entry.getKey(), nodeTypeValue);
sch.addNodeType(entry.getKey(), nodeTypeValue);
}
}
示例6: testGetNodeType_Undeclared_ThrowsException
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test(expected = UndeclaredIdentifierException.class)
public void testGetNodeType_Undeclared_ThrowsException()
throws SchematicException {
Schematic sch = new Schematic("test");
NodeTypeValue tv = sch.getNodeType("bogus");
}