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

Side by Side Diff: pkg/analysis_server/test/services/completion/local_declaration_visitor_test.dart

Issue 1138963005: Fix exception in code completion (issue 23439) (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 main() {
16 groupSep = ' | ';
17 defineReflectiveTests(LocalDeclarationVisitorTest);
18 }
19
20 @reflectiveTest
21 class LocalDeclarationVisitorTest {
22 CompilationUnit parseCompilationUnit(String source) {
23 AnalysisErrorListener listener = AnalysisErrorListener.NULL_LISTENER;
24 Scanner scanner =
25 new Scanner(null, new CharSequenceReader(source), listener);
26 Token token = scanner.tokenize();
27 Parser parser = new Parser(null, listener);
28 CompilationUnit unit = parser.parseCompilationUnit(token);
29 expect(unit, isNotNull);
30 return unit;
31 }
32
33 test_visitForEachStatement() {
34 CompilationUnit unit = parseCompilationUnit('''
35 class MyClass {}
36 f(List<MyClass> list) {
37 for(MyClas( x in list) {}
38 }
39 ''');
40 NodeList<CompilationUnitMember> declarations = unit.declarations;
41 expect(declarations, hasLength(2));
42 FunctionDeclaration f = declarations[1];
43 expect(f, isNotNull);
44 BlockFunctionBody body = f.functionExpression.body;
45 Statement statement = body.block.statements[0];
46 expect(statement, new isInstanceOf<ForEachStatement>());
47 statement.accept(new TestVisitor(statement.offset));
48 }
49 }
50
51 class TestVisitor extends LocalDeclarationVisitor {
52 TestVisitor(int offset) : super(offset);
53
54 @override
55 void declaredClass(ClassDeclaration declaration) {}
56
57 @override
58 void declaredClassTypeAlias(ClassTypeAlias declaration) {}
59
60 @override
61 void declaredField(FieldDeclaration fieldDecl, VariableDeclaration varDecl) {}
62
63 @override
64 void declaredFunction(FunctionDeclaration declaration) {}
65
66 @override
67 void declaredFunctionTypeAlias(FunctionTypeAlias declaration) {}
68
69 @override
70 void declaredLabel(Label label, bool isCaseLabel) {}
71
72 @override
73 void declaredLocalVar(SimpleIdentifier name, TypeName type) {
74 expect(name, isNotNull);
75 }
76
77 @override
78 void declaredMethod(MethodDeclaration declaration) {}
79
80 @override
81 void declaredParam(SimpleIdentifier name, TypeName type) {}
82
83 @override
84 void declaredTopLevelVar(
85 VariableDeclarationList varList, VariableDeclaration varDecl) {}
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698