OLD | NEW |
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.dart.ast.utilities; | 5 library analyzer.src.dart.ast.utilities; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 cloneNodeList(node.members), | 209 cloneNodeList(node.members), |
210 cloneToken(node.rightBracket)); | 210 cloneToken(node.rightBracket)); |
211 copy.nativeClause = cloneNode(node.nativeClause); | 211 copy.nativeClause = cloneNode(node.nativeClause); |
212 return copy; | 212 return copy; |
213 } | 213 } |
214 | 214 |
215 @override | 215 @override |
216 ClassTypeAlias visitClassTypeAlias(ClassTypeAlias node) { | 216 ClassTypeAlias visitClassTypeAlias(ClassTypeAlias node) { |
217 cloneToken(node.abstractKeyword); | 217 cloneToken(node.abstractKeyword); |
218 return new ClassTypeAlias( | 218 return new ClassTypeAlias( |
219 cloneNode(node.documentationComment), | 219 cloneNode(node.documentationComment), |
220 cloneNodeList(node.metadata), | 220 cloneNodeList(node.metadata), |
221 cloneToken(node.typedefKeyword), | 221 cloneToken(node.typedefKeyword), |
222 cloneNode(node.name), | 222 cloneNode(node.name), |
223 cloneNode(node.typeParameters), | 223 cloneNode(node.typeParameters), |
224 cloneToken(node.equals), | 224 cloneToken(node.equals), |
225 cloneToken(node.abstractKeyword), | 225 cloneToken(node.abstractKeyword), |
226 cloneNode(node.superclass), | 226 cloneNode(node.superclass), |
227 cloneNode(node.withClause), | 227 cloneNode(node.withClause), |
228 cloneNode(node.implementsClause), | 228 cloneNode(node.implementsClause), |
229 cloneToken(node.semicolon)); | 229 cloneToken(node.semicolon)); |
230 } | 230 } |
231 | 231 |
232 @override | 232 @override |
233 Comment visitComment(Comment node) { | 233 Comment visitComment(Comment node) { |
234 if (node.isDocumentation) { | 234 if (node.isDocumentation) { |
235 return Comment.createDocumentationCommentWithReferences( | 235 return Comment.createDocumentationCommentWithReferences( |
236 cloneTokenList(node.tokens), cloneNodeList(node.references)); | 236 cloneTokenList(node.tokens), cloneNodeList(node.references)); |
237 } else if (node.isBlock) { | 237 } else if (node.isBlock) { |
238 return Comment.createBlockComment(cloneTokenList(node.tokens)); | 238 return Comment.createBlockComment(cloneTokenList(node.tokens)); |
239 } | 239 } |
240 return Comment.createEndOfLineComment(cloneTokenList(node.tokens)); | 240 return Comment.createEndOfLineComment(cloneTokenList(node.tokens)); |
241 } | 241 } |
242 | 242 |
243 @override | 243 @override |
244 CommentReference visitCommentReference(CommentReference node) => | 244 CommentReference visitCommentReference(CommentReference node) => |
245 new CommentReference( | 245 new CommentReference( |
246 cloneToken(node.newKeyword), cloneNode(node.identifier)); | 246 cloneToken(node.newKeyword), cloneNode(node.identifier)); |
247 | 247 |
248 @override | 248 @override |
249 CompilationUnit visitCompilationUnit(CompilationUnit node) { | 249 CompilationUnit visitCompilationUnit(CompilationUnit node) { |
250 ScriptTag scriptTag = cloneNode(node.scriptTag); | |
251 List<Directive> directives = cloneNodeList(node.directives); | |
252 List<CompilationUnitMember> declarations = cloneNodeList(node.declarations); | |
253 Token endToken = cloneToken(node.endToken); | |
254 Token beginToken = scriptTag?.beginToken ?? | |
255 (directives.isEmpty ? null : directives.first.beginToken) ?? | |
256 (declarations.isEmpty ? null : declarations.first.beginToken) ?? | |
257 endToken; | |
258 CompilationUnit clone = new CompilationUnit( | 250 CompilationUnit clone = new CompilationUnit( |
259 beginToken, scriptTag, directives, declarations, endToken); | 251 cloneToken(node.beginToken), |
| 252 cloneNode(node.scriptTag), |
| 253 cloneNodeList(node.directives), |
| 254 cloneNodeList(node.declarations), |
| 255 cloneToken(node.endToken)); |
260 clone.lineInfo = node.lineInfo; | 256 clone.lineInfo = node.lineInfo; |
261 return clone; | 257 return clone; |
262 } | 258 } |
263 | 259 |
264 @override | 260 @override |
265 ConditionalExpression visitConditionalExpression( | 261 ConditionalExpression visitConditionalExpression( |
266 ConditionalExpression node) => | 262 ConditionalExpression node) => |
267 new ConditionalExpression( | 263 new ConditionalExpression( |
268 cloneNode(node.condition), | 264 cloneNode(node.condition), |
269 cloneToken(node.question), | 265 cloneToken(node.question), |
(...skipping 6076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6346 * Safely visit the given [token], printing the [suffix] after the token if it | 6342 * Safely visit the given [token], printing the [suffix] after the token if it |
6347 * is non-`null`. | 6343 * is non-`null`. |
6348 */ | 6344 */ |
6349 void _visitTokenWithSuffix(Token token, String suffix) { | 6345 void _visitTokenWithSuffix(Token token, String suffix) { |
6350 if (token != null) { | 6346 if (token != null) { |
6351 _writer.print(token.lexeme); | 6347 _writer.print(token.lexeme); |
6352 _writer.print(suffix); | 6348 _writer.print(suffix); |
6353 } | 6349 } |
6354 } | 6350 } |
6355 } | 6351 } |
OLD | NEW |