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/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: 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.');
skybrian 2016/01/14 02:39:13 Another suggestion: + // The incremental res
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 {
1570 Token token = _scan(code); 1569 Token token = _scan(code);
(...skipping 17 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 Comment oldComment = _findNodeCovering(_oldUnit, offset, offset);
skybrian 2016/01/14 02:33:11 In addition, I suggest changing these two lines:
scheglov 2016/01/14 03:19:29 Done.
1599 Comment newComment = _findNodeCovering(newUnit, offset, offset); 1598 Comment newComment = _findNodeCovering(newUnit, offset, offset);
1600 logger.log('oldComment.beginToken: ${oldComment.beginToken}'); 1599 logger.log('oldComment.beginToken: ${oldComment.beginToken}');
1601 logger.log('newComment.beginToken: ${newComment.beginToken}'); 1600 logger.log('newComment.beginToken: ${newComment.beginToken}');
1602 _updateOffset = oldToken.offset - 1; 1601 _updateOffset = oldToken.offset - 1;
1603 // update token references 1602 // update token references
1604 _shiftTokens(firstPair.oldToken); 1603 _shiftTokens(firstPair.oldToken);
1605 _setPrecedingComments(oldToken, newComment.tokens.first); 1604 _setPrecedingComments(oldToken, newComment.tokens.first);
1606 // replace node 1605 // replace node
1607 NodeReplacer.replace(oldComment, newComment); 1606 NodeReplacer.replace(oldComment, newComment);
1608 // update elements 1607 // update elements
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1726 } 1725 }
1727 if (oldToken.type == TokenType.EOF || newToken.type == TokenType.EOF) { 1726 if (oldToken.type == TokenType.EOF || newToken.type == TokenType.EOF) {
1728 return new _TokenPair(_TokenDifferenceKind.CONTENT, oldToken, newToken); 1727 return new _TokenPair(_TokenDifferenceKind.CONTENT, oldToken, newToken);
1729 } 1728 }
1730 // compare comments 1729 // compare comments
1731 { 1730 {
1732 Token oldComment = oldToken.precedingComments; 1731 Token oldComment = oldToken.precedingComments;
1733 Token newComment = newToken.precedingComments; 1732 Token newComment = newToken.precedingComments;
1734 if (_compareToken(oldComment, newComment, 0, true) != null) { 1733 if (_compareToken(oldComment, newComment, 0, true) != null) {
1735 _TokenDifferenceKind diffKind = _TokenDifferenceKind.COMMENT; 1734 _TokenDifferenceKind diffKind = _TokenDifferenceKind.COMMENT;
1736 if (oldComment is DocumentationCommentToken || 1735 if (oldComment is DocumentationCommentToken &&
1737 newComment is DocumentationCommentToken) { 1736 newComment is DocumentationCommentToken) {
1738 diffKind = _TokenDifferenceKind.COMMENT_DOC; 1737 diffKind = _TokenDifferenceKind.COMMENT_DOC;
1739 } 1738 }
1740 return new _TokenPair(diffKind, oldToken, newToken); 1739 return new _TokenPair(diffKind, oldToken, newToken);
1741 } 1740 }
1742 } 1741 }
1743 // compare tokens 1742 // compare tokens
1744 _TokenDifferenceKind diffKind = 1743 _TokenDifferenceKind diffKind =
1745 _compareToken(oldToken, newToken, 0, false); 1744 _compareToken(oldToken, newToken, 0, false);
1746 if (diffKind != null) { 1745 if (diffKind != null) {
(...skipping 15 matching lines...) Expand all
1762 _compareToken(oldToken, newToken, delta, false); 1761 _compareToken(oldToken, newToken, delta, false);
1763 if (diffKind != null) { 1762 if (diffKind != null) {
1764 return new _TokenPair(diffKind, oldToken.next, newToken.next); 1763 return new _TokenPair(diffKind, oldToken.next, newToken.next);
1765 } 1764 }
1766 // compare comments 1765 // compare comments
1767 { 1766 {
1768 Token oldComment = oldToken.precedingComments; 1767 Token oldComment = oldToken.precedingComments;
1769 Token newComment = newToken.precedingComments; 1768 Token newComment = newToken.precedingComments;
1770 if (_compareToken(oldComment, newComment, delta, true) != null) { 1769 if (_compareToken(oldComment, newComment, delta, true) != null) {
1771 _TokenDifferenceKind diffKind = _TokenDifferenceKind.COMMENT; 1770 _TokenDifferenceKind diffKind = _TokenDifferenceKind.COMMENT;
1772 if (oldComment is DocumentationCommentToken || 1771 if (oldComment is DocumentationCommentToken &&
1773 newComment is DocumentationCommentToken) { 1772 newComment is DocumentationCommentToken) {
1774 diffKind = _TokenDifferenceKind.COMMENT_DOC; 1773 diffKind = _TokenDifferenceKind.COMMENT_DOC;
1775 } 1774 }
1776 return new _TokenPair(diffKind, oldToken, newToken); 1775 return new _TokenPair(diffKind, oldToken, newToken);
1777 } 1776 }
1778 } 1777 }
1779 // next tokens 1778 // next tokens
1780 oldToken = oldToken.previous; 1779 oldToken = oldToken.previous;
1781 newToken = newToken.previous; 1780 newToken = newToken.previous;
1782 } 1781 }
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 @override 2096 @override
2098 String toString() => name; 2097 String toString() => name;
2099 } 2098 }
2100 2099
2101 class _TokenPair { 2100 class _TokenPair {
2102 final _TokenDifferenceKind kind; 2101 final _TokenDifferenceKind kind;
2103 final Token oldToken; 2102 final Token oldToken;
2104 final Token newToken; 2103 final Token newToken;
2105 _TokenPair(this.kind, this.oldToken, this.newToken); 2104 _TokenPair(this.kind, this.oldToken, this.newToken);
2106 } 2105 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/incremental_logger.dart ('k') | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698