KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > base > ast > ConstructorBody


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.compiler.base.ast;
26
27 import org.aspectj.compiler.base.JavaCompiler;
28 import org.aspectj.compiler.base.CodeWriter;
29 import org.aspectj.compiler.base.LocalClassPass;
30 import org.aspectj.compiler.base.cst.*;
31
32 import org.aspectj.compiler.base.bcg.CodeBuilder;
33 import org.aspectj.compiler.base.bcg.Label;
34 import org.aspectj.compiler.base.bcg.MethodBuilder;
35 import org.aspectj.compiler.base.bcg.ClassfileBuilder;
36
37 /**
38   * @grammar { constructorCall; stmts* }
39   * @child ConstructorCallExpr constructorCall
40   */

41
42 public class ConstructorBody extends CodeBody {
43
44     protected void setupDefaultConstructorCall() {
45         if (constructorCall == null) {
46             Type superType = getDeclaringType().getTypeDec().getSuperClassType();
47             Exprs args = getAST().makeExprs();
48             Constructor superConstructor = superType.getConstructor(this, args, true);
49             ConstructorCallExpr newCallExpr =
50                 getAST().makeSuperConstructorCall(superConstructor);
51             setConstructorCall(newCallExpr);
52         }
53     }
54
55     //INTRO from ScopePass
56
public void preScope(ScopeWalker walker) {
57         if (stmts != null && walker.walkBodies()) setupDefaultConstructorCall();
58         super.preScope(walker);
59     }
60
61     // for auto-added constructors
62
public ConstructorBody(SourceLocation location, Stmts _stmts, ConstructorCallExpr _constructorCall, boolean _parsed) {
63         super(location,_stmts,_parsed);
64         setConstructorCall(_constructorCall);
65     }
66
67     public void unparse(CodeWriter writer) {
68         writer.openBlock();
69         writer.write(constructorCall);
70         writer.newLine();
71         if (tmpStmts != null) writer.write(tmpStmts);
72         writer.write(stmts);
73         writer.closeBlock();
74     }
75
76     public void cleanup() {
77         constructorCall = null;
78         super.cleanup();
79     }
80
81     // ------------------------------
82
// INTRO: LocalClassPass.ThreadingWalker
83

84     public void preThreading(LocalClassPass.ThreadingWalker walker) {
85         if (getConstructorCall().getIsSuper()) {
86             walker.addFieldSets(getStmts());
87         }
88     }
89
90     // ------------------------------
91
// bcg
92
protected void cgStmt(CodeBuilder cb) {
93         getConstructorCall().cgEffect(cb);
94         super.cgStmt(cb);
95     }
96
97     // ------------------------------
98
// convenience constructors
99

100     public ConstructorBody(SourceLocation location, Stmts _stmts,
101                            boolean _parsed, ConstructorCallExpr _constructorCall) {
102         this(location, null, _stmts, _parsed, _constructorCall);
103     }
104
105     //BEGIN: Generated from @child and @property
106
protected ConstructorCallExpr constructorCall;
107     public ConstructorCallExpr getConstructorCall() { return constructorCall; }
108     public void setConstructorCall(ConstructorCallExpr _constructorCall) {
109         if (_constructorCall != null) _constructorCall.setParent(this);
110         constructorCall = _constructorCall;
111     }
112
113     public ConstructorBody(SourceLocation location, Stmts _tmpStmts, Stmts _stmts, boolean _parsed, ConstructorCallExpr _constructorCall) {
114         super(location, _tmpStmts, _stmts, _parsed);
115         setConstructorCall(_constructorCall);
116     }
117     protected ConstructorBody(SourceLocation source) {
118         super(source);
119     }
120
121     public ASTObject copyWalk(CopyWalker walker) {
122         ConstructorBody ret = new ConstructorBody(getSourceLocation());
123         ret.preCopy(walker, this);
124         if (tmpStmts != null) ret.setTmpStmts( (Stmts)walker.process(tmpStmts) );
125         if (stmts != null) ret.setStmts( (Stmts)walker.process(stmts) );
126         ret.parsed = parsed;
127         if (constructorCall != null) ret.setConstructorCall( (ConstructorCallExpr)walker.process(constructorCall) );
128         return ret;
129     }
130
131     public ASTObject getChildAt(int childIndex) {
132         switch(childIndex) {
133         case 2: return constructorCall;
134         default: return super.getChildAt(childIndex);
135         }
136     }
137      public String JavaDoc getChildNameAt(int childIndex) {
138         switch(childIndex) {
139         case 2: return "constructorCall";
140         default: return super.getChildNameAt(childIndex);
141         }
142     }
143      public void setChildAt(int childIndex, ASTObject child) {
144         switch(childIndex) {
145         case 2: setConstructorCall((ConstructorCallExpr)child); return;
146         default: super.setChildAt(childIndex, child); return;
147         }
148     }
149      public int getChildCount() {
150         return 3;
151     }
152
153     public String JavaDoc getDefaultDisplayName() {
154         return "ConstructorBody(parsed: "+parsed+")";
155     }
156
157     //END: Generated from @child and @property
158
}
159
Popular Tags