From: Rico Tzschichholz Date: Mon, 12 Jun 2023 13:13:15 +0000 (+0200) Subject: vala: Add CodeNode.has_attribute() helper and use it accordingly X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e9b9d6e942a33edff3526ef2d9c859f315b707f5;p=thirdparty%2Fvala.git vala: Add CodeNode.has_attribute() helper and use it accordingly --- diff --git a/codegen/valaccode.vala b/codegen/valaccode.vala index 30d196b9e..9a0283e34 100644 --- a/codegen/valaccode.vala +++ b/codegen/valaccode.vala @@ -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) { diff --git a/codegen/valaccodeattribute.vala b/codegen/valaccodeattribute.vala index f47eb3b7c..08de1251f 100644 --- a/codegen/valaccodeattribute.vala +++ b/codegen/valaccodeattribute.vala @@ -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")) { diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index d1e665747..2f0ea22d8 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -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; } } diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala index 6365d3ad4..05b9a2916 100644 --- a/codegen/valaccodemethodmodule.vala +++ b/codegen/valaccodemethodmodule.vala @@ -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); diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala index 35779f881..e1373a331 100644 --- a/codegen/valaccodestructmodule.vala +++ b/codegen/valaccodestructmodule.vala @@ -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); } } diff --git a/codegen/valagtkmodule.vala b/codegen/valagtkmodule.vala index 69125ce57..2e9befc0c 100644 --- a/codegen/valagtkmodule.vala +++ b/codegen/valagtkmodule.vala @@ -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; } diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index c1f7a1df1..8d4966f05 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -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; diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala index 1d62a17c0..0c5be5bf5 100644 --- a/vala/valaassignment.vala +++ b/vala/valaassignment.vala @@ -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; diff --git a/vala/valaclass.vala b/vala/valaclass.vala index a87bb4240..cf2943e4d 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -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; diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala index 4ca44c8d9..3ff39dbc8 100644 --- a/vala/valacodenode.vala +++ b/vala/valacodenode.vala @@ -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. * diff --git a/vala/valacodewriter.vala b/vala/valacodewriter.vala index f9f1fccd1..d5fcc8035 100644 --- a/vala/valacodewriter.vala +++ b/vala/valacodewriter.vala @@ -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)); } diff --git a/vala/valaenum.vala b/vala/valaenum.vala index 2d403157d..b2b40285c 100644 --- a/vala/valaenum.vala +++ b/vala/valaenum.vala @@ -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; } diff --git a/vala/valafield.vala b/vala/valafield.vala index dbe8176e8..2f675a96f 100644 --- a/vala/valafield.vala +++ b/vala/valafield.vala @@ -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; } diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala index 45f524546..c66668225 100644 --- a/vala/valaflowanalyzer.vala +++ b/vala/valaflowanalyzer.vala @@ -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; } diff --git a/vala/valagenieparser.vala b/vala/valagenieparser.vala index cca9919eb..a1336ae4b 100644 --- a/vala/valagenieparser.vala +++ b/vala/valagenieparser.vala @@ -2413,7 +2413,7 @@ public class Vala.Genie.Parser : CodeVisitor { void set_attributes (CodeNode node, List? attributes) { if (attributes != null) { foreach (Attribute attr in (List) 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); diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index 1e1f51f05..fa4337019 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -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; diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala index 23078f25b..31b1ca959 100644 --- a/vala/valamemberaccess.vala +++ b/vala/valamemberaccess.vala @@ -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; diff --git a/vala/valamethod.vala b/vala/valamethod.vala index 0814565c8..6a1d686cf 100644 --- a/vala/valamethod.vala +++ b/vala/valamethod.vala @@ -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; } diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala index 7333891b4..3f0c0d118 100644 --- a/vala/valamethodcall.vala +++ b/vala/valamethodcall.vala @@ -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; diff --git a/vala/valanamespace.vala b/vala/valanamespace.vala index d62babb63..1e763f32e 100644 --- a/vala/valanamespace.vala +++ b/vala/valanamespace.vala @@ -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); } } diff --git a/vala/valanulltype.vala b/vala/valanulltype.vala index 630f1225d..0e8189714 100644 --- a/vala/valanulltype.vala +++ b/vala/valanulltype.vala @@ -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; } diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala index 619f2770b..3e568d888 100644 --- a/vala/valaobjectcreationexpression.vala +++ b/vala/valaobjectcreationexpression.vala @@ -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; } diff --git a/vala/valaobjecttypesymbol.vala b/vala/valaobjecttypesymbol.vala index 7594d4657..794b81941 100644 --- a/vala/valaobjecttypesymbol.vala +++ b/vala/valaobjecttypesymbol.vala @@ -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"); } diff --git a/vala/valaparameter.vala b/vala/valaparameter.vala index ef27b4cd2..eaf08746d 100644 --- a/vala/valaparameter.vala +++ b/vala/valaparameter.vala @@ -46,7 +46,7 @@ public class Vala.Parameter : Variable { public bool format_arg { get { - return get_attribute ("FormatArg") != null; + return has_attribute ("FormatArg"); } } diff --git a/vala/valaparser.vala b/vala/valaparser.vala index 9ac94e4a5..85f7fbcde 100644 --- a/vala/valaparser.vala +++ b/vala/valaparser.vala @@ -2632,7 +2632,7 @@ public class Vala.Parser : CodeVisitor { void set_attributes (CodeNode node, List? attributes) { if (attributes != null) { foreach (Attribute attr in (List) 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); diff --git a/vala/valapointertype.vala b/vala/valapointertype.vala index 7371de68b..b9176f93b 100644 --- a/vala/valapointertype.vala +++ b/vala/valapointertype.vala @@ -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; } diff --git a/vala/valaproperty.vala b/vala/valaproperty.vala index 9963d19ff..668768d05 100644 --- a/vala/valaproperty.vala +++ b/vala/valaproperty.vala @@ -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); diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala index 72e5ce675..643086259 100644 --- a/vala/valapropertyaccessor.vala +++ b/vala/valapropertyaccessor.vala @@ -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 diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index a5076a2fe..b560f2a7a 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -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 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; diff --git a/vala/valasignal.vala b/vala/valasignal.vala index 9eb7c894c..1da87cff0 100644 --- a/vala/valasignal.vala +++ b/vala/valasignal.vala @@ -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; diff --git a/vala/valastruct.vala b/vala/valastruct.vala index 198ff3462..52c85dac7 100644 --- a/vala/valastruct.vala +++ b/vala/valastruct.vala @@ -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; } diff --git a/vala/valasymbolresolver.vala b/vala/valasymbolresolver.vala index d029aa9a7..40c7c98e9 100644 --- a/vala/valasymbolresolver.vala +++ b/vala/valasymbolresolver.vala @@ -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); diff --git a/vala/valaunaryexpression.vala b/vala/valaunaryexpression.vala index b45d7da83..976c05825 100644 --- a/vala/valaunaryexpression.vala +++ b/vala/valaunaryexpression.vala @@ -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; diff --git a/vala/valaversionattribute.vala b/vala/valaversionattribute.vala index 9ef5e0e91..aca09768e 100644 --- a/vala/valaversionattribute.vala +++ b/vala/valaversionattribute.vala @@ -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; } diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala index 271570325..b1c728ee1 100644 --- a/vapigen/valagidlparser.vala +++ b/vapigen/valagidlparser.vala @@ -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; } }