gio-unix-2.0: Add DesktopAppInfo.launch_uris_as_manager_with_fds()
[vala-gnome.git] / vala / valaobjecttype.vala
blob4683f2081586025f6d7e00f0eb8594fc0e5dd8c6
1 /* valaobjecttype.vala
3 * Copyright (C) 2007-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>
23 using GLib;
25 /**
26 * A class type.
28 public class Vala.ObjectType : ReferenceType {
29 /**
30 * The referred class or interface.
32 public weak ObjectTypeSymbol type_symbol { get; set; }
34 public ObjectType (ObjectTypeSymbol type_symbol) {
35 this.type_symbol = type_symbol;
36 data_type = type_symbol;
39 public override DataType copy () {
40 var result = new ObjectType (type_symbol);
41 result.source_reference = source_reference;
42 result.value_owned = value_owned;
43 result.nullable = nullable;
44 result.is_dynamic = is_dynamic;
45 result.floating_reference = floating_reference;
47 foreach (DataType arg in get_type_arguments ()) {
48 result.add_type_argument (arg.copy ());
51 return result;
54 public override bool stricter (DataType target_type) {
55 var obj_target_type = target_type as ObjectType;
56 if (obj_target_type == null) {
57 return false;
60 if (value_owned != target_type.value_owned) {
61 return false;
64 if (nullable && !target_type.nullable) {
65 return false;
68 return type_symbol.is_subtype_of (obj_target_type.type_symbol);
71 public override bool is_invokable () {
72 var cl = type_symbol as Class;
73 if (cl != null && cl.default_construction_method != null) {
74 return true;
75 } else {
76 return false;
80 public override DataType? get_return_type () {
81 var cl = type_symbol as Class;
82 if (cl != null && cl.default_construction_method != null) {
83 return cl.default_construction_method.return_type;
84 } else {
85 return null;
89 public override List<Parameter>? get_parameters () {
90 var cl = type_symbol as Class;
91 if (cl != null && cl.default_construction_method != null) {
92 return cl.default_construction_method.get_parameters ();
93 } else {
94 return null;
98 public override bool check (CodeContext context) {
99 if (!type_symbol.check (context)) {
100 return false;
103 int n_type_args = get_type_arguments ().size;
104 if (n_type_args > 0 && n_type_args < type_symbol.get_type_parameters ().size) {
105 Report.error (source_reference, "too few type arguments");
106 return false;
107 } else if (n_type_args > 0 && n_type_args > type_symbol.get_type_parameters ().size) {
108 Report.error (source_reference, "too many type arguments");
109 return false;
112 foreach (DataType type in get_type_arguments ()) {
113 if (!type.check (context)) {
114 return false;
118 return true;