| 1 |
/* |
| 2 |
* Copyright (C) 2018 Google, Inc. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
package com.google.escapevelocity; |
| 17 |
|
| 18 |
/** |
| 19 |
* A node in the parse tree representing a constant value. Evaluating the node yields the constant |
| 20 |
* value. Instances of this class are used both in expressions, like the {@code 23} in |
| 21 |
* {@code #set ($x = 23)}, and for literal text in templates. In the template... |
| 22 |
* <pre>{@code |
| 23 |
* abc#{if}($x == 5)def#{end}xyz |
| 24 |
* }</pre> |
| 25 |
* ...each of the strings {@code abc}, {@code def}, {@code xyz} is represented by an instance of |
| 26 |
* this class that {@linkplain #evaluate evaluates} to that string, and the value {@code 5} is |
| 27 |
* represented by an instance of this class that evaluates to the integer 5. |
| 28 |
* |
| 29 |
* @author [email protected] (Éamonn McManus) |
| 30 |
*/ |
| 31 |
class ConstantExpressionNode extends ExpressionNode { |
| 32 |
private final Object value; |
| 33 |
|
| 34 |
ConstantExpressionNode(String resourceName, int lineNumber, Object value) { |
| 35 |
super(resourceName, lineNumber); |
| 36 |
this.value = value; |
| 37 |
} |
| 38 |
|
| 39 |
@Override |
| 40 |
Object evaluate(EvaluationContext context) { |
| 41 |
return value; |
| 42 |
} |
| 43 |
} |