| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.task.dart; | 5 library analyzer.src.task.dart; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'package:analyzer/src/context/cache.dart'; | 9 import 'package:analyzer/src/context/cache.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 2935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2946 InferStaticVariableTask( | 2946 InferStaticVariableTask( |
| 2947 InternalAnalysisContext context, VariableElement variable) | 2947 InternalAnalysisContext context, VariableElement variable) |
| 2948 : super(context, variable); | 2948 : super(context, variable); |
| 2949 | 2949 |
| 2950 /** | 2950 /** |
| 2951 * Return the declaration of the target within the given compilation [unit]. | 2951 * Return the declaration of the target within the given compilation [unit]. |
| 2952 * Throw an exception if the declaration cannot be found. | 2952 * Throw an exception if the declaration cannot be found. |
| 2953 */ | 2953 */ |
| 2954 VariableDeclaration getDeclaration(CompilationUnit unit) { | 2954 VariableDeclaration getDeclaration(CompilationUnit unit) { |
| 2955 VariableElement variable = target; | 2955 VariableElement variable = target; |
| 2956 // Usually: Type ^name = ... | 2956 AstNode node = new NodeLocator2(variable.nameOffset).searchWithin(unit); |
| 2957 // Sometimes there is no space after the type: List<Type>^name = ... | |
| 2958 // So, we need to use an offset within (or right after) the name: | |
| 2959 // Type n^ame = | |
| 2960 // List<Type>n^ame = | |
| 2961 // Type x^= | |
| 2962 int searchOffset = variable.nameOffset + 1; | |
| 2963 NodeLocator locator = new NodeLocator(searchOffset); | |
| 2964 AstNode node = locator.searchWithin(unit); | |
| 2965 VariableDeclaration declaration = | 2957 VariableDeclaration declaration = |
| 2966 node.getAncestor((AstNode ancestor) => ancestor is VariableDeclaration); | 2958 node.getAncestor((AstNode ancestor) => ancestor is VariableDeclaration); |
| 2967 if (declaration == null || declaration.name != node) { | 2959 if (declaration == null || declaration.name != node) { |
| 2968 throw new AnalysisException( | 2960 throw new AnalysisException( |
| 2969 "Failed to find the declaration of the variable " | 2961 "Failed to find the declaration of the variable " |
| 2970 "${variable.displayName} in ${variable.source}"); | 2962 "${variable.displayName} in ${variable.source}"); |
| 2971 } | 2963 } |
| 2972 return declaration; | 2964 return declaration; |
| 2973 } | 2965 } |
| 2974 } | 2966 } |
| (...skipping 2299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5274 | 5266 |
| 5275 @override | 5267 @override |
| 5276 bool moveNext() { | 5268 bool moveNext() { |
| 5277 if (_newSources.isEmpty) { | 5269 if (_newSources.isEmpty) { |
| 5278 return false; | 5270 return false; |
| 5279 } | 5271 } |
| 5280 currentTarget = _newSources.removeLast(); | 5272 currentTarget = _newSources.removeLast(); |
| 5281 return true; | 5273 return true; |
| 5282 } | 5274 } |
| 5283 } | 5275 } |
| OLD | NEW |