OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 kernel.transformations.closure.mock; | 5 library kernel.transformations.closure.mock; |
6 | 6 |
7 import '../../ast.dart' | 7 import '../../ast.dart' |
8 show | 8 show |
9 Arguments, | 9 Arguments, |
10 Block, | 10 Block, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 /// } | 61 /// } |
62 /// Context copy() { | 62 /// Context copy() { |
63 /// Context c = new Context(list.length); | 63 /// Context c = new Context(list.length); |
64 /// c.parent = parent; | 64 /// c.parent = parent; |
65 /// c.list.setRange(0, list.length, list); | 65 /// c.list.setRange(0, list.length, list); |
66 /// return c; | 66 /// return c; |
67 /// } | 67 /// } |
68 /// } | 68 /// } |
69 /// | 69 /// |
70 /// Returns the mock. | 70 /// Returns the mock. |
71 Class mockUpContext(CoreTypes coreTypes, Program program) { | 71 Library mockUpContextLibrary(CoreTypes coreTypes) { |
72 String fileUri = "dart:mock"; | 72 String fileUri = "dart:mock"; |
73 | 73 |
74 /// final List list; | 74 /// final List list; |
75 Field listField = new Field(new Name("list"), | 75 Field listField = new Field(new Name("list"), |
76 type: coreTypes.listClass.rawType, isFinal: true, fileUri: fileUri); | 76 type: coreTypes.listClass.rawType, isFinal: true, fileUri: fileUri); |
77 Accessor listFieldAccessor = new ThisPropertyAccessor( | 77 Accessor listFieldAccessor = new ThisPropertyAccessor( |
78 listField.name, listField, null, TreeNode.noOffset); | 78 listField.name, listField, null, TreeNode.noOffset); |
79 | 79 |
80 /// var parent; | 80 /// var parent; |
81 Field parentField = new Field(new Name("parent"), fileUri: fileUri); | 81 Field parentField = new Field(new Name("parent"), fileUri: fileUri); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 Class contextClass = new Class( | 195 Class contextClass = new Class( |
196 name: "Context", | 196 name: "Context", |
197 supertype: new Supertype(coreTypes.objectClass, const <DartType>[]), | 197 supertype: new Supertype(coreTypes.objectClass, const <DartType>[]), |
198 constructors: [constructor], | 198 constructors: [constructor], |
199 fields: fields, | 199 fields: fields, |
200 procedures: procedures, | 200 procedures: procedures, |
201 fileUri: fileUri); | 201 fileUri: fileUri); |
202 Library mock = | 202 Library mock = |
203 new Library(Uri.parse(fileUri), name: "mock", classes: [contextClass]) | 203 new Library(Uri.parse(fileUri), name: "mock", classes: [contextClass]) |
204 ..fileUri = fileUri; | 204 ..fileUri = fileUri; |
| 205 |
| 206 return mock; |
| 207 } |
| 208 |
| 209 Class mockUpContextForLibraries(CoreTypes coreTypes, List<Library> libraries) { |
| 210 Library mock = mockUpContextLibrary(coreTypes); |
| 211 Program parent = libraries.length > 0 ? libraries[0]?.parent : null; |
| 212 libraries.add(mock); |
| 213 mock.parent = parent; |
| 214 parent?.uriToSource[mock.fileUri] = new Source(<int>[0], const <int>[]); |
| 215 return mock.classes[0]; |
| 216 } |
| 217 |
| 218 Class mockUpContextForProgram(CoreTypes coreTypes, Program program) { |
| 219 Library mock = mockUpContextLibrary(coreTypes); |
205 program.libraries.add(mock); | 220 program.libraries.add(mock); |
206 mock.parent = program; | 221 mock.parent = program; |
207 program.uriToSource[mock.fileUri] = new Source(<int>[0], const <int>[]); | 222 program.uriToSource[mock.fileUri] = new Source(<int>[0], const <int>[]); |
208 return contextClass; | 223 return mock.classes[0]; |
209 } | 224 } |
OLD | NEW |