Skip to content

Commit

Permalink
remove unused DocumentationCommentToken.references field
Browse files Browse the repository at this point in the history
Change-Id: Ia35dfe2c69d4f35d3a54dd0fcb026de23d888d1c
Reviewed-on: https://dart-review.googlesource.com/68520
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
  • Loading branch information
danrubel authored and commit-bot@chromium.org committed Aug 7, 2018
1 parent 49b1844 commit 89fd468
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 47 deletions.
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2206,7 +2206,7 @@ class CommentReferenceImpl extends AstNodeImpl implements CommentReference {
}

@override
Token get beginToken => _identifier.beginToken;
Token get beginToken => newKeyword ?? _identifier.beginToken;

@override
Iterable<SyntacticEntity> get childEntities =>
Expand Down
25 changes: 16 additions & 9 deletions pkg/analyzer/lib/src/dart/ast/utilities.dart
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,22 @@ class AstCloner implements AstVisitor<AstNode> {
}

@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) {
Expand Down Expand Up @@ -1001,12 +1014,6 @@ class AstCloner implements AstVisitor<AstNode> {
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;
}
Expand Down
2 changes: 0 additions & 2 deletions pkg/analyzer/lib/src/generated/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,6 @@ class Parser {
comment.substring(leftIndex + 1, rightIndex), nameOffset);
if (reference != null) {
references.add(reference);
token.references.add(reference.beginToken);
}
}
}
Expand All @@ -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;
}
Expand Down
15 changes: 4 additions & 11 deletions pkg/analyzer/test/generated/parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13694,16 +13694,13 @@ abstract class Foo {}
List<CommentReference> references = parser.parseCommentReferences(tokens);
expectNotNullIfNoErrors(references);
assertNoErrors();
List<Token> 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');
}
Expand All @@ -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');
}
Expand All @@ -13727,12 +13723,10 @@ abstract class Foo {}
parser.parseCommentReferences(<DocumentationCommentToken>[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, "");
Expand All @@ -13750,10 +13744,9 @@ abstract class Foo {}
parser.parseCommentReferences(<DocumentationCommentToken>[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);
Expand Down
2 changes: 0 additions & 2 deletions pkg/front_end/lib/src/fasta/parser/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6036,15 +6036,13 @@ class Parser {
if (token.isUserDefinableOperator) {
if (token.next.isEof) {
listener.handleCommentReference(newKeyword, prefix, period, token);
commentToken.references.add(begin);
return;
}
} else {
token = operatorKeyword ?? token;
if (token.next.isEof) {
if (token.isIdentifier) {
listener.handleCommentReference(newKeyword, prefix, period, token);
commentToken.references.add(begin);
return;
}
Keyword keyword = token.keyword;
Expand Down
11 changes: 2 additions & 9 deletions pkg/front_end/lib/src/fasta/scanner/token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ class CommentToken extends StringToken implements analyzer.CommentToken {

class DartDocToken extends CommentToken
implements analyzer.DocumentationCommentToken {
@override
final List<Token> references = <Token>[];

/**
* Creates a lazy comment token. If [canonicalize] is true, the string
* is canonicalized before the token is created.
Expand All @@ -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);
}

/**
Expand Down
14 changes: 1 addition & 13 deletions pkg/front_end/lib/src/scanner/token.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Token> references = <Token>[];

/**
* Initialize a newly created token to represent a token of the given [type]
* with the given [value] at the given [offset].
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 89fd468

Please sign in to comment.