| 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 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1819 class A {} | 1819 class A {} |
| 1820 class B extends Object with A {} | 1820 class B extends Object with A {} |
| 1821 '''); | 1821 '''); |
| 1822 } | 1822 } |
| 1823 | 1823 |
| 1824 void _assertCompilationUnitMatches(bool expectMatch, String oldContent, | 1824 void _assertCompilationUnitMatches(bool expectMatch, String oldContent, |
| 1825 String newContent) { | 1825 String newContent) { |
| 1826 Source source = addSource(oldContent); | 1826 Source source = addSource(oldContent); |
| 1827 LibraryElement library = resolve(source); | 1827 LibraryElement library = resolve(source); |
| 1828 CompilationUnit oldUnit = resolveCompilationUnit(source, library); | 1828 CompilationUnit oldUnit = resolveCompilationUnit(source, library); |
| 1829 // parse |
| 1829 CompilationUnit newUnit = ParserTestCase.parseCompilationUnit(newContent); | 1830 CompilationUnit newUnit = ParserTestCase.parseCompilationUnit(newContent); |
| 1831 // build elements |
| 1832 { |
| 1833 ElementHolder holder = new ElementHolder(); |
| 1834 ElementBuilder builder = new ElementBuilder(holder); |
| 1835 newUnit.accept(builder); |
| 1836 } |
| 1837 // match |
| 1830 DeclarationMatcher matcher = new DeclarationMatcher(); | 1838 DeclarationMatcher matcher = new DeclarationMatcher(); |
| 1831 expect(matcher.matches(newUnit, oldUnit.element), expectMatch); | 1839 expect(matcher.matches(newUnit, oldUnit.element), expectMatch); |
| 1832 } | 1840 } |
| 1833 } | 1841 } |
| 1834 | 1842 |
| 1835 | 1843 |
| 1836 class IncrementalResolverTest extends ResolverTestCase { | 1844 class IncrementalResolverTest extends ResolverTestCase { |
| 1837 Source source; | 1845 Source source; |
| 1838 String code; | 1846 String code; |
| 1839 LibraryElement library; | 1847 LibraryElement library; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1873 _resolveUnit(r''' | 1881 _resolveUnit(r''' |
| 1874 class A { | 1882 class A { |
| 1875 int f; | 1883 int f; |
| 1876 A(int a, int b) : f = a + b { | 1884 A(int a, int b) : f = a + b { |
| 1877 int a = 42; | 1885 int a = 42; |
| 1878 } | 1886 } |
| 1879 }'''); | 1887 }'''); |
| 1880 _resolve(_editString('+', '*'), _isExpression); | 1888 _resolve(_editString('+', '*'), _isExpression); |
| 1881 } | 1889 } |
| 1882 | 1890 |
| 1891 void test_constructor_label_add() { |
| 1892 _resolveUnit(r''' |
| 1893 class A { |
| 1894 A() { |
| 1895 return 42; |
| 1896 } |
| 1897 } |
| 1898 '''); |
| 1899 _resolve(_editString('return', 'label: return'), _isBlock); |
| 1900 } |
| 1901 |
| 1902 void test_constructor_localVariable_add() { |
| 1903 _resolveUnit(r''' |
| 1904 class A { |
| 1905 A() { |
| 1906 42; |
| 1907 } |
| 1908 } |
| 1909 '''); |
| 1910 _resolve(_editString('42;', 'var res = 42;'), _isBlock); |
| 1911 } |
| 1912 |
| 1883 void test_constructor_superConstructorInvocation() { | 1913 void test_constructor_superConstructorInvocation() { |
| 1884 _resolveUnit(r''' | 1914 _resolveUnit(r''' |
| 1885 class A { | 1915 class A { |
| 1886 A(int p); | 1916 A(int p); |
| 1887 } | 1917 } |
| 1888 class B extends A { | 1918 class B extends A { |
| 1889 B(int a, int b) : super(a + b); | 1919 B(int a, int b) : super(a + b); |
| 1890 } | 1920 } |
| 1891 '''); | 1921 '''); |
| 1892 _resolve(_editString('+', '*'), _isExpression); | 1922 _resolve(_editString('+', '*'), _isExpression); |
| (...skipping 2033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3926 } | 3956 } |
| 3927 | 3957 |
| 3928 @override | 3958 @override |
| 3929 visitYieldStatement(YieldStatement node) { | 3959 visitYieldStatement(YieldStatement node) { |
| 3930 YieldStatement other = this.other; | 3960 YieldStatement other = this.other; |
| 3931 _visitNode(node.expression, other.expression); | 3961 _visitNode(node.expression, other.expression); |
| 3932 } | 3962 } |
| 3933 | 3963 |
| 3934 void _verifyElement(Element a, Element b) { | 3964 void _verifyElement(Element a, Element b) { |
| 3935 if (a != b) { | 3965 if (a != b) { |
| 3966 print(a.location); |
| 3967 print(b.location); |
| 3936 fail('Expected: $b\n Actual: $a'); | 3968 fail('Expected: $b\n Actual: $a'); |
| 3937 } | 3969 } |
| 3938 if (a == null && b == null) { | 3970 if (a == null && b == null) { |
| 3939 return; | 3971 return; |
| 3940 } | 3972 } |
| 3941 if (a.nameOffset != b.nameOffset) { | 3973 if (a.nameOffset != b.nameOffset) { |
| 3942 fail('Expected: ${b.nameOffset}\n Actual: ${a.nameOffset}'); | 3974 fail('Expected: ${b.nameOffset}\n Actual: ${a.nameOffset}'); |
| 3943 } | 3975 } |
| 3944 } | 3976 } |
| 3945 | 3977 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3995 _visitList(node.metadata, other.metadata); | 4027 _visitList(node.metadata, other.metadata); |
| 3996 _visitNode(node.identifier, other.identifier); | 4028 _visitNode(node.identifier, other.identifier); |
| 3997 } | 4029 } |
| 3998 | 4030 |
| 3999 static void assertSameResolution(CompilationUnit actual, | 4031 static void assertSameResolution(CompilationUnit actual, |
| 4000 CompilationUnit expected) { | 4032 CompilationUnit expected) { |
| 4001 _SameResolutionValidator validator = new _SameResolutionValidator(expected); | 4033 _SameResolutionValidator validator = new _SameResolutionValidator(expected); |
| 4002 actual.accept(validator); | 4034 actual.accept(validator); |
| 4003 } | 4035 } |
| 4004 } | 4036 } |
| OLD | NEW |