construct method
Creates a new constant object by applying constructor arguments to this object.
This is used during constant evaluation to create new objects based on existing ones with constructor arguments applied.
@param args The argument list from the constructor call @param evaluator The constant evaluator to evaluate arguments @param name The constructor name (optional) @return A new constant object with arguments applied
Implementation
ConstObjectImpl construct(
ArgumentList args,
ConstantEvaluator evaluator, [
String? name,
]) {
final Map<String, Constant?> props = Map<String, Constant?>.of(this.props);
for (int i = 0; i < args.arguments.length; i++) {
final Expression arg = args.arguments[i];
if (arg is NamedExpression) {
final String name = arg.name.label.name;
props[name] = evaluator.evaluate(arg.expression);
} else {
final String? name = positionalNames[i];
if (name != null) {
props[name] = evaluator.evaluate(arg);
}
}
}
return ConstObjectImpl(
props,
type,
positionalNames: positionalNames,
constructorName: name,
constructorArguments: List<Expression>.of(args.arguments),
);
}