Release 0.41.92
[vala-gnome.git] / vala / valaerrortype.vala
blob7a7946643e8986a95f976b03f6c1741456136d7f
1 /* valaerrortype.vala
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
21 * Raffaele Sandrini <raffaele@sandrini.ch>
24 using GLib;
26 /**
27 * A class type.
29 public class Vala.ErrorType : ReferenceType {
30 /**
31 * The error domain or null for generic error.
33 public weak ErrorDomain? error_domain { get; set; }
35 /**
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 is GenericType) {
52 return true;
55 var et = target_type as ErrorType;
57 /* error types are only compatible to error types */
58 if (et == null) {
59 return false;
62 /* every error type is compatible to the base error type */
63 if (et.error_domain == null) {
64 return true;
67 /* otherwhise the error_domain has to be equal */
68 if (et.error_domain != error_domain) {
69 return false;
72 if (et.error_code == null) {
73 return true;
76 return et.error_code == error_code;
79 public override string to_qualified_string (Scope? scope) {
80 string result;
82 if (error_domain == null) {
83 result = "GLib.Error";
84 } else {
85 result = error_domain.get_full_name ();
88 if (nullable) {
89 result += "?";
92 return result;
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;
101 return result;
104 public override bool equals (DataType type2) {
105 var et = type2 as ErrorType;
107 if (et == null) {
108 return false;
111 return error_domain == et.error_domain;
114 public override Symbol? get_member (string member_name) {
115 var root_symbol = source_reference.file.context.root;
116 var gerror_symbol = root_symbol.scope.lookup ("GLib").scope.lookup ("Error");
117 return gerror_symbol.scope.lookup (member_name);
120 public override bool is_reference_type_or_type_parameter () {
121 return true;
124 public override bool check (CodeContext context) {
125 if (error_domain != null) {
126 return error_domain.check (context);
128 return true;