Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1291)

Side by Side Diff: pkg/analyzer/lib/src/generated/error.dart

Issue 1265453005: Code clean-up, mostly constructors (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/lib/src/generated/html.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library engine.error; 5 library engine.error;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'ast.dart' show AstNode; 9 import 'ast.dart' show AstNode;
10 import 'element.dart'; 10 import 'element.dart';
(...skipping 22 matching lines...) Expand all
33 /** 33 /**
34 * A [Comparator] that sorts error codes first by their severity (errors 34 * A [Comparator] that sorts error codes first by their severity (errors
35 * first, warnings second), and then by the the error code type. 35 * first, warnings second), and then by the the error code type.
36 */ 36 */
37 static Comparator<AnalysisError> ERROR_CODE_COMPARATOR = (AnalysisError o1, 37 static Comparator<AnalysisError> ERROR_CODE_COMPARATOR = (AnalysisError o1,
38 AnalysisError o2) { 38 AnalysisError o2) {
39 ErrorCode errorCode1 = o1.errorCode; 39 ErrorCode errorCode1 = o1.errorCode;
40 ErrorCode errorCode2 = o2.errorCode; 40 ErrorCode errorCode2 = o2.errorCode;
41 ErrorSeverity errorSeverity1 = errorCode1.errorSeverity; 41 ErrorSeverity errorSeverity1 = errorCode1.errorSeverity;
42 ErrorSeverity errorSeverity2 = errorCode2.errorSeverity; 42 ErrorSeverity errorSeverity2 = errorCode2.errorSeverity;
43 ErrorType errorType1 = errorCode1.type;
44 ErrorType errorType2 = errorCode2.type;
45 if (errorSeverity1 == errorSeverity2) { 43 if (errorSeverity1 == errorSeverity2) {
44 ErrorType errorType1 = errorCode1.type;
45 ErrorType errorType2 = errorCode2.type;
46 return errorType1.compareTo(errorType2); 46 return errorType1.compareTo(errorType2);
47 } else { 47 } else {
48 return errorSeverity2.compareTo(errorSeverity1); 48 return errorSeverity2.compareTo(errorSeverity1);
49 } 49 }
50 }; 50 };
51 51
52 /** 52 /**
53 * The error code associated with the error. 53 * The error code associated with the error.
54 */ 54 */
55 final ErrorCode errorCode; 55 final ErrorCode errorCode;
(...skipping 17 matching lines...) Expand all
73 /** 73 /**
74 * The character offset from the beginning of the source (zero based) where 74 * The character offset from the beginning of the source (zero based) where
75 * the error occurred. 75 * the error occurred.
76 */ 76 */
77 int offset = 0; 77 int offset = 0;
78 78
79 /** 79 /**
80 * The number of characters from the offset to the end of the source which 80 * The number of characters from the offset to the end of the source which
81 * encompasses the compilation error. 81 * encompasses the compilation error.
82 */ 82 */
83 int _length = 0; 83 int length = 0;
84 84
85 /** 85 /**
86 * A flag indicating whether this error can be shown to be a non-issue because 86 * A flag indicating whether this error can be shown to be a non-issue because
87 * of the result of type propagation. 87 * of the result of type propagation.
88 */ 88 */
89 bool isStaticOnly = false; 89 bool isStaticOnly = false;
90 90
91 /** 91 /**
92 * Initialize a newly created analysis error. The error is associated with the 92 * Initialize a newly created analysis error. The error is associated with the
93 * given [source] and is located at the given [offset] with the given 93 * given [source] and is located at the given [offset] with the given
94 * [length]. The error will have the given [errorCode] and the list of 94 * [length]. The error will have the given [errorCode] and the list of
95 * [arguments] will be used to complete the message. 95 * [arguments] will be used to complete the message.
96 */ 96 */
97 AnalysisError(this.source, this.offset, int length, this.errorCode, 97 AnalysisError(this.source, this.offset, this.length, this.errorCode,
98 [List<Object> arguments]) { 98 [List<Object> arguments]) {
99 this._length = length;
100 this._message = formatList(errorCode.message, arguments); 99 this._message = formatList(errorCode.message, arguments);
101 String correctionTemplate = errorCode.correction; 100 String correctionTemplate = errorCode.correction;
102 if (correctionTemplate != null) { 101 if (correctionTemplate != null) {
103 this._correction = formatList(correctionTemplate, arguments); 102 this._correction = formatList(correctionTemplate, arguments);
104 } 103 }
105 } 104 }
106 105
107 /** 106 /**
108 * Initialize a newly created analysis error for the specified [source]. The 107 * Initialize a newly created analysis error for the specified [source]. The
109 * error will have the given [errorCode] and the list of [arguments] will be 108 * error will have the given [errorCode] and the list of [arguments] will be
(...skipping 24 matching lines...) Expand all
134 133
135 @override 134 @override
136 int get hashCode { 135 int get hashCode {
137 int hashCode = offset; 136 int hashCode = offset;
138 hashCode ^= (_message != null) ? _message.hashCode : 0; 137 hashCode ^= (_message != null) ? _message.hashCode : 0;
139 hashCode ^= (source != null) ? source.hashCode : 0; 138 hashCode ^= (source != null) ? source.hashCode : 0;
140 return hashCode; 139 return hashCode;
141 } 140 }
142 141
143 /** 142 /**
144 * Return the length of the error location, that is, the number of characters
145 * from the offset to the end of the source which encompasses the compilation
146 * error.
147 */
148 int get length => _length;
149
150 /**
151 * Return the message to be displayed for this error. The message should 143 * Return the message to be displayed for this error. The message should
152 * indicate what is wrong and why it is wrong. 144 * indicate what is wrong and why it is wrong.
153 */ 145 */
154 String get message => _message; 146 String get message => _message;
155 147
156 @override 148 @override
157 bool operator ==(Object obj) { 149 bool operator ==(Object obj) {
158 if (identical(obj, this)) { 150 if (identical(obj, this)) {
159 return true; 151 return true;
160 } 152 }
161 // prepare other AnalysisError 153 // prepare other AnalysisError
162 if (obj is! AnalysisError) { 154 if (obj is! AnalysisError) {
163 return false; 155 return false;
164 } 156 }
165 AnalysisError other = obj as AnalysisError; 157 AnalysisError other = obj as AnalysisError;
166 // Quick checks. 158 // Quick checks.
167 if (!identical(errorCode, other.errorCode)) { 159 if (!identical(errorCode, other.errorCode)) {
168 return false; 160 return false;
169 } 161 }
170 if (offset != other.offset || _length != other._length) { 162 if (offset != other.offset || length != other.length) {
171 return false; 163 return false;
172 } 164 }
173 if (isStaticOnly != other.isStaticOnly) { 165 if (isStaticOnly != other.isStaticOnly) {
174 return false; 166 return false;
175 } 167 }
176 // Deep checks. 168 // Deep checks.
177 if (_message != other._message) { 169 if (_message != other._message) {
178 return false; 170 return false;
179 } 171 }
180 if (source != other.source) { 172 if (source != other.source) {
181 return false; 173 return false;
182 } 174 }
183 // OK 175 // OK
184 return true; 176 return true;
185 } 177 }
186 178
187 /** 179 /**
188 * Return the value of the given [property], or `null` if the given property 180 * Return the value of the given [property], or `null` if the given property
189 * is not defined for this error. 181 * is not defined for this error.
190 */ 182 */
191 Object getProperty(ErrorProperty property) => null; 183 Object getProperty(ErrorProperty property) => null;
192 184
193 @override 185 @override
194 String toString() { 186 String toString() {
195 StringBuffer buffer = new StringBuffer(); 187 StringBuffer buffer = new StringBuffer();
196 buffer.write((source != null) ? source.fullName : "<unknown source>"); 188 buffer.write((source != null) ? source.fullName : "<unknown source>");
197 buffer.write("("); 189 buffer.write("(");
198 buffer.write(offset); 190 buffer.write(offset);
199 buffer.write(".."); 191 buffer.write("..");
200 buffer.write(offset + _length - 1); 192 buffer.write(offset + length - 1);
201 buffer.write("): "); 193 buffer.write("): ");
202 //buffer.write("(" + lineNumber + ":" + columnNumber + "): "); 194 //buffer.write("(" + lineNumber + ":" + columnNumber + "): ");
203 buffer.write(_message); 195 buffer.write(_message);
204 return buffer.toString(); 196 return buffer.toString();
205 } 197 }
206 198
207 /** 199 /**
208 * Merge all of the errors in the lists in the given list of [errorLists] into 200 * Merge all of the errors in the lists in the given list of [errorLists] into
209 * a single list of errors. 201 * a single list of errors.
210 */ 202 */
(...skipping 4759 matching lines...) Expand 10 before | Expand all | Expand 10 after
4970 * Initialize a newly created error code to have the given [name]. 4962 * Initialize a newly created error code to have the given [name].
4971 */ 4963 */
4972 const TodoCode(String name) : super(name, "{0}"); 4964 const TodoCode(String name) : super(name, "{0}");
4973 4965
4974 @override 4966 @override
4975 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; 4967 ErrorSeverity get errorSeverity => ErrorSeverity.INFO;
4976 4968
4977 @override 4969 @override
4978 ErrorType get type => ErrorType.TODO; 4970 ErrorType get type => ErrorType.TODO;
4979 } 4971 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/lib/src/generated/html.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698