SymbolResolver extends TreeSymbolTable { @Override public FixValue<?> assign(PathStep pathStep, FixValue<?> value) throws ModelException { final String pathName = pathStep.getName(); if (pathName.startsWith("$")) { final Scope variables = (Scope) super.resolve(VARIABLE_ROOT); final PathStep vPathStep = new PathStep(pathName.substring(1)); vPathStep.setIndex(pathStep.getIndex()); vPathStep.setPredicate(pathStep.getPredicate()); return variables.assign(vPathStep, value); } else if (pathName.startsWith("this.")) { final Scope variables = (Scope) super.resolve(LOCAL_ROOT); final PathStep vPathStep = new PathStep(pathName.substring(5)); vPathStep.setIndex(pathStep.getIndex()); vPathStep.setPredicate(pathStep.getPredicate()); return variables.assign(vPathStep, value); } else { return super.assign(pathStep, value); } } SymbolResolver(); @Override FixValue<?> assign(PathStep pathStep, FixValue<?> value); @Override FixNode resolve(PathStep pathStep); static final PathStep VARIABLE_ROOT; static final PathStep CODE_SET_ROOT; static final PathStep LOCAL_ROOT; }
@Test public void testAssign() throws ModelException { FixValue<?> value = new FixValue<Integer>("x", FixType.intType, 33); PathStep pathStep = new PathStep("$x"); symbolResolver.assign(pathStep, value); @SuppressWarnings("unchecked") FixValue<Integer> found = (FixValue<Integer>) symbolResolver.resolve(pathStep); assertNotNull(found); assertEquals(33, found.getValue().intValue()); }