vala: Report error for error-domains without any code
[vala-gnome.git] / vala / valacallabletype.vala
blob0642fa644f30c92b5813d8065c480dc1833eaf03
1 /* valacallabletype.vala
3 * Copyright (C) 2017 Rico Tzschichholz
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 * Rico Tzschichholz <ricotz@ubuntu.com>
23 using GLib;
25 /**
26 * A callable type, i.e. a delegate, method, or signal type.
28 public abstract class Vala.CallableType : DataType {
29 public override string to_prototype_string (string? override_name = null) {
30 StringBuilder builder = new StringBuilder ();
32 // Append return-type
33 var return_type = get_return_type ();
34 if (return_type.is_weak ()) {
35 builder.append ("unowned ");
37 builder.append (return_type.to_qualified_string ());
39 // Append name
40 builder.append_c (' ');
41 builder.append (override_name ?? this.to_string ());
42 builder.append_c (' ');
44 // Append parameter-list
45 builder.append_c ('(');
46 int i = 1;
47 // add sender parameter for internal signal-delegates
48 var delegate_type = this as DelegateType;
49 if (delegate_type != null) {
50 var delegate_symbol = delegate_type.delegate_symbol;
51 if (delegate_symbol.parent_symbol is Signal && delegate_symbol.sender_type != null) {
52 builder.append (delegate_symbol.sender_type.to_qualified_string ());
53 i++;
56 foreach (Parameter param in get_parameters ()) {
57 if (i > 1) {
58 builder.append (", ");
61 if (param.ellipsis) {
62 builder.append ("...");
63 continue;
66 if (param.direction == ParameterDirection.IN) {
67 if (param.variable_type.value_owned) {
68 builder.append ("owned ");
70 } else {
71 if (param.direction == ParameterDirection.REF) {
72 builder.append ("ref ");
73 } else if (param.direction == ParameterDirection.OUT) {
74 builder.append ("out ");
76 if (!param.variable_type.value_owned && param.variable_type is ReferenceType) {
77 builder.append ("weak ");
81 builder.append (param.variable_type.to_qualified_string ());
83 if (param.initializer != null) {
84 builder.append (" = ");
85 builder.append (param.initializer.to_string ());
88 i++;
90 builder.append_c (')');
92 // Append error-types
93 var error_types = get_error_types ();
94 if (error_types.size > 0) {
95 builder.append (" throws ");
97 bool first = true;
98 foreach (DataType type in error_types) {
99 if (!first) {
100 builder.append (", ");
101 } else {
102 first = false;
105 builder.append (type.to_string ());
109 return builder.str;