KickJava   Java API By Example, From Geeks To Geeks.

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


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.*;
28
29 import org.aspectj.compiler.base.JavaCompiler;
30 import org.aspectj.compiler.base.CodeWriter;
31 import org.aspectj.compiler.base.cst.*;
32
33 /**
34   * @grammar catch (formal) body
35   * @child FormalDec formal
36   * @child Stmt body
37   */

38 public class CatchClause extends ASTObject {
39
40     //INTRO from ScopePass
41
public void preScope(ScopeWalker walker) { walker.pushBlock(); }
42     public ASTObject postScope(ScopeWalker walker) { walker.popBlock(); return this; }
43
44     public void checkSpec() {
45         Type exnType = formal.getType();
46         Type throwableType = getTypeManager().getThrowableType();
47         if (! exnType.isSubtypeOf(throwableType)) {
48             formal.getTypeD().showTypeError(exnType, throwableType);
49         }
50         
51         body.requireBlockStmt();
52     }
53
54     public void unparse(CodeWriter writer) {
55         writer.writeKeyword("catch");
56         writer.optionalSpace();
57         writer.write('(');
58         writer.write(formal);
59         writer.write(')');
60         writer.optionalSpace();
61         writer.write(body);
62     }
63
64     // ------------------------------
65
// Intro: FrameLocPass
66

67     public void walkFrameLoc(FrameLocPass walker) {
68         int start = walker.getfs();
69         super.walkFrameLoc(walker);
70         walker.setfs(start);
71     }
72
73     //BEGIN: Generated from @child and @property
74
protected FormalDec formal;
75     public FormalDec getFormal() { return formal; }
76     public void setFormal(FormalDec _formal) {
77         if (_formal != null) _formal.setParent(this);
78         formal = _formal;
79     }
80
81     protected Stmt body;
82     public Stmt getBody() { return body; }
83     public void setBody(Stmt _body) {
84         if (_body != null) _body.setParent(this);
85         body = _body;
86     }
87
88     public CatchClause(SourceLocation location, FormalDec _formal, Stmt _body) {
89         super(location);
90         setFormal(_formal);
91         setBody(_body);
92     }
93     protected CatchClause(SourceLocation source) {
94         super(source);
95     }
96
97     public ASTObject copyWalk(CopyWalker walker) {
98         CatchClause ret = new CatchClause(getSourceLocation());
99         ret.preCopy(walker, this);
100         if (formal != null) ret.setFormal( (FormalDec)walker.process(formal) );
101         if (body != null) ret.setBody( (Stmt)walker.process(body) );
102         return ret;
103     }
104
105     public ASTObject getChildAt(int childIndex) {
106         switch(childIndex) {
107         case 0: return formal;
108         case 1: return body;
109         default: return super.getChildAt(childIndex);
110         }
111     }
112      public String JavaDoc getChildNameAt(int childIndex) {
113         switch(childIndex) {
114         case 0: return "formal";
115         case 1: return "body";
116         default: return super.getChildNameAt(childIndex);
117         }
118     }
119      public void setChildAt(int childIndex, ASTObject child) {
120         switch(childIndex) {
121         case 0: setFormal((FormalDec)child); return;
122         case 1: setBody((Stmt)child); return;
123         default: super.setChildAt(childIndex, child); return;
124         }
125     }
126      public int getChildCount() {
127         return 2;
128     }
129
130     public String JavaDoc getDefaultDisplayName() {
131         return "CatchClause()";
132     }
133
134     //END: Generated from @child and @property
135
}
136
137
138
Popular Tags