| 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/standard_ast_factory.dart'; | 10 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 * Initialize a newly created AST cloner to optionally clone tokens while | 63 * Initialize a newly created AST cloner to optionally clone tokens while |
| 64 * cloning AST nodes if [cloneTokens] is `true`. | 64 * cloning AST nodes if [cloneTokens] is `true`. |
| 65 * | 65 * |
| 66 * TODO(brianwilkerson) Change this to be a named parameter. | 66 * TODO(brianwilkerson) Change this to be a named parameter. |
| 67 */ | 67 */ |
| 68 AstCloner([this.cloneTokens = false]); | 68 AstCloner([this.cloneTokens = false]); |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * Return a clone of the given [node]. | 71 * Return a clone of the given [node]. |
| 72 */ | 72 */ |
| 73 AstNode/*=E*/ cloneNode/*<E extends AstNode>*/(AstNode/*=E*/ node) { | 73 E cloneNode<E extends AstNode>(E node) { |
| 74 if (node == null) { | 74 if (node == null) { |
| 75 return null; | 75 return null; |
| 76 } | 76 } |
| 77 return node.accept(this) as AstNode/*=E*/; | 77 return node.accept(this) as E; |
| 78 } | 78 } |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * Return a list containing cloned versions of the nodes in the given list of | 81 * Return a list containing cloned versions of the nodes in the given list of |
| 82 * [nodes]. | 82 * [nodes]. |
| 83 */ | 83 */ |
| 84 List<AstNode/*=E*/ > cloneNodeList/*<E extends AstNode>*/(List/*<E>*/ nodes) { | 84 List<E> cloneNodeList<E extends AstNode>(List<E> nodes) { |
| 85 int count = nodes.length; | 85 int count = nodes.length; |
| 86 List/*<E>*/ clonedNodes = new List/*<E>*/(); | 86 List<E> clonedNodes = new List<E>(); |
| 87 for (int i = 0; i < count; i++) { | 87 for (int i = 0; i < count; i++) { |
| 88 clonedNodes.add((nodes[i]).accept(this) as AstNode/*=E*/); | 88 clonedNodes.add((nodes[i]).accept(this) as E); |
| 89 } | 89 } |
| 90 return clonedNodes; | 90 return clonedNodes; |
| 91 } | 91 } |
| 92 | 92 |
| 93 /** | 93 /** |
| 94 * Clone the given [token] if tokens are supposed to be cloned. | 94 * Clone the given [token] if tokens are supposed to be cloned. |
| 95 */ | 95 */ |
| 96 Token cloneToken(Token token) { | 96 Token cloneToken(Token token) { |
| 97 if (cloneTokens) { | 97 if (cloneTokens) { |
| 98 if (token == null) { | 98 if (token == null) { |
| (...skipping 3768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3867 _mapToken(node.withKeyword), _cloneNodeList(node.mixinTypes)); | 3867 _mapToken(node.withKeyword), _cloneNodeList(node.mixinTypes)); |
| 3868 | 3868 |
| 3869 @override | 3869 @override |
| 3870 YieldStatement visitYieldStatement(YieldStatement node) => | 3870 YieldStatement visitYieldStatement(YieldStatement node) => |
| 3871 astFactory.yieldStatement( | 3871 astFactory.yieldStatement( |
| 3872 _mapToken(node.yieldKeyword), | 3872 _mapToken(node.yieldKeyword), |
| 3873 _mapToken(node.star), | 3873 _mapToken(node.star), |
| 3874 _cloneNode(node.expression), | 3874 _cloneNode(node.expression), |
| 3875 _mapToken(node.semicolon)); | 3875 _mapToken(node.semicolon)); |
| 3876 | 3876 |
| 3877 AstNode/*=E*/ _cloneNode/*<E extends AstNode>*/(AstNode/*=E*/ node) { | 3877 E _cloneNode<E extends AstNode>(E node) { |
| 3878 if (node == null) { | 3878 if (node == null) { |
| 3879 return null; | 3879 return null; |
| 3880 } | 3880 } |
| 3881 if (identical(node, _oldNode)) { | 3881 if (identical(node, _oldNode)) { |
| 3882 return _newNode as AstNode/*=E*/; | 3882 return _newNode as E; |
| 3883 } | 3883 } |
| 3884 return node.accept(this) as AstNode/*=E*/; | 3884 return node.accept(this) as E; |
| 3885 } | 3885 } |
| 3886 | 3886 |
| 3887 List/*<E>*/ _cloneNodeList/*<E extends AstNode>*/(NodeList/*<E>*/ nodes) { | 3887 List<E> _cloneNodeList<E extends AstNode>(NodeList<E> nodes) { |
| 3888 List/*<E>*/ clonedNodes = new List/*<E>*/(); | 3888 List<E> clonedNodes = new List<E>(); |
| 3889 for (AstNode/*=E*/ node in nodes) { | 3889 for (E node in nodes) { |
| 3890 clonedNodes.add(_cloneNode(node)); | 3890 clonedNodes.add(_cloneNode(node)); |
| 3891 } | 3891 } |
| 3892 return clonedNodes; | 3892 return clonedNodes; |
| 3893 } | 3893 } |
| 3894 | 3894 |
| 3895 Token _mapToken(Token oldToken) { | 3895 Token _mapToken(Token oldToken) { |
| 3896 if (oldToken == null) { | 3896 if (oldToken == null) { |
| 3897 return null; | 3897 return null; |
| 3898 } | 3898 } |
| 3899 return _tokenMap.get(oldToken); | 3899 return _tokenMap.get(oldToken); |
| (...skipping 5482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9382 if (node.star != null) { | 9382 if (node.star != null) { |
| 9383 sink.write("yield* "); | 9383 sink.write("yield* "); |
| 9384 } else { | 9384 } else { |
| 9385 sink.write("yield "); | 9385 sink.write("yield "); |
| 9386 } | 9386 } |
| 9387 safelyVisitNode(node.expression); | 9387 safelyVisitNode(node.expression); |
| 9388 sink.write(";"); | 9388 sink.write(";"); |
| 9389 return null; | 9389 return null; |
| 9390 } | 9390 } |
| 9391 } | 9391 } |
| OLD | NEW |