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 test.services.completion.contributor.dart.optype; | 5 library test.services.completion.contributor.dart.optype; |
6 | 6 |
7 import 'package:analysis_server/src/services/completion/completion_target.dart'; | 7 import 'package:analysis_server/src/services/completion/completion_target.dart'; |
8 import 'package:analysis_server/src/services/completion/optype.dart'; | 8 import 'package:analysis_server/src/services/completion/optype.dart'; |
9 import 'package:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
10 import 'package:analyzer/src/generated/engine.dart'; | 10 import 'package:analyzer/src/generated/engine.dart'; |
(...skipping 25 matching lines...) Expand all Loading... |
36 new SourceFactory([AbstractContextTest.SDK_RESOLVER]); | 36 new SourceFactory([AbstractContextTest.SDK_RESOLVER]); |
37 context.setContents(source, content); | 37 context.setContents(source, content); |
38 CompilationUnit unit = resolved | 38 CompilationUnit unit = resolved |
39 ? context.resolveCompilationUnit2(source, source) | 39 ? context.resolveCompilationUnit2(source, source) |
40 : context.parseCompilationUnit(source); | 40 : context.parseCompilationUnit(source); |
41 CompletionTarget completionTarget = | 41 CompletionTarget completionTarget = |
42 new CompletionTarget.forOffset(unit, offset); | 42 new CompletionTarget.forOffset(unit, offset); |
43 visitor = new OpType.forCompletion(completionTarget, offset); | 43 visitor = new OpType.forCompletion(completionTarget, offset); |
44 } | 44 } |
45 | 45 |
46 void assertOpType({bool prefixed: false, bool returnValue: false, | 46 void assertOpType( |
47 bool typeNames: false, bool voidReturn: false, bool statementLabel: false, | 47 {bool caseLabel: false, |
48 bool caseLabel: false, bool constructors: false}) { | 48 bool constructors: false, |
| 49 bool prefixed: false, |
| 50 bool returnValue: false, |
| 51 bool statementLabel: false, |
| 52 bool staticMethodBody: false, |
| 53 bool typeNames: false, |
| 54 bool voidReturn: false}) { |
| 55 expect(visitor.includeCaseLabelSuggestions, caseLabel, reason: 'caseLabel'); |
| 56 expect(visitor.includeConstructorSuggestions, constructors, |
| 57 reason: 'constructors'); |
49 expect(visitor.includeReturnValueSuggestions, returnValue, | 58 expect(visitor.includeReturnValueSuggestions, returnValue, |
50 reason: 'returnValue'); | 59 reason: 'returnValue'); |
| 60 expect(visitor.includeStatementLabelSuggestions, statementLabel, |
| 61 reason: 'statementLabel'); |
51 expect(visitor.includeTypeNameSuggestions, typeNames, reason: 'typeNames'); | 62 expect(visitor.includeTypeNameSuggestions, typeNames, reason: 'typeNames'); |
52 expect(visitor.includeVoidReturnSuggestions, voidReturn, | 63 expect(visitor.includeVoidReturnSuggestions, voidReturn, |
53 reason: 'voidReturn'); | 64 reason: 'voidReturn'); |
54 expect(visitor.includeStatementLabelSuggestions, statementLabel, | 65 expect(visitor.inStaticMethodBody, staticMethodBody, |
55 reason: 'statementLabel'); | 66 reason: 'staticMethodBody'); |
56 expect(visitor.includeCaseLabelSuggestions, caseLabel, reason: 'caseLabel'); | |
57 expect(visitor.includeConstructorSuggestions, constructors, | |
58 reason: 'constructors'); | |
59 expect(visitor.isPrefixed, prefixed, reason: 'prefixed'); | 67 expect(visitor.isPrefixed, prefixed, reason: 'prefixed'); |
60 } | 68 } |
61 | 69 |
62 test_Annotation() { | 70 test_Annotation() { |
63 // SimpleIdentifier Annotation MethodDeclaration ClassDeclaration | 71 // SimpleIdentifier Annotation MethodDeclaration ClassDeclaration |
64 addTestSource('class C { @A^ }'); | 72 addTestSource('class C { @A^ }'); |
65 assertOpType(returnValue: true, typeNames: true); | 73 assertOpType(returnValue: true, typeNames: true); |
66 } | 74 } |
67 | 75 |
68 test_ArgumentList() { | 76 test_ArgumentList() { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 addTestSource('class X {a() {var f; {var x;} D^ var r;} void b() { }}'); | 245 addTestSource('class X {a() {var f; {var x;} D^ var r;} void b() { }}'); |
238 assertOpType(returnValue: true, typeNames: true, voidReturn: true); | 246 assertOpType(returnValue: true, typeNames: true, voidReturn: true); |
239 } | 247 } |
240 | 248 |
241 test_Block_keyword() { | 249 test_Block_keyword() { |
242 addTestSource('class C { static C get instance => null; } main() {C.in^}'); | 250 addTestSource('class C { static C get instance => null; } main() {C.in^}'); |
243 assertOpType( | 251 assertOpType( |
244 prefixed: true, returnValue: true, typeNames: true, voidReturn: true); | 252 prefixed: true, returnValue: true, typeNames: true, voidReturn: true); |
245 } | 253 } |
246 | 254 |
| 255 test_Block_static() { |
| 256 addTestSource('class A {static foo() {^}}'); |
| 257 assertOpType( |
| 258 returnValue: true, |
| 259 typeNames: true, |
| 260 staticMethodBody: true, |
| 261 voidReturn: true); |
| 262 } |
| 263 |
247 test_Break_after_label() { | 264 test_Break_after_label() { |
248 addTestSource('main() { foo: while (true) { break foo ^ ; } }'); | 265 addTestSource('main() { foo: while (true) { break foo ^ ; } }'); |
249 assertOpType(/* No valid completions */); | 266 assertOpType(/* No valid completions */); |
250 } | 267 } |
251 | 268 |
252 test_Break_before_label() { | 269 test_Break_before_label() { |
253 addTestSource('main() { foo: while (true) { break ^ foo; } }'); | 270 addTestSource('main() { foo: while (true) { break ^ foo; } }'); |
254 assertOpType(statementLabel: true); | 271 assertOpType(statementLabel: true); |
255 } | 272 } |
256 | 273 |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 bool get isInSystemLibrary => false; | 1361 bool get isInSystemLibrary => false; |
1345 | 1362 |
1346 @override | 1363 @override |
1347 String get shortName => fullName; | 1364 String get shortName => fullName; |
1348 | 1365 |
1349 @override | 1366 @override |
1350 Source get source => this; | 1367 Source get source => this; |
1351 | 1368 |
1352 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 1369 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
1353 } | 1370 } |
OLD | NEW |