本文整理汇总了Java中org.manifold.compiler.middle.Schematic.getNode方法的典型用法代码示例。如果您正苦于以下问题:Java Schematic.getNode方法的具体用法?Java Schematic.getNode怎么用?Java Schematic.getNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.manifold.compiler.middle.Schematic
的用法示例。
在下文中一共展示了Schematic.getNode方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetNode
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testGetNode() throws SchematicException {
Schematic sch = new Schematic("test");
// create a test node type
String nodeTypeName = "TestNode";
Map<String, PortTypeValue> ports = new HashMap<>();
NodeTypeValue nodeType = new NodeTypeValue(attributes, ports);
sch.addNodeType(nodeTypeName, nodeType);
// create a node based on this type
String nodeName = "testNode";
Map<String, Value> nodeAttrs = new HashMap<>();
Map<String, Map<String, Value>> nodePortAttrs = new HashMap<>();
NodeValue node1 = new NodeValue(nodeType, nodeAttrs, nodePortAttrs);
sch.addNode(nodeName, node1);
NodeValue actual = sch.getNode(nodeName);
assertEquals(node1, actual);
}
示例2: testModifyNodeAttribute
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testModifyNodeAttribute() throws SchematicException {
// Modify the "foo" attribute on node "nIN" to be False instead of True.
NodeValue inOriginal = originalSchematic.getNode("nIN");
assertTrue("precondition failed",
inOriginal.getAttribute(NODE_ATTR_FOO).equals(
BooleanValue.getInstance(true)));
BackAnnotationBuilder builder =
new BackAnnotationBuilder(originalSchematic);
builder.annotateNodeAttribute("nIN", NODE_ATTR_FOO,
BooleanValue.getInstance(false));
Schematic modifiedSchematic = builder.build();
NodeValue inModified = modifiedSchematic.getNode("nIN");
assertTrue("back-annotation failed",
inModified.getAttribute(NODE_ATTR_FOO).equals(
BooleanValue.getInstance(false)));
}
示例3: testModifyNodeAttribute_PreservesOthers
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testModifyNodeAttribute_PreservesOthers()
throws SchematicException {
// Check that modifying one node attribute doesn't modify any others.
NodeValue inOriginal = originalSchematic.getNode("nIN");
InferredValue vBar = (InferredValue) inOriginal.getAttribute(NODE_ATTR_BAR);
assertTrue("precondition failed",
vBar.get().equals(
BooleanValue.getInstance(true)));
BackAnnotationBuilder builder =
new BackAnnotationBuilder(originalSchematic);
builder.annotateNodeAttribute("nIN", NODE_ATTR_FOO,
BooleanValue.getInstance(false));
Schematic modifiedSchematic = builder.build();
NodeValue inModified = modifiedSchematic.getNode("nIN");
vBar = (InferredValue) inModified.getAttribute(NODE_ATTR_BAR);
assertTrue("back-annotation smashed unmodified node attribute",
vBar.get().equals(
BooleanValue.getInstance(true)));
}
示例4: testModifyNodeAttribute_ToInferred
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testModifyNodeAttribute_ToInferred()
throws SchematicException {
// Modify the "iBaz" attribute on node "nIN" to be <Inferred> instead of
// True
NodeValue inOriginal = originalSchematic.getNode("nIN");
InferredValue vBar = (InferredValue) inOriginal.getAttribute(NODE_ATTR_BAR);
assertTrue("precondition failed", vBar.isSet());
assertTrue("precondition failed",
vBar.get().equals(
BooleanValue.getInstance(true)));
InferredTypeValue maybeBool = new InferredTypeValue(
originalSchematic.getUserDefinedType("Bool"));
Value newValue = new InferredValue(maybeBool);
BackAnnotationBuilder builder =
new BackAnnotationBuilder(originalSchematic);
builder.annotateNodeAttribute("nIN", NODE_ATTR_BAR, newValue);
Schematic modifiedSchematic = builder.build();
NodeValue inModified = modifiedSchematic.getNode("nIN");
vBar = (InferredValue) inModified.getAttribute(NODE_ATTR_BAR);
assertFalse("back-annotation failed", vBar.isSet());
}
示例5: testPassthrough
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testPassthrough() throws SchematicException {
// If we don't make any annotations, the builder should give us back
// a schematic whose nodes, ports, connections, and constraints
// have the same attributes as the one that we started with.
BackAnnotationBuilder builder =
new BackAnnotationBuilder(originalSchematic);
Schematic modifiedSchematic = builder.build();
NodeValue inNodeOriginal = originalSchematic.getNode("nIN");
NodeValue inNodeModified = modifiedSchematic.getNode("nIN");
assertTrue(inNodeOriginal.getAttributes().
equals(inNodeModified.getAttributes()));
PortValue inPortOriginal = inNodeOriginal.getPort(IN_PORT_NAME);
PortValue inPortModified = inNodeModified.getPort(IN_PORT_NAME);
assertTrue(inPortOriginal.getAttributes().
equals(inPortModified.getAttributes()));
ConnectionValue inConnOriginal = originalSchematic.
getConnection(CONNECTION_NAME);
ConnectionValue inConnModified = modifiedSchematic.
getConnection(CONNECTION_NAME);
assertTrue(inConnOriginal.getAttributes().
equals(inConnModified.getAttributes()));
}
示例6: testCopyConstraint_RecreatedNode
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testCopyConstraint_RecreatedNode()
throws SchematicException {
// Check that a constraint referencing a node actually refers
// to the correct node in the backannotated copy.
BackAnnotationBuilder builder =
new BackAnnotationBuilder(originalSchematic);
Schematic modifiedSchematic = builder.build();
NodeValue expectedNode = modifiedSchematic.getNode("nIN");
ConstraintValue cxt = modifiedSchematic.getConstraint("c1");
NodeValue actualNode = (NodeValue) cxt.getAttribute("din_reference");
assertEquals(expectedNode, actualNode);
}
示例7: getPortValue
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
private PortValue getPortValue(Schematic sch, String ref)
throws UndeclaredIdentifierException {
int delim = ref.indexOf(GlobalConsts.NODE_PORT_DELIM);
NodeValue node = sch.getNode(ref.substring(0, delim));
return node.getPort(ref.substring(delim + 1));
}
示例8: 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());
}
示例9: 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());
}
示例10: testSerializeInferredAttributesWithoutUDT
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test
public void testSerializeInferredAttributesWithoutUDT() throws
SchematicException {
final String NODE_TYPE_NAME = "NodeInferred";
InferredTypeValue maybe = new InferredTypeValue(
BooleanTypeValue.getInstance());
BooleanValue trueValue = BooleanValue.getInstance(true);
NodeTypeValue testNodeType = new NodeTypeValue(
ImmutableMap.of("foom", maybe), 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);
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());
}
示例11: 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());
}
示例12: testGetNode_Undeclared_ThrowsException
import org.manifold.compiler.middle.Schematic; //导入方法依赖的package包/类
@Test(expected = UndeclaredIdentifierException.class)
public void testGetNode_Undeclared_ThrowsException()
throws SchematicException {
Schematic sch = new Schematic("test");
NodeValue nv = sch.getNode("bogus");
}