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

Side by Side Diff: pkg/analyzer/test/generated/incremental_resolver_test.dart

Issue 770333003: First step to resolving simple API changes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | Annotate | Revision Log
OLDNEW
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 1637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 class A { 1648 class A {
1649 operator +(other) {} 1649 operator +(other) {}
1650 } 1650 }
1651 ''', r''' 1651 ''', r'''
1652 class A { 1652 class A {
1653 operator +(other) {} 1653 operator +(other) {}
1654 } 1654 }
1655 '''); 1655 ''');
1656 } 1656 }
1657 1657
1658 void test_true_method_parameters_type_functionType() {
1659 _assertMatches(r'''
1660 typedef F();
1661 class A {
1662 m(F p) {}
1663 }
1664 ''', r'''
1665 typedef F();
1666 class A {
1667 m(F p) {}
1668 }
1669 ''');
1670 }
1671
1658 void test_true_part_list_reorder() { 1672 void test_true_part_list_reorder() {
1659 addNamedSource('/unitA.dart', 'part of lib; class A {}'); 1673 addNamedSource('/unitA.dart', 'part of lib; class A {}');
1660 addNamedSource('/unitB.dart', 'part of lib; class B {}'); 1674 addNamedSource('/unitB.dart', 'part of lib; class B {}');
1661 _assertMatches(r''' 1675 _assertMatches(r'''
1662 library lib; 1676 library lib;
1663 part 'unitA.dart'; 1677 part 'unitA.dart';
1664 part 'unitB.dart'; 1678 part 'unitB.dart';
1665 ''', r''' 1679 ''', r'''
1666 library lib; 1680 library lib;
1667 part 'unitB.dart'; 1681 part 'unitB.dart';
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 } 1887 }
1874 } 1888 }
1875 1889
1876 1890
1877 class IncrementalResolverTest extends ResolverTestCase { 1891 class IncrementalResolverTest extends ResolverTestCase {
1878 Source source; 1892 Source source;
1879 String code; 1893 String code;
1880 LibraryElement library; 1894 LibraryElement library;
1881 CompilationUnit unit; 1895 CompilationUnit unit;
1882 1896
1897 void setUp() {
1898 super.setUp();
1899 test_resolveApiChanges = true;
1900 }
1901
1902 void test_api_method_edit_returnType() {
1903 _resolveUnit(r'''
1904 class A {
1905 int m() {
1906 return null;
1907 }
1908 }
1909 main() {
1910 A a = new A();
1911 var v = a.m();
1912 }
1913 ''');
1914 _resolve(_editString('int m', 'String m'), _isDeclaration);
1915 // We don't add or fix an error, but we verify that type of "v"
1916 // is updated from "int" to "String".
1917 }
1918
1883 void test_classMemberAccessor_body() { 1919 void test_classMemberAccessor_body() {
1884 _resolveUnit(r''' 1920 _resolveUnit(r'''
1885 class A { 1921 class A {
1886 int get test { 1922 int get test {
1887 return 1 + 2; 1923 return 1 + 2;
1888 } 1924 }
1889 }'''); 1925 }''');
1890 _resolve(_editString('+', '*'), _isFunctionBody); 1926 _resolve(_editString('+', '*'), _isFunctionBody);
1891 } 1927 }
1892 1928
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
2165 * the incremental resolution and non-incremental resolutions are the same. 2201 * the incremental resolution and non-incremental resolutions are the same.
2166 */ 2202 */
2167 void _resolve(_Edit edit, Predicate<AstNode> predicate) { 2203 void _resolve(_Edit edit, Predicate<AstNode> predicate) {
2168 int offset = edit.offset; 2204 int offset = edit.offset;
2169 // parse "newCode" 2205 // parse "newCode"
2170 String newCode = 2206 String newCode =
2171 code.substring(0, offset) + 2207 code.substring(0, offset) +
2172 edit.replacement + 2208 edit.replacement +
2173 code.substring(offset + edit.length); 2209 code.substring(offset + edit.length);
2174 CompilationUnit newUnit = _parseUnit(newCode); 2210 CompilationUnit newUnit = _parseUnit(newCode);
2175 // update tokens
2176 {
2177 int delta = edit.replacement.length - edit.length;
2178 _shiftTokens(unit.beginToken, offset, delta);
2179 }
2180 // replace the node 2211 // replace the node
2181 AstNode oldNode = _findNodeAt(unit, offset, predicate); 2212 AstNode oldNode = _findNodeAt(unit, offset, predicate);
2182 AstNode newNode = _findNodeAt(newUnit, offset, predicate); 2213 AstNode newNode = _findNodeAt(newUnit, offset, predicate);
2183 { 2214 {
2184 bool success = NodeReplacer.replace(oldNode, newNode); 2215 bool success = NodeReplacer.replace(oldNode, newNode);
2185 expect(success, isTrue); 2216 expect(success, isTrue);
2186 } 2217 }
2218 // update tokens
2219 {
2220 int delta = edit.replacement.length - edit.length;
2221 _shiftTokens(unit.beginToken, offset, delta);
2222 }
2187 // do incremental resolution 2223 // do incremental resolution
2188 IncrementalResolver resolver = new IncrementalResolver( 2224 IncrementalResolver resolver = new IncrementalResolver(
2189 typeProvider, 2225 typeProvider,
2190 unit.element, 2226 unit.element,
2191 edit.offset, 2227 edit.offset,
2192 edit.length, 2228 edit.length,
2193 edit.replacement.length); 2229 edit.replacement.length);
2194 bool success = resolver.resolve(newNode); 2230 bool success = resolver.resolve(newNode);
2195 expect(success, isTrue); 2231 expect(success, isTrue);
2196 // resolve "newCode" from scratch 2232 // resolve "newCode" from scratch
(...skipping 1792 matching lines...) Expand 10 before | Expand all | Expand 10 after
3989 } 4025 }
3990 4026
3991 @override 4027 @override
3992 visitYieldStatement(YieldStatement node) { 4028 visitYieldStatement(YieldStatement node) {
3993 YieldStatement other = this.other; 4029 YieldStatement other = this.other;
3994 _visitNode(node.expression, other.expression); 4030 _visitNode(node.expression, other.expression);
3995 } 4031 }
3996 4032
3997 void _verifyElement(Element a, Element b) { 4033 void _verifyElement(Element a, Element b) {
3998 if (a != b) { 4034 if (a != b) {
3999 print(a.location);
4000 print(b.location);
4001 fail('Expected: $b\n Actual: $a'); 4035 fail('Expected: $b\n Actual: $a');
4002 } 4036 }
4003 if (a == null && b == null) { 4037 if (a == null && b == null) {
4004 return; 4038 return;
4005 } 4039 }
4006 if (a.nameOffset != b.nameOffset) { 4040 if (a.nameOffset != b.nameOffset) {
4007 fail('Expected: ${b.nameOffset}\n Actual: ${a.nameOffset}'); 4041 fail('Expected: ${b.nameOffset}\n Actual: ${a.nameOffset}');
4008 } 4042 }
4009 } 4043 }
4010 4044
4011 void _verifyType(DartType a, DartType b) { 4045 void _verifyType(DartType a, DartType b) {
4012 expect(a, equals(b)); 4046 if (a != b) {
4047 fail('Expected: $b\n Actual: $a');
4048 }
4013 } 4049 }
4014 4050
4015 void _visitAnnotatedNode(AnnotatedNode node, AnnotatedNode other) { 4051 void _visitAnnotatedNode(AnnotatedNode node, AnnotatedNode other) {
4016 _visitNode(node.documentationComment, other.documentationComment); 4052 _visitNode(node.documentationComment, other.documentationComment);
4017 _visitList(node.metadata, other.metadata); 4053 _visitList(node.metadata, other.metadata);
4018 } 4054 }
4019 4055
4020 _visitDeclaration(Declaration node, Declaration other) { 4056 _visitDeclaration(Declaration node, Declaration other) {
4021 _verifyElement(node.element, other.element); 4057 _verifyElement(node.element, other.element);
4022 _visitAnnotatedNode(node, other); 4058 _visitAnnotatedNode(node, other);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4060 _visitList(node.metadata, other.metadata); 4096 _visitList(node.metadata, other.metadata);
4061 _visitNode(node.identifier, other.identifier); 4097 _visitNode(node.identifier, other.identifier);
4062 } 4098 }
4063 4099
4064 static void assertSameResolution(CompilationUnit actual, 4100 static void assertSameResolution(CompilationUnit actual,
4065 CompilationUnit expected) { 4101 CompilationUnit expected) {
4066 _SameResolutionValidator validator = new _SameResolutionValidator(expected); 4102 _SameResolutionValidator validator = new _SameResolutionValidator(expected);
4067 actual.accept(validator); 4103 actual.accept(validator);
4068 } 4104 }
4069 } 4105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698