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

Side by Side Diff: pkg/front_end/lib/src/base/instrumentation.dart

Issue 2824393002: Introduce a testing framework for use with fasta type inference. (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:kernel/ast.dart';
6
7 /// Interface providing the ability to record property/value pairs associated
8 /// with source file locations. Intended to facilitate testing.
9 abstract class Instrumentation {
10 /// Records a property/value pair associated with the given URI and offset.
11 void record(String property, Uri uri, int offset, InstrumentationValue value);
12 }
13
14 /// Interface for values recorded by [Instrumentation].
15 abstract class InstrumentationValue {
16 const InstrumentationValue();
17
18 /// Converts the value to the string representation most suitable for
19 /// storing as an annotation in a source file.
20 ///
21 /// Invariant: `this.matches(this.canonicalize())` should always return
22 /// `true`.
23 String canonicalize();
ahe 2017/04/19 11:38:29 Is this a potential gotcha? Perhaps we should just
Paul Berry 2017/04/19 13:20:09 Good point. Fixed.
24
25 /// Checks if the given String is an accurate description of this value.
26 ///
27 /// The default implementation just checks for equality with the return value
28 /// of [canonicalize], however derived classes may want a more sophisticated
29 /// implementation (e.g. to allow abbreviations in the description).
30 ///
31 /// Derived classes should ensure that the invariant holds:
32 /// `this.matches(this.canonicalize())` should always return `true`.
33 bool matches(String description) => description == canonicalize();
34 }
35
36 /// Instance of [InstrumentationValue] describing a [DartType].
37 class InstrumentationValueForType extends InstrumentationValue {
38 final DartType type;
39
40 InstrumentationValueForType(this.type);
41
42 @override
43 String canonicalize() {
44 // Convert '→' to '->' because '→' doesn't show up in some terminals.
45 return type.toString().replaceAll('→', '->');
46 }
47 }
48
49 /// Instance of [InstrumentationValue] which only matches the given literal
50 /// string.
51 class InstrumentationValueLiteral extends InstrumentationValue {
52 final String value;
53
54 const InstrumentationValueLiteral(this.value);
55
56 @override
57 String canonicalize() => value;
58 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698