Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(929)

Unified Diff: pkg/analyzer/lib/src/task/dart.dart

Issue 1484713002: Issue 25030. Fix for searching variable declaration when there is no whitespace after the type. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/task/dart.dart
diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart
index e0d8155afa08f6519739f633e500e49bf50ff5d9..f347a8a84dad00ba578e27c72775754ee2f7383e 100644
--- a/pkg/analyzer/lib/src/task/dart.dart
+++ b/pkg/analyzer/lib/src/task/dart.dart
@@ -1836,7 +1836,7 @@ class ComputeConstantValueTask extends ConstantEvaluationAnalysisTask {
* static variable whose type should be inferred.
*/
class ComputeInferableStaticVariableDependenciesTask
- extends ConstantEvaluationAnalysisTask {
+ extends InferStaticVariableTask {
/**
* The name of the [RESOLVED_UNIT5] input.
*/
@@ -1860,19 +1860,11 @@ class ComputeInferableStaticVariableDependenciesTask
//
// Prepare inputs.
//
- VariableElement variable = target;
CompilationUnit unit = getRequiredInput(UNIT_INPUT);
//
// Compute dependencies.
//
- NodeLocator locator = new NodeLocator(variable.nameOffset);
- AstNode node = locator.searchWithin(unit);
- VariableDeclaration declaration =
- node.getAncestor((AstNode ancestor) => ancestor is VariableDeclaration);
- if (declaration == null || declaration.name != node) {
- throw new AnalysisException(
- "NodeLocator failed to find a variable's declaration");
- }
+ VariableDeclaration declaration = getDeclaration(unit);
VariableGatherer gatherer = new VariableGatherer(_isInferableStatic);
declaration.initializer.accept(gatherer);
//
@@ -2027,7 +2019,7 @@ class ComputeLibraryCycleTask extends SourceBasedAnalysisTask {
* A task that computes the [PROPAGABLE_VARIABLE_DEPENDENCIES] for a variable.
*/
class ComputePropagableVariableDependenciesTask
- extends ConstantEvaluationAnalysisTask {
+ extends InferStaticVariableTask {
/**
* The name of the [RESOLVED_UNIT5] input.
*/
@@ -2051,19 +2043,11 @@ class ComputePropagableVariableDependenciesTask
//
// Prepare inputs.
//
- VariableElement variable = target;
CompilationUnit unit = getRequiredInput(UNIT_INPUT);
//
// Compute dependencies.
//
- NodeLocator locator = new NodeLocator(variable.nameOffset);
- AstNode node = locator.searchWithin(unit);
- VariableDeclaration declaration =
- node.getAncestor((AstNode ancestor) => ancestor is VariableDeclaration);
- if (declaration == null || declaration.name != node) {
- throw new AnalysisException(
- "NodeLocator failed to find a variable's declaration");
- }
+ VariableDeclaration declaration = getDeclaration(unit);
VariableGatherer gatherer = new VariableGatherer(_isPropagable);
declaration.initializer.accept(gatherer);
//
@@ -2969,13 +2953,21 @@ abstract class InferStaticVariableTask extends ConstantEvaluationAnalysisTask {
*/
VariableDeclaration getDeclaration(CompilationUnit unit) {
VariableElement variable = target;
- NodeLocator locator = new NodeLocator(variable.nameOffset);
+ // Usually: Type ^name = ...
+ // Sometimes there is no space after the type: List<Type>^name = ...
+ // So, we need to use an offset within (or right after) the name:
+ // Type n^ame =
+ // List<Type>n^ame =
+ // Type x^=
+ int searchOffset = variable.nameOffset + 1;
+ NodeLocator locator = new NodeLocator(searchOffset);
AstNode node = locator.searchWithin(unit);
VariableDeclaration declaration =
node.getAncestor((AstNode ancestor) => ancestor is VariableDeclaration);
if (declaration == null || declaration.name != node) {
throw new AnalysisException(
- "Failed to find the declaration of the variable ${variable.displayName} in ${variable.source}");
+ "Failed to find the declaration of the variable "
+ "${variable.displayName} in ${variable.source}");
}
return declaration;
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/dart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698