本文整理汇总了Java中org.manifold.compiler.middle.Schematic类的典型用法代码示例。如果您正苦于以下问题:Java Schematic类的具体用法?Java Schematic怎么用?Java Schematic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Schematic类属于org.manifold.compiler.middle包,在下文中一共展示了Schematic类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserializeConnections
import org.manifold.compiler.middle.Schematic; //导入依赖的package包/类
/**
* <pre>
* connections: {
* con_one: {
* type: connection_type
* attributes: { ... }
* from: nodeName:portName
* to: nodeName:portName
* },
* ...
* }
* </pre>
*/
private void deserializeConnections(Schematic sch, JsonObject in)
throws UndeclaredIdentifierException, UndeclaredAttributeException,
InvalidAttributeException, MultipleAssignmentException,
TypeMismatchException {
if (in == null) {
// TODO warning?
return;
}
for (Entry<String, JsonElement> entry : in.entrySet()) {
JsonObject obj = entry.getValue().getAsJsonObject();
// TODO: read attributes; non-trivial since we no longer have their type
Map<String, Value> attributeMap = new HashMap<>();
ConnectionValue conVal = new ConnectionValue(
getPortValue(sch, obj.get(ConnectionConsts.FROM).getAsString()),
getPortValue(sch, obj.get(ConnectionConsts.TO).getAsString()),
attributeMap);
compTable.put(entry.getKey(), conVal);
sch.addConnection(entry.getKey(), conVal);
}
}
示例2: deserializeConstraints
import org.manifold.compiler.middle.Schematic; //导入依赖的package包/类
/**
* <pre>
* constraints: {
* con_one: {
* type: constraint_type
* attributes: { ... }
* },
* ...
* }
* </pre>
*/
private void deserializeConstraints(Schematic sch, JsonObject in)
throws UndeclaredIdentifierException, UndeclaredAttributeException,
InvalidAttributeException, MultipleAssignmentException,
TypeMismatchException {
if (in == null) {
// TODO warning?
return;
}
for (Entry<String, JsonElement> entry : in.entrySet()) {
JsonObject obj = entry.getValue().getAsJsonObject();
ConstraintType conType = sch.getConstraintType(obj.get(GlobalConsts.TYPE)
.getAsString());
Map<String, Value> attributeMap = getValueAttributes(sch, conType
.getAttributes(), obj);
ConstraintValue conVal = new ConstraintValue(conType,
attributeMap);
compTable.put(entry.getKey(), conVal);
sch.addConstraint(entry.getKey(), conVal);
}
}
示例3: deserialize
import org.manifold.compiler.middle.Schematic; //导入依赖的package包/类
public Schematic deserialize(JsonObject in) {
Schematic sch = new Schematic(
in.get(GlobalConsts.SCHEMATIC_NAME).getAsString());
sch.getUserDefinedTypes().forEach(compTable::put);
try {
deserializeUserDefinedTypes(sch, in.getAsJsonObject(
SchematicConsts.USER_DEF_TYPES));
deserializePortTypes(sch, in.getAsJsonObject(SchematicConsts.PORT_TYPES));
deserializeNodeTypes(sch, in.getAsJsonObject(SchematicConsts.NODE_TYPES));
deserializeConstraintTypes(sch,
in.getAsJsonObject(SchematicConsts.CONSTRAINT_TYPES));
deserializeNodes(sch, in.getAsJsonObject(SchematicConsts.NODE_DEFS));
deserializeConnections(sch,
in.getAsJsonObject(SchematicConsts.CONNECTION_DEFS));
deserializeConstraints(sch,
in.getAsJsonObject(SchematicConsts.CONSTRAINT_DEFS));
} catch (Exception e) {
Throwables.propagate(e);
}
return sch;
}
示例4: testRawSerializeRoundtrip
import org.manifold.compiler.middle.Schematic; //导入依赖的package包/类
@Test
public void testRawSerializeRoundtrip() throws IOException {
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);
JsonObject reparsed = new JsonParser().parse(prettyJsonString)
.getAsJsonObject();
Schematic deserialized = new SchematicDeserializer()
.deserialize(reparsed);
assertEquals(result, SchematicSerializer.serialize(deserialized));
}
示例5: testSerialize
import org.manifold.compiler.middle.Schematic; //导入依赖的package包/类
@Test
public void testSerialize() throws IOException {
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);
JsonObject result = SchematicSerializer.serialize(sch);
// fuck this pretty printing
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);
}
示例6: 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));
}
示例7: 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));
}
示例8: 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));
}
示例9: 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));
}
示例10: testSerialize_DerivedConstraint
import org.manifold.compiler.middle.Schematic; //导入依赖的package包/类
@Test
@Ignore
// not currently being used & breaks attribute serial/deserial.
// TODO: fix attr serial/deserial
public void testSerialize_DerivedConstraint()
throws UndeclaredIdentifierException, MultipleDefinitionException {
// add a derived constraint type to the test schematic
ConstraintType dConDerived = new ConstraintType(new HashMap<>(),
testSchematic.getConstraintType(TEST_CONSTRAINT_TYPE_NAME));
String derivedConstraintName = TEST_CONSTRAINT_TYPE_NAME + "Derived";
testSchematic.addConstraintType(derivedConstraintName, dConDerived);
// 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);
ConstraintType tBase = sch.getConstraintType(TEST_CONSTRAINT_TYPE_NAME);
ConstraintType tDerived = sch.getConstraintType(derivedConstraintName);
assertTrue(tDerived.isSubtypeOf(tBase));
}
示例11: testDeserialize_DerivedConstraint
import org.manifold.compiler.middle.Schematic; //导入依赖的package包/类
@Test
public void testDeserialize_DerivedConstraint()
throws JsonSyntaxException, IOException, UndeclaredIdentifierException {
URL url = Resources
.getResource("org/manifold/compiler/serialization/data/"
+ "deserialization-derived-constraint-test.json");
JsonObject json = new JsonParser().parse(
Resources.toString(url, Charsets.UTF_8)).getAsJsonObject();
Schematic sch = new SchematicDeserializer().deserialize(json);
final String BASE_CONSTRAINT_NAME = "baseConstraint";
final String DERIVED_CONSTRAINT_NAME = "derivedConstraint";
ConstraintType baseConstraint =
sch.getConstraintType(BASE_CONSTRAINT_NAME);
ConstraintType derivedConstraint =
sch.getConstraintType(DERIVED_CONSTRAINT_NAME);
assertTrue(derivedConstraint.isSubtypeOf(baseConstraint));
}
示例12: 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()));
}
示例13: regressionTestDeserialize_UndeclaredNodeAttributeInst_incorrect
import org.manifold.compiler.middle.Schematic; //导入依赖的package包/类
@Test
public void regressionTestDeserialize_UndeclaredNodeAttributeInst_incorrect()
throws JsonSyntaxException, IOException {
URL url = Resources
.getResource("org/manifold/compiler/serialization/data/"
+ "node_attribute_undeclared_instantiation_negative.json");
JsonObject json = new JsonParser().parse(
Resources.toString(url, Charsets.UTF_8)).getAsJsonObject();
try {
Schematic sch = new SchematicDeserializer().deserialize(json);
fail("deserialization failed to detect incorrect schematic");
} catch (RuntimeException e) {
if (e.getCause() instanceof UndeclaredAttributeException) {
UndeclaredAttributeException uae =
(UndeclaredAttributeException) e.getCause();
assertEquals("initialValue", uae.name);
} else {
fail(e.getMessage());
}
}
}
示例14: regressionTestDeserialize_UndeclaredNodeAttributeType_incorrect
import org.manifold.compiler.middle.Schematic; //导入依赖的package包/类
@Test
public void regressionTestDeserialize_UndeclaredNodeAttributeType_incorrect()
throws JsonSyntaxException, IOException {
URL url = Resources
.getResource("org/manifold/compiler/serialization/data/"
+ "node_attribute_undeclared_type_negative.json");
JsonObject json = new JsonParser().parse(
Resources.toString(url, Charsets.UTF_8)).getAsJsonObject();
try {
Schematic sch = new SchematicDeserializer().deserialize(json);
fail("deserialization failed to detect incorrect schematic");
} catch (RuntimeException e) {
if (e.getCause() instanceof UndeclaredAttributeException) {
UndeclaredAttributeException uae =
(UndeclaredAttributeException) e.getCause();
assertEquals("test1", uae.name);
} else {
fail(e.getMessage());
}
}
}
示例15: regressionTestDeserialize_UndeclaredPortAttributeInst_incorrect
import org.manifold.compiler.middle.Schematic; //导入依赖的package包/类
@Test
public void regressionTestDeserialize_UndeclaredPortAttributeInst_incorrect()
throws JsonSyntaxException, IOException {
URL url = Resources
.getResource("org/manifold/compiler/serialization/data/"
+ "port_attribute_undeclared_instantiation_negative.json");
JsonObject json = new JsonParser().parse(
Resources.toString(url, Charsets.UTF_8)).getAsJsonObject();
try {
Schematic sch = new SchematicDeserializer().deserialize(json);
fail("deserialization failed to detect incorrect schematic");
} catch (RuntimeException e) {
if (e.getCause() instanceof UndeclaredAttributeException) {
UndeclaredAttributeException uae =
(UndeclaredAttributeException) e.getCause();
assertEquals("extra", uae.name);
} else {
fail(e.getMessage());
}
}
}