當前位置: 首頁>>代碼示例>>Java>>正文


Java Schematic.addPortType方法代碼示例

本文整理匯總了Java中org.manifold.compiler.middle.Schematic.addPortType方法的典型用法代碼示例。如果您正苦於以下問題:Java Schematic.addPortType方法的具體用法?Java Schematic.addPortType怎麽用?Java Schematic.addPortType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.manifold.compiler.middle.Schematic的用法示例。


在下文中一共展示了Schematic.addPortType方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testAddPortType_AlreadyDefined_ThrowsException

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test(expected = MultipleDefinitionException.class)
public void testAddPortType_AlreadyDefined_ThrowsException()
    throws SchematicException {
  Schematic sch = new Schematic("test");
  // add the first port type
  String portTypeName = "TestPort";
  try {
    PortTypeValue portType1 = new PortTypeValue(
        BooleanTypeValue.getInstance(), portAttributes);
    sch.addPortType(portTypeName, portType1);
  } catch (MultipleDefinitionException e) {
    fail("exception thrown too early");
  }
  // try to add another port type with the same name
  PortTypeValue portType2 = new PortTypeValue(
      BooleanTypeValue.getInstance(), portAttributes);
  sch.addPortType(portTypeName, portType2);
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:19,代碼來源:TestSchematic.java

示例2: 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

示例3: testGetConnection

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testGetConnection() throws SchematicException {
  Schematic sch = new Schematic("test");
  ConnectionTypeValue connType = null;
  NodeValue node1 = null, node2 = null;
  Map<String, Value> connAttrs = null;
  String connName = "conn1";
  // create a test port type
  String portTypeName = "TestPort";
  PortTypeValue portType = new PortTypeValue(
      BooleanTypeValue.getInstance(), portAttributes);
  sch.addPortType(portTypeName, portType);
  // create a test node type
  String nodeTypeName = "TestNode";
  Map<String, PortTypeValue> ports = new HashMap<>();
  ports.put("p", portType);
  NodeTypeValue nodeType = new NodeTypeValue(attributes, ports);
  sch.addNodeType(nodeTypeName, nodeType);
  // create two nodes based on this type
  Map<String, Value> nodeAttrs = new HashMap<>();
  Map<String, Map<String, Value>> nodePortAttrs = new HashMap<>();
  nodePortAttrs.put("p", new HashMap<>());
  node1 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode("node1", node1);
  node2 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode("node2", node2);

  // create the first connection
  connAttrs = new HashMap<>();
  ConnectionValue conn1 = new ConnectionValue(
      node1.getPort("p"), node2.getPort("p"), connAttrs);
  sch.addConnection(connName, conn1);
  ConnectionValue actual = sch.getConnection(connName);
  assertEquals(conn1, actual);
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:36,代碼來源:TestSchematic.java

示例4: testGetConnectionName

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test
public void testGetConnectionName()
    throws SchematicException {
  Schematic sch = new Schematic("test");
  // create a test port type
  String portTypeName = "TestPort";
  PortTypeValue portType1 = new PortTypeValue(
      BooleanTypeValue.getInstance(), portAttributes);
  sch.addPortType(portTypeName, portType1);

  // create a test node type
  String nodeTypeName = "TestNode";
  Map<String, PortTypeValue> ports = new HashMap<>();
  ports.put("p0", portType1);

  NodeTypeValue nodeType = new NodeTypeValue(attributes, ports);
  sch.addNodeType(nodeTypeName, nodeType);
  // create two nodes based on this type
  Map<String, Value> nodeAttrs = new HashMap<>();
  Map<String, Map<String, Value>> nodePortAttrs = new HashMap<>();
  nodePortAttrs.put("p0", new HashMap<>());
  NodeValue node1 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode("testNode1", node1);
  NodeValue node2 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode("testNode2", node2);

  String connName = "testConn1";
  ConnectionValue conn = new ConnectionValue(
      node1.getPort("p0"), node2.getPort("p0"), nodeAttrs);
  sch.addConnection(connName, conn);
  String retrievedName = sch.getConnectionName(conn);
  assertEquals(connName, retrievedName);
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:34,代碼來源:TestSchematic.java

示例5: testGetConnectionName_Undeclared_ThrowsException

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test(expected = NoSuchElementException.class)
public void testGetConnectionName_Undeclared_ThrowsException()
    throws SchematicException {
  Schematic sch = new Schematic("test");
  // create a test port type
  String portTypeName = "TestPort";
  PortTypeValue portType1 = new PortTypeValue(
      BooleanTypeValue.getInstance(), portAttributes);
  sch.addPortType(portTypeName, portType1);

  // create a test node type
  String nodeTypeName = "TestNode";
  Map<String, PortTypeValue> ports = new HashMap<>();
  ports.put("p0", portType1);

  NodeTypeValue nodeType = new NodeTypeValue(attributes, ports);
  sch.addNodeType(nodeTypeName, nodeType);
  // create two nodes based on this type
  Map<String, Value> nodeAttrs = new HashMap<>();
  Map<String, Map<String, Value>> nodePortAttrs = new HashMap<>();
  nodePortAttrs.put("p0", new HashMap<>());
  NodeValue node1 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode("testNode1", node1);
  NodeValue node2 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
  sch.addNode("testNode2", node2);

  String connName = "testConn1";
  ConnectionValue conn = new ConnectionValue(
      node1.getPort("p0"), node2.getPort("p0"), nodeAttrs);
  //sch.addConnection(connName, conn);
  String retrievedName = sch.getConnectionName(conn);
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:33,代碼來源:TestSchematic.java

示例6: elaborateSchematicTypes

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
public static void elaborateSchematicTypes(ExpressionGraph g, Schematic s)
    throws Exception {
  // look for all primitive node/port vertices in the expression graph;
  // for each one, find any variables to which
  // it is directly assigned, and use the non-namespaced identifier
  // as the type name in the schematic
  for (ExpressionVertex v : g.getNonVariableVertices()) {
    if (v instanceof PrimitivePortVertex ||
        v instanceof PrimitiveNodeVertex) {
      v.elaborate(); // usually redundant but always safe
      List<ExpressionEdge> outgoingEdges = g.getEdgesFromSource(v);
      for (ExpressionEdge e : outgoingEdges) {
        if (e.getTarget() instanceof VariableReferenceVertex) {
          VariableReferenceVertex id = (VariableReferenceVertex)
              e.getTarget();
          String typename = id.getIdentifier().getName();
          // now add to the correct schematic type list
          if (v instanceof PrimitivePortVertex) {
            log.debug("elaborated port type " + typename);
            PortTypeValue portType = (PortTypeValue) v.getValue();
            s.addPortType(typename, portType);
          } else if (v instanceof PrimitiveNodeVertex) {
            log.debug("elaborated node type " + typename);
            NodeTypeValue nodeType = (NodeTypeValue) v.getValue();
            s.addNodeType(typename, nodeType);
          }
        }
      } // for (e: outgoingEdges)
    } // if (v instanceof ...)
  }
}
 
開發者ID:manifold-lang,項目名稱:manifold-frontend,代碼行數:32,代碼來源:Main.java

示例7: 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

示例8: setup

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Before
public void setup() throws SchematicException {

  testSchematic = new Schematic(TEST_SCHEMATIC_NAME);

  // port type
  PortTypeValue din = new PortTypeValue(
      testSchematic.getUserDefinedType("Bool"), new HashMap<>());
  PortTypeValue dout = new PortTypeValue(
      testSchematic.getUserDefinedType("Bool"), new HashMap<>());
  testSchematic.addPortType(DIGITAL_IN, din);
  testSchematic.addPortType(DIGITAL_OUT, dout);

  // node type
  HashMap<String, PortTypeValue> dinPortMap = new HashMap<>();
  dinPortMap.put(IN_PORT_NAME, din);

  HashMap<String, PortTypeValue> doutPortMap = new HashMap<>();
  doutPortMap.put(OUT_PORT_NAME, dout);

  NodeTypeValue dinNodeType = new NodeTypeValue(new HashMap<>(), dinPortMap);
  NodeTypeValue doutNodeType = new NodeTypeValue(new HashMap<>(),
      doutPortMap);

  testSchematic.addNodeType(IN_NODE_NAME, dinNodeType);
  testSchematic.addNodeType(OUT_NODE_NAME, doutNodeType);

  // node
  Map<String, Map<String, Value>> inNodeAttr = new HashMap<>();
  inNodeAttr.put(IN_PORT_NAME, new HashMap<>());

  Map<String, Map<String, Value>> outNodeAttr = new HashMap<>();
  outNodeAttr.put(OUT_PORT_NAME, new HashMap<>());

  NodeValue inNode = new NodeValue(dinNodeType, new HashMap<>(), inNodeAttr);
  testSchematic.addNode("nIN", inNode);

  NodeValue outNode = new NodeValue(doutNodeType, new HashMap<>(),
      outNodeAttr);
  testSchematic.addNode("nOUT", outNode);

  ConnectionValue con = new ConnectionValue(inNode
      .getPort(IN_PORT_NAME), outNode.getPort(OUT_PORT_NAME),
      new HashMap<>());

  testSchematic.addConnection(CONNECTION_NAME, con);

  // constraint
  TypeValue stringType = testSchematic.getUserDefinedType("String");
  ConstraintType constraintType = new ConstraintType(ImmutableMap.of(
      "foo", stringType,
      "din_reference", dinNodeType,
      "port_reference", din));
  testSchematic.addConstraintType(TEST_CONSTRAINT_TYPE_NAME, constraintType);

  ConstraintValue constraintValue = new ConstraintValue(constraintType,
      ImmutableMap.of(
          "foo", new StringValue(stringType, "bar"),
          "din_reference", inNode,
          "port_reference", inNode.getPort(IN_PORT_NAME)));

  testSchematic.addConstraint("c1", constraintValue);
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:64,代碼來源:TestSerialization.java

示例9: testAddConnection_AlreadyDeclared_ThrowsException

import org.manifold.compiler.middle.Schematic; //導入方法依賴的package包/類
@Test(expected = MultipleAssignmentException.class)
public void testAddConnection_AlreadyDeclared_ThrowsException()
    throws SchematicException {
  Schematic sch = new Schematic("test");
  ConnectionTypeValue connType = null;
  NodeValue node1 = null, node2 = null;
  Map<String, Value> connAttrs = null;
  String connName = "conn1";
  try {
    // create a test port type
    String portTypeName = "TestPort";
    PortTypeValue portType = new PortTypeValue(
        BooleanTypeValue.getInstance(), portAttributes);
    sch.addPortType(portTypeName, portType);
    // create a test node type
    String nodeTypeName = "TestNode";
    Map<String, PortTypeValue> ports = new HashMap<>();
    ports.put("p", portType);
    NodeTypeValue nodeType = new NodeTypeValue(attributes, ports);
    sch.addNodeType(nodeTypeName, nodeType);
    // create two nodes based on this type
    Map<String, Value> nodeAttrs = new HashMap<>();
    Map<String, Map<String, Value>> nodePortAttrs = new HashMap<>();
    nodePortAttrs.put("p", new HashMap<>());
    node1 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
    sch.addNode("node1", node1);
    node2 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
    sch.addNode("node2", node2);

    // create the first connection
    connAttrs = new HashMap<>();
    ConnectionValue conn1 = new ConnectionValue(
        node1.getPort("p"), node2.getPort("p"), connAttrs);
    sch.addConnection(connName, conn1);
  } catch (MultipleAssignmentException e) {
    fail("exception thrown too early");
  }
  ConnectionValue conn2 = new ConnectionValue(
      node1.getPort("p"), node2.getPort("p"), connAttrs);
  sch.addConnection(connName, conn2);
}
 
開發者ID:manifold-lang,項目名稱:manifold-core,代碼行數:42,代碼來源:TestSchematic.java


注:本文中的org.manifold.compiler.middle.Schematic.addPortType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。