当前位置: 首页>>代码示例>>Java>>正文


Java Schematic.getNodeType方法代码示例

本文整理汇总了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));
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:24,代码来源:TestSerialization.java

示例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));

}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:20,代码来源:TestSerialization.java

示例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);
  }
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:58,代码来源:SchematicDeserializer.java

示例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);
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:12,代码来源:TestSchematic.java

示例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);
  }
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:42,代码来源:SchematicDeserializer.java

示例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");
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:7,代码来源:TestSchematic.java


注:本文中的org.manifold.compiler.middle.Schematic.getNodeType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。