View Javadoc
Minimize
Table

1   /*
2    * Copyright 2003-2007 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;
17  
18  import org.codehaus.groovy.ast.expr.ConstructorCallExpression;
19  import org.codehaus.groovy.ast.expr.Expression;
20  import org.codehaus.groovy.ast.stmt.ExpressionStatement;
21  import org.codehaus.groovy.ast.stmt.Statement;
22  
23  
24  /**
25   * Represents a constructor declaration
26   * 
27   * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
28   * @version $Revision: 15098 $
29   */
30  public class ConstructorNode extends MethodNode {
31      
32      public ConstructorNode(int modifiers, Statement code) {
33          this(modifiers, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, code);
34      }
35      
36      public ConstructorNode(int modifiers, Parameter[] parameters, ClassNode[] exceptions, Statement code) {
37          super("<init>",modifiers,ClassHelper.VOID_TYPE,parameters,exceptions,code);
38          
39          // This variable scope is thrown out and replaced with a different one during semantic analysis.
40          VariableScope scope = new VariableScope();
41          for (int i = 0; i < parameters.length; i++) {
42              scope.putDeclaredVariable(parameters[i]);
43          }
44          this.setVariableScope(scope);
45      }
46      
47      public boolean firstStatementIsSpecialConstructorCall() {
48          Statement code = getFirstStatement();
49          if (code == null || !(code instanceof ExpressionStatement)) return false;
50  
51          Expression expression = ((ExpressionStatement) code).getExpression();
52          if (!(expression instanceof ConstructorCallExpression)) return false;
53          ConstructorCallExpression cce = (ConstructorCallExpression) expression;
54          return cce.isSpecialCall();
55      }
56  
57  }