| OLD | NEW |
| 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 library engine.incremental_resolver_test; | 5 library engine.incremental_resolver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/ast.dart'; | 7 import 'package:analyzer/src/generated/ast.dart'; |
| 8 import 'package:analyzer/src/generated/element.dart'; | 8 import 'package:analyzer/src/generated/element.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
| (...skipping 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2110 code.substring(offset + edit.length); | 2110 code.substring(offset + edit.length); |
| 2111 CompilationUnit newUnit = _parseUnit(newCode); | 2111 CompilationUnit newUnit = _parseUnit(newCode); |
| 2112 // update tokens | 2112 // update tokens |
| 2113 { | 2113 { |
| 2114 int delta = edit.replacement.length - edit.length; | 2114 int delta = edit.replacement.length - edit.length; |
| 2115 _shiftTokens(unit.beginToken, offset, delta); | 2115 _shiftTokens(unit.beginToken, offset, delta); |
| 2116 } | 2116 } |
| 2117 // replace the node | 2117 // replace the node |
| 2118 AstNode oldNode = _findNodeAt(unit, offset, predicate); | 2118 AstNode oldNode = _findNodeAt(unit, offset, predicate); |
| 2119 AstNode newNode = _findNodeAt(newUnit, offset, predicate); | 2119 AstNode newNode = _findNodeAt(newUnit, offset, predicate); |
| 2120 bool success = NodeReplacer.replace(oldNode, newNode); | 2120 { |
| 2121 expect(success, isTrue); | 2121 bool success = NodeReplacer.replace(oldNode, newNode); |
| 2122 expect(success, isTrue); |
| 2123 } |
| 2122 // do incremental resolution | 2124 // do incremental resolution |
| 2123 IncrementalResolver resolver = new IncrementalResolver( | 2125 IncrementalResolver resolver = new IncrementalResolver( |
| 2124 typeProvider, | 2126 typeProvider, |
| 2125 unit.element, | 2127 unit.element, |
| 2126 edit.offset, | 2128 edit.offset, |
| 2127 edit.length, | 2129 edit.length, |
| 2128 edit.replacement.length); | 2130 edit.replacement.length); |
| 2129 resolver.resolve(newNode); | 2131 bool success = resolver.resolve(newNode); |
| 2132 expect(success, isTrue); |
| 2130 // resolve "newCode" from scratch | 2133 // resolve "newCode" from scratch |
| 2131 CompilationUnit fullNewUnit; | 2134 CompilationUnit fullNewUnit; |
| 2132 { | 2135 { |
| 2133 source = addSource(newCode); | 2136 source = addSource(newCode); |
| 2134 LibraryElement library = resolve(source); | 2137 LibraryElement library = resolve(source); |
| 2135 fullNewUnit = resolveCompilationUnit(source, library); | 2138 fullNewUnit = resolveCompilationUnit(source, library); |
| 2136 } | 2139 } |
| 2137 _SameResolutionValidator.assertSameResolution(unit, fullNewUnit); | 2140 _SameResolutionValidator.assertSameResolution(unit, fullNewUnit); |
| 2138 } | 2141 } |
| 2139 | 2142 |
| (...skipping 1828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3968 _visitList(node.metadata, other.metadata); | 3971 _visitList(node.metadata, other.metadata); |
| 3969 _visitNode(node.identifier, other.identifier); | 3972 _visitNode(node.identifier, other.identifier); |
| 3970 } | 3973 } |
| 3971 | 3974 |
| 3972 static void assertSameResolution(CompilationUnit actual, | 3975 static void assertSameResolution(CompilationUnit actual, |
| 3973 CompilationUnit expected) { | 3976 CompilationUnit expected) { |
| 3974 _SameResolutionValidator validator = new _SameResolutionValidator(expected); | 3977 _SameResolutionValidator validator = new _SameResolutionValidator(expected); |
| 3975 actual.accept(validator); | 3978 actual.accept(validator); |
| 3976 } | 3979 } |
| 3977 } | 3980 } |
| OLD | NEW |