Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Unified Diff: pkg/analyzer/test/src/task/dart_test.dart

Issue 1322983002: Implement task to infer instance members (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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].
*/
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698