From: Jean Privat Date: Tue, 10 Oct 2017 16:52:03 +0000 (-0400) Subject: Merge: model: is_accessor X-Git-Url: http://nitlanguage.org?hp=-c Merge: model: is_accessor Add a way to associate attributes and their getters/setters. This will be useful for filtering things and groupings properties together. Pull-Request: #2559 --- 09f9c7c347bc744a4e5738c3cf6aefd218c7e20b diff --combined src/model/model.nit index 47900c5,e9e3afb..dc9b978 --- a/src/model/model.nit +++ b/src/model/model.nit @@@ -588,8 -588,6 +588,8 @@@ class MClas # Is `self` and abstract class? var is_abstract: Bool is lazy do return kind == abstract_kind + redef var is_test is lazy do return intro.is_test + redef fun mdoc_or_fallback do # Don’t use `intro.mdoc_or_fallback` because it would create an infinite @@@ -2329,20 -2327,6 +2329,20 @@@ abstract class MPropert end private var lookup_all_definitions_cache = new HashMap2[MModule, MType, Array[MPROPDEF]] + + redef var is_test is lazy do return intro.is_test + + # Does self have the `before` annotation? + var is_before: Bool is lazy do return intro.is_before + + # Does self have the `before_all` annotation? + var is_before_all: Bool is lazy do return intro.is_before_all + + # Does self have the `after` annotation? + var is_after: Bool is lazy do return intro.is_after + + # Does self have the `after_all` annotation? + var is_after_all: Bool is lazy do return intro.is_after_all end # A global method @@@ -2377,6 -2361,29 +2377,29 @@@ class MMetho # A specific method that is safe to call on null. # Currently, only `==`, `!=` and `is_same_instance` are safe fun is_null_safe: Bool do return name == "==" or name == "!=" or name == "is_same_instance" + + # Is this method a getter (auto or not)? + # + # See `getter_for`. + fun is_getter: Bool do return getter_for != null + + # The attribute this getter is for + # + # Return `null` is this method is not a getter. + var getter_for: nullable MAttribute = null is writable + + # Is this method a setter (auto or not)? + # + # See `setter_for`. + fun is_setter: Bool do return setter_for != null + + # The attribute this setter is for + # + # Return `null` is this method is not a setter. + var setter_for: nullable MAttribute = null is writable + + # Is this method a getter or a setter? + fun is_accessor: Bool do return is_getter or is_setter end # A global attribute @@@ -2385,6 -2392,21 +2408,21 @@@ class MAttribut redef type MPROPDEF: MAttributeDef + # Does this attribute have a getter (auto or not)? + # + # See `getter`. + fun has_getter: Bool do return getter != null + + # The getter of this attribute (if any) + var getter: nullable MProperty = null is writable + + # Does this attribute have a setter (auto or not)? + # + # See `setter`. + fun has_setter: Bool do return setter != null + + # The setter of this attribute (if any) + var setter: nullable MProperty = null is writable end # A global virtual type @@@ -2420,7 -2442,7 +2458,7 @@@ abstract class MPropDe # The associated global property var mproperty: MPROPERTY - redef var location: Location + redef var location redef fun visibility do return mproperty.visibility @@@ -2532,18 -2554,6 +2570,18 @@@ end redef fun mdoc_or_fallback do return mdoc or else mproperty.mdoc_or_fallback + + # Does self have the `before` annotation? + var is_before = false is writable + + # Does self have the `before_all` annotation? + var is_before_all = false is writable + + # Does self have the `after` annotation? + var is_after = false is writable + + # Does self have the `after_all` annotation? + var is_after_all = false is writable end # A local definition of a method