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(new SimpleIdentifier( |
18 new StringToken(TokenType.IDENTIFIER, 'StackTrace', 0)), null); | 18 new StringToken(TokenType.IDENTIFIER, 'StackTrace', 0)), null); |
19 | 19 |
20 final int offset; | 20 final int offset; |
21 | 21 |
22 LocalDeclarationVisitor(this.offset); | 22 LocalDeclarationVisitor(this.offset); |
23 | 23 |
24 void declaredClass(ClassDeclaration declaration); | 24 void declaredClass(ClassDeclaration declaration); |
25 | 25 |
26 void declaredClassTypeAlias(ClassTypeAlias declaration); | 26 void declaredClassTypeAlias(ClassTypeAlias declaration); |
27 | 27 |
| 28 void declaredEnum(EnumDeclaration declaration) {} |
| 29 |
28 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl); | 30 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl); |
29 | 31 |
30 void declaredFunction(FunctionDeclaration declaration); | 32 void declaredFunction(FunctionDeclaration declaration); |
31 | 33 |
32 void declaredFunctionTypeAlias(FunctionTypeAlias declaration); | 34 void declaredFunctionTypeAlias(FunctionTypeAlias declaration); |
33 | 35 |
34 void declaredLabel(Label label, bool isCaseLabel); | 36 void declaredLabel(Label label, bool isCaseLabel); |
35 | 37 |
36 void declaredLocalVar(SimpleIdentifier name, TypeName type); | 38 void declaredLocalVar(SimpleIdentifier name, TypeName type); |
37 | 39 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 }); | 118 }); |
117 visitNode(node); | 119 visitNode(node); |
118 } | 120 } |
119 | 121 |
120 @override | 122 @override |
121 void visitCompilationUnit(CompilationUnit node) { | 123 void visitCompilationUnit(CompilationUnit node) { |
122 node.declarations.forEach((Declaration declaration) { | 124 node.declarations.forEach((Declaration declaration) { |
123 if (declaration is ClassDeclaration) { | 125 if (declaration is ClassDeclaration) { |
124 declaredClass(declaration); | 126 declaredClass(declaration); |
125 } else if (declaration is EnumDeclaration) { | 127 } else if (declaration is EnumDeclaration) { |
126 // TODO (danrubel) enum support | 128 declaredEnum(declaration); |
127 // declaredEnum(........) | |
128 } else if (declaration is FunctionDeclaration) { | 129 } else if (declaration is FunctionDeclaration) { |
129 declaredFunction(declaration); | 130 declaredFunction(declaration); |
130 } else if (declaration is TopLevelVariableDeclaration) { | 131 } else if (declaration is TopLevelVariableDeclaration) { |
131 var varList = declaration.variables; | 132 var varList = declaration.variables; |
132 if (varList != null) { | 133 if (varList != null) { |
133 varList.variables.forEach((VariableDeclaration varDecl) { | 134 varList.variables.forEach((VariableDeclaration varDecl) { |
134 declaredTopLevelVar(varList, varDecl); | 135 declaredTopLevelVar(varList, varDecl); |
135 }); | 136 }); |
136 } | 137 } |
137 } else if (declaration is ClassTypeAlias) { | 138 } else if (declaration is ClassTypeAlias) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 }); | 264 }); |
264 } | 265 } |
265 } | 266 } |
266 } | 267 } |
267 | 268 |
268 /** | 269 /** |
269 * Internal exception used to indicate that [LocalDeclarationVisitor] | 270 * Internal exception used to indicate that [LocalDeclarationVisitor] |
270 * should stop visiting. | 271 * should stop visiting. |
271 */ | 272 */ |
272 class _LocalDeclarationVisitorFinished {} | 273 class _LocalDeclarationVisitorFinished {} |
OLD | NEW |