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

Side by Side 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, 3 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 unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/task/dart.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 29 matching lines...) Expand all
40 runReflectiveTests(BuildTypeProviderTaskTest); 40 runReflectiveTests(BuildTypeProviderTaskTest);
41 runReflectiveTests(ComputeConstantDependenciesTaskTest); 41 runReflectiveTests(ComputeConstantDependenciesTaskTest);
42 runReflectiveTests(ComputeConstantValueTaskTest); 42 runReflectiveTests(ComputeConstantValueTaskTest);
43 runReflectiveTests(ComputeInferableStaticVariableDependenciesTaskTest); 43 runReflectiveTests(ComputeInferableStaticVariableDependenciesTaskTest);
44 runReflectiveTests(ContainingLibrariesTaskTest); 44 runReflectiveTests(ContainingLibrariesTaskTest);
45 runReflectiveTests(DartErrorsTaskTest); 45 runReflectiveTests(DartErrorsTaskTest);
46 runReflectiveTests(EvaluateUnitConstantsTaskTest); 46 runReflectiveTests(EvaluateUnitConstantsTaskTest);
47 runReflectiveTests(GatherUsedImportedElementsTaskTest); 47 runReflectiveTests(GatherUsedImportedElementsTaskTest);
48 runReflectiveTests(GatherUsedLocalElementsTaskTest); 48 runReflectiveTests(GatherUsedLocalElementsTaskTest);
49 runReflectiveTests(GenerateHintsTaskTest); 49 runReflectiveTests(GenerateHintsTaskTest);
50 runReflectiveTests(InferInstanceMembersInUnitTaskTest);
50 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest); 51 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest);
51 runReflectiveTests(InferStaticVariableTypeTaskTest); 52 runReflectiveTests(InferStaticVariableTypeTaskTest);
52 runReflectiveTests(LibraryErrorsReadyTaskTest); 53 runReflectiveTests(LibraryErrorsReadyTaskTest);
53 runReflectiveTests(LibraryUnitErrorsTaskTest); 54 runReflectiveTests(LibraryUnitErrorsTaskTest);
54 runReflectiveTests(ParseDartTaskTest); 55 runReflectiveTests(ParseDartTaskTest);
55 runReflectiveTests(PartiallyResolveReferencesTaskTest); 56 runReflectiveTests(PartiallyResolveReferencesTaskTest);
56 runReflectiveTests(ResolveUnitTypeNamesTaskTest); 57 runReflectiveTests(ResolveUnitTypeNamesTaskTest);
57 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); 58 runReflectiveTests(ResolveLibraryTypeNamesTaskTest);
58 runReflectiveTests(ResolveReferencesTaskTest); 59 runReflectiveTests(ResolveReferencesTaskTest);
59 runReflectiveTests(ResolveVariableReferencesTaskTest); 60 runReflectiveTests(ResolveVariableReferencesTaskTest);
(...skipping 1967 matching lines...) Expand 10 before | Expand all | Expand 10 after
2027 computeResult(target, HINTS); 2028 computeResult(target, HINTS);
2028 expect(task, new isInstanceOf<GenerateHintsTask>()); 2029 expect(task, new isInstanceOf<GenerateHintsTask>());
2029 // validate 2030 // validate
2030 _fillErrorListener(HINTS); 2031 _fillErrorListener(HINTS);
2031 errorListener.assertErrorsWithCodes( 2032 errorListener.assertErrorsWithCodes(
2032 <ErrorCode>[HintCode.UNUSED_ELEMENT, HintCode.UNUSED_ELEMENT]); 2033 <ErrorCode>[HintCode.UNUSED_ELEMENT, HintCode.UNUSED_ELEMENT]);
2033 } 2034 }
2034 } 2035 }
2035 2036
2036 @reflectiveTest 2037 @reflectiveTest
2038 class InferInstanceMembersInUnitTaskTest extends _AbstractDartTaskTest {
2039 void test_perform() {
2040 enableStrongMode();
2041 AnalysisTarget source = newSource(
2042 '/test.dart',
2043 '''
2044 class A {
2045 X f;
2046 Y m(Z x) {}
2047 }
2048 class B extends A {
2049 var f;
2050 m(x) {}
2051 }
2052 class X {}
2053 class Y {}
2054 class Z {}
2055 ''');
2056 computeResult(new LibrarySpecificUnit(source, source),
2057 RESOLVED_UNIT7); // new isInstanceOf<InferInstanceMembersInUnitTask>()
2058 CompilationUnit unit = outputs[RESOLVED_UNIT7];
2059 VariableDeclaration field = getFieldInClass(unit, 'B', 'f');
2060 MethodDeclaration method = getMethodInClass(unit, 'B', 'm');
2061 DartType typeX = getClass(unit, 'X').element.type;
2062 DartType typeY = getClass(unit, 'Y').element.type;
2063 DartType typeZ = getClass(unit, 'Z').element.type;
2064
2065 expect(field.element.type, typeX);
2066 expect(method.element.returnType, typeY);
2067 expect(method.element.parameters[0].type, typeZ);
2068 }
2069 }
2070
2071 @reflectiveTest
2037 class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest { 2072 class InferStaticVariableTypesInUnitTaskTest extends _AbstractDartTaskTest {
2038 void test_perform() { 2073 void test_perform() {
2039 enableStrongMode(); 2074 enableStrongMode();
2040 AnalysisTarget firstSource = newSource( 2075 AnalysisTarget firstSource = newSource(
2041 '/first.dart', 2076 '/first.dart',
2042 ''' 2077 '''
2043 import 'second.dart'; 2078 import 'second.dart';
2044 2079
2045 var a = new M(); 2080 var a = new M();
2046 var c = b; 2081 var c = b;
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
3013 if (field.name.name == fieldName) { 3048 if (field.name.name == fieldName) {
3014 return field; 3049 return field;
3015 } 3050 }
3016 } 3051 }
3017 } 3052 }
3018 } 3053 }
3019 return null; 3054 return null;
3020 } 3055 }
3021 3056
3022 /** 3057 /**
3058 * Return the declaration of the method with the given [methodName] in the
3059 * class with the given [className] in the given compilation [unit].
3060 */
3061 MethodDeclaration getMethodInClass(
3062 CompilationUnit unit, String className, String methodName) {
3063 ClassDeclaration unitMember = getClass(unit, className);
3064 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
3065 return null;
3066 }
3067 NodeList<ClassMember> classMembers = unitMember.members;
3068 for (ClassMember classMember in classMembers) {
3069 if (classMember is MethodDeclaration) {
3070 if (classMember.name.name == methodName) {
3071 return classMember;
3072 }
3073 }
3074 }
3075 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
3076 }
3077
3078 /**
3023 * Return the declaration of the top-level variable with the given 3079 * Return the declaration of the top-level variable with the given
3024 * [variableName] in the given compilation [unit]. 3080 * [variableName] in the given compilation [unit].
3025 */ 3081 */
3026 VariableDeclaration getTopLevelVariable( 3082 VariableDeclaration getTopLevelVariable(
3027 CompilationUnit unit, String variableName) { 3083 CompilationUnit unit, String variableName) {
3028 NodeList<CompilationUnitMember> unitMembers = unit.declarations; 3084 NodeList<CompilationUnitMember> unitMembers = unit.declarations;
3029 for (CompilationUnitMember unitMember in unitMembers) { 3085 for (CompilationUnitMember unitMember in unitMembers) {
3030 if (unitMember is TopLevelVariableDeclaration) { 3086 if (unitMember is TopLevelVariableDeclaration) {
3031 NodeList<VariableDeclaration> variables = 3087 NodeList<VariableDeclaration> variables =
3032 unitMember.variables.variables; 3088 unitMember.variables.variables;
(...skipping 15 matching lines...) Expand all
3048 /** 3104 /**
3049 * Fill [errorListener] with [result] errors in the current [task]. 3105 * Fill [errorListener] with [result] errors in the current [task].
3050 */ 3106 */
3051 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { 3107 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) {
3052 List<AnalysisError> errors = task.outputs[result]; 3108 List<AnalysisError> errors = task.outputs[result];
3053 expect(errors, isNotNull, reason: result.name); 3109 expect(errors, isNotNull, reason: result.name);
3054 errorListener = new GatheringErrorListener(); 3110 errorListener = new GatheringErrorListener();
3055 errorListener.addAll(errors); 3111 errorListener.addAll(errors);
3056 } 3112 }
3057 } 3113 }
OLDNEW
« 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