+ # Construction of the read property. If it's not correctly built just return.
+ if not build_write_property(modelbuilder, mclassdef, false) then return
+
+ if atabstract != null then mwritepropdef.is_abstract = true
+
+ var atautoinit = self.get_single_annotation("autoinit", modelbuilder)
+ if atautoinit != null then
+ if has_value then
+ modelbuilder.error(atautoinit, "Error: `autoinit` attributes cannot have an initial value.")
+ else if not mwritepropdef.is_intro then
+ modelbuilder.error(atautoinit, "Error: `autoinit` attributes cannot be set on redefinitions.")
+ else if not mclassdef.is_intro then
+ modelbuilder.error(atautoinit, "Error: `autoinit` attributes cannot be used in class refinements.")
+ else if atabstract == null then
+ modelbuilder.warning(atautoinit, "useless-autoinit", "Warning: superfluous `autoinit` on attribute.")
+ end
+ else if atabstract != null then
+ # By default, abstract attribute are not autoinit
+ noinit = true
+ end
+ end
+
+ # Build the attribute property
+ fun build_attribute_property(modelbuilder: ModelBuilder, mclassdef: MClassDef)
+ do
+ var mclass = mclassdef.mclass
+ var attribute_name = "_" + name
+
+ if not mclass.kind.need_init then
+ modelbuilder.error(self, "Error: attempt to define attribute `{name}` in the {mclass.kind} `{mclass}`.")
+ end
+ var mprop = new MAttribute(mclassdef, "_" + name, self.location, private_visibility)
+ var mpropdef = new MAttributeDef(mclassdef, mprop, self.location)
+ self.mpropdef = mpropdef
+ modelbuilder.mpropdef2npropdef[mpropdef] = self
+ end
+
+ # Build the read method property to get the value of the attribute
+ # Return `true` if the property was correctly created else return `false`.
+ # Warning the signature of the property is not set. This step is done by `build_signature`.
+ fun build_read_property(modelbuilder: ModelBuilder, mclassdef: MClassDef): Bool
+ do
+ var mclass = mclassdef.mclass
+
+ var readname = name
+ var mreadprop = modelbuilder.try_get_mproperty_by_name(self, mclassdef, readname).as(nullable MMethod)
+ if mreadprop == null then
+ var mvisibility = new_property_visibility(modelbuilder, mclassdef, self.n_visibility)
+ mreadprop = new MMethod(mclassdef, readname, self.location, mvisibility)
+ if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, false, mreadprop) then
+ mreadprop.is_broken = true
+ return false
+ end
+ else
+ if mreadprop.is_broken then return false
+ if not self.check_redef_keyword(modelbuilder, mclassdef, n_kwredef, true, mreadprop) then return false
+ check_redef_property_visibility(modelbuilder, self.n_visibility, mreadprop)
+ end
+ mclassdef.mprop2npropdef[mreadprop] = self
+
+ var attr_mpropdef = mpropdef
+ if attr_mpropdef != null then
+ mreadprop.getter_for = attr_mpropdef.mproperty
+ attr_mpropdef.mproperty.getter = mreadprop
+ end
+
+ var mreadpropdef = new MMethodDef(mclassdef, mreadprop, self.location)
+ self.mreadpropdef = mreadpropdef
+ modelbuilder.mpropdef2npropdef[mreadpropdef] = self
+ set_doc(mreadpropdef, modelbuilder)
+ if mpropdef != null then mpropdef.mdoc = mreadpropdef.mdoc
+
+ return true
+ end
+
+ # Build the write method property to set the attribute value
+ # Return `true` if the property was correctly created else return `false`.
+ # Warning the signature of the property is not set.
+ fun build_write_property(modelbuilder: ModelBuilder, mclassdef: MClassDef, is_same_visibility: Bool): Bool
+ do
+ var mclass = mclassdef.mclass
+