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 | import com.google.javascript.jscomp.jsonml.TagType; |
21 | |
22 | import java.util.List; |
23 | |
24 | /** |
25 | * |
26 | * @author mikesamuel@gmail.com |
27 | */ |
28 | public final class DefaultCaseStmt extends SwitchCase { |
29 | private Block body; |
30 | |
31 | /** @param value unused. This ctor is provided for reflection. */ |
32 | @ReflectiveCtor |
33 | public DefaultCaseStmt( |
34 | FilePosition pos, Void value, List<? extends Block> children) { |
35 | this(pos, children.get(0)); |
36 | } |
37 | |
38 | public DefaultCaseStmt(FilePosition pos, Block body) { |
39 | super(pos); |
40 | appendChild(body); |
41 | } |
42 | |
43 | @Override |
44 | protected void childrenChanged() { |
45 | super.childrenChanged(); |
46 | this.body = (Block) children().get(0); |
47 | } |
48 | |
49 | @Override |
50 | public Object getValue() { return null; } |
51 | |
52 | @Override |
53 | public Block getBody() { return body; } |
54 | |
55 | @Override |
56 | protected void renderHead(RenderContext rc) { |
57 | rc.getOut().consume("default"); |
58 | } |
59 | |
60 | public JsonML toJsonML() { |
61 | return JsonMLBuilder.builder(TagType.DefaultCase, getFilePosition()) |
62 | .addChildren(body.children()) |
63 | .build(); |
64 | } |
65 | } |