Skip to content

Package: AstMapData

AstMapData

nameinstructionbranchcomplexitylinemethod
AstMapData(int)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getValue(EvaluationContext)
M: 65 C: 0
0%
M: 10 C: 0
0%
M: 6 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package com.sun.el.parser;
18:
19: import java.util.HashMap;
20: import java.util.HashSet;
21:
22: import jakarta.el.ELException;
23:
24: import com.sun.el.lang.EvaluationContext;
25:
26: /**
27: * @author Kin-man Chung
28: */
29: public class AstMapData extends SimpleNode {
30: public AstMapData(int id) {
31: super(id);
32: }
33:
34: @Override
35: public Object getValue(EvaluationContext ctx) {
36: HashSet<Object> set = new HashSet<Object>();
37: HashMap<Object, Object> map = new HashMap<Object, Object>();
38:
39: int paramCount = this.jjtGetNumChildren();
40:• for (int i = 0; i < paramCount; i++) {
41: Node entry = this.children[i];
42: Object v1 = entry.jjtGetChild(0).getValue(ctx);
43:• if (entry.jjtGetNumChildren() > 1) {
44: // expr: expr
45: map.put(v1, entry.jjtGetChild(1).getValue(ctx));
46: } else {
47: set.add(v1);
48: }
49: }
50: // It is error to have mixed set/map entries
51:• if (set.size() > 0 && map.size() > 0) {
52: throw new ELException("Cannot mix set entry with map entry.");
53: }
54:• if (map.size() > 0) {
55: return map;
56: }
57: return set;
58: }
59: }