Clover coverage report - DynamicJava Test Coverage (dynamicjava-20130622-r5436)
Coverage timestamp: Sat Jun 22 2013 03:01:29 CDT
file stats: LOC: 82   Methods: 3
NCLOC: 29   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
IntegerLiteral.java 70% 77.3% 100% 77.1%
coverage coverage
 1    /*
 2    * DynamicJava - Copyright (C) 1999-2001
 3    *
 4    * Permission is hereby granted, free of charge, to any person obtaining a
 5    * copy of this software and associated documentation files
 6    * (the "Software"), to deal in the Software without restriction, including
 7    * without limitation the rights to use, copy, modify, merge, publish,
 8    * distribute, sublicense, and/or sell copies of the Software, and to permit
 9    * persons to whom the Software is furnished to do so, subject to the
 10    * following conditions:
 11    * The above copyright notice and this permission notice shall be included
 12    * in all copies or substantial portions of the Software.
 13    *
 14    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 15    * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 16    * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 17    * IN NO EVENT SHALL DYADE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 18    * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 19    * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 20    * DEALINGS IN THE SOFTWARE.
 21    *
 22    * Except as contained in this notice, the name of Dyade shall not be
 23    * used in advertising or otherwise to promote the sale, use or other
 24    * dealings in this Software without prior written authorization from
 25    * Dyade.
 26    *
 27    */
 28   
 29    package koala.dynamicjava.tree;
 30   
 31    import java.math.BigInteger;
 32   
 33    /**
 34    * This class represents the integer literal nodes of the syntax tree
 35    *
 36    * @author Stephane Hillion
 37    * @version 1.0 - 1999/04/24
 38    */
 39   
 40    public class IntegerLiteral extends Literal {
 41    /**
 42    * Initializes a literal
 43    * @param rep the representation of the literal
 44    */
 45  32 public IntegerLiteral(String rep) throws NumberFormatException {
 46  32 this(rep, SourceInfo.NONE);
 47    }
 48   
 49    /**
 50    * Initializes a literal
 51    * @param rep the representation of the literal
 52    */
 53  451 public IntegerLiteral(String rep, SourceInfo si) throws NumberFormatException {
 54  451 super(rep,
 55    parse(rep),
 56    int.class,
 57    si);
 58    }
 59   
 60    /**
 61    * Parses the representation of an integer
 62    */
 63  451 private static Integer parse(String s) throws NumberFormatException {
 64  451 int radix = 10;
 65  451 int start = 0;
 66  451 boolean negate = false;
 67  451 int end = s.length();
 68    // only consider 0x or 0 or - if this doesn't make the string empty
 69  3 if ((end-start>1) && (s.startsWith("-"))) { start++; negate = true; }
 70  0 if ((end-start>2) && (s.startsWith("0x",start))) { radix = 16; start += 2; }
 71  0 else if ((end-start>1) && (s.startsWith("0",start)) && (s.length() > 1)) { radix = 8; start++; }
 72    // BigInteger can parse hex numbers representing negative ints; Integer can't
 73  451 BigInteger val = new BigInteger(s.substring(start), radix);
 74  3 if (negate) { val = val.negate(); }
 75  451 int result = val.intValue();
 76  451 if (val.bitLength() > 32 || (radix == 10 && !val.equals(BigInteger.valueOf(result)))) {
 77  0 throw new NumberFormatException("Literal is out of range: "+s);
 78    }
 79  451 return result;
 80    }
 81   
 82    }