3 * Copyright (C) 2008-2010 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
20 * Jürg Billeter <j@bitron.ch>
21 * Raffaele Sandrini <raffaele@sandrini.ch>
29 public class Vala
.ErrorType
: ReferenceType
{
31 * The error domain or null for generic error.
33 public weak ErrorDomain? error_domain
{ get; set; }
36 * The error code or null for generic error.
38 public weak ErrorCode? error_code
{ get; set; }
40 public bool dynamic_error
{ get; set; }
42 public ErrorType (ErrorDomain? error_domain
, ErrorCode? error_code
, SourceReference? source_reference
= null) {
43 this
.error_domain
= error_domain
;
44 this
.data_type
= error_domain
;
45 this
.error_code
= error_code
;
46 this
.source_reference
= source_reference
;
49 public override bool compatible (DataType target_type
) {
50 /* temporarily ignore type parameters */
51 if (target_type
.type_parameter
!= null) {
55 var et
= target_type as ErrorType
;
57 /* error types are only compatible to error types */
62 /* every error type is compatible to the base error type */
63 if (et
.error_domain
== null) {
67 /* otherwhise the error_domain has to be equal */
68 if (et
.error_domain
!= error_domain
) {
72 if (et
.error_code
== null) {
76 return et
.error_code
== error_code
;
79 public override string to_qualified_string (Scope? scope
) {
82 if (error_domain
== null) {
83 result
= "GLib.Error";
85 result
= error_domain
.get_full_name ();
95 public override DataType
copy () {
96 var result
= new
ErrorType (error_domain
, error_code
, source_reference
);
97 result
.value_owned
= value_owned
;
98 result
.nullable
= nullable
;
99 result
.dynamic_error
= dynamic_error
;
104 public override string?
get_cname () {
108 public override string?
get_lower_case_cname (string? infix
= null) {
109 if (error_domain
== null) {
113 return "g_%s_error".printf (infix
);
115 } else if (error_code
== null) {
116 return error_domain
.get_lower_case_cname (infix
);
118 return error_code
.get_lower_case_cname (infix
);
122 public override bool equals (DataType type2
) {
123 var et
= type2 as ErrorType
;
129 return error_domain
== et
.error_domain
;
132 public override Symbol?
get_member (string member_name
) {
133 var root_symbol
= source_reference
.file
.context
.root
;
134 var gerror_symbol
= root_symbol
.scope
.lookup ("GLib").scope
.lookup ("Error");
135 return gerror_symbol
.scope
.lookup (member_name
);
138 public override string?
get_type_id () {
139 if (source_reference
!= null && source_reference
.file
.context
.require_glib_version (2, 26)) {
140 return "G_TYPE_ERROR";
142 return "G_TYPE_POINTER";
146 public override bool is_reference_type_or_type_parameter () {
150 public override bool check (CodeContext context
) {
151 if (error_domain
!= null) {
152 return error_domain
.check (context
);