use of dyvilx.tools.compiler.ast.expression.intrinsic.VarargsOperator in project Dyvil by Dyvil.
the class CaseClassMetadata method createApplyMethod.
private CodeMethod createApplyMethod() {
// static final func apply<TypeParams...>(classParams...: ClassParamTypes...) -> This
final SourcePosition position = this.theClass.position();
final AttributeList attributes = AttributeList.of(Modifiers.PUBLIC | Modifiers.STATIC_FINAL | Modifiers.GENERATED);
final IType type = this.theClass.getThisType();
final CodeMethod applyMethod = new CodeMethod(this.theClass, Names.apply, type, attributes);
applyMethod.setPosition(position);
applyMethod.getTypeParameters().addAll(this.theClass.getTypeParameters());
this.copyClassParameters(applyMethod);
// = new This<TypeParams...>(classParams...)
final ArgumentList arguments = new ArgumentList();
for (IParameter param : applyMethod.getParameters()) {
// no need to check for override class parameters here, since we are dealing with parameters of the
// apply method
final IValue access;
if (param.isVarargs()) {
access = new VarargsOperator(position, new FieldAccess(param));
} else {
access = new FieldAccess(param);
}
arguments.add(access);
}
// = new This(params...)
applyMethod.setValue(new ConstructorCall(this.theClass.position(), this.theClass.getThisType(), arguments));
return applyMethod;
}
Aggregations