1 | // Copyright (C) 2005 Google Inc. |
2 | // |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | // you may not use this file except in compliance with the License. |
5 | // You may obtain a copy of the License at |
6 | // |
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | // |
9 | // Unless required by applicable law or agreed to in writing, software |
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | // See the License for the specific language governing permissions and |
13 | // limitations under the License. |
14 | |
15 | package com.google.caja.parser.js; |
16 | |
17 | import com.google.caja.lexer.FilePosition; |
18 | import com.google.caja.reporting.RenderContext; |
19 | import com.google.javascript.jscomp.jsonml.JsonML; |
20 | |
21 | import java.util.List; |
22 | |
23 | /** |
24 | * |
25 | * @author mikesamuel@gmail.com |
26 | */ |
27 | public final class FinallyStmt extends AbstractStatement { |
28 | private Block body; |
29 | |
30 | /** @param value unused. This ctor is provided for reflection. */ |
31 | @ReflectiveCtor |
32 | public FinallyStmt( |
33 | FilePosition pos, Void value, List<? extends Block> children) { |
34 | this(pos, children.get(0)); |
35 | } |
36 | |
37 | public FinallyStmt(FilePosition pos, Block body) { |
38 | super(pos, Block.class); |
39 | appendChild(body); |
40 | } |
41 | |
42 | public Block getBody() { return body; } |
43 | |
44 | @Override |
45 | protected void childrenChanged() { |
46 | super.childrenChanged(); |
47 | this.body = (Block) children().get(0); |
48 | if (children().size() != 1) { throw new IndexOutOfBoundsException(); } |
49 | } |
50 | |
51 | @Override |
52 | public Object getValue() { return null; } |
53 | |
54 | public void render(RenderContext rc) { |
55 | rc.getOut().mark(getFilePosition()); |
56 | rc.getOut().consume("finally"); |
57 | body.renderBlock(rc, false); |
58 | } |
59 | |
60 | public boolean hasHangingConditional() { return false; } |
61 | |
62 | public JsonML toJsonML() { return body.toJsonML(); } |
63 | } |