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.parser.ParseTreeNode; |
19 | import com.google.javascript.jscomp.jsonml.JsonML; |
20 | import com.google.javascript.jscomp.jsonml.TagAttr; |
21 | import com.google.javascript.jscomp.jsonml.TagType; |
22 | |
23 | import java.util.List; |
24 | |
25 | /** |
26 | * A literal boolean value. |
27 | * |
28 | * @author mikesamuel@gmail.com |
29 | */ |
30 | public final class BooleanLiteral extends Literal { |
31 | public final boolean value; |
32 | |
33 | /** @param children unused. This ctor is provided for reflection. */ |
34 | @ReflectiveCtor |
35 | public BooleanLiteral( |
36 | FilePosition pos, Boolean value, List<? extends ParseTreeNode> children) { |
37 | this(pos, value); |
38 | } |
39 | |
40 | public BooleanLiteral(FilePosition pos, boolean value) { |
41 | super(pos); |
42 | this.value = value; |
43 | } |
44 | |
45 | @Override |
46 | public Boolean getValue() { |
47 | return Boolean.valueOf(value); |
48 | } |
49 | |
50 | @Override |
51 | public boolean getValueInBooleanContext() { |
52 | return value; |
53 | } |
54 | |
55 | public String typeOf() { return "boolean"; } |
56 | |
57 | public JsonML toJsonML() { |
58 | return JsonMLBuilder.builder(TagType.LiteralExpr, getFilePosition()) |
59 | .setAttribute(TagAttr.TYPE, "boolean") |
60 | .setAttribute(TagAttr.VALUE, value) |
61 | .build(); |
62 | } |
63 | } |