OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library test.services.completion.local_declaration_visitor_test; | |
6 | |
7 import 'package:analysis_server/src/services/completion/local_declaration_visito
r.dart'; | |
8 import 'package:analyzer/src/generated/ast.dart'; | |
9 import 'package:analyzer/src/generated/error.dart'; | |
10 import 'package:analyzer/src/generated/parser.dart'; | |
11 import 'package:analyzer/src/generated/scanner.dart'; | |
12 import 'package:test_reflective_loader/test_reflective_loader.dart'; | |
13 import 'package:unittest/unittest.dart'; | |
14 | |
15 import '../../utils.dart'; | |
16 | |
17 main() { | |
18 initializeTestEnvironment(); | |
19 defineReflectiveTests(LocalDeclarationVisitorTest); | |
20 } | |
21 | |
22 @reflectiveTest | |
23 class LocalDeclarationVisitorTest { | |
24 CompilationUnit parseCompilationUnit(String source) { | |
25 AnalysisErrorListener listener = AnalysisErrorListener.NULL_LISTENER; | |
26 Scanner scanner = | |
27 new Scanner(null, new CharSequenceReader(source), listener); | |
28 Token token = scanner.tokenize(); | |
29 Parser parser = new Parser(null, listener); | |
30 CompilationUnit unit = parser.parseCompilationUnit(token); | |
31 expect(unit, isNotNull); | |
32 return unit; | |
33 } | |
34 | |
35 test_visitForEachStatement() { | |
36 CompilationUnit unit = parseCompilationUnit(''' | |
37 class MyClass {} | |
38 f(List<MyClass> list) { | |
39 for(MyClas( x in list) {} | |
40 } | |
41 '''); | |
42 NodeList<CompilationUnitMember> declarations = unit.declarations; | |
43 expect(declarations, hasLength(2)); | |
44 FunctionDeclaration f = declarations[1]; | |
45 expect(f, isNotNull); | |
46 BlockFunctionBody body = f.functionExpression.body; | |
47 Statement statement = body.block.statements[0]; | |
48 expect(statement, new isInstanceOf<ForEachStatement>()); | |
49 statement.accept(new TestVisitor(statement.offset)); | |
50 } | |
51 } | |
52 | |
53 class TestVisitor extends LocalDeclarationVisitor { | |
54 TestVisitor(int offset) : super(offset); | |
55 | |
56 @override | |
57 void declaredClass(ClassDeclaration declaration) {} | |
58 | |
59 @override | |
60 void declaredClassTypeAlias(ClassTypeAlias declaration) {} | |
61 | |
62 @override | |
63 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {} | |
64 | |
65 @override | |
66 void declaredFunction(FunctionDeclaration declaration) {} | |
67 | |
68 @override | |
69 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) {} | |
70 | |
71 @override | |
72 void declaredLabel(Label label, bool isCaseLabel) {} | |
73 | |
74 @override | |
75 void declaredLocalVar(SimpleIdentifier name, TypeName type) { | |
76 expect(name, isNotNull); | |
77 } | |
78 | |
79 @override | |
80 void declaredMethod(MethodDeclaration declaration) {} | |
81 | |
82 @override | |
83 void declaredParam(SimpleIdentifier name, TypeName type) {} | |
84 | |
85 @override | |
86 void declaredTopLevelVar( | |
87 VariableDeclarationList varList, VariableDeclaration varDecl) {} | |
88 } | |
OLD | NEW |