ScoreVisitorImpl extends AbstractParseTreeVisitor<FixValue<?>> implements ScoreVisitor<FixValue<?>> { @Override public FixValue<?> visitAssignment(AssignmentContext ctx) { final FixValue<?> val = visit(ctx.expr()); if (val == null) { errorListener.onError( String.format("Semantic error; missing val for assignment at '%s'", ctx.getText())); return null; } final FixValue<?> var = visitVar(ctx.var()); try { if (var != null) { var.assign(val); return var; } else { final FixValue<?> namedVal = FixValueFactory.copy(pathStep.getName(), val); return currentScope.assign(pathStep, namedVal); } } catch (final ModelException e) { errorListener .onError(String.format("Semantic error; %s at '%s'", e.getMessage(), ctx.getText())); return null; } } ScoreVisitorImpl(SymbolResolver symbolResolver);  ScoreVisitorImpl(SymbolResolver symbolResolver, SemanticErrorListener errorListener); boolean isTrace(); void setTrace(boolean trace); @Override FixValue<?> visitAddSub(AddSubContext ctx); @Override FixValue<?> visitAnyExpression(AnyExpressionContext ctx); @Override FixValue<?> visitAssignment(AssignmentContext ctx); @Override FixValue<?> visitCharacter(CharacterContext ctx); @Override FixValue<?> visitContains(ContainsContext ctx); @Override FixValue<?> visitDateonly(DateonlyContext ctx); @Override FixValue<?> visitDecimal(DecimalContext ctx); @Override FixValue<?> visitDuration(DurationContext ctx); @Override FixValue<Boolean> visitEquality(EqualityContext ctx); @Override FixValue<?> visitExist(ExistContext ctx); @Override FixValue<?> visitIndex(IndexContext ctx); @Override FixValue<?> visitInteger(IntegerContext ctx); @SuppressWarnings("unchecked") @Override FixValue<Boolean> visitLogicalAnd(LogicalAndContext ctx); @Override FixValue<Boolean> visitLogicalNot(LogicalNotContext ctx); @Override FixValue<Boolean> visitLogicalOr(LogicalOrContext ctx); @Override FixValue<?> visitMulDiv(MulDivContext ctx); @Override FixValue<?> visitParens(ParensContext ctx); @Override FixValue<?> visitPred(PredContext ctx); @Override FixValue<?> visitQual(QualContext ctx); @Override FixValue<?> visitRange(RangeContext ctx); @Override FixValue<Boolean> visitRelational(RelationalContext ctx); @Override FixValue<?> visitString(StringContext ctx); @Override FixValue<?> visitTimeonly(TimeonlyContext ctx); @Override FixValue<?> visitTimestamp(TimestampContext ctx); @SuppressWarnings("unchecked") @Override FixValue<?> visitUnaryMinus(UnaryMinusContext ctx); @Override FixValue<?> visitVar(VarContext ctx); @Override FixValue<?> visitVariable(VariableContext ctx);  }
@Test public void testVisitAssignment() throws IOException { TestData[] data = new TestData[] { new TestData("$x = 33", 33), new TestData("$y = 33.5", new BigDecimal("33.5")), new TestData("$a = 'a'", 'a'), new TestData("$b = \"abc\"", "abc"),}; for (int i = 0; i < data.length; i++) { ScoreParser parser = parse(data[i].getExpression()); AnyExpressionContext ctx = parser.anyExpression(); Object expression = visitor.visitAnyExpression(ctx); FixValue<?> fixValue = (FixValue<?>) expression; assertEquals(data[i].getExpected(), fixValue.getValue()); } }