use of org.apache.sling.scripting.sightly.compiler.expression.nodes.MapLiteral in project sling by apache.
the class SyntheticMapRemoval method overrideMap.
private MapLiteral overrideMap(String variableName, MapLiteral mapLiteral) {
Map<String, ExpressionNode> newLiteral = new HashMap<>();
for (Map.Entry<String, ExpressionNode> entry : mapLiteral.getMap().entrySet()) {
String property = entry.getKey();
ExpressionNode valueNode = entry.getValue();
String valueVariable = valueVariableName(variableName, property);
newLiteral.put(property, new Identifier(valueVariable));
outputStream.write(new VariableBinding.Start(valueVariable, valueNode));
}
return new MapLiteral(newLiteral);
}
use of org.apache.sling.scripting.sightly.compiler.expression.nodes.MapLiteral in project sling by apache.
the class ExpressionReducer method evaluate.
@Override
public EvalResult evaluate(MapLiteral mapLiteral) {
HashMap<String, EvalResult> results = new HashMap<>();
boolean isConstant = true;
for (Map.Entry<String, ExpressionNode> entry : mapLiteral.getMap().entrySet()) {
EvalResult result = eval(entry.getValue());
results.put(entry.getKey(), result);
isConstant = isConstant && result.isConstant();
}
if (isConstant) {
HashMap<String, Object> map = new HashMap<>();
for (Map.Entry<String, EvalResult> entry : results.entrySet()) {
map.put(entry.getKey(), entry.getValue().getValue());
}
return EvalResult.constant(map);
} else {
HashMap<String, ExpressionNode> literal = new HashMap<>();
for (Map.Entry<String, EvalResult> entry : results.entrySet()) {
literal.put(entry.getKey(), entry.getValue().getNode());
}
return EvalResult.nonConstant(new MapLiteral(literal));
}
}
Aggregations