1 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 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 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 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 getDefaultDisplayName() { 112 return "SwitchClause()"; 113 } 114 115 } 117 118 119 | Popular Tags |