From: Rico Tzschichholz Date: Thu, 8 Nov 2018 11:45:24 +0000 (+0100) Subject: vala: Add CodeNode.copy_attribute_*() helper methods X-Git-Tag: 0.43.1~123 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=295e31b22195c5fad4ae07ae0818e5ed287813fc;p=thirdparty%2Fvala.git vala: Add CodeNode.copy_attribute_*() helper methods Provides an easy way to copy a specific attribute argument from another code node if the source has it set. --- diff --git a/vala/valacodenode.vala b/vala/valacodenode.vala index 216b5604f..a4002bf9a 100644 --- a/vala/valacodenode.vala +++ b/vala/valacodenode.vala @@ -295,6 +295,70 @@ public abstract class Vala.CodeNode { a.add_argument (argument, value.to_string ()); } + /** + * Copy the string value of the specified attribute argument if available. + * + * @param source codenode to copy from + * @param attribute attribute name + * @param argument argument name + * @return true if successful + */ + public bool copy_attribute_string (CodeNode source, string attribute, string argument) { + if (source.has_attribute_argument (attribute, argument)) { + set_attribute_string (attribute, argument, source.get_attribute_string (attribute, argument)); + return true; + } + return false; + } + + /** + * Copy the integer value of the specified attribute argument if available. + * + * @param source codenode to copy from + * @param attribute attribute name + * @param argument argument name + * @return true if successful + */ + public bool copy_attribute_integer (CodeNode source, string attribute, string argument) { + if (source.has_attribute_argument (attribute, argument)) { + set_attribute_integer (attribute, argument, source.get_attribute_integer (attribute, argument)); + return true; + } + return false; + } + + /** + * Copy the double value of the specified attribute argument if available. + * + * @param source codenode to copy from + * @param attribute attribute name + * @param argument argument name + * @return true if successful + */ + public bool copy_attribute_double (CodeNode source, string attribute, string argument) { + if (source.has_attribute_argument (attribute, argument)) { + set_attribute_double (attribute, argument, source.get_attribute_double (attribute, argument)); + return true; + } + return false; + } + + /** + * Copy the boolean value of the specified attribute argument if available. + * + * @param source codenode to copy from + * @param attribute attribute name + * @param argument argument name + * @return true if successful + */ + public bool copy_attribute_bool (CodeNode source, string attribute, string argument) { + if (source.has_attribute_argument (attribute, argument)) { + set_attribute_bool (attribute, argument, source.get_attribute_bool (attribute, argument)); + return true; + } + return false; + } + /** * Returns the attribute cache at the specified index. *