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

Side by Side Diff: pkg/analyzer/test/src/context/context_test.dart

Issue 2485043004: Don't serialize elements of top-level function/constructor/method bodies. (Closed)
Patch Set: Created 4 years, 1 month 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
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 analyzer.test.src.context.context_test; 5 library analyzer.test.src.context.context_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 5377 matching lines...) Expand 10 before | Expand all | Expand 10 after
5388 */ 5388 */
5389 void expectNoDifferences() { 5389 void expectNoDifferences() {
5390 if (overwrittenCount > 0) { 5390 if (overwrittenCount > 0) {
5391 fail('Found $overwrittenCount overwritten elements.$buffer'); 5391 fail('Found $overwrittenCount overwritten elements.$buffer');
5392 } 5392 }
5393 } 5393 }
5394 5394
5395 @override 5395 @override
5396 void visitElement(Element element) { 5396 void visitElement(Element element) {
5397 Element previousElement = previousElements[element]; 5397 Element previousElement = previousElements[element];
5398 bool expectIdentical = element is! LocalVariableElement; 5398 bool ok = _expectedIdentical(element)
5399 bool ok = expectIdentical
5400 ? identical(previousElement, element) 5399 ? identical(previousElement, element)
5401 : previousElement == element; 5400 : previousElement == element;
5402 if (!ok) { 5401 if (!ok) {
5403 if (overwrittenCount == 0) { 5402 if (overwrittenCount == 0) {
5404 buffer.writeln(); 5403 buffer.writeln();
5405 } 5404 }
5406 overwrittenCount++; 5405 overwrittenCount++;
5407 buffer.writeln('Overwritten element:'); 5406 buffer.writeln('Overwritten element:');
5408 Element currentElement = element; 5407 Element currentElement = element;
5409 while (currentElement != null) { 5408 while (currentElement != null) {
5410 buffer.write(' '); 5409 buffer.write(' ');
5411 buffer.writeln(currentElement.toString()); 5410 buffer.writeln(currentElement.toString());
5412 currentElement = currentElement.enclosingElement; 5411 currentElement = currentElement.enclosingElement;
5413 } 5412 }
5414 } 5413 }
5415 super.visitElement(element); 5414 super.visitElement(element);
5416 } 5415 }
5416
5417 /**
5418 * Return `true` if the given [element] should be the same as the previous
5419 * element at the same position in the element model.
5420 */
5421 static bool _expectedIdentical(Element element) {
5422 while (element != null) {
5423 if (element is ConstructorElement ||
5424 element is MethodElement ||
5425 element is FunctionElement &&
5426 element.enclosingElement is CompilationUnitElement) {
5427 return false;
5428 }
5429 element = element.enclosingElement;
5430 }
5431 return true;
5432 }
5417 } 5433 }
5418 5434
5419 /** 5435 /**
5420 * A visitor that can be used to collect all of the elements in an element 5436 * A visitor that can be used to collect all of the elements in an element
5421 * model. 5437 * model.
5422 */ 5438 */
5423 class _ElementGatherer extends GeneralizingElementVisitor { 5439 class _ElementGatherer extends GeneralizingElementVisitor {
5424 /** 5440 /**
5425 * The map in which the elements are collected. The value of each key is the 5441 * The map in which the elements are collected. The value of each key is the
5426 * key itself. 5442 * key itself.
5427 */ 5443 */
5428 Map<Element, Element> elements = new HashMap<Element, Element>(); 5444 Map<Element, Element> elements = new HashMap<Element, Element>();
5429 5445
5430 /** 5446 /**
5431 * Initialize the visitor. 5447 * Initialize the visitor.
5432 */ 5448 */
5433 _ElementGatherer(); 5449 _ElementGatherer();
5434 5450
5435 @override 5451 @override
5436 void visitElement(Element element) { 5452 void visitElement(Element element) {
5437 elements[element] = element; 5453 elements[element] = element;
5438 super.visitElement(element); 5454 super.visitElement(element);
5439 } 5455 }
5440 } 5456 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698