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

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

Issue 712083003: Create fewer unnecessary lists (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
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 import 'java_core.dart'; 8 import 'java_core.dart';
9 import 'source.dart'; 9 import 'source.dart';
10 import 'scanner.dart' show Token; 10 import 'scanner.dart' show Token;
11 import 'ast.dart' show AstNode; 11 import 'ast.dart' show AstNode;
12 import 'element.dart'; 12 import 'element.dart';
13 13
14 /** 14 /**
15 * Instances of the class `AnalysisError` represent an error discovered during t he analysis of 15 * Instances of the class `AnalysisError` represent an error discovered during t he analysis of
16 * some Dart code. 16 * some Dart code.
17 * 17 *
18 * See [AnalysisErrorListener]. 18 * See [AnalysisErrorListener].
19 */ 19 */
20 class AnalysisError { 20 class AnalysisError {
21 /** 21 /**
22 * An empty array of errors used when no errors are expected. 22 * An empty array of errors used when no errors are expected.
23 */ 23 */
24 static List<AnalysisError> NO_ERRORS = new List<AnalysisError>(0); 24 static const List<AnalysisError> NO_ERRORS = const <AnalysisError>[];
25 25
26 /** 26 /**
27 * A [Comparator] that sorts by the name of the file that the [AnalysisError] was 27 * A [Comparator] that sorts by the name of the file that the [AnalysisError] was
28 * found. 28 * found.
29 */ 29 */
30 static Comparator<AnalysisError> FILE_COMPARATOR = (AnalysisError o1, Analysis Error o2) => o1.source.shortName.compareTo(o2.source.shortName); 30 static Comparator<AnalysisError> FILE_COMPARATOR = (AnalysisError o1, Analysis Error o2) => o1.source.shortName.compareTo(o2.source.shortName);
31 31
32 /** 32 /**
33 * A [Comparator] that sorts error codes first by their severity (errors first , warnings 33 * A [Comparator] that sorts error codes first by their severity (errors first , warnings
34 * second), and then by the the error code type. 34 * second), and then by the the error code type.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 bool isStaticOnly = false; 86 bool isStaticOnly = false;
87 87
88 /** 88 /**
89 * Initialize a newly created analysis error for the specified source. The err or has no location 89 * Initialize a newly created analysis error for the specified source. The err or has no location
90 * information. 90 * information.
91 * 91 *
92 * @param source the source for which the exception occurred 92 * @param source the source for which the exception occurred
93 * @param errorCode the error code to be associated with this error 93 * @param errorCode the error code to be associated with this error
94 * @param arguments the arguments used to build the error message 94 * @param arguments the arguments used to build the error message
95 */ 95 */
96 AnalysisError.con1(this.source, this.errorCode, List<Object> arguments) { 96 AnalysisError.con1(this.source, this.errorCode, [List<Object> arguments]) {
97 this._message = formatList(errorCode.message, arguments); 97 this._message = formatList(errorCode.message, arguments);
98 } 98 }
99 99
100 /** 100 /**
101 * Initialize a newly created analysis error for the specified source at the g iven location. 101 * Initialize a newly created analysis error for the specified source at the g iven location.
102 * 102 *
103 * @param source the source for which the exception occurred 103 * @param source the source for which the exception occurred
104 * @param offset the offset of the location of the error 104 * @param offset the offset of the location of the error
105 * @param length the length of the location of the error 105 * @param length the length of the location of the error
106 * @param errorCode the error code to be associated with this error 106 * @param errorCode the error code to be associated with this error
107 * @param arguments the arguments used to build the error message 107 * @param arguments the arguments used to build the error message
108 */ 108 */
109 AnalysisError.con2(this.source, int offset, int length, this.errorCode, List<O bject> arguments) { 109 AnalysisError.con2(this.source, int offset, int length, this.errorCode, [List< Object> arguments]) {
110 this._offset = offset; 110 this._offset = offset;
111 this._length = length; 111 this._length = length;
112 this._message = formatList(errorCode.message, arguments); 112 this._message = formatList(errorCode.message, arguments);
113 String correctionTemplate = errorCode.correction; 113 String correctionTemplate = errorCode.correction;
114 if (correctionTemplate != null) { 114 if (correctionTemplate != null) {
115 this._correction = formatList(correctionTemplate, arguments); 115 this._correction = formatList(correctionTemplate, arguments);
116 } 116 }
117 } 117 }
118 118
119 @override 119 @override
(...skipping 1917 matching lines...) Expand 10 before | Expand all | Expand 10 after
2037 final String message; 2037 final String message;
2038 2038
2039 /** 2039 /**
2040 * The template used to create the correction to be displayed for this error, 2040 * The template used to create the correction to be displayed for this error,
2041 * or `null` if there is no correction information for this error. The 2041 * or `null` if there is no correction information for this error. The
2042 * correction should indicate how the user can fix the error. 2042 * correction should indicate how the user can fix the error.
2043 */ 2043 */
2044 final String correction; 2044 final String correction;
2045 2045
2046 /** 2046 /**
2047 * An empty list of error codes.
2048 */
2049 static const List<ErrorCode> EMPTY_LIST = const <ErrorCode>[];
2050
2051 /**
2047 * Initialize a newly created error code to have the given [name]. The message 2052 * Initialize a newly created error code to have the given [name]. The message
2048 * associated with the error will be created from the given [message] 2053 * associated with the error will be created from the given [message]
2049 * template. The correction associated with the error will be created from the 2054 * template. The correction associated with the error will be created from the
2050 * given [correction] template. 2055 * given [correction] template.
2051 */ 2056 */
2052 const ErrorCode(this.name, this.message, [this.correction]); 2057 const ErrorCode(this.name, this.message, [this.correction]);
2053 2058
2054 /** 2059 /**
2055 * The severity of the error. 2060 * The severity of the error.
2056 */ 2061 */
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
2153 * Report an error with the given error code and arguments. 2158 * Report an error with the given error code and arguments.
2154 * 2159 *
2155 * If the arguments contain the names of two or more types, the method 2160 * If the arguments contain the names of two or more types, the method
2156 * [reportTypeErrorForNode] should be used and the types 2161 * [reportTypeErrorForNode] should be used and the types
2157 * themselves (rather than their names) should be passed as arguments. 2162 * themselves (rather than their names) should be passed as arguments.
2158 * 2163 *
2159 * @param errorCode the error code of the error to be reported 2164 * @param errorCode the error code of the error to be reported
2160 * @param node the node specifying the location of the error 2165 * @param node the node specifying the location of the error
2161 * @param arguments the arguments to the error, used to compose the error mess age 2166 * @param arguments the arguments to the error, used to compose the error mess age
2162 */ 2167 */
2163 void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> argume nts) { 2168 void reportErrorForNode(ErrorCode errorCode, AstNode node, [List<Object> argum ents]) {
2164 reportErrorForOffset(errorCode, node.offset, node.length, arguments); 2169 reportErrorForOffset(errorCode, node.offset, node.length, arguments);
2165 } 2170 }
2166 2171
2167 /** 2172 /**
2168 * Report an error with the given error code and arguments. 2173 * Report an error with the given error code and arguments.
2169 * 2174 *
2170 * @param errorCode the error code of the error to be reported 2175 * @param errorCode the error code of the error to be reported
2171 * @param offset the offset of the location of the error 2176 * @param offset the offset of the location of the error
2172 * @param length the length of the location of the error 2177 * @param length the length of the location of the error
2173 * @param arguments the arguments to the error, used to compose the error mess age 2178 * @param arguments the arguments to the error, used to compose the error mess age
2174 */ 2179 */
2175 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Ob ject> arguments) { 2180 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, [List<O bject> arguments]) {
2176 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error Code, arguments)); 2181 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error Code, arguments));
2177 } 2182 }
2178 2183
2179 /** 2184 /**
2180 * Report an error with the given error code and arguments. 2185 * Report an error with the given error code and arguments.
2181 * 2186 *
2182 * @param errorCode the error code of the error to be reported 2187 * @param errorCode the error code of the error to be reported
2183 * @param token the token specifying the location of the error 2188 * @param token the token specifying the location of the error
2184 * @param arguments the arguments to the error, used to compose the error mess age 2189 * @param arguments the arguments to the error, used to compose the error mess age
2185 */ 2190 */
2186 void reportErrorForToken(ErrorCode errorCode, Token token, List<Object> argume nts) { 2191 void reportErrorForToken(ErrorCode errorCode, Token token, [List<Object> argum ents]) {
2187 reportErrorForOffset(errorCode, token.offset, token.length, arguments); 2192 reportErrorForOffset(errorCode, token.offset, token.length, arguments);
2188 } 2193 }
2189 2194
2190 /** 2195 /**
2191 * Report an error with the given error code and arguments. The arguments are expected to contain 2196 * Report an error with the given error code and arguments. The arguments are expected to contain
2192 * two or more types. Convert the types into strings by using the display name s of the types, 2197 * two or more types. Convert the types into strings by using the display name s of the types,
2193 * unless there are two or more types with the same names, in which case the e xtended display 2198 * unless there are two or more types with the same names, in which case the e xtended display
2194 * names of the types will be used in order to clarify the message. 2199 * names of the types will be used in order to clarify the message.
2195 * 2200 *
2196 * If there are not two or more types in the argument list, the method 2201 * If there are not two or more types in the argument list, the method
(...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after
4051 * Initialize a newly created error code to have the given [name]. 4056 * Initialize a newly created error code to have the given [name].
4052 */ 4057 */
4053 const TodoCode(String name) : super(name, "{0}"); 4058 const TodoCode(String name) : super(name, "{0}");
4054 4059
4055 @override 4060 @override
4056 ErrorSeverity get errorSeverity => ErrorSeverity.INFO; 4061 ErrorSeverity get errorSeverity => ErrorSeverity.INFO;
4057 4062
4058 @override 4063 @override
4059 ErrorType get type => ErrorType.TODO; 4064 ErrorType get type => ErrorType.TODO;
4060 } 4065 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/lib/src/generated/error_verifier.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698