| 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 services.completion.suggestion.builder; | 5 library services.completion.suggestion.builder; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/protocol_server.dart' as protocol; | 10 import 'package:analysis_server/src/protocol_server.dart' as protocol; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 mixinTypes.forEach((TypeName type) { | 150 mixinTypes.forEach((TypeName type) { |
| 151 visit(type); | 151 visit(type); |
| 152 }); | 152 }); |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 /** | 157 /** |
| 158 * Starting with the given class node, traverse the inheritence hierarchy | 158 * Starting with the given class node, traverse the inheritence hierarchy |
| 159 * calling the given functions with each non-null non-empty inherited class | 159 * calling the given functions with each non-null non-empty inherited class |
| 160 * declaration. For each locally defined class declaration, call [local]. | 160 * declaration. For each locally defined declaration, call [localDeclaration]. |
| 161 * For each class identifier in the hierarchy that is not defined locally, | 161 * For each class identifier in the hierarchy that is not defined locally, |
| 162 * call the [imported] function. | 162 * call the [importedTypeName] function. |
| 163 */ | 163 */ |
| 164 void visitInheritedTypes(ClassDeclaration node, | 164 void visitInheritedTypes(ClassDeclaration node, |
| 165 void local(ClassDeclaration classNode), void imported(String typeName)) { | 165 {void localDeclaration(ClassDeclaration classNode), |
| 166 void importedTypeName(String typeName)}) { |
| 166 CompilationUnit unit = node.getAncestor((p) => p is CompilationUnit); | 167 CompilationUnit unit = node.getAncestor((p) => p is CompilationUnit); |
| 167 List<ClassDeclaration> todo = new List<ClassDeclaration>(); | 168 List<ClassDeclaration> todo = new List<ClassDeclaration>(); |
| 168 todo.add(node); | 169 todo.add(node); |
| 169 Set<String> visited = new Set<String>(); | 170 Set<String> visited = new Set<String>(); |
| 170 while (todo.length > 0) { | 171 while (todo.length > 0) { |
| 171 node = todo.removeLast(); | 172 node = todo.removeLast(); |
| 172 visitInheritedTypeNames(node, (String name) { | 173 visitInheritedTypeNames(node, (String name) { |
| 173 if (visited.add(name)) { | 174 if (visited.add(name)) { |
| 174 var classNode = unit.declarations.firstWhere((member) { | 175 var classNode = unit.declarations.firstWhere((member) { |
| 175 if (member is ClassDeclaration) { | 176 if (member is ClassDeclaration) { |
| 176 SimpleIdentifier id = member.name; | 177 SimpleIdentifier id = member.name; |
| 177 if (id != null && id.name == name) { | 178 if (id != null && id.name == name) { |
| 178 return true; | 179 return true; |
| 179 } | 180 } |
| 180 } | 181 } |
| 181 return false; | 182 return false; |
| 182 }, orElse: () => null); | 183 }, orElse: () => null); |
| 183 if (classNode is ClassDeclaration) { | 184 if (classNode is ClassDeclaration) { |
| 184 local(classNode); | 185 if (localDeclaration != null) { |
| 186 localDeclaration(classNode); |
| 187 } |
| 185 todo.add(classNode); | 188 todo.add(classNode); |
| 186 } else { | 189 } else { |
| 187 imported(name); | 190 if (importedTypeName != null) { |
| 191 importedTypeName(name); |
| 192 } |
| 188 } | 193 } |
| 189 } | 194 } |
| 190 }); | 195 }); |
| 191 } | 196 } |
| 192 } | 197 } |
| 193 | 198 |
| 194 /** | 199 /** |
| 195 * Common mixin for sharing behavior | 200 * Common mixin for sharing behavior |
| 196 */ | 201 */ |
| 197 abstract class ElementSuggestionBuilder { | 202 abstract class ElementSuggestionBuilder { |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 * or `false` if [computeFull] should be called. | 615 * or `false` if [computeFull] should be called. |
| 611 */ | 616 */ |
| 612 bool computeFast(AstNode node); | 617 bool computeFast(AstNode node); |
| 613 | 618 |
| 614 /** | 619 /** |
| 615 * Return a future that computes the suggestions given a fully resolved AST. | 620 * Return a future that computes the suggestions given a fully resolved AST. |
| 616 * The future returns `true` if suggestions were added, else `false`. | 621 * The future returns `true` if suggestions were added, else `false`. |
| 617 */ | 622 */ |
| 618 Future<bool> computeFull(AstNode node); | 623 Future<bool> computeFull(AstNode node); |
| 619 } | 624 } |
| OLD | NEW |