001 /* 002 * Copyright (C) 2006-2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package org.codehaus.gmaven.runtime.support.stubgen.parser; 018 019 /** 020 * Thrown to indicate a parsing failure. 021 * 022 * @version $Id: ParseException.java 18 2009-07-16 09:39:40Z user57 $ 023 * @author <a href="mailto:jason@planet57.com">Jason Dillon</a> 024 */ 025 public class ParseException 026 extends Exception 027 { 028 private Location location; 029 030 public ParseException(final Throwable cause) { 031 super(cause); 032 } 033 034 public ParseException(final Throwable cause, final Location location) { 035 super(cause); 036 037 assert location != null; 038 039 this.location = location; 040 } 041 042 public ParseException(final String message, final Location location) { 043 super(message); 044 045 assert location != null; 046 047 this.location = location; 048 } 049 050 public Location getLocation() { 051 return location; 052 } 053 054 public String getMessage() { 055 if (location == null) { 056 return super.getMessage(); 057 } 058 059 return super.getMessage() + " - " + location; 060 } 061 062 public static class Location 063 { 064 public final int line; 065 066 public final int column; 067 068 public final String fileName; 069 070 public Location(final int line, final int column, final String fileName) { 071 assert line > 0; 072 assert column > 0; 073 assert fileName != null; 074 075 this.line = line; 076 this.column = column; 077 this.fileName = fileName; 078 } 079 080 public String toString() { 081 return fileName + "[" + line + ":" + column + "]"; 082 } 083 } 084 }