2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 import java.util.SortedSet;
18 import java.util.TreeSet;
22 public static boolean hadError = false;
23 private static boolean warningsAreErrors = false;
24 private static TreeSet<Message> allErrors = new TreeSet<Message>();
26 private static class Message implements Comparable {
27 SourcePositionInfo pos;
31 Message(SourcePositionInfo p, int l, String m) {
37 public int compareTo(Object o) {
38 Message that = (Message)o;
39 int r = this.pos.compareTo(that.pos);
41 return this.msg.compareTo(that.msg);
45 public String toString() {
46 String whereText = this.pos == null ? "unknown: " : this.pos.toString() + ':';
47 return whereText + this.msg;
51 public static void error(Error error, SourcePositionInfo where, String text) {
52 if (error.level == HIDDEN) {
56 int level = (!warningsAreErrors && error.level == WARNING) ? WARNING : ERROR;
57 String which = level == WARNING ? " warning " : " error ";
58 String message = which + error.code + ": " + text;
61 where = new SourcePositionInfo("unknown", 0, 0);
64 allErrors.add(new Message(where, level, message));
66 if (error.level == ERROR || (warningsAreErrors && error.level == WARNING)) {
71 public static void printErrors() {
72 for (Message m: allErrors) {
73 if (m.level == WARNING) {
74 System.err.println(m.toString());
77 for (Message m: allErrors) {
78 if (m.level == ERROR) {
79 System.err.println(m.toString());
84 public static int HIDDEN = 0;
85 public static int WARNING = 1;
86 public static int ERROR = 2;
88 public static void setWarningsAreErrors(boolean val) {
89 warningsAreErrors = val;
92 public static class Error {
96 public Error(int code, int level)
103 public static Error UNRESOLVED_LINK = new Error(1, WARNING);
104 public static Error BAD_INCLUDE_TAG = new Error(2, WARNING);
105 public static Error UNKNOWN_TAG = new Error(3, WARNING);
106 public static Error UNKNOWN_PARAM_TAG_NAME = new Error(4, WARNING);
107 public static Error UNDOCUMENTED_PARAMETER = new Error(5, HIDDEN);
108 public static Error BAD_ATTR_TAG = new Error(6, ERROR);
109 public static Error BAD_INHERITDOC = new Error(7, HIDDEN);
110 public static Error HIDDEN_LINK = new Error(8, WARNING);
111 public static Error HIDDEN_CONSTRUCTOR = new Error(9, WARNING);
112 public static Error UNAVAILABLE_SYMBOL = new Error(10, ERROR);
113 public static Error HIDDEN_SUPERCLASS = new Error(11, WARNING);
114 public static Error DEPRECATED = new Error(12, HIDDEN);
115 public static Error DEPRECATION_MISMATCH = new Error(13, WARNING);
116 public static Error MISSING_COMMENT = new Error(14, WARNING);
117 public static Error IO_ERROR = new Error(15, HIDDEN);
118 public static Error NO_SINCE_DATA = new Error(16, HIDDEN);
120 public static Error[] ERRORS = {
124 UNKNOWN_PARAM_TAG_NAME,
125 UNDOCUMENTED_PARAMETER,
133 DEPRECATION_MISMATCH,
139 public static boolean setErrorLevel(int code, int level) {
140 for (Error e: ERRORS) {
141 if (e.code == code) {