-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathEagerAstChoice.java
More file actions
103 lines (94 loc) · 2.65 KB
/
EagerAstChoice.java
File metadata and controls
103 lines (94 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.hubspot.jinjava.el.ext.eager;
import com.hubspot.jinjava.el.NoInvokeELContext;
import com.hubspot.jinjava.el.ext.DeferredParsingException;
import de.odysseus.el.tree.Bindings;
import de.odysseus.el.tree.impl.ast.AstChoice;
import de.odysseus.el.tree.impl.ast.AstNode;
import jakarta.el.ELContext;
import jakarta.el.ELException;
public class EagerAstChoice extends AstChoice implements EvalResultHolder {
protected Object evalResult;
protected boolean hasEvalResult;
protected final EvalResultHolder question;
protected final EvalResultHolder yes;
protected final EvalResultHolder no;
public EagerAstChoice(AstNode question, AstNode yes, AstNode no) {
this(
EagerAstNodeDecorator.getAsEvalResultHolder(question),
EagerAstNodeDecorator.getAsEvalResultHolder(yes),
EagerAstNodeDecorator.getAsEvalResultHolder(no)
);
}
private EagerAstChoice(
EvalResultHolder question,
EvalResultHolder yes,
EvalResultHolder no
) {
super((AstNode) question, (AstNode) yes, (AstNode) no);
this.question = question;
this.yes = yes;
this.no = no;
}
@Override
public Object eval(Bindings bindings, ELContext context) throws ELException {
try {
setEvalResult(super.eval(bindings, context));
return checkEvalResultSize(context);
} catch (DeferredParsingException e) {
if (question.hasEvalResult()) {
// the question was evaluated so jump to either yes or no
throw new DeferredParsingException(this, e.getDeferredEvalResult());
}
throw new DeferredParsingException(
this,
getPartiallyResolved(bindings, context, e, false)
);
}
}
@Override
public Object getEvalResult() {
return evalResult;
}
@Override
public void setEvalResult(Object evalResult) {
this.evalResult = evalResult;
hasEvalResult = true;
}
@Override
public boolean hasEvalResult() {
return hasEvalResult;
}
@Override
public String getPartiallyResolved(
Bindings bindings,
ELContext context,
DeferredParsingException deferredParsingException,
boolean preserveIdentifier
) {
return (
EvalResultHolder.reconstructNode(
bindings,
context,
question,
deferredParsingException,
false
) +
" ? " +
EvalResultHolder.reconstructNode(
bindings,
new NoInvokeELContext(context),
yes,
deferredParsingException,
preserveIdentifier
) +
" : " +
EvalResultHolder.reconstructNode(
bindings,
new NoInvokeELContext(context),
no,
deferredParsingException,
preserveIdentifier
)
);
}
}