Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
36   178   24   3.27
22   86   0.67   11
11     2.18  
1    
 
  SourceFileException       Line # 30 36 24 91.3% 0.9130435
 
  (3)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.se.common;
17   
18    import java.io.IOException;
19   
20    import org.qedeq.base.io.SourceArea;
21    import org.qedeq.base.io.SourcePosition;
22    import org.qedeq.base.utility.EqualsUtility;
23   
24   
25    /**
26    * Data validation error. Shows an error or warning within a source file.
27    *
28    * @author Michael Meyling
29    */
 
30    public class SourceFileException extends QedeqException {
31   
32    /** Serialization information. */
33    private static final long serialVersionUID = -4109767904038020052L;
34   
35    /** Error code of this Exception. */
36    private final Service service;
37   
38    /** Start of error location. */
39    private final SourceArea errorArea;
40   
41    /** End of error location. */
42    private final SourceArea referenceArea;
43   
44   
45    /**
46    * Constructor.
47    *
48    * @param service This service generated the error.
49    * @param errorCode Error code.
50    * @param errorText Error text.
51    * @param exception Exception to wrap.
52    * @param errorArea Error location.
53    * @param referenceArea Error reference location.
54    */
 
55  625 toggle public SourceFileException(final Service service, final int errorCode, final String errorText,
56    final Throwable exception, final SourceArea errorArea, final SourceArea referenceArea) {
57  625 super(errorCode, errorText, exception);
58  625 this.service = service;
59  625 this.errorArea = errorArea;
60  625 this.referenceArea = referenceArea;
61    }
62   
63    /**
64    * Constructor.
65    *
66    * @param service This service generated the error.
67    * @param exception Exception to wrap.
68    * @param errorArea Error location.
69    * @param referenceArea Error reference location.
70    */
 
71  436 toggle public SourceFileException(final Service service, final QedeqException exception,
72    final SourceArea errorArea, final SourceArea referenceArea) {
73  436 this(service, exception.getErrorCode(), exception.getMessage(), exception,
74    errorArea, referenceArea);
75    }
76   
77    /**
78    * Get service that found the error.
79    *
80    * @return Service.
81    */
 
82  105820 toggle public Service getService() {
83  105820 return service;
84    }
85   
86    /**
87    * Get position information about error location.
88    *
89    * @return Error location position.
90    */
 
91  201 toggle public SourceArea getSourceArea() {
92  201 return errorArea;
93    }
94   
95    /**
96    * Get additional position information about another associated location.
97    *
98    * @return Additional error location position.
99    */
 
100  3 toggle public SourceArea getReferenceArea() {
101  3 return referenceArea;
102    }
103   
 
104  105454 toggle public String getMessage() {
105  105454 if (getCause() != null) {
106  105416 if (getCause().getCause() != null) {
107  14 return getText(super.getMessage(), getCause().getCause());
108    }
109  105402 return getText(super.getMessage(), getCause());
110    }
111  38 return super.getMessage();
112    }
113   
114    /**
115    * Format error message.
116    *
117    * @param message Normal error message.
118    * @param cause This caused the exception. Must not be <code>null</code>.
119    * @return Error message.
120    */
 
121  105416 toggle private String getText(final String message, final Throwable cause) {
122  105416 if (message != null) {
123  105416 if (message.equals(cause.getMessage())) {
124  105205 return message;
125    }
126  211 if (cause instanceof IOException || cause instanceof NullPointerException) {
127  0 return message + "; " + cause.toString();
128    }
129  211 return message + "; " + cause.getMessage();
130    }
131  0 return cause.toString();
132    }
133   
134    /**
135    * Get detailed error description.
136    * The first line contains {@link #getErrorCode()} and {@link #getMessage()}.
137    * The second line contains the local address, the line and column.
138    *
139    * @return Error description.
140    */
 
141  377 toggle public String getDescription() {
142  377 final StringBuffer buffer = new StringBuffer();
143  377 if (errorArea != null && errorArea.getStartPosition() != null) {
144  365 final SourcePosition start = errorArea.getStartPosition();
145  365 buffer.append(errorArea.getAddress() + ":" + start.getRow() + ":"
146    + start.getColumn());
147  365 final SourcePosition end = errorArea.getEndPosition();
148  365 if (end != null) {
149  365 buffer.append(":" + end.getRow() + ":" + end.getColumn());
150    }
151  365 buffer.append("\n");
152    }
153  377 buffer.append("\t" + getErrorCode() + ": " + getMessage());
154  377 return buffer.toString();
155    }
156   
 
157  55 toggle public final int hashCode() {
158  55 return getErrorCode() ^ (errorArea != null ? errorArea.hashCode() : 13)
159  55 ^ (getService() != null ? getService().hashCode() : 131)
160  55 ^ (getMessage() != null ? getMessage().hashCode() : 499);
161    }
162   
 
163  228310 toggle public final boolean equals(final Object obj) {
164  228310 if (!(obj instanceof SourceFileException)) {
165  5 return false;
166    }
167  228305 final SourceFileException other = (SourceFileException) obj;
168  228305 return (getErrorCode() == other.getErrorCode())
169    && EqualsUtility.equals(getService(), other.getService())
170    && EqualsUtility.equals(getMessage(), other.getMessage())
171    && EqualsUtility.equals(errorArea, other.errorArea);
172    }
173   
 
174  359 toggle public final String toString() {
175  359 return getDescription();
176    }
177   
178    }