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


Java Schematic.getPortType方法代码示例

本文整理汇总了Java中org.manifold.compiler.middle.Schematic.getPortType方法的典型用法代码示例。如果您正苦于以下问题:Java Schematic.getPortType方法的具体用法?Java Schematic.getPortType怎么用?Java Schematic.getPortType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.manifold.compiler.middle.Schematic的用法示例。


在下文中一共展示了Schematic.getPortType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSerialize_DerivedPort

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testSerialize_DerivedPort()
    throws UndeclaredIdentifierException, MultipleDefinitionException {
  // add a derived port type to the test schematic
  PortTypeValue dPortDerived = new PortTypeValue(
      testSchematic.getUserDefinedType("Bool"), new HashMap<>(),
      testSchematic.getPortType(DIGITAL_IN));
  String derivedPortName = DIGITAL_IN + "Derived";
  testSchematic.addPortType(derivedPortName, dPortDerived);
  // 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);
  PortTypeValue tBase = sch.getPortType(DIGITAL_IN);
  PortTypeValue tDerived = sch.getPortType(derivedPortName);
  assertTrue(tDerived.isSubtypeOf(tBase));
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:25,代码来源:TestSerialization.java

示例2: testDeserialize_DerivedPort

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testDeserialize_DerivedPort()
    throws JsonSyntaxException, IOException, UndeclaredIdentifierException {
  URL url = Resources
      .getResource("org/manifold/compiler/serialization/data/"
          + "deserialization-derived-port-test.json");

  JsonObject json = new JsonParser().parse(
      Resources.toString(url, Charsets.UTF_8)).getAsJsonObject();
  Schematic sch = new SchematicDeserializer().deserialize(json);

  final String BASE_PORT_NAME = "basePort";
  final String DERIVED_PORT_NAME = "derivedPort";

  PortTypeValue basePort = sch.getPortType(BASE_PORT_NAME);
  PortTypeValue derivedPort = sch.getPortType(DERIVED_PORT_NAME);
  assertTrue(derivedPort.isSubtypeOf(basePort));
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:19,代码来源:TestSerialization.java

示例3: testGetPortType

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testGetPortType() throws SchematicException {
  Schematic sch = new Schematic("test");
  // add the first port type
  String portTypeName = "TestPort";
  PortTypeValue portType1 = new PortTypeValue(
      BooleanTypeValue.getInstance(), portAttributes);

  sch.addPortType(portTypeName, portType1);
  PortTypeValue actual = sch.getPortType(portTypeName);
  assertEquals(portType1, actual);
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:13,代码来源:TestSchematic.java

示例4: deserializePortTypes

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
private void deserializePortTypes(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());

    // get signal type
    if (!(entry.getValue().getAsJsonObject().has(SIGNAL_TYPE))) {
      throw new JsonSyntaxException("port type '" + entry.getKey() + "'"
          + " does not define a signal type;"
          + " possible schematic version mismatch");
    }
    String signalTypeName = entry.getValue().getAsJsonObject()
        .get(SIGNAL_TYPE).getAsString();
    TypeValue signalType = sch.getUserDefinedType(signalTypeName);

    // get supertype if it exists
    PortTypeValue supertype = null;
    if (entry.getValue().getAsJsonObject().has(SUPERTYPE)) {
      String supertypeName = entry.getValue().getAsJsonObject()
          .get(SUPERTYPE).getAsString();
      supertype = sch.getPortType(supertypeName);
    }

    PortTypeValue portTypeValue = null;
    if (supertype == null) {
      portTypeValue = new PortTypeValue(signalType, attributeMap);
    } else {
      portTypeValue = new PortTypeValue(signalType, attributeMap, supertype);
    }

    compTable.put(entry.getKey(), portTypeValue);
    sch.addPortType(entry.getKey(), portTypeValue);
  }
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:43,代码来源:SchematicDeserializer.java

示例5: testDeserialize

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testDeserialize() throws IOException,
    UndeclaredIdentifierException, UndeclaredAttributeException {
  final String IN_NODE_NAME = "in_node";
  final String OUT_NODE_NAME = "out_node";
  final String DIGITAL_IN_PORT_NAME = "digital_in";
  final String DIGITAL_OUT_PORT_NAME = "digital_out";

  URL url = Resources
      .getResource("org/manifold/compiler/serialization/data/"
          + "deserialization-types-test.json");

  JsonObject json = new JsonParser().parse(
      Resources.toString(url, Charsets.UTF_8)).getAsJsonObject();
  Schematic sch = new SchematicDeserializer().deserialize(json);

  Map<String, PortTypeValue> outNodePorts = sch.getNodeType(OUT_NODE_NAME)
      .getPorts();
  Map<String, PortTypeValue> inNodePorts = sch.getNodeType(IN_NODE_NAME)
      .getPorts();

  PortTypeValue digitalIn = sch.getPortType(DIGITAL_IN_PORT_NAME);
  PortTypeValue digitalOut = sch.getPortType(DIGITAL_OUT_PORT_NAME);

  assertEquals(TEST_SCHEMATIC_NAME, sch.getName());

  assertTrue(sch.getUserDefinedType("Flag")
      .isSubtypeOf(BooleanTypeValue.getInstance()));

  assertEquals(digitalIn, inNodePorts.get("in1"));
  assertEquals(digitalIn, inNodePorts.get("in2"));
  assertEquals(digitalOut, outNodePorts.get("out2"));
  assertEquals(digitalOut, outNodePorts.get("out2"));

  NodeValue andNode = sch.getNode("and_node");
  NodeValue andNode2 = sch.getNode("and_node2");

  assertEquals(sch.getNodeType("and"), andNode.getType());
  assertEquals(andNode.getType(), andNode2.getType());
  assertEquals(digitalIn, andNode.getPort("in1").getType());
  assertFalse(((BooleanValue) andNode.getAttribute("is_awesome"))
      .toBoolean());
  assertTrue(((BooleanValue) andNode2.getAttribute("is_awesome"))
      .toBoolean());

  ConnectionValue conVal = sch.getConnection("con1");
  assertEquals(andNode.getPort("out1"), conVal.getFrom());
  assertEquals(andNode2.getPort("in2"), conVal.getTo());
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:50,代码来源:TestSerialization.java

示例6: testDeserializeInferredAttributes

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testDeserializeInferredAttributes() throws IOException,
    UndeclaredIdentifierException, UndeclaredAttributeException {
  final String IN_NODE_NAME = "in_node";
  final String OUT_NODE_NAME = "out_node";
  final String DIGITAL_IN_PORT_NAME = "digital_in";
  final String DIGITAL_OUT_PORT_NAME = "digital_out";

  URL url = Resources
      .getResource("org/manifold/compiler/serialization/data/"
          + "deserialization-inferred-attributes-test.json");
  JsonObject json = new JsonParser().parse(
      Resources.toString(url, Charsets.UTF_8)).getAsJsonObject();
  Schematic sch = new SchematicDeserializer().deserialize(json);

  Map<String, PortTypeValue> outNodePorts = sch.getNodeType(OUT_NODE_NAME)
      .getPorts();
  Map<String, PortTypeValue> inNodePorts = sch.getNodeType(IN_NODE_NAME)
      .getPorts();

  PortTypeValue digitalIn = sch.getPortType(DIGITAL_IN_PORT_NAME);
  PortTypeValue digitalOut = sch.getPortType(DIGITAL_OUT_PORT_NAME);

  assertEquals(TEST_SCHEMATIC_NAME, sch.getName());

  assertEquals(digitalIn, inNodePorts.get("in1"));
  assertEquals(digitalIn, inNodePorts.get("in2"));
  assertEquals(digitalOut, outNodePorts.get("out2"));
  assertEquals(digitalOut, outNodePorts.get("out2"));

  NodeValue andNode = sch.getNode("and_node");
  NodeValue andNode2 = sch.getNode("and_node2");

  assertEquals(sch.getNodeType("and"), andNode.getType());
  assertEquals(andNode.getType(), andNode2.getType());
  assertEquals(digitalIn, andNode.getPort("in1").getType());

  assertEquals(BooleanValue.getInstance(false),
      ((InferredValue) andNode.getAttribute("is_awesome")).get());
  assertEquals(null,
      ((InferredValue) andNode2.getAttribute("is_awesome")).get());

  ConnectionValue conVal = sch.getConnection("con1");
  assertEquals(andNode.getPort("out1"), conVal.getFrom());
  assertEquals(andNode2.getPort("in2"), conVal.getTo());

  InferredValue foom = (InferredValue) andNode.getPort("out1")
      .getAttributes().get("foom");
  InferredValue foom2 = (InferredValue) andNode2.getPort("out1")
      .getAttributes().get("foom");
  assertEquals(null, foom.get());
  assertEquals(BooleanValue.getInstance(true), foom2.get());

  assertEquals(sch.getUserDefinedType("Bool"),
      ((InferredTypeValue) foom.getType()).getInferredType());
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:57,代码来源:TestSerialization.java

示例7: testGetPortType_Undeclared_ThrowsException

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test(expected = UndeclaredIdentifierException.class)
public void testGetPortType_Undeclared_ThrowsException()
    throws SchematicException {
  Schematic sch = new Schematic("test");
  PortTypeValue tv = sch.getPortType("bogus");
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:7,代码来源:TestSchematic.java


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