Coverage report

| %line | %branch
--- | --- | ---
org.apache.commons.jexl.parser.ASTUnaryMinusNode |
87% |
97% |

1 |  |
     /*
2 |  |
      * Copyright 2002-2006 The Apache Software Foundation.
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 org.apache.commons.jexl.parser;
17 |  |
18 |  |
     import java.math.BigDecimal;
19 |  |
     import java.math.BigInteger;
20 |  |
21 |  |
     import org.apache.commons.jexl.JexlContext;
22 |  |
23 |  |
     /**
24 |  |
      * - (unary minus).
25 |  |
      *
26 |  |
      * @author <a href="mailto:mhw@kremvax.net">Mark H. Wilkinson</a>
27 |  |
      * @version $Id: ASTUnaryMinusNode.java 398325 2006-04-30 12:34:29Z dion $
28 |  |
      */
29 |  |
     public class ASTUnaryMinusNode extends SimpleNode {
30 |  |
         /**
31 |  |
          * Create the node given an id.
32 |  |
          *
33 |  |
          * @param id node id.
34 |  |
          */
35 |  |
         public ASTUnaryMinusNode(int id) {
36 | 0 |
             super(id);
37 | 0 |
         }
38 |  |
39 |  |
         /**
40 |  |
          * Create a node with the given parser and id.
41 |  |
          *
42 |  |
          * @param p a parser.
43 |  |
          * @param id node id.
44 |  |
          */
45 |  |
         public ASTUnaryMinusNode(Parser p, int id) {
46 | 14 |
             super(p, id);
47 | 14 |
         }
48 |  |
49 |  |
         /** {@inheritDoc} */
50 |  |
         public Object jjtAccept(ParserVisitor visitor, Object data) {
51 | 0 |
             return visitor.visit(this, data);
52 |  |
         }
53 |  |
54 |  |
         /** {@inheritDoc} */
55 |  |
         public Object value(JexlContext jc) throws Exception {
56 | 14 |
             Object val = ((SimpleNode) jjtGetChild(0)).value(jc);
57 |  |
58 | 14 |
             if (val instanceof Byte) {
59 | 1 |
                 byte valueAsByte = ((Byte) val).byteValue();
60 | 1 |
                 return new Byte((byte) -valueAsByte);
61 | 13 |
             } else if (val instanceof Short) {
62 | 1 |
                 short valueAsShort = ((Short) val).class="keyword">shortValue();
63 | 1 |
                 return new Short((short) -valueAsShort);
64 | 12 |
             } else if (val instanceof Integer) {
65 | 6 |
                 int valueAsInt = ((Integer) val).class="keyword">intValue();
66 | 6 |
                 return new Integer(-valueAsInt);
67 | 6 |
             } else if (val instanceof Long) {
68 | 1 |
                 long valueAsLong = ((Long) val).class="keyword">longValue();
69 | 1 |
                 return new Long(-valueAsLong);
70 | 5 |
             } else if (val instanceof Float) {
71 | 2 |
                 float valueAsFloat = ((Float) val).class="keyword">floatValue();
72 | 2 |
                 return new Float(-valueAsFloat);
73 | 3 |
             } else if (val instanceof Double) {
74 | 1 |
                 double valueAsDouble = ((Double) val).class="keyword">doubleValue();
75 | 1 |
                 return new Double(-valueAsDouble);
76 | 2 |
             } else if (val instanceof BigDecimal) {
77 | 1 |
                 BigDecimal valueAsBigD = (BigDecimal) val;
78 | 1 |
                 return valueAsBigD.negate();
79 | 1 |
             } else if (val instanceof BigInteger) {
80 | 1 |
                 BigInteger valueAsBigI = (BigInteger) val;
81 | 1 |
                 return valueAsBigI.negate();
82 |  |
             }
83 | 0 |
             throw new Exception("expression not a number");
84 |  |
         }
85 |  |
     }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.