| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
package org.mozilla.javascript.ast; |
| 8 |
|
| 9 |
import org.mozilla.javascript.Token; |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
public class CatchClause extends AstNode { |
| 19 |
|
| 20 |
private Name varName; |
| 21 |
private AstNode catchCondition; |
| 22 |
private Block body; |
| 23 |
private int ifPosition = -1; |
| 24 |
private int lp = -1; |
| 25 |
private int rp = -1; |
| 26 |
|
| 27 |
{ |
| 28 |
type = Token.CATCH; |
| 29 |
} |
| 30 |
|
| 31 |
public CatchClause() { |
| 32 |
} |
| 33 |
|
| 34 |
public CatchClause(int pos) { |
| 35 |
super(pos); |
| 36 |
} |
| 37 |
|
| 38 |
public CatchClause(int pos, int len) { |
| 39 |
super(pos, len); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public Name getVarName() { |
| 47 |
return varName; |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public void setVarName(Name varName) { |
| 56 |
assertNotNull(varName); |
| 57 |
this.varName = varName; |
| 58 |
varName.setParent(this); |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public AstNode getCatchCondition() { |
| 66 |
return catchCondition; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
public void setCatchCondition(AstNode catchCondition) { |
| 74 |
this.catchCondition = catchCondition; |
| 75 |
if (catchCondition != null) |
| 76 |
catchCondition.setParent(this); |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
public Block getBody() { |
| 83 |
return body; |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public void setBody(Block body) { |
| 91 |
assertNotNull(body); |
| 92 |
this.body = body; |
| 93 |
body.setParent(this); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
public int getLp() { |
| 100 |
return lp; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
public void setLp(int lp) { |
| 107 |
this.lp = lp; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
public int getRp() { |
| 114 |
return rp; |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
public void setRp(int rp) { |
| 121 |
this.rp = rp; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
public void setParens(int lp, int rp) { |
| 128 |
this.lp = lp; |
| 129 |
this.rp = rp; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
public int getIfPosition() { |
| 137 |
return ifPosition; |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public void setIfPosition(int ifPosition) { |
| 145 |
this.ifPosition = ifPosition; |
| 146 |
} |
| 147 |
|
| 148 |
@Override |
| 149 |
public String toSource(int depth) { |
| 150 |
StringBuilder sb = new StringBuilder(); |
| 151 |
sb.append(makeIndent(depth)); |
| 152 |
sb.append("catch ("); |
| 153 |
sb.append(varName.toSource(0)); |
| 154 |
if (catchCondition != null) { |
| 155 |
sb.append(" if "); |
| 156 |
sb.append(catchCondition.toSource(0)); |
| 157 |
} |
| 158 |
sb.append(") "); |
| 159 |
sb.append(body.toSource(0)); |
| 160 |
return sb.toString(); |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
@Override |
| 168 |
public void visit(NodeVisitor v) { |
| 169 |
if (v.visit(this)) { |
| 170 |
varName.visit(v); |
| 171 |
if (catchCondition != null) { |
| 172 |
catchCondition.visit(v); |
| 173 |
} |
| 174 |
body.visit(v); |
| 175 |
} |
| 176 |
} |
| 177 |
} |