| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of tree; | 5 part of tree; |
| 6 | 6 |
| 7 abstract class Visitor<R> { | 7 abstract class Visitor<R> { |
| 8 const Visitor(); | 8 const Visitor(); |
| 9 | 9 |
| 10 abstract R visitNode(Node node); | 10 abstract R visitNode(Node node); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 if (first != null) { | 86 if (first != null) { |
| 87 token = first.getBeginToken(); | 87 token = first.getBeginToken(); |
| 88 } | 88 } |
| 89 if (token == null && second != null) { | 89 if (token == null && second != null) { |
| 90 // [token] might be null even when [first] is not, e.g. for empty Modifiers. | 90 // [token] might be null even when [first] is not, e.g. for empty Modifiers. |
| 91 token = second.getBeginToken(); | 91 token = second.getBeginToken(); |
| 92 } | 92 } |
| 93 return token; | 93 return token; |
| 94 } | 94 } |
| 95 | 95 |
| 96 class NodeAssertionFailure implements Exception { | |
| 97 final Node node; | |
| 98 final String message; | |
| 99 NodeAssertionFailure(this.node, this.message); | |
| 100 } | |
| 101 | |
| 102 /** | 96 /** |
| 103 * A node in a syntax tree. | 97 * A node in a syntax tree. |
| 104 * | 98 * |
| 105 * The abstract part of "abstract syntax tree" is invalidated when | 99 * The abstract part of "abstract syntax tree" is invalidated when |
| 106 * supporting tools such as code formatting. These tools need concrete | 100 * supporting tools such as code formatting. These tools need concrete |
| 107 * syntax such as parentheses and no constant folding. | 101 * syntax such as parentheses and no constant folding. |
| 108 * | 102 * |
| 109 * We support these tools by storing additional references back to the | 103 * We support these tools by storing additional references back to the |
| 110 * token stream. These references are stored in fields ending with | 104 * token stream. These references are stored in fields ending with |
| 111 * "Token". | 105 * "Token". |
| (...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 return isInterpolationCache; | 1291 return isInterpolationCache; |
| 1298 } | 1292 } |
| 1299 | 1293 |
| 1300 /** | 1294 /** |
| 1301 * Retrieve a single DartString that represents this entire juxtaposition | 1295 * Retrieve a single DartString that represents this entire juxtaposition |
| 1302 * of string literals. | 1296 * of string literals. |
| 1303 * Should only be called if [isInterpolation] returns false. | 1297 * Should only be called if [isInterpolation] returns false. |
| 1304 */ | 1298 */ |
| 1305 DartString get dartString { | 1299 DartString get dartString { |
| 1306 if (isInterpolation) { | 1300 if (isInterpolation) { |
| 1307 throw new NodeAssertionFailure(this, | 1301 throw new SpannableAssertionFailure( |
| 1308 "Getting dartString on interpolation;"); | 1302 this, "Getting dartString on interpolation;"); |
| 1309 } | 1303 } |
| 1310 if (dartStringCache == null) { | 1304 if (dartStringCache == null) { |
| 1311 DartString firstString = first.accept(const GetDartStringVisitor()); | 1305 DartString firstString = first.accept(const GetDartStringVisitor()); |
| 1312 DartString secondString = second.accept(const GetDartStringVisitor()); | 1306 DartString secondString = second.accept(const GetDartStringVisitor()); |
| 1313 if (firstString == null || secondString == null) { | 1307 if (firstString == null || secondString == null) { |
| 1314 return null; | 1308 return null; |
| 1315 } | 1309 } |
| 1316 dartStringCache = new DartString.concat(firstString, secondString); | 1310 dartStringCache = new DartString.concat(firstString, secondString); |
| 1317 } | 1311 } |
| 1318 return dartStringCache; | 1312 return dartStringCache; |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2017 * argument). | 2011 * argument). |
| 2018 * | 2012 * |
| 2019 * TODO(ahe): This method is controversial, the team needs to discuss | 2013 * TODO(ahe): This method is controversial, the team needs to discuss |
| 2020 * if top-level methods are acceptable and what naming conventions to | 2014 * if top-level methods are acceptable and what naming conventions to |
| 2021 * use. | 2015 * use. |
| 2022 */ | 2016 */ |
| 2023 initializerDo(Node node, f(Node node)) { | 2017 initializerDo(Node node, f(Node node)) { |
| 2024 SendSet send = node.asSendSet(); | 2018 SendSet send = node.asSendSet(); |
| 2025 if (send != null) return f(send.arguments.head); | 2019 if (send != null) return f(send.arguments.head); |
| 2026 } | 2020 } |
| OLD | NEW |