PrimitiveTypeConsequenceRewrite { public String rewrite(String consequence) { BlockStmt blockStmt; try { blockStmt = StaticJavaParser.parseBlock(consequence); } catch (ParseProblemException e) { logger.warn(String.format("Cannot post process consequence: %s", consequence)); return consequence; } for (Statement t : blockStmt.getStatements()) { t.findAll(CastExpr.class, ce -> ce.getExpression().isNameExpr()).forEach(this::convertStatement); } return blockStmt.toString(); } PrimitiveTypeConsequenceRewrite(RuleContext context); String rewrite(String consequence);  }
@Test public void shouldConvertCastOfShortToShortValue() { RuleContext context = createContext(); context.addDeclaration("$interimVar", int.class); String rewritten = new PrimitiveTypeConsequenceRewrite(context) .rewrite("{ $address.setShortNumber((short)$interimVar); }"); assertThat(rewritten, equalToIgnoringWhiteSpace("{ $address.setShortNumber($interimVar.shortValue()); }")); }