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

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

Issue 628053002: Create a NullErrorReporter to use when errors don't need to be recorded. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 | 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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.error; 8 library engine.error;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 2102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 2113
2114 static const List<ErrorProperty> values = const [UNIMPLEMENTED_METHODS]; 2114 static const List<ErrorProperty> values = const [UNIMPLEMENTED_METHODS];
2115 2115
2116 const ErrorProperty(String name, int ordinal) : super(name, ordinal); 2116 const ErrorProperty(String name, int ordinal) : super(name, ordinal);
2117 } 2117 }
2118 2118
2119 /** 2119 /**
2120 * Instances of the class `ErrorReporter` wrap an error listener with utility me thods used to 2120 * Instances of the class `ErrorReporter` wrap an error listener with utility me thods used to
2121 * create the errors being reported. 2121 * create the errors being reported.
2122 */ 2122 */
2123 class ErrorReporter { 2123 abstract class ErrorReporter {
Brian Wilkerson 2014/10/06 14:10:08 I'm not sure why we needed to make this an abstrac
Paul Berry 2014/10/06 16:44:39 Since NullErrorReporter is in the same library as
2124 /** 2124 /**
2125 * The error listener to which errors will be reported. 2125 * The source used when reporting errors.
2126 */ 2126 */
2127 final AnalysisErrorListener _errorListener; 2127 Source get source;
2128
2129 /**
2130 * The default source to be used when reporting errors.
2131 */
2132 final Source _defaultSource;
2133
2134 /**
2135 * The source to be used when reporting errors.
2136 */
2137 Source _source;
2138
2139 /**
2140 * Initialize a newly created error reporter that will report errors to the gi ven listener.
2141 *
2142 * @param errorListener the error listener to which errors will be reported
2143 * @param defaultSource the default source to be used when reporting errors
2144 */
2145 ErrorReporter(this._errorListener, this._defaultSource) {
2146 if (_errorListener == null) {
2147 throw new IllegalArgumentException("An error listener must be provided");
2148 } else if (_defaultSource == null) {
2149 throw new IllegalArgumentException("A default source must be provided");
2150 }
2151 this._source = _defaultSource;
2152 }
2153
2154 Source get source => _source;
2155 2128
2156 /** 2129 /**
2157 * Creates an error with properties with the given error code and arguments. 2130 * Creates an error with properties with the given error code and arguments.
2158 * 2131 *
2159 * @param errorCode the error code of the error to be reported 2132 * @param errorCode the error code of the error to be reported
2160 * @param node the node specifying the location of the error 2133 * @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 2134 * @param arguments the arguments to the error, used to compose the error mess age
2162 */ 2135 */
2163 AnalysisErrorWithProperties newErrorWithProperties(ErrorCode errorCode, AstNod e node, List<Object> arguments) => new AnalysisErrorWithProperties.con2(_source, node.offset, node.length, errorCode, arguments); 2136 AnalysisErrorWithProperties newErrorWithProperties(ErrorCode errorCode, AstNod e node, List<Object> arguments);
2164 2137
2165 /** 2138 /**
2166 * Report a passed error. 2139 * Report a passed error.
2167 * 2140 *
2168 * @param error the error to report 2141 * @param error the error to report
2169 */ 2142 */
2170 void reportError(AnalysisError error) { 2143 void reportError(AnalysisError error);
2171 _errorListener.onError(error);
2172 }
2173 2144
2174 /** 2145 /**
2175 * Report an error with the given error code and arguments. 2146 * Report an error with the given error code and arguments.
2176 * 2147 *
2177 * @param errorCode the error code of the error to be reported 2148 * @param errorCode the error code of the error to be reported
2178 * @param element the element which name should be used as the location of the error 2149 * @param element the element which name should be used as the location of the error
2179 * @param arguments the arguments to the error, used to compose the error mess age 2150 * @param arguments the arguments to the error, used to compose the error mess age
2180 */ 2151 */
2181 void reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments) { 2152 void reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments);
2182 reportErrorForOffset(errorCode, element.nameOffset, element.displayName.leng th, arguments);
2183 }
2184 2153
2185 /** 2154 /**
2186 * Report an error with the given error code and arguments. 2155 * Report an error with the given error code and arguments.
2187 * 2156 *
2188 * If the arguments contain the names of two or more types, the method 2157 * If the arguments contain the names of two or more types, the method
2189 * [reportTypeErrorForNode] should be used and the types 2158 * [reportTypeErrorForNode] should be used and the types
2190 * themselves (rather than their names) should be passed as arguments. 2159 * themselves (rather than their names) should be passed as arguments.
2191 * 2160 *
2192 * @param errorCode the error code of the error to be reported 2161 * @param errorCode the error code of the error to be reported
2193 * @param node the node specifying the location of the error 2162 * @param node the node specifying the location of the error
2194 * @param arguments the arguments to the error, used to compose the error mess age 2163 * @param arguments the arguments to the error, used to compose the error mess age
2195 */ 2164 */
2196 void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> argume nts) { 2165 void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> argume nts);
2197 reportErrorForOffset(errorCode, node.offset, node.length, arguments);
2198 }
2199 2166
2200 /** 2167 /**
2201 * Report an error with the given error code and arguments. 2168 * Report an error with the given error code and arguments.
2202 * 2169 *
2203 * @param errorCode the error code of the error to be reported 2170 * @param errorCode the error code of the error to be reported
2204 * @param offset the offset of the location of the error 2171 * @param offset the offset of the location of the error
2205 * @param length the length of the location of the error 2172 * @param length the length of the location of the error
2206 * @param arguments the arguments to the error, used to compose the error mess age 2173 * @param arguments the arguments to the error, used to compose the error mess age
2207 */ 2174 */
2208 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Ob ject> arguments) { 2175 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Ob ject> arguments);
2209 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error Code, arguments));
2210 }
2211 2176
2212 /** 2177 /**
2213 * Report an error with the given error code and arguments. 2178 * Report an error with the given error code and arguments.
2214 * 2179 *
2215 * @param errorCode the error code of the error to be reported 2180 * @param errorCode the error code of the error to be reported
2216 * @param token the token specifying the location of the error 2181 * @param token the token specifying the location of the error
2217 * @param arguments the arguments to the error, used to compose the error mess age 2182 * @param arguments the arguments to the error, used to compose the error mess age
2218 */ 2183 */
2219 void reportErrorForToken(ErrorCode errorCode, Token token, List<Object> argume nts) { 2184 void reportErrorForToken(ErrorCode errorCode, Token token, List<Object> argume nts);
2220 reportErrorForOffset(errorCode, token.offset, token.length, arguments);
2221 }
2222 2185
2223 /** 2186 /**
2224 * Report an error with the given error code and arguments. The arguments are expected to contain 2187 * Report an error with the given error code and arguments. The arguments are expected to contain
2225 * two or more types. Convert the types into strings by using the display name s of the types, 2188 * two or more types. Convert the types into strings by using the display name s of the types,
2226 * unless there are two or more types with the same names, in which case the e xtended display 2189 * unless there are two or more types with the same names, in which case the e xtended display
2227 * names of the types will be used in order to clarify the message. 2190 * names of the types will be used in order to clarify the message.
2228 * 2191 *
2229 * If there are not two or more types in the argument list, the method 2192 * If there are not two or more types in the argument list, the method
2230 * [reportErrorForNode] should be used instead. 2193 * [reportErrorForNode] should be used instead.
2231 * 2194 *
2232 * @param errorCode the error code of the error to be reported 2195 * @param errorCode the error code of the error to be reported
2233 * @param node the node specifying the location of the error 2196 * @param node the node specifying the location of the error
2234 * @param arguments the arguments to the error, used to compose the error mess age 2197 * @param arguments the arguments to the error, used to compose the error mess age
2235 */ 2198 */
2236 void reportTypeErrorForNode(ErrorCode errorCode, AstNode node, List<Object> ar guments) { 2199 void reportTypeErrorForNode(ErrorCode errorCode, AstNode node, List<Object> ar guments);
2237 _convertTypeNames(arguments);
2238 reportErrorForOffset(errorCode, node.offset, node.length, arguments);
2239 }
2240 2200
2241 /** 2201 /**
2242 * Set the source to be used when reporting errors. Setting the source to `nul l` will cause 2202 * Set the source to be used when reporting errors. Setting the source to `nul l` will cause
2243 * the default source to be used. 2203 * the default source to be used.
2244 * 2204 *
2245 * @param source the source to be used when reporting errors 2205 * @param source the source to be used when reporting errors
2246 */ 2206 */
2207 void set source(Source source);
2208 }
2209
2210 class ErrorReporterImpl implements ErrorReporter {
2211 /**
2212 * The error listener to which errors will be reported.
2213 */
2214 final AnalysisErrorListener _errorListener;
2215
2216 /**
2217 * The default source to be used when reporting errors.
2218 */
2219 final Source _defaultSource;
2220
2221 /**
2222 * The source to be used when reporting errors.
2223 */
2224 Source _source;
2225
2226 /**
2227 * Initialize a newly created error reporter that will report errors to the gi ven listener.
2228 *
2229 * @param errorListener the error listener to which errors will be reported
2230 * @param defaultSource the default source to be used when reporting errors
2231 */
2232 ErrorReporterImpl(this._errorListener, this._defaultSource) {
2233 if (_errorListener == null) {
2234 throw new IllegalArgumentException("An error listener must be provided");
2235 } else if (_defaultSource == null) {
2236 throw new IllegalArgumentException("A default source must be provided");
2237 }
2238 this._source = _defaultSource;
2239 }
2240
2241 @override
2242 Source get source => _source;
2243
2244 @override
2245 AnalysisErrorWithProperties newErrorWithProperties(ErrorCode errorCode, AstNod e node, List<Object> arguments) => new AnalysisErrorWithProperties.con2(_source, node.offset, node.length, errorCode, arguments);
2246
2247 @override
2248 void reportError(AnalysisError error) {
2249 _errorListener.onError(error);
2250 }
2251
2252 @override
2253 void reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments) {
2254 reportErrorForOffset(errorCode, element.nameOffset, element.displayName.leng th, arguments);
2255 }
2256
2257 @override
2258 void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> argume nts) {
2259 reportErrorForOffset(errorCode, node.offset, node.length, arguments);
2260 }
2261
2262 @override
2263 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Ob ject> arguments) {
2264 _errorListener.onError(new AnalysisError.con2(_source, offset, length, error Code, arguments));
2265 }
2266
2267 @override
2268 void reportErrorForToken(ErrorCode errorCode, Token token, List<Object> argume nts) {
2269 reportErrorForOffset(errorCode, token.offset, token.length, arguments);
2270 }
2271
2272 @override
2273 void reportTypeErrorForNode(ErrorCode errorCode, AstNode node, List<Object> ar guments) {
2274 _convertTypeNames(arguments);
2275 reportErrorForOffset(errorCode, node.offset, node.length, arguments);
2276 }
2277
2278 @override
2247 void set source(Source source) { 2279 void set source(Source source) {
2248 this._source = source == null ? _defaultSource : source; 2280 this._source = source == null ? _defaultSource : source;
2249 } 2281 }
2250 2282
2251 /** 2283 /**
2252 * Given an array of arguments that is expected to contain two or more types, convert the types 2284 * Given an array of arguments that is expected to contain two or more types, convert the types
2253 * into strings by using the display names of the types, unless there are two or more types with 2285 * into strings by using the display names of the types, unless there are two or more types with
2254 * the same names, in which case the extended display names of the types will be used in order to 2286 * the same names, in which case the extended display names of the types will be used in order to
2255 * clarify the message. 2287 * clarify the message.
2256 * 2288 *
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
2767 @override 2799 @override
2768 ErrorSeverity get errorSeverity => ErrorSeverity.WARNING; 2800 ErrorSeverity get errorSeverity => ErrorSeverity.WARNING;
2769 2801
2770 @override 2802 @override
2771 ErrorType get type => ErrorType.STATIC_WARNING; 2803 ErrorType get type => ErrorType.STATIC_WARNING;
2772 2804
2773 @override 2805 @override
2774 String get uniqueName => "${runtimeType.toString()}.${name}"; 2806 String get uniqueName => "${runtimeType.toString()}.${name}";
2775 } 2807 }
2776 2808
2809
2810 /**
2811 * The class [NullErrorReporter] presents the same interface as [ErrorReporter]
2812 * but discards all error information.
2813 */
2814 class NullErrorReporter implements ErrorReporter {
2815 /**
2816 * The default source to be used when reporting errors.
2817 */
2818 final Source _defaultSource;
2819
2820 /**
2821 * The source to be used when reporting errors.
2822 */
2823 Source _source;
2824
2825 NullErrorReporter(this._defaultSource) {
2826 _source = _defaultSource;
2827 }
2828
2829 @override
2830 AnalysisErrorWithProperties newErrorWithProperties(ErrorCode errorCode, AstNod e node, List<Object> arguments) {
2831 return new AnalysisErrorWithProperties.con2(_source, node.offset, node.lengt h, errorCode, arguments);
2832 }
2833
2834 @override
2835 void reportError(AnalysisError error) {
2836 }
2837
2838 @override
2839 void reportErrorForElement(ErrorCode errorCode, Element element, List<Object> arguments) {
2840 }
2841
2842 @override
2843 void reportErrorForNode(ErrorCode errorCode, AstNode node, List<Object> argume nts) {
2844 }
2845
2846 @override
2847 void reportErrorForOffset(ErrorCode errorCode, int offset, int length, List<Ob ject> arguments) {
2848 }
2849
2850 @override
2851 void reportErrorForToken(ErrorCode errorCode, Token token, List<Object> argume nts) {
2852 }
2853
2854 @override
2855 void reportTypeErrorForNode(ErrorCode errorCode, AstNode node, List<Object> ar guments) {
2856 }
2857
2858 @override
2859 void set source(Source source) {
2860 this._source = source == null ? _defaultSource : source;
2861 }
2862
2863 @override
2864 Source get source => _source;
2865 }
2866
2867
2777 /** 2868 /**
2778 * The enumeration `PolymerCode` defines Polymer specific problems. 2869 * The enumeration `PolymerCode` defines Polymer specific problems.
2779 */ 2870 */
2780 class PolymerCode extends Enum<PolymerCode> implements ErrorCode { 2871 class PolymerCode extends Enum<PolymerCode> implements ErrorCode {
2781 static const PolymerCode ATTRIBUTE_FIELD_NOT_PUBLISHED = const PolymerCode('AT TRIBUTE_FIELD_NOT_PUBLISHED', 0, "Field '{0}' in '{1}' must be @published"); 2872 static const PolymerCode ATTRIBUTE_FIELD_NOT_PUBLISHED = const PolymerCode('AT TRIBUTE_FIELD_NOT_PUBLISHED', 0, "Field '{0}' in '{1}' must be @published");
2782 2873
2783 static const PolymerCode DUPLICATE_ATTRIBUTE_DEFINITION = const PolymerCode('D UPLICATE_ATTRIBUTE_DEFINITION', 1, "The attribute '{0}' is already defined"); 2874 static const PolymerCode DUPLICATE_ATTRIBUTE_DEFINITION = const PolymerCode('D UPLICATE_ATTRIBUTE_DEFINITION', 1, "The attribute '{0}' is already defined");
2784 2875
2785 static const PolymerCode EMPTY_ATTRIBUTES = const PolymerCode('EMPTY_ATTRIBUTE S', 2, "Empty 'attributes' attribute is useless"); 2876 static const PolymerCode EMPTY_ATTRIBUTES = const PolymerCode('EMPTY_ATTRIBUTE S', 2, "Empty 'attributes' attribute is useless");
2786 2877
(...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after
4224 4315
4225 @override 4316 @override
4226 String get message => "{0}"; 4317 String get message => "{0}";
4227 4318
4228 @override 4319 @override
4229 ErrorType get type => ErrorType.TODO; 4320 ErrorType get type => ErrorType.TODO;
4230 4321
4231 @override 4322 @override
4232 String get uniqueName => "${runtimeType.toString()}.${name}"; 4323 String get uniqueName => "${runtimeType.toString()}.${name}";
4233 } 4324 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/engine.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698