]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Add CodeNode.has_attribute() helper and use it accordingly
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 12 Jun 2023 13:13:15 +0000 (15:13 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 12 Jun 2023 13:14:08 +0000 (15:14 +0200)
35 files changed:
codegen/valaccode.vala
codegen/valaccodeattribute.vala
codegen/valaccodebasemodule.vala
codegen/valaccodemethodmodule.vala
codegen/valaccodestructmodule.vala
codegen/valagtkmodule.vala
codegen/valagtypemodule.vala
vala/valaassignment.vala
vala/valaclass.vala
vala/valacodenode.vala
vala/valacodewriter.vala
vala/valaenum.vala
vala/valafield.vala
vala/valaflowanalyzer.vala
vala/valagenieparser.vala
vala/valagirparser.vala
vala/valamemberaccess.vala
vala/valamethod.vala
vala/valamethodcall.vala
vala/valanamespace.vala
vala/valanulltype.vala
vala/valaobjectcreationexpression.vala
vala/valaobjecttypesymbol.vala
vala/valaparameter.vala
vala/valaparser.vala
vala/valapointertype.vala
vala/valaproperty.vala
vala/valapropertyaccessor.vala
vala/valasemanticanalyzer.vala
vala/valasignal.vala
vala/valastruct.vala
vala/valasymbolresolver.vala
vala/valaunaryexpression.vala
vala/valaversionattribute.vala
vapigen/valagidlparser.vala

index 30d196b9e6603df68d040e4f179383969ad7047e..9a0283e343000d4e5efee60e7901f0f75688ad01 100644 (file)
@@ -436,15 +436,15 @@ namespace Vala {
        }
 
        public static bool get_ccode_no_accessor_method (Property p) {
-               return p.get_attribute ("NoAccessorMethod") != null;
+               return p.has_attribute ("NoAccessorMethod");
        }
 
        public static bool get_ccode_concrete_accessor (Property p) {
-               return p.get_attribute ("ConcreteAccessor") != null;
+               return p.has_attribute ("ConcreteAccessor");
        }
 
        public static bool get_ccode_has_emitter (Signal sig) {
-               return sig.get_attribute ("HasEmitter") != null;
+               return sig.has_attribute ("HasEmitter");
        }
 
        public static bool get_ccode_has_type_id (TypeSymbol sym) {
@@ -469,7 +469,7 @@ namespace Vala {
        }
 
        public static bool get_ccode_no_wrapper (Method m) {
-               return m.get_attribute ("NoWrapper") != null;
+               return m.has_attribute ("NoWrapper");
        }
 
        public static string get_ccode_sentinel (Method m) {
index f47eb3b7c584143d4fca482a326f8c1fc79a695a..08de1251f9cdc51a19ca2715471b75297733e4ff 100644 (file)
@@ -602,7 +602,7 @@ public class Vala.CCodeAttribute : AttributeCache {
        public bool array_length {
                get {
                        if (_array_length == null) {
-                               if (node.get_attribute ("NoArrayLength") != null) {
+                               if (node.has_attribute ("NoArrayLength")) {
                                        Report.deprecated (node.source_reference, "[NoArrayLength] is deprecated, use [CCode (array_length = false)] instead.");
                                        _array_length = false;
                                } else if (ccode != null && ccode.has_argument ("array_length")) {
index d1e665747d98a5d067249591f1f20795efffd97b..2f0ea22d8b9e0e33b85bf88db19f504661a8f9f7 100644 (file)
@@ -2941,7 +2941,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
        }
 
        void require_generic_accessors (Interface iface) {
-               if (iface.get_attribute ("GenericAccessors") == null) {
+               if (!iface.has_attribute ("GenericAccessors")) {
                        Report.error (iface.source_reference,
                                      "missing generic type for interface `%s', add GenericAccessors attribute to interface declaration",
                                      iface.get_full_name ());
@@ -4219,7 +4219,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                }
 
                // TODO: don't duplicate the code in CCodeMethodModule, we do this right now because it needs to be before return
-               if (current_method != null && current_method.get_attribute ("Profile") != null) {
+               if (current_method != null && current_method.has_attribute ("Profile")) {
                        string prefix = "_vala_prof_%s".printf (get_ccode_real_name (current_method));
 
                        var level = new CCodeIdentifier (prefix + "_level");
@@ -4315,7 +4315,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                unowned Class? cl = expr.value_type.type_symbol as Class;
                if (cl != null && cl.is_compact && expr.parent_node is MemberAccess) {
                        unowned MethodType? mt = ((MemberAccess) expr.parent_node).value_type as MethodType;
-                       if (mt != null && mt.method_symbol != null && mt.method_symbol.get_attribute ("DestroysInstance") != null) {
+                       if (mt != null && mt.method_symbol != null && mt.method_symbol.has_attribute ("DestroysInstance")) {
                                return true;
                        }
                }
index 6365d3ad4dec0e6baa5941ea0081fa29bc00a07b..05b9a29166da1d5e271fa9b4db98adf67aa494cf 100644 (file)
@@ -340,7 +340,7 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                bool in_gobject_creation_method = false;
                bool in_fundamental_creation_method = false;
 
-               bool profile = m.get_attribute ("Profile") != null;
+               bool profile = m.has_attribute ("Profile");
 
                string real_name = get_ccode_real_name (m);
 
index 35779f8818d4bcb648cf85e507c7b2adb0ba4c0e..e1373a331369f665153fe7c9ea56e2deda4aa501 100644 (file)
@@ -34,7 +34,7 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                        generate_struct_declaration (st.base_struct, decl_space);
                } else if (!st.external_package) {
                        // custom simple type structs cannot have a type id which depends on head-allocation
-                       if (st.get_attribute ("SimpleType") != null && !st.has_attribute_argument ("CCode", "type_id")) {
+                       if (st.has_attribute ("SimpleType") && !st.has_attribute_argument ("CCode", "type_id")) {
                                st.set_attribute_bool ("CCode", "has_type_id", false);
                        }
                }
index 69125ce574e16974108c1e3db59c02b7ecfe740f..2e9befc0c34826b01fd149650627d60623feff8f 100644 (file)
@@ -384,7 +384,7 @@ public class Vala.GtkModule : GSignalModule {
        }
 
        public override void visit_property (Property prop) {
-               if (prop.get_attribute ("GtkChild") != null && prop.field == null) {
+               if (prop.has_attribute ("GtkChild") && prop.field == null) {
                        Report.error (prop.source_reference, "[GtkChild] is only allowed on automatic properties");
                }
 
@@ -399,7 +399,7 @@ public class Vala.GtkModule : GSignalModule {
                        return;
                }
 
-               if (f.binding != MemberBinding.INSTANCE || f.get_attribute ("GtkChild") == null) {
+               if (f.binding != MemberBinding.INSTANCE || !f.has_attribute ("GtkChild")) {
                        return;
                }
 
@@ -465,7 +465,7 @@ public class Vala.GtkModule : GSignalModule {
                        return;
                }
 
-               if (m.get_attribute ("GtkCallback") == null) {
+               if (!m.has_attribute ("GtkCallback")) {
                        return;
                }
 
index c1f7a1df1e37d579d1edfdef383345671e089eb8..8d4966f05119919a4d8ff0b16127ce99b8ce54d5 100644 (file)
@@ -1474,7 +1474,7 @@ public class Vala.GTypeModule : GErrorModule {
                        }
                }
 
-               if (iface.get_attribute ("GenericAccessors") != null) {
+               if (iface.has_attribute ("GenericAccessors")) {
                        foreach (TypeParameter p in iface.get_type_parameters ()) {
                                GenericType p_type = new GenericType (p);
                                DataType p_data_type = p_type.get_actual_type (SemanticAnalyzer.get_data_type_for_symbol (cl), null, cl);
@@ -2153,7 +2153,7 @@ public class Vala.GTypeModule : GErrorModule {
 
                type_struct.add_field ("GTypeInterface", "parent_iface");
 
-               if (iface.get_attribute ("GenericAccessors") != null) {
+               if (iface.has_attribute ("GenericAccessors")) {
                        foreach (TypeParameter p in iface.get_type_parameters ()) {
                                var vdeclarator = new CCodeFunctionDeclarator ("get_%s".printf (get_ccode_type_id (p)));
                                var this_type = SemanticAnalyzer.get_data_type_for_symbol (iface);
@@ -2355,7 +2355,7 @@ public class Vala.GTypeModule : GErrorModule {
 
        public override void visit_struct (Struct st) {
                // custom simple type structs cannot have a type id which depends on head-allocation
-               if (st.get_attribute ("SimpleType") != null && !st.has_attribute_argument ("CCode", "type_id")) {
+               if (st.has_attribute ("SimpleType") && !st.has_attribute_argument ("CCode", "type_id")) {
                        st.set_attribute_bool ("CCode", "has_type_id", false);
                }
 
@@ -2445,7 +2445,7 @@ public class Vala.GTypeModule : GErrorModule {
                        base_prop = prop.base_interface_property;
                }
 
-               if (base_prop.get_attribute ("NoAccessorMethod") == null &&
+               if (!base_prop.has_attribute ("NoAccessorMethod") &&
                        prop.name == "type" && ((cl != null && !cl.is_compact) || (st != null && get_ccode_has_type_id (st)))) {
                        Report.error (prop.source_reference, "Property 'type' not allowed");
                        return;
index 1d62a17c0bc4346026e990b600e6e5ff6039710f..0c5be5bf5929c4c550376152e45dc97fa74526a3 100644 (file)
@@ -178,7 +178,7 @@ public class Vala.Assignment : Expression {
                                return false;
                        }
 
-                       if (ma.symbol_reference.get_attribute ("GtkChild") != null) {
+                       if (ma.symbol_reference.has_attribute ("GtkChild")) {
                                error = true;
                                Report.error (source_reference, "Assignment of [GtkChild] `%s' is not allowed", ma.symbol_reference.get_full_name ());
                                return false;
index a87bb4240de12e591be8f48b9a28ed44e69a6d67..cf2943e4de15a4bd6455b8580f003833671c769c 100644 (file)
@@ -56,7 +56,7 @@ public class Vala.Class : ObjectTypeSymbol {
                                if (base_class != null && !base_class.is_subtype_of (this)) {
                                        _is_compact = base_class.is_compact;
                                } else {
-                                       _is_compact = get_attribute ("Compact") != null;
+                                       _is_compact = has_attribute ("Compact");
                                }
                        }
                        return _is_compact;
@@ -85,7 +85,7 @@ public class Vala.Class : ObjectTypeSymbol {
                                if (base_class != null && !base_class.is_subtype_of (this)) {
                                        _is_immutable = base_class.is_immutable;
                                } else {
-                                       _is_immutable = get_attribute ("Immutable") != null;
+                                       _is_immutable = has_attribute ("Immutable");
                                }
                        }
                        return _is_immutable;
@@ -98,7 +98,7 @@ public class Vala.Class : ObjectTypeSymbol {
        public bool is_singleton {
                get {
                        if (_is_singleton == null) {
-                               _is_singleton = get_attribute ("SingleInstance") != null;
+                               _is_singleton = has_attribute ("SingleInstance");
                        }
                        return _is_singleton;
                }
@@ -210,7 +210,7 @@ public class Vala.Class : ObjectTypeSymbol {
         */
        public bool is_error_base {
                get {
-                       return get_attribute ("ErrorBase") != null;
+                       return has_attribute ("ErrorBase");
                }
        }
 
@@ -644,7 +644,7 @@ public class Vala.Class : ObjectTypeSymbol {
                }
 
                foreach (Property prop in get_properties ()) {
-                       if (prop.get_attribute ("NoAccessorMethod") != null && !is_subtype_of (context.analyzer.object_type)) {
+                       if (prop.has_attribute ("NoAccessorMethod") && !is_subtype_of (context.analyzer.object_type)) {
                                error = true;
                                Report.error (prop.source_reference, "NoAccessorMethod is only allowed for properties in classes derived from GLib.Object");
                                return false;
index 4ca44c8d916168bf2bbf50ce1f0fbc8b656ff148..3ff39dbc8e7c9b9a862d302c58d49e4f7109d534 100644 (file)
@@ -147,6 +147,16 @@ public abstract class Vala.CodeNode {
                return (!) a;
        }
 
+       /**
+        * Returns true if the specified attribute is set.
+        *
+        * @param  attribute attribute name
+        * @return           true if the node has the given attribute
+        */
+       public bool has_attribute (string attribute) {
+               return get_attribute (attribute) != null;
+       }
+
        /**
         * Returns true if the specified attribute argument is set.
         *
index f9f1fccd1f175a00dcb328c480075061c8e50b33..d5fcc8035a8bf5407e2d16d6a1ece6ae9f5e4af6 100644 (file)
@@ -1657,7 +1657,7 @@ public class Vala.CodeWriter : CodeVisitor {
                foreach (var attr in node.attributes) {
                        attributes.insert_sorted (attr, (a, b) => strcmp (a.name, b.name));
                }
-               if (need_cheaders && node.get_attribute ("CCode") == null) {
+               if (need_cheaders && !node.has_attribute ("CCode")) {
                        attributes.insert_sorted (new Attribute ("CCode"), (a, b) => strcmp (a.name, b.name));
                }
 
index 2d403157dd38ce05d39b32f44252f338a2feba10..b2b40285c2a8ce4d4e9fca23fb5d6212c000339e 100644 (file)
@@ -32,7 +32,7 @@ public class Vala.Enum : TypeSymbol {
        public bool is_flags {
                get {
                        if (_is_flags == null) {
-                               _is_flags = get_attribute ("Flags") != null;
+                               _is_flags = has_attribute ("Flags");
                        }
                        return _is_flags;
                }
index dbe8176e8c948719c307e849f3b26a7c7a6117df..2f675a96f6183280969dbd07ece95efc430bc38d 100644 (file)
@@ -104,7 +104,7 @@ public class Vala.Field : Variable, Lockable {
                        return false;
                }
 
-               if (get_attribute ("GtkChild") != null && variable_type.value_owned) {
+               if (has_attribute ("GtkChild") && variable_type.value_owned) {
                        Report.warning (source_reference, "[GtkChild] fields must be declared as `unowned'");
                        variable_type.value_owned = false;
                }
index 45f524546cfcb9059a7252087d28c3a3f66c1e20..c66668225c8cbf33cadda86533aceb26accb033b 100644 (file)
@@ -171,7 +171,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
                    && !(m is CreationMethod)) {
                        if (!m.is_private_symbol () && (context.internal_header_filename != null || context.use_fast_vapi)) {
                                // do not warn if internal member may be used outside this compilation unit
-                       } else if (m.parent_symbol != null && m.parent_symbol.get_attribute ("DBus") != null
+                       } else if (m.parent_symbol != null && m.parent_symbol.has_attribute ("DBus")
                            && m.get_attribute_bool ("DBus", "visible", true)) {
                                // do not warn if internal member is a visible DBus method
                        } else {
@@ -594,7 +594,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
                if (stmt.expression is MethodCall) {
                        unowned MethodCall expr = (MethodCall) stmt.expression;
                        unowned MemberAccess? ma = expr.call as MemberAccess;
-                       if (ma != null && ma.symbol_reference != null && ma.symbol_reference.get_attribute ("NoReturn") != null) {
+                       if (ma != null && ma.symbol_reference != null && ma.symbol_reference.has_attribute ("NoReturn")) {
                                mark_unreachable ();
                                return;
                        }
index cca9919ebf6b03646fd5af4e5b9631975cb1e22b..a1336ae4b586afa1fa6769ec04ddb137d1d68908 100644 (file)
@@ -2413,7 +2413,7 @@ public class Vala.Genie.Parser : CodeVisitor {
        void set_attributes (CodeNode node, List<Attribute>? attributes) {
                if (attributes != null) {
                        foreach (Attribute attr in (List<Attribute>) attributes) {
-                               if (node.get_attribute (attr.name) != null) {
+                               if (node.has_attribute (attr.name)) {
                                        Report.error (attr.source_reference, "duplicate attribute `%s'", attr.name);
                                }
                                node.attributes.append (attr);
index 1e1f51f051ee8e3f604ce77ca7b77f69f1d56ce0..fa4337019783a44448ef4776346ed0d1272f63fd 100644 (file)
@@ -645,7 +645,7 @@ public class Vala.GirParser : CodeVisitor {
 
                        for (unowned Node? node = this ; node != null ; node = node.parent) {
                                if (node.symbol is Namespace) {
-                                       if (node.symbol.get_attribute_string ("CCode", "gir_namespace") != null) {
+                                       if (node.symbol.has_attribute_argument ("CCode", "gir_namespace")) {
                                                break;
                                        }
                                }
@@ -960,8 +960,8 @@ public class Vala.GirParser : CodeVisitor {
                                                } else if (sym is Method && !(sym is CreationMethod) && node != this) {
                                                        if (m.is_virtual || m.is_abstract) {
                                                                bool different_invoker = false;
-                                                               var attr = m.get_attribute ("NoWrapper");
-                                                               if (attr != null) {
+                                                               var no_wrapper = m.has_attribute ("NoWrapper");
+                                                               if (no_wrapper) {
                                                                        /* no invoker but this method has the same name,
                                                                           most probably the invoker has a different name
                                                                           and g-ir-scanner missed it */
@@ -975,7 +975,7 @@ public class Vala.GirParser : CodeVisitor {
                                                                        }
                                                                }
                                                                if (!different_invoker) {
-                                                                       if (attr != null) {
+                                                                       if (no_wrapper) {
                                                                                Report.warning (symbol.source_reference, "Virtual method `%s' conflicts with method of the same name", get_full_name ());
                                                                        }
                                                                        node.merged = true;
@@ -1089,7 +1089,7 @@ public class Vala.GirParser : CodeVisitor {
                                                }
                                        }
 
-                                       if (prop.get_attribute ("NoAccessorMethod") == null && prop.set_accessor != null && prop.set_accessor.writable) {
+                                       if (!prop.has_attribute ("NoAccessorMethod") && prop.set_accessor != null && prop.set_accessor.writable) {
                                                var m = setter != null ? setter.symbol as Method : null;
                                                // ensure setter vfunc if the property is abstract
                                                if (m != null) {
@@ -1099,7 +1099,7 @@ public class Vala.GirParser : CodeVisitor {
                                                                prop.set_attribute ("ConcreteAccessor", false);
                                                        } else {
                                                                prop.set_accessor.value_type.value_owned = m.get_parameters()[0].variable_type.value_owned;
-                                                               if (prop.get_attribute ("ConcreteAccessor") != null && !m.is_abstract && !m.is_virtual && prop.is_abstract) {
+                                                               if (prop.has_attribute ("ConcreteAccessor") && !m.is_abstract && !m.is_virtual && prop.is_abstract) {
                                                                        prop.set_attribute ("ConcreteAccessor", true);
                                                                        prop.set_attribute ("NoAccessorMethod", false);
                                                                }
@@ -1110,7 +1110,7 @@ public class Vala.GirParser : CodeVisitor {
                                                }
                                        }
 
-                                       if (prop.get_attribute ("NoAccessorMethod") != null) {
+                                       if (prop.has_attribute ("NoAccessorMethod")) {
                                                if (!prop.overrides && parent.symbol is Class) {
                                                        // bug 742012
                                                        // find base interface property with ConcreteAccessor and this overriding property with NoAccessorMethod
@@ -1119,7 +1119,7 @@ public class Vala.GirParser : CodeVisitor {
                                                                base_prop_node.process (parser);
 
                                                                var base_property = (Property) base_prop_node.symbol;
-                                                               if (base_property.get_attribute ("ConcreteAccessor") != null) {
+                                                               if (base_property.has_attribute ("ConcreteAccessor")) {
                                                                        prop.set_attribute ("NoAccessorMethod", false);
                                                                        if (prop.get_accessor != null) {
                                                                                prop.get_accessor.value_type.value_owned = base_property.get_accessor.value_type.value_owned;
@@ -1137,7 +1137,7 @@ public class Vala.GirParser : CodeVisitor {
                                                prop.set_attribute ("NoAccessorMethod", metadata.get_bool (ArgumentType.NO_ACCESSOR_METHOD));
                                        }
 
-                                       if (prop.get_attribute ("NoAccessorMethod") != null) {
+                                       if (prop.has_attribute ("NoAccessorMethod")) {
                                                // gobject defaults
                                                if (prop.get_accessor != null) {
                                                        prop.get_accessor.value_type.value_owned = true;
index 23078f25b9b68e111f9eef658cba0467dbab0c64..31b1ca9590f78c1a5fe276dd8f8cce5d47d55183 100644 (file)
@@ -633,7 +633,7 @@ public class Vala.MemberAccess : Expression {
                        unowned CodeNode? parent = ma.parent_node;
                        if (parent != null && !(parent is ElementAccess) && !(((MemberAccess) ma).inner is BaseAccess)
                            && (!(parent is MethodCall) || ((MethodCall) parent).get_argument_list ().contains (this))) {
-                               if (sig.get_attribute ("HasEmitter") != null) {
+                               if (sig.has_attribute ("HasEmitter")) {
                                        if (!sig.check (context)) {
                                                return false;
                                        }
@@ -1161,7 +1161,7 @@ public class Vala.MemberAccess : Expression {
                        }
                }
 
-               if (symbol_reference is Method && ((Method) symbol_reference).get_attribute ("DestroysInstance") != null) {
+               if (symbol_reference is Method && ((Method) symbol_reference).has_attribute ("DestroysInstance")) {
                        unowned Class? cl = ((Method) symbol_reference).parent_symbol as Class;
                        if (cl != null && cl.is_compact && ma != null) {
                                ma.lvalue = true;
index 0814565c8faf122ee490aa6d299dd68368db8029..6a1d686cf33b2bfc4ec959d1093706f86ec38e55 100644 (file)
@@ -91,7 +91,7 @@ public class Vala.Method : Subroutine, Callable, GenericSymbol {
         */
        public bool returns_modified_pointer {
                get {
-                       return get_attribute ("ReturnsModifiedPointer") != null;
+                       return has_attribute ("ReturnsModifiedPointer");
                }
                set {
                        set_attribute ("ReturnsModifiedPointer", value);
@@ -145,7 +145,7 @@ public class Vala.Method : Subroutine, Callable, GenericSymbol {
         */
        public bool printf_format {
                get {
-                       return get_attribute ("PrintfFormat") != null;
+                       return has_attribute ("PrintfFormat");
                }
                set {
                        set_attribute ("PrintfFormat", value);
@@ -157,7 +157,7 @@ public class Vala.Method : Subroutine, Callable, GenericSymbol {
         */
        public bool scanf_format {
                get {
-                       return get_attribute ("ScanfFormat") != null;
+                       return has_attribute ("ScanfFormat");
                }
                set {
                        set_attribute ("ScanfFormat", value);
@@ -752,10 +752,10 @@ public class Vala.Method : Subroutine, Callable, GenericSymbol {
                        this_parameter.check (context);
                }
 
-               if (get_attribute ("DestroysInstance") != null) {
+               if (has_attribute ("DestroysInstance")) {
                        this_parameter.variable_type.value_owned = true;
                }
-               if (get_attribute ("NoThrow") != null) {
+               if (has_attribute ("NoThrow")) {
                        error_types = null;
                }
 
@@ -779,7 +779,7 @@ public class Vala.Method : Subroutine, Callable, GenericSymbol {
                        return false;
                }
 
-               if (get_attribute ("NoWrapper") != null && !(is_abstract || is_virtual)) {
+               if (has_attribute ("NoWrapper") && !(is_abstract || is_virtual)) {
                        error = true;
                        Report.error (source_reference, "[NoWrapper] methods must be declared abstract or virtual");
                        return false;
@@ -875,8 +875,7 @@ public class Vala.Method : Subroutine, Callable, GenericSymbol {
                        return false;
                }
 
-               var init_attr = get_attribute ("ModuleInit");
-               if (init_attr != null) {
+               if (has_attribute ("ModuleInit")) {
                        source_reference.file.context.module_init_method = this;
                }
 
@@ -886,7 +885,7 @@ public class Vala.Method : Subroutine, Callable, GenericSymbol {
                        Report.error (parameters[0].source_reference, "Named parameter required before `...'");
                }
 
-               if (get_attribute ("Print") != null && (parameters.size != 1 || parameters[0].variable_type.type_symbol != context.analyzer.string_type.type_symbol)) {
+               if (has_attribute ("Print") && (parameters.size != 1 || parameters[0].variable_type.type_symbol != context.analyzer.string_type.type_symbol)) {
                        error = true;
                        Report.error (source_reference, "[Print] methods must have exactly one parameter of type `string'");
                }
@@ -1132,7 +1131,7 @@ public class Vala.Method : Subroutine, Callable, GenericSymbol {
                // check that DBus methods at least throw "GLib.Error" or "GLib.DBusError, GLib.IOError"
                if (!(this is CreationMethod) && binding == MemberBinding.INSTANCE
                    && !overrides && access == SymbolAccessibility.PUBLIC
-                   && parent_symbol is ObjectTypeSymbol && parent_symbol.get_attribute ("DBus") != null) {
+                   && parent_symbol is ObjectTypeSymbol && parent_symbol.has_attribute ("DBus")) {
                        Attribute? dbus_attr = get_attribute ("DBus");
                        if (dbus_attr == null || dbus_attr.get_bool ("visible", true)) {
                                bool throws_gerror = false;
@@ -1182,7 +1181,7 @@ public class Vala.Method : Subroutine, Callable, GenericSymbol {
                        }
                }
 
-               if (get_attribute ("GtkCallback") != null) {
+               if (has_attribute ("GtkCallback")) {
                        used = true;
                }
 
index 7333891b412289ef2724bf11209f6404b2f2a1e1..3f0c0d11814c4a923e87fef42046a0248a7edf2b 100644 (file)
@@ -227,7 +227,7 @@ public class Vala.MethodCall : Expression, CallableExpression {
                                }
                        }
 
-                       if (ma.symbol_reference != null && ma.symbol_reference.get_attribute ("Assert") != null) {
+                       if (ma.symbol_reference != null && ma.symbol_reference.has_attribute ("Assert")) {
                                this.is_assert = true;
 
                                if (argument_list.size == 1) {
@@ -426,7 +426,7 @@ public class Vala.MethodCall : Expression, CallableExpression {
                }
 
                // concatenate stringified arguments for methods with attribute [Print]
-               if (mtype is MethodType && ((MethodType) mtype).method_symbol.get_attribute ("Print") != null) {
+               if (mtype is MethodType && ((MethodType) mtype).method_symbol.has_attribute ("Print")) {
                        var template = new Template (source_reference);
                        foreach (Expression arg in argument_list) {
                                arg.parent_node = null;
index d62babb63fd306e42f631de6ca3caa505c280c11..1e763f32e4967379a879464bf48e91db39670d9b 100644 (file)
@@ -130,7 +130,7 @@ public class Vala.Namespace : Symbol {
                                old_ns.add_comment (c);
                        }
                        foreach (Attribute a in ns.attributes) {
-                               if (old_ns.get_attribute (a.name) == null) {
+                               if (!old_ns.has_attribute (a.name)) {
                                        old_ns.attributes.append(a);
                                }
                        }
index 630f1225d1d64fd05aaf883b727d8175adc0789c..0e8189714d70dfb548b77246331f22f4e78a56cd 100644 (file)
@@ -44,7 +44,7 @@ public class Vala.NullType : ReferenceType {
                if (target_type is GenericType ||
                    target_type is PointerType ||
                    target_type.nullable ||
-                   target_type.type_symbol.get_attribute ("PointerType") != null) {
+                   target_type.type_symbol.has_attribute ("PointerType")) {
                        return true;
                }
 
index 619f2770b244121c3175c65fa3eb0b05ccc5a0a9..3e568d888aa75c80e8c80b0cd240ef3a1b4769a5 100644 (file)
@@ -312,7 +312,7 @@ public class Vala.ObjectCreationExpression : Expression, CallableExpression {
 
                        while (cl != null) {
                                // FIXME: use target values in the codegen
-                               if (cl.get_attribute_string ("CCode", "ref_sink_function") != null) {
+                               if (cl.has_attribute_argument ("CCode", "ref_sink_function")) {
                                        value_type.floating_reference = true;
                                        break;
                                }
index 7594d465723b9bb204a6f9d1e2767315723b2a62..794b81941ef0ba7ef2997213c5f09d11c5228435 100644 (file)
@@ -381,7 +381,7 @@ public abstract class Vala.ObjectTypeSymbol : TypeSymbol, GenericSymbol {
                        return !error;
                }
 
-               if (!external_package && get_attribute ("DBus") != null && !context.has_package ("gio-2.0")) {
+               if (!external_package && has_attribute ("DBus") && !context.has_package ("gio-2.0")) {
                        error = true;
                        Report.error (source_reference, "gio-2.0 package required for DBus support");
                }
index ef27b4cd2f1119eda234be2f818d55e8efe90a86..eaf08746d889f42aa2f35d60338e4f4e16195a92 100644 (file)
@@ -46,7 +46,7 @@ public class Vala.Parameter : Variable {
 
        public bool format_arg {
                get {
-                       return get_attribute ("FormatArg") != null;
+                       return has_attribute ("FormatArg");
                }
        }
 
index 9ac94e4a57b4cd0d7a8f547781c86f6f9a13855d..85f7fbcde9a4620d4778994c3baba26612eb7f39 100644 (file)
@@ -2632,7 +2632,7 @@ public class Vala.Parser : CodeVisitor {
        void set_attributes (CodeNode node, List<Attribute>? attributes) {
                if (attributes != null) {
                        foreach (Attribute attr in (List<Attribute>) attributes) {
-                               if (node.get_attribute (attr.name) != null) {
+                               if (node.has_attribute (attr.name)) {
                                        Report.error (attr.source_reference, "duplicate attribute `%s'", attr.name);
                                }
                                node.attributes.append (attr);
index 7371de68b0a25fbc329def9a6d05adcbf36eb2a2..b9176f93b9492ccb040d1b877a9f1fcba207cdb8 100644 (file)
@@ -69,7 +69,7 @@ public class Vala.PointerType : DataType {
                        return base_type.compatible (tt.base_type);
                }
 
-               if ((target_type.type_symbol != null && target_type.type_symbol.get_attribute ("PointerType") != null)) {
+               if ((target_type.type_symbol != null && target_type.type_symbol.has_attribute ("PointerType"))) {
                        return true;
                }
 
index 9963d19ffa4bf34fa78c0a93346f4ef72fd2e1ba..668768d05e057da6dc20a1a2a9da7a0730920fdb 100644 (file)
@@ -116,7 +116,7 @@ public class Vala.Property : Symbol, Lockable {
                                                Report.error (source_reference, "Property setter must have a body");
                                        }
                                        if (!get_has_body && !set_has_body) {
-                                               if (get_attribute ("GtkChild") != null && property_type.value_owned) {
+                                               if (has_attribute ("GtkChild") && property_type.value_owned) {
                                                        Report.warning (source_reference, "[GtkChild] properties must be declared as `unowned'");
                                                        property_type.value_owned = false;
                                                }
@@ -126,7 +126,7 @@ public class Vala.Property : Symbol, Lockable {
                                                _field.access = SymbolAccessibility.PRIVATE;
                                                _field.binding = binding;
                                                // apply gtk-child attribute to backing field for gtk-template support
-                                               if (get_attribute ("GtkChild") != null) {
+                                               if (has_attribute ("GtkChild")) {
                                                        _field.set_attribute_string ("GtkChild", "name", get_attribute_string ("GtkChild", "name", name));
                                                        _field.set_attribute_bool ("GtkChild", "internal", get_attribute_bool ("GtkChild", "internal"));
                                                }
@@ -506,7 +506,7 @@ public class Vala.Property : Symbol, Lockable {
                        get_accessor.check (context);
                }
                if (set_accessor != null) {
-                       if (get_attribute ("GtkChild") != null) {
+                       if (has_attribute ("GtkChild")) {
                                Report.warning (set_accessor.source_reference, "[GtkChild] property `%s' is not allowed to have `set' accessor", get_full_name ());
                        }
                        set_accessor.check (context);
index 72e5ce675ac93b1aa77ee47e338c78018b6a91fd..643086259499fea3a6d171496f38e6533033b8f2 100644 (file)
@@ -176,7 +176,7 @@ public class Vala.PropertyAccessor : Subroutine {
                if (context.profile == Profile.GOBJECT
                    && readable && ((TypeSymbol) prop.parent_symbol).is_subtype_of (context.analyzer.object_type)) {
                        //FIXME Code duplication with CCodeMemberAccessModule.visit_member_access()
-                       if (prop.get_attribute ("NoAccessorMethod") != null) {
+                       if (prop.has_attribute ("NoAccessorMethod")) {
                                if (value_type.is_real_struct_type ()) {
                                        if (source_reference == null || source_reference.file == null) {
                                                // Hopefully good as is
index a5076a2fef72c09f24617893a703a340b8d17947..b560f2a7ac206e58b861cd2500eff84b1bc7d6b5 100644 (file)
@@ -473,7 +473,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                        return false;
                }
 
-               if (type_sym is Interface && type_sym.get_attribute ("DBus") != null) {
+               if (type_sym is Interface && type_sym.has_attribute ("DBus")) {
                        // GObject properties not currently supported in D-Bus interfaces
                        return false;
                }
@@ -515,7 +515,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
                Expression prev_arg = null;
                Iterator<Expression> arg_it = args.iterator ();
 
-               bool diag = (mtype is MethodType && ((MethodType) mtype).method_symbol.get_attribute ("Diagnostics") != null);
+               bool diag = (mtype is MethodType && ((MethodType) mtype).method_symbol.has_attribute ("Diagnostics"));
 
                bool ellipsis = false;
                int i = 0;
index 9eb7c894c61eebeac3db2c798d7ccd867c2bd109..1da87cff06e8f19b640450d0234945fa87555e59 100644 (file)
@@ -249,7 +249,7 @@ public class Vala.Signal : Symbol, Callable {
                        default_handler.check (context);
                }
 
-               if (get_attribute ("HasEmitter") != null) {
+               if (has_attribute ("HasEmitter")) {
                        emitter = new Method (name, return_type, source_reference);
 
                        emitter.owner = owner;
index 198ff3462343f807d54fac7b055b597bc3381b61..52c85dac725a71e000b5f7a3e48e1215f46b87c6 100644 (file)
@@ -81,7 +81,7 @@ public class Vala.Struct : TypeSymbol, GenericSymbol {
        public bool is_immutable {
                get {
                        if (_is_immutable == null) {
-                               _is_immutable = get_attribute ("Immutable") != null;
+                               _is_immutable = has_attribute ("Immutable");
                        }
                        return _is_immutable;
                }
@@ -343,7 +343,7 @@ public class Vala.Struct : TypeSymbol, GenericSymbol {
                        return true;
                }
                if (boolean_type == null) {
-                       boolean_type = get_attribute ("BooleanType") != null;
+                       boolean_type = has_attribute ("BooleanType");
                }
                return boolean_type;
        }
@@ -359,7 +359,7 @@ public class Vala.Struct : TypeSymbol, GenericSymbol {
                        return true;
                }
                if (integer_type == null) {
-                       integer_type = get_attribute ("IntegerType") != null;
+                       integer_type = has_attribute ("IntegerType");
                }
                return integer_type;
        }
@@ -375,7 +375,7 @@ public class Vala.Struct : TypeSymbol, GenericSymbol {
                        return true;
                }
                if (floating_type == null) {
-                       floating_type = get_attribute ("FloatingType") != null;
+                       floating_type = has_attribute ("FloatingType");
                }
                return floating_type;
        }
@@ -414,7 +414,7 @@ public class Vala.Struct : TypeSymbol, GenericSymbol {
                        return true;
                }
                if (simple_type == null) {
-                       simple_type = get_attribute ("SimpleType") != null || get_attribute ("BooleanType") != null || get_attribute ("IntegerType") != null || get_attribute ("FloatingType") != null;
+                       simple_type = has_attribute ("SimpleType") || has_attribute ("BooleanType") || has_attribute ("IntegerType") || has_attribute ("FloatingType");
                }
                return simple_type;
        }
@@ -449,7 +449,7 @@ public class Vala.Struct : TypeSymbol, GenericSymbol {
        }
 
        public bool is_disposable () {
-               if (get_attribute_string ("CCode", "destroy_function") != null) {
+               if (has_attribute_argument ("CCode", "destroy_function")) {
                        return true;
                }
 
index d029aa9a77f79e8fd2228840c8d411120f37d82b..40c7c98e9b7ac53af56c2544e6aab54a20686914 100644 (file)
@@ -412,11 +412,11 @@ public class Vala.SymbolResolver : CodeVisitor {
                }
 
                // attributes are not processed yet, access them directly
-               if (base_struct.get_attribute ("BooleanType") != null) {
+               if (base_struct.has_attribute ("BooleanType")) {
                        return new BooleanType (st, source_reference);
-               } else if (base_struct.get_attribute ("IntegerType") != null) {
+               } else if (base_struct.has_attribute ("IntegerType")) {
                        return new IntegerType (st, null, null, source_reference);
-               } else if (base_struct.get_attribute ("FloatingType") != null) {
+               } else if (base_struct.has_attribute ("FloatingType")) {
                        return new FloatingType (st, source_reference);
                } else {
                        return new StructValueType (st, source_reference);
index b45d7da834abc3de560a56a53a31b2dc30165772..976c0582500f4600e3fd1fb272cc719f4ce39554 100644 (file)
@@ -229,7 +229,7 @@ public class Vala.UnaryExpression : Expression {
                                Report.error (source_reference, "ref and out method arguments can only be used with fields, parameters, local variables, and array element access");
                                return false;
                        }
-                       if (inner.symbol_reference != null && inner.symbol_reference.get_attribute ("GtkChild") != null) {
+                       if (inner.symbol_reference != null && inner.symbol_reference.has_attribute ("GtkChild")) {
                                error = true;
                                Report.error (source_reference, "Assignment of [GtkChild] `%s' is not allowed", inner.symbol_reference.get_full_name ());
                                return false;
index 9ef5e0e915fa05df97a4d128cd0863fe0c22a233..aca09768e3ba4066eff20ac438273a906950e2c9 100644 (file)
@@ -52,10 +52,10 @@ public class Vala.VersionAttribute {
                get {
                        if (_deprecated == null) {
                                _deprecated = symbol.get_attribute_bool ("Version", "deprecated", false)
-                                       || symbol.get_attribute_string ("Version", "deprecated_since") != null
-                                       || symbol.get_attribute_string ("Version", "replacement") != null
+                                       || symbol.has_attribute_argument ("Version", "deprecated_since")
+                                       || symbol.has_attribute_argument ("Version", "replacement")
                                        // [Deprecated] is deprecated
-                                       || symbol.get_attribute ("Deprecated") != null;
+                                       || symbol.has_attribute ("Deprecated");
                        }
                        return _deprecated;
                }
@@ -102,8 +102,8 @@ public class Vala.VersionAttribute {
                get {
                        if (_experimental == null) {
                                _experimental = symbol.get_attribute_bool ("Version", "experimental", false)
-                                       || symbol.get_attribute_string ("Version", "experimental_until") != null
-                                       || symbol.get_attribute ("Experimental") != null;
+                                       || symbol.has_attribute_argument ("Version", "experimental_until")
+                                       || symbol.has_attribute ("Experimental");
                        }
                        return _experimental;
                }
index 2715703256e38121fe62727dc994c93c5a05ca80..b1c728ee183c2d7d644921cedf232a765af38a6d 100644 (file)
@@ -1661,7 +1661,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                prop.set_attribute ("NoAccessorMethod", true);
                        }
 
-                       if (prop.get_attribute ("NoAccessorMethod") != null && prop.get_accessor != null) {
+                       if (prop.has_attribute ("NoAccessorMethod") && prop.get_accessor != null) {
                                prop.get_accessor.value_type.value_owned = true;
                        }
                }
@@ -1773,7 +1773,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                prop.set_attribute ("NoAccessorMethod", true);
                        }
 
-                       if (prop.get_attribute ("NoAccessorMethod") != null && prop.get_accessor != null) {
+                       if (prop.has_attribute ("NoAccessorMethod") && prop.get_accessor != null) {
                                prop.get_accessor.value_type.value_owned = true;
                        }
                }