| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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.src.task.dart_test; | 5 library analyzer.test.src.task.dart_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/visitor.dart'; | 8 import 'package:analyzer/dart/ast/visitor.dart'; |
| 9 import 'package:analyzer/dart/element/element.dart'; | 9 import 'package:analyzer/dart/element/element.dart'; |
| 10 import 'package:analyzer/dart/element/type.dart'; | 10 import 'package:analyzer/dart/element/type.dart'; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 178 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 179 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT]; | 179 CompilationUnitElement unitElement = outputs[COMPILATION_UNIT_ELEMENT]; |
| 180 Annotation annotation = unit.declarations | 180 Annotation annotation = unit.declarations |
| 181 .firstWhere((m) => m is FunctionDeclaration) | 181 .firstWhere((m) => m is FunctionDeclaration) |
| 182 .metadata[0]; | 182 .metadata[0]; |
| 183 List<ConstantEvaluationTarget> expectedConstants = [ | 183 List<ConstantEvaluationTarget> expectedConstants = [ |
| 184 unitElement.accessors.firstWhere((e) => e.isGetter).variable, | 184 unitElement.accessors.firstWhere((e) => e.isGetter).variable, |
| 185 unitElement.types[0].fields[0], | 185 unitElement.types[0].fields[0], |
| 186 unitElement.functions[0].localVariables[0], | 186 unitElement.functions[0].localVariables[0], |
| 187 unitElement.types[0].constructors[0], | 187 unitElement.types[0].constructors[0], |
| 188 new ConstantEvaluationTarget_Annotation( | 188 annotation.elementAnnotation, |
| 189 context, source, source, annotation), | |
| 190 unitElement.types[0].constructors[0].parameters[0] | 189 unitElement.types[0].constructors[0].parameters[0] |
| 191 ]; | 190 ]; |
| 192 expect( | 191 expect( |
| 193 outputs[COMPILATION_UNIT_CONSTANTS].toSet(), expectedConstants.toSet()); | 192 outputs[COMPILATION_UNIT_CONSTANTS].toSet(), expectedConstants.toSet()); |
| 194 } | 193 } |
| 195 | 194 |
| 196 test_perform_library() { | 195 test_perform_library() { |
| 197 _performBuildTask(r''' | 196 _performBuildTask(r''' |
| 198 library lib; | 197 library lib; |
| 199 import 'lib2.dart'; | 198 import 'lib2.dart'; |
| (...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 .firstWhere((PropertyAccessorElement accessor) => | 1133 .firstWhere((PropertyAccessorElement accessor) => |
| 1135 accessor.isGetter && accessor.name == 'x') | 1134 accessor.isGetter && accessor.name == 'x') |
| 1136 .variable; | 1135 .variable; |
| 1137 List<ClassElement> types = unit.element.types; | 1136 List<ClassElement> types = unit.element.types; |
| 1138 Element constructorForD = | 1137 Element constructorForD = |
| 1139 types.firstWhere((ClassElement cls) => cls.name == 'D').constructors[0]; | 1138 types.firstWhere((ClassElement cls) => cls.name == 'D').constructors[0]; |
| 1140 Annotation annotation = findClassAnnotation(unit, 'C'); | 1139 Annotation annotation = findClassAnnotation(unit, 'C'); |
| 1141 // Now compute the dependencies for the annotation, and check that it is | 1140 // Now compute the dependencies for the annotation, and check that it is |
| 1142 // the set [x, constructorForD]. | 1141 // the set [x, constructorForD]. |
| 1143 // TODO(paulberry): test librarySource != source | 1142 // TODO(paulberry): test librarySource != source |
| 1144 computeResult( | 1143 computeResult(annotation.elementAnnotation, CONSTANT_DEPENDENCIES, |
| 1145 new ConstantEvaluationTarget_Annotation( | |
| 1146 context, source, source, annotation), | |
| 1147 CONSTANT_DEPENDENCIES, | |
| 1148 matcher: isComputeConstantDependenciesTask); | 1144 matcher: isComputeConstantDependenciesTask); |
| 1149 expect( | 1145 expect( |
| 1150 outputs[CONSTANT_DEPENDENCIES].toSet(), [x, constructorForD].toSet()); | 1146 outputs[CONSTANT_DEPENDENCIES].toSet(), [x, constructorForD].toSet()); |
| 1151 } | 1147 } |
| 1152 | 1148 |
| 1153 test_annotation_without_args() { | 1149 test_annotation_without_args() { |
| 1154 Source source = newSource( | 1150 Source source = newSource( |
| 1155 '/test.dart', | 1151 '/test.dart', |
| 1156 ''' | 1152 ''' |
| 1157 const x = 1; | 1153 const x = 1; |
| 1158 @x class C {} | 1154 @x class C {} |
| 1159 '''); | 1155 '''); |
| 1160 // First compute the resolved unit for the source. | 1156 // First compute the resolved unit for the source. |
| 1161 LibrarySpecificUnit librarySpecificUnit = | 1157 LibrarySpecificUnit librarySpecificUnit = |
| 1162 new LibrarySpecificUnit(source, source); | 1158 new LibrarySpecificUnit(source, source); |
| 1163 computeResult(librarySpecificUnit, RESOLVED_UNIT1); | 1159 computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
| 1164 CompilationUnit unit = outputs[RESOLVED_UNIT1]; | 1160 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 1165 // Find the element for x and the annotation on C. | 1161 // Find the element for x and the annotation on C. |
| 1166 List<PropertyAccessorElement> accessors = unit.element.accessors; | 1162 List<PropertyAccessorElement> accessors = unit.element.accessors; |
| 1167 Element x = accessors | 1163 Element x = accessors |
| 1168 .firstWhere((PropertyAccessorElement accessor) => | 1164 .firstWhere((PropertyAccessorElement accessor) => |
| 1169 accessor.isGetter && accessor.name == 'x') | 1165 accessor.isGetter && accessor.name == 'x') |
| 1170 .variable; | 1166 .variable; |
| 1171 Annotation annotation = findClassAnnotation(unit, 'C'); | 1167 Annotation annotation = findClassAnnotation(unit, 'C'); |
| 1172 // Now compute the dependencies for the annotation, and check that it is | 1168 // Now compute the dependencies for the annotation, and check that it is |
| 1173 // the list [x]. | 1169 // the list [x]. |
| 1174 computeResult( | 1170 computeResult(annotation.elementAnnotation, CONSTANT_DEPENDENCIES, |
| 1175 new ConstantEvaluationTarget_Annotation( | |
| 1176 context, source, source, annotation), | |
| 1177 CONSTANT_DEPENDENCIES, | |
| 1178 matcher: isComputeConstantDependenciesTask); | 1171 matcher: isComputeConstantDependenciesTask); |
| 1179 expect(outputs[CONSTANT_DEPENDENCIES], [x]); | 1172 expect(outputs[CONSTANT_DEPENDENCIES], [x]); |
| 1180 } | 1173 } |
| 1181 | 1174 |
| 1182 test_enumConstant() { | 1175 test_enumConstant() { |
| 1183 Source source = newSource( | 1176 Source source = newSource( |
| 1184 '/test.dart', | 1177 '/test.dart', |
| 1185 ''' | 1178 ''' |
| 1186 enum E {A, B, C} | 1179 enum E {A, B, C} |
| 1187 '''); | 1180 '''); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1231 } | 1224 } |
| 1232 | 1225 |
| 1233 @reflectiveTest | 1226 @reflectiveTest |
| 1234 class ComputeConstantValueTaskTest extends _AbstractDartTaskTest { | 1227 class ComputeConstantValueTaskTest extends _AbstractDartTaskTest { |
| 1235 EvaluationResultImpl computeClassAnnotation( | 1228 EvaluationResultImpl computeClassAnnotation( |
| 1236 Source source, CompilationUnit unit, String className) { | 1229 Source source, CompilationUnit unit, String className) { |
| 1237 for (CompilationUnitMember member in unit.declarations) { | 1230 for (CompilationUnitMember member in unit.declarations) { |
| 1238 if (member is ClassDeclaration && member.name.name == className) { | 1231 if (member is ClassDeclaration && member.name.name == className) { |
| 1239 expect(member.metadata, hasLength(1)); | 1232 expect(member.metadata, hasLength(1)); |
| 1240 Annotation annotation = member.metadata[0]; | 1233 Annotation annotation = member.metadata[0]; |
| 1241 ConstantEvaluationTarget_Annotation target = | 1234 ElementAnnotationImpl target = annotation.elementAnnotation; |
| 1242 new ConstantEvaluationTarget_Annotation( | |
| 1243 context, source, source, annotation); | |
| 1244 computeResult(target, CONSTANT_VALUE, | 1235 computeResult(target, CONSTANT_VALUE, |
| 1245 matcher: isComputeConstantValueTask); | 1236 matcher: isComputeConstantValueTask); |
| 1246 expect(outputs[CONSTANT_VALUE], same(target)); | 1237 expect(outputs[CONSTANT_VALUE], same(target)); |
| 1247 EvaluationResultImpl evaluationResult = | 1238 EvaluationResultImpl evaluationResult = |
| 1248 (annotation.elementAnnotation as ElementAnnotationImpl) | 1239 (annotation.elementAnnotation as ElementAnnotationImpl) |
| 1249 .evaluationResult; | 1240 .evaluationResult; |
| 1250 return evaluationResult; | 1241 return evaluationResult; |
| 1251 } | 1242 } |
| 1252 } | 1243 } |
| 1253 fail('Annotation not found'); | 1244 fail('Annotation not found'); |
| (...skipping 3694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4948 /** | 4939 /** |
| 4949 * Fill [errorListener] with [result] errors in the current [task]. | 4940 * Fill [errorListener] with [result] errors in the current [task]. |
| 4950 */ | 4941 */ |
| 4951 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 4942 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 4952 List<AnalysisError> errors = task.outputs[result]; | 4943 List<AnalysisError> errors = task.outputs[result]; |
| 4953 expect(errors, isNotNull, reason: result.name); | 4944 expect(errors, isNotNull, reason: result.name); |
| 4954 errorListener = new GatheringErrorListener(); | 4945 errorListener = new GatheringErrorListener(); |
| 4955 errorListener.addAll(errors); | 4946 errorListener.addAll(errors); |
| 4956 } | 4947 } |
| 4957 } | 4948 } |
| OLD | NEW |