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

Side by Side Diff: pkg/analyzer/test/src/task/incremental_element_builder_test.dart

Issue 2160673002: Another fix incremental constants - annotations should use the old unit element. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 5 months 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
« no previous file with comments | « pkg/analyzer/test/src/context/context_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 analyzer.test.src.task.incremental_element_builder_test; 5 library analyzer.test.src.task.incremental_element_builder_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/element/element.dart'; 8 import 'package:analyzer/dart/element/element.dart';
9 import 'package:analyzer/src/dart/ast/utilities.dart'; 9 import 'package:analyzer/src/dart/ast/utilities.dart';
10 import 'package:analyzer/src/dart/element/element.dart'; 10 import 'package:analyzer/src/dart/element/element.dart';
(...skipping 1631 matching lines...) Expand 10 before | Expand all | Expand 10 after
1642 _buildNewUnit(r''' 1642 _buildNewUnit(r'''
1643 class A { 1643 class A {
1644 b 1644 b
1645 1645
1646 /// CCC 1646 /// CCC
1647 A(); 1647 A();
1648 } 1648 }
1649 '''); 1649 ''');
1650 } 1650 }
1651 1651
1652 test_update_annotation_add() {
1653 _buildOldUnit(r'''
1654 const myAnnotation = const Object();
1655 foo() {}
1656 ''');
1657 _buildNewUnit(r'''
1658 const myAnnotation = const Object();
1659 @myAnnotation
1660 foo() {}
1661 ''');
1662 }
1663
1652 test_update_beforeClassWithDelta_nameOffset() { 1664 test_update_beforeClassWithDelta_nameOffset() {
1653 _buildOldUnit(r''' 1665 _buildOldUnit(r'''
1654 class A {} 1666 class A {}
1655 1667
1656 class B { 1668 class B {
1657 A a; 1669 A a;
1658 } 1670 }
1659 '''); 1671 ''');
1660 _buildNewUnit(r''' 1672 _buildNewUnit(r'''
1661 class A2 {} 1673 class A2 {}
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1859 } 1871 }
1860 // Field elements referenced by field formal parameters of constructors 1872 // Field elements referenced by field formal parameters of constructors
1861 // must by fields of the enclosing class element. 1873 // must by fields of the enclosing class element.
1862 if (actual is FieldFormalParameter) { 1874 if (actual is FieldFormalParameter) {
1863 FieldFormalParameterElement parameterElement = actual.element; 1875 FieldFormalParameterElement parameterElement = actual.element;
1864 FieldElement element = parameterElement.field; 1876 FieldElement element = parameterElement.field;
1865 ClassDeclaration classNode = 1877 ClassDeclaration classNode =
1866 actual.getAncestor((n) => n is ClassDeclaration); 1878 actual.getAncestor((n) => n is ClassDeclaration);
1867 expect(element.enclosingElement, same(classNode.element)); 1879 expect(element.enclosingElement, same(classNode.element));
1868 } 1880 }
1881 // ElementAnnotationImpl must use the enclosing CompilationUnitElement.
1882 if (actual is Annotation) {
1883 AstNode parent = actual.parent;
1884 if (parent is Declaration) {
1885 ElementAnnotationImpl actualElement = actual.elementAnnotation;
1886 CompilationUnitElement enclosingUnitElement =
1887 parent.element.getAncestor((a) => a is CompilationUnitElement);
1888 expect(actualElement.compilationUnit, same(enclosingUnitElement));
1889 }
1890 }
1869 // Identifiers like 'a.b' in 'new a.b()' might be rewritten if resolver 1891 // Identifiers like 'a.b' in 'new a.b()' might be rewritten if resolver
1870 // sees that 'a' is actually a class name, so 'b' is a constructor name. 1892 // sees that 'a' is actually a class name, so 'b' is a constructor name.
1871 // 1893 //
1872 if (expected is ConstructorName && actual is ConstructorName) { 1894 if (expected is ConstructorName && actual is ConstructorName) {
1873 Identifier expectedTypeName = expected.type.name; 1895 Identifier expectedTypeName = expected.type.name;
1874 Identifier actualTypeName = actual.type.name; 1896 Identifier actualTypeName = actual.type.name;
1875 if (expectedTypeName is PrefixedIdentifier && 1897 if (expectedTypeName is PrefixedIdentifier &&
1876 actualTypeName is SimpleIdentifier) { 1898 actualTypeName is SimpleIdentifier) {
1877 return isEqualNodes(expectedTypeName.prefix, actualTypeName) && 1899 return isEqualNodes(expectedTypeName.prefix, actualTypeName) &&
1878 isEqualNodes(expectedTypeName.identifier, actual.name); 1900 isEqualNodes(expectedTypeName.identifier, actual.name);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1959 expect(oldClass, isNotNull); 1981 expect(oldClass, isNotNull);
1960 element = oldClass.element; 1982 element = oldClass.element;
1961 oldVersion = element.version; 1983 oldVersion = element.version;
1962 oldMembers = oldClass.members.toList(); 1984 oldMembers = oldClass.members.toList();
1963 } 1985 }
1964 1986
1965 ClassDeclaration _findClassNode(CompilationUnit unit, String name) => 1987 ClassDeclaration _findClassNode(CompilationUnit unit, String name) =>
1966 unit.declarations.singleWhere((unitMember) => 1988 unit.declarations.singleWhere((unitMember) =>
1967 unitMember is ClassDeclaration && unitMember.name.name == name); 1989 unitMember is ClassDeclaration && unitMember.name.name == name);
1968 } 1990 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/context/context_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698