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

Side by Side Diff: pkg/analyzer/lib/src/generated/incremental_resolver.dart

Issue 832143007: Issue 22044. A changes in annotations should be considered as a mismatch. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Positive tests. Created 5 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | 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) 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; 5 library engine.incremental_resolver;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:math' as math; 8 import 'dart:math' as math;
9 9
10 import 'ast.dart'; 10 import 'ast.dart';
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 visitBlockFunctionBody(BlockFunctionBody node) { 129 visitBlockFunctionBody(BlockFunctionBody node) {
130 // ignore bodies 130 // ignore bodies
131 } 131 }
132 132
133 @override 133 @override
134 visitClassDeclaration(ClassDeclaration node) { 134 visitClassDeclaration(ClassDeclaration node) {
135 String name = node.name.name; 135 String name = node.name.name;
136 ClassElement element = _findElement(_enclosingUnit.types, name); 136 ClassElement element = _findElement(_enclosingUnit.types, name);
137 _enclosingClass = element; 137 _enclosingClass = element;
138 _processElement(element); 138 _processElement(element);
139 _assertSameAnnotations(node, element);
139 _assertSameTypeParameters(node.typeParameters, element.typeParameters); 140 _assertSameTypeParameters(node.typeParameters, element.typeParameters);
140 // check for missing clauses 141 // check for missing clauses
141 if (node.extendsClause == null) { 142 if (node.extendsClause == null) {
142 _assertTrue(element.supertype.name == 'Object'); 143 _assertTrue(element.supertype.name == 'Object');
143 } 144 }
144 if (node.implementsClause == null) { 145 if (node.implementsClause == null) {
145 _assertTrue(element.interfaces.isEmpty); 146 _assertTrue(element.interfaces.isEmpty);
146 } 147 }
147 if (node.withClause == null) { 148 if (node.withClause == null) {
148 _assertTrue(element.mixins.isEmpty); 149 _assertTrue(element.mixins.isEmpty);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 // prepare element 258 // prepare element
258 Token property = node.propertyKeyword; 259 Token property = node.propertyKeyword;
259 ExecutableElementImpl element; 260 ExecutableElementImpl element;
260 if (property == null) { 261 if (property == null) {
261 element = _findElement(_enclosingUnit.functions, name); 262 element = _findElement(_enclosingUnit.functions, name);
262 } else { 263 } else {
263 element = _findElement(_enclosingUnit.accessors, name); 264 element = _findElement(_enclosingUnit.accessors, name);
264 } 265 }
265 // process element 266 // process element
266 _processElement(element); 267 _processElement(element);
268 _assertSameAnnotations(node, element);
267 _assertFalse(element.isSynthetic); 269 _assertFalse(element.isSynthetic);
268 _assertSameType(node.returnType, element.returnType); 270 _assertSameType(node.returnType, element.returnType);
269 _assertCompatibleParameters( 271 _assertCompatibleParameters(
270 node.functionExpression.parameters, 272 node.functionExpression.parameters,
271 element.parameters); 273 element.parameters);
272 // matches, update the existing element 274 // matches, update the existing element
273 ExecutableElement newElement = node.element; 275 ExecutableElement newElement = node.element;
274 node.name.staticElement = element; 276 node.name.staticElement = element;
275 node.functionExpression.element = element; 277 node.functionExpression.element = element;
276 _setLocalElements(element, newElement); 278 _setLocalElements(element, newElement);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 ExecutableElementImpl element; 333 ExecutableElementImpl element;
332 if (property == null) { 334 if (property == null) {
333 element = _findElement(_enclosingClass.methods, name); 335 element = _findElement(_enclosingClass.methods, name);
334 } else { 336 } else {
335 element = _findElement(_enclosingClass.accessors, name); 337 element = _findElement(_enclosingClass.accessors, name);
336 } 338 }
337 // process element 339 // process element
338 ExecutableElement newElement = node.element; 340 ExecutableElement newElement = node.element;
339 try { 341 try {
340 _assertNotNull(element); 342 _assertNotNull(element);
343 _assertSameAnnotations(node, element);
341 _assertEquals(node.isStatic, element.isStatic); 344 _assertEquals(node.isStatic, element.isStatic);
342 _assertSameType(node.returnType, element.returnType); 345 _assertSameType(node.returnType, element.returnType);
343 _assertCompatibleParameters(node.parameters, element.parameters); 346 _assertCompatibleParameters(node.parameters, element.parameters);
344 _removedElements.remove(element); 347 _removedElements.remove(element);
345 // matches, update the existing element 348 // matches, update the existing element
346 node.name.staticElement = element; 349 node.name.staticElement = element;
347 _setLocalElements(element, newElement); 350 _setLocalElements(element, newElement);
348 } on _DeclarationMismatchException catch (e) { 351 } on _DeclarationMismatchException catch (e) {
349 _addedElements.add(newElement); 352 _addedElements.add(newElement);
350 _removeElement(element); 353 _removeElement(element);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 // prepare variable 390 // prepare variable
388 String name = node.name.name; 391 String name = node.name.name;
389 PropertyInducingElement element; 392 PropertyInducingElement element;
390 if (_inTopLevelVariableDeclaration) { 393 if (_inTopLevelVariableDeclaration) {
391 element = _findElement(_enclosingUnit.topLevelVariables, name); 394 element = _findElement(_enclosingUnit.topLevelVariables, name);
392 } else { 395 } else {
393 element = _findElement(_enclosingClass.fields, name); 396 element = _findElement(_enclosingClass.fields, name);
394 } 397 }
395 // verify 398 // verify
396 PropertyInducingElement newElement = node.name.staticElement; 399 PropertyInducingElement newElement = node.name.staticElement;
397 _assertNotNull(element);
398 _processElement(element); 400 _processElement(element);
401 _assertSameAnnotations(node, element);
399 _assertEquals(node.isConst, element.isConst); 402 _assertEquals(node.isConst, element.isConst);
400 _assertEquals(node.isFinal, element.isFinal); 403 _assertEquals(node.isFinal, element.isFinal);
401 if (_enclosingFieldNode != null) { 404 if (_enclosingFieldNode != null) {
402 _assertEquals(_enclosingFieldNode.isStatic, element.isStatic); 405 _assertEquals(_enclosingFieldNode.isStatic, element.isStatic);
403 } 406 }
404 _assertSameType( 407 _assertSameType(
405 (node.parent as VariableDeclarationList).type, 408 (node.parent as VariableDeclarationList).type,
406 element.type); 409 element.type);
407 // matches, restore the existing element 410 // matches, restore the existing element
408 node.name.staticElement = element; 411 node.name.staticElement = element;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 throw new _DeclarationMismatchException(); 507 throw new _DeclarationMismatchException();
505 } 508 }
506 } 509 }
507 510
508 void _assertNull(Object object) { 511 void _assertNull(Object object) {
509 if (object != null) { 512 if (object != null) {
510 throw new _DeclarationMismatchException(); 513 throw new _DeclarationMismatchException();
511 } 514 }
512 } 515 }
513 516
517 void _assertSameAnnotation(Annotation node, ElementAnnotation annotation) {
518 _assertNull(node.arguments);
519 Element element = annotation.element;
520 _assertTrue(element is PropertyAccessorElement);
521 _assertTrue(node.name is SimpleIdentifier);
522 String nodeName = node.name.name;
523 String elementName = element.displayName;
524 _assertEquals(nodeName, elementName);
525 }
526
527 void _assertSameAnnotations(AnnotatedNode node, Element element) {
528 List<Annotation> nodeAnnotaitons = node.metadata;
529 List<ElementAnnotation> elementAnnotations = element.metadata;
530 int length = nodeAnnotaitons.length;
531 _assertEquals(elementAnnotations.length, length);
532 for (int i = 0; i < length; i++) {
533 _assertSameAnnotation(nodeAnnotaitons[i], elementAnnotations[i]);
534 }
535 }
536
514 void _assertSameType(TypeName node, DartType type) { 537 void _assertSameType(TypeName node, DartType type) {
515 // no return type == dynamic 538 // no return type == dynamic
516 if (node == null) { 539 if (node == null) {
517 return _assertTrue(type == null || type.isDynamic); 540 return _assertTrue(type == null || type.isDynamic);
518 } 541 }
519 if (type == null) { 542 if (type == null) {
520 return _assertTrue(false); 543 return _assertTrue(false);
521 } 544 }
522 // prepare name 545 // prepare name
523 Identifier nameIdentifier = node.name; 546 Identifier nameIdentifier = node.name;
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1827 String toString() => name; 1850 String toString() => name;
1828 } 1851 }
1829 1852
1830 1853
1831 class _TokenPair { 1854 class _TokenPair {
1832 final _TokenDifferenceKind kind; 1855 final _TokenDifferenceKind kind;
1833 final Token oldToken; 1856 final Token oldToken;
1834 final Token newToken; 1857 final Token newToken;
1835 _TokenPair(this.kind, this.oldToken, this.newToken); 1858 _TokenPair(this.kind, this.oldToken, this.newToken);
1836 } 1859 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698