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

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

Issue 1581293002: Issue 25064. Incrementally resolve comments only if both are documentation. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Check types in comment incremental resolution. Created 4 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
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.src.generated.incremental_resolver; 5 library analyzer.src.generated.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 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 } 590 }
591 if (element is PropertyAccessorElement) { 591 if (element is PropertyAccessorElement) {
592 _assertTrue(node.name is SimpleIdentifier); 592 _assertTrue(node.name is SimpleIdentifier);
593 String nodeName = node.name.name; 593 String nodeName = node.name.name;
594 String elementName = element.displayName; 594 String elementName = element.displayName;
595 _assertEquals(nodeName, elementName); 595 _assertEquals(nodeName, elementName);
596 } 596 }
597 } 597 }
598 598
599 void _assertSameAnnotations(AnnotatedNode node, Element element) { 599 void _assertSameAnnotations(AnnotatedNode node, Element element) {
600 List<Annotation> nodeAnnotaitons = node.metadata; 600 List<Annotation> nodeAnnotations = node.metadata;
601 List<ElementAnnotation> elementAnnotations = element.metadata; 601 List<ElementAnnotation> elementAnnotations = element.metadata;
602 int length = nodeAnnotaitons.length; 602 int length = nodeAnnotations.length;
603 _assertEquals(elementAnnotations.length, length); 603 _assertEquals(elementAnnotations.length, length);
604 for (int i = 0; i < length; i++) { 604 for (int i = 0; i < length; i++) {
605 _assertSameAnnotation(nodeAnnotaitons[i], elementAnnotations[i]); 605 _assertSameAnnotation(nodeAnnotations[i], elementAnnotations[i]);
606 } 606 }
607 } 607 }
608 608
609 void _assertSameType(TypeName node, DartType type) { 609 void _assertSameType(TypeName node, DartType type) {
610 // no type == dynamic 610 // no type == dynamic
611 if (node == null) { 611 if (node == null) {
612 return _assertTrue(type == null || type.isDynamic); 612 return _assertTrue(type == null || type.isDynamic);
613 } 613 }
614 if (type == null) { 614 if (type == null) {
615 return _assertTrue(false); 615 return _assertTrue(false);
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 if (!success) { 1548 if (!success) {
1549 logger.log('Failure: element model changed.'); 1549 logger.log('Failure: element model changed.');
1550 return false; 1550 return false;
1551 } 1551 }
1552 // update DartEntry 1552 // update DartEntry
1553 _updateEntry(); 1553 _updateEntry();
1554 logger.log('Success.'); 1554 logger.log('Success.');
1555 return true; 1555 return true;
1556 } 1556 }
1557 } catch (e, st) { 1557 } catch (e, st) {
1558 logger.log(e); 1558 logger.logException(e, st);
1559 logger.log(st);
1560 logger.log('Failure: exception.'); 1559 logger.log('Failure: exception.');
1561 } finally { 1560 } finally {
1562 logger.exit(); 1561 logger.exit();
1563 } 1562 }
1564 return false; 1563 return false;
1565 } 1564 }
1566 1565
1567 CompilationUnit _parseUnit(String code) { 1566 CompilationUnit _parseUnit(String code) {
1568 LoggingTimer timer = logger.startTimer(); 1567 LoggingTimer timer = logger.startTimer();
1569 try { 1568 try {
(...skipping 18 matching lines...) Expand all
1588 Token oldToken = firstPair.oldToken; 1587 Token oldToken = firstPair.oldToken;
1589 Token newToken = firstPair.newToken; 1588 Token newToken = firstPair.newToken;
1590 CommentToken oldComments = oldToken.precedingComments; 1589 CommentToken oldComments = oldToken.precedingComments;
1591 CommentToken newComments = newToken.precedingComments; 1590 CommentToken newComments = newToken.precedingComments;
1592 if (oldComments == null || newComments == null) { 1591 if (oldComments == null || newComments == null) {
1593 return false; 1592 return false;
1594 } 1593 }
1595 // find nodes 1594 // find nodes
1596 int offset = oldComments.offset; 1595 int offset = oldComments.offset;
1597 logger.log('offset: $offset'); 1596 logger.log('offset: $offset');
1598 Comment oldComment = _findNodeCovering(_oldUnit, offset, offset); 1597 AstNode oldNode = _findNodeCovering(_oldUnit, offset, offset);
1599 Comment newComment = _findNodeCovering(newUnit, offset, offset); 1598 AstNode newNode = _findNodeCovering(newUnit, offset, offset);
1599 if (oldNode is! Comment || newNode is! Comment) {
1600 return false;
1601 }
1602 Comment oldComment = oldNode;
1603 Comment newComment = newNode;
1600 logger.log('oldComment.beginToken: ${oldComment.beginToken}'); 1604 logger.log('oldComment.beginToken: ${oldComment.beginToken}');
1601 logger.log('newComment.beginToken: ${newComment.beginToken}'); 1605 logger.log('newComment.beginToken: ${newComment.beginToken}');
1602 _updateOffset = oldToken.offset - 1; 1606 _updateOffset = oldToken.offset - 1;
1603 // update token references 1607 // update token references
1604 _shiftTokens(firstPair.oldToken); 1608 _shiftTokens(firstPair.oldToken);
1605 _setPrecedingComments(oldToken, newComment.tokens.first); 1609 _setPrecedingComments(oldToken, newComment.tokens.first);
1606 // replace node 1610 // replace node
1607 NodeReplacer.replace(oldComment, newComment); 1611 NodeReplacer.replace(oldComment, newComment);
1608 // update elements 1612 // update elements
1609 IncrementalResolver incrementalResolver = new IncrementalResolver( 1613 IncrementalResolver incrementalResolver = new IncrementalResolver(
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 } 1730 }
1727 if (oldToken.type == TokenType.EOF || newToken.type == TokenType.EOF) { 1731 if (oldToken.type == TokenType.EOF || newToken.type == TokenType.EOF) {
1728 return new _TokenPair(_TokenDifferenceKind.CONTENT, oldToken, newToken); 1732 return new _TokenPair(_TokenDifferenceKind.CONTENT, oldToken, newToken);
1729 } 1733 }
1730 // compare comments 1734 // compare comments
1731 { 1735 {
1732 Token oldComment = oldToken.precedingComments; 1736 Token oldComment = oldToken.precedingComments;
1733 Token newComment = newToken.precedingComments; 1737 Token newComment = newToken.precedingComments;
1734 if (_compareToken(oldComment, newComment, 0, true) != null) { 1738 if (_compareToken(oldComment, newComment, 0, true) != null) {
1735 _TokenDifferenceKind diffKind = _TokenDifferenceKind.COMMENT; 1739 _TokenDifferenceKind diffKind = _TokenDifferenceKind.COMMENT;
1736 if (oldComment is DocumentationCommentToken || 1740 if (oldComment is DocumentationCommentToken &&
1737 newComment is DocumentationCommentToken) { 1741 newComment is DocumentationCommentToken) {
1738 diffKind = _TokenDifferenceKind.COMMENT_DOC; 1742 diffKind = _TokenDifferenceKind.COMMENT_DOC;
1739 } 1743 }
1740 return new _TokenPair(diffKind, oldToken, newToken); 1744 return new _TokenPair(diffKind, oldToken, newToken);
1741 } 1745 }
1742 } 1746 }
1743 // compare tokens 1747 // compare tokens
1744 _TokenDifferenceKind diffKind = 1748 _TokenDifferenceKind diffKind =
1745 _compareToken(oldToken, newToken, 0, false); 1749 _compareToken(oldToken, newToken, 0, false);
1746 if (diffKind != null) { 1750 if (diffKind != null) {
(...skipping 15 matching lines...) Expand all
1762 _compareToken(oldToken, newToken, delta, false); 1766 _compareToken(oldToken, newToken, delta, false);
1763 if (diffKind != null) { 1767 if (diffKind != null) {
1764 return new _TokenPair(diffKind, oldToken.next, newToken.next); 1768 return new _TokenPair(diffKind, oldToken.next, newToken.next);
1765 } 1769 }
1766 // compare comments 1770 // compare comments
1767 { 1771 {
1768 Token oldComment = oldToken.precedingComments; 1772 Token oldComment = oldToken.precedingComments;
1769 Token newComment = newToken.precedingComments; 1773 Token newComment = newToken.precedingComments;
1770 if (_compareToken(oldComment, newComment, delta, true) != null) { 1774 if (_compareToken(oldComment, newComment, delta, true) != null) {
1771 _TokenDifferenceKind diffKind = _TokenDifferenceKind.COMMENT; 1775 _TokenDifferenceKind diffKind = _TokenDifferenceKind.COMMENT;
1772 if (oldComment is DocumentationCommentToken || 1776 if (oldComment is DocumentationCommentToken &&
1773 newComment is DocumentationCommentToken) { 1777 newComment is DocumentationCommentToken) {
1774 diffKind = _TokenDifferenceKind.COMMENT_DOC; 1778 diffKind = _TokenDifferenceKind.COMMENT_DOC;
1775 } 1779 }
1776 return new _TokenPair(diffKind, oldToken, newToken); 1780 return new _TokenPair(diffKind, oldToken, newToken);
1777 } 1781 }
1778 } 1782 }
1779 // next tokens 1783 // next tokens
1780 oldToken = oldToken.previous; 1784 oldToken = oldToken.previous;
1781 newToken = newToken.previous; 1785 newToken = newToken.previous;
1782 } 1786 }
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 @override 2101 @override
2098 String toString() => name; 2102 String toString() => name;
2099 } 2103 }
2100 2104
2101 class _TokenPair { 2105 class _TokenPair {
2102 final _TokenDifferenceKind kind; 2106 final _TokenDifferenceKind kind;
2103 final Token oldToken; 2107 final Token oldToken;
2104 final Token newToken; 2108 final Token newToken;
2105 _TokenPair(this.kind, this.oldToken, this.newToken); 2109 _TokenPair(this.kind, this.oldToken, this.newToken);
2106 } 2110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698