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


Java Schematic.getUserDefinedType方法代码示例

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


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

示例1: testDeserialize_UserDefinedArray

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

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

  final String UDT_TYPENAME = "Bitvector";
  UserDefinedTypeValue udt = sch.getUserDefinedType(UDT_TYPENAME);
  assertTrue(udt.getTypeAlias() instanceof ArrayTypeValue);
  ArrayTypeValue arrayType = (ArrayTypeValue) udt.getTypeAlias();
  assertTrue(arrayType.getElementType()
      .isSubtypeOf(BooleanTypeValue.getInstance()));
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:19,代码来源:TestSerialization.java

示例2: testSerialize_UserDefinedArray

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testSerialize_UserDefinedArray()
    throws SchematicException {
  // add an array UDT to the test schematic
  TypeValue bitvectorType = new ArrayTypeValue(
      testSchematic.getUserDefinedType("Bool"));
  String typename = "Bitvector";
  testSchematic.addUserDefinedType(
      new UserDefinedTypeValue(bitvectorType, typename));
  // serialize, 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);
  try {
    UserDefinedTypeValue udt = sch.getUserDefinedType(typename);
    assertTrue(udt.getTypeAlias() instanceof ArrayTypeValue);
    ArrayTypeValue arrayType = (ArrayTypeValue) udt.getTypeAlias();
    assertTrue(arrayType.getElementType()
        .isSubtypeOf(BooleanTypeValue.getInstance()));
  } catch (UndeclaredIdentifierException e) {
    fail("undeclared identifier '" + e.getIdentifier() + "'; "
        + "the user-defined type may not have been serialized");
  }
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:32,代码来源:TestSerialization.java

示例3: testGetUserDefinedType

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testGetUserDefinedType() throws SchematicException {
  Schematic sch = new Schematic("test");
  String udtName = "TestUDT";
  UserDefinedTypeValue tv = new UserDefinedTypeValue(
      BooleanTypeValue.getInstance(), udtName);
  sch.addUserDefinedType(tv);
  TypeValue actual = sch.getUserDefinedType(udtName);
  assertEquals(tv, actual);
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:11,代码来源: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: 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

示例6: testSerializeInferredAttributes

import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testSerializeInferredAttributes() throws
    SchematicException {

  final String NODE_TYPE_NAME = "NodeInferred";
  final String INFERRED_TYPE_NAME = "InferredBool";
  InferredTypeValue maybe = new InferredTypeValue(
      testSchematic.getUserDefinedType("Bool"));
  // add an inferred UDT to the test schematic
  UserDefinedTypeValue udtMaybe =
      new UserDefinedTypeValue(maybe, INFERRED_TYPE_NAME);
  testSchematic.addUserDefinedType(udtMaybe);
  BooleanValue trueValue = BooleanValue.getInstance(true);

  NodeTypeValue testNodeType = new NodeTypeValue(
      ImmutableMap.of("foom", udtMaybe), new HashMap<>());
  testSchematic.addNodeType(NODE_TYPE_NAME, testNodeType);

  Map<String, Value> withInferred =
      ImmutableMap.of("foom", new InferredValue(maybe, trueValue));
  Map<String, Value> withoutInferred =
      ImmutableMap.of("foom", new InferredValue(maybe));

  NodeValue nodeWithoutInferred =
      new NodeValue(testNodeType, withoutInferred, new HashMap<>());
  NodeValue nodeWithInferred =
      new NodeValue(testNodeType, withInferred, new HashMap<>());
  testSchematic.addNode("n1", nodeWithoutInferred);
  testSchematic.addNode("n2", nodeWithInferred);

  // serialize, 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);
  try {
    UserDefinedTypeValue udt = sch.getUserDefinedType(INFERRED_TYPE_NAME);
    assertTrue(udt.getTypeAlias() instanceof InferredTypeValue);
    InferredTypeValue inferredType = (InferredTypeValue) udt.getTypeAlias();
    assertTrue(inferredType.getInferredType()
        .isSubtypeOf(BooleanTypeValue.getInstance()));
  } catch (UndeclaredIdentifierException e) {
    fail("undeclared identifier '" + e.getIdentifier() + "'; "
        + "the user-defined type may not have been serialized");
  }

  NodeValue n2 = sch.getNode("n2");
  InferredValue v2 = (InferredValue) n2.getAttribute("foom");
  assertEquals(trueValue, v2.get());
  NodeValue n1 = sch.getNode("n1");
  InferredValue v1 = (InferredValue) n1.getAttribute("foom");
  assertEquals(null, v1.get());
}
 
开发者ID:manifold-lang,项目名称:manifold-core,代码行数:60,代码来源:TestSerialization.java

示例7: testGetUserDefinedType_Undeclared_ThrowsException

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


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