KickJava   Java API By Example, From Geeks To Geeks.

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


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
30 /**
31  * @grammar case label: stmts
32  * @child Expr label
33  * @child Stmts stmts
34  */

35
36 public class SwitchClause extends ASTObject {
37
38     public void unparse(CodeWriter writer) {
39         if (label == null) {
40             writer.writeln("default: ");
41         } else {
42             writer.writeKeyword("case");
43             writer.requiredSpace();
44             writer.write(label);
45             writer.writeln(":");
46         }
47         if (stmts == null) return;
48
49         writer.indent();
50         writer.write(stmts);
51         writer.dedent();
52     }
53
54     //BEGIN: Generated from @child and @property
55
protected Expr label;
56     public Expr getLabel() { return label; }
57     public void setLabel(Expr _label) {
58         if (_label != null) _label.setParent(this);
59         label = _label;
60     }
61
62     protected Stmts stmts;
63     public Stmts getStmts() { return stmts; }
64     public void setStmts(Stmts _stmts) {
65         if (_stmts != null) _stmts.setParent(this);
66         stmts = _stmts;
67     }
68
69     public SwitchClause(SourceLocation location, Expr _label, Stmts _stmts) {
70         super(location);
71         setLabel(_label);
72         setStmts(_stmts);
73     }
74     protected SwitchClause(SourceLocation source) {
75         super(source);
76     }
77
78     public ASTObject copyWalk(CopyWalker walker) {
79         SwitchClause ret = new SwitchClause(getSourceLocation());
80         ret.preCopy(walker, this);
81         if (label != null) ret.setLabel( (Expr)walker.process(label) );
82         if (stmts != null) ret.setStmts( (Stmts)walker.process(stmts) );
83         return ret;
84     }
85
86     public ASTObject getChildAt(int childIndex) {
87         switch(childIndex) {
88         case 0: return label;
89         case 1: return stmts;
90         default: return super.getChildAt(childIndex);
91         }
92     }
93      public String JavaDoc getChildNameAt(int childIndex) {
94         switch(childIndex) {
95         case 0: return "label";
96         case 1: return "stmts";
97         default: return super.getChildNameAt(childIndex);
98         }
99     }
100      public void setChildAt(int childIndex, ASTObject child) {
101         switch(childIndex) {
102         case 0: setLabel((Expr)child); return;
103         case 1: setStmts((Stmts)child); return;
104         default: super.setChildAt(childIndex, child); return;
105         }
106     }
107      public int getChildCount() {
108         return 2;
109     }
110
111     public String JavaDoc getDefaultDisplayName() {
112         return "SwitchClause()";
113     }
114
115     //END: Generated from @child and @property
116
}
117
118
119
Popular Tags