Chromium Code Reviews| Index: pkg/analyzer/test/src/task/dart_test.dart |
| diff --git a/pkg/analyzer/test/src/task/dart_test.dart b/pkg/analyzer/test/src/task/dart_test.dart |
| index f2184611aa7391ae1f7d6e6448fee7e7daabb6eb..6e0bb485ab9f1829ceb3bf7767c556ea1d915001 100644 |
| --- a/pkg/analyzer/test/src/task/dart_test.dart |
| +++ b/pkg/analyzer/test/src/task/dart_test.dart |
| @@ -47,6 +47,7 @@ main() { |
| runReflectiveTests(GatherUsedImportedElementsTaskTest); |
| runReflectiveTests(GatherUsedLocalElementsTaskTest); |
| runReflectiveTests(GenerateHintsTaskTest); |
| + runReflectiveTests(InferInstanceMembersInUnitTaskTest); |
| runReflectiveTests(InferStaticVariableTypesInUnitTaskTest); |
| runReflectiveTests(InferStaticVariableTypeTaskTest); |
| runReflectiveTests(LibraryErrorsReadyTaskTest); |
| @@ -2034,6 +2035,40 @@ f(A a) { |
| } |
| @reflectiveTest |
| +class InferInstanceMembersInUnitTaskTest extends _AbstractDartTaskTest { |
| + void test_perform() { |
| + enableStrongMode(); |
| + AnalysisTarget source = newSource( |
| + '/test.dart', |
| + ''' |
| +class A { |
| + X f; |
| + Y m(Z x) {} |
| +} |
| +class B extends A { |
| + var f; |
| + m(x) {} |
| +} |
| +class X {} |
| +class Y {} |
| +class Z {} |
| +'''); |
| + computeResult(new LibrarySpecificUnit(source, source), |
| + RESOLVED_UNIT7); // new isInstanceOf<InferInstanceMembersInUnitTask>() |
| + CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| + VariableDeclaration field = getFieldInClass(unit, 'B', 'f'); |
| + MethodDeclaration method = getMethodInClass(unit, 'B', 'm'); |
| + DartType typeX = getClass(unit, 'X').element.type; |
| + DartType typeY = getClass(unit, 'Y').element.type; |
| + DartType typeZ = getClass(unit, 'Z').element.type; |
| + |
| + expect(field.element.type, typeX); |
| + expect(method.element.returnType, typeY); |
| + expect(method.element.parameters[0].type, typeZ); |
| + } |
| +} |
| + |
| +@reflectiveTest |
| class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest { |
| void test_perform() { |
| enableStrongMode(); |
| @@ -3020,6 +3055,27 @@ class _AbstractDartTaskTest extends AbstractContextTest { |
| } |
| /** |
| + * Return the declaration of the method with the given [methodName] in the |
| + * class with the given [className] in the given compilation [unit]. |
| + */ |
| + MethodDeclaration getMethodInClass( |
| + CompilationUnit unit, String className, String methodName) { |
| + ClassDeclaration unitMember = getClass(unit, className); |
| + if (unitMember == null) { |
|
Paul Berry
2015/08/31 20:39:24
Nit: since this is test code, I don't think it's n
Brian Wilkerson
2015/08/31 21:23:34
Based on the next comment, I just put a call to 'f
|
| + return null; |
| + } |
| + NodeList<ClassMember> classMembers = unitMember.members; |
| + for (ClassMember classMember in classMembers) { |
| + if (classMember is MethodDeclaration) { |
| + if (classMember.name.name == methodName) { |
| + return classMember; |
| + } |
| + } |
| + } |
| + return null; |
|
Paul Berry
2015/08/31 20:39:24
Similarly, consider changing this to something lik
Brian Wilkerson
2015/08/31 21:23:34
I added the file (but can't remove the return with
|
| + } |
| + |
| + /** |
| * Return the declaration of the top-level variable with the given |
| * [variableName] in the given compilation [unit]. |
| */ |