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

Unified Diff: pkg/analyzer/lib/src/generated/incremental_resolver.dart

Issue 980513002: Issue 22644. Fix for removing non-Dartdoc comments before a declaration. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/incremental_resolver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/incremental_resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/incremental_resolver.dart b/pkg/analyzer/lib/src/generated/incremental_resolver.dart
index 44cca00c54940de33f5b56a8bf09eb6337a07244..2fdf505ef7d000d67b40316b2bab9320487ab261 100644
--- a/pkg/analyzer/lib/src/generated/incremental_resolver.dart
+++ b/pkg/analyzer/lib/src/generated/incremental_resolver.dart
@@ -1189,9 +1189,15 @@ class PoorMansIncrementalResolver {
_updateEndOld = endOffsetOld;
_updateEndNew = endOffsetNew;
_updateDelta = newUnit.length - _oldUnit.length;
+ // A comment change.
+ if (firstPair.kind == _TokenDifferenceKind.COMMENT) {
+ bool success = _resolveComment(newUnit, firstPair);
+ logger.log('Comment change: $success');
+ return success;
+ }
// A Dart documentation comment change.
if (firstPair.kind == _TokenDifferenceKind.COMMENT_DOC) {
- bool success = _resolveComment(_oldUnit, newUnit, firstPair);
+ bool success = _resolveCommentDoc(newUnit, firstPair);
logger.log('Documentation comment resolved: $success');
return success;
}
@@ -1309,11 +1315,32 @@ class PoorMansIncrementalResolver {
}
/**
+ * Attempts to resolve a comment change.
+ * Returns `true` if success.
+ */
+ bool _resolveComment(CompilationUnit newUnit, _TokenPair firstPair) {
+ Token oldToken = firstPair.oldToken;
+ Token newToken = firstPair.newToken;
+ CommentToken newComments = newToken.precedingComments;
+ // update token references
+ _updateOffset = oldToken.offset - 1;
+ _shiftTokens(firstPair.oldToken);
+ _setPrecedingComments(oldToken, newComments);
+ // update elements
+ IncrementalResolver incrementalResolver = new IncrementalResolver(
+ _unitElement, _updateOffset, _updateEndOld, _updateEndNew);
+ incrementalResolver._updateElementNameOffsets();
+ incrementalResolver._shiftEntryErrors();
+ _updateEntry();
+ // OK
+ return true;
+ }
+
+ /**
* Attempts to resolve a documentation comment change.
* Returns `true` if success.
*/
- bool _resolveComment(
- CompilationUnit oldUnit, CompilationUnit newUnit, _TokenPair firstPair) {
+ bool _resolveCommentDoc(CompilationUnit newUnit, _TokenPair firstPair) {
Token oldToken = firstPair.oldToken;
Token newToken = firstPair.newToken;
CommentToken oldComments = oldToken.precedingComments;
@@ -1324,7 +1351,7 @@ class PoorMansIncrementalResolver {
// find nodes
int offset = oldComments.offset;
logger.log('offset: $offset');
- Comment oldComment = _findNodeCovering(oldUnit, offset, offset);
+ Comment oldComment = _findNodeCovering(_oldUnit, offset, offset);
Comment newComment = _findNodeCovering(newUnit, offset, offset);
logger.log('oldComment.beginToken: ${oldComment.beginToken}');
logger.log('newComment.beginToken: ${newComment.beginToken}');
@@ -1355,6 +1382,40 @@ class PoorMansIncrementalResolver {
return token;
}
+ /**
+ * Set the given [comment] as a "precedingComments" for [token].
+ */
+ void _setPrecedingComments(Token token, CommentToken comment) {
+ if (token is BeginTokenWithComment) {
+ token.precedingComments = comment;
+ } else if (token is KeywordTokenWithComment) {
+ token.precedingComments = comment;
+ } else if (token is KeywordToken) {
+ KeywordTokenWithComment newToken =
+ new KeywordTokenWithComment(token.keyword, token.offset, comment);
+ token.previous.setNext(newToken);
+ newToken.setNext(token.next);
+ if (_oldUnit.beginToken == token) {
+ _oldUnit.beginToken = newToken;
+ }
+ } else if (token is StringTokenWithComment) {
+ token.precedingComments = comment;
+ } else if (token is StringToken) {
+ StringTokenWithComment newToken = new StringTokenWithComment(
+ token.type, token.value(), token.offset, comment);
+ token.previous.setNext(newToken);
+ newToken.setNext(token.next);
+ if (_oldUnit.beginToken == token) {
+ _oldUnit.beginToken = newToken;
+ }
+ } else if (token is TokenWithComment) {
+ token.precedingComments = comment;
+ } else {
+ Type parentType = token != null ? token.runtimeType : null;
+ throw new AnalysisException('Uknown parent token type: $parentType');
+ }
+ }
+
void _shiftTokens(Token token) {
while (token != null) {
if (token.offset > _updateOffset) {
@@ -1518,24 +1579,6 @@ class PoorMansIncrementalResolver {
}
return count;
}
-
- /**
- * Set the given [comment] as a "precedingComments" for [parent].
- */
- static void _setPrecedingComments(Token parent, CommentToken comment) {
- if (parent is BeginTokenWithComment) {
- parent.precedingComments = comment;
- } else if (parent is KeywordTokenWithComment) {
- parent.precedingComments = comment;
- } else if (parent is StringTokenWithComment) {
- parent.precedingComments = comment;
- } else if (parent is TokenWithComment) {
- parent.precedingComments = comment;
- } else {
- Type parentType = parent != null ? parent.runtimeType : null;
- throw new AnalysisException('Uknown parent token type: $parentType');
- }
- }
}
/**
« 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