blob: 143131446fd72019dd240390513d869bc78d1c72 [file] [log] [blame]
The Android Open Source Projectb6c1cf62008-10-21 07:00:00 -07001/*
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 String msg;
29
30 Message(SourcePositionInfo p, String m) {
31 pos = p;
32 msg = m;
33 }
34
35 public int compareTo(Object o) {
36 Message that = (Message)o;
37 int r = this.pos.compareTo(that.pos);
38 if (r != 0) return r;
39 return this.msg.compareTo(that.msg);
40 }
41
42 public String toString() {
43 String whereText = this.pos == null ? "unknown: " : this.pos.toString() + ':';
44 return whereText + this.msg;
45 }
46 }
47
48 public static void error(Error error, SourcePositionInfo where, String text) {
49 if (error.level == HIDDEN) {
50 return;
51 }
52
53 String which = (!warningsAreErrors && error.level == WARNING) ? " warning " : " error ";
54 String message = which + error.code + ": " + text;
55
56 if (where == null) {
57 where = new SourcePositionInfo("unknown", 0, 0);
58 }
59
60 allErrors.add(new Message(where, message));
61
62 if (error.level == ERROR || (warningsAreErrors && error.level == WARNING)) {
63 hadError = true;
64 }
65 }
66
67 public static void printErrors() {
68 for (Message m: allErrors) {
69 System.err.println(m.toString());
70 }
71 }
72
73 public static int HIDDEN = 0;
74 public static int WARNING = 1;
75 public static int ERROR = 2;
76
77 public static void setWarningsAreErrors(boolean val) {
78 warningsAreErrors = val;
79 }
80
81 public static class Error {
82 public int code;
83 public int level;
84
85 public Error(int code, int level)
86 {
87 this.code = code;
88 this.level = level;
89 }
90 }
91
92 public static Error UNRESOLVED_LINK = new Error(1, WARNING);
93 public static Error BAD_INCLUDE_TAG = new Error(2, WARNING);
94 public static Error UNKNOWN_TAG = new Error(3, WARNING);
95 public static Error UNKNOWN_PARAM_TAG_NAME = new Error(4, WARNING);
96 public static Error UNDOCUMENTED_PARAMETER = new Error(5, HIDDEN);
97 public static Error BAD_ATTR_TAG = new Error(6, ERROR);
98 public static Error BAD_INHERITDOC = new Error(7, HIDDEN);
99 public static Error HIDDEN_LINK = new Error(8, WARNING);
100 public static Error HIDDEN_CONSTRUCTOR = new Error(9, WARNING);
101 public static Error UNAVAILABLE_SYMBOL = new Error(10, ERROR);
102 public static Error HIDDEN_SUPERCLASS = new Error(11, WARNING);
103 public static Error DEPRECATED = new Error(12, HIDDEN);
104 public static Error DEPRECATION_MISMATCH = new Error(13, WARNING);
105 public static Error MISSING_COMMENT = new Error(14, WARNING);
106 public static Error IO_ERROR = new Error(15, HIDDEN);
107
108 public static Error[] ERRORS = {
109 UNRESOLVED_LINK,
110 BAD_INCLUDE_TAG,
111 UNKNOWN_TAG,
112 UNKNOWN_PARAM_TAG_NAME,
113 UNDOCUMENTED_PARAMETER,
114 BAD_ATTR_TAG,
115 BAD_INHERITDOC,
116 HIDDEN_LINK,
117 HIDDEN_CONSTRUCTOR,
118 UNAVAILABLE_SYMBOL,
119 HIDDEN_SUPERCLASS,
120 DEPRECATED,
121 IO_ERROR,
122 };
123
124 public static boolean setErrorLevel(int code, int level) {
125 for (Error e: ERRORS) {
126 if (e.code == code) {
127 e.level = level;
128 return true;
129 }
130 }
131 return false;
132 }
133}