1 /* valaobjectcreationexpression.vala
3 * Copyright (C) 2006-2007 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 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>
26 * Represents an object creation expression in the source code.
28 public class Vala
.ObjectCreationExpression
: Expression
{
30 * The object type to create.
32 public TypeReference type_reference
{ get; set; }
35 * The construction method to use. May be null to indicate that
36 * the default construction method should be used.
38 public Method constructor
{ get; set; }
41 * The construction method to use or the data type to be created
42 * with the default construction method.
44 public MemberAccess member_name
{ get; set; }
46 private List
<Expression
> argument_list
;
49 * Creates a new object creation expression.
51 * @param type object type to create
52 * @param source reference to source code
53 * @return newly created object creation expression
55 public ObjectCreationExpression (MemberAccess
! name
, SourceReference source
) {
57 source_reference
= source
;
61 * Appends the specified expression to the list of arguments.
63 * @param arg an argument
65 public void add_argument (Expression
! arg
) {
66 argument_list
.append (arg
);
67 arg
.parent_node
= this
;
71 * Returns a copy of the argument list.
73 * @return argument list
75 public List
<weak Expression
> get_argument_list () {
76 return argument_list
.copy ();
79 public override void accept (CodeVisitor
! visitor
) {
80 if (type_reference
!= null) {
81 type_reference
.accept (visitor
);
84 if (member_name
!= null) {
85 member_name
.accept (visitor
);
88 visitor
.visit_begin_object_creation_expression (this
);
90 // iterate over list copy as list may change in loop body
91 foreach (Expression arg
in argument_list
.copy ()) {
95 visitor
.visit_end_object_creation_expression (this
);
98 public override void replace (CodeNode
! old_node
, CodeNode
! new_node
) {
99 weak List
<Expression
> l
= argument_list
.find (old_node
);
101 if (new_node
.parent_node
!= null) {
105 argument_list
.insert_before (l
, new_node
);
106 argument_list
.remove_link (l
);
107 new_node
.parent_node
= this
;