1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.peaseplate.internal.lang.command;
21
22 import org.peaseplate.TemplateRuntimeException;
23 import org.peaseplate.internal.BuildContext;
24 import org.peaseplate.locator.TemplateLocator;
25
26 public class NotCommand extends AbstractUnaryCommand {
27
28 public NotCommand(TemplateLocator locator, int line, int column, ICommand command) {
29 super(locator, line, column, command);
30 }
31
32
33
34
35 @Override
36 public String getSign() {
37 return "!";
38 }
39
40
41
42
43 public Object call(BuildContext context) throws TemplateRuntimeException {
44 Object value = callCommand(context);
45
46 if (value == null)
47 throw new TemplateRuntimeException(
48 getCommand().getLocator(), getCommand().getLine(), getCommand().getColumn(),
49 "Unexpected NULL value"
50 );
51
52 if (value instanceof Boolean)
53 return Boolean.valueOf(!((Boolean)value).booleanValue());
54
55 throw new TemplateRuntimeException(
56 getLocator(), getLine(), getColumn(),
57 "Operation \"!\" not compatible with \"" + value.getClass() + "\""
58 );
59 }
60
61 }