View Javadoc
Minimize
Table

1   /*
2    * Copyright 2003-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.codehaus.groovy.ast.expr;
17  
18  import org.codehaus.groovy.ast.ClassNode;
19  import org.codehaus.groovy.ast.GroovyCodeVisitor;
20  
21  /**
22   * A constructor call
23   *
24   * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
25   * @author Jochen Theodorou
26   * @version $Revision: 19881 $
27   */
28  public class ConstructorCallExpression extends Expression {
29  
30      private final Expression arguments;
31      private boolean usesAnonymousInnerClass;
32  
33      public ConstructorCallExpression(ClassNode type, Expression arguments) {
34          super.setType(type);
35          if (!(arguments instanceof TupleExpression)) {
36              this.arguments = new TupleExpression(arguments);
37          } else {
38              this.arguments = arguments;
39          }
40      }
41  
42      public void visit(GroovyCodeVisitor visitor) {
43          visitor.visitConstructorCallExpression(this);
44      }
45  
46      public Expression transformExpression(ExpressionTransformer transformer) {
47          Expression args = transformer.transform(arguments);
48          ConstructorCallExpression ret = new ConstructorCallExpression(getType(), args);
49          ret.setSourcePosition(this);
50          ret.setUsingAnonymousInnerClass(isUsingAnonymousInnerClass());
51          return ret;
52      }
53  
54      public Expression getArguments() {
55          return arguments;
56      }
57  
58      public String getText() {
59          String text = null;
60          if (isSuperCall()) {
61              text = "super ";
62          } else if (isThisCall()) {
63              text = "this ";
64          } else {
65              text = "new " + getType().getName();
66          }
67          return text + arguments.getText();
68      }
69  
70      public String toString() {
71          return super.toString() + "[type: " + getType() + " arguments: " + arguments + "]";
72      }
73  
74      public boolean isSuperCall() {
75          return getType() == ClassNode.SUPER;
76      }
77  
78      public boolean isSpecialCall() {
79          return isThisCall() || isSuperCall();
80      }
81  
82      public boolean isThisCall() {
83          return getType() == ClassNode.THIS;
84      }
85  
86      public void setUsingAnonymousInnerClass(boolean usage) {
87          this.usesAnonymousInnerClass = usage;
88      }
89  
90      public boolean isUsingAnonymousInnerClass() {
91          return usesAnonymousInnerClass;
92      }
93  }