| 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/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 * Initialize a newly created AST cloner to optionally clone tokens while | 53 * Initialize a newly created AST cloner to optionally clone tokens while |
| 54 * cloning AST nodes if [cloneTokens] is `true`. | 54 * cloning AST nodes if [cloneTokens] is `true`. |
| 55 * | 55 * |
| 56 * TODO(brianwilkerson) Change this to be a named parameter. | 56 * TODO(brianwilkerson) Change this to be a named parameter. |
| 57 */ | 57 */ |
| 58 AstCloner([this.cloneTokens = false]); | 58 AstCloner([this.cloneTokens = false]); |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Return a clone of the given [node]. | 61 * Return a clone of the given [node]. |
| 62 */ | 62 */ |
| 63 AstNode cloneNode(AstNode node) { | 63 AstNode/*=E*/ cloneNode/*<E extends AstNode>*/(AstNode/*=E*/ node) { |
| 64 if (node == null) { | 64 if (node == null) { |
| 65 return null; | 65 return null; |
| 66 } | 66 } |
| 67 return node.accept(this) as AstNode; | 67 return node.accept(this) as AstNode/*=E*/; |
| 68 } | 68 } |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * Return a list containing cloned versions of the nodes in the given list of | 71 * Return a list containing cloned versions of the nodes in the given list of |
| 72 * [nodes]. | 72 * [nodes]. |
| 73 */ | 73 */ |
| 74 List<AstNode> cloneNodeList(NodeList nodes) { | 74 List<AstNode/*=E*/ > cloneNodeList/*<E extends AstNode>*/( |
| 75 NodeList/*<E>*/ nodes) { |
| 75 int count = nodes.length; | 76 int count = nodes.length; |
| 76 List clonedNodes = new List(); | 77 List/*<E>*/ clonedNodes = new List/*<E>*/(); |
| 77 for (int i = 0; i < count; i++) { | 78 for (int i = 0; i < count; i++) { |
| 78 clonedNodes.add((nodes[i]).accept(this) as AstNode); | 79 clonedNodes.add((nodes[i]).accept(this) as AstNode/*=E*/); |
| 79 } | 80 } |
| 80 return clonedNodes; | 81 return clonedNodes; |
| 81 } | 82 } |
| 82 | 83 |
| 83 /** | 84 /** |
| 84 * Clone the given [token] if tokens are supposed to be cloned. | 85 * Clone the given [token] if tokens are supposed to be cloned. |
| 85 */ | 86 */ |
| 86 Token cloneToken(Token token) { | 87 Token cloneToken(Token token) { |
| 87 if (cloneTokens) { | 88 if (cloneTokens) { |
| 88 if (token == null) { | 89 if (token == null) { |
| (...skipping 3518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3607 WithClause visitWithClause(WithClause node) => new WithClause( | 3608 WithClause visitWithClause(WithClause node) => new WithClause( |
| 3608 _mapToken(node.withKeyword), _cloneNodeList(node.mixinTypes)); | 3609 _mapToken(node.withKeyword), _cloneNodeList(node.mixinTypes)); |
| 3609 | 3610 |
| 3610 @override | 3611 @override |
| 3611 YieldStatement visitYieldStatement(YieldStatement node) => new YieldStatement( | 3612 YieldStatement visitYieldStatement(YieldStatement node) => new YieldStatement( |
| 3612 _mapToken(node.yieldKeyword), | 3613 _mapToken(node.yieldKeyword), |
| 3613 _mapToken(node.star), | 3614 _mapToken(node.star), |
| 3614 _cloneNode(node.expression), | 3615 _cloneNode(node.expression), |
| 3615 _mapToken(node.semicolon)); | 3616 _mapToken(node.semicolon)); |
| 3616 | 3617 |
| 3617 AstNode _cloneNode(AstNode node) { | 3618 AstNode/*=E*/ _cloneNode/*<E extends AstNode>*/(AstNode/*=E*/ node) { |
| 3618 if (node == null) { | 3619 if (node == null) { |
| 3619 return null; | 3620 return null; |
| 3620 } | 3621 } |
| 3621 if (identical(node, _oldNode)) { | 3622 if (identical(node, _oldNode)) { |
| 3622 return _newNode; | 3623 return _newNode as AstNode/*=E*/; |
| 3623 } | 3624 } |
| 3624 return node.accept(this) as AstNode; | 3625 return node.accept(this) as AstNode/*=E*/; |
| 3625 } | 3626 } |
| 3626 | 3627 |
| 3627 List _cloneNodeList(NodeList nodes) { | 3628 List/*<E>*/ _cloneNodeList/*<E extends AstNode>*/(NodeList/*<E>*/ nodes) { |
| 3628 List clonedNodes = new List(); | 3629 List/*<E>*/ clonedNodes = new List/*<E>*/(); |
| 3629 for (AstNode node in nodes) { | 3630 for (AstNode/*=E*/ node in nodes) { |
| 3630 clonedNodes.add(_cloneNode(node)); | 3631 clonedNodes.add(_cloneNode(node)); |
| 3631 } | 3632 } |
| 3632 return clonedNodes; | 3633 return clonedNodes; |
| 3633 } | 3634 } |
| 3634 | 3635 |
| 3635 Token _mapToken(Token oldToken) { | 3636 Token _mapToken(Token oldToken) { |
| 3636 if (oldToken == null) { | 3637 if (oldToken == null) { |
| 3637 return null; | 3638 return null; |
| 3638 } | 3639 } |
| 3639 return _tokenMap.get(oldToken); | 3640 return _tokenMap.get(oldToken); |
| (...skipping 4142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7782 * Safely visit the given [token], printing the [suffix] after the token if it | 7783 * Safely visit the given [token], printing the [suffix] after the token if it |
| 7783 * is non-`null`. | 7784 * is non-`null`. |
| 7784 */ | 7785 */ |
| 7785 void _visitTokenWithSuffix(Token token, String suffix) { | 7786 void _visitTokenWithSuffix(Token token, String suffix) { |
| 7786 if (token != null) { | 7787 if (token != null) { |
| 7787 _writer.print(token.lexeme); | 7788 _writer.print(token.lexeme); |
| 7788 _writer.print(suffix); | 7789 _writer.print(suffix); |
| 7789 } | 7790 } |
| 7790 } | 7791 } |
| 7791 } | 7792 } |
| OLD | NEW |