| OLD | NEW |
| 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/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 import 'package:analyzer/src/generated/sdk.dart'; | 21 import 'package:analyzer/src/generated/sdk.dart'; |
| 22 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; | 22 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; |
| 23 import 'package:analyzer/src/generated/source_io.dart'; | 23 import 'package:analyzer/src/generated/source_io.dart'; |
| 24 import 'package:analyzer/src/generated/static_type_analyzer.dart'; | 24 import 'package:analyzer/src/generated/static_type_analyzer.dart'; |
| 25 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 25 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 26 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 26 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 27 import 'package:analyzer/src/generated/utilities_dart.dart'; | 27 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 28 import 'package:unittest/unittest.dart'; | 28 import 'package:unittest/unittest.dart'; |
| 29 | 29 |
| 30 import '../reflective_tests.dart'; | 30 import '../reflective_tests.dart'; |
| 31 import 'parser_test.dart'; | |
| 32 import 'test_support.dart'; | 31 import 'test_support.dart'; |
| 33 | 32 |
| 34 | 33 |
| 35 main() { | 34 main() { |
| 36 groupSep = ' | '; | 35 groupSep = ' | '; |
| 37 runReflectiveTests(AnalysisDeltaTest); | 36 runReflectiveTests(AnalysisDeltaTest); |
| 38 runReflectiveTests(ChangeSetTest); | 37 runReflectiveTests(ChangeSetTest); |
| 39 runReflectiveTests(EnclosedScopeTest); | 38 runReflectiveTests(EnclosedScopeTest); |
| 40 runReflectiveTests(LibraryImportScopeTest); | 39 runReflectiveTests(LibraryImportScopeTest); |
| 41 runReflectiveTests(LibraryScopeTest); | 40 runReflectiveTests(LibraryScopeTest); |
| 42 runReflectiveTests(ScopeBuilderTest); | |
| 43 runReflectiveTests(ScopeTest); | 41 runReflectiveTests(ScopeTest); |
| 44 runReflectiveTests(DeclarationMatcherTest); | |
| 45 runReflectiveTests(ElementResolverTest); | 42 runReflectiveTests(ElementResolverTest); |
| 46 runReflectiveTests(IncrementalResolverTest); | |
| 47 runReflectiveTests(InheritanceManagerTest); | 43 runReflectiveTests(InheritanceManagerTest); |
| 48 runReflectiveTests(LibraryElementBuilderTest); | 44 runReflectiveTests(LibraryElementBuilderTest); |
| 49 runReflectiveTests(LibraryResolver2Test); | 45 runReflectiveTests(LibraryResolver2Test); |
| 50 runReflectiveTests(LibraryResolverTest); | 46 runReflectiveTests(LibraryResolverTest); |
| 51 runReflectiveTests(LibraryTest); | 47 runReflectiveTests(LibraryTest); |
| 52 runReflectiveTests(StaticTypeAnalyzerTest); | 48 runReflectiveTests(StaticTypeAnalyzerTest); |
| 53 runReflectiveTests(StaticTypeAnalyzer2Test); | 49 runReflectiveTests(StaticTypeAnalyzer2Test); |
| 54 runReflectiveTests(SubtypeManagerTest); | 50 runReflectiveTests(SubtypeManagerTest); |
| 55 runReflectiveTests(TypeOverrideManagerTest); | 51 runReflectiveTests(TypeOverrideManagerTest); |
| 56 runReflectiveTests(TypeProviderImplTest); | 52 runReflectiveTests(TypeProviderImplTest); |
| (...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 resolve(source); | 1130 resolve(source); |
| 1135 assertErrors( | 1131 assertErrors( |
| 1136 source, | 1132 source, |
| 1137 [ | 1133 [ |
| 1138 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, | 1134 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, |
| 1139 StaticWarningCode.UNDEFINED_CLASS]); | 1135 StaticWarningCode.UNDEFINED_CLASS]); |
| 1140 verify([source]); | 1136 verify([source]); |
| 1141 } | 1137 } |
| 1142 } | 1138 } |
| 1143 | 1139 |
| 1144 class DeclarationMatcherTest extends ResolverTestCase { | |
| 1145 void test_compilationUnitMatches_false_topLevelVariable() { | |
| 1146 _assertCompilationUnitMatches(false, r''' | |
| 1147 class C { | |
| 1148 int m(int p) { | |
| 1149 return p + p; | |
| 1150 } | |
| 1151 }''', r''' | |
| 1152 const int ZERO = 0; | |
| 1153 class C { | |
| 1154 int m(int p) { | |
| 1155 return p + p; | |
| 1156 } | |
| 1157 }'''); | |
| 1158 } | |
| 1159 | |
| 1160 void test_compilationUnitMatches_true_different() { | |
| 1161 _assertCompilationUnitMatches(true, r''' | |
| 1162 class C { | |
| 1163 int m(int p) { | |
| 1164 return p + p; | |
| 1165 } | |
| 1166 }''', r''' | |
| 1167 class C { | |
| 1168 int m(int p) { | |
| 1169 return (p * p) + (p * p); | |
| 1170 } | |
| 1171 }'''); | |
| 1172 } | |
| 1173 | |
| 1174 void test_compilationUnitMatches_true_same() { | |
| 1175 String content = r''' | |
| 1176 class C { | |
| 1177 int m(int p) { | |
| 1178 return p + p; | |
| 1179 } | |
| 1180 }'''; | |
| 1181 _assertCompilationUnitMatches(true, content, content); | |
| 1182 } | |
| 1183 | |
| 1184 void test_methodDeclarationMatches_false_localVariable() { | |
| 1185 _assertMethodMatches(false, r''' | |
| 1186 class C { | |
| 1187 int m(int p) { | |
| 1188 return p + p; | |
| 1189 } | |
| 1190 }''', r''' | |
| 1191 class C { | |
| 1192 int m(int p) { | |
| 1193 int product = p * p; | |
| 1194 return product + product; | |
| 1195 } | |
| 1196 }'''); | |
| 1197 } | |
| 1198 | |
| 1199 void test_methodDeclarationMatches_false_parameter() { | |
| 1200 _assertMethodMatches(false, r''' | |
| 1201 class C { | |
| 1202 int m(int p) { | |
| 1203 return p + p; | |
| 1204 } | |
| 1205 }''', r''' | |
| 1206 class C { | |
| 1207 int m(int p, int q) { | |
| 1208 return (p * q) + (q * p); | |
| 1209 } | |
| 1210 }'''); | |
| 1211 } | |
| 1212 | |
| 1213 void test_methodDeclarationMatches_true_different() { | |
| 1214 _assertMethodMatches(true, r''' | |
| 1215 class C { | |
| 1216 int m(int p) { | |
| 1217 return p + p; | |
| 1218 } | |
| 1219 }''', r''' | |
| 1220 class C { | |
| 1221 int m(int p) { | |
| 1222 return (p * p) + (p * p); | |
| 1223 } | |
| 1224 }'''); | |
| 1225 } | |
| 1226 | |
| 1227 void test_methodDeclarationMatches_true_same() { | |
| 1228 String content = r''' | |
| 1229 class C { | |
| 1230 int m(int p) { | |
| 1231 return p + p; | |
| 1232 } | |
| 1233 }'''; | |
| 1234 _assertMethodMatches(true, content, content); | |
| 1235 } | |
| 1236 | |
| 1237 void _assertCompilationUnitMatches(bool expectMatch, String oldContent, | |
| 1238 String newContent) { | |
| 1239 Source source = addSource(oldContent); | |
| 1240 LibraryElement library = resolve(source); | |
| 1241 CompilationUnit oldUnit = resolveCompilationUnit(source, library); | |
| 1242 CompilationUnit newUnit = ParserTestCase.parseCompilationUnit(newContent); | |
| 1243 DeclarationMatcher matcher = new DeclarationMatcher(); | |
| 1244 expect(matcher.matches(newUnit, oldUnit.element), expectMatch); | |
| 1245 } | |
| 1246 | |
| 1247 void _assertMethodMatches(bool expectMatch, String oldContent, | |
| 1248 String newContent) { | |
| 1249 Source source = addSource(oldContent); | |
| 1250 LibraryElement library = resolve(source); | |
| 1251 CompilationUnit oldUnit = resolveCompilationUnit(source, library); | |
| 1252 MethodElement element = _getFirstMethod(oldUnit).element as MethodElement; | |
| 1253 AnalysisContext context = analysisContext; | |
| 1254 context.setContents(source, newContent); | |
| 1255 CompilationUnit newUnit = context.parseCompilationUnit(source); | |
| 1256 MethodDeclaration newMethod = _getFirstMethod(newUnit); | |
| 1257 DeclarationMatcher matcher = new DeclarationMatcher(); | |
| 1258 expect(matcher.matches(newMethod, element), expectMatch); | |
| 1259 } | |
| 1260 | |
| 1261 MethodDeclaration _getFirstMethod(CompilationUnit unit) { | |
| 1262 ClassDeclaration classNode = unit.declarations[0] as ClassDeclaration; | |
| 1263 return classNode.members[0] as MethodDeclaration; | |
| 1264 } | |
| 1265 } | |
| 1266 | |
| 1267 class ElementResolverTest extends EngineTestCase { | 1140 class ElementResolverTest extends EngineTestCase { |
| 1268 /** | 1141 /** |
| 1269 * The error listener to which errors will be reported. | 1142 * The error listener to which errors will be reported. |
| 1270 */ | 1143 */ |
| 1271 GatheringErrorListener _listener; | 1144 GatheringErrorListener _listener; |
| 1272 | 1145 |
| 1273 /** | 1146 /** |
| 1274 * The type provider used to access the types. | 1147 * The type provider used to access the types. |
| 1275 */ | 1148 */ |
| 1276 TestTypeProvider _typeProvider; | 1149 TestTypeProvider _typeProvider; |
| (...skipping 3215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4492 } | 4365 } |
| 4493 }'''); | 4366 }'''); |
| 4494 resolve(source); | 4367 resolve(source); |
| 4495 assertErrors( | 4368 assertErrors( |
| 4496 source, | 4369 source, |
| 4497 [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); | 4370 [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); |
| 4498 verify([source]); | 4371 verify([source]); |
| 4499 } | 4372 } |
| 4500 } | 4373 } |
| 4501 | 4374 |
| 4502 class IncrementalResolverTest extends ResolverTestCase { | |
| 4503 void test_resolve() { | |
| 4504 MethodDeclaration method = _resolveMethod(r''' | |
| 4505 class C { | |
| 4506 int m(int a) { | |
| 4507 return a + a; | |
| 4508 } | |
| 4509 }'''); | |
| 4510 BlockFunctionBody body = method.body as BlockFunctionBody; | |
| 4511 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | |
| 4512 BinaryExpression expression = statement.expression as BinaryExpression; | |
| 4513 SimpleIdentifier left = expression.leftOperand as SimpleIdentifier; | |
| 4514 Element leftElement = left.staticElement; | |
| 4515 SimpleIdentifier right = expression.rightOperand as SimpleIdentifier; | |
| 4516 Element rightElement = right.staticElement; | |
| 4517 expect(leftElement, isNotNull); | |
| 4518 expect(rightElement, same(leftElement)); | |
| 4519 } | |
| 4520 | |
| 4521 MethodDeclaration _resolveMethod(String content) { | |
| 4522 Source source = addSource(content); | |
| 4523 LibraryElement library = resolve(source); | |
| 4524 CompilationUnit unit = resolveCompilationUnit(source, library); | |
| 4525 ClassDeclaration classNode = unit.declarations[0] as ClassDeclaration; | |
| 4526 MethodDeclaration method = classNode.members[0] as MethodDeclaration; | |
| 4527 method.body.accept(new ResolutionEraser()); | |
| 4528 GatheringErrorListener errorListener = new GatheringErrorListener(); | |
| 4529 IncrementalResolver resolver = | |
| 4530 new IncrementalResolver(library, source, typeProvider, errorListener); | |
| 4531 resolver.resolve(method.body); | |
| 4532 return method; | |
| 4533 } | |
| 4534 } | |
| 4535 | |
| 4536 class InheritanceManagerTest extends EngineTestCase { | 4375 class InheritanceManagerTest extends EngineTestCase { |
| 4537 /** | 4376 /** |
| 4538 * The type provider used to access the types. | 4377 * The type provider used to access the types. |
| 4539 */ | 4378 */ |
| 4540 TestTypeProvider _typeProvider; | 4379 TestTypeProvider _typeProvider; |
| 4541 | 4380 |
| 4542 /** | 4381 /** |
| 4543 * The library containing the code being resolved. | 4382 * The library containing the code being resolved. |
| 4544 */ | 4383 */ |
| 4545 LibraryElementImpl _definingLibrary; | 4384 LibraryElementImpl _definingLibrary; |
| (...skipping 3497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8043 | 7882 |
| 8044 @override | 7883 @override |
| 8045 AnalysisErrorListener get errorListener => listener; | 7884 AnalysisErrorListener get errorListener => listener; |
| 8046 | 7885 |
| 8047 @override | 7886 @override |
| 8048 Element internalLookup(Identifier identifier, String name, | 7887 Element internalLookup(Identifier identifier, String name, |
| 8049 LibraryElement referencingLibrary) => | 7888 LibraryElement referencingLibrary) => |
| 8050 null; | 7889 null; |
| 8051 } | 7890 } |
| 8052 | 7891 |
| 8053 class ScopeBuilderTest extends EngineTestCase { | |
| 8054 void test_scopeFor_ClassDeclaration() { | |
| 8055 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8056 Scope scope = | |
| 8057 ScopeBuilder.scopeFor(_createResolvedClassDeclaration(), listener); | |
| 8058 EngineTestCase.assertInstanceOf( | |
| 8059 (obj) => obj is LibraryScope, | |
| 8060 LibraryScope, | |
| 8061 scope); | |
| 8062 } | |
| 8063 | |
| 8064 void test_scopeFor_ClassTypeAlias() { | |
| 8065 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8066 Scope scope = | |
| 8067 ScopeBuilder.scopeFor(_createResolvedClassTypeAlias(), listener); | |
| 8068 EngineTestCase.assertInstanceOf( | |
| 8069 (obj) => obj is LibraryScope, | |
| 8070 LibraryScope, | |
| 8071 scope); | |
| 8072 } | |
| 8073 | |
| 8074 void test_scopeFor_CompilationUnit() { | |
| 8075 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8076 Scope scope = | |
| 8077 ScopeBuilder.scopeFor(_createResolvedCompilationUnit(), listener); | |
| 8078 EngineTestCase.assertInstanceOf( | |
| 8079 (obj) => obj is LibraryScope, | |
| 8080 LibraryScope, | |
| 8081 scope); | |
| 8082 } | |
| 8083 | |
| 8084 void test_scopeFor_ConstructorDeclaration() { | |
| 8085 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8086 Scope scope = | |
| 8087 ScopeBuilder.scopeFor(_createResolvedConstructorDeclaration(), listener)
; | |
| 8088 EngineTestCase.assertInstanceOf( | |
| 8089 (obj) => obj is ClassScope, | |
| 8090 ClassScope, | |
| 8091 scope); | |
| 8092 } | |
| 8093 | |
| 8094 void test_scopeFor_ConstructorDeclaration_parameters() { | |
| 8095 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8096 Scope scope = ScopeBuilder.scopeFor( | |
| 8097 _createResolvedConstructorDeclaration().parameters, | |
| 8098 listener); | |
| 8099 EngineTestCase.assertInstanceOf( | |
| 8100 (obj) => obj is FunctionScope, | |
| 8101 FunctionScope, | |
| 8102 scope); | |
| 8103 } | |
| 8104 | |
| 8105 void test_scopeFor_FunctionDeclaration() { | |
| 8106 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8107 Scope scope = | |
| 8108 ScopeBuilder.scopeFor(_createResolvedFunctionDeclaration(), listener); | |
| 8109 EngineTestCase.assertInstanceOf( | |
| 8110 (obj) => obj is LibraryScope, | |
| 8111 LibraryScope, | |
| 8112 scope); | |
| 8113 } | |
| 8114 | |
| 8115 void test_scopeFor_FunctionDeclaration_parameters() { | |
| 8116 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8117 Scope scope = ScopeBuilder.scopeFor( | |
| 8118 _createResolvedFunctionDeclaration().functionExpression.parameters, | |
| 8119 listener); | |
| 8120 EngineTestCase.assertInstanceOf( | |
| 8121 (obj) => obj is FunctionScope, | |
| 8122 FunctionScope, | |
| 8123 scope); | |
| 8124 } | |
| 8125 | |
| 8126 void test_scopeFor_FunctionTypeAlias() { | |
| 8127 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8128 Scope scope = | |
| 8129 ScopeBuilder.scopeFor(_createResolvedFunctionTypeAlias(), listener); | |
| 8130 EngineTestCase.assertInstanceOf( | |
| 8131 (obj) => obj is LibraryScope, | |
| 8132 LibraryScope, | |
| 8133 scope); | |
| 8134 } | |
| 8135 | |
| 8136 void test_scopeFor_FunctionTypeAlias_parameters() { | |
| 8137 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8138 Scope scope = | |
| 8139 ScopeBuilder.scopeFor(_createResolvedFunctionTypeAlias().parameters, lis
tener); | |
| 8140 EngineTestCase.assertInstanceOf( | |
| 8141 (obj) => obj is FunctionTypeScope, | |
| 8142 FunctionTypeScope, | |
| 8143 scope); | |
| 8144 } | |
| 8145 | |
| 8146 void test_scopeFor_MethodDeclaration() { | |
| 8147 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8148 Scope scope = | |
| 8149 ScopeBuilder.scopeFor(_createResolvedMethodDeclaration(), listener); | |
| 8150 EngineTestCase.assertInstanceOf( | |
| 8151 (obj) => obj is ClassScope, | |
| 8152 ClassScope, | |
| 8153 scope); | |
| 8154 } | |
| 8155 | |
| 8156 void test_scopeFor_MethodDeclaration_body() { | |
| 8157 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8158 Scope scope = | |
| 8159 ScopeBuilder.scopeFor(_createResolvedMethodDeclaration().body, listener)
; | |
| 8160 EngineTestCase.assertInstanceOf( | |
| 8161 (obj) => obj is FunctionScope, | |
| 8162 FunctionScope, | |
| 8163 scope); | |
| 8164 } | |
| 8165 | |
| 8166 void test_scopeFor_notInCompilationUnit() { | |
| 8167 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8168 try { | |
| 8169 ScopeBuilder.scopeFor(AstFactory.identifier3("x"), listener); | |
| 8170 fail("Expected AnalysisException"); | |
| 8171 } on AnalysisException catch (exception) { | |
| 8172 // Expected | |
| 8173 } | |
| 8174 } | |
| 8175 | |
| 8176 void test_scopeFor_null() { | |
| 8177 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8178 try { | |
| 8179 ScopeBuilder.scopeFor(null, listener); | |
| 8180 fail("Expected AnalysisException"); | |
| 8181 } on AnalysisException catch (exception) { | |
| 8182 // Expected | |
| 8183 } | |
| 8184 } | |
| 8185 | |
| 8186 void test_scopeFor_unresolved() { | |
| 8187 GatheringErrorListener listener = new GatheringErrorListener(); | |
| 8188 try { | |
| 8189 ScopeBuilder.scopeFor(AstFactory.compilationUnit(), listener); | |
| 8190 fail("Expected AnalysisException"); | |
| 8191 } on AnalysisException catch (exception) { | |
| 8192 // Expected | |
| 8193 } | |
| 8194 } | |
| 8195 | |
| 8196 ClassDeclaration _createResolvedClassDeclaration() { | |
| 8197 CompilationUnit unit = _createResolvedCompilationUnit(); | |
| 8198 String className = "C"; | |
| 8199 ClassDeclaration classNode = AstFactory.classDeclaration( | |
| 8200 null, | |
| 8201 className, | |
| 8202 AstFactory.typeParameterList(), | |
| 8203 null, | |
| 8204 null, | |
| 8205 null); | |
| 8206 unit.declarations.add(classNode); | |
| 8207 ClassElement classElement = ElementFactory.classElement2(className); | |
| 8208 classNode.name.staticElement = classElement; | |
| 8209 (unit.element as CompilationUnitElementImpl).types = | |
| 8210 <ClassElement>[classElement]; | |
| 8211 return classNode; | |
| 8212 } | |
| 8213 | |
| 8214 ClassTypeAlias _createResolvedClassTypeAlias() { | |
| 8215 CompilationUnit unit = _createResolvedCompilationUnit(); | |
| 8216 String className = "C"; | |
| 8217 ClassTypeAlias classNode = AstFactory.classTypeAlias( | |
| 8218 className, | |
| 8219 AstFactory.typeParameterList(), | |
| 8220 null, | |
| 8221 null, | |
| 8222 null, | |
| 8223 null); | |
| 8224 unit.declarations.add(classNode); | |
| 8225 ClassElement classElement = ElementFactory.classElement2(className); | |
| 8226 classNode.name.staticElement = classElement; | |
| 8227 (unit.element as CompilationUnitElementImpl).types = | |
| 8228 <ClassElement>[classElement]; | |
| 8229 return classNode; | |
| 8230 } | |
| 8231 | |
| 8232 CompilationUnit _createResolvedCompilationUnit() { | |
| 8233 CompilationUnit unit = AstFactory.compilationUnit(); | |
| 8234 LibraryElementImpl library = | |
| 8235 ElementFactory.library(AnalysisContextFactory.contextWithCore(), "lib"); | |
| 8236 unit.element = library.definingCompilationUnit; | |
| 8237 return unit; | |
| 8238 } | |
| 8239 | |
| 8240 ConstructorDeclaration _createResolvedConstructorDeclaration() { | |
| 8241 ClassDeclaration classNode = _createResolvedClassDeclaration(); | |
| 8242 String constructorName = "f"; | |
| 8243 ConstructorDeclaration constructorNode = AstFactory.constructorDeclaration( | |
| 8244 AstFactory.identifier3(constructorName), | |
| 8245 null, | |
| 8246 AstFactory.formalParameterList(), | |
| 8247 null); | |
| 8248 classNode.members.add(constructorNode); | |
| 8249 ConstructorElement constructorElement = | |
| 8250 ElementFactory.constructorElement2(classNode.element, null); | |
| 8251 constructorNode.element = constructorElement; | |
| 8252 (classNode.element as ClassElementImpl).constructors = | |
| 8253 <ConstructorElement>[constructorElement]; | |
| 8254 return constructorNode; | |
| 8255 } | |
| 8256 | |
| 8257 FunctionDeclaration _createResolvedFunctionDeclaration() { | |
| 8258 CompilationUnit unit = _createResolvedCompilationUnit(); | |
| 8259 String functionName = "f"; | |
| 8260 FunctionDeclaration functionNode = AstFactory.functionDeclaration( | |
| 8261 null, | |
| 8262 null, | |
| 8263 functionName, | |
| 8264 AstFactory.functionExpression()); | |
| 8265 unit.declarations.add(functionNode); | |
| 8266 FunctionElement functionElement = | |
| 8267 ElementFactory.functionElement(functionName); | |
| 8268 functionNode.name.staticElement = functionElement; | |
| 8269 (unit.element as CompilationUnitElementImpl).functions = | |
| 8270 <FunctionElement>[functionElement]; | |
| 8271 return functionNode; | |
| 8272 } | |
| 8273 | |
| 8274 FunctionTypeAlias _createResolvedFunctionTypeAlias() { | |
| 8275 CompilationUnit unit = _createResolvedCompilationUnit(); | |
| 8276 FunctionTypeAlias aliasNode = AstFactory.typeAlias( | |
| 8277 AstFactory.typeName4("A"), | |
| 8278 "F", | |
| 8279 AstFactory.typeParameterList(), | |
| 8280 AstFactory.formalParameterList()); | |
| 8281 unit.declarations.add(aliasNode); | |
| 8282 SimpleIdentifier aliasName = aliasNode.name; | |
| 8283 FunctionTypeAliasElement aliasElement = | |
| 8284 new FunctionTypeAliasElementImpl.forNode(aliasName); | |
| 8285 aliasName.staticElement = aliasElement; | |
| 8286 (unit.element as CompilationUnitElementImpl).typeAliases = | |
| 8287 <FunctionTypeAliasElement>[aliasElement]; | |
| 8288 return aliasNode; | |
| 8289 } | |
| 8290 | |
| 8291 MethodDeclaration _createResolvedMethodDeclaration() { | |
| 8292 ClassDeclaration classNode = _createResolvedClassDeclaration(); | |
| 8293 String methodName = "f"; | |
| 8294 MethodDeclaration methodNode = AstFactory.methodDeclaration( | |
| 8295 null, | |
| 8296 null, | |
| 8297 null, | |
| 8298 null, | |
| 8299 AstFactory.identifier3(methodName), | |
| 8300 AstFactory.formalParameterList()); | |
| 8301 classNode.members.add(methodNode); | |
| 8302 MethodElement methodElement = | |
| 8303 ElementFactory.methodElement(methodName, null); | |
| 8304 methodNode.name.staticElement = methodElement; | |
| 8305 (classNode.element as ClassElementImpl).methods = | |
| 8306 <MethodElement>[methodElement]; | |
| 8307 return methodNode; | |
| 8308 } | |
| 8309 } | |
| 8310 | |
| 8311 class ScopeTest extends ResolverTestCase { | 7892 class ScopeTest extends ResolverTestCase { |
| 8312 void test_define_duplicate() { | 7893 void test_define_duplicate() { |
| 8313 GatheringErrorListener errorListener = new GatheringErrorListener(); | 7894 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 8314 ScopeTest_TestScope scope = new ScopeTest_TestScope(errorListener); | 7895 ScopeTest_TestScope scope = new ScopeTest_TestScope(errorListener); |
| 8315 VariableElement element1 = | 7896 VariableElement element1 = |
| 8316 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); | 7897 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); |
| 8317 VariableElement element2 = | 7898 VariableElement element2 = |
| 8318 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); | 7899 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); |
| 8319 scope.define(element1); | 7900 scope.define(element1); |
| 8320 scope.define(element2); | 7901 scope.define(element2); |
| (...skipping 5523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13844 // check propagated type | 13425 // check propagated type |
| 13845 FunctionType propagatedType = node.propagatedType as FunctionType; | 13426 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 13846 expect(propagatedType.returnType, test.typeProvider.stringType); | 13427 expect(propagatedType.returnType, test.typeProvider.stringType); |
| 13847 } on AnalysisException catch (e, stackTrace) { | 13428 } on AnalysisException catch (e, stackTrace) { |
| 13848 thrownException[0] = new CaughtException(e, stackTrace); | 13429 thrownException[0] = new CaughtException(e, stackTrace); |
| 13849 } | 13430 } |
| 13850 } | 13431 } |
| 13851 return null; | 13432 return null; |
| 13852 } | 13433 } |
| 13853 } | 13434 } |
| OLD | NEW |