blob: 7ba562341906ce4ce5b8a00038df490fa924adcf [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001/*
2 * Copyright (C) 2008 The Android Open Source Project
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
17import java.util.SortedSet;
18import java.util.TreeSet;
19
20public class Errors
21{
22 public static boolean hadError = false;
23 private static boolean warningsAreErrors = false;
24 private static TreeSet<Message> allErrors = new TreeSet<Message>();
25
26 private static class Message implements Comparable {
27 SourcePositionInfo pos;
28 int level;
29 String msg;
30
31 Message(SourcePositionInfo p, int l, String m) {
32 pos = p;
33 level = l;
34 msg = m;
35 }
36
37 public int compareTo(Object o) {
38 Message that = (Message)o;
39 int r = this.pos.compareTo(that.pos);
40 if (r != 0) return r;
41 return this.msg.compareTo(that.msg);
42 }
43
Xavier Ducrohet5ee390d2009-09-10 13:08:27 -070044 @Override
The Android Open Source Project88b60792009-03-03 19:28:42 -080045 public String toString() {
46 String whereText = this.pos == null ? "unknown: " : this.pos.toString() + ':';
47 return whereText + this.msg;
48 }
49 }
50
51 public static void error(Error error, SourcePositionInfo where, String text) {
52 if (error.level == HIDDEN) {
53 return;
54 }
55
56 int level = (!warningsAreErrors && error.level == WARNING) ? WARNING : ERROR;
57 String which = level == WARNING ? " warning " : " error ";
58 String message = which + error.code + ": " + text;
59
60 if (where == null) {
61 where = new SourcePositionInfo("unknown", 0, 0);
62 }
63
64 allErrors.add(new Message(where, level, message));
65
66 if (error.level == ERROR || (warningsAreErrors && error.level == WARNING)) {
67 hadError = true;
68 }
69 }
70
71 public static void printErrors() {
72 for (Message m: allErrors) {
73 if (m.level == WARNING) {
74 System.err.println(m.toString());
75 }
76 }
77 for (Message m: allErrors) {
78 if (m.level == ERROR) {
79 System.err.println(m.toString());
80 }
81 }
82 }
83
84 public static int HIDDEN = 0;
85 public static int WARNING = 1;
86 public static int ERROR = 2;
87
88 public static void setWarningsAreErrors(boolean val) {
89 warningsAreErrors = val;
90 }
91
92 public static class Error {
93 public int code;
94 public int level;
95
96 public Error(int code, int level)
97 {
98 this.code = code;
99 this.level = level;
100 }
101 }
102
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);
Jesse Wilsonb1279972010-01-28 10:50:58 -0800118 public static Error NO_SINCE_DATA = new Error(16, HIDDEN);
The Android Open Source Project88b60792009-03-03 19:28:42 -0800119
120 public static Error[] ERRORS = {
121 UNRESOLVED_LINK,
122 BAD_INCLUDE_TAG,
123 UNKNOWN_TAG,
124 UNKNOWN_PARAM_TAG_NAME,
125 UNDOCUMENTED_PARAMETER,
126 BAD_ATTR_TAG,
127 BAD_INHERITDOC,
128 HIDDEN_LINK,
129 HIDDEN_CONSTRUCTOR,
130 UNAVAILABLE_SYMBOL,
131 HIDDEN_SUPERCLASS,
132 DEPRECATED,
133 IO_ERROR,
Jesse Wilson5e0dd412009-06-01 17:59:44 -0700134 NO_SINCE_DATA,
The Android Open Source Project88b60792009-03-03 19:28:42 -0800135 };
136
137 public static boolean setErrorLevel(int code, int level) {
138 for (Error e: ERRORS) {
139 if (e.code == code) {
140 e.level = level;
141 return true;
142 }
143 }
144 return false;
145 }
146}