From 89fd468b894f6d1340a05a6ec4cebe28de3c8d2d Mon Sep 17 00:00:00 2001 From: danrubel Date: Tue, 7 Aug 2018 16:07:09 +0000 Subject: [PATCH] remove unused DocumentationCommentToken.references field Change-Id: Ia35dfe2c69d4f35d3a54dd0fcb026de23d888d1c Reviewed-on: https://dart-review.googlesource.com/68520 Reviewed-by: Brian Wilkerson --- pkg/analyzer/lib/src/dart/ast/ast.dart | 2 +- pkg/analyzer/lib/src/dart/ast/utilities.dart | 25 ++++++++++++------- pkg/analyzer/lib/src/generated/parser.dart | 2 -- pkg/analyzer/test/generated/parser_test.dart | 15 +++-------- .../lib/src/fasta/parser/parser.dart | 2 -- .../lib/src/fasta/scanner/token.dart | 11 ++------ pkg/front_end/lib/src/scanner/token.dart | 14 +---------- 7 files changed, 24 insertions(+), 47 deletions(-) diff --git a/pkg/analyzer/lib/src/dart/ast/ast.dart b/pkg/analyzer/lib/src/dart/ast/ast.dart index 409d2197733f8..7a6d5222953de 100644 --- a/pkg/analyzer/lib/src/dart/ast/ast.dart +++ b/pkg/analyzer/lib/src/dart/ast/ast.dart @@ -2206,7 +2206,7 @@ class CommentReferenceImpl extends AstNodeImpl implements CommentReference { } @override - Token get beginToken => _identifier.beginToken; + Token get beginToken => newKeyword ?? _identifier.beginToken; @override Iterable get childEntities => diff --git a/pkg/analyzer/lib/src/dart/ast/utilities.dart b/pkg/analyzer/lib/src/dart/ast/utilities.dart index b942974806919..f0966b146bf5f 100644 --- a/pkg/analyzer/lib/src/dart/ast/utilities.dart +++ b/pkg/analyzer/lib/src/dart/ast/utilities.dart @@ -259,9 +259,22 @@ class AstCloner implements AstVisitor { } @override - CommentReference visitCommentReference(CommentReference node) => - astFactory.commentReference( - cloneToken(node.newKeyword), cloneNode(node.identifier)); + CommentReference visitCommentReference(CommentReference node) { + Token token = node.beginToken; + Token lastCloned = new Token.eof(-1); + while (token != null) { + Token clone = token.copy(); + _clonedTokens[token] = clone; + lastCloned.setNext(clone); + lastCloned = clone; + if (token.isEof) { + break; + } + token = token.next; + } + return astFactory.commentReference( + cloneToken(node.newKeyword), cloneNode(node.identifier)); + } @override CompilationUnit visitCompilationUnit(CompilationUnit node) { @@ -1001,12 +1014,6 @@ class AstCloner implements AstVisitor { CommentToken c2 = clone.precedingComments; while (c1 != null && c2 != null) { _clonedTokens[c1] = c2; - if (c1 is DocumentationCommentToken && - c2 is DocumentationCommentToken) { - for (int i = 0; i < c1.references.length; i++) { - _clonedTokens[c1.references[i]] = c2.references[i]; - } - } c1 = c1.next; c2 = c2.next; } diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart index 94226468d15dc..4e0133d8fbb37 100644 --- a/pkg/analyzer/lib/src/generated/parser.dart +++ b/pkg/analyzer/lib/src/generated/parser.dart @@ -1901,7 +1901,6 @@ class Parser { comment.substring(leftIndex + 1, rightIndex), nameOffset); if (reference != null) { references.add(reference); - token.references.add(reference.beginToken); } } } @@ -1922,7 +1921,6 @@ class Parser { nameToken.setNext(new Token.eof(nameToken.end)); references.add(astFactory.commentReference( null, astFactory.simpleIdentifier(nameToken))); - token.references.add(nameToken); // next character rightIndex = leftIndex + 1; } diff --git a/pkg/analyzer/test/generated/parser_test.dart b/pkg/analyzer/test/generated/parser_test.dart index f06a44bfa22cb..adfc02243e904 100644 --- a/pkg/analyzer/test/generated/parser_test.dart +++ b/pkg/analyzer/test/generated/parser_test.dart @@ -13694,16 +13694,13 @@ abstract class Foo {} List references = parser.parseCommentReferences(tokens); expectNotNullIfNoErrors(references); assertNoErrors(); - List tokenReferences = token.references; expect(references, hasLength(2)); - expect(tokenReferences, hasLength(2)); { CommentReference reference = references[0]; expect(reference, isNotNull); expect(reference.identifier, isNotNull); expect(reference.offset, 12); - // the reference is recorded in the comment token - Token referenceToken = tokenReferences[0]; + Token referenceToken = reference.identifier.beginToken; expect(referenceToken.offset, 12); expect(referenceToken.lexeme, 'a'); } @@ -13712,8 +13709,7 @@ abstract class Foo {} expect(reference, isNotNull); expect(reference.identifier, isNotNull); expect(reference.offset, 20); - // the reference is recorded in the comment token - Token referenceToken = tokenReferences[1]; + Token referenceToken = reference.identifier.beginToken; expect(referenceToken.offset, 20); expect(referenceToken.lexeme, 'bb'); } @@ -13727,12 +13723,10 @@ abstract class Foo {} parser.parseCommentReferences([docToken]); expectNotNullIfNoErrors(references); assertNoErrors(); - expect(docToken.references, hasLength(1)); expect(references, hasLength(1)); - Token referenceToken = docToken.references[0]; CommentReference reference = references[0]; + Token referenceToken = reference.identifier.beginToken; expect(reference, isNotNull); - expect(docToken.references[0], same(reference.beginToken)); expect(reference.identifier, isNotNull); expect(reference.identifier.isSynthetic, isTrue); expect(reference.identifier.name, ""); @@ -13750,10 +13744,9 @@ abstract class Foo {} parser.parseCommentReferences([docToken]); expectNotNullIfNoErrors(references); assertNoErrors(); - expect(docToken.references, hasLength(1)); expect(references, hasLength(1)); - Token referenceToken = docToken.references[0]; CommentReference reference = references[0]; + Token referenceToken = reference.identifier.beginToken; expect(reference, isNotNull); expect(referenceToken, same(reference.beginToken)); expect(reference.identifier, isNotNull); diff --git a/pkg/front_end/lib/src/fasta/parser/parser.dart b/pkg/front_end/lib/src/fasta/parser/parser.dart index c3071fd457373..73a08d7fb70c7 100644 --- a/pkg/front_end/lib/src/fasta/parser/parser.dart +++ b/pkg/front_end/lib/src/fasta/parser/parser.dart @@ -6036,7 +6036,6 @@ class Parser { if (token.isUserDefinableOperator) { if (token.next.isEof) { listener.handleCommentReference(newKeyword, prefix, period, token); - commentToken.references.add(begin); return; } } else { @@ -6044,7 +6043,6 @@ class Parser { if (token.next.isEof) { if (token.isIdentifier) { listener.handleCommentReference(newKeyword, prefix, period, token); - commentToken.references.add(begin); return; } Keyword keyword = token.keyword; diff --git a/pkg/front_end/lib/src/fasta/scanner/token.dart b/pkg/front_end/lib/src/fasta/scanner/token.dart index bd837c10c18dd..f10081dbd8d78 100644 --- a/pkg/front_end/lib/src/fasta/scanner/token.dart +++ b/pkg/front_end/lib/src/fasta/scanner/token.dart @@ -189,9 +189,6 @@ class CommentToken extends StringToken implements analyzer.CommentToken { class DartDocToken extends CommentToken implements analyzer.DocumentationCommentToken { - @override - final List references = []; - /** * Creates a lazy comment token. If [canonicalize] is true, the string * is canonicalized before the token is created. @@ -214,12 +211,8 @@ class DartDocToken extends CommentToken : super._(type, valueOrLazySubstring, charOffset); @override - DartDocToken copy() { - DartDocToken copy = - new DartDocToken._(type, valueOrLazySubstring, charOffset); - references.forEach((ref) => copy.references.add(ref.copy())); - return copy; - } + DartDocToken copy() => + new DartDocToken._(type, valueOrLazySubstring, charOffset); } /** diff --git a/pkg/front_end/lib/src/scanner/token.dart b/pkg/front_end/lib/src/scanner/token.dart index 3543578e95ffa..d1c6d0e8d2acc 100644 --- a/pkg/front_end/lib/src/scanner/token.dart +++ b/pkg/front_end/lib/src/scanner/token.dart @@ -107,13 +107,6 @@ class CommentToken extends StringToken { * A documentation comment token. */ class DocumentationCommentToken extends CommentToken { - /** - * The references embedded within the documentation comment. - * This list will be empty unless this is a documentation comment that has - * references embedded within it. - */ - final List references = []; - /** * Initialize a newly created token to represent a token of the given [type] * with the given [value] at the given [offset]. @@ -122,12 +115,7 @@ class DocumentationCommentToken extends CommentToken { : super(type, value, offset); @override - CommentToken copy() { - DocumentationCommentToken copy = - new DocumentationCommentToken(type, _value, offset); - references.forEach((ref) => copy.references.add(ref.copy())); - return copy; - } + CommentToken copy() => new DocumentationCommentToken(type, _value, offset); } /**