glib-2.0: Fix g_variant_new_tuple binding
[vala-lang.git] / vala / valamethodtype.vala
blob87ec555b92effb55c4e319ca374c13ce222825ed
1 /* valamethodtype.vala
3 * Copyright (C) 2007-2008 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * The type of a method referencea.
28 public class Vala.MethodType : DataType {
29 public Method method_symbol { get; set; }
31 public MethodType (Method method_symbol) {
32 this.method_symbol = method_symbol;
35 public override bool is_invokable () {
36 return true;
39 public override DataType? get_return_type () {
40 return method_symbol.return_type;
43 public override List<FormalParameter>? get_parameters () {
44 return method_symbol.get_parameters ();
47 public override DataType copy () {
48 return new MethodType (method_symbol);
51 public override bool compatible (DataType target_type) {
52 var dt = target_type as DelegateType;
53 if (dt == null) {
54 // method types incompatible to anything but delegates
55 return false;
58 return dt.delegate_symbol.matches_method (method_symbol, dt);
61 public override string to_qualified_string (Scope? scope) {
62 return method_symbol.get_full_name ();
65 public override string? get_cname () {
66 return "gpointer";
69 public override Symbol? get_member (string member_name) {
70 if (method_symbol.coroutine && member_name == "begin") {
71 return method_symbol;
72 } else if (method_symbol.coroutine && member_name == "end") {
73 return method_symbol;
74 } else if (method_symbol.coroutine && member_name == "callback") {
75 return method_symbol.get_callback_method ();
77 return null;
80 public string to_prototype_string (bool with_type_parameters = false) {
81 var proto = "%s %s (".printf (get_return_type ().to_string (), this.to_string ());
83 int i = 1;
84 foreach (FormalParameter param in get_parameters ()) {
85 if (i > 1) {
86 proto += ", ";
89 if (param.ellipsis) {
90 proto += "...";
91 continue;
94 if (param.direction == ParameterDirection.IN) {
95 if (param.variable_type.value_owned) {
96 proto += "owned ";
98 } else {
99 if (param.direction == ParameterDirection.REF) {
100 proto += "ref ";
101 } else if (param.direction == ParameterDirection.OUT) {
102 proto += "out ";
104 if (param.variable_type.is_weak ()) {
105 proto += "unowned ";
109 proto = "%s%s %s".printf (proto, param.variable_type.to_qualified_string (), param.name);
111 if (param.initializer != null) {
112 proto = "%s = %s".printf (proto, param.initializer.to_string ());
115 i++;
118 return proto + ")";