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

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 1329743005: Abstract over the type system. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Cleanup small issues 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 engine.resolver_test; 5 library engine.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/context/context.dart' as newContext; 9 import 'package:analyzer/src/context/context.dart' as newContext;
10 import 'package:analyzer/src/generated/ast.dart'; 10 import 'package:analyzer/src/generated/ast.dart';
(...skipping 1969 matching lines...) Expand 10 before | Expand all | Expand 10 after
1980 FileBasedSource source = 1980 FileBasedSource source =
1981 new FileBasedSource(FileUtilities2.createFile("/test.dart")); 1981 new FileBasedSource(FileUtilities2.createFile("/test.dart"));
1982 CompilationUnitElementImpl definingCompilationUnit = 1982 CompilationUnitElementImpl definingCompilationUnit =
1983 new CompilationUnitElementImpl("test.dart"); 1983 new CompilationUnitElementImpl("test.dart");
1984 definingCompilationUnit.librarySource = 1984 definingCompilationUnit.librarySource =
1985 definingCompilationUnit.source = source; 1985 definingCompilationUnit.source = source;
1986 _definingLibrary = ElementFactory.library(context, "test"); 1986 _definingLibrary = ElementFactory.library(context, "test");
1987 _definingLibrary.definingCompilationUnit = definingCompilationUnit; 1987 _definingLibrary.definingCompilationUnit = definingCompilationUnit;
1988 Library library = new Library(context, _listener, source); 1988 Library library = new Library(context, _listener, source);
1989 library.libraryElement = _definingLibrary; 1989 library.libraryElement = _definingLibrary;
1990 _visitor = new ResolverVisitor( 1990 _visitor = new ResolverVisitor(library.libraryElement, source,
1991 library.libraryElement, source, _typeProvider, library.errorListener, 1991 _typeProvider, context.typeSystem, library.errorListener,
1992 nameScope: library.libraryScope, 1992 nameScope: library.libraryScope,
1993 inheritanceManager: library.inheritanceManager); 1993 inheritanceManager: library.inheritanceManager);
1994 try { 1994 try {
1995 return _visitor.elementResolver; 1995 return _visitor.elementResolver;
1996 } catch (exception) { 1996 } catch (exception) {
1997 throw new IllegalArgumentException( 1997 throw new IllegalArgumentException(
1998 "Could not create resolver", exception); 1998 "Could not create resolver", exception);
1999 } 1999 }
2000 } 2000 }
2001 2001
(...skipping 5885 matching lines...) Expand 10 before | Expand all | Expand 10 after
7887 7887
7888 /** 7888 /**
7889 * Return a type provider that can be used to test the results of resolution. 7889 * Return a type provider that can be used to test the results of resolution.
7890 * 7890 *
7891 * @return a type provider 7891 * @return a type provider
7892 * @throws AnalysisException if dart:core cannot be resolved 7892 * @throws AnalysisException if dart:core cannot be resolved
7893 */ 7893 */
7894 TypeProvider get typeProvider => analysisContext2.typeProvider; 7894 TypeProvider get typeProvider => analysisContext2.typeProvider;
7895 7895
7896 /** 7896 /**
7897 * Return a type system that can be used to test the results of resolution.
7898 *
7899 * @return a type system
7900 */
7901 TypeSystem get typeSystem => analysisContext2.typeSystem;
7902
7903 /**
7897 * Add a source file to the content provider. The file path should be absolute . 7904 * Add a source file to the content provider. The file path should be absolute .
7898 * 7905 *
7899 * @param filePath the path of the file being added 7906 * @param filePath the path of the file being added
7900 * @param contents the contents to be returned by the content provider for the specified file 7907 * @param contents the contents to be returned by the content provider for the specified file
7901 * @return the source object representing the added file 7908 * @return the source object representing the added file
7902 */ 7909 */
7903 Source addNamedSource(String filePath, String contents) { 7910 Source addNamedSource(String filePath, String contents) {
7904 Source source = cacheSource(filePath, contents); 7911 Source source = cacheSource(filePath, contents);
7905 ChangeSet changeSet = new ChangeSet(); 7912 ChangeSet changeSet = new ChangeSet();
7906 changeSet.addedSource(source); 7913 changeSet.addedSource(source);
(...skipping 3465 matching lines...) Expand 10 before | Expand all | Expand 10 after
11372 new FileBasedSource(FileUtilities2.createFile("/lib.dart")); 11379 new FileBasedSource(FileUtilities2.createFile("/lib.dart"));
11373 CompilationUnitElementImpl definingCompilationUnit = 11380 CompilationUnitElementImpl definingCompilationUnit =
11374 new CompilationUnitElementImpl("lib.dart"); 11381 new CompilationUnitElementImpl("lib.dart");
11375 definingCompilationUnit.librarySource = 11382 definingCompilationUnit.librarySource =
11376 definingCompilationUnit.source = source; 11383 definingCompilationUnit.source = source;
11377 LibraryElementImpl definingLibrary = 11384 LibraryElementImpl definingLibrary =
11378 new LibraryElementImpl.forNode(context, null); 11385 new LibraryElementImpl.forNode(context, null);
11379 definingLibrary.definingCompilationUnit = definingCompilationUnit; 11386 definingLibrary.definingCompilationUnit = definingCompilationUnit;
11380 Library library = new Library(context, _listener, source); 11387 Library library = new Library(context, _listener, source);
11381 library.libraryElement = definingLibrary; 11388 library.libraryElement = definingLibrary;
11382 _visitor = new ResolverVisitor( 11389 _visitor = new ResolverVisitor(library.libraryElement, source,
11383 library.libraryElement, source, _typeProvider, library.errorListener, 11390 _typeProvider, context.typeSystem, library.errorListener,
11384 nameScope: library.libraryScope, 11391 nameScope: library.libraryScope,
11385 inheritanceManager: library.inheritanceManager); 11392 inheritanceManager: library.inheritanceManager);
11386 _visitor.overrideManager.enterScope(); 11393 _visitor.overrideManager.enterScope();
11387 try { 11394 try {
11388 return _visitor.typeAnalyzer; 11395 return _visitor.typeAnalyzer;
11389 } catch (exception) { 11396 } catch (exception) {
11390 throw new IllegalArgumentException( 11397 throw new IllegalArgumentException(
11391 "Could not create analyzer", exception); 11398 "Could not create analyzer", exception);
11392 } 11399 }
11393 } 11400 }
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
11951 } 11958 }
11952 }'''; 11959 }''';
11953 _assertPropagatedIterationType(code, typeProvider.intType, null); 11960 _assertPropagatedIterationType(code, typeProvider.intType, null);
11954 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 11961 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
11955 } 11962 }
11956 11963
11957 void test_localVariableInference_bottom_disabled() { 11964 void test_localVariableInference_bottom_disabled() {
11958 String code = r''' 11965 String code = r'''
11959 main() { 11966 main() {
11960 var v = null; 11967 var v = null;
11961 return v; // marker 11968 v; // marker
11962 }'''; 11969 }''';
11963 _assertPropagatedAssignedType(code, typeProvider.dynamicType, null); 11970 _assertPropagatedAssignedType(code, typeProvider.dynamicType, null);
11964 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, null); 11971 _assertTypeOfMarkedExpression(code, typeProvider.dynamicType, null);
11965 } 11972 }
11966 11973
11967 void test_localVariableInference_constant() { 11974 void test_localVariableInference_constant() {
11968 String code = r''' 11975 String code = r'''
11969 main() { 11976 main() {
11970 var v = 3; 11977 var v = 3;
11971 return v; // marker 11978 v; // marker
11972 }'''; 11979 }''';
11973 _assertPropagatedAssignedType(code, typeProvider.intType, null); 11980 _assertPropagatedAssignedType(code, typeProvider.intType, null);
11974 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 11981 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
11975 } 11982 }
11976 11983
11977 void test_localVariableInference_declaredType_disabled() { 11984 void test_localVariableInference_declaredType_disabled() {
11978 String code = r''' 11985 String code = r'''
11979 main() { 11986 main() {
11980 dynamic v = 3; 11987 dynamic v = 3;
11981 return v; // marker 11988 v; // marker
11982 }'''; 11989 }''';
11983 _assertPropagatedAssignedType( 11990 _assertPropagatedAssignedType(
11984 code, typeProvider.dynamicType, typeProvider.intType); 11991 code, typeProvider.dynamicType, typeProvider.intType);
11985 _assertTypeOfMarkedExpression( 11992 _assertTypeOfMarkedExpression(
11986 code, typeProvider.dynamicType, typeProvider.intType); 11993 code, typeProvider.dynamicType, typeProvider.intType);
11987 } 11994 }
11988 11995
11989 void test_localVariableInference_noInitializer_disabled() { 11996 void test_localVariableInference_noInitializer_disabled() {
11990 String code = r''' 11997 String code = r'''
11991 main() { 11998 main() {
11992 var v; 11999 var v;
11993 v = 3; 12000 v = 3;
11994 return v; // marker 12001 v; // marker
11995 }'''; 12002 }''';
11996 _assertPropagatedAssignedType( 12003 _assertPropagatedAssignedType(
11997 code, typeProvider.dynamicType, typeProvider.intType); 12004 code, typeProvider.dynamicType, typeProvider.intType);
11998 _assertTypeOfMarkedExpression( 12005 _assertTypeOfMarkedExpression(
11999 code, typeProvider.dynamicType, typeProvider.intType); 12006 code, typeProvider.dynamicType, typeProvider.intType);
12000 } 12007 }
12001 12008
12002 void test_localVariableInference_transitive_field_inferred_lexical() { 12009 void test_localVariableInference_transitive_field_inferred_lexical() {
12003 if (!AnalysisEngine.instance.useTaskModel) { 12010 if (!AnalysisEngine.instance.useTaskModel) {
12004 return; 12011 return;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
12067 '''; 12074 ''';
12068 _assertPropagatedAssignedType(code, typeProvider.intType, null); 12075 _assertPropagatedAssignedType(code, typeProvider.intType, null);
12069 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 12076 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
12070 } 12077 }
12071 12078
12072 void test_localVariableInference_transitive_list_local() { 12079 void test_localVariableInference_transitive_list_local() {
12073 String code = r''' 12080 String code = r'''
12074 main() { 12081 main() {
12075 var x = <int>[3]; 12082 var x = <int>[3];
12076 var v = x[0]; 12083 var v = x[0];
12077 return v; // marker 12084 v; // marker
12078 }'''; 12085 }''';
12079 _assertPropagatedAssignedType(code, typeProvider.intType, null); 12086 _assertPropagatedAssignedType(code, typeProvider.intType, null);
12080 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 12087 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
12081 } 12088 }
12082 12089
12083 void test_localVariableInference_transitive_local() { 12090 void test_localVariableInference_transitive_local() {
12084 String code = r''' 12091 String code = r'''
12085 main() { 12092 main() {
12086 var x = 3; 12093 var x = 3;
12087 var v = x; 12094 var v = x;
12088 return v; // marker 12095 v; // marker
12089 }'''; 12096 }''';
12090 _assertPropagatedAssignedType(code, typeProvider.intType, null); 12097 _assertPropagatedAssignedType(code, typeProvider.intType, null);
12091 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 12098 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
12092 } 12099 }
12093 12100
12094 void test_localVariableInference_transitive_toplevel_inferred_lexical() { 12101 void test_localVariableInference_transitive_toplevel_inferred_lexical() {
12095 if (!AnalysisEngine.instance.useTaskModel) { 12102 if (!AnalysisEngine.instance.useTaskModel) {
12096 return; 12103 return;
12097 } 12104 }
12098 String code = r''' 12105 String code = r'''
12099 final x = 3; 12106 final x = 3;
12100 main() { 12107 main() {
12101 var v = x; 12108 var v = x;
12102 return v; // marker 12109 v; // marker
12103 } 12110 }
12104 '''; 12111 ''';
12105 _assertPropagatedAssignedType(code, typeProvider.intType, null); 12112 _assertPropagatedAssignedType(code, typeProvider.intType, null);
12106 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 12113 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
12107 } 12114 }
12108 12115
12109 void test_localVariableInference_transitive_toplevel_inferred_reversed() { 12116 void test_localVariableInference_transitive_toplevel_inferred_reversed() {
12110 if (!AnalysisEngine.instance.useTaskModel) { 12117 if (!AnalysisEngine.instance.useTaskModel) {
12111 return; 12118 return;
12112 } 12119 }
12113 String code = r''' 12120 String code = r'''
12114 main() { 12121 main() {
12115 var v = x; 12122 var v = x;
12116 return v; // marker 12123 v; // marker
12117 } 12124 }
12118 final x = 3; 12125 final x = 3;
12119 '''; 12126 ''';
12120 _assertPropagatedAssignedType(code, typeProvider.intType, null); 12127 _assertPropagatedAssignedType(code, typeProvider.intType, null);
12121 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 12128 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
12122 } 12129 }
12123 12130
12124 void test_localVariableInference_transitive_toplevel_lexical() { 12131 void test_localVariableInference_transitive_toplevel_lexical() {
12125 String code = r''' 12132 String code = r'''
12126 int x = 3; 12133 int x = 3;
12127 main() { 12134 main() {
12128 var v = x; 12135 var v = x;
12129 return v; // marker 12136 v; // marker
12130 } 12137 }
12131 '''; 12138 ''';
12132 _assertPropagatedAssignedType(code, typeProvider.intType, null); 12139 _assertPropagatedAssignedType(code, typeProvider.intType, null);
12133 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 12140 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
12134 } 12141 }
12135 12142
12136 void test_localVariableInference_transitive_toplevel_reversed() { 12143 void test_localVariableInference_transitive_toplevel_reversed() {
12137 String code = r''' 12144 String code = r'''
12138 main() { 12145 main() {
12139 var v = x; 12146 var v = x;
12140 return v; // marker 12147 v; // marker
12141 } 12148 }
12142 int x = 3; 12149 int x = 3;
12143 '''; 12150 ''';
12144 _assertPropagatedAssignedType(code, typeProvider.intType, null); 12151 _assertPropagatedAssignedType(code, typeProvider.intType, null);
12145 _assertTypeOfMarkedExpression(code, typeProvider.intType, null); 12152 _assertTypeOfMarkedExpression(code, typeProvider.intType, null);
12146 } 12153 }
12147 } 12154 }
12148 12155
12149 @reflectiveTest 12156 @reflectiveTest
12150 class SubtypeManagerTest extends EngineTestCase { 12157 class SubtypeManagerTest extends EngineTestCase {
(...skipping 2399 matching lines...) Expand 10 before | Expand all | Expand 10 after
14550 // check propagated type 14557 // check propagated type
14551 FunctionType propagatedType = node.propagatedType as FunctionType; 14558 FunctionType propagatedType = node.propagatedType as FunctionType;
14552 expect(propagatedType.returnType, test.typeProvider.stringType); 14559 expect(propagatedType.returnType, test.typeProvider.stringType);
14553 } on AnalysisException catch (e, stackTrace) { 14560 } on AnalysisException catch (e, stackTrace) {
14554 thrownException[0] = new CaughtException(e, stackTrace); 14561 thrownException[0] = new CaughtException(e, stackTrace);
14555 } 14562 }
14556 } 14563 }
14557 return null; 14564 return null;
14558 } 14565 }
14559 } 14566 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698