@Test void testMapAccess() { Context context = new Context(); eval("A = {x: 0, y: 22, z: 0, text: 'hello'}\n" + "A.x = 20\n" + "A.z = A.y\n" + "A.newKey = 'newValue'", context); Value value = context.variables().get("A"); assertThat(value, instanceOf(MapValue.class)); Map<String, Value> map = ((MapValue) value).getMap(); assertThat(map, allOf( hasEntry("x", NumberValue.of(20)), hasEntry("y", NumberValue.of(22)), hasEntry("z", NumberValue.of(22)) )); assertThat(map, allOf( hasEntry("text", new StringValue("hello")), hasEntry("newKey", new StringValue("newValue")) )); }
@Override public Value get(AccessNode node, Context context) { Value container = node.root.accept(this, context); return getContainer(node.indices, context, container) .orElseThrow(() -> new TypeException("Unable to get property from non-accessible type", node.start(), node.end())); }
InterpreterVisitor implements ResultVisitor<Value, Context> { @Override public Value get(AccessNode node, Context context) { Value container = node.root.accept(this, context); return getContainer(node.indices, context, container) .orElseThrow(() -> new TypeException("Unable to get property from non-accessible type", node.start(), node.end())); } }
InterpreterVisitor implements ResultVisitor<Value, Context> { @Override public Value get(AccessNode node, Context context) { Value container = node.root.accept(this, context); return getContainer(node.indices, context, container) .orElseThrow(() -> new TypeException("Unable to get property from non-accessible type", node.start(), node.end())); }  }
InterpreterVisitor implements ResultVisitor<Value, Context> { @Override public Value get(AccessNode node, Context context) { Value container = node.root.accept(this, context); return getContainer(node.indices, context, container) .orElseThrow(() -> new TypeException("Unable to get property from non-accessible type", node.start(), node.end())); }  @Override Value visit(AccessNode node, Context context); @Override Value visit(ArrayNode node, Context context); @Override Value visit(AssignNode node, Context context); @Override Value visit(BlockNode node, Context context); @Override Value visit(FunctionNode node, Context context); @Override Value visit(MapNode node, Context context); @Override Value visit(PropertyNode node, Context context); @Override Value visit(UnaryNode node, Context context); @Override Value visit(UnitNode node, Context context); @Override Value visit(ValueNode node, Context context); @Override Value visit(VariableNode node, Context context); @Override Value get(AccessNode node, Context context); @Override Value set(AccessNode node, Value value, Context context); @Override Value get(VariableNode node, Context context); @Override Value set(VariableNode node, Value value, Context context); }
InterpreterVisitor implements ResultVisitor<Value, Context> { @Override public Value get(AccessNode node, Context context) { Value container = node.root.accept(this, context); return getContainer(node.indices, context, container) .orElseThrow(() -> new TypeException("Unable to get property from non-accessible type", node.start(), node.end())); }  @Override Value visit(AccessNode node, Context context); @Override Value visit(ArrayNode node, Context context); @Override Value visit(AssignNode node, Context context); @Override Value visit(BlockNode node, Context context); @Override Value visit(FunctionNode node, Context context); @Override Value visit(MapNode node, Context context); @Override Value visit(PropertyNode node, Context context); @Override Value visit(UnaryNode node, Context context); @Override Value visit(UnitNode node, Context context); @Override Value visit(ValueNode node, Context context); @Override Value visit(VariableNode node, Context context); @Override Value get(AccessNode node, Context context); @Override Value set(AccessNode node, Value value, Context context); @Override Value get(VariableNode node, Context context); @Override Value set(VariableNode node, Value value, Context context);  }