| 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 test.src.task.dart_test; | 5 library test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/constant.dart'; | 9 import 'package:analyzer/src/generated/constant.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 } | 1161 } |
| 1162 } | 1162 } |
| 1163 | 1163 |
| 1164 @reflectiveTest | 1164 @reflectiveTest |
| 1165 class ComputeConstantDependenciesTaskTest extends _AbstractDartTaskTest { | 1165 class ComputeConstantDependenciesTaskTest extends _AbstractDartTaskTest { |
| 1166 test_perform() { | 1166 test_perform() { |
| 1167 Source source = newSource('/test.dart', ''' | 1167 Source source = newSource('/test.dart', ''' |
| 1168 const x = y; | 1168 const x = y; |
| 1169 const y = 1; | 1169 const y = 1; |
| 1170 '''); | 1170 '''); |
| 1171 // First compute the library element for the source. | 1171 // First compute the resolved unit for the source. |
| 1172 _computeResult(source, LIBRARY_ELEMENT1); | 1172 LibrarySpecificUnit librarySpecificUnit = |
| 1173 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT1]; | 1173 new LibrarySpecificUnit(source, source); |
| 1174 _computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
| 1175 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 1174 // Find the elements for the constants x and y. | 1176 // Find the elements for the constants x and y. |
| 1175 List<PropertyAccessorElement> accessors = | 1177 List<PropertyAccessorElement> accessors = unit.element.accessors; |
| 1176 libraryElement.definingCompilationUnit.accessors; | |
| 1177 Element x = accessors.firstWhere((PropertyAccessorElement accessor) => | 1178 Element x = accessors.firstWhere((PropertyAccessorElement accessor) => |
| 1178 accessor.isGetter && accessor.name == 'x').variable; | 1179 accessor.isGetter && accessor.name == 'x').variable; |
| 1179 Element y = accessors.firstWhere((PropertyAccessorElement accessor) => | 1180 Element y = accessors.firstWhere((PropertyAccessorElement accessor) => |
| 1180 accessor.isGetter && accessor.name == 'y').variable; | 1181 accessor.isGetter && accessor.name == 'y').variable; |
| 1181 // Now compute the dependencies for x, and check that it is the list [y]. | 1182 // Now compute the dependencies for x, and check that it is the list [y]. |
| 1182 _computeResult(x, CONSTANT_DEPENDENCIES); | 1183 _computeResult(x, CONSTANT_DEPENDENCIES); |
| 1183 expect(outputs[CONSTANT_DEPENDENCIES], [y]); | 1184 expect(outputs[CONSTANT_DEPENDENCIES], [y]); |
| 1184 } | 1185 } |
| 1185 } | 1186 } |
| 1186 | 1187 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1217 const x = 1; | 1218 const x = 1; |
| 1218 '''); | 1219 '''); |
| 1219 expect(evaluationResult, isNotNull); | 1220 expect(evaluationResult, isNotNull); |
| 1220 expect(evaluationResult.value, isNotNull); | 1221 expect(evaluationResult.value, isNotNull); |
| 1221 expect(evaluationResult.value.intValue, 1); | 1222 expect(evaluationResult.value.intValue, 1); |
| 1222 } | 1223 } |
| 1223 | 1224 |
| 1224 EvaluationResultImpl _computeTopLevelVariableConstValue( | 1225 EvaluationResultImpl _computeTopLevelVariableConstValue( |
| 1225 String variableName, String content) { | 1226 String variableName, String content) { |
| 1226 Source source = newSource('/test.dart', content); | 1227 Source source = newSource('/test.dart', content); |
| 1227 // First compute the library element for the source. | 1228 // First compute the resolved unit for the source. |
| 1228 _computeResult(source, LIBRARY_ELEMENT1); | 1229 LibrarySpecificUnit librarySpecificUnit = |
| 1229 LibraryElement libraryElement = outputs[LIBRARY_ELEMENT1]; | 1230 new LibrarySpecificUnit(source, source); |
| 1231 _computeResult(librarySpecificUnit, RESOLVED_UNIT1); |
| 1232 CompilationUnit unit = outputs[RESOLVED_UNIT1]; |
| 1230 // Find the element for the given constant. | 1233 // Find the element for the given constant. |
| 1231 List<PropertyAccessorElement> accessors = | 1234 List<PropertyAccessorElement> accessors = unit.element.accessors; |
| 1232 libraryElement.definingCompilationUnit.accessors; | |
| 1233 Element variableElement = accessors | 1235 Element variableElement = accessors |
| 1234 .firstWhere((PropertyAccessorElement accessor) { | 1236 .firstWhere((PropertyAccessorElement accessor) { |
| 1235 return accessor.isGetter && accessor.name == variableName; | 1237 return accessor.isGetter && accessor.name == variableName; |
| 1236 }).variable; | 1238 }).variable; |
| 1237 // Now compute the value of the constant. | 1239 // Now compute the value of the constant. |
| 1238 _computeResult(variableElement, CONSTANT_EVALUATED_ELEMENT); | 1240 _computeResult(variableElement, CONSTANT_EVALUATED_ELEMENT); |
| 1239 expect(outputs[CONSTANT_EVALUATED_ELEMENT], same(variableElement)); | 1241 expect(outputs[CONSTANT_EVALUATED_ELEMENT], same(variableElement)); |
| 1240 EvaluationResultImpl evaluationResult = | 1242 EvaluationResultImpl evaluationResult = |
| 1241 (variableElement as TopLevelVariableElementImpl).evaluationResult; | 1243 (variableElement as TopLevelVariableElementImpl).evaluationResult; |
| 1242 return evaluationResult; | 1244 return evaluationResult; |
| (...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2168 /** | 2170 /** |
| 2169 * Fill [errorListener] with [result] errors in the current [task]. | 2171 * Fill [errorListener] with [result] errors in the current [task]. |
| 2170 */ | 2172 */ |
| 2171 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 2173 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 2172 List<AnalysisError> errors = task.outputs[result]; | 2174 List<AnalysisError> errors = task.outputs[result]; |
| 2173 expect(errors, isNotNull, reason: result.name); | 2175 expect(errors, isNotNull, reason: result.name); |
| 2174 errorListener = new GatheringErrorListener(); | 2176 errorListener = new GatheringErrorListener(); |
| 2175 errorListener.addAll(errors); | 2177 errorListener.addAll(errors); |
| 2176 } | 2178 } |
| 2177 } | 2179 } |
| OLD | NEW |