| 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.dart.local.declaration.visitor; | 5 library services.completion.dart.local.declaration.visitor; |
| 6 | 6 |
| 7 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; | 7 import 'package:analysis_server/src/services/completion/suggestion_builder.dart'
; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/scanner.dart'; | 9 import 'package:analyzer/src/generated/scanner.dart'; |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * `LocalDeclarationCollector` visits an [AstNode] and its parent recursively | 12 * `LocalDeclarationCollector` visits an [AstNode] and its parent recursively |
| 13 * along with any declarations in those nodes. Consumers typically call [visit] | 13 * along with any declarations in those nodes. Consumers typically call [visit] |
| 14 * which catches the exception thrown by [finished()]. | 14 * which catches the exception thrown by [finished()]. |
| 15 */ | 15 */ |
| 16 abstract class LocalDeclarationVisitor extends GeneralizingAstVisitor { | 16 abstract class LocalDeclarationVisitor extends GeneralizingAstVisitor { |
| 17 static final TypeName STACKTRACE_TYPE = new TypeName(new SimpleIdentifier( | 17 static final TypeName STACKTRACE_TYPE = new TypeName( |
| 18 new StringToken(TokenType.IDENTIFIER, 'StackTrace', 0)), null); | 18 new SimpleIdentifier( |
| 19 new StringToken(TokenType.IDENTIFIER, 'StackTrace', 0)), |
| 20 null); |
| 19 | 21 |
| 20 final int offset; | 22 final int offset; |
| 21 | 23 |
| 24 /** |
| 25 * `true` if local inherited types should be visited. |
| 26 */ |
| 27 bool includeLocalInheritedTypes = true; |
| 28 |
| 22 LocalDeclarationVisitor(this.offset); | 29 LocalDeclarationVisitor(this.offset); |
| 23 | 30 |
| 24 void declaredClass(ClassDeclaration declaration); | 31 void declaredClass(ClassDeclaration declaration); |
| 25 | 32 |
| 26 void declaredClassTypeAlias(ClassTypeAlias declaration); | 33 void declaredClassTypeAlias(ClassTypeAlias declaration); |
| 27 | 34 |
| 28 void declaredEnum(EnumDeclaration declaration) {} | 35 void declaredEnum(EnumDeclaration declaration) {} |
| 29 | 36 |
| 30 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl); | 37 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl); |
| 31 | 38 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 if (param != null) { | 113 if (param != null) { |
| 107 declaredParam(param, STACKTRACE_TYPE); | 114 declaredParam(param, STACKTRACE_TYPE); |
| 108 } | 115 } |
| 109 visitNode(node); | 116 visitNode(node); |
| 110 } | 117 } |
| 111 | 118 |
| 112 @override | 119 @override |
| 113 void visitClassDeclaration(ClassDeclaration node) { | 120 void visitClassDeclaration(ClassDeclaration node) { |
| 114 _visitClassDeclarationMembers(node); | 121 _visitClassDeclarationMembers(node); |
| 115 // imported types are handled by the imported reference contributor | 122 // imported types are handled by the imported reference contributor |
| 116 visitInheritedTypes(node, localDeclaration: (ClassDeclaration classNode) { | 123 if (includeLocalInheritedTypes) { |
| 117 _visitClassDeclarationMembers(classNode); | 124 visitInheritedTypes(node, localDeclaration: (ClassDeclaration classNode) { |
| 118 }); | 125 _visitClassDeclarationMembers(classNode); |
| 126 }); |
| 127 } |
| 119 visitNode(node); | 128 visitNode(node); |
| 120 } | 129 } |
| 121 | 130 |
| 122 @override | 131 @override |
| 123 void visitCompilationUnit(CompilationUnit node) { | 132 void visitCompilationUnit(CompilationUnit node) { |
| 124 node.declarations.forEach((Declaration declaration) { | 133 node.declarations.forEach((Declaration declaration) { |
| 125 if (declaration is ClassDeclaration) { | 134 if (declaration is ClassDeclaration) { |
| 126 declaredClass(declaration); | 135 declaredClass(declaration); |
| 127 } else if (declaration is EnumDeclaration) { | 136 } else if (declaration is EnumDeclaration) { |
| 128 declaredEnum(declaration); | 137 declaredEnum(declaration); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 void visitSwitchStatement(SwitchStatement node) { | 233 void visitSwitchStatement(SwitchStatement node) { |
| 225 for (SwitchMember member in node.members) { | 234 for (SwitchMember member in node.members) { |
| 226 for (Label label in member.labels) { | 235 for (Label label in member.labels) { |
| 227 declaredLabel(label, true); | 236 declaredLabel(label, true); |
| 228 } | 237 } |
| 229 } | 238 } |
| 230 visitNode(node); | 239 visitNode(node); |
| 231 } | 240 } |
| 232 | 241 |
| 233 void _visitClassDeclarationMembers(ClassDeclaration node) { | 242 void _visitClassDeclarationMembers(ClassDeclaration node) { |
| 234 node.members.forEach((ClassMember member) { | 243 for (ClassMember member in node.members) { |
| 235 if (member is FieldDeclaration) { | 244 if (member is FieldDeclaration) { |
| 236 member.fields.variables.forEach((VariableDeclaration varDecl) { | 245 member.fields.variables.forEach((VariableDeclaration varDecl) { |
| 237 declaredField(member, varDecl); | 246 declaredField(member, varDecl); |
| 238 }); | 247 }); |
| 239 } else if (member is MethodDeclaration) { | 248 } else if (member is MethodDeclaration) { |
| 240 declaredMethod(member); | 249 declaredMethod(member); |
| 241 } | 250 } |
| 242 }); | 251 } |
| 243 } | 252 } |
| 244 | 253 |
| 245 void _visitParamList(FormalParameterList paramList) { | 254 void _visitParamList(FormalParameterList paramList) { |
| 246 if (paramList != null) { | 255 if (paramList != null) { |
| 247 paramList.parameters.forEach((FormalParameter param) { | 256 paramList.parameters.forEach((FormalParameter param) { |
| 248 NormalFormalParameter normalParam; | 257 NormalFormalParameter normalParam; |
| 249 if (param is DefaultFormalParameter) { | 258 if (param is DefaultFormalParameter) { |
| 250 normalParam = param.parameter; | 259 normalParam = param.parameter; |
| 251 } else if (param is NormalFormalParameter) { | 260 } else if (param is NormalFormalParameter) { |
| 252 normalParam = param; | 261 normalParam = param; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 264 }); | 273 }); |
| 265 } | 274 } |
| 266 } | 275 } |
| 267 } | 276 } |
| 268 | 277 |
| 269 /** | 278 /** |
| 270 * Internal exception used to indicate that [LocalDeclarationVisitor] | 279 * Internal exception used to indicate that [LocalDeclarationVisitor] |
| 271 * should stop visiting. | 280 * should stop visiting. |
| 272 */ | 281 */ |
| 273 class _LocalDeclarationVisitorFinished {} | 282 class _LocalDeclarationVisitorFinished {} |
| OLD | NEW |