var mprop2npropdef: Map[MProperty, APropdef] = new HashMap[MProperty, APropdef]
end
-redef class Prod
- # Join the text of all tokens
- # Used to get the 'real name' of method definitions.
- fun collect_text: String
- do
- var v = new TextCollectorVisitor
- v.enter_visit(self)
- assert v.text != ""
- return v.text
- end
-end
-
-private class TextCollectorVisitor
- super Visitor
- var text: String = ""
- redef fun visit(n)
- do
- if n isa Token then text += n.text
- n.visit_all(self)
- end
-end
-
redef class APropdef
# The associated main model entity
type MPROPDEF: MPropDef
name = "init"
name_node = n_kwinit
else if n_kwnew != null then
- name = "init"
+ name = "new"
name_node = n_kwnew
else
abort
modelbuilder.error(node, "Redef error: {mpropdef} redefines {mpropdef.mproperty.intro} with {param_names.length} parameter(s), {msignature.arity} expected. Signature is {mpropdef}{msignature}")
return
end
- else if mpropdef.mproperty.is_init then
+ else if mpropdef.mproperty.is_init and not mpropdef.mproperty.is_new then
# FIXME UGLY: inherit signature from a super-constructor
for msupertype in mclassdef.supertypes do
msupertype = msupertype.anchor_to(mmodule, mclassdef.bound_mtype)
mparameters.add(mparameter)
end
+ # In `new`-factories, the return type is by default the classtype.
+ if ret_type == null and mpropdef.mproperty.is_new then ret_type = mclassdef.mclass.mclass_type
+
msignature = new MSignature(mparameters, ret_type)
mpropdef.msignature = msignature
mpropdef.is_abstract = self.get_single_annotation("abstract", modelbuilder) != null