libgda-4.0, gedit-2.20: Fix gedit typo and GdaXaTransactionId.data
[vala-lang.git] / vala / valaunresolvedtype.vala
blob527fa0a7d08104703d4b516a16b2ccaa66fe260c
1 /* valaunresolvedtype.vala
3 * Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini
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 * An unresolved reference to a data type.
29 public class Vala.UnresolvedType : DataType {
30 /**
31 * The unresolved reference to a type symbol.
33 public UnresolvedSymbol unresolved_symbol { get; set; }
35 public UnresolvedType () {
38 /**
39 * Creates a new type reference.
41 * @param symbol unresolved type symbol
42 * @param source reference to source code
43 * @return newly created type reference
45 public UnresolvedType.from_symbol (UnresolvedSymbol symbol, SourceReference? source = null) {
46 this.unresolved_symbol = symbol;
47 source_reference = source;
50 /**
51 * Creates a new type reference from a code expression.
53 * @param expr member access expression
54 * @return newly created type reference
56 public static UnresolvedType? new_from_expression (Expression expr) {
57 var sym = UnresolvedSymbol.new_from_expression (expr);
59 if (sym != null) {
60 var type_ref = new UnresolvedType.from_symbol (sym, expr.source_reference);
61 type_ref.value_owned = true;
63 var ma = (MemberAccess) expr;
64 foreach (DataType arg in ma.get_type_arguments ()) {
65 type_ref.add_type_argument (arg);
68 return type_ref;
71 return null;
74 public override DataType copy () {
75 var result = new UnresolvedType ();
76 result.source_reference = source_reference;
77 result.value_owned = value_owned;
78 result.nullable = nullable;
79 result.is_dynamic = is_dynamic;
80 result.unresolved_symbol = unresolved_symbol.copy ();
82 foreach (DataType arg in get_type_arguments ()) {
83 result.add_type_argument (arg.copy ());
86 return result;
89 public override string to_qualified_string (Scope? scope) {
90 var s = unresolved_symbol.to_string ();
92 var type_args = get_type_arguments ();
93 if (type_args.size > 0) {
94 s += "<";
95 bool first = true;
96 foreach (DataType type_arg in type_args) {
97 if (!first) {
98 s += ",";
99 } else {
100 first = false;
102 if (!type_arg.value_owned) {
103 s += "weak ";
105 s += type_arg.to_qualified_string (scope);
107 s += ">";
109 if (nullable) {
110 s += "?";
113 return s;
116 public override bool is_disposable () {
117 return value_owned;