1 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 38 public class CatchClause extends ASTObject { 39 40 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 67 public void walkFrameLoc(FrameLocPass walker) { 68 int start = walker.getfs(); 69 super.walkFrameLoc(walker); 70 walker.setfs(start); 71 } 72 73 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 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 getDefaultDisplayName() { 131 return "CatchClause()"; 132 } 133 134 } 136 137 138 | Popular Tags |