Clover coverage report - DynamicJava Test Coverage (dynamicjava-20120303-r5436)
Coverage timestamp: Sat Mar 3 2012 03:02:19 CST
file stats: LOC: 114   Methods: 6
NCLOC: 54   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ParseError.java 0% 0% 0% 0%
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.parser.wrapper;
 30   
 31   
 32    import java.io.File;
 33   
 34    import edu.rice.cs.plt.text.TextUtil;
 35    import koala.dynamicjava.parser.impl.ParseException;
 36    import koala.dynamicjava.parser.impl.Token;
 37    import koala.dynamicjava.tree.SourceInfo;
 38   
 39    /**
 40    * This error is thrown when an unexpected error append while
 41    * parsing a statement
 42    *
 43    * @author Stephane Hillion
 44    * @version 1.0 - 1999/05/03
 45    */
 46   
 47    public class ParseError extends Error implements SourceInfo.Wrapper {
 48    private SourceInfo _si;
 49   
 50   
 51    /**
 52    * Constructs an <code>ExecutionError</code> with the specified
 53    * detail message.
 54    * @param s the detail message.
 55    */
 56  0 public ParseError(String s, SourceInfo si) {
 57  0 super(s);
 58  0 _si = si;
 59    }
 60   
 61    /**
 62    * Constructs a ParseError based on a ParseException.
 63    * @param e the ParseException.
 64    * @param f the source file, or {@code null} if it is unknown.
 65    */
 66  0 public ParseError(ParseException e, File f) {
 67  0 super(parseExceptionMessage(e), e);
 68  0 _si = parseExceptionLocation(e, f);
 69    }
 70   
 71  0 public ParseError(Throwable t, SourceInfo si) {
 72  0 super(t.getMessage(), t);
 73  0 _si = si;
 74    }
 75   
 76  0 public SourceInfo getSourceInfo() { return _si; }
 77   
 78   
 79  0 private static String parseExceptionMessage(ParseException e) {
 80  0 if (e.expectedTokenSequences == null) { return e.getMessage(); }
 81    else {
 82  0 int maxSize = 0;
 83  0 for (int i = 0; i < e.expectedTokenSequences.length; i++) {
 84  0 if (maxSize < e.expectedTokenSequences[i].length) {
 85  0 maxSize = e.expectedTokenSequences[i].length;
 86    }
 87    }
 88  0 String retval = "Syntax Error: \"";
 89  0 Token tok = e.currentToken.next;
 90   
 91  0 for (int i = 0; i < maxSize; i++) {
 92  0 if (i != 0) retval += " ";
 93  0 if (tok.kind == 0) {
 94  0 retval += e.tokenImage[0];
 95  0 break;
 96    }
 97  0 retval += TextUtil.javaEscape(tok.image);
 98  0 tok = tok.next;
 99    }
 100  0 retval += "\"";
 101  0 return retval;
 102    }
 103    }
 104   
 105  0 private static SourceInfo parseExceptionLocation(ParseException e, File f) {
 106  0 Token t = e.currentToken;
 107  0 if (t == null) { return SourceInfo.point(f, 0, 0); }
 108    else {
 109  0 if (t.next != null) { t = t.next; }
 110  0 return SourceInfo.range(f, t.beginLine, t.beginColumn, t.endLine, t.endColumn);
 111    }
 112    }
 113   
 114    }