PageRenderTime 45ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/org.eclim/java/org/eclim/command/Error.java

https://github.com/ervandew/eclim
Java | 217 lines | 106 code | 16 blank | 95 comment | 5 complexity | 70f538ec1090776220147e26d2f96414 MD5 | raw file
Possible License(s): 0BSD, BSD-3-Clause, MPL-2.0-no-copyleft-exception, GPL-3.0, LGPL-2.1, Apache-2.0, GPL-2.0
  1. /**
  2. * Copyright (C) 2005 - 2020 Eric Van Dewoestine
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. package org.eclim.command;
  18. import org.apache.commons.lang3.builder.EqualsBuilder;
  19. import org.apache.commons.lang3.builder.HashCodeBuilder;
  20. import org.eclim.util.StringUtils;
  21. /**
  22. * Represents an error to be reported to the user.
  23. *
  24. * @author Eric Van Dewoestine
  25. */
  26. public class Error
  27. {
  28. private String message;
  29. private String filename;
  30. private int line;
  31. private int column;
  32. private int endLine;
  33. private int endColumn;
  34. private boolean warning;
  35. /**
  36. * Constructs a new instance from the supplied values.
  37. *
  38. * @param message The error message.
  39. * @param filename The file containing the error.
  40. * @param line The line where the error occured.
  41. * @param column The column where the error occured.
  42. */
  43. public Error (
  44. String message,
  45. String filename,
  46. int line,
  47. int column)
  48. {
  49. this(message, filename, line, column, -1, -1, false);
  50. }
  51. /**
  52. * Constructs a new instance from the supplied values.
  53. *
  54. * @param message The error message.
  55. * @param filename The file containing the error.
  56. * @param line The line where the error occured.
  57. * @param column The column where the error occured.
  58. * @param warning true if this error is just a warning, false otherwise.
  59. */
  60. public Error (
  61. String message,
  62. String filename,
  63. int line,
  64. int column,
  65. boolean warning)
  66. {
  67. this(message, filename, line, column, -1, -1, warning);
  68. }
  69. /**
  70. * Constructs a new instance from the supplied values.
  71. *
  72. * @param message The error message.
  73. * @param filename The file containing the error.
  74. * @param line The line where the error occured.
  75. * @param column The column where the error occured.
  76. * @param endLine The line where the error ends.
  77. * @param endColumn The column where the error ends.
  78. * @param warning true if this error is just a warning, false otherwise.
  79. */
  80. public Error (
  81. String message,
  82. String filename,
  83. int line,
  84. int column,
  85. int endLine,
  86. int endColumn,
  87. boolean warning)
  88. {
  89. this.message = message != null ? message : StringUtils.EMPTY;
  90. this.filename = filename;
  91. this.line = line > 0 ? line : 1;
  92. this.column = column > 0 ? column : 1;
  93. this.endLine = endLine;
  94. this.endColumn = endColumn;
  95. this.warning = warning;
  96. }
  97. /**
  98. * Gets the error message.
  99. *
  100. * @return The error message.
  101. */
  102. public String getMessage()
  103. {
  104. return message != null ? message : StringUtils.EMPTY;
  105. }
  106. /**
  107. * Gets the file name.
  108. *
  109. * @return The file name.
  110. */
  111. public String getFilename()
  112. {
  113. return filename;
  114. }
  115. /**
  116. * Gets the line number.
  117. *
  118. * @return The line number.
  119. */
  120. public int getLine()
  121. {
  122. return line;
  123. }
  124. /**
  125. * Gets the column for this instance.
  126. *
  127. * @return The column.
  128. */
  129. public int getColumn()
  130. {
  131. return this.column;
  132. }
  133. /**
  134. * Gets the endLine for this instance.
  135. *
  136. * @return The endLine.
  137. */
  138. public int getEndLine()
  139. {
  140. return this.endLine;
  141. }
  142. /**
  143. * Gets the endColumn for this instance.
  144. *
  145. * @return The endColumn.
  146. */
  147. public int getEndColumn()
  148. {
  149. return this.endColumn;
  150. }
  151. /**
  152. * Checks if this error is just a warning.
  153. *
  154. * @return true if a warning, false otherwise.
  155. */
  156. public boolean isWarning()
  157. {
  158. return warning;
  159. }
  160. /**
  161. * Determines if this object is equal to the supplied object.
  162. *
  163. * @param other The object to test equality with.
  164. * @return true if the objects are equal, false otherwise.
  165. */
  166. public boolean equals(Object other)
  167. {
  168. if (!(other instanceof Error)) {
  169. return false;
  170. }
  171. if (this == other) {
  172. return true;
  173. }
  174. Error error = (Error)other;
  175. boolean equal = new EqualsBuilder()
  176. .append(getFilename(), error.getFilename())
  177. .append(getLine(), error.getLine())
  178. .append(getColumn(), error.getColumn())
  179. .append(getEndLine(), error.getEndLine())
  180. .append(getEndColumn(), error.getEndColumn())
  181. .append(getMessage(), error.getMessage())
  182. .isEquals();
  183. return equal;
  184. }
  185. /**
  186. * Gets the hash code for this object.
  187. *
  188. * @return The hash code for this object.
  189. */
  190. public int hashCode()
  191. {
  192. return new HashCodeBuilder(17, 37)
  193. .append(filename)
  194. .append(line)
  195. .append(column)
  196. .append(endLine)
  197. .append(endColumn)
  198. .append(message)
  199. .toHashCode();
  200. }
  201. }