PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/src/com/google/doclava/Errors.java

https://bitbucket.org/fredgrott/androidlava
Java | 370 lines | 149 code | 77 blank | 144 comment | 24 complexity | 784ee5524dacea970c1de2201533dd64 MD5 | raw file
Possible License(s): CC0-1.0
  1. /*
  2. * Copyright (C) 2010 Google Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.google.doclava;
  17. import java.util.Set;
  18. import java.util.TreeSet;
  19. // TODO: Auto-generated Javadoc
  20. /**
  21. * The Class Errors.
  22. */
  23. public class Errors {
  24. /** The had error. */
  25. public static boolean hadError = false;
  26. /** The warnings are errors. */
  27. private static boolean warningsAreErrors = false;
  28. /** The all errors. */
  29. private static TreeSet<ErrorMessage> allErrors = new TreeSet<ErrorMessage>();
  30. /**
  31. * The Class ErrorMessage.
  32. */
  33. @SuppressWarnings("rawtypes")
  34. public static class ErrorMessage implements Comparable {
  35. /** The error. */
  36. Error error;
  37. /** The pos. */
  38. SourcePositionInfo pos;
  39. /** The msg. */
  40. String msg;
  41. /**
  42. * Instantiates a new error message.
  43. *
  44. * @param e the e
  45. * @param p the p
  46. * @param m the m
  47. */
  48. ErrorMessage(Error e, SourcePositionInfo p, String m) {
  49. error = e;
  50. pos = p;
  51. msg = m;
  52. }
  53. /**
  54. * @see java.lang.Comparable#compareTo(java.lang.Object)
  55. */
  56. public int compareTo(Object o) {
  57. ErrorMessage that = (ErrorMessage) o;
  58. int r = this.pos.compareTo(that.pos);
  59. if (r != 0) return r;
  60. return this.msg.compareTo(that.msg);
  61. }
  62. /**
  63. * @see java.lang.Object#toString()
  64. */
  65. @Override
  66. public String toString() {
  67. String whereText = this.pos == null ? "unknown: " : this.pos.toString() + ':';
  68. return whereText + this.msg;
  69. }
  70. /**
  71. * Error.
  72. *
  73. * @return the error
  74. */
  75. public Error error() {
  76. return error;
  77. }
  78. }
  79. /**
  80. * Error.
  81. *
  82. * @param error the error
  83. * @param where the where
  84. * @param text the text
  85. */
  86. public static void error(Error error, SourcePositionInfo where, String text) {
  87. if (error.level == HIDDEN) {
  88. return;
  89. }
  90. int level = (!warningsAreErrors && error.level == WARNING) ? WARNING : ERROR;
  91. String which = level == WARNING ? " warning " : " error ";
  92. String message = which + error.code + ": " + text;
  93. if (where == null) {
  94. where = new SourcePositionInfo("unknown", 0, 0);
  95. }
  96. allErrors.add(new ErrorMessage(error, where, message));
  97. if (error.level == ERROR || (warningsAreErrors && error.level == WARNING)) {
  98. hadError = true;
  99. }
  100. }
  101. /**
  102. * Clear errors.
  103. */
  104. public static void clearErrors() {
  105. hadError = false;
  106. allErrors.clear();
  107. }
  108. /**
  109. * Prints the errors.
  110. */
  111. public static void printErrors() {
  112. printErrors(allErrors);
  113. }
  114. /**
  115. * Prints the errors.
  116. *
  117. * @param errors the errors
  118. */
  119. public static void printErrors(Set<ErrorMessage> errors) {
  120. for (ErrorMessage m : errors) {
  121. if (m.error.level == WARNING) {
  122. System.err.println(m.toString());
  123. }
  124. }
  125. for (ErrorMessage m : errors) {
  126. if (m.error.level == ERROR) {
  127. System.err.println(m.toString());
  128. }
  129. }
  130. }
  131. /**
  132. * Gets the errors.
  133. *
  134. * @return the errors
  135. */
  136. public static Set<ErrorMessage> getErrors() {
  137. return allErrors;
  138. }
  139. /** The hidden. */
  140. public static int HIDDEN = 0;
  141. /** The warning. */
  142. public static int WARNING = 1;
  143. /** The error. */
  144. public static int ERROR = 2;
  145. /**
  146. * Sets the warnings are errors.
  147. *
  148. * @param val the new warnings are errors
  149. */
  150. public static void setWarningsAreErrors(boolean val) {
  151. warningsAreErrors = val;
  152. }
  153. /**
  154. * The Class Error.
  155. */
  156. public static class Error {
  157. /** The code. */
  158. public int code;
  159. /** The level. */
  160. public int level;
  161. /**
  162. * Instantiates a new error.
  163. *
  164. * @param code the code
  165. * @param level the level
  166. */
  167. public Error(int code, int level) {
  168. this.code = code;
  169. this.level = level;
  170. }
  171. /**
  172. * @see java.lang.Object#toString()
  173. */
  174. public String toString() {
  175. return "Error #" + this.code;
  176. }
  177. }
  178. // Errors for API verification
  179. /** The parse error. */
  180. public static Error PARSE_ERROR = new Error(1, ERROR);
  181. /** The added package. */
  182. public static Error ADDED_PACKAGE = new Error(2, WARNING);
  183. /** The added class. */
  184. public static Error ADDED_CLASS = new Error(3, WARNING);
  185. /** The added method. */
  186. public static Error ADDED_METHOD = new Error(4, WARNING);
  187. /** The added field. */
  188. public static Error ADDED_FIELD = new Error(5, WARNING);
  189. /** The added interface. */
  190. public static Error ADDED_INTERFACE = new Error(6, WARNING);
  191. /** The removed package. */
  192. public static Error REMOVED_PACKAGE = new Error(7, WARNING);
  193. /** The removed class. */
  194. public static Error REMOVED_CLASS = new Error(8, WARNING);
  195. /** The removed method. */
  196. public static Error REMOVED_METHOD = new Error(9, WARNING);
  197. /** The removed field. */
  198. public static Error REMOVED_FIELD = new Error(10, WARNING);
  199. /** The removed interface. */
  200. public static Error REMOVED_INTERFACE = new Error(11, WARNING);
  201. /** The changed static. */
  202. public static Error CHANGED_STATIC = new Error(12, WARNING);
  203. /** The changed final. */
  204. public static Error CHANGED_FINAL = new Error(13, WARNING);
  205. /** The changed transient. */
  206. public static Error CHANGED_TRANSIENT = new Error(14, WARNING);
  207. /** The changed volatile. */
  208. public static Error CHANGED_VOLATILE = new Error(15, WARNING);
  209. /** The changed type. */
  210. public static Error CHANGED_TYPE = new Error(16, WARNING);
  211. /** The changed value. */
  212. public static Error CHANGED_VALUE = new Error(17, WARNING);
  213. /** The changed superclass. */
  214. public static Error CHANGED_SUPERCLASS = new Error(18, WARNING);
  215. /** The changed scope. */
  216. public static Error CHANGED_SCOPE = new Error(19, WARNING);
  217. /** The changed abstract. */
  218. public static Error CHANGED_ABSTRACT = new Error(20, WARNING);
  219. /** The changed throws. */
  220. public static Error CHANGED_THROWS = new Error(21, WARNING);
  221. /** The changed native. */
  222. public static Error CHANGED_NATIVE = new Error(22, HIDDEN);
  223. /** The changed class. */
  224. public static Error CHANGED_CLASS = new Error(23, WARNING);
  225. /** The changed deprecated. */
  226. public static Error CHANGED_DEPRECATED = new Error(24, WARNING);
  227. /** The changed synchronized. */
  228. public static Error CHANGED_SYNCHRONIZED = new Error(25, ERROR);
  229. // Errors in javadoc generation
  230. /** The Constant UNRESOLVED_LINK. */
  231. public static final Error UNRESOLVED_LINK = new Error(101, WARNING);
  232. /** The Constant BAD_INCLUDE_TAG. */
  233. public static final Error BAD_INCLUDE_TAG = new Error(102, WARNING);
  234. /** The Constant UNKNOWN_TAG. */
  235. public static final Error UNKNOWN_TAG = new Error(103, WARNING);
  236. /** The Constant UNKNOWN_PARAM_TAG_NAME. */
  237. public static final Error UNKNOWN_PARAM_TAG_NAME = new Error(104, WARNING);
  238. /** The Constant UNDOCUMENTED_PARAMETER. */
  239. public static final Error UNDOCUMENTED_PARAMETER = new Error(105, HIDDEN);
  240. /** The Constant BAD_ATTR_TAG. */
  241. public static final Error BAD_ATTR_TAG = new Error(106, ERROR);
  242. /** The Constant BAD_INHERITDOC. */
  243. public static final Error BAD_INHERITDOC = new Error(107, HIDDEN);
  244. /** The Constant HIDDEN_LINK. */
  245. public static final Error HIDDEN_LINK = new Error(108, WARNING);
  246. /** The Constant HIDDEN_CONSTRUCTOR. */
  247. public static final Error HIDDEN_CONSTRUCTOR = new Error(109, WARNING);
  248. /** The Constant UNAVAILABLE_SYMBOL. */
  249. public static final Error UNAVAILABLE_SYMBOL = new Error(110, ERROR);
  250. /** The Constant HIDDEN_SUPERCLASS. */
  251. public static final Error HIDDEN_SUPERCLASS = new Error(111, WARNING);
  252. /** The Constant DEPRECATED. */
  253. public static final Error DEPRECATED = new Error(112, HIDDEN);
  254. /** The Constant DEPRECATION_MISMATCH. */
  255. public static final Error DEPRECATION_MISMATCH = new Error(113, WARNING);
  256. /** The Constant MISSING_COMMENT. */
  257. public static final Error MISSING_COMMENT = new Error(114, WARNING);
  258. /** The Constant IO_ERROR. */
  259. public static final Error IO_ERROR = new Error(115, HIDDEN);
  260. /** The Constant NO_SINCE_DATA. */
  261. public static final Error NO_SINCE_DATA = new Error(116, HIDDEN);
  262. /** The Constant NO_FEDERATION_DATA. */
  263. public static final Error NO_FEDERATION_DATA = new Error(117, WARNING);
  264. /** The Constant BROKEN_SINCE_FILE. */
  265. public static final Error BROKEN_SINCE_FILE = new Error(118, ERROR);
  266. /** The Constant ERRORS. */
  267. public static final Error[] ERRORS =
  268. {UNRESOLVED_LINK, BAD_INCLUDE_TAG, UNKNOWN_TAG, UNKNOWN_PARAM_TAG_NAME,
  269. UNDOCUMENTED_PARAMETER, BAD_ATTR_TAG, BAD_INHERITDOC, HIDDEN_LINK, HIDDEN_CONSTRUCTOR,
  270. UNAVAILABLE_SYMBOL, HIDDEN_SUPERCLASS, DEPRECATED, DEPRECATION_MISMATCH, MISSING_COMMENT,
  271. IO_ERROR, NO_SINCE_DATA, NO_FEDERATION_DATA, PARSE_ERROR, ADDED_PACKAGE, ADDED_CLASS,
  272. ADDED_METHOD, ADDED_FIELD, ADDED_INTERFACE, REMOVED_PACKAGE, REMOVED_CLASS,
  273. REMOVED_METHOD, REMOVED_FIELD, REMOVED_INTERFACE, CHANGED_STATIC, CHANGED_FINAL,
  274. CHANGED_TRANSIENT, CHANGED_VOLATILE, CHANGED_TYPE, CHANGED_VALUE, CHANGED_SUPERCLASS,
  275. CHANGED_SCOPE, CHANGED_ABSTRACT, CHANGED_THROWS, CHANGED_NATIVE, CHANGED_CLASS,
  276. CHANGED_DEPRECATED, CHANGED_SYNCHRONIZED, BROKEN_SINCE_FILE};
  277. /**
  278. * Sets the error level.
  279. *
  280. * @param code the code
  281. * @param level the level
  282. * @return true, if successful
  283. */
  284. public static boolean setErrorLevel(int code, int level) {
  285. for (Error e : ERRORS) {
  286. if (e.code == code) {
  287. e.level = level;
  288. return true;
  289. }
  290. }
  291. return false;
  292. }
  293. }