OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013, 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 "mock_compiler.dart"; |
| 6 |
| 7 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar
t" |
| 8 show Element, FunctionElement; |
| 9 import "../../../sdk/lib/_internal/compiler/implementation/patch_parser.dart"; |
| 10 import "../../../sdk/lib/_internal/compiler/implementation/scanner/scannerlib.da
rt" |
| 11 show StringScanner; |
| 12 import "../../../sdk/lib/_internal/compiler/implementation/util/util.dart"; |
| 13 |
| 14 class TestPatchElementListener extends PatchElementListener { |
| 15 TestPatchElementListener(compiler, unit) |
| 16 : super(compiler, unit, compiler.getNextFreeClassId, new LinkBuilder()); |
| 17 |
| 18 void applyPatch(Element patch) { |
| 19 } |
| 20 } |
| 21 |
| 22 Element buildElement(MockCompiler compiler, String source) { |
| 23 var library = compiler.createLibrary('origin', 'external foo();'); |
| 24 var elements = library.localMembers.toList(); |
| 25 Expect.equals(1, elements.length); |
| 26 return elements[0]; |
| 27 } |
| 28 |
| 29 Element buildPatchElement(MockCompiler compiler, String source) { |
| 30 var library = compiler.createUnparsedLibrary('patch', source); |
| 31 var unit = library.entryCompilationUnit; |
| 32 |
| 33 var tokens = new StringScanner(source).tokenize(); |
| 34 var listener = new TestPatchElementListener(compiler, unit); |
| 35 new PatchParser(listener).parseUnit(tokens); |
| 36 |
| 37 var elements = unit.localMembers.toList(); |
| 38 Expect.equals(1, elements.length); |
| 39 Expect.isTrue(isPatchElement(elements[0])); |
| 40 return elements[0]; |
| 41 } |
| 42 |
| 43 main() { |
| 44 MockCompiler compiler = new MockCompiler(); |
| 45 FunctionElement foo = buildElement(compiler, 'external foo();'); |
| 46 FunctionElement fooPatch = buildPatchElement(compiler, 'patch foo() {}'); |
| 47 patchElement(null, foo, fooPatch); |
| 48 } |
OLD | NEW |