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 import 'package:analyzer/dart/ast/ast.dart'; | 5 import 'package:analyzer/dart/ast/ast.dart'; |
6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 6 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
7 import 'package:analyzer/dart/ast/token.dart'; | 7 import 'package:analyzer/dart/ast/token.dart'; |
8 import 'package:analyzer/dart/ast/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
9 import 'package:analyzer/error/error.dart'; | 9 import 'package:analyzer/error/error.dart'; |
10 import 'package:analyzer/error/listener.dart'; | 10 import 'package:analyzer/error/listener.dart'; |
(...skipping 4297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4308 } | 4308 } |
4309 | 4309 |
4310 void test_varTypedef() { | 4310 void test_varTypedef() { |
4311 parseCompilationUnit("var typedef F();", [ParserErrorCode.VAR_TYPEDEF]); | 4311 parseCompilationUnit("var typedef F();", [ParserErrorCode.VAR_TYPEDEF]); |
4312 } | 4312 } |
4313 | 4313 |
4314 void test_voidParameter() { | 4314 void test_voidParameter() { |
4315 createParser('void a)'); | 4315 createParser('void a)'); |
4316 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); | 4316 NormalFormalParameter parameter = parser.parseNormalFormalParameter(); |
4317 expectNotNullIfNoErrors(parameter); | 4317 expectNotNullIfNoErrors(parameter); |
4318 listener.assertErrorsWithCodes([ParserErrorCode.VOID_PARAMETER]); | 4318 listener.assertNoErrors(); |
4319 } | 4319 } |
4320 | 4320 |
4321 void test_voidVariable_parseClassMember_initializer() { | 4321 void test_voidVariable_parseClassMember_initializer() { |
4322 createParser('void x = 0;'); | 4322 createParser('void x = 0;'); |
4323 ClassMember member = parser.parseClassMember('C'); | 4323 ClassMember member = parser.parseClassMember('C'); |
4324 expectNotNullIfNoErrors(member); | 4324 expectNotNullIfNoErrors(member); |
4325 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); | 4325 listener.assertNoErrors(); |
4326 } | 4326 } |
4327 | 4327 |
4328 void test_voidVariable_parseClassMember_noInitializer() { | 4328 void test_voidVariable_parseClassMember_noInitializer() { |
4329 createParser('void x;'); | 4329 createParser('void x;'); |
4330 ClassMember member = parser.parseClassMember('C'); | 4330 ClassMember member = parser.parseClassMember('C'); |
4331 expectNotNullIfNoErrors(member); | 4331 expectNotNullIfNoErrors(member); |
4332 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); | 4332 listener.assertNoErrors(); |
4333 } | 4333 } |
4334 | 4334 |
4335 void test_voidVariable_parseCompilationUnit_initializer() { | 4335 void test_voidVariable_parseCompilationUnit_initializer() { |
4336 parseCompilationUnit("void x = 0;", [ParserErrorCode.VOID_VARIABLE]); | 4336 parseCompilationUnit("void x = 0;"); |
4337 } | 4337 } |
4338 | 4338 |
4339 void test_voidVariable_parseCompilationUnit_noInitializer() { | 4339 void test_voidVariable_parseCompilationUnit_noInitializer() { |
4340 parseCompilationUnit("void x;", [ParserErrorCode.VOID_VARIABLE]); | 4340 parseCompilationUnit("void x;"); |
4341 } | 4341 } |
4342 | 4342 |
4343 void test_voidVariable_parseCompilationUnitMember_initializer() { | 4343 void test_voidVariable_parseCompilationUnitMember_initializer() { |
4344 createParser('void a = 0;'); | 4344 createParser('void a = 0;'); |
4345 CompilationUnitMember member = parseFullCompilationUnitMember(); | 4345 CompilationUnitMember member = parseFullCompilationUnitMember(); |
4346 expectNotNullIfNoErrors(member); | 4346 expectNotNullIfNoErrors(member); |
4347 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); | 4347 listener.assertNoErrors(); |
4348 } | 4348 } |
4349 | 4349 |
4350 void test_voidVariable_parseCompilationUnitMember_noInitializer() { | 4350 void test_voidVariable_parseCompilationUnitMember_noInitializer() { |
4351 createParser('void a;'); | 4351 createParser('void a;'); |
4352 CompilationUnitMember member = parseFullCompilationUnitMember(); | 4352 CompilationUnitMember member = parseFullCompilationUnitMember(); |
4353 expectNotNullIfNoErrors(member); | 4353 expectNotNullIfNoErrors(member); |
4354 listener.assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); | 4354 listener.assertNoErrors(); |
4355 } | 4355 } |
4356 | 4356 |
4357 void test_voidVariable_statement_initializer() { | 4357 void test_voidVariable_statement_initializer() { |
4358 parseStatement("void x = 0;"); | 4358 parseStatement("void x = 0;"); |
4359 assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); | 4359 listener.assertNoErrors(); |
4360 } | 4360 } |
4361 | 4361 |
4362 void test_voidVariable_statement_noInitializer() { | 4362 void test_voidVariable_statement_noInitializer() { |
4363 parseStatement("void x;"); | 4363 parseStatement("void x;"); |
4364 assertErrorsWithCodes([ParserErrorCode.VOID_VARIABLE]); | 4364 listener.assertNoErrors(); |
4365 } | 4365 } |
4366 | 4366 |
4367 void test_withBeforeExtends() { | 4367 void test_withBeforeExtends() { |
4368 parseCompilationUnit( | 4368 parseCompilationUnit( |
4369 "class A with B extends C {}", [ParserErrorCode.WITH_BEFORE_EXTENDS]); | 4369 "class A with B extends C {}", [ParserErrorCode.WITH_BEFORE_EXTENDS]); |
4370 } | 4370 } |
4371 | 4371 |
4372 void test_withWithoutExtends() { | 4372 void test_withWithoutExtends() { |
4373 createParser('class A with B, C {}'); | 4373 createParser('class A with B, C {}'); |
4374 ClassDeclaration declaration = parseFullCompilationUnitMember(); | 4374 ClassDeclaration declaration = parseFullCompilationUnitMember(); |
(...skipping 6812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11187 expectNotNullIfNoErrors(result); | 11187 expectNotNullIfNoErrors(result); |
11188 listener.assertNoErrors(); | 11188 listener.assertNoErrors(); |
11189 expect(result.keyword, isNull); | 11189 expect(result.keyword, isNull); |
11190 expect(result.type, isNotNull); | 11190 expect(result.type, isNotNull); |
11191 } | 11191 } |
11192 | 11192 |
11193 void test_parseFinalConstVarOrType_void_noIdentifier() { | 11193 void test_parseFinalConstVarOrType_void_noIdentifier() { |
11194 createParser('void,'); | 11194 createParser('void,'); |
11195 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); | 11195 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
11196 expectNotNullIfNoErrors(result); | 11196 expectNotNullIfNoErrors(result); |
| 11197 listener.assertErrorsWithCodes( |
| 11198 [ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE]); |
| 11199 } |
| 11200 |
| 11201 void test_parseFinalConstVarOrType_void_identifier() { |
| 11202 createParser('void x'); |
| 11203 FinalConstVarOrType result = parser.parseFinalConstVarOrType(false); |
| 11204 expectNotNullIfNoErrors(result); |
11197 listener.assertNoErrors(); | 11205 listener.assertNoErrors(); |
11198 expect(result.keyword, isNull); | 11206 expect(result.keyword, isNull); |
11199 expect(result.type, isNotNull); | 11207 expect(result.type, isNotNull); |
11200 } | 11208 } |
11201 | 11209 |
11202 void test_parseFunctionBody_block() { | 11210 void test_parseFunctionBody_block() { |
11203 createParser('{}'); | 11211 createParser('{}'); |
11204 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); | 11212 FunctionBody functionBody = parser.parseFunctionBody(false, null, false); |
11205 expectNotNullIfNoErrors(functionBody); | 11213 expectNotNullIfNoErrors(functionBody); |
11206 listener.assertNoErrors(); | 11214 listener.assertNoErrors(); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11483 createParser('return x;'); | 11491 createParser('return x;'); |
11484 ReturnStatement statement = parser.parseReturnStatement(); | 11492 ReturnStatement statement = parser.parseReturnStatement(); |
11485 expectNotNullIfNoErrors(statement); | 11493 expectNotNullIfNoErrors(statement); |
11486 listener.assertNoErrors(); | 11494 listener.assertNoErrors(); |
11487 expect(statement.returnKeyword, isNotNull); | 11495 expect(statement.returnKeyword, isNotNull); |
11488 expect(statement.expression, isNotNull); | 11496 expect(statement.expression, isNotNull); |
11489 expect(statement.semicolon, isNotNull); | 11497 expect(statement.semicolon, isNotNull); |
11490 } | 11498 } |
11491 | 11499 |
11492 void test_parseReturnType_function() { | 11500 void test_parseReturnType_function() { |
| 11501 // TODO(eernst): `parseReturnType` eliminated, delete this test? |
11493 createParser('A<B> Function<B>(B)'); | 11502 createParser('A<B> Function<B>(B)'); |
11494 GenericFunctionType type = parser.parseReturnType(false); | 11503 GenericFunctionType type = parser.parseTypeAnnotation(false); |
11495 expectNotNullIfNoErrors(type); | 11504 expectNotNullIfNoErrors(type); |
11496 listener.assertNoErrors(); | 11505 listener.assertNoErrors(); |
11497 expect(type.returnType, isNotNull); | 11506 expect(type.returnType, isNotNull); |
11498 expect(type.typeParameters, isNotNull); | 11507 expect(type.typeParameters, isNotNull); |
11499 expect(type.parameters, isNotNull); | 11508 expect(type.parameters, isNotNull); |
11500 } | 11509 } |
11501 | 11510 |
11502 void test_parseReturnType_named() { | 11511 void test_parseReturnType_named() { |
| 11512 // TODO(eernst): `parseReturnType` eliminated, delete this test? |
11503 createParser('A<B>'); | 11513 createParser('A<B>'); |
11504 TypeName typeName = parser.parseReturnType(false); | 11514 TypeName typeName = parser.parseTypeAnnotation(false); |
11505 expectNotNullIfNoErrors(typeName); | 11515 expectNotNullIfNoErrors(typeName); |
11506 listener.assertNoErrors(); | 11516 listener.assertNoErrors(); |
11507 expect(typeName.name, isNotNull); | 11517 expect(typeName.name, isNotNull); |
11508 expect(typeName.typeArguments, isNotNull); | 11518 expect(typeName.typeArguments, isNotNull); |
11509 } | 11519 } |
11510 | 11520 |
11511 void test_parseReturnType_void() { | 11521 void test_parseReturnType_void() { |
| 11522 // TODO(eernst): `parseReturnType` eliminated, delete this test? |
11512 createParser('void'); | 11523 createParser('void'); |
11513 TypeName typeName = parser.parseReturnType(false); | 11524 TypeName typeName = parser.parseTypeAnnotation(false); |
11514 expectNotNullIfNoErrors(typeName); | 11525 expectNotNullIfNoErrors(typeName); |
11515 listener.assertNoErrors(); | 11526 listener.assertNoErrors(); |
11516 expect(typeName.name, isNotNull); | 11527 expect(typeName.name, isNotNull); |
11517 expect(typeName.typeArguments, isNull); | 11528 expect(typeName.typeArguments, isNull); |
11518 } | 11529 } |
11519 | 11530 |
11520 void test_parseStatement_function_noReturnType() { | 11531 void test_parseStatement_function_noReturnType() { |
11521 createParser(''' | 11532 createParser(''' |
11522 Function<A>(core.List<core.int> x) m() => null; | 11533 Function<A>(core.List<core.int> x) m() => null; |
11523 '''); | 11534 '''); |
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12013 } | 12024 } |
12014 | 12025 |
12015 void test_skipPrefixedIdentifier_prefixed() { | 12026 void test_skipPrefixedIdentifier_prefixed() { |
12016 createParser('a.b +'); | 12027 createParser('a.b +'); |
12017 Token following = parser.skipPrefixedIdentifier(parser.currentToken); | 12028 Token following = parser.skipPrefixedIdentifier(parser.currentToken); |
12018 expect(following, isNotNull); | 12029 expect(following, isNotNull); |
12019 expect(following.type, TokenType.PLUS); | 12030 expect(following.type, TokenType.PLUS); |
12020 } | 12031 } |
12021 | 12032 |
12022 void test_skipReturnType_invalid() { | 12033 void test_skipReturnType_invalid() { |
| 12034 // TODO(eernst): `skipReturnType` eliminated, delete this test? |
12023 createParser('+'); | 12035 createParser('+'); |
12024 Token following = parser.skipReturnType(parser.currentToken); | 12036 Token following = parser.skipTypeAnnotation(parser.currentToken); |
12025 expect(following, isNull); | 12037 expect(following, isNull); |
12026 } | 12038 } |
12027 | 12039 |
12028 void test_skipReturnType_type() { | 12040 void test_skipReturnType_type() { |
| 12041 // TODO(eernst): `skipReturnType` eliminated, delete this test? |
12029 createParser('C +'); | 12042 createParser('C +'); |
12030 Token following = parser.skipReturnType(parser.currentToken); | 12043 Token following = parser.skipTypeAnnotation(parser.currentToken); |
12031 expect(following, isNotNull); | 12044 expect(following, isNotNull); |
12032 expect(following.type, TokenType.PLUS); | 12045 expect(following.type, TokenType.PLUS); |
12033 } | 12046 } |
12034 | 12047 |
12035 void test_skipReturnType_void() { | 12048 void test_skipReturnType_void() { |
| 12049 // TODO(eernst): `skipReturnType` eliminated, delete this test? |
12036 createParser('void +'); | 12050 createParser('void +'); |
12037 Token following = parser.skipReturnType(parser.currentToken); | 12051 Token following = parser.skipTypeAnnotation(parser.currentToken); |
12038 expect(following, isNotNull); | 12052 expect(following, isNotNull); |
12039 expect(following.type, TokenType.PLUS); | 12053 expect(following.type, TokenType.PLUS); |
12040 } | 12054 } |
12041 | 12055 |
12042 void test_skipSimpleIdentifier_identifier() { | 12056 void test_skipSimpleIdentifier_identifier() { |
12043 createParser('i +'); | 12057 createParser('i +'); |
12044 Token following = parser.skipSimpleIdentifier(parser.currentToken); | 12058 Token following = parser.skipSimpleIdentifier(parser.currentToken); |
12045 expect(following, isNotNull); | 12059 expect(following, isNotNull); |
12046 expect(following.type, TokenType.PLUS); | 12060 expect(following.type, TokenType.PLUS); |
12047 } | 12061 } |
(...skipping 3126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15174 expectCommentText(typeVariable.documentationComment, '/// Doc'); | 15188 expectCommentText(typeVariable.documentationComment, '/// Doc'); |
15175 } | 15189 } |
15176 | 15190 |
15177 /** | 15191 /** |
15178 * Assert that the given [name] is in declaration context. | 15192 * Assert that the given [name] is in declaration context. |
15179 */ | 15193 */ |
15180 void _assertIsDeclarationName(SimpleIdentifier name) { | 15194 void _assertIsDeclarationName(SimpleIdentifier name) { |
15181 expect(name.inDeclarationContext(), isTrue); | 15195 expect(name.inDeclarationContext(), isTrue); |
15182 } | 15196 } |
15183 } | 15197 } |
OLD | NEW |