Skip to content

Package: AstNegative

AstNegative

nameinstructionbranchcomplexitylinemethod
AstNegative(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%
getType(EvaluationContext)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getValue(EvaluationContext)
M: 132 C: 0
0%
M: 34 C: 0
0%
M: 18 C: 0
0%
M: 26 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 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.math.BigDecimal;
20: import java.math.BigInteger;
21:
22: import jakarta.el.ELException;
23:
24: import com.sun.el.lang.EvaluationContext;
25:
26: /**
27: * @author Jacob Hookom [jacob@hookom.net]
28: * @version $Change: 181177 $$DateTime: 2001/06/26 08:45:09 $$Author: kchung $
29: */
30: public final class AstNegative extends SimpleNode {
31: public AstNegative(int id) {
32: super(id);
33: }
34:
35: @Override
36: public Class getType(EvaluationContext ctx) throws ELException {
37: return Number.class;
38: }
39:
40: @Override
41: public Object getValue(EvaluationContext ctx) throws ELException {
42: Object obj = this.children[0].getValue(ctx);
43:
44:• if (obj == null) {
45: return Long.valueOf(0);
46: }
47:• if (obj instanceof BigDecimal) {
48: return ((BigDecimal) obj).negate();
49: }
50:• if (obj instanceof BigInteger) {
51: return ((BigInteger) obj).negate();
52: }
53:• if (obj instanceof String) {
54:• if (isStringFloat((String) obj)) {
55: return Double.valueOf(-Double.parseDouble((String) obj));
56: }
57: return Long.valueOf(-Long.parseLong((String) obj));
58: }
59: Class type = obj.getClass();
60:• if (obj instanceof Long || Long.TYPE == type) {
61: return Long.valueOf(-((Long) obj).longValue());
62: }
63:• if (obj instanceof Double || Double.TYPE == type) {
64: return Double.valueOf(-((Double) obj).doubleValue());
65: }
66:• if (obj instanceof Integer || Integer.TYPE == type) {
67: return Integer.valueOf(-((Integer) obj).intValue());
68: }
69:• if (obj instanceof Float || Float.TYPE == type) {
70: return Float.valueOf(-((Float) obj).floatValue());
71: }
72:• if (obj instanceof Short || Short.TYPE == type) {
73: return Short.valueOf((short) -((Short) obj).shortValue());
74: }
75:• if (obj instanceof Byte || Byte.TYPE == type) {
76: return Byte.valueOf((byte) -((Byte) obj).byteValue());
77: }
78: Long num = (Long) coerceToNumber(obj, Long.class);
79: return Long.valueOf(-num.longValue());
80: }
81: }