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

Side by Side Diff: pkg/analysis_server/lib/src/status/validator.dart

Issue 2835703002: Remove ReferencedNames(Builder). (Closed)
Patch Set: Created 3 years, 8 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
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 analysis_server.src.status.validator; 5 library analysis_server.src.status.validator;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/ast/token.dart'; 10 import 'package:analyzer/dart/ast/token.dart';
(...skipping 1491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 } else if (actual is DartScript) { 1502 } else if (actual is DartScript) {
1503 return _compareDartScripts(expected, actual, buffer); 1503 return _compareDartScripts(expected, actual, buffer);
1504 } else if (actual is html.Document) { 1504 } else if (actual is html.Document) {
1505 return _compareDocuments(expected, actual, buffer); 1505 return _compareDocuments(expected, actual, buffer);
1506 } else if (actual is Element) { 1506 } else if (actual is Element) {
1507 return _compareElements(expected, actual, buffer); 1507 return _compareElements(expected, actual, buffer);
1508 } else if (actual is LibrarySpecificUnit) { 1508 } else if (actual is LibrarySpecificUnit) {
1509 return _compareLibrarySpecificUnits(expected, actual, buffer); 1509 return _compareLibrarySpecificUnits(expected, actual, buffer);
1510 } else if (actual is LineInfo) { 1510 } else if (actual is LineInfo) {
1511 return _compareLineInfos(expected, actual, buffer); 1511 return _compareLineInfos(expected, actual, buffer);
1512 } else if (actual is ReferencedNames) {
1513 return _compareReferencedNames(expected, actual, buffer);
1514 } else if (actual is Source) { 1512 } else if (actual is Source) {
1515 return _compareSources(expected, actual, buffer); 1513 return _compareSources(expected, actual, buffer);
1516 } else if (actual is SourceKind) { 1514 } else if (actual is SourceKind) {
1517 return _comparePrimitives(expected, actual, buffer); 1515 return _comparePrimitives(expected, actual, buffer);
1518 } else if (actual is Token) { 1516 } else if (actual is Token) {
1519 return _compareTokenStreams(expected, actual, buffer); 1517 return _compareTokenStreams(expected, actual, buffer);
1520 } else if (actual is TypeProvider) { 1518 } else if (actual is TypeProvider) {
1521 return true; 1519 return true;
1522 } else if (actual is UsedLocalElements) { 1520 } else if (actual is UsedLocalElements) {
1523 return _compareUsedLocalElements(expected, actual, buffer); 1521 return _compareUsedLocalElements(expected, actual, buffer);
(...skipping 15 matching lines...) Expand all
1539 } 1537 }
1540 if (buffer != null) { 1538 if (buffer != null) {
1541 buffer.write('Expected '); 1539 buffer.write('Expected ');
1542 buffer.write(expected); 1540 buffer.write(expected);
1543 buffer.write('; found '); 1541 buffer.write('; found ');
1544 buffer.write(actual); 1542 buffer.write(actual);
1545 } 1543 }
1546 return false; 1544 return false;
1547 } 1545 }
1548 1546
1549 bool _compareReferencedNames(
1550 ReferencedNames expected, ReferencedNames actual, StringBuffer buffer) {
1551 Set<String> expectedNames = expected.names;
1552 Map<String, Set<String>> expectedUserToDependsOn = expected.userToDependsOn;
1553 Set<String> expectedKeys = expectedUserToDependsOn.keys.toSet();
1554
1555 Set<String> actualNames = actual.names;
1556 Map<String, Set<String>> actualUserToDependsOn = actual.userToDependsOn;
1557 Set<String> actualKeys = actualUserToDependsOn.keys.toSet();
1558
1559 Set<String> missingNames = expectedNames.difference(actualNames);
1560 Set<String> extraNames = actualNames.difference(expectedNames);
1561 Set<String> missingKeys = expectedKeys.difference(actualKeys);
1562 Set<String> extraKeys = actualKeys.difference(expectedKeys);
1563 Map<String, List<Set<String>>> mismatchedDependencies =
1564 new HashMap<String, List<Set<String>>>();
1565 Set<String> commonKeys = expectedKeys.intersection(actualKeys);
1566 for (String key in commonKeys) {
1567 Set<String> expectedDependencies = expectedUserToDependsOn[key];
1568 Set<String> actualDependencies = actualUserToDependsOn[key];
1569 Set<String> missingDependencies =
1570 expectedDependencies.difference(actualDependencies);
1571 Set<String> extraDependencies =
1572 actualDependencies.difference(expectedDependencies);
1573 if (missingDependencies.isNotEmpty || extraDependencies.isNotEmpty) {
1574 mismatchedDependencies[key] = [missingDependencies, extraDependencies];
1575 }
1576 }
1577
1578 if (missingNames.isEmpty &&
1579 extraNames.isEmpty &&
1580 missingKeys.isEmpty &&
1581 extraKeys.isEmpty &&
1582 mismatchedDependencies.isEmpty) {
1583 return true;
1584 }
1585 if (buffer != null) {
1586 void write(String title, Set<String> names) {
1587 buffer.write(names.length);
1588 buffer.write(' ');
1589 buffer.write(title);
1590 buffer.write(': {');
1591 bool first = true;
1592 for (String name in names) {
1593 if (first) {
1594 first = false;
1595 } else {
1596 buffer.write(', ');
1597 }
1598 buffer.write(name);
1599 }
1600 buffer.write('}');
1601 }
1602
1603 bool needsNewline = false;
1604 if (missingNames.isNotEmpty) {
1605 buffer.write('Has ');
1606 write('missing names', missingNames);
1607 needsNewline = true;
1608 }
1609 if (extraNames.isNotEmpty) {
1610 if (needsNewline) {
1611 buffer.write('</p><p>');
1612 }
1613 buffer.write('Has ');
1614 write('extra names', extraNames);
1615 needsNewline = true;
1616 }
1617 if (missingKeys.isNotEmpty) {
1618 if (needsNewline) {
1619 buffer.write('</p><p>');
1620 }
1621 buffer.write('Has ');
1622 write('missing keys', missingKeys);
1623 needsNewline = true;
1624 }
1625 if (extraKeys.isNotEmpty) {
1626 if (needsNewline) {
1627 buffer.write('</p><p>');
1628 }
1629 buffer.write('Has ');
1630 write('extra keys', extraKeys);
1631 needsNewline = true;
1632 }
1633 mismatchedDependencies.forEach((String key, List<Set<String>> value) {
1634 Set<String> missingDependencies = value[0];
1635 Set<String> extraDependencies = value[1];
1636 if (needsNewline) {
1637 buffer.write('</p><p>');
1638 }
1639 buffer.write('The key ');
1640 buffer.write(key);
1641 buffer.write(' has ');
1642 bool needsConjunction = false;
1643 if (missingNames.isNotEmpty) {
1644 write('missing dependencies', missingDependencies);
1645 needsConjunction = true;
1646 }
1647 if (extraNames.isNotEmpty) {
1648 if (needsConjunction) {
1649 buffer.write(' and ');
1650 }
1651 write('extra dependencies', extraDependencies);
1652 }
1653 needsNewline = true;
1654 });
1655 }
1656 return true;
1657 }
1658
1659 bool _compareSources(Source expected, Source actual, StringBuffer buffer) { 1547 bool _compareSources(Source expected, Source actual, StringBuffer buffer) {
1660 if (actual.fullName == expected.fullName) { 1548 if (actual.fullName == expected.fullName) {
1661 return true; 1549 return true;
1662 } 1550 }
1663 if (buffer != null) { 1551 if (buffer != null) {
1664 buffer.write('Expected a source for '); 1552 buffer.write('Expected a source for ');
1665 buffer.write(expected.fullName); 1553 buffer.write(expected.fullName);
1666 buffer.write('; found a source for '); 1554 buffer.write('; found a source for ');
1667 buffer.write(actual.fullName); 1555 buffer.write(actual.fullName);
1668 } 1556 }
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 * Determine whether or not there is any interesting difference between the 1664 * Determine whether or not there is any interesting difference between the
1777 * original and cloned values. 1665 * original and cloned values.
1778 */ 1666 */
1779 void _performComparison() { 1667 void _performComparison() {
1780 StringBuffer buffer = new StringBuffer(); 1668 StringBuffer buffer = new StringBuffer();
1781 if (!_compareObjects(cloneValue, originalValue, buffer)) { 1669 if (!_compareObjects(cloneValue, originalValue, buffer)) {
1782 description = buffer.toString(); 1670 description = buffer.toString();
1783 } 1671 }
1784 } 1672 }
1785 } 1673 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/status/get_handler.dart ('k') | pkg/analyzer/lib/src/generated/incremental_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698