OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 import 'dart:async'; | 4 import 'dart:async'; |
5 import 'dart:convert'; | 5 import 'dart:convert'; |
6 import 'dart:io'; | 6 import 'dart:io'; |
7 | 7 |
8 import 'package:front_end/src/base/instrumentation.dart'; | 8 import 'package:front_end/src/base/instrumentation.dart'; |
9 import 'package:front_end/src/fasta/messages.dart'; | 9 import 'package:front_end/src/fasta/messages.dart'; |
10 import 'package:front_end/src/fasta/scanner.dart'; | 10 import 'package:front_end/src/fasta/scanner.dart'; |
11 import 'package:front_end/src/fasta/scanner/io.dart'; | 11 import 'package:front_end/src/fasta/scanner/io.dart'; |
12 import 'package:front_end/src/scanner/token.dart' as analyzer; | 12 import 'package:front_end/src/scanner/token.dart' as analyzer; |
13 | 13 |
14 /// Implementation of [Instrumentation] which checks property/value pairs | 14 /// Implementation of [Instrumentation] which checks property/value pairs |
15 /// against expectations encoded in source files using "/*@...*/" comments. | 15 /// against expectations encoded in source files using "/*@...*/" comments. |
16 class ValidatingInstrumentation implements Instrumentation { | 16 class ValidatingInstrumentation implements Instrumentation { |
17 static final _ESCAPE_SEQUENCE = new RegExp(r'\\(.)'); | 17 static final _ESCAPE_SEQUENCE = new RegExp(r'\\(.)'); |
18 | 18 |
19 /// Map from feature names to the property names they are short for. | 19 /// Map from feature names to the property names they are short for. |
20 static const _FEATURES = const { | 20 static const _FEATURES = const { |
21 'inference': const [ | 21 'inference': const [ |
22 'topType', | 22 'topType', |
23 'typeArg', | 23 'typeArg', |
24 'typeArgs', | 24 'typeArgs', |
25 'promotedType', | 25 'promotedType', |
26 'type', | 26 'type', |
27 'returnType' | 27 'returnType', |
| 28 'target', |
28 ], | 29 ], |
29 }; | 30 }; |
30 | 31 |
31 /// Map from file URI to the as-yet unsatisfied expectations from that file, | 32 /// Map from file URI to the as-yet unsatisfied expectations from that file, |
32 /// organized by file offset. | 33 /// organized by file offset. |
33 final _unsatisfiedExpectations = <Uri, Map<int, List<_Expectation>>>{}; | 34 final _unsatisfiedExpectations = <Uri, Map<int, List<_Expectation>>>{}; |
34 | 35 |
35 /// Information about "testedFeatures" annotations, organized by file URI and | 36 /// Information about "testedFeatures" annotations, organized by file URI and |
36 /// file offset. The inner map is guaranteed to be in ascending order of | 37 /// file offset. The inner map is guaranteed to be in ascending order of |
37 /// file offset. | 38 /// file offset. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 if (_shouldCheck(property, uri, offset)) { | 170 if (_shouldCheck(property, uri, offset)) { |
170 _problemWithStack( | 171 _problemWithStack( |
171 uri, | 172 uri, |
172 offset, | 173 offset, |
173 'expected nothing, got $property=${value.toString()}', | 174 'expected nothing, got $property=${value.toString()}', |
174 new _Fix(offset, 0, _makeExpectationComment(property, value))); | 175 new _Fix(offset, 0, _makeExpectationComment(property, value))); |
175 } | 176 } |
176 } | 177 } |
177 | 178 |
178 String _escape(String s) { | 179 String _escape(String s) { |
179 return s.replaceAll(r'\', r'\\').replaceAll('*/', r'*\/'); | 180 s = s.replaceAll(r'\', r'\\'); |
| 181 if (s.endsWith('/')) { |
| 182 s = '$s '; |
| 183 } |
| 184 return s.replaceAll('/*', r'/\*').replaceAll('*/', r'*\/'); |
180 } | 185 } |
181 | 186 |
182 String _formatProblem( | 187 String _formatProblem( |
183 Uri uri, int offset, String desc, StackTrace stackTrace) { | 188 Uri uri, int offset, String desc, StackTrace stackTrace) { |
184 return format( | 189 return format( |
185 uri, offset, '$desc${stackTrace == null ? '' : '\n$stackTrace'}'); | 190 uri, offset, '$desc${stackTrace == null ? '' : '\n$stackTrace'}'); |
186 } | 191 } |
187 | 192 |
188 String _makeExpectationComment(String property, InstrumentationValue value) { | 193 String _makeExpectationComment(String property, InstrumentationValue value) { |
189 return '/*@$property=${_escape(value.toString())}*/'; | 194 return '/*@$property=${_escape(value.toString())}*/'; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 this.property, this.value, this.commentOffset, this.commentLength); | 227 this.property, this.value, this.commentOffset, this.commentLength); |
223 } | 228 } |
224 | 229 |
225 class _Fix { | 230 class _Fix { |
226 final int offset; | 231 final int offset; |
227 final int length; | 232 final int length; |
228 final String replacement; | 233 final String replacement; |
229 | 234 |
230 _Fix(this.offset, this.length, this.replacement); | 235 _Fix(this.offset, this.length, this.replacement); |
231 } | 236 } |
OLD | NEW |