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 analyzer.test.dart.element.builder_test; | 5 library analyzer.test.dart.element.builder_test; |
6 | 6 |
7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; | 8 import 'package:analyzer/dart/ast/standard_ast_factory.dart'; |
9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 // Validate the variable element. | 1107 // Validate the variable element. |
1108 var variableElement = variable.element as VariableElementImpl; | 1108 var variableElement = variable.element as VariableElementImpl; |
1109 expect(variableElement, isNotNull); | 1109 expect(variableElement, isNotNull); |
1110 expect(variableElement.initializer, isNull); | 1110 expect(variableElement.initializer, isNull); |
1111 // Build the initializer element. | 1111 // Build the initializer element. |
1112 new LocalElementBuilder(new ElementHolder(), compilationUnitElement) | 1112 new LocalElementBuilder(new ElementHolder(), compilationUnitElement) |
1113 .buildVariableInitializer(variableElement, variable.initializer); | 1113 .buildVariableInitializer(variableElement, variable.initializer); |
1114 expect(variableElement.initializer, isNotNull); | 1114 expect(variableElement.initializer, isNotNull); |
1115 } | 1115 } |
1116 | 1116 |
| 1117 void test_genericFunction_isExpression() { |
| 1118 buildElementsForText('main(p) { p is Function(int a, String); }'); |
| 1119 var main = compilationUnit.declarations[0] as FunctionDeclaration; |
| 1120 var body = main.functionExpression.body as BlockFunctionBody; |
| 1121 var statement = body.block.statements[0] as ExpressionStatement; |
| 1122 var expression = statement.expression as IsExpression; |
| 1123 var typeNode = expression.type as GenericFunctionType; |
| 1124 var typeElement = typeNode.type.element as GenericFunctionTypeElementImpl; |
| 1125 expect(typeElement.parameters, hasLength(2)); |
| 1126 expect(typeElement.parameters[0].name, 'a'); |
| 1127 expect(typeElement.parameters[1].name, ''); |
| 1128 } |
| 1129 |
1117 void test_visitDefaultFormalParameter_local() { | 1130 void test_visitDefaultFormalParameter_local() { |
1118 CompilationUnit unit = parseCompilationUnit(''' | 1131 CompilationUnit unit = parseCompilationUnit(''' |
1119 main() { | 1132 main() { |
1120 f({bool b: false}) {} | 1133 f({bool b: false}) {} |
1121 } | 1134 } |
1122 '''); | 1135 '''); |
1123 var mainAst = unit.declarations.single as FunctionDeclaration; | 1136 var mainAst = unit.declarations.single as FunctionDeclaration; |
1124 // Build API elements. | 1137 // Build API elements. |
1125 FunctionElementImpl main; | 1138 FunctionElementImpl main; |
1126 { | 1139 { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 * [ElementAnnotationImpl] is unresolved. | 1227 * [ElementAnnotationImpl] is unresolved. |
1215 */ | 1228 */ |
1216 void checkAnnotation(NodeList<Annotation> metadata); | 1229 void checkAnnotation(NodeList<Annotation> metadata); |
1217 | 1230 |
1218 /** | 1231 /** |
1219 * Verify that the given [element] has exactly one annotation, and that its | 1232 * Verify that the given [element] has exactly one annotation, and that its |
1220 * [ElementAnnotationImpl] is unresolved. | 1233 * [ElementAnnotationImpl] is unresolved. |
1221 */ | 1234 */ |
1222 void checkMetadata(Element element); | 1235 void checkMetadata(Element element); |
1223 | 1236 |
| 1237 void test_genericFunction_asTopLevelVariableType() { |
| 1238 buildElementsForText('int Function(int a, String) v;'); |
| 1239 var v = compilationUnit.declarations[0] as TopLevelVariableDeclaration; |
| 1240 var typeNode = v.variables.type as GenericFunctionType; |
| 1241 var typeElement = typeNode.type.element as GenericFunctionTypeElementImpl; |
| 1242 expect(typeElement.parameters, hasLength(2)); |
| 1243 expect(typeElement.parameters[0].name, 'a'); |
| 1244 expect(typeElement.parameters[1].name, ''); |
| 1245 } |
| 1246 |
1224 void test_metadata_fieldDeclaration() { | 1247 void test_metadata_fieldDeclaration() { |
1225 List<FieldElement> fields = | 1248 List<FieldElement> fields = |
1226 buildElementsForText('class C { @a int x, y; }').types[0].fields; | 1249 buildElementsForText('class C { @a int x, y; }').types[0].fields; |
1227 checkMetadata(fields[0]); | 1250 checkMetadata(fields[0]); |
1228 checkMetadata(fields[1]); | 1251 checkMetadata(fields[1]); |
1229 expect(fields[0].metadata, same(fields[1].metadata)); | 1252 expect(fields[0].metadata, same(fields[1].metadata)); |
1230 } | 1253 } |
1231 | 1254 |
1232 void test_metadata_topLevelVariableDeclaration() { | 1255 void test_metadata_topLevelVariableDeclaration() { |
1233 List<TopLevelVariableElement> topLevelVariables = | 1256 List<TopLevelVariableElement> topLevelVariables = |
(...skipping 1424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2658 AnalysisEngine.instance.logger = logger; | 2681 AnalysisEngine.instance.logger = logger; |
2659 try { | 2682 try { |
2660 _compilationUnit = parseCompilationUnit(code); | 2683 _compilationUnit = parseCompilationUnit(code); |
2661 compilationUnit.accept(visitor); | 2684 compilationUnit.accept(visitor); |
2662 } finally { | 2685 } finally { |
2663 expect(logger.log, hasLength(0)); | 2686 expect(logger.log, hasLength(0)); |
2664 AnalysisEngine.instance.logger = Logger.NULL; | 2687 AnalysisEngine.instance.logger = Logger.NULL; |
2665 } | 2688 } |
2666 } | 2689 } |
2667 } | 2690 } |
OLD | NEW |