| 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 import 'package:analyzer/src/generated/java_core.dart'; | 8 import 'package:analyzer/src/generated/java_core.dart'; |
| 9 import 'package:analyzer/src/generated/java_junit.dart'; | |
| 10 import 'package:analyzer/src/generated/java_engine.dart'; | 9 import 'package:analyzer/src/generated/java_engine.dart'; |
| 11 import 'package:analyzer/src/generated/java_engine_io.dart'; | 10 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 12 import 'package:analyzer/src/generated/source_io.dart'; | 11 import 'package:analyzer/src/generated/source_io.dart'; |
| 13 import 'package:analyzer/src/generated/error.dart'; | 12 import 'package:analyzer/src/generated/error.dart'; |
| 14 import 'package:analyzer/src/generated/scanner.dart'; | 13 import 'package:analyzer/src/generated/scanner.dart'; |
| 15 import 'package:analyzer/src/generated/ast.dart'; | 14 import 'package:analyzer/src/generated/ast.dart'; |
| 16 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; | 15 import 'package:analyzer/src/generated/parser.dart' show ParserErrorCode; |
| 17 import 'package:analyzer/src/generated/element.dart'; | 16 import 'package:analyzer/src/generated/element.dart'; |
| 18 import 'package:analyzer/src/generated/resolver.dart'; | 17 import 'package:analyzer/src/generated/resolver.dart'; |
| 19 import 'package:analyzer/src/generated/engine.dart'; | 18 import 'package:analyzer/src/generated/engine.dart'; |
| 20 import 'package:analyzer/src/generated/utilities_dart.dart'; | 19 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 21 import 'package:analyzer/src/generated/sdk.dart'; | 20 import 'package:analyzer/src/generated/sdk.dart'; |
| 22 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; | 21 import 'package:analyzer/src/generated/sdk_io.dart' show DirectoryBasedDartSdk; |
| 23 import 'package:unittest/unittest.dart' as _ut; | 22 import 'package:unittest/unittest.dart'; |
| 24 import 'test_support.dart'; | 23 import 'test_support.dart'; |
| 25 import 'package:analyzer/src/generated/testing/ast_factory.dart'; | 24 import 'package:analyzer/src/generated/testing/ast_factory.dart'; |
| 26 import 'package:analyzer/src/generated/testing/element_factory.dart'; | 25 import 'package:analyzer/src/generated/testing/element_factory.dart'; |
| 27 import 'package:analyzer/src/generated/java_io.dart'; | 26 import 'package:analyzer/src/generated/java_io.dart'; |
| 28 import '../reflective_tests.dart'; | 27 import '../reflective_tests.dart'; |
| 29 | 28 |
| 30 | 29 |
| 31 /** | 30 /** |
| 32 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts | 31 * The class `AnalysisContextFactory` defines utility methods used to create ana
lysis contexts |
| 33 * for testing purposes. | 32 * for testing purposes. |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 return sourceFactory.dartSdk.context.getModificationStamp(source); | 259 return sourceFactory.dartSdk.context.getModificationStamp(source); |
| 261 } | 260 } |
| 262 return super.getModificationStamp(source); | 261 return super.getModificationStamp(source); |
| 263 } | 262 } |
| 264 | 263 |
| 265 @override | 264 @override |
| 266 void set analysisOptions(AnalysisOptions options) { | 265 void set analysisOptions(AnalysisOptions options) { |
| 267 AnalysisOptions currentOptions = analysisOptions; | 266 AnalysisOptions currentOptions = analysisOptions; |
| 268 bool needsRecompute = currentOptions.analyzeFunctionBodies != options.analyz
eFunctionBodies || currentOptions.generateSdkErrors != options.generateSdkErrors
|| currentOptions.enableAsync != options.enableAsync || currentOptions.enableDe
ferredLoading != options.enableDeferredLoading || currentOptions.enableEnum != o
ptions.enableEnum || currentOptions.dart2jsHint != options.dart2jsHint || (curre
ntOptions.hint && !options.hint) || currentOptions.preserveComments != options.p
reserveComments; | 267 bool needsRecompute = currentOptions.analyzeFunctionBodies != options.analyz
eFunctionBodies || currentOptions.generateSdkErrors != options.generateSdkErrors
|| currentOptions.enableAsync != options.enableAsync || currentOptions.enableDe
ferredLoading != options.enableDeferredLoading || currentOptions.enableEnum != o
ptions.enableEnum || currentOptions.dart2jsHint != options.dart2jsHint || (curre
ntOptions.hint && !options.hint) || currentOptions.preserveComments != options.p
reserveComments; |
| 269 if (needsRecompute) { | 268 if (needsRecompute) { |
| 270 JUnitTestCase.fail("Cannot set options that cause the sources to be reanal
yzed in a test context"); | 269 fail("Cannot set options that cause the sources to be reanalyzed in a test
context"); |
| 271 } | 270 } |
| 272 super.analysisOptions = options; | 271 super.analysisOptions = options; |
| 273 } | 272 } |
| 274 | 273 |
| 275 /** | 274 /** |
| 276 * Set the analysis options, even if they would force re-analysis. This method
should only be | 275 * Set the analysis options, even if they would force re-analysis. This method
should only be |
| 277 * invoked before the fake SDK is initialized. | 276 * invoked before the fake SDK is initialized. |
| 278 * | 277 * |
| 279 * @param options the analysis options to be set | 278 * @param options the analysis options to be set |
| 280 */ | 279 */ |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 delta.setAnalysisLevel(source1, AnalysisLevel.ALL); | 334 delta.setAnalysisLevel(source1, AnalysisLevel.ALL); |
| 336 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS); | 335 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS); |
| 337 delta.setAnalysisLevel(source3, AnalysisLevel.NONE); | 336 delta.setAnalysisLevel(source3, AnalysisLevel.NONE); |
| 338 List<Source> addedSources = delta.addedSources; | 337 List<Source> addedSources = delta.addedSources; |
| 339 EngineTestCase.assertLength(2, addedSources); | 338 EngineTestCase.assertLength(2, addedSources); |
| 340 EngineTestCase.assertContains(addedSources, [source1, source2]); | 339 EngineTestCase.assertContains(addedSources, [source1, source2]); |
| 341 } | 340 } |
| 342 | 341 |
| 343 void test_getAnalysisLevels() { | 342 void test_getAnalysisLevels() { |
| 344 AnalysisDelta delta = new AnalysisDelta(); | 343 AnalysisDelta delta = new AnalysisDelta(); |
| 345 JUnitTestCase.assertEquals(0, delta.analysisLevels.length); | 344 expect(delta.analysisLevels.length, 0); |
| 346 } | 345 } |
| 347 | 346 |
| 348 void test_setAnalysisLevel() { | 347 void test_setAnalysisLevel() { |
| 349 AnalysisDelta delta = new AnalysisDelta(); | 348 AnalysisDelta delta = new AnalysisDelta(); |
| 350 delta.setAnalysisLevel(source1, AnalysisLevel.ALL); | 349 delta.setAnalysisLevel(source1, AnalysisLevel.ALL); |
| 351 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS); | 350 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS); |
| 352 Map<Source, AnalysisLevel> levels = delta.analysisLevels; | 351 Map<Source, AnalysisLevel> levels = delta.analysisLevels; |
| 353 JUnitTestCase.assertEquals(2, levels.length); | 352 expect(levels.length, 2); |
| 354 JUnitTestCase.assertEquals(AnalysisLevel.ALL, levels[source1]); | 353 expect(levels[source1], AnalysisLevel.ALL); |
| 355 JUnitTestCase.assertEquals(AnalysisLevel.ERRORS, levels[source2]); | 354 expect(levels[source2], AnalysisLevel.ERRORS); |
| 356 } | 355 } |
| 357 | 356 |
| 358 void test_toString() { | 357 void test_toString() { |
| 359 AnalysisDelta delta = new AnalysisDelta(); | 358 AnalysisDelta delta = new AnalysisDelta(); |
| 360 delta.setAnalysisLevel(new TestSource(), AnalysisLevel.ALL); | 359 delta.setAnalysisLevel(new TestSource(), AnalysisLevel.ALL); |
| 361 String result = delta.toString(); | 360 String result = delta.toString(); |
| 362 JUnitTestCase.assertNotNull(result); | 361 expect(result, isNotNull); |
| 363 JUnitTestCase.assertTrue(result.length > 0); | 362 expect(result.length > 0, isTrue); |
| 364 } | 363 } |
| 365 } | 364 } |
| 366 | 365 |
| 367 class ChangeSetTest extends EngineTestCase { | 366 class ChangeSetTest extends EngineTestCase { |
| 368 void test_changedContent() { | 367 void test_changedContent() { |
| 369 TestSource source = new TestSource(); | 368 TestSource source = new TestSource(); |
| 370 String content = ""; | 369 String content = ""; |
| 371 ChangeSet changeSet = new ChangeSet(); | 370 ChangeSet changeSet = new ChangeSet(); |
| 372 changeSet.changedContent(source, content); | 371 changeSet.changedContent(source, content); |
| 373 EngineTestCase.assertSizeOfList(0, changeSet.addedSources); | 372 EngineTestCase.assertSizeOfList(0, changeSet.addedSources); |
| 374 EngineTestCase.assertSizeOfList(0, changeSet.changedSources); | 373 EngineTestCase.assertSizeOfList(0, changeSet.changedSources); |
| 375 Map<Source, String> map = changeSet.changedContents; | 374 Map<Source, String> map = changeSet.changedContents; |
| 376 EngineTestCase.assertSizeOfMap(1, map); | 375 EngineTestCase.assertSizeOfMap(1, map); |
| 377 JUnitTestCase.assertSame(content, map[source]); | 376 expect(map[source], same(content)); |
| 378 EngineTestCase.assertSizeOfMap(0, changeSet.changedRanges); | 377 EngineTestCase.assertSizeOfMap(0, changeSet.changedRanges); |
| 379 EngineTestCase.assertSizeOfList(0, changeSet.deletedSources); | 378 EngineTestCase.assertSizeOfList(0, changeSet.deletedSources); |
| 380 EngineTestCase.assertSizeOfList(0, changeSet.removedSources); | 379 EngineTestCase.assertSizeOfList(0, changeSet.removedSources); |
| 381 EngineTestCase.assertSizeOfList(0, changeSet.removedContainers); | 380 EngineTestCase.assertSizeOfList(0, changeSet.removedContainers); |
| 382 } | 381 } |
| 383 | 382 |
| 384 void test_changedRange() { | 383 void test_changedRange() { |
| 385 TestSource source = new TestSource(); | 384 TestSource source = new TestSource(); |
| 386 String content = ""; | 385 String content = ""; |
| 387 ChangeSet changeSet = new ChangeSet(); | 386 ChangeSet changeSet = new ChangeSet(); |
| 388 changeSet.changedRange(source, content, 1, 2, 3); | 387 changeSet.changedRange(source, content, 1, 2, 3); |
| 389 EngineTestCase.assertSizeOfList(0, changeSet.addedSources); | 388 EngineTestCase.assertSizeOfList(0, changeSet.addedSources); |
| 390 EngineTestCase.assertSizeOfList(0, changeSet.changedSources); | 389 EngineTestCase.assertSizeOfList(0, changeSet.changedSources); |
| 391 EngineTestCase.assertSizeOfMap(0, changeSet.changedContents); | 390 EngineTestCase.assertSizeOfMap(0, changeSet.changedContents); |
| 392 Map<Source, ChangeSet_ContentChange> map = changeSet.changedRanges; | 391 Map<Source, ChangeSet_ContentChange> map = changeSet.changedRanges; |
| 393 EngineTestCase.assertSizeOfMap(1, map); | 392 EngineTestCase.assertSizeOfMap(1, map); |
| 394 ChangeSet_ContentChange change = map[source]; | 393 ChangeSet_ContentChange change = map[source]; |
| 395 JUnitTestCase.assertNotNull(change); | 394 expect(change, isNotNull); |
| 396 JUnitTestCase.assertEquals(content, change.contents); | 395 expect(change.contents, content); |
| 397 JUnitTestCase.assertEquals(1, change.offset); | 396 expect(change.offset, 1); |
| 398 JUnitTestCase.assertEquals(2, change.oldLength); | 397 expect(change.oldLength, 2); |
| 399 JUnitTestCase.assertEquals(3, change.newLength); | 398 expect(change.newLength, 3); |
| 400 EngineTestCase.assertSizeOfList(0, changeSet.deletedSources); | 399 EngineTestCase.assertSizeOfList(0, changeSet.deletedSources); |
| 401 EngineTestCase.assertSizeOfList(0, changeSet.removedSources); | 400 EngineTestCase.assertSizeOfList(0, changeSet.removedSources); |
| 402 EngineTestCase.assertSizeOfList(0, changeSet.removedContainers); | 401 EngineTestCase.assertSizeOfList(0, changeSet.removedContainers); |
| 403 } | 402 } |
| 404 | 403 |
| 405 void test_toString() { | 404 void test_toString() { |
| 406 ChangeSet changeSet = new ChangeSet(); | 405 ChangeSet changeSet = new ChangeSet(); |
| 407 changeSet.addedSource(new TestSource()); | 406 changeSet.addedSource(new TestSource()); |
| 408 changeSet.changedSource(new TestSource()); | 407 changeSet.changedSource(new TestSource()); |
| 409 changeSet.changedContent(new TestSource(), ""); | 408 changeSet.changedContent(new TestSource(), ""); |
| 410 changeSet.changedRange(new TestSource(), "", 0, 0, 0); | 409 changeSet.changedRange(new TestSource(), "", 0, 0, 0); |
| 411 changeSet.deletedSource(new TestSource()); | 410 changeSet.deletedSource(new TestSource()); |
| 412 changeSet.removedSource(new TestSource()); | 411 changeSet.removedSource(new TestSource()); |
| 413 changeSet.removedContainer(new SourceContainer_ChangeSetTest_test_toString()
); | 412 changeSet.removedContainer(new SourceContainer_ChangeSetTest_test_toString()
); |
| 414 JUnitTestCase.assertNotNull(changeSet.toString()); | 413 expect(changeSet.toString(), isNotNull); |
| 415 } | 414 } |
| 416 } | 415 } |
| 417 | 416 |
| 418 class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase { | 417 class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase { |
| 419 void test_fieldFormalParameterAssignableToField_extends() { | 418 void test_fieldFormalParameterAssignableToField_extends() { |
| 420 // According to checked-mode type checking rules, a value of type B is | 419 // According to checked-mode type checking rules, a value of type B is |
| 421 // assignable to a field of type A, because B extends A (and hence is a | 420 // assignable to a field of type A, because B extends A (and hence is a |
| 422 // subtype of A). | 421 // subtype of A). |
| 423 Source source = addSource(r''' | 422 Source source = addSource(r''' |
| 424 class A { | 423 class A { |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 } | 1060 } |
| 1062 | 1061 |
| 1063 void _assertCompilationUnitMatches(bool expectMatch, String oldContent, String
newContent) { | 1062 void _assertCompilationUnitMatches(bool expectMatch, String oldContent, String
newContent) { |
| 1064 Source source = addSource(oldContent); | 1063 Source source = addSource(oldContent); |
| 1065 LibraryElement library = resolve(source); | 1064 LibraryElement library = resolve(source); |
| 1066 CompilationUnit oldUnit = resolveCompilationUnit(source, library); | 1065 CompilationUnit oldUnit = resolveCompilationUnit(source, library); |
| 1067 AnalysisContext context = analysisContext; | 1066 AnalysisContext context = analysisContext; |
| 1068 context.setContents(source, newContent); | 1067 context.setContents(source, newContent); |
| 1069 CompilationUnit newUnit = context.parseCompilationUnit(source); | 1068 CompilationUnit newUnit = context.parseCompilationUnit(source); |
| 1070 DeclarationMatcher matcher = new DeclarationMatcher(); | 1069 DeclarationMatcher matcher = new DeclarationMatcher(); |
| 1071 JUnitTestCase.assertEquals(expectMatch, matcher.matches(newUnit, oldUnit.ele
ment)); | 1070 expect(matcher.matches(newUnit, oldUnit.element), expectMatch); |
| 1072 } | 1071 } |
| 1073 | 1072 |
| 1074 void _assertMethodMatches(bool expectMatch, String oldContent, String newConte
nt) { | 1073 void _assertMethodMatches(bool expectMatch, String oldContent, String newConte
nt) { |
| 1075 Source source = addSource(oldContent); | 1074 Source source = addSource(oldContent); |
| 1076 LibraryElement library = resolve(source); | 1075 LibraryElement library = resolve(source); |
| 1077 CompilationUnit oldUnit = resolveCompilationUnit(source, library); | 1076 CompilationUnit oldUnit = resolveCompilationUnit(source, library); |
| 1078 MethodElement element = _getFirstMethod(oldUnit).element as MethodElement; | 1077 MethodElement element = _getFirstMethod(oldUnit).element as MethodElement; |
| 1079 AnalysisContext context = analysisContext; | 1078 AnalysisContext context = analysisContext; |
| 1080 context.setContents(source, newContent); | 1079 context.setContents(source, newContent); |
| 1081 CompilationUnit newUnit = context.parseCompilationUnit(source); | 1080 CompilationUnit newUnit = context.parseCompilationUnit(source); |
| 1082 MethodDeclaration newMethod = _getFirstMethod(newUnit); | 1081 MethodDeclaration newMethod = _getFirstMethod(newUnit); |
| 1083 DeclarationMatcher matcher = new DeclarationMatcher(); | 1082 DeclarationMatcher matcher = new DeclarationMatcher(); |
| 1084 JUnitTestCase.assertEquals(expectMatch, matcher.matches(newMethod, element))
; | 1083 expect(matcher.matches(newMethod, element), expectMatch); |
| 1085 } | 1084 } |
| 1086 | 1085 |
| 1087 MethodDeclaration _getFirstMethod(CompilationUnit unit) { | 1086 MethodDeclaration _getFirstMethod(CompilationUnit unit) { |
| 1088 ClassDeclaration classNode = unit.declarations[0] as ClassDeclaration; | 1087 ClassDeclaration classNode = unit.declarations[0] as ClassDeclaration; |
| 1089 return classNode.members[0] as MethodDeclaration; | 1088 return classNode.members[0] as MethodDeclaration; |
| 1090 } | 1089 } |
| 1091 } | 1090 } |
| 1092 | 1091 |
| 1093 class DirectoryBasedDartSdk_AnalysisContextFactory_initContextWithCore extends D
irectoryBasedDartSdk { | 1092 class DirectoryBasedDartSdk_AnalysisContextFactory_initContextWithCore extends D
irectoryBasedDartSdk { |
| 1094 DirectoryBasedDartSdk_AnalysisContextFactory_initContextWithCore(JavaFile arg0
) : super(arg0); | 1093 DirectoryBasedDartSdk_AnalysisContextFactory_initContextWithCore(JavaFile arg0
) : super(arg0); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 * The resolver visitor that maintains the state for the resolver. | 1134 * The resolver visitor that maintains the state for the resolver. |
| 1136 */ | 1135 */ |
| 1137 ResolverVisitor _visitor; | 1136 ResolverVisitor _visitor; |
| 1138 | 1137 |
| 1139 /** | 1138 /** |
| 1140 * The resolver being used to resolve the test cases. | 1139 * The resolver being used to resolve the test cases. |
| 1141 */ | 1140 */ |
| 1142 ElementResolver _resolver; | 1141 ElementResolver _resolver; |
| 1143 | 1142 |
| 1144 void fail_visitExportDirective_combinators() { | 1143 void fail_visitExportDirective_combinators() { |
| 1145 JUnitTestCase.fail("Not yet tested"); | 1144 fail("Not yet tested"); |
| 1146 // Need to set up the exported library so that the identifier can be resolve
d | 1145 // Need to set up the exported library so that the identifier can be resolve
d |
| 1147 ExportDirective directive = AstFactory.exportDirective2(null, [AstFactory.hi
deCombinator2(["A"])]); | 1146 ExportDirective directive = AstFactory.exportDirective2(null, [AstFactory.hi
deCombinator2(["A"])]); |
| 1148 _resolveNode(directive, []); | 1147 _resolveNode(directive, []); |
| 1149 _listener.assertNoErrors(); | 1148 _listener.assertNoErrors(); |
| 1150 } | 1149 } |
| 1151 | 1150 |
| 1152 void fail_visitFunctionExpressionInvocation() { | 1151 void fail_visitFunctionExpressionInvocation() { |
| 1153 JUnitTestCase.fail("Not yet tested"); | 1152 fail("Not yet tested"); |
| 1154 _listener.assertNoErrors(); | 1153 _listener.assertNoErrors(); |
| 1155 } | 1154 } |
| 1156 | 1155 |
| 1157 void fail_visitImportDirective_combinators_noPrefix() { | 1156 void fail_visitImportDirective_combinators_noPrefix() { |
| 1158 JUnitTestCase.fail("Not yet tested"); | 1157 fail("Not yet tested"); |
| 1159 // Need to set up the imported library so that the identifier can be resolve
d | 1158 // Need to set up the imported library so that the identifier can be resolve
d |
| 1160 ImportDirective directive = AstFactory.importDirective3(null, null, [AstFact
ory.showCombinator2(["A"])]); | 1159 ImportDirective directive = AstFactory.importDirective3(null, null, [AstFact
ory.showCombinator2(["A"])]); |
| 1161 _resolveNode(directive, []); | 1160 _resolveNode(directive, []); |
| 1162 _listener.assertNoErrors(); | 1161 _listener.assertNoErrors(); |
| 1163 } | 1162 } |
| 1164 | 1163 |
| 1165 void fail_visitImportDirective_combinators_prefix() { | 1164 void fail_visitImportDirective_combinators_prefix() { |
| 1166 JUnitTestCase.fail("Not yet tested"); | 1165 fail("Not yet tested"); |
| 1167 // Need to set up the imported library so that the identifiers can be resolv
ed | 1166 // Need to set up the imported library so that the identifiers can be resolv
ed |
| 1168 String prefixName = "p"; | 1167 String prefixName = "p"; |
| 1169 _definingLibrary.imports = <ImportElement> [ElementFactory.importFor(null, E
lementFactory.prefix(prefixName), [])]; | 1168 _definingLibrary.imports = <ImportElement> [ElementFactory.importFor(null, E
lementFactory.prefix(prefixName), [])]; |
| 1170 ImportDirective directive = AstFactory.importDirective3(null, prefixName, [ | 1169 ImportDirective directive = AstFactory.importDirective3(null, prefixName, [ |
| 1171 AstFactory.showCombinator2(["A"]), | 1170 AstFactory.showCombinator2(["A"]), |
| 1172 AstFactory.hideCombinator2(["B"])]); | 1171 AstFactory.hideCombinator2(["B"])]); |
| 1173 _resolveNode(directive, []); | 1172 _resolveNode(directive, []); |
| 1174 _listener.assertNoErrors(); | 1173 _listener.assertNoErrors(); |
| 1175 } | 1174 } |
| 1176 | 1175 |
| 1177 void fail_visitRedirectingConstructorInvocation() { | 1176 void fail_visitRedirectingConstructorInvocation() { |
| 1178 JUnitTestCase.fail("Not yet tested"); | 1177 fail("Not yet tested"); |
| 1179 _listener.assertNoErrors(); | 1178 _listener.assertNoErrors(); |
| 1180 } | 1179 } |
| 1181 | 1180 |
| 1182 @override | 1181 @override |
| 1183 void setUp() { | 1182 void setUp() { |
| 1184 _listener = new GatheringErrorListener(); | 1183 _listener = new GatheringErrorListener(); |
| 1185 _typeProvider = new TestTypeProvider(); | 1184 _typeProvider = new TestTypeProvider(); |
| 1186 _resolver = _createResolver(); | 1185 _resolver = _createResolver(); |
| 1187 } | 1186 } |
| 1188 | 1187 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1208 // class D extends C {} | 1207 // class D extends C {} |
| 1209 // | 1208 // |
| 1210 ClassElementImpl classD = ElementFactory.classElement("D", classC.type, []); | 1209 ClassElementImpl classD = ElementFactory.classElement("D", classC.type, []); |
| 1211 // | 1210 // |
| 1212 // D a; | 1211 // D a; |
| 1213 // a[i]; | 1212 // a[i]; |
| 1214 // | 1213 // |
| 1215 SimpleIdentifier array = AstFactory.identifier3("a"); | 1214 SimpleIdentifier array = AstFactory.identifier3("a"); |
| 1216 array.staticType = classD.type; | 1215 array.staticType = classD.type; |
| 1217 IndexExpression expression = AstFactory.indexExpression(array, AstFactory.id
entifier3("i")); | 1216 IndexExpression expression = AstFactory.indexExpression(array, AstFactory.id
entifier3("i")); |
| 1218 JUnitTestCase.assertSame(operator, _resolveIndexExpression(expression, [])); | 1217 expect(_resolveIndexExpression(expression, []), same(operator)); |
| 1219 _listener.assertNoErrors(); | 1218 _listener.assertNoErrors(); |
| 1220 } | 1219 } |
| 1221 | 1220 |
| 1222 void test_visitAssignmentExpression_compound() { | 1221 void test_visitAssignmentExpression_compound() { |
| 1223 InterfaceType intType = _typeProvider.intType; | 1222 InterfaceType intType = _typeProvider.intType; |
| 1224 SimpleIdentifier leftHandSide = AstFactory.identifier3("a"); | 1223 SimpleIdentifier leftHandSide = AstFactory.identifier3("a"); |
| 1225 leftHandSide.staticType = intType; | 1224 leftHandSide.staticType = intType; |
| 1226 AssignmentExpression assignment = AstFactory.assignmentExpression(leftHandSi
de, TokenType.PLUS_EQ, AstFactory.integer(1)); | 1225 AssignmentExpression assignment = AstFactory.assignmentExpression(leftHandSi
de, TokenType.PLUS_EQ, AstFactory.integer(1)); |
| 1227 _resolveNode(assignment, []); | 1226 _resolveNode(assignment, []); |
| 1228 JUnitTestCase.assertSame(getMethod(_typeProvider.numType, "+"), assignment.s
taticElement); | 1227 expect(assignment.staticElement, same(getMethod(_typeProvider.numType, "+"))
); |
| 1229 _listener.assertNoErrors(); | 1228 _listener.assertNoErrors(); |
| 1230 } | 1229 } |
| 1231 | 1230 |
| 1232 void test_visitAssignmentExpression_simple() { | 1231 void test_visitAssignmentExpression_simple() { |
| 1233 AssignmentExpression expression = AstFactory.assignmentExpression(AstFactory
.identifier3("x"), TokenType.EQ, AstFactory.integer(0)); | 1232 AssignmentExpression expression = AstFactory.assignmentExpression(AstFactory
.identifier3("x"), TokenType.EQ, AstFactory.integer(0)); |
| 1234 _resolveNode(expression, []); | 1233 _resolveNode(expression, []); |
| 1235 JUnitTestCase.assertNull(expression.staticElement); | 1234 expect(expression.staticElement, isNull); |
| 1236 _listener.assertNoErrors(); | 1235 _listener.assertNoErrors(); |
| 1237 } | 1236 } |
| 1238 | 1237 |
| 1239 void test_visitBinaryExpression() { | 1238 void test_visitBinaryExpression() { |
| 1240 // num i; | 1239 // num i; |
| 1241 // var j; | 1240 // var j; |
| 1242 // i + j | 1241 // i + j |
| 1243 InterfaceType numType = _typeProvider.numType; | 1242 InterfaceType numType = _typeProvider.numType; |
| 1244 SimpleIdentifier left = AstFactory.identifier3("i"); | 1243 SimpleIdentifier left = AstFactory.identifier3("i"); |
| 1245 left.staticType = numType; | 1244 left.staticType = numType; |
| 1246 BinaryExpression expression = AstFactory.binaryExpression(left, TokenType.PL
US, AstFactory.identifier3("j")); | 1245 BinaryExpression expression = AstFactory.binaryExpression(left, TokenType.PL
US, AstFactory.identifier3("j")); |
| 1247 _resolveNode(expression, []); | 1246 _resolveNode(expression, []); |
| 1248 JUnitTestCase.assertEquals(getMethod(numType, "+"), expression.staticElement
); | 1247 expect(expression.staticElement, getMethod(numType, "+")); |
| 1249 JUnitTestCase.assertNull(expression.propagatedElement); | 1248 expect(expression.propagatedElement, isNull); |
| 1250 _listener.assertNoErrors(); | 1249 _listener.assertNoErrors(); |
| 1251 } | 1250 } |
| 1252 | 1251 |
| 1253 void test_visitBinaryExpression_propagatedElement() { | 1252 void test_visitBinaryExpression_propagatedElement() { |
| 1254 // var i = 1; | 1253 // var i = 1; |
| 1255 // var j; | 1254 // var j; |
| 1256 // i + j | 1255 // i + j |
| 1257 InterfaceType numType = _typeProvider.numType; | 1256 InterfaceType numType = _typeProvider.numType; |
| 1258 SimpleIdentifier left = AstFactory.identifier3("i"); | 1257 SimpleIdentifier left = AstFactory.identifier3("i"); |
| 1259 left.propagatedType = numType; | 1258 left.propagatedType = numType; |
| 1260 BinaryExpression expression = AstFactory.binaryExpression(left, TokenType.PL
US, AstFactory.identifier3("j")); | 1259 BinaryExpression expression = AstFactory.binaryExpression(left, TokenType.PL
US, AstFactory.identifier3("j")); |
| 1261 _resolveNode(expression, []); | 1260 _resolveNode(expression, []); |
| 1262 JUnitTestCase.assertNull(expression.staticElement); | 1261 expect(expression.staticElement, isNull); |
| 1263 JUnitTestCase.assertEquals(getMethod(numType, "+"), expression.propagatedEle
ment); | 1262 expect(expression.propagatedElement, getMethod(numType, "+")); |
| 1264 _listener.assertNoErrors(); | 1263 _listener.assertNoErrors(); |
| 1265 } | 1264 } |
| 1266 | 1265 |
| 1267 void test_visitBreakStatement_withLabel() { | 1266 void test_visitBreakStatement_withLabel() { |
| 1268 String label = "loop"; | 1267 String label = "loop"; |
| 1269 LabelElementImpl labelElement = new LabelElementImpl(AstFactory.identifier3(
label), false, false); | 1268 LabelElementImpl labelElement = new LabelElementImpl(AstFactory.identifier3(
label), false, false); |
| 1270 BreakStatement statement = AstFactory.breakStatement2(label); | 1269 BreakStatement statement = AstFactory.breakStatement2(label); |
| 1271 JUnitTestCase.assertSame(labelElement, _resolveBreak(statement, labelElement
)); | 1270 expect(_resolveBreak(statement, labelElement), same(labelElement)); |
| 1272 _listener.assertNoErrors(); | 1271 _listener.assertNoErrors(); |
| 1273 } | 1272 } |
| 1274 | 1273 |
| 1275 void test_visitBreakStatement_withoutLabel() { | 1274 void test_visitBreakStatement_withoutLabel() { |
| 1276 BreakStatement statement = AstFactory.breakStatement(); | 1275 BreakStatement statement = AstFactory.breakStatement(); |
| 1277 _resolveStatement(statement, null); | 1276 _resolveStatement(statement, null); |
| 1278 _listener.assertNoErrors(); | 1277 _listener.assertNoErrors(); |
| 1279 } | 1278 } |
| 1280 | 1279 |
| 1281 void test_visitConstructorName_named() { | 1280 void test_visitConstructorName_named() { |
| 1282 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1281 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1283 String constructorName = "a"; | 1282 String constructorName = "a"; |
| 1284 ConstructorElement constructor = ElementFactory.constructorElement2(classA,
constructorName, []); | 1283 ConstructorElement constructor = ElementFactory.constructorElement2(classA,
constructorName, []); |
| 1285 classA.constructors = <ConstructorElement> [constructor]; | 1284 classA.constructors = <ConstructorElement> [constructor]; |
| 1286 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA
, []), constructorName); | 1285 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA
, []), constructorName); |
| 1287 _resolveNode(name, []); | 1286 _resolveNode(name, []); |
| 1288 JUnitTestCase.assertSame(constructor, name.staticElement); | 1287 expect(name.staticElement, same(constructor)); |
| 1289 _listener.assertNoErrors(); | 1288 _listener.assertNoErrors(); |
| 1290 } | 1289 } |
| 1291 | 1290 |
| 1292 void test_visitConstructorName_unnamed() { | 1291 void test_visitConstructorName_unnamed() { |
| 1293 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1292 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1294 String constructorName = null; | 1293 String constructorName = null; |
| 1295 ConstructorElement constructor = ElementFactory.constructorElement2(classA,
constructorName, []); | 1294 ConstructorElement constructor = ElementFactory.constructorElement2(classA,
constructorName, []); |
| 1296 classA.constructors = <ConstructorElement> [constructor]; | 1295 classA.constructors = <ConstructorElement> [constructor]; |
| 1297 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA
, []), constructorName); | 1296 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA
, []), constructorName); |
| 1298 _resolveNode(name, []); | 1297 _resolveNode(name, []); |
| 1299 JUnitTestCase.assertSame(constructor, name.staticElement); | 1298 expect(name.staticElement, same(constructor)); |
| 1300 _listener.assertNoErrors(); | 1299 _listener.assertNoErrors(); |
| 1301 } | 1300 } |
| 1302 | 1301 |
| 1303 void test_visitContinueStatement_withLabel() { | 1302 void test_visitContinueStatement_withLabel() { |
| 1304 String label = "loop"; | 1303 String label = "loop"; |
| 1305 LabelElementImpl labelElement = new LabelElementImpl(AstFactory.identifier3(
label), false, false); | 1304 LabelElementImpl labelElement = new LabelElementImpl(AstFactory.identifier3(
label), false, false); |
| 1306 ContinueStatement statement = AstFactory.continueStatement(label); | 1305 ContinueStatement statement = AstFactory.continueStatement(label); |
| 1307 JUnitTestCase.assertSame(labelElement, _resolveContinue(statement, labelElem
ent)); | 1306 expect(_resolveContinue(statement, labelElement), same(labelElement)); |
| 1308 _listener.assertNoErrors(); | 1307 _listener.assertNoErrors(); |
| 1309 } | 1308 } |
| 1310 | 1309 |
| 1311 void test_visitContinueStatement_withoutLabel() { | 1310 void test_visitContinueStatement_withoutLabel() { |
| 1312 ContinueStatement statement = AstFactory.continueStatement(); | 1311 ContinueStatement statement = AstFactory.continueStatement(); |
| 1313 _resolveStatement(statement, null); | 1312 _resolveStatement(statement, null); |
| 1314 _listener.assertNoErrors(); | 1313 _listener.assertNoErrors(); |
| 1315 } | 1314 } |
| 1316 | 1315 |
| 1317 void test_visitExportDirective_noCombinators() { | 1316 void test_visitExportDirective_noCombinators() { |
| 1318 ExportDirective directive = AstFactory.exportDirective2(null, []); | 1317 ExportDirective directive = AstFactory.exportDirective2(null, []); |
| 1319 directive.element = ElementFactory.exportFor(ElementFactory.library(_definin
gLibrary.context, "lib"), []); | 1318 directive.element = ElementFactory.exportFor(ElementFactory.library(_definin
gLibrary.context, "lib"), []); |
| 1320 _resolveNode(directive, []); | 1319 _resolveNode(directive, []); |
| 1321 _listener.assertNoErrors(); | 1320 _listener.assertNoErrors(); |
| 1322 } | 1321 } |
| 1323 | 1322 |
| 1324 void test_visitFieldFormalParameter() { | 1323 void test_visitFieldFormalParameter() { |
| 1325 String fieldName = "f"; | 1324 String fieldName = "f"; |
| 1326 InterfaceType intType = _typeProvider.intType; | 1325 InterfaceType intType = _typeProvider.intType; |
| 1327 FieldElementImpl fieldElement = ElementFactory.fieldElement(fieldName, false
, false, false, intType); | 1326 FieldElementImpl fieldElement = ElementFactory.fieldElement(fieldName, false
, false, false, intType); |
| 1328 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1327 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1329 classA.fields = <FieldElement> [fieldElement]; | 1328 classA.fields = <FieldElement> [fieldElement]; |
| 1330 FieldFormalParameter parameter = AstFactory.fieldFormalParameter2(fieldName)
; | 1329 FieldFormalParameter parameter = AstFactory.fieldFormalParameter2(fieldName)
; |
| 1331 FieldFormalParameterElementImpl parameterElement = ElementFactory.fieldForma
lParameter(parameter.identifier); | 1330 FieldFormalParameterElementImpl parameterElement = ElementFactory.fieldForma
lParameter(parameter.identifier); |
| 1332 parameterElement.field = fieldElement; | 1331 parameterElement.field = fieldElement; |
| 1333 parameterElement.type = intType; | 1332 parameterElement.type = intType; |
| 1334 parameter.identifier.staticElement = parameterElement; | 1333 parameter.identifier.staticElement = parameterElement; |
| 1335 _resolveInClass(parameter, classA); | 1334 _resolveInClass(parameter, classA); |
| 1336 JUnitTestCase.assertSame(intType, parameter.element.type); | 1335 expect(parameter.element.type, same(intType)); |
| 1337 } | 1336 } |
| 1338 | 1337 |
| 1339 void test_visitImportDirective_noCombinators_noPrefix() { | 1338 void test_visitImportDirective_noCombinators_noPrefix() { |
| 1340 ImportDirective directive = AstFactory.importDirective3(null, null, []); | 1339 ImportDirective directive = AstFactory.importDirective3(null, null, []); |
| 1341 directive.element = ElementFactory.importFor(ElementFactory.library(_definin
gLibrary.context, "lib"), null, []); | 1340 directive.element = ElementFactory.importFor(ElementFactory.library(_definin
gLibrary.context, "lib"), null, []); |
| 1342 _resolveNode(directive, []); | 1341 _resolveNode(directive, []); |
| 1343 _listener.assertNoErrors(); | 1342 _listener.assertNoErrors(); |
| 1344 } | 1343 } |
| 1345 | 1344 |
| 1346 void test_visitImportDirective_noCombinators_prefix() { | 1345 void test_visitImportDirective_noCombinators_prefix() { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1358 ImportDirective directive = AstFactory.importDirective3(null, null, [combina
tor]); | 1357 ImportDirective directive = AstFactory.importDirective3(null, null, [combina
tor]); |
| 1359 LibraryElementImpl library = ElementFactory.library(_definingLibrary.context
, "lib"); | 1358 LibraryElementImpl library = ElementFactory.library(_definingLibrary.context
, "lib"); |
| 1360 TopLevelVariableElementImpl varA = ElementFactory.topLevelVariableElement2("
A"); | 1359 TopLevelVariableElementImpl varA = ElementFactory.topLevelVariableElement2("
A"); |
| 1361 TopLevelVariableElementImpl varB = ElementFactory.topLevelVariableElement2("
B"); | 1360 TopLevelVariableElementImpl varB = ElementFactory.topLevelVariableElement2("
B"); |
| 1362 TopLevelVariableElementImpl varC = ElementFactory.topLevelVariableElement2("
C"); | 1361 TopLevelVariableElementImpl varC = ElementFactory.topLevelVariableElement2("
C"); |
| 1363 CompilationUnitElementImpl unit = library.definingCompilationUnit as Compila
tionUnitElementImpl; | 1362 CompilationUnitElementImpl unit = library.definingCompilationUnit as Compila
tionUnitElementImpl; |
| 1364 unit.accessors = <PropertyAccessorElement> [varA.getter, varA.setter, varB.g
etter, varC.setter]; | 1363 unit.accessors = <PropertyAccessorElement> [varA.getter, varA.setter, varB.g
etter, varC.setter]; |
| 1365 unit.topLevelVariables = <TopLevelVariableElement> [varA, varB, varC]; | 1364 unit.topLevelVariables = <TopLevelVariableElement> [varA, varB, varC]; |
| 1366 directive.element = ElementFactory.importFor(library, null, []); | 1365 directive.element = ElementFactory.importFor(library, null, []); |
| 1367 _resolveNode(directive, []); | 1366 _resolveNode(directive, []); |
| 1368 JUnitTestCase.assertSame(varA, combinator.shownNames[0].staticElement); | 1367 expect(combinator.shownNames[0].staticElement, same(varA)); |
| 1369 JUnitTestCase.assertSame(varB, combinator.shownNames[1].staticElement); | 1368 expect(combinator.shownNames[1].staticElement, same(varB)); |
| 1370 JUnitTestCase.assertSame(varC, combinator.shownNames[2].staticElement); | 1369 expect(combinator.shownNames[2].staticElement, same(varC)); |
| 1371 _listener.assertNoErrors(); | 1370 _listener.assertNoErrors(); |
| 1372 } | 1371 } |
| 1373 | 1372 |
| 1374 void test_visitIndexExpression_get() { | 1373 void test_visitIndexExpression_get() { |
| 1375 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1374 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1376 InterfaceType intType = _typeProvider.intType; | 1375 InterfaceType intType = _typeProvider.intType; |
| 1377 MethodElement getter = ElementFactory.methodElement("[]", intType, [intType]
); | 1376 MethodElement getter = ElementFactory.methodElement("[]", intType, [intType]
); |
| 1378 classA.methods = <MethodElement> [getter]; | 1377 classA.methods = <MethodElement> [getter]; |
| 1379 SimpleIdentifier array = AstFactory.identifier3("a"); | 1378 SimpleIdentifier array = AstFactory.identifier3("a"); |
| 1380 array.staticType = classA.type; | 1379 array.staticType = classA.type; |
| 1381 IndexExpression expression = AstFactory.indexExpression(array, AstFactory.id
entifier3("i")); | 1380 IndexExpression expression = AstFactory.indexExpression(array, AstFactory.id
entifier3("i")); |
| 1382 JUnitTestCase.assertSame(getter, _resolveIndexExpression(expression, [])); | 1381 expect(_resolveIndexExpression(expression, []), same(getter)); |
| 1383 _listener.assertNoErrors(); | 1382 _listener.assertNoErrors(); |
| 1384 } | 1383 } |
| 1385 | 1384 |
| 1386 void test_visitIndexExpression_set() { | 1385 void test_visitIndexExpression_set() { |
| 1387 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1386 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1388 InterfaceType intType = _typeProvider.intType; | 1387 InterfaceType intType = _typeProvider.intType; |
| 1389 MethodElement setter = ElementFactory.methodElement("[]=", intType, [intType
]); | 1388 MethodElement setter = ElementFactory.methodElement("[]=", intType, [intType
]); |
| 1390 classA.methods = <MethodElement> [setter]; | 1389 classA.methods = <MethodElement> [setter]; |
| 1391 SimpleIdentifier array = AstFactory.identifier3("a"); | 1390 SimpleIdentifier array = AstFactory.identifier3("a"); |
| 1392 array.staticType = classA.type; | 1391 array.staticType = classA.type; |
| 1393 IndexExpression expression = AstFactory.indexExpression(array, AstFactory.id
entifier3("i")); | 1392 IndexExpression expression = AstFactory.indexExpression(array, AstFactory.id
entifier3("i")); |
| 1394 AstFactory.assignmentExpression(expression, TokenType.EQ, AstFactory.integer
(0)); | 1393 AstFactory.assignmentExpression(expression, TokenType.EQ, AstFactory.integer
(0)); |
| 1395 JUnitTestCase.assertSame(setter, _resolveIndexExpression(expression, [])); | 1394 expect(_resolveIndexExpression(expression, []), same(setter)); |
| 1396 _listener.assertNoErrors(); | 1395 _listener.assertNoErrors(); |
| 1397 } | 1396 } |
| 1398 | 1397 |
| 1399 void test_visitInstanceCreationExpression_named() { | 1398 void test_visitInstanceCreationExpression_named() { |
| 1400 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1399 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1401 String constructorName = "a"; | 1400 String constructorName = "a"; |
| 1402 ConstructorElement constructor = ElementFactory.constructorElement2(classA,
constructorName, []); | 1401 ConstructorElement constructor = ElementFactory.constructorElement2(classA,
constructorName, []); |
| 1403 classA.constructors = <ConstructorElement> [constructor]; | 1402 classA.constructors = <ConstructorElement> [constructor]; |
| 1404 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA
, []), constructorName); | 1403 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA
, []), constructorName); |
| 1405 name.staticElement = constructor; | 1404 name.staticElement = constructor; |
| 1406 InstanceCreationExpression creation = AstFactory.instanceCreationExpression(
Keyword.NEW, name, []); | 1405 InstanceCreationExpression creation = AstFactory.instanceCreationExpression(
Keyword.NEW, name, []); |
| 1407 _resolveNode(creation, []); | 1406 _resolveNode(creation, []); |
| 1408 JUnitTestCase.assertSame(constructor, creation.staticElement); | 1407 expect(creation.staticElement, same(constructor)); |
| 1409 _listener.assertNoErrors(); | 1408 _listener.assertNoErrors(); |
| 1410 } | 1409 } |
| 1411 | 1410 |
| 1412 void test_visitInstanceCreationExpression_unnamed() { | 1411 void test_visitInstanceCreationExpression_unnamed() { |
| 1413 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1412 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1414 String constructorName = null; | 1413 String constructorName = null; |
| 1415 ConstructorElement constructor = ElementFactory.constructorElement2(classA,
constructorName, []); | 1414 ConstructorElement constructor = ElementFactory.constructorElement2(classA,
constructorName, []); |
| 1416 classA.constructors = <ConstructorElement> [constructor]; | 1415 classA.constructors = <ConstructorElement> [constructor]; |
| 1417 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA
, []), constructorName); | 1416 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA
, []), constructorName); |
| 1418 name.staticElement = constructor; | 1417 name.staticElement = constructor; |
| 1419 InstanceCreationExpression creation = AstFactory.instanceCreationExpression(
Keyword.NEW, name, []); | 1418 InstanceCreationExpression creation = AstFactory.instanceCreationExpression(
Keyword.NEW, name, []); |
| 1420 _resolveNode(creation, []); | 1419 _resolveNode(creation, []); |
| 1421 JUnitTestCase.assertSame(constructor, creation.staticElement); | 1420 expect(creation.staticElement, same(constructor)); |
| 1422 _listener.assertNoErrors(); | 1421 _listener.assertNoErrors(); |
| 1423 } | 1422 } |
| 1424 | 1423 |
| 1425 void test_visitInstanceCreationExpression_unnamed_namedParameter() { | 1424 void test_visitInstanceCreationExpression_unnamed_namedParameter() { |
| 1426 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1425 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1427 String constructorName = null; | 1426 String constructorName = null; |
| 1428 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas
sA, constructorName, []); | 1427 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas
sA, constructorName, []); |
| 1429 String parameterName = "a"; | 1428 String parameterName = "a"; |
| 1430 ParameterElement parameter = ElementFactory.namedParameter(parameterName); | 1429 ParameterElement parameter = ElementFactory.namedParameter(parameterName); |
| 1431 constructor.parameters = <ParameterElement> [parameter]; | 1430 constructor.parameters = <ParameterElement> [parameter]; |
| 1432 classA.constructors = <ConstructorElement> [constructor]; | 1431 classA.constructors = <ConstructorElement> [constructor]; |
| 1433 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA
, []), constructorName); | 1432 ConstructorName name = AstFactory.constructorName(AstFactory.typeName(classA
, []), constructorName); |
| 1434 name.staticElement = constructor; | 1433 name.staticElement = constructor; |
| 1435 InstanceCreationExpression creation = AstFactory.instanceCreationExpression(
Keyword.NEW, name, [AstFactory.namedExpression2(parameterName, AstFactory.intege
r(0))]); | 1434 InstanceCreationExpression creation = AstFactory.instanceCreationExpression(
Keyword.NEW, name, [AstFactory.namedExpression2(parameterName, AstFactory.intege
r(0))]); |
| 1436 _resolveNode(creation, []); | 1435 _resolveNode(creation, []); |
| 1437 JUnitTestCase.assertSame(constructor, creation.staticElement); | 1436 expect(creation.staticElement, same(constructor)); |
| 1438 JUnitTestCase.assertSame(parameter, (creation.argumentList.arguments[0] as N
amedExpression).name.label.staticElement); | 1437 expect((creation.argumentList.arguments[0] as NamedExpression).name.label.st
aticElement, same(parameter)); |
| 1439 _listener.assertNoErrors(); | 1438 _listener.assertNoErrors(); |
| 1440 } | 1439 } |
| 1441 | 1440 |
| 1442 void test_visitMethodInvocation() { | 1441 void test_visitMethodInvocation() { |
| 1443 InterfaceType numType = _typeProvider.numType; | 1442 InterfaceType numType = _typeProvider.numType; |
| 1444 SimpleIdentifier left = AstFactory.identifier3("i"); | 1443 SimpleIdentifier left = AstFactory.identifier3("i"); |
| 1445 left.staticType = numType; | 1444 left.staticType = numType; |
| 1446 String methodName = "abs"; | 1445 String methodName = "abs"; |
| 1447 MethodInvocation invocation = AstFactory.methodInvocation(left, methodName,
[]); | 1446 MethodInvocation invocation = AstFactory.methodInvocation(left, methodName,
[]); |
| 1448 _resolveNode(invocation, []); | 1447 _resolveNode(invocation, []); |
| 1449 JUnitTestCase.assertSame(getMethod(numType, methodName), invocation.methodNa
me.staticElement); | 1448 expect(invocation.methodName.staticElement, same(getMethod(numType, methodNa
me))); |
| 1450 _listener.assertNoErrors(); | 1449 _listener.assertNoErrors(); |
| 1451 } | 1450 } |
| 1452 | 1451 |
| 1453 void test_visitMethodInvocation_namedParameter() { | 1452 void test_visitMethodInvocation_namedParameter() { |
| 1454 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1453 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1455 String methodName = "m"; | 1454 String methodName = "m"; |
| 1456 String parameterName = "p"; | 1455 String parameterName = "p"; |
| 1457 MethodElementImpl method = ElementFactory.methodElement(methodName, null, []
); | 1456 MethodElementImpl method = ElementFactory.methodElement(methodName, null, []
); |
| 1458 ParameterElement parameter = ElementFactory.namedParameter(parameterName); | 1457 ParameterElement parameter = ElementFactory.namedParameter(parameterName); |
| 1459 method.parameters = <ParameterElement> [parameter]; | 1458 method.parameters = <ParameterElement> [parameter]; |
| 1460 classA.methods = <MethodElement> [method]; | 1459 classA.methods = <MethodElement> [method]; |
| 1461 SimpleIdentifier left = AstFactory.identifier3("i"); | 1460 SimpleIdentifier left = AstFactory.identifier3("i"); |
| 1462 left.staticType = classA.type; | 1461 left.staticType = classA.type; |
| 1463 MethodInvocation invocation = AstFactory.methodInvocation(left, methodName,
[AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]); | 1462 MethodInvocation invocation = AstFactory.methodInvocation(left, methodName,
[AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]); |
| 1464 _resolveNode(invocation, []); | 1463 _resolveNode(invocation, []); |
| 1465 JUnitTestCase.assertSame(method, invocation.methodName.staticElement); | 1464 expect(invocation.methodName.staticElement, same(method)); |
| 1466 JUnitTestCase.assertSame(parameter, (invocation.argumentList.arguments[0] as
NamedExpression).name.label.staticElement); | 1465 expect((invocation.argumentList.arguments[0] as NamedExpression).name.label.
staticElement, same(parameter)); |
| 1467 _listener.assertNoErrors(); | 1466 _listener.assertNoErrors(); |
| 1468 } | 1467 } |
| 1469 | 1468 |
| 1470 void test_visitPostfixExpression() { | 1469 void test_visitPostfixExpression() { |
| 1471 InterfaceType numType = _typeProvider.numType; | 1470 InterfaceType numType = _typeProvider.numType; |
| 1472 SimpleIdentifier operand = AstFactory.identifier3("i"); | 1471 SimpleIdentifier operand = AstFactory.identifier3("i"); |
| 1473 operand.staticType = numType; | 1472 operand.staticType = numType; |
| 1474 PostfixExpression expression = AstFactory.postfixExpression(operand, TokenTy
pe.PLUS_PLUS); | 1473 PostfixExpression expression = AstFactory.postfixExpression(operand, TokenTy
pe.PLUS_PLUS); |
| 1475 _resolveNode(expression, []); | 1474 _resolveNode(expression, []); |
| 1476 JUnitTestCase.assertEquals(getMethod(numType, "+"), expression.staticElement
); | 1475 expect(expression.staticElement, getMethod(numType, "+")); |
| 1477 _listener.assertNoErrors(); | 1476 _listener.assertNoErrors(); |
| 1478 } | 1477 } |
| 1479 | 1478 |
| 1480 void test_visitPrefixedIdentifier_dynamic() { | 1479 void test_visitPrefixedIdentifier_dynamic() { |
| 1481 DartType dynamicType = _typeProvider.dynamicType; | 1480 DartType dynamicType = _typeProvider.dynamicType; |
| 1482 SimpleIdentifier target = AstFactory.identifier3("a"); | 1481 SimpleIdentifier target = AstFactory.identifier3("a"); |
| 1483 VariableElementImpl variable = ElementFactory.localVariableElement(target); | 1482 VariableElementImpl variable = ElementFactory.localVariableElement(target); |
| 1484 variable.type = dynamicType; | 1483 variable.type = dynamicType; |
| 1485 target.staticElement = variable; | 1484 target.staticElement = variable; |
| 1486 target.staticType = dynamicType; | 1485 target.staticType = dynamicType; |
| 1487 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide
ntifier3("b")); | 1486 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide
ntifier3("b")); |
| 1488 _resolveNode(identifier, []); | 1487 _resolveNode(identifier, []); |
| 1489 JUnitTestCase.assertNull(identifier.staticElement); | 1488 expect(identifier.staticElement, isNull); |
| 1490 JUnitTestCase.assertNull(identifier.identifier.staticElement); | 1489 expect(identifier.identifier.staticElement, isNull); |
| 1491 _listener.assertNoErrors(); | 1490 _listener.assertNoErrors(); |
| 1492 } | 1491 } |
| 1493 | 1492 |
| 1494 void test_visitPrefixedIdentifier_nonDynamic() { | 1493 void test_visitPrefixedIdentifier_nonDynamic() { |
| 1495 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1494 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1496 String getterName = "b"; | 1495 String getterName = "b"; |
| 1497 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa
lse, _typeProvider.intType); | 1496 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa
lse, _typeProvider.intType); |
| 1498 classA.accessors = <PropertyAccessorElement> [getter]; | 1497 classA.accessors = <PropertyAccessorElement> [getter]; |
| 1499 SimpleIdentifier target = AstFactory.identifier3("a"); | 1498 SimpleIdentifier target = AstFactory.identifier3("a"); |
| 1500 VariableElementImpl variable = ElementFactory.localVariableElement(target); | 1499 VariableElementImpl variable = ElementFactory.localVariableElement(target); |
| 1501 variable.type = classA.type; | 1500 variable.type = classA.type; |
| 1502 target.staticElement = variable; | 1501 target.staticElement = variable; |
| 1503 target.staticType = classA.type; | 1502 target.staticType = classA.type; |
| 1504 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide
ntifier3(getterName)); | 1503 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide
ntifier3(getterName)); |
| 1505 _resolveNode(identifier, []); | 1504 _resolveNode(identifier, []); |
| 1506 JUnitTestCase.assertSame(getter, identifier.staticElement); | 1505 expect(identifier.staticElement, same(getter)); |
| 1507 JUnitTestCase.assertSame(getter, identifier.identifier.staticElement); | 1506 expect(identifier.identifier.staticElement, same(getter)); |
| 1508 _listener.assertNoErrors(); | 1507 _listener.assertNoErrors(); |
| 1509 } | 1508 } |
| 1510 | 1509 |
| 1511 void test_visitPrefixedIdentifier_staticClassMember_getter() { | 1510 void test_visitPrefixedIdentifier_staticClassMember_getter() { |
| 1512 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1511 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1513 // set accessors | 1512 // set accessors |
| 1514 String propName = "b"; | 1513 String propName = "b"; |
| 1515 PropertyAccessorElement getter = ElementFactory.getterElement(propName, fals
e, _typeProvider.intType); | 1514 PropertyAccessorElement getter = ElementFactory.getterElement(propName, fals
e, _typeProvider.intType); |
| 1516 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals
e, _typeProvider.intType); | 1515 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals
e, _typeProvider.intType); |
| 1517 classA.accessors = <PropertyAccessorElement> [getter, setter]; | 1516 classA.accessors = <PropertyAccessorElement> [getter, setter]; |
| 1518 // prepare "A.m" | 1517 // prepare "A.m" |
| 1519 SimpleIdentifier target = AstFactory.identifier3("A"); | 1518 SimpleIdentifier target = AstFactory.identifier3("A"); |
| 1520 target.staticElement = classA; | 1519 target.staticElement = classA; |
| 1521 target.staticType = classA.type; | 1520 target.staticType = classA.type; |
| 1522 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide
ntifier3(propName)); | 1521 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide
ntifier3(propName)); |
| 1523 // resolve | 1522 // resolve |
| 1524 _resolveNode(identifier, []); | 1523 _resolveNode(identifier, []); |
| 1525 JUnitTestCase.assertSame(getter, identifier.staticElement); | 1524 expect(identifier.staticElement, same(getter)); |
| 1526 JUnitTestCase.assertSame(getter, identifier.identifier.staticElement); | 1525 expect(identifier.identifier.staticElement, same(getter)); |
| 1527 _listener.assertNoErrors(); | 1526 _listener.assertNoErrors(); |
| 1528 } | 1527 } |
| 1529 | 1528 |
| 1530 void test_visitPrefixedIdentifier_staticClassMember_method() { | 1529 void test_visitPrefixedIdentifier_staticClassMember_method() { |
| 1531 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1530 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1532 // set accessors | 1531 // set accessors |
| 1533 String propName = "m"; | 1532 String propName = "m"; |
| 1534 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals
e, _typeProvider.intType); | 1533 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals
e, _typeProvider.intType); |
| 1535 classA.accessors = <PropertyAccessorElement> [setter]; | 1534 classA.accessors = <PropertyAccessorElement> [setter]; |
| 1536 // set methods | 1535 // set methods |
| 1537 MethodElement method = ElementFactory.methodElement("m", _typeProvider.intTy
pe, []); | 1536 MethodElement method = ElementFactory.methodElement("m", _typeProvider.intTy
pe, []); |
| 1538 classA.methods = <MethodElement> [method]; | 1537 classA.methods = <MethodElement> [method]; |
| 1539 // prepare "A.m" | 1538 // prepare "A.m" |
| 1540 SimpleIdentifier target = AstFactory.identifier3("A"); | 1539 SimpleIdentifier target = AstFactory.identifier3("A"); |
| 1541 target.staticElement = classA; | 1540 target.staticElement = classA; |
| 1542 target.staticType = classA.type; | 1541 target.staticType = classA.type; |
| 1543 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide
ntifier3(propName)); | 1542 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide
ntifier3(propName)); |
| 1544 AstFactory.assignmentExpression(identifier, TokenType.EQ, AstFactory.nullLit
eral()); | 1543 AstFactory.assignmentExpression(identifier, TokenType.EQ, AstFactory.nullLit
eral()); |
| 1545 // resolve | 1544 // resolve |
| 1546 _resolveNode(identifier, []); | 1545 _resolveNode(identifier, []); |
| 1547 JUnitTestCase.assertSame(method, identifier.staticElement); | 1546 expect(identifier.staticElement, same(method)); |
| 1548 JUnitTestCase.assertSame(method, identifier.identifier.staticElement); | 1547 expect(identifier.identifier.staticElement, same(method)); |
| 1549 _listener.assertNoErrors(); | 1548 _listener.assertNoErrors(); |
| 1550 } | 1549 } |
| 1551 | 1550 |
| 1552 void test_visitPrefixedIdentifier_staticClassMember_setter() { | 1551 void test_visitPrefixedIdentifier_staticClassMember_setter() { |
| 1553 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1552 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1554 // set accessors | 1553 // set accessors |
| 1555 String propName = "b"; | 1554 String propName = "b"; |
| 1556 PropertyAccessorElement getter = ElementFactory.getterElement(propName, fals
e, _typeProvider.intType); | 1555 PropertyAccessorElement getter = ElementFactory.getterElement(propName, fals
e, _typeProvider.intType); |
| 1557 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals
e, _typeProvider.intType); | 1556 PropertyAccessorElement setter = ElementFactory.setterElement(propName, fals
e, _typeProvider.intType); |
| 1558 classA.accessors = <PropertyAccessorElement> [getter, setter]; | 1557 classA.accessors = <PropertyAccessorElement> [getter, setter]; |
| 1559 // prepare "A.b = null" | 1558 // prepare "A.b = null" |
| 1560 SimpleIdentifier target = AstFactory.identifier3("A"); | 1559 SimpleIdentifier target = AstFactory.identifier3("A"); |
| 1561 target.staticElement = classA; | 1560 target.staticElement = classA; |
| 1562 target.staticType = classA.type; | 1561 target.staticType = classA.type; |
| 1563 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide
ntifier3(propName)); | 1562 PrefixedIdentifier identifier = AstFactory.identifier(target, AstFactory.ide
ntifier3(propName)); |
| 1564 AstFactory.assignmentExpression(identifier, TokenType.EQ, AstFactory.nullLit
eral()); | 1563 AstFactory.assignmentExpression(identifier, TokenType.EQ, AstFactory.nullLit
eral()); |
| 1565 // resolve | 1564 // resolve |
| 1566 _resolveNode(identifier, []); | 1565 _resolveNode(identifier, []); |
| 1567 JUnitTestCase.assertSame(setter, identifier.staticElement); | 1566 expect(identifier.staticElement, same(setter)); |
| 1568 JUnitTestCase.assertSame(setter, identifier.identifier.staticElement); | 1567 expect(identifier.identifier.staticElement, same(setter)); |
| 1569 _listener.assertNoErrors(); | 1568 _listener.assertNoErrors(); |
| 1570 } | 1569 } |
| 1571 | 1570 |
| 1572 void test_visitPrefixExpression() { | 1571 void test_visitPrefixExpression() { |
| 1573 InterfaceType numType = _typeProvider.numType; | 1572 InterfaceType numType = _typeProvider.numType; |
| 1574 SimpleIdentifier operand = AstFactory.identifier3("i"); | 1573 SimpleIdentifier operand = AstFactory.identifier3("i"); |
| 1575 operand.staticType = numType; | 1574 operand.staticType = numType; |
| 1576 PrefixExpression expression = AstFactory.prefixExpression(TokenType.PLUS_PLU
S, operand); | 1575 PrefixExpression expression = AstFactory.prefixExpression(TokenType.PLUS_PLU
S, operand); |
| 1577 _resolveNode(expression, []); | 1576 _resolveNode(expression, []); |
| 1578 JUnitTestCase.assertEquals(getMethod(numType, "+"), expression.staticElement
); | 1577 expect(expression.staticElement, getMethod(numType, "+")); |
| 1579 _listener.assertNoErrors(); | 1578 _listener.assertNoErrors(); |
| 1580 } | 1579 } |
| 1581 | 1580 |
| 1582 void test_visitPropertyAccess_getter_identifier() { | 1581 void test_visitPropertyAccess_getter_identifier() { |
| 1583 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1582 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1584 String getterName = "b"; | 1583 String getterName = "b"; |
| 1585 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa
lse, _typeProvider.intType); | 1584 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa
lse, _typeProvider.intType); |
| 1586 classA.accessors = <PropertyAccessorElement> [getter]; | 1585 classA.accessors = <PropertyAccessorElement> [getter]; |
| 1587 SimpleIdentifier target = AstFactory.identifier3("a"); | 1586 SimpleIdentifier target = AstFactory.identifier3("a"); |
| 1588 target.staticType = classA.type; | 1587 target.staticType = classA.type; |
| 1589 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); | 1588 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); |
| 1590 _resolveNode(access, []); | 1589 _resolveNode(access, []); |
| 1591 JUnitTestCase.assertSame(getter, access.propertyName.staticElement); | 1590 expect(access.propertyName.staticElement, same(getter)); |
| 1592 _listener.assertNoErrors(); | 1591 _listener.assertNoErrors(); |
| 1593 } | 1592 } |
| 1594 | 1593 |
| 1595 void test_visitPropertyAccess_getter_super() { | 1594 void test_visitPropertyAccess_getter_super() { |
| 1596 // | 1595 // |
| 1597 // class A { | 1596 // class A { |
| 1598 // int get b; | 1597 // int get b; |
| 1599 // } | 1598 // } |
| 1600 // class B { | 1599 // class B { |
| 1601 // ... super.m ... | 1600 // ... super.m ... |
| 1602 // } | 1601 // } |
| 1603 // | 1602 // |
| 1604 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1603 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1605 String getterName = "b"; | 1604 String getterName = "b"; |
| 1606 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa
lse, _typeProvider.intType); | 1605 PropertyAccessorElement getter = ElementFactory.getterElement(getterName, fa
lse, _typeProvider.intType); |
| 1607 classA.accessors = <PropertyAccessorElement> [getter]; | 1606 classA.accessors = <PropertyAccessorElement> [getter]; |
| 1608 SuperExpression target = AstFactory.superExpression(); | 1607 SuperExpression target = AstFactory.superExpression(); |
| 1609 target.staticType = ElementFactory.classElement("B", classA.type, []).type; | 1608 target.staticType = ElementFactory.classElement("B", classA.type, []).type; |
| 1610 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); | 1609 PropertyAccess access = AstFactory.propertyAccess2(target, getterName); |
| 1611 AstFactory.methodDeclaration2(null, null, null, null, AstFactory.identifier3
("m"), AstFactory.formalParameterList([]), AstFactory.expressionFunctionBody(acc
ess)); | 1610 AstFactory.methodDeclaration2(null, null, null, null, AstFactory.identifier3
("m"), AstFactory.formalParameterList([]), AstFactory.expressionFunctionBody(acc
ess)); |
| 1612 _resolveNode(access, []); | 1611 _resolveNode(access, []); |
| 1613 JUnitTestCase.assertSame(getter, access.propertyName.staticElement); | 1612 expect(access.propertyName.staticElement, same(getter)); |
| 1614 _listener.assertNoErrors(); | 1613 _listener.assertNoErrors(); |
| 1615 } | 1614 } |
| 1616 | 1615 |
| 1617 void test_visitPropertyAccess_setter_this() { | 1616 void test_visitPropertyAccess_setter_this() { |
| 1618 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1617 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1619 String setterName = "b"; | 1618 String setterName = "b"; |
| 1620 PropertyAccessorElement setter = ElementFactory.setterElement(setterName, fa
lse, _typeProvider.intType); | 1619 PropertyAccessorElement setter = ElementFactory.setterElement(setterName, fa
lse, _typeProvider.intType); |
| 1621 classA.accessors = <PropertyAccessorElement> [setter]; | 1620 classA.accessors = <PropertyAccessorElement> [setter]; |
| 1622 ThisExpression target = AstFactory.thisExpression(); | 1621 ThisExpression target = AstFactory.thisExpression(); |
| 1623 target.staticType = classA.type; | 1622 target.staticType = classA.type; |
| 1624 PropertyAccess access = AstFactory.propertyAccess2(target, setterName); | 1623 PropertyAccess access = AstFactory.propertyAccess2(target, setterName); |
| 1625 AstFactory.assignmentExpression(access, TokenType.EQ, AstFactory.integer(0))
; | 1624 AstFactory.assignmentExpression(access, TokenType.EQ, AstFactory.integer(0))
; |
| 1626 _resolveNode(access, []); | 1625 _resolveNode(access, []); |
| 1627 JUnitTestCase.assertSame(setter, access.propertyName.staticElement); | 1626 expect(access.propertyName.staticElement, same(setter)); |
| 1628 _listener.assertNoErrors(); | 1627 _listener.assertNoErrors(); |
| 1629 } | 1628 } |
| 1630 | 1629 |
| 1631 void test_visitSimpleIdentifier_classScope() { | 1630 void test_visitSimpleIdentifier_classScope() { |
| 1632 InterfaceType doubleType = _typeProvider.doubleType; | 1631 InterfaceType doubleType = _typeProvider.doubleType; |
| 1633 String fieldName = "NAN"; | 1632 String fieldName = "NAN"; |
| 1634 SimpleIdentifier node = AstFactory.identifier3(fieldName); | 1633 SimpleIdentifier node = AstFactory.identifier3(fieldName); |
| 1635 _resolveInClass(node, doubleType.element); | 1634 _resolveInClass(node, doubleType.element); |
| 1636 JUnitTestCase.assertEquals(getGetter(doubleType, fieldName), node.staticElem
ent); | 1635 expect(node.staticElement, getGetter(doubleType, fieldName)); |
| 1637 _listener.assertNoErrors(); | 1636 _listener.assertNoErrors(); |
| 1638 } | 1637 } |
| 1639 | 1638 |
| 1640 void test_visitSimpleIdentifier_dynamic() { | 1639 void test_visitSimpleIdentifier_dynamic() { |
| 1641 SimpleIdentifier node = AstFactory.identifier3("dynamic"); | 1640 SimpleIdentifier node = AstFactory.identifier3("dynamic"); |
| 1642 _resolveIdentifier(node, []); | 1641 _resolveIdentifier(node, []); |
| 1643 JUnitTestCase.assertSame(_typeProvider.dynamicType.element, node.staticEleme
nt); | 1642 expect(node.staticElement, same(_typeProvider.dynamicType.element)); |
| 1644 JUnitTestCase.assertSame(_typeProvider.typeType, node.staticType); | 1643 expect(node.staticType, same(_typeProvider.typeType)); |
| 1645 _listener.assertNoErrors(); | 1644 _listener.assertNoErrors(); |
| 1646 } | 1645 } |
| 1647 | 1646 |
| 1648 void test_visitSimpleIdentifier_lexicalScope() { | 1647 void test_visitSimpleIdentifier_lexicalScope() { |
| 1649 SimpleIdentifier node = AstFactory.identifier3("i"); | 1648 SimpleIdentifier node = AstFactory.identifier3("i"); |
| 1650 VariableElementImpl element = ElementFactory.localVariableElement(node); | 1649 VariableElementImpl element = ElementFactory.localVariableElement(node); |
| 1651 JUnitTestCase.assertSame(element, _resolveIdentifier(node, [element])); | 1650 expect(_resolveIdentifier(node, [element]), same(element)); |
| 1652 _listener.assertNoErrors(); | 1651 _listener.assertNoErrors(); |
| 1653 } | 1652 } |
| 1654 | 1653 |
| 1655 void test_visitSimpleIdentifier_lexicalScope_field_setter() { | 1654 void test_visitSimpleIdentifier_lexicalScope_field_setter() { |
| 1656 InterfaceType intType = _typeProvider.intType; | 1655 InterfaceType intType = _typeProvider.intType; |
| 1657 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 1656 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 1658 String fieldName = "a"; | 1657 String fieldName = "a"; |
| 1659 FieldElement field = ElementFactory.fieldElement(fieldName, false, false, fa
lse, intType); | 1658 FieldElement field = ElementFactory.fieldElement(fieldName, false, false, fa
lse, intType); |
| 1660 classA.fields = <FieldElement> [field]; | 1659 classA.fields = <FieldElement> [field]; |
| 1661 classA.accessors = <PropertyAccessorElement> [field.getter, field.setter]; | 1660 classA.accessors = <PropertyAccessorElement> [field.getter, field.setter]; |
| 1662 SimpleIdentifier node = AstFactory.identifier3(fieldName); | 1661 SimpleIdentifier node = AstFactory.identifier3(fieldName); |
| 1663 AstFactory.assignmentExpression(node, TokenType.EQ, AstFactory.integer(0)); | 1662 AstFactory.assignmentExpression(node, TokenType.EQ, AstFactory.integer(0)); |
| 1664 _resolveInClass(node, classA); | 1663 _resolveInClass(node, classA); |
| 1665 Element element = node.staticElement; | 1664 Element element = node.staticElement; |
| 1666 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, Pro
pertyAccessorElement, element); | 1665 EngineTestCase.assertInstanceOf((obj) => obj is PropertyAccessorElement, Pro
pertyAccessorElement, element); |
| 1667 JUnitTestCase.assertTrue((element as PropertyAccessorElement).isSetter); | 1666 expect((element as PropertyAccessorElement).isSetter, isTrue); |
| 1668 _listener.assertNoErrors(); | 1667 _listener.assertNoErrors(); |
| 1669 } | 1668 } |
| 1670 | 1669 |
| 1671 void test_visitSuperConstructorInvocation() { | 1670 void test_visitSuperConstructorInvocation() { |
| 1672 ClassElementImpl superclass = ElementFactory.classElement2("A", []); | 1671 ClassElementImpl superclass = ElementFactory.classElement2("A", []); |
| 1673 ConstructorElementImpl superConstructor = ElementFactory.constructorElement2
(superclass, null, []); | 1672 ConstructorElementImpl superConstructor = ElementFactory.constructorElement2
(superclass, null, []); |
| 1674 superclass.constructors = <ConstructorElement> [superConstructor]; | 1673 superclass.constructors = <ConstructorElement> [superConstructor]; |
| 1675 ClassElementImpl subclass = ElementFactory.classElement("B", superclass.type
, []); | 1674 ClassElementImpl subclass = ElementFactory.classElement("B", superclass.type
, []); |
| 1676 ConstructorElementImpl subConstructor = ElementFactory.constructorElement2(s
ubclass, null, []); | 1675 ConstructorElementImpl subConstructor = ElementFactory.constructorElement2(s
ubclass, null, []); |
| 1677 subclass.constructors = <ConstructorElement> [subConstructor]; | 1676 subclass.constructors = <ConstructorElement> [subConstructor]; |
| 1678 SuperConstructorInvocation invocation = AstFactory.superConstructorInvocatio
n([]); | 1677 SuperConstructorInvocation invocation = AstFactory.superConstructorInvocatio
n([]); |
| 1679 _resolveInClass(invocation, subclass); | 1678 _resolveInClass(invocation, subclass); |
| 1680 JUnitTestCase.assertEquals(superConstructor, invocation.staticElement); | 1679 expect(invocation.staticElement, superConstructor); |
| 1681 _listener.assertNoErrors(); | 1680 _listener.assertNoErrors(); |
| 1682 } | 1681 } |
| 1683 | 1682 |
| 1684 void test_visitSuperConstructorInvocation_namedParameter() { | 1683 void test_visitSuperConstructorInvocation_namedParameter() { |
| 1685 ClassElementImpl superclass = ElementFactory.classElement2("A", []); | 1684 ClassElementImpl superclass = ElementFactory.classElement2("A", []); |
| 1686 ConstructorElementImpl superConstructor = ElementFactory.constructorElement2
(superclass, null, []); | 1685 ConstructorElementImpl superConstructor = ElementFactory.constructorElement2
(superclass, null, []); |
| 1687 String parameterName = "p"; | 1686 String parameterName = "p"; |
| 1688 ParameterElement parameter = ElementFactory.namedParameter(parameterName); | 1687 ParameterElement parameter = ElementFactory.namedParameter(parameterName); |
| 1689 superConstructor.parameters = <ParameterElement> [parameter]; | 1688 superConstructor.parameters = <ParameterElement> [parameter]; |
| 1690 superclass.constructors = <ConstructorElement> [superConstructor]; | 1689 superclass.constructors = <ConstructorElement> [superConstructor]; |
| 1691 ClassElementImpl subclass = ElementFactory.classElement("B", superclass.type
, []); | 1690 ClassElementImpl subclass = ElementFactory.classElement("B", superclass.type
, []); |
| 1692 ConstructorElementImpl subConstructor = ElementFactory.constructorElement2(s
ubclass, null, []); | 1691 ConstructorElementImpl subConstructor = ElementFactory.constructorElement2(s
ubclass, null, []); |
| 1693 subclass.constructors = <ConstructorElement> [subConstructor]; | 1692 subclass.constructors = <ConstructorElement> [subConstructor]; |
| 1694 SuperConstructorInvocation invocation = AstFactory.superConstructorInvocatio
n([AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]); | 1693 SuperConstructorInvocation invocation = AstFactory.superConstructorInvocatio
n([AstFactory.namedExpression2(parameterName, AstFactory.integer(0))]); |
| 1695 _resolveInClass(invocation, subclass); | 1694 _resolveInClass(invocation, subclass); |
| 1696 JUnitTestCase.assertEquals(superConstructor, invocation.staticElement); | 1695 expect(invocation.staticElement, superConstructor); |
| 1697 JUnitTestCase.assertSame(parameter, (invocation.argumentList.arguments[0] as
NamedExpression).name.label.staticElement); | 1696 expect((invocation.argumentList.arguments[0] as NamedExpression).name.label.
staticElement, same(parameter)); |
| 1698 _listener.assertNoErrors(); | 1697 _listener.assertNoErrors(); |
| 1699 } | 1698 } |
| 1700 | 1699 |
| 1701 /** | 1700 /** |
| 1702 * Create the resolver used by the tests. | 1701 * Create the resolver used by the tests. |
| 1703 * | 1702 * |
| 1704 * @return the resolver that was created | 1703 * @return the resolver that was created |
| 1705 */ | 1704 */ |
| 1706 ElementResolver _createResolver() { | 1705 ElementResolver _createResolver() { |
| 1707 AnalysisContextImpl context = new AnalysisContextImpl(); | 1706 AnalysisContextImpl context = new AnalysisContextImpl(); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1916 } | 1915 } |
| 1917 | 1916 |
| 1918 void test_enclosingElement_invalidLocalFunction() { | 1917 void test_enclosingElement_invalidLocalFunction() { |
| 1919 Source source = addSource(r''' | 1918 Source source = addSource(r''' |
| 1920 class C { | 1919 class C { |
| 1921 C() { | 1920 C() { |
| 1922 int get x => 0; | 1921 int get x => 0; |
| 1923 } | 1922 } |
| 1924 }'''); | 1923 }'''); |
| 1925 LibraryElement library = resolve(source); | 1924 LibraryElement library = resolve(source); |
| 1926 JUnitTestCase.assertNotNull(library); | 1925 expect(library, isNotNull); |
| 1927 var unit = library.definingCompilationUnit; | 1926 var unit = library.definingCompilationUnit; |
| 1928 JUnitTestCase.assertNotNull(unit); | 1927 expect(unit, isNotNull); |
| 1929 var types = unit.types; | 1928 var types = unit.types; |
| 1930 JUnitTestCase.assertNotNull(types); | 1929 expect(types, isNotNull); |
| 1931 EngineTestCase.assertSizeOfList(1, types); | 1930 EngineTestCase.assertSizeOfList(1, types); |
| 1932 var type = types[0]; | 1931 var type = types[0]; |
| 1933 JUnitTestCase.assertNotNull(type); | 1932 expect(type, isNotNull); |
| 1934 var constructors = type.constructors; | 1933 var constructors = type.constructors; |
| 1935 JUnitTestCase.assertNotNull(constructors); | 1934 expect(constructors, isNotNull); |
| 1936 EngineTestCase.assertSizeOfList(1, constructors); | 1935 EngineTestCase.assertSizeOfList(1, constructors); |
| 1937 ConstructorElement constructor = constructors[0]; | 1936 ConstructorElement constructor = constructors[0]; |
| 1938 JUnitTestCase.assertNotNull(constructor); | 1937 expect(constructor, isNotNull); |
| 1939 List<FunctionElement> functions = constructor.functions; | 1938 List<FunctionElement> functions = constructor.functions; |
| 1940 JUnitTestCase.assertNotNull(functions); | 1939 expect(functions, isNotNull); |
| 1941 EngineTestCase.assertSizeOfList(1, functions); | 1940 EngineTestCase.assertSizeOfList(1, functions); |
| 1942 JUnitTestCase.assertEquals(constructor, functions[0].enclosingElement); | 1941 expect(functions[0].enclosingElement, constructor); |
| 1943 assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]); | 1942 assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]); |
| 1944 } | 1943 } |
| 1945 } | 1944 } |
| 1946 | 1945 |
| 1947 class HintCodeTest extends ResolverTestCase { | 1946 class HintCodeTest extends ResolverTestCase { |
| 1948 void fail_deadCode_statementAfterRehrow() { | 1947 void fail_deadCode_statementAfterRehrow() { |
| 1949 Source source = addSource(r''' | 1948 Source source = addSource(r''' |
| 1950 f() { | 1949 f() { |
| 1951 try { | 1950 try { |
| 1952 var one = 1; | 1951 var one = 1; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2026 n(void f(int i)) {} | 2025 n(void f(int i)) {} |
| 2027 }'''); | 2026 }'''); |
| 2028 resolve(source); | 2027 resolve(source); |
| 2029 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 2028 assertErrors(source, [HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 2030 verify([source]); | 2029 verify([source]); |
| 2031 } | 2030 } |
| 2032 | 2031 |
| 2033 void test_argumentTypeNotAssignable_message() { | 2032 void test_argumentTypeNotAssignable_message() { |
| 2034 // The implementation of HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE assumes that | 2033 // The implementation of HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE assumes that |
| 2035 // StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE has the same message. | 2034 // StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE has the same message. |
| 2036 JUnitTestCase.assertEquals(HintCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message, St
aticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message); | 2035 expect(StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE.message, HintCode.ARGU
MENT_TYPE_NOT_ASSIGNABLE.message); |
| 2037 } | 2036 } |
| 2038 | 2037 |
| 2039 void test_argumentTypeNotAssignable_type() { | 2038 void test_argumentTypeNotAssignable_type() { |
| 2040 Source source = addSource(r''' | 2039 Source source = addSource(r''' |
| 2041 m() { | 2040 m() { |
| 2042 var i = ''; | 2041 var i = ''; |
| 2043 n(i); | 2042 n(i); |
| 2044 } | 2043 } |
| 2045 n(int i) {}'''); | 2044 n(int i) {}'''); |
| 2046 resolve(source); | 2045 resolve(source); |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2780 } | 2779 } |
| 2781 }'''); | 2780 }'''); |
| 2782 resolve(source); | 2781 resolve(source); |
| 2783 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); | 2782 assertErrors(source, [HintCode.INVALID_ASSIGNMENT]); |
| 2784 verify([source]); | 2783 verify([source]); |
| 2785 } | 2784 } |
| 2786 | 2785 |
| 2787 void test_invalidAssignment_message() { | 2786 void test_invalidAssignment_message() { |
| 2788 // The implementation of HintCode.INVALID_ASSIGNMENT assumes that | 2787 // The implementation of HintCode.INVALID_ASSIGNMENT assumes that |
| 2789 // StaticTypeWarningCode.INVALID_ASSIGNMENT has the same message. | 2788 // StaticTypeWarningCode.INVALID_ASSIGNMENT has the same message. |
| 2790 JUnitTestCase.assertEquals(HintCode.INVALID_ASSIGNMENT.message, StaticTypeWa
rningCode.INVALID_ASSIGNMENT.message); | 2789 expect(StaticTypeWarningCode.INVALID_ASSIGNMENT.message, HintCode.INVALID_AS
SIGNMENT.message); |
| 2791 } | 2790 } |
| 2792 | 2791 |
| 2793 void test_invalidAssignment_staticVariable() { | 2792 void test_invalidAssignment_staticVariable() { |
| 2794 Source source = addSource(r''' | 2793 Source source = addSource(r''' |
| 2795 class A { | 2794 class A { |
| 2796 static int x; | 2795 static int x; |
| 2797 } | 2796 } |
| 2798 f(var y) { | 2797 f(var y) { |
| 2799 if(y is String) { | 2798 if(y is String) { |
| 2800 A.x = y; | 2799 A.x = y; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2929 return a.m; | 2928 return a.m; |
| 2930 } | 2929 } |
| 2931 }'''); | 2930 }'''); |
| 2932 resolve(source); | 2931 resolve(source); |
| 2933 assertErrors(source, [HintCode.UNDEFINED_GETTER]); | 2932 assertErrors(source, [HintCode.UNDEFINED_GETTER]); |
| 2934 } | 2933 } |
| 2935 | 2934 |
| 2936 void test_undefinedGetter_message() { | 2935 void test_undefinedGetter_message() { |
| 2937 // The implementation of HintCode.UNDEFINED_SETTER assumes that UNDEFINED_SE
TTER in | 2936 // The implementation of HintCode.UNDEFINED_SETTER assumes that UNDEFINED_SE
TTER in |
| 2938 // StaticTypeWarningCode and StaticWarningCode are the same, this verifies t
hat assumption. | 2937 // StaticTypeWarningCode and StaticWarningCode are the same, this verifies t
hat assumption. |
| 2939 JUnitTestCase.assertEquals(StaticTypeWarningCode.UNDEFINED_GETTER.message, S
taticWarningCode.UNDEFINED_GETTER.message); | 2938 expect(StaticWarningCode.UNDEFINED_GETTER.message, StaticTypeWarningCode.UND
EFINED_GETTER.message); |
| 2940 } | 2939 } |
| 2941 | 2940 |
| 2942 void test_undefinedMethod() { | 2941 void test_undefinedMethod() { |
| 2943 Source source = addSource(r''' | 2942 Source source = addSource(r''' |
| 2944 f() { | 2943 f() { |
| 2945 var a = 'str'; | 2944 var a = 'str'; |
| 2946 a.notAMethodOnString(); | 2945 a.notAMethodOnString(); |
| 2947 }'''); | 2946 }'''); |
| 2948 resolve(source); | 2947 resolve(source); |
| 2949 assertErrors(source, [HintCode.UNDEFINED_METHOD]); | 2948 assertErrors(source, [HintCode.UNDEFINED_METHOD]); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3065 a.m = 0; | 3064 a.m = 0; |
| 3066 } | 3065 } |
| 3067 }'''); | 3066 }'''); |
| 3068 resolve(source); | 3067 resolve(source); |
| 3069 assertErrors(source, [HintCode.UNDEFINED_SETTER]); | 3068 assertErrors(source, [HintCode.UNDEFINED_SETTER]); |
| 3070 } | 3069 } |
| 3071 | 3070 |
| 3072 void test_undefinedSetter_message() { | 3071 void test_undefinedSetter_message() { |
| 3073 // The implementation of HintCode.UNDEFINED_SETTER assumes that UNDEFINED_SE
TTER in | 3072 // The implementation of HintCode.UNDEFINED_SETTER assumes that UNDEFINED_SE
TTER in |
| 3074 // StaticTypeWarningCode and StaticWarningCode are the same, this verifies t
hat assumption. | 3073 // StaticTypeWarningCode and StaticWarningCode are the same, this verifies t
hat assumption. |
| 3075 JUnitTestCase.assertEquals(StaticTypeWarningCode.UNDEFINED_SETTER.message, S
taticWarningCode.UNDEFINED_SETTER.message); | 3074 expect(StaticWarningCode.UNDEFINED_SETTER.message, StaticTypeWarningCode.UND
EFINED_SETTER.message); |
| 3076 } | 3075 } |
| 3077 | 3076 |
| 3078 void test_unnecessaryCast_type_supertype() { | 3077 void test_unnecessaryCast_type_supertype() { |
| 3079 Source source = addSource(r''' | 3078 Source source = addSource(r''' |
| 3080 m(int i) { | 3079 m(int i) { |
| 3081 var b = i as Object; | 3080 var b = i as Object; |
| 3082 }'''); | 3081 }'''); |
| 3083 resolve(source); | 3082 resolve(source); |
| 3084 assertErrors(source, [HintCode.UNNECESSARY_CAST]); | 3083 assertErrors(source, [HintCode.UNNECESSARY_CAST]); |
| 3085 verify([source]); | 3084 verify([source]); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3295 return a + a; | 3294 return a + a; |
| 3296 } | 3295 } |
| 3297 }'''); | 3296 }'''); |
| 3298 BlockFunctionBody body = method.body as BlockFunctionBody; | 3297 BlockFunctionBody body = method.body as BlockFunctionBody; |
| 3299 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 3298 ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| 3300 BinaryExpression expression = statement.expression as BinaryExpression; | 3299 BinaryExpression expression = statement.expression as BinaryExpression; |
| 3301 SimpleIdentifier left = expression.leftOperand as SimpleIdentifier; | 3300 SimpleIdentifier left = expression.leftOperand as SimpleIdentifier; |
| 3302 Element leftElement = left.staticElement; | 3301 Element leftElement = left.staticElement; |
| 3303 SimpleIdentifier right = expression.rightOperand as SimpleIdentifier; | 3302 SimpleIdentifier right = expression.rightOperand as SimpleIdentifier; |
| 3304 Element rightElement = right.staticElement; | 3303 Element rightElement = right.staticElement; |
| 3305 JUnitTestCase.assertNotNull(leftElement); | 3304 expect(leftElement, isNotNull); |
| 3306 JUnitTestCase.assertSame(leftElement, rightElement); | 3305 expect(rightElement, same(leftElement)); |
| 3307 } | 3306 } |
| 3308 | 3307 |
| 3309 MethodDeclaration _resolveMethod(String content) { | 3308 MethodDeclaration _resolveMethod(String content) { |
| 3310 Source source = addSource(content); | 3309 Source source = addSource(content); |
| 3311 LibraryElement library = resolve(source); | 3310 LibraryElement library = resolve(source); |
| 3312 CompilationUnit unit = resolveCompilationUnit(source, library); | 3311 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 3313 ClassDeclaration classNode = unit.declarations[0] as ClassDeclaration; | 3312 ClassDeclaration classNode = unit.declarations[0] as ClassDeclaration; |
| 3314 MethodDeclaration method = classNode.members[0] as MethodDeclaration; | 3313 MethodDeclaration method = classNode.members[0] as MethodDeclaration; |
| 3315 method.body.accept(new ResolutionEraser()); | 3314 method.body.accept(new ResolutionEraser()); |
| 3316 GatheringErrorListener errorListener = new GatheringErrorListener(); | 3315 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3352 void test_getMapOfMembersInheritedFromClasses_accessor_extends() { | 3351 void test_getMapOfMembersInheritedFromClasses_accessor_extends() { |
| 3353 // class A { int get g; } | 3352 // class A { int get g; } |
| 3354 // class B extends A {} | 3353 // class B extends A {} |
| 3355 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3354 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3356 String getterName = "g"; | 3355 String getterName = "g"; |
| 3357 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); | 3356 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); |
| 3358 classA.accessors = <PropertyAccessorElement> [getterG]; | 3357 classA.accessors = <PropertyAccessorElement> [getterG]; |
| 3359 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 3358 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 3360 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssB); | 3359 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssB); |
| 3361 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); | 3360 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); |
| 3362 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3361 expect(mapA.size, _numOfMembersInObject); |
| 3363 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapB.size); | 3362 expect(mapB.size, _numOfMembersInObject + 1); |
| 3364 JUnitTestCase.assertSame(getterG, mapB.get(getterName)); | 3363 expect(mapB.get(getterName), same(getterG)); |
| 3365 _assertNoErrors(classA); | 3364 _assertNoErrors(classA); |
| 3366 _assertNoErrors(classB); | 3365 _assertNoErrors(classB); |
| 3367 } | 3366 } |
| 3368 | 3367 |
| 3369 void test_getMapOfMembersInheritedFromClasses_accessor_implements() { | 3368 void test_getMapOfMembersInheritedFromClasses_accessor_implements() { |
| 3370 // class A { int get g; } | 3369 // class A { int get g; } |
| 3371 // class B implements A {} | 3370 // class B implements A {} |
| 3372 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3371 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3373 String getterName = "g"; | 3372 String getterName = "g"; |
| 3374 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); | 3373 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); |
| 3375 classA.accessors = <PropertyAccessorElement> [getterG]; | 3374 classA.accessors = <PropertyAccessorElement> [getterG]; |
| 3376 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 3375 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 3377 classB.interfaces = <InterfaceType> [classA.type]; | 3376 classB.interfaces = <InterfaceType> [classA.type]; |
| 3378 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssB); | 3377 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssB); |
| 3379 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); | 3378 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); |
| 3380 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3379 expect(mapA.size, _numOfMembersInObject); |
| 3381 JUnitTestCase.assertEquals(_numOfMembersInObject, mapB.size); | 3380 expect(mapB.size, _numOfMembersInObject); |
| 3382 JUnitTestCase.assertNull(mapB.get(getterName)); | 3381 expect(mapB.get(getterName), isNull); |
| 3383 _assertNoErrors(classA); | 3382 _assertNoErrors(classA); |
| 3384 _assertNoErrors(classB); | 3383 _assertNoErrors(classB); |
| 3385 } | 3384 } |
| 3386 | 3385 |
| 3387 void test_getMapOfMembersInheritedFromClasses_accessor_with() { | 3386 void test_getMapOfMembersInheritedFromClasses_accessor_with() { |
| 3388 // class A { int get g; } | 3387 // class A { int get g; } |
| 3389 // class B extends Object with A {} | 3388 // class B extends Object with A {} |
| 3390 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3389 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3391 String getterName = "g"; | 3390 String getterName = "g"; |
| 3392 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); | 3391 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); |
| 3393 classA.accessors = <PropertyAccessorElement> [getterG]; | 3392 classA.accessors = <PropertyAccessorElement> [getterG]; |
| 3394 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 3393 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 3395 classB.mixins = <InterfaceType> [classA.type]; | 3394 classB.mixins = <InterfaceType> [classA.type]; |
| 3396 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssB); | 3395 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssB); |
| 3397 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); | 3396 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); |
| 3398 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3397 expect(mapA.size, _numOfMembersInObject); |
| 3399 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapB.size); | 3398 expect(mapB.size, _numOfMembersInObject + 1); |
| 3400 JUnitTestCase.assertSame(getterG, mapB.get(getterName)); | 3399 expect(mapB.get(getterName), same(getterG)); |
| 3401 _assertNoErrors(classA); | 3400 _assertNoErrors(classA); |
| 3402 _assertNoErrors(classB); | 3401 _assertNoErrors(classB); |
| 3403 } | 3402 } |
| 3404 | 3403 |
| 3405 void test_getMapOfMembersInheritedFromClasses_implicitExtends() { | 3404 void test_getMapOfMembersInheritedFromClasses_implicitExtends() { |
| 3406 // class A {} | 3405 // class A {} |
| 3407 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3406 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3408 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); | 3407 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); |
| 3409 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3408 expect(mapA.size, _numOfMembersInObject); |
| 3410 _assertNoErrors(classA); | 3409 _assertNoErrors(classA); |
| 3411 } | 3410 } |
| 3412 | 3411 |
| 3413 void test_getMapOfMembersInheritedFromClasses_method_extends() { | 3412 void test_getMapOfMembersInheritedFromClasses_method_extends() { |
| 3414 // class A { int g(); } | 3413 // class A { int g(); } |
| 3415 // class B extends A {} | 3414 // class B extends A {} |
| 3416 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3415 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3417 String methodName = "m"; | 3416 String methodName = "m"; |
| 3418 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 3417 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 3419 classA.methods = <MethodElement> [methodM]; | 3418 classA.methods = <MethodElement> [methodM]; |
| 3420 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 3419 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 3421 classB.supertype = classA.type; | 3420 classB.supertype = classA.type; |
| 3422 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssB); | 3421 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssB); |
| 3423 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); | 3422 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); |
| 3424 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3423 expect(mapA.size, _numOfMembersInObject); |
| 3425 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapB.size); | 3424 expect(mapB.size, _numOfMembersInObject + 1); |
| 3426 JUnitTestCase.assertSame(methodM, mapB.get(methodName)); | 3425 expect(mapB.get(methodName), same(methodM)); |
| 3427 _assertNoErrors(classA); | 3426 _assertNoErrors(classA); |
| 3428 _assertNoErrors(classB); | 3427 _assertNoErrors(classB); |
| 3429 } | 3428 } |
| 3430 | 3429 |
| 3431 void test_getMapOfMembersInheritedFromClasses_method_implements() { | 3430 void test_getMapOfMembersInheritedFromClasses_method_implements() { |
| 3432 // class A { int g(); } | 3431 // class A { int g(); } |
| 3433 // class B implements A {} | 3432 // class B implements A {} |
| 3434 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3433 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3435 String methodName = "m"; | 3434 String methodName = "m"; |
| 3436 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 3435 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 3437 classA.methods = <MethodElement> [methodM]; | 3436 classA.methods = <MethodElement> [methodM]; |
| 3438 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 3437 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 3439 classB.interfaces = <InterfaceType> [classA.type]; | 3438 classB.interfaces = <InterfaceType> [classA.type]; |
| 3440 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssB); | 3439 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssB); |
| 3441 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); | 3440 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); |
| 3442 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3441 expect(mapA.size, _numOfMembersInObject); |
| 3443 JUnitTestCase.assertEquals(_numOfMembersInObject, mapB.size); | 3442 expect(mapB.size, _numOfMembersInObject); |
| 3444 JUnitTestCase.assertNull(mapB.get(methodName)); | 3443 expect(mapB.get(methodName), isNull); |
| 3445 _assertNoErrors(classA); | 3444 _assertNoErrors(classA); |
| 3446 _assertNoErrors(classB); | 3445 _assertNoErrors(classB); |
| 3447 } | 3446 } |
| 3448 | 3447 |
| 3449 void test_getMapOfMembersInheritedFromClasses_method_with() { | 3448 void test_getMapOfMembersInheritedFromClasses_method_with() { |
| 3450 // class A { int g(); } | 3449 // class A { int g(); } |
| 3451 // class B extends Object with A {} | 3450 // class B extends Object with A {} |
| 3452 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3451 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3453 String methodName = "m"; | 3452 String methodName = "m"; |
| 3454 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 3453 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 3455 classA.methods = <MethodElement> [methodM]; | 3454 classA.methods = <MethodElement> [methodM]; |
| 3456 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 3455 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 3457 classB.mixins = <InterfaceType> [classA.type]; | 3456 classB.mixins = <InterfaceType> [classA.type]; |
| 3458 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssB); | 3457 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssB); |
| 3459 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); | 3458 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromClasses(cla
ssA); |
| 3460 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3459 expect(mapA.size, _numOfMembersInObject); |
| 3461 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapB.size); | 3460 expect(mapB.size, _numOfMembersInObject + 1); |
| 3462 JUnitTestCase.assertSame(methodM, mapB.get(methodName)); | 3461 expect(mapB.get(methodName), same(methodM)); |
| 3463 _assertNoErrors(classA); | 3462 _assertNoErrors(classA); |
| 3464 _assertNoErrors(classB); | 3463 _assertNoErrors(classB); |
| 3465 } | 3464 } |
| 3466 | 3465 |
| 3467 void test_getMapOfMembersInheritedFromInterfaces_accessor_extends() { | 3466 void test_getMapOfMembersInheritedFromInterfaces_accessor_extends() { |
| 3468 // class A { int get g; } | 3467 // class A { int get g; } |
| 3469 // class B extends A {} | 3468 // class B extends A {} |
| 3470 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3469 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3471 String getterName = "g"; | 3470 String getterName = "g"; |
| 3472 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); | 3471 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); |
| 3473 classA.accessors = <PropertyAccessorElement> [getterG]; | 3472 classA.accessors = <PropertyAccessorElement> [getterG]; |
| 3474 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 3473 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 3475 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classB); | 3474 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classB); |
| 3476 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3475 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3477 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3476 expect(mapA.size, _numOfMembersInObject); |
| 3478 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapB.size); | 3477 expect(mapB.size, _numOfMembersInObject + 1); |
| 3479 JUnitTestCase.assertSame(getterG, mapB.get(getterName)); | 3478 expect(mapB.get(getterName), same(getterG)); |
| 3480 _assertNoErrors(classA); | 3479 _assertNoErrors(classA); |
| 3481 _assertNoErrors(classB); | 3480 _assertNoErrors(classB); |
| 3482 } | 3481 } |
| 3483 | 3482 |
| 3484 void test_getMapOfMembersInheritedFromInterfaces_accessor_implements() { | 3483 void test_getMapOfMembersInheritedFromInterfaces_accessor_implements() { |
| 3485 // class A { int get g; } | 3484 // class A { int get g; } |
| 3486 // class B implements A {} | 3485 // class B implements A {} |
| 3487 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3486 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3488 String getterName = "g"; | 3487 String getterName = "g"; |
| 3489 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); | 3488 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); |
| 3490 classA.accessors = <PropertyAccessorElement> [getterG]; | 3489 classA.accessors = <PropertyAccessorElement> [getterG]; |
| 3491 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 3490 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 3492 classB.interfaces = <InterfaceType> [classA.type]; | 3491 classB.interfaces = <InterfaceType> [classA.type]; |
| 3493 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classB); | 3492 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classB); |
| 3494 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3493 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3495 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3494 expect(mapA.size, _numOfMembersInObject); |
| 3496 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapB.size); | 3495 expect(mapB.size, _numOfMembersInObject + 1); |
| 3497 JUnitTestCase.assertSame(getterG, mapB.get(getterName)); | 3496 expect(mapB.get(getterName), same(getterG)); |
| 3498 _assertNoErrors(classA); | 3497 _assertNoErrors(classA); |
| 3499 _assertNoErrors(classB); | 3498 _assertNoErrors(classB); |
| 3500 } | 3499 } |
| 3501 | 3500 |
| 3502 void test_getMapOfMembersInheritedFromInterfaces_accessor_with() { | 3501 void test_getMapOfMembersInheritedFromInterfaces_accessor_with() { |
| 3503 // class A { int get g; } | 3502 // class A { int get g; } |
| 3504 // class B extends Object with A {} | 3503 // class B extends Object with A {} |
| 3505 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3504 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3506 String getterName = "g"; | 3505 String getterName = "g"; |
| 3507 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); | 3506 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); |
| 3508 classA.accessors = <PropertyAccessorElement> [getterG]; | 3507 classA.accessors = <PropertyAccessorElement> [getterG]; |
| 3509 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 3508 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 3510 classB.mixins = <InterfaceType> [classA.type]; | 3509 classB.mixins = <InterfaceType> [classA.type]; |
| 3511 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classB); | 3510 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classB); |
| 3512 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3511 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3513 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3512 expect(mapA.size, _numOfMembersInObject); |
| 3514 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapB.size); | 3513 expect(mapB.size, _numOfMembersInObject + 1); |
| 3515 JUnitTestCase.assertSame(getterG, mapB.get(getterName)); | 3514 expect(mapB.get(getterName), same(getterG)); |
| 3516 _assertNoErrors(classA); | 3515 _assertNoErrors(classA); |
| 3517 _assertNoErrors(classB); | 3516 _assertNoErrors(classB); |
| 3518 } | 3517 } |
| 3519 | 3518 |
| 3520 void test_getMapOfMembersInheritedFromInterfaces_implicitExtends() { | 3519 void test_getMapOfMembersInheritedFromInterfaces_implicitExtends() { |
| 3521 // class A {} | 3520 // class A {} |
| 3522 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3521 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3523 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3522 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3524 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3523 expect(mapA.size, _numOfMembersInObject); |
| 3525 _assertNoErrors(classA); | 3524 _assertNoErrors(classA); |
| 3526 } | 3525 } |
| 3527 | 3526 |
| 3528 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_getter_method() { | 3527 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_getter_method() { |
| 3529 // class I1 { int m(); } | 3528 // class I1 { int m(); } |
| 3530 // class I2 { int get m; } | 3529 // class I2 { int get m; } |
| 3531 // class A implements I2, I1 {} | 3530 // class A implements I2, I1 {} |
| 3532 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3531 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3533 String methodName = "m"; | 3532 String methodName = "m"; |
| 3534 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 3533 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 3535 classI1.methods = <MethodElement> [methodM]; | 3534 classI1.methods = <MethodElement> [methodM]; |
| 3536 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); | 3535 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); |
| 3537 PropertyAccessorElement getter = ElementFactory.getterElement(methodName, fa
lse, _typeProvider.intType); | 3536 PropertyAccessorElement getter = ElementFactory.getterElement(methodName, fa
lse, _typeProvider.intType); |
| 3538 classI2.accessors = <PropertyAccessorElement> [getter]; | 3537 classI2.accessors = <PropertyAccessorElement> [getter]; |
| 3539 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3538 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3540 classA.interfaces = <InterfaceType> [classI2.type, classI1.type]; | 3539 classA.interfaces = <InterfaceType> [classI2.type, classI1.type]; |
| 3541 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3540 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3542 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3541 expect(mapA.size, _numOfMembersInObject); |
| 3543 JUnitTestCase.assertNull(mapA.get(methodName)); | 3542 expect(mapA.get(methodName), isNull); |
| 3544 _assertErrors(classA, [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GET
TER_AND_METHOD]); | 3543 _assertErrors(classA, [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GET
TER_AND_METHOD]); |
| 3545 } | 3544 } |
| 3546 | 3545 |
| 3547 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_int_str() { | 3546 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_int_str() { |
| 3548 // class I1 { int m(); } | 3547 // class I1 { int m(); } |
| 3549 // class I2 { String m(); } | 3548 // class I2 { String m(); } |
| 3550 // class A implements I1, I2 {} | 3549 // class A implements I1, I2 {} |
| 3551 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3550 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3552 String methodName = "m"; | 3551 String methodName = "m"; |
| 3553 MethodElement methodM1 = ElementFactory.methodElement(methodName, null, [_ty
peProvider.intType]); | 3552 MethodElement methodM1 = ElementFactory.methodElement(methodName, null, [_ty
peProvider.intType]); |
| 3554 classI1.methods = <MethodElement> [methodM1]; | 3553 classI1.methods = <MethodElement> [methodM1]; |
| 3555 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); | 3554 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); |
| 3556 MethodElement methodM2 = ElementFactory.methodElement(methodName, null, [_ty
peProvider.stringType]); | 3555 MethodElement methodM2 = ElementFactory.methodElement(methodName, null, [_ty
peProvider.stringType]); |
| 3557 classI2.methods = <MethodElement> [methodM2]; | 3556 classI2.methods = <MethodElement> [methodM2]; |
| 3558 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3557 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3559 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; | 3558 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; |
| 3560 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3559 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3561 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3560 expect(mapA.size, _numOfMembersInObject); |
| 3562 JUnitTestCase.assertNull(mapA.get(methodName)); | 3561 expect(mapA.get(methodName), isNull); |
| 3563 _assertErrors(classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE
]); | 3562 _assertErrors(classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE
]); |
| 3564 } | 3563 } |
| 3565 | 3564 |
| 3566 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_method_getter() { | 3565 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_method_getter() { |
| 3567 // class I1 { int m(); } | 3566 // class I1 { int m(); } |
| 3568 // class I2 { int get m; } | 3567 // class I2 { int get m; } |
| 3569 // class A implements I1, I2 {} | 3568 // class A implements I1, I2 {} |
| 3570 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3569 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3571 String methodName = "m"; | 3570 String methodName = "m"; |
| 3572 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 3571 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 3573 classI1.methods = <MethodElement> [methodM]; | 3572 classI1.methods = <MethodElement> [methodM]; |
| 3574 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); | 3573 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); |
| 3575 PropertyAccessorElement getter = ElementFactory.getterElement(methodName, fa
lse, _typeProvider.intType); | 3574 PropertyAccessorElement getter = ElementFactory.getterElement(methodName, fa
lse, _typeProvider.intType); |
| 3576 classI2.accessors = <PropertyAccessorElement> [getter]; | 3575 classI2.accessors = <PropertyAccessorElement> [getter]; |
| 3577 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3576 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3578 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; | 3577 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; |
| 3579 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3578 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3580 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3579 expect(mapA.size, _numOfMembersInObject); |
| 3581 JUnitTestCase.assertNull(mapA.get(methodName)); | 3580 expect(mapA.get(methodName), isNull); |
| 3582 _assertErrors(classA, [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GET
TER_AND_METHOD]); | 3581 _assertErrors(classA, [StaticWarningCode.INCONSISTENT_METHOD_INHERITANCE_GET
TER_AND_METHOD]); |
| 3583 } | 3582 } |
| 3584 | 3583 |
| 3585 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_numOfRequiredParams() { | 3584 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_numOfRequiredParams() { |
| 3586 // class I1 { dynamic m(int, [int]); } | 3585 // class I1 { dynamic m(int, [int]); } |
| 3587 // class I2 { dynamic m(int, int, int); } | 3586 // class I2 { dynamic m(int, int, int); } |
| 3588 // class A implements I1, I2 {} | 3587 // class A implements I1, I2 {} |
| 3589 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3588 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3590 String methodName = "m"; | 3589 String methodName = "m"; |
| 3591 MethodElementImpl methodM1 = ElementFactory.methodElement(methodName, _typeP
rovider.dynamicType, []); | 3590 MethodElementImpl methodM1 = ElementFactory.methodElement(methodName, _typeP
rovider.dynamicType, []); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3606 parameter4.type = _typeProvider.intType; | 3605 parameter4.type = _typeProvider.intType; |
| 3607 parameter4.parameterKind = ParameterKind.REQUIRED; | 3606 parameter4.parameterKind = ParameterKind.REQUIRED; |
| 3608 ParameterElementImpl parameter5 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a5")); | 3607 ParameterElementImpl parameter5 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a5")); |
| 3609 parameter5.type = _typeProvider.intType; | 3608 parameter5.type = _typeProvider.intType; |
| 3610 parameter5.parameterKind = ParameterKind.REQUIRED; | 3609 parameter5.parameterKind = ParameterKind.REQUIRED; |
| 3611 methodM2.parameters = <ParameterElement> [parameter3, parameter4, parameter5
]; | 3610 methodM2.parameters = <ParameterElement> [parameter3, parameter4, parameter5
]; |
| 3612 classI2.methods = <MethodElement> [methodM2]; | 3611 classI2.methods = <MethodElement> [methodM2]; |
| 3613 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3612 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3614 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; | 3613 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; |
| 3615 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3614 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3616 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3615 expect(mapA.size, _numOfMembersInObject); |
| 3617 JUnitTestCase.assertNull(mapA.get(methodName)); | 3616 expect(mapA.get(methodName), isNull); |
| 3618 _assertErrors(classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE
]); | 3617 _assertErrors(classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE
]); |
| 3619 } | 3618 } |
| 3620 | 3619 |
| 3621 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_str_int() { | 3620 void test_getMapOfMembersInheritedFromInterfaces_inconsistentMethodInheritance
_str_int() { |
| 3622 // class I1 { int m(); } | 3621 // class I1 { int m(); } |
| 3623 // class I2 { String m(); } | 3622 // class I2 { String m(); } |
| 3624 // class A implements I2, I1 {} | 3623 // class A implements I2, I1 {} |
| 3625 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3624 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3626 String methodName = "m"; | 3625 String methodName = "m"; |
| 3627 MethodElement methodM1 = ElementFactory.methodElement(methodName, null, [_ty
peProvider.stringType]); | 3626 MethodElement methodM1 = ElementFactory.methodElement(methodName, null, [_ty
peProvider.stringType]); |
| 3628 classI1.methods = <MethodElement> [methodM1]; | 3627 classI1.methods = <MethodElement> [methodM1]; |
| 3629 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); | 3628 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); |
| 3630 MethodElement methodM2 = ElementFactory.methodElement(methodName, null, [_ty
peProvider.intType]); | 3629 MethodElement methodM2 = ElementFactory.methodElement(methodName, null, [_ty
peProvider.intType]); |
| 3631 classI2.methods = <MethodElement> [methodM2]; | 3630 classI2.methods = <MethodElement> [methodM2]; |
| 3632 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3631 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3633 classA.interfaces = <InterfaceType> [classI2.type, classI1.type]; | 3632 classA.interfaces = <InterfaceType> [classI2.type, classI1.type]; |
| 3634 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3633 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3635 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3634 expect(mapA.size, _numOfMembersInObject); |
| 3636 JUnitTestCase.assertNull(mapA.get(methodName)); | 3635 expect(mapA.get(methodName), isNull); |
| 3637 _assertErrors(classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE
]); | 3636 _assertErrors(classA, [StaticTypeWarningCode.INCONSISTENT_METHOD_INHERITANCE
]); |
| 3638 } | 3637 } |
| 3639 | 3638 |
| 3640 void test_getMapOfMembersInheritedFromInterfaces_method_extends() { | 3639 void test_getMapOfMembersInheritedFromInterfaces_method_extends() { |
| 3641 // class A { int g(); } | 3640 // class A { int g(); } |
| 3642 // class B extends A {} | 3641 // class B extends A {} |
| 3643 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3642 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3644 String methodName = "m"; | 3643 String methodName = "m"; |
| 3645 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 3644 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 3646 classA.methods = <MethodElement> [methodM]; | 3645 classA.methods = <MethodElement> [methodM]; |
| 3647 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 3646 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 3648 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classB); | 3647 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classB); |
| 3649 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3648 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3650 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3649 expect(mapA.size, _numOfMembersInObject); |
| 3651 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapB.size); | 3650 expect(mapB.size, _numOfMembersInObject + 1); |
| 3652 JUnitTestCase.assertSame(methodM, mapB.get(methodName)); | 3651 expect(mapB.get(methodName), same(methodM)); |
| 3653 _assertNoErrors(classA); | 3652 _assertNoErrors(classA); |
| 3654 _assertNoErrors(classB); | 3653 _assertNoErrors(classB); |
| 3655 } | 3654 } |
| 3656 | 3655 |
| 3657 void test_getMapOfMembersInheritedFromInterfaces_method_implements() { | 3656 void test_getMapOfMembersInheritedFromInterfaces_method_implements() { |
| 3658 // class A { int g(); } | 3657 // class A { int g(); } |
| 3659 // class B implements A {} | 3658 // class B implements A {} |
| 3660 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3659 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3661 String methodName = "m"; | 3660 String methodName = "m"; |
| 3662 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 3661 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 3663 classA.methods = <MethodElement> [methodM]; | 3662 classA.methods = <MethodElement> [methodM]; |
| 3664 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 3663 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 3665 classB.interfaces = <InterfaceType> [classA.type]; | 3664 classB.interfaces = <InterfaceType> [classA.type]; |
| 3666 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classB); | 3665 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classB); |
| 3667 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3666 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3668 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3667 expect(mapA.size, _numOfMembersInObject); |
| 3669 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapB.size); | 3668 expect(mapB.size, _numOfMembersInObject + 1); |
| 3670 JUnitTestCase.assertSame(methodM, mapB.get(methodName)); | 3669 expect(mapB.get(methodName), same(methodM)); |
| 3671 _assertNoErrors(classA); | 3670 _assertNoErrors(classA); |
| 3672 _assertNoErrors(classB); | 3671 _assertNoErrors(classB); |
| 3673 } | 3672 } |
| 3674 | 3673 |
| 3675 void test_getMapOfMembersInheritedFromInterfaces_method_with() { | 3674 void test_getMapOfMembersInheritedFromInterfaces_method_with() { |
| 3676 // class A { int g(); } | 3675 // class A { int g(); } |
| 3677 // class B extends Object with A {} | 3676 // class B extends Object with A {} |
| 3678 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3677 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3679 String methodName = "m"; | 3678 String methodName = "m"; |
| 3680 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 3679 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 3681 classA.methods = <MethodElement> [methodM]; | 3680 classA.methods = <MethodElement> [methodM]; |
| 3682 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 3681 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 3683 classB.mixins = <InterfaceType> [classA.type]; | 3682 classB.mixins = <InterfaceType> [classA.type]; |
| 3684 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classB); | 3683 MemberMap mapB = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classB); |
| 3685 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3684 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3686 JUnitTestCase.assertEquals(_numOfMembersInObject, mapA.size); | 3685 expect(mapA.size, _numOfMembersInObject); |
| 3687 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapB.size); | 3686 expect(mapB.size, _numOfMembersInObject + 1); |
| 3688 JUnitTestCase.assertSame(methodM, mapB.get(methodName)); | 3687 expect(mapB.get(methodName), same(methodM)); |
| 3689 _assertNoErrors(classA); | 3688 _assertNoErrors(classA); |
| 3690 _assertNoErrors(classB); | 3689 _assertNoErrors(classB); |
| 3691 } | 3690 } |
| 3692 | 3691 |
| 3693 void test_getMapOfMembersInheritedFromInterfaces_union_differentNames() { | 3692 void test_getMapOfMembersInheritedFromInterfaces_union_differentNames() { |
| 3694 // class I1 { int m1(); } | 3693 // class I1 { int m1(); } |
| 3695 // class I2 { int m2(); } | 3694 // class I2 { int m2(); } |
| 3696 // class A implements I1, I2 {} | 3695 // class A implements I1, I2 {} |
| 3697 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3696 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3698 String methodName1 = "m1"; | 3697 String methodName1 = "m1"; |
| 3699 MethodElement methodM1 = ElementFactory.methodElement(methodName1, _typeProv
ider.intType, []); | 3698 MethodElement methodM1 = ElementFactory.methodElement(methodName1, _typeProv
ider.intType, []); |
| 3700 classI1.methods = <MethodElement> [methodM1]; | 3699 classI1.methods = <MethodElement> [methodM1]; |
| 3701 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); | 3700 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); |
| 3702 String methodName2 = "m2"; | 3701 String methodName2 = "m2"; |
| 3703 MethodElement methodM2 = ElementFactory.methodElement(methodName2, _typeProv
ider.intType, []); | 3702 MethodElement methodM2 = ElementFactory.methodElement(methodName2, _typeProv
ider.intType, []); |
| 3704 classI2.methods = <MethodElement> [methodM2]; | 3703 classI2.methods = <MethodElement> [methodM2]; |
| 3705 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3704 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3706 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; | 3705 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; |
| 3707 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3706 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3708 JUnitTestCase.assertEquals(_numOfMembersInObject + 2, mapA.size); | 3707 expect(mapA.size, _numOfMembersInObject + 2); |
| 3709 JUnitTestCase.assertSame(methodM1, mapA.get(methodName1)); | 3708 expect(mapA.get(methodName1), same(methodM1)); |
| 3710 JUnitTestCase.assertSame(methodM2, mapA.get(methodName2)); | 3709 expect(mapA.get(methodName2), same(methodM2)); |
| 3711 _assertNoErrors(classA); | 3710 _assertNoErrors(classA); |
| 3712 } | 3711 } |
| 3713 | 3712 |
| 3714 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_gett
ers() { | 3713 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_gett
ers() { |
| 3715 // class I1 { int get g; } | 3714 // class I1 { int get g; } |
| 3716 // class I2 { num get g; } | 3715 // class I2 { num get g; } |
| 3717 // class A implements I1, I2 {} | 3716 // class A implements I1, I2 {} |
| 3718 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3717 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3719 String accessorName = "g"; | 3718 String accessorName = "g"; |
| 3720 PropertyAccessorElement getter1 = ElementFactory.getterElement(accessorName,
false, _typeProvider.intType); | 3719 PropertyAccessorElement getter1 = ElementFactory.getterElement(accessorName,
false, _typeProvider.intType); |
| 3721 classI1.accessors = <PropertyAccessorElement> [getter1]; | 3720 classI1.accessors = <PropertyAccessorElement> [getter1]; |
| 3722 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); | 3721 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); |
| 3723 PropertyAccessorElement getter2 = ElementFactory.getterElement(accessorName,
false, _typeProvider.numType); | 3722 PropertyAccessorElement getter2 = ElementFactory.getterElement(accessorName,
false, _typeProvider.numType); |
| 3724 classI2.accessors = <PropertyAccessorElement> [getter2]; | 3723 classI2.accessors = <PropertyAccessorElement> [getter2]; |
| 3725 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3724 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3726 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; | 3725 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; |
| 3727 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3726 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3728 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapA.size); | 3727 expect(mapA.size, _numOfMembersInObject + 1); |
| 3729 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(acc
essorName, false, _typeProvider.dynamicType); | 3728 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(acc
essorName, false, _typeProvider.dynamicType); |
| 3730 JUnitTestCase.assertEquals(syntheticAccessor.type, mapA.get(accessorName).ty
pe); | 3729 expect(mapA.get(accessorName).type, syntheticAccessor.type); |
| 3731 _assertNoErrors(classA); | 3730 _assertNoErrors(classA); |
| 3732 } | 3731 } |
| 3733 | 3732 |
| 3734 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_meth
ods() { | 3733 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_meth
ods() { |
| 3735 // class I1 { dynamic m(int); } | 3734 // class I1 { dynamic m(int); } |
| 3736 // class I2 { dynamic m(num); } | 3735 // class I2 { dynamic m(num); } |
| 3737 // class A implements I1, I2 {} | 3736 // class A implements I1, I2 {} |
| 3738 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3737 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3739 String methodName = "m"; | 3738 String methodName = "m"; |
| 3740 MethodElementImpl methodM1 = ElementFactory.methodElement(methodName, _typeP
rovider.dynamicType, []); | 3739 MethodElementImpl methodM1 = ElementFactory.methodElement(methodName, _typeP
rovider.dynamicType, []); |
| 3741 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a0")); | 3740 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a0")); |
| 3742 parameter1.type = _typeProvider.intType; | 3741 parameter1.type = _typeProvider.intType; |
| 3743 parameter1.parameterKind = ParameterKind.REQUIRED; | 3742 parameter1.parameterKind = ParameterKind.REQUIRED; |
| 3744 methodM1.parameters = <ParameterElement> [parameter1]; | 3743 methodM1.parameters = <ParameterElement> [parameter1]; |
| 3745 classI1.methods = <MethodElement> [methodM1]; | 3744 classI1.methods = <MethodElement> [methodM1]; |
| 3746 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); | 3745 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); |
| 3747 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP
rovider.dynamicType, []); | 3746 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP
rovider.dynamicType, []); |
| 3748 ParameterElementImpl parameter2 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a0")); | 3747 ParameterElementImpl parameter2 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a0")); |
| 3749 parameter2.type = _typeProvider.numType; | 3748 parameter2.type = _typeProvider.numType; |
| 3750 parameter2.parameterKind = ParameterKind.REQUIRED; | 3749 parameter2.parameterKind = ParameterKind.REQUIRED; |
| 3751 methodM2.parameters = <ParameterElement> [parameter2]; | 3750 methodM2.parameters = <ParameterElement> [parameter2]; |
| 3752 classI2.methods = <MethodElement> [methodM2]; | 3751 classI2.methods = <MethodElement> [methodM2]; |
| 3753 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3752 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3754 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; | 3753 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; |
| 3755 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3754 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3756 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapA.size); | 3755 expect(mapA.size, _numOfMembersInObject + 1); |
| 3757 MethodElement syntheticMethod = ElementFactory.methodElement(methodName, _ty
peProvider.dynamicType, [_typeProvider.dynamicType]); | 3756 MethodElement syntheticMethod = ElementFactory.methodElement(methodName, _ty
peProvider.dynamicType, [_typeProvider.dynamicType]); |
| 3758 JUnitTestCase.assertEquals(syntheticMethod.type, mapA.get(methodName).type); | 3757 expect(mapA.get(methodName).type, syntheticMethod.type); |
| 3759 _assertNoErrors(classA); | 3758 _assertNoErrors(classA); |
| 3760 } | 3759 } |
| 3761 | 3760 |
| 3762 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_sett
ers() { | 3761 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_2_sett
ers() { |
| 3763 // class I1 { set s(int); } | 3762 // class I1 { set s(int); } |
| 3764 // class I2 { set s(num); } | 3763 // class I2 { set s(num); } |
| 3765 // class A implements I1, I2 {} | 3764 // class A implements I1, I2 {} |
| 3766 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3765 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3767 String accessorName = "s"; | 3766 String accessorName = "s"; |
| 3768 PropertyAccessorElement setter1 = ElementFactory.setterElement(accessorName,
false, _typeProvider.intType); | 3767 PropertyAccessorElement setter1 = ElementFactory.setterElement(accessorName,
false, _typeProvider.intType); |
| 3769 classI1.accessors = <PropertyAccessorElement> [setter1]; | 3768 classI1.accessors = <PropertyAccessorElement> [setter1]; |
| 3770 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); | 3769 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); |
| 3771 PropertyAccessorElement setter2 = ElementFactory.setterElement(accessorName,
false, _typeProvider.numType); | 3770 PropertyAccessorElement setter2 = ElementFactory.setterElement(accessorName,
false, _typeProvider.numType); |
| 3772 classI2.accessors = <PropertyAccessorElement> [setter2]; | 3771 classI2.accessors = <PropertyAccessorElement> [setter2]; |
| 3773 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3772 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3774 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; | 3773 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; |
| 3775 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3774 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3776 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapA.size); | 3775 expect(mapA.size, _numOfMembersInObject + 1); |
| 3777 PropertyAccessorElementImpl syntheticAccessor = ElementFactory.setterElement
(accessorName, false, _typeProvider.dynamicType); | 3776 PropertyAccessorElementImpl syntheticAccessor = ElementFactory.setterElement
(accessorName, false, _typeProvider.dynamicType); |
| 3778 syntheticAccessor.returnType = _typeProvider.dynamicType; | 3777 syntheticAccessor.returnType = _typeProvider.dynamicType; |
| 3779 JUnitTestCase.assertEquals(syntheticAccessor.type, mapA.get("$accessorName="
).type); | 3778 expect(mapA.get("$accessorName=").type, syntheticAccessor.type); |
| 3780 _assertNoErrors(classA); | 3779 _assertNoErrors(classA); |
| 3781 } | 3780 } |
| 3782 | 3781 |
| 3783 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_gett
ers() { | 3782 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_gett
ers() { |
| 3784 // class A {} | 3783 // class A {} |
| 3785 // class B extends A {} | 3784 // class B extends A {} |
| 3786 // class C extends B {} | 3785 // class C extends B {} |
| 3787 // class I1 { A get g; } | 3786 // class I1 { A get g; } |
| 3788 // class I2 { B get g; } | 3787 // class I2 { B get g; } |
| 3789 // class I3 { C get g; } | 3788 // class I3 { C get g; } |
| 3790 // class D implements I1, I2, I3 {} | 3789 // class D implements I1, I2, I3 {} |
| 3791 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3790 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3792 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 3791 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 3793 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); | 3792 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); |
| 3794 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3793 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3795 String accessorName = "g"; | 3794 String accessorName = "g"; |
| 3796 PropertyAccessorElement getter1 = ElementFactory.getterElement(accessorName,
false, classA.type); | 3795 PropertyAccessorElement getter1 = ElementFactory.getterElement(accessorName,
false, classA.type); |
| 3797 classI1.accessors = <PropertyAccessorElement> [getter1]; | 3796 classI1.accessors = <PropertyAccessorElement> [getter1]; |
| 3798 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); | 3797 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); |
| 3799 PropertyAccessorElement getter2 = ElementFactory.getterElement(accessorName,
false, classB.type); | 3798 PropertyAccessorElement getter2 = ElementFactory.getterElement(accessorName,
false, classB.type); |
| 3800 classI2.accessors = <PropertyAccessorElement> [getter2]; | 3799 classI2.accessors = <PropertyAccessorElement> [getter2]; |
| 3801 ClassElementImpl classI3 = ElementFactory.classElement2("I3", []); | 3800 ClassElementImpl classI3 = ElementFactory.classElement2("I3", []); |
| 3802 PropertyAccessorElement getter3 = ElementFactory.getterElement(accessorName,
false, classC.type); | 3801 PropertyAccessorElement getter3 = ElementFactory.getterElement(accessorName,
false, classC.type); |
| 3803 classI3.accessors = <PropertyAccessorElement> [getter3]; | 3802 classI3.accessors = <PropertyAccessorElement> [getter3]; |
| 3804 ClassElementImpl classD = ElementFactory.classElement2("D", []); | 3803 ClassElementImpl classD = ElementFactory.classElement2("D", []); |
| 3805 classD.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ
e]; | 3804 classD.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ
e]; |
| 3806 MemberMap mapD = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classD); | 3805 MemberMap mapD = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classD); |
| 3807 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapD.size); | 3806 expect(mapD.size, _numOfMembersInObject + 1); |
| 3808 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(acc
essorName, false, _typeProvider.dynamicType); | 3807 PropertyAccessorElement syntheticAccessor = ElementFactory.getterElement(acc
essorName, false, _typeProvider.dynamicType); |
| 3809 JUnitTestCase.assertEquals(syntheticAccessor.type, mapD.get(accessorName).ty
pe); | 3808 expect(mapD.get(accessorName).type, syntheticAccessor.type); |
| 3810 _assertNoErrors(classD); | 3809 _assertNoErrors(classD); |
| 3811 } | 3810 } |
| 3812 | 3811 |
| 3813 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_meth
ods() { | 3812 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_meth
ods() { |
| 3814 // class A {} | 3813 // class A {} |
| 3815 // class B extends A {} | 3814 // class B extends A {} |
| 3816 // class C extends B {} | 3815 // class C extends B {} |
| 3817 // class I1 { dynamic m(A a); } | 3816 // class I1 { dynamic m(A a); } |
| 3818 // class I2 { dynamic m(B b); } | 3817 // class I2 { dynamic m(B b); } |
| 3819 // class I3 { dynamic m(C c); } | 3818 // class I3 { dynamic m(C c); } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3839 ClassElementImpl classI3 = ElementFactory.classElement2("I3", []); | 3838 ClassElementImpl classI3 = ElementFactory.classElement2("I3", []); |
| 3840 MethodElementImpl methodM3 = ElementFactory.methodElement(methodName, _typeP
rovider.dynamicType, []); | 3839 MethodElementImpl methodM3 = ElementFactory.methodElement(methodName, _typeP
rovider.dynamicType, []); |
| 3841 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a0")); | 3840 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a0")); |
| 3842 parameter3.type = classC.type; | 3841 parameter3.type = classC.type; |
| 3843 parameter3.parameterKind = ParameterKind.REQUIRED; | 3842 parameter3.parameterKind = ParameterKind.REQUIRED; |
| 3844 methodM3.parameters = <ParameterElement> [parameter3]; | 3843 methodM3.parameters = <ParameterElement> [parameter3]; |
| 3845 classI3.methods = <MethodElement> [methodM3]; | 3844 classI3.methods = <MethodElement> [methodM3]; |
| 3846 ClassElementImpl classD = ElementFactory.classElement2("D", []); | 3845 ClassElementImpl classD = ElementFactory.classElement2("D", []); |
| 3847 classD.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ
e]; | 3846 classD.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ
e]; |
| 3848 MemberMap mapD = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classD); | 3847 MemberMap mapD = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classD); |
| 3849 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapD.size); | 3848 expect(mapD.size, _numOfMembersInObject + 1); |
| 3850 MethodElement syntheticMethod = ElementFactory.methodElement(methodName, _ty
peProvider.dynamicType, [_typeProvider.dynamicType]); | 3849 MethodElement syntheticMethod = ElementFactory.methodElement(methodName, _ty
peProvider.dynamicType, [_typeProvider.dynamicType]); |
| 3851 JUnitTestCase.assertEquals(syntheticMethod.type, mapD.get(methodName).type); | 3850 expect(mapD.get(methodName).type, syntheticMethod.type); |
| 3852 _assertNoErrors(classD); | 3851 _assertNoErrors(classD); |
| 3853 } | 3852 } |
| 3854 | 3853 |
| 3855 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_sett
ers() { | 3854 void test_getMapOfMembersInheritedFromInterfaces_union_multipleSubtypes_3_sett
ers() { |
| 3856 // class A {} | 3855 // class A {} |
| 3857 // class B extends A {} | 3856 // class B extends A {} |
| 3858 // class C extends B {} | 3857 // class C extends B {} |
| 3859 // class I1 { set s(A); } | 3858 // class I1 { set s(A); } |
| 3860 // class I2 { set s(B); } | 3859 // class I2 { set s(B); } |
| 3861 // class I3 { set s(C); } | 3860 // class I3 { set s(C); } |
| 3862 // class D implements I1, I2, I3 {} | 3861 // class D implements I1, I2, I3 {} |
| 3863 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3862 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3864 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 3863 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 3865 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); | 3864 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); |
| 3866 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3865 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3867 String accessorName = "s"; | 3866 String accessorName = "s"; |
| 3868 PropertyAccessorElement setter1 = ElementFactory.setterElement(accessorName,
false, classA.type); | 3867 PropertyAccessorElement setter1 = ElementFactory.setterElement(accessorName,
false, classA.type); |
| 3869 classI1.accessors = <PropertyAccessorElement> [setter1]; | 3868 classI1.accessors = <PropertyAccessorElement> [setter1]; |
| 3870 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); | 3869 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); |
| 3871 PropertyAccessorElement setter2 = ElementFactory.setterElement(accessorName,
false, classB.type); | 3870 PropertyAccessorElement setter2 = ElementFactory.setterElement(accessorName,
false, classB.type); |
| 3872 classI2.accessors = <PropertyAccessorElement> [setter2]; | 3871 classI2.accessors = <PropertyAccessorElement> [setter2]; |
| 3873 ClassElementImpl classI3 = ElementFactory.classElement2("I3", []); | 3872 ClassElementImpl classI3 = ElementFactory.classElement2("I3", []); |
| 3874 PropertyAccessorElement setter3 = ElementFactory.setterElement(accessorName,
false, classC.type); | 3873 PropertyAccessorElement setter3 = ElementFactory.setterElement(accessorName,
false, classC.type); |
| 3875 classI3.accessors = <PropertyAccessorElement> [setter3]; | 3874 classI3.accessors = <PropertyAccessorElement> [setter3]; |
| 3876 ClassElementImpl classD = ElementFactory.classElement2("D", []); | 3875 ClassElementImpl classD = ElementFactory.classElement2("D", []); |
| 3877 classD.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ
e]; | 3876 classD.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ
e]; |
| 3878 MemberMap mapD = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classD); | 3877 MemberMap mapD = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classD); |
| 3879 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapD.size); | 3878 expect(mapD.size, _numOfMembersInObject + 1); |
| 3880 PropertyAccessorElementImpl syntheticAccessor = ElementFactory.setterElement
(accessorName, false, _typeProvider.dynamicType); | 3879 PropertyAccessorElementImpl syntheticAccessor = ElementFactory.setterElement
(accessorName, false, _typeProvider.dynamicType); |
| 3881 syntheticAccessor.returnType = _typeProvider.dynamicType; | 3880 syntheticAccessor.returnType = _typeProvider.dynamicType; |
| 3882 JUnitTestCase.assertEquals(syntheticAccessor.type, mapD.get("$accessorName="
).type); | 3881 expect(mapD.get("$accessorName=").type, syntheticAccessor.type); |
| 3883 _assertNoErrors(classD); | 3882 _assertNoErrors(classD); |
| 3884 } | 3883 } |
| 3885 | 3884 |
| 3886 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_2_methods()
{ | 3885 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_2_methods()
{ |
| 3887 // class I1 { int m(); } | 3886 // class I1 { int m(); } |
| 3888 // class I2 { int m([int]); } | 3887 // class I2 { int m([int]); } |
| 3889 // class A implements I1, I2 {} | 3888 // class A implements I1, I2 {} |
| 3890 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3889 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3891 String methodName = "m"; | 3890 String methodName = "m"; |
| 3892 MethodElement methodM1 = ElementFactory.methodElement(methodName, _typeProvi
der.intType, []); | 3891 MethodElement methodM1 = ElementFactory.methodElement(methodName, _typeProvi
der.intType, []); |
| 3893 classI1.methods = <MethodElement> [methodM1]; | 3892 classI1.methods = <MethodElement> [methodM1]; |
| 3894 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); | 3893 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); |
| 3895 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP
rovider.intType, []); | 3894 MethodElementImpl methodM2 = ElementFactory.methodElement(methodName, _typeP
rovider.intType, []); |
| 3896 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a1")); | 3895 ParameterElementImpl parameter1 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a1")); |
| 3897 parameter1.type = _typeProvider.intType; | 3896 parameter1.type = _typeProvider.intType; |
| 3898 parameter1.parameterKind = ParameterKind.POSITIONAL; | 3897 parameter1.parameterKind = ParameterKind.POSITIONAL; |
| 3899 methodM2.parameters = <ParameterElement> [parameter1]; | 3898 methodM2.parameters = <ParameterElement> [parameter1]; |
| 3900 classI2.methods = <MethodElement> [methodM2]; | 3899 classI2.methods = <MethodElement> [methodM2]; |
| 3901 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3900 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3902 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; | 3901 classA.interfaces = <InterfaceType> [classI1.type, classI2.type]; |
| 3903 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3902 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3904 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapA.size); | 3903 expect(mapA.size, _numOfMembersInObject + 1); |
| 3905 JUnitTestCase.assertSame(methodM2, mapA.get(methodName)); | 3904 expect(mapA.get(methodName), same(methodM2)); |
| 3906 _assertNoErrors(classA); | 3905 _assertNoErrors(classA); |
| 3907 } | 3906 } |
| 3908 | 3907 |
| 3909 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_3_methods()
{ | 3908 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_3_methods()
{ |
| 3910 // class I1 { int m(); } | 3909 // class I1 { int m(); } |
| 3911 // class I2 { int m([int]); } | 3910 // class I2 { int m([int]); } |
| 3912 // class I3 { int m([int, int]); } | 3911 // class I3 { int m([int, int]); } |
| 3913 // class A implements I1, I2, I3 {} | 3912 // class A implements I1, I2, I3 {} |
| 3914 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3913 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 3915 String methodName = "m"; | 3914 String methodName = "m"; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3928 parameter2.type = _typeProvider.intType; | 3927 parameter2.type = _typeProvider.intType; |
| 3929 parameter2.parameterKind = ParameterKind.POSITIONAL; | 3928 parameter2.parameterKind = ParameterKind.POSITIONAL; |
| 3930 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a3")); | 3929 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a3")); |
| 3931 parameter3.type = _typeProvider.intType; | 3930 parameter3.type = _typeProvider.intType; |
| 3932 parameter3.parameterKind = ParameterKind.POSITIONAL; | 3931 parameter3.parameterKind = ParameterKind.POSITIONAL; |
| 3933 methodM3.parameters = <ParameterElement> [parameter2, parameter3]; | 3932 methodM3.parameters = <ParameterElement> [parameter2, parameter3]; |
| 3934 classI3.methods = <MethodElement> [methodM3]; | 3933 classI3.methods = <MethodElement> [methodM3]; |
| 3935 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3934 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3936 classA.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ
e]; | 3935 classA.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ
e]; |
| 3937 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3936 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3938 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapA.size); | 3937 expect(mapA.size, _numOfMembersInObject + 1); |
| 3939 JUnitTestCase.assertSame(methodM3, mapA.get(methodName)); | 3938 expect(mapA.get(methodName), same(methodM3)); |
| 3940 _assertNoErrors(classA); | 3939 _assertNoErrors(classA); |
| 3941 } | 3940 } |
| 3942 | 3941 |
| 3943 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_4_methods()
{ | 3942 void test_getMapOfMembersInheritedFromInterfaces_union_oneSubtype_4_methods()
{ |
| 3944 // class I1 { int m(); } | 3943 // class I1 { int m(); } |
| 3945 // class I2 { int m(); } | 3944 // class I2 { int m(); } |
| 3946 // class I3 { int m([int]); } | 3945 // class I3 { int m([int]); } |
| 3947 // class I4 { int m([int, int]); } | 3946 // class I4 { int m([int, int]); } |
| 3948 // class A implements I1, I2, I3, I4 {} | 3947 // class A implements I1, I2, I3, I4 {} |
| 3949 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 3948 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3966 parameter2.type = _typeProvider.intType; | 3965 parameter2.type = _typeProvider.intType; |
| 3967 parameter2.parameterKind = ParameterKind.POSITIONAL; | 3966 parameter2.parameterKind = ParameterKind.POSITIONAL; |
| 3968 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a3")); | 3967 ParameterElementImpl parameter3 = new ParameterElementImpl.forNode(AstFactor
y.identifier3("a3")); |
| 3969 parameter3.type = _typeProvider.intType; | 3968 parameter3.type = _typeProvider.intType; |
| 3970 parameter3.parameterKind = ParameterKind.POSITIONAL; | 3969 parameter3.parameterKind = ParameterKind.POSITIONAL; |
| 3971 methodM4.parameters = <ParameterElement> [parameter2, parameter3]; | 3970 methodM4.parameters = <ParameterElement> [parameter2, parameter3]; |
| 3972 classI4.methods = <MethodElement> [methodM4]; | 3971 classI4.methods = <MethodElement> [methodM4]; |
| 3973 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3972 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3974 classA.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ
e, classI4.type]; | 3973 classA.interfaces = <InterfaceType> [classI1.type, classI2.type, classI3.typ
e, classI4.type]; |
| 3975 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); | 3974 MemberMap mapA = _inheritanceManager.getMapOfMembersInheritedFromInterfaces(
classA); |
| 3976 JUnitTestCase.assertEquals(_numOfMembersInObject + 1, mapA.size); | 3975 expect(mapA.size, _numOfMembersInObject + 1); |
| 3977 JUnitTestCase.assertSame(methodM4, mapA.get(methodName)); | 3976 expect(mapA.get(methodName), same(methodM4)); |
| 3978 _assertNoErrors(classA); | 3977 _assertNoErrors(classA); |
| 3979 } | 3978 } |
| 3980 | 3979 |
| 3981 void test_lookupInheritance_interface_getter() { | 3980 void test_lookupInheritance_interface_getter() { |
| 3982 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3981 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3983 String getterName = "g"; | 3982 String getterName = "g"; |
| 3984 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); | 3983 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); |
| 3985 classA.accessors = <PropertyAccessorElement> [getterG]; | 3984 classA.accessors = <PropertyAccessorElement> [getterG]; |
| 3986 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 3985 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 3987 classB.interfaces = <InterfaceType> [classA.type]; | 3986 classB.interfaces = <InterfaceType> [classA.type]; |
| 3988 JUnitTestCase.assertSame(getterG, _inheritanceManager.lookupInheritance(clas
sB, getterName)); | 3987 expect(_inheritanceManager.lookupInheritance(classB, getterName), same(gette
rG)); |
| 3989 _assertNoErrors(classA); | 3988 _assertNoErrors(classA); |
| 3990 _assertNoErrors(classB); | 3989 _assertNoErrors(classB); |
| 3991 } | 3990 } |
| 3992 | 3991 |
| 3993 void test_lookupInheritance_interface_method() { | 3992 void test_lookupInheritance_interface_method() { |
| 3994 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 3993 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 3995 String methodName = "m"; | 3994 String methodName = "m"; |
| 3996 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 3995 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 3997 classA.methods = <MethodElement> [methodM]; | 3996 classA.methods = <MethodElement> [methodM]; |
| 3998 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 3997 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 3999 classB.interfaces = <InterfaceType> [classA.type]; | 3998 classB.interfaces = <InterfaceType> [classA.type]; |
| 4000 JUnitTestCase.assertSame(methodM, _inheritanceManager.lookupInheritance(clas
sB, methodName)); | 3999 expect(_inheritanceManager.lookupInheritance(classB, methodName), same(metho
dM)); |
| 4001 _assertNoErrors(classA); | 4000 _assertNoErrors(classA); |
| 4002 _assertNoErrors(classB); | 4001 _assertNoErrors(classB); |
| 4003 } | 4002 } |
| 4004 | 4003 |
| 4005 void test_lookupInheritance_interface_setter() { | 4004 void test_lookupInheritance_interface_setter() { |
| 4006 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4005 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4007 String setterName = "s"; | 4006 String setterName = "s"; |
| 4008 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f
alse, _typeProvider.intType); | 4007 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f
alse, _typeProvider.intType); |
| 4009 classA.accessors = <PropertyAccessorElement> [setterS]; | 4008 classA.accessors = <PropertyAccessorElement> [setterS]; |
| 4010 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 4009 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 4011 classB.interfaces = <InterfaceType> [classA.type]; | 4010 classB.interfaces = <InterfaceType> [classA.type]; |
| 4012 JUnitTestCase.assertSame(setterS, _inheritanceManager.lookupInheritance(clas
sB, "$setterName=")); | 4011 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="), same(s
etterS)); |
| 4013 _assertNoErrors(classA); | 4012 _assertNoErrors(classA); |
| 4014 _assertNoErrors(classB); | 4013 _assertNoErrors(classB); |
| 4015 } | 4014 } |
| 4016 | 4015 |
| 4017 void test_lookupInheritance_interface_staticMember() { | 4016 void test_lookupInheritance_interface_staticMember() { |
| 4018 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4017 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4019 String methodName = "m"; | 4018 String methodName = "m"; |
| 4020 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 4019 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 4021 (methodM as MethodElementImpl).static = true; | 4020 (methodM as MethodElementImpl).static = true; |
| 4022 classA.methods = <MethodElement> [methodM]; | 4021 classA.methods = <MethodElement> [methodM]; |
| 4023 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 4022 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 4024 classB.interfaces = <InterfaceType> [classA.type]; | 4023 classB.interfaces = <InterfaceType> [classA.type]; |
| 4025 JUnitTestCase.assertNull(_inheritanceManager.lookupInheritance(classB, metho
dName)); | 4024 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull); |
| 4026 _assertNoErrors(classA); | 4025 _assertNoErrors(classA); |
| 4027 _assertNoErrors(classB); | 4026 _assertNoErrors(classB); |
| 4028 } | 4027 } |
| 4029 | 4028 |
| 4030 void test_lookupInheritance_interfaces_infiniteLoop() { | 4029 void test_lookupInheritance_interfaces_infiniteLoop() { |
| 4031 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4030 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4032 classA.interfaces = <InterfaceType> [classA.type]; | 4031 classA.interfaces = <InterfaceType> [classA.type]; |
| 4033 JUnitTestCase.assertNull(_inheritanceManager.lookupInheritance(classA, "name
")); | 4032 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull); |
| 4034 _assertNoErrors(classA); | 4033 _assertNoErrors(classA); |
| 4035 } | 4034 } |
| 4036 | 4035 |
| 4037 void test_lookupInheritance_interfaces_infiniteLoop2() { | 4036 void test_lookupInheritance_interfaces_infiniteLoop2() { |
| 4038 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4037 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4039 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 4038 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 4040 classA.interfaces = <InterfaceType> [classB.type]; | 4039 classA.interfaces = <InterfaceType> [classB.type]; |
| 4041 classB.interfaces = <InterfaceType> [classA.type]; | 4040 classB.interfaces = <InterfaceType> [classA.type]; |
| 4042 JUnitTestCase.assertNull(_inheritanceManager.lookupInheritance(classA, "name
")); | 4041 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull); |
| 4043 _assertNoErrors(classA); | 4042 _assertNoErrors(classA); |
| 4044 _assertNoErrors(classB); | 4043 _assertNoErrors(classB); |
| 4045 } | 4044 } |
| 4046 | 4045 |
| 4047 void test_lookupInheritance_interfaces_union2() { | 4046 void test_lookupInheritance_interfaces_union2() { |
| 4048 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); | 4047 ClassElementImpl classI1 = ElementFactory.classElement2("I1", []); |
| 4049 String methodName1 = "m1"; | 4048 String methodName1 = "m1"; |
| 4050 MethodElement methodM1 = ElementFactory.methodElement(methodName1, _typeProv
ider.intType, []); | 4049 MethodElement methodM1 = ElementFactory.methodElement(methodName1, _typeProv
ider.intType, []); |
| 4051 classI1.methods = <MethodElement> [methodM1]; | 4050 classI1.methods = <MethodElement> [methodM1]; |
| 4052 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); | 4051 ClassElementImpl classI2 = ElementFactory.classElement2("I2", []); |
| 4053 String methodName2 = "m2"; | 4052 String methodName2 = "m2"; |
| 4054 MethodElement methodM2 = ElementFactory.methodElement(methodName2, _typeProv
ider.intType, []); | 4053 MethodElement methodM2 = ElementFactory.methodElement(methodName2, _typeProv
ider.intType, []); |
| 4055 classI2.methods = <MethodElement> [methodM2]; | 4054 classI2.methods = <MethodElement> [methodM2]; |
| 4056 classI2.interfaces = <InterfaceType> [classI1.type]; | 4055 classI2.interfaces = <InterfaceType> [classI1.type]; |
| 4057 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4056 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4058 classA.interfaces = <InterfaceType> [classI2.type]; | 4057 classA.interfaces = <InterfaceType> [classI2.type]; |
| 4059 JUnitTestCase.assertSame(methodM1, _inheritanceManager.lookupInheritance(cla
ssA, methodName1)); | 4058 expect(_inheritanceManager.lookupInheritance(classA, methodName1), same(meth
odM1)); |
| 4060 JUnitTestCase.assertSame(methodM2, _inheritanceManager.lookupInheritance(cla
ssA, methodName2)); | 4059 expect(_inheritanceManager.lookupInheritance(classA, methodName2), same(meth
odM2)); |
| 4061 _assertNoErrors(classI1); | 4060 _assertNoErrors(classI1); |
| 4062 _assertNoErrors(classI2); | 4061 _assertNoErrors(classI2); |
| 4063 _assertNoErrors(classA); | 4062 _assertNoErrors(classA); |
| 4064 } | 4063 } |
| 4065 | 4064 |
| 4066 void test_lookupInheritance_mixin_getter() { | 4065 void test_lookupInheritance_mixin_getter() { |
| 4067 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4066 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4068 String getterName = "g"; | 4067 String getterName = "g"; |
| 4069 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); | 4068 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); |
| 4070 classA.accessors = <PropertyAccessorElement> [getterG]; | 4069 classA.accessors = <PropertyAccessorElement> [getterG]; |
| 4071 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 4070 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 4072 classB.mixins = <InterfaceType> [classA.type]; | 4071 classB.mixins = <InterfaceType> [classA.type]; |
| 4073 JUnitTestCase.assertSame(getterG, _inheritanceManager.lookupInheritance(clas
sB, getterName)); | 4072 expect(_inheritanceManager.lookupInheritance(classB, getterName), same(gette
rG)); |
| 4074 _assertNoErrors(classA); | 4073 _assertNoErrors(classA); |
| 4075 _assertNoErrors(classB); | 4074 _assertNoErrors(classB); |
| 4076 } | 4075 } |
| 4077 | 4076 |
| 4078 void test_lookupInheritance_mixin_method() { | 4077 void test_lookupInheritance_mixin_method() { |
| 4079 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4078 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4080 String methodName = "m"; | 4079 String methodName = "m"; |
| 4081 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 4080 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 4082 classA.methods = <MethodElement> [methodM]; | 4081 classA.methods = <MethodElement> [methodM]; |
| 4083 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 4082 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 4084 classB.mixins = <InterfaceType> [classA.type]; | 4083 classB.mixins = <InterfaceType> [classA.type]; |
| 4085 JUnitTestCase.assertSame(methodM, _inheritanceManager.lookupInheritance(clas
sB, methodName)); | 4084 expect(_inheritanceManager.lookupInheritance(classB, methodName), same(metho
dM)); |
| 4086 _assertNoErrors(classA); | 4085 _assertNoErrors(classA); |
| 4087 _assertNoErrors(classB); | 4086 _assertNoErrors(classB); |
| 4088 } | 4087 } |
| 4089 | 4088 |
| 4090 void test_lookupInheritance_mixin_setter() { | 4089 void test_lookupInheritance_mixin_setter() { |
| 4091 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4090 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4092 String setterName = "s"; | 4091 String setterName = "s"; |
| 4093 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f
alse, _typeProvider.intType); | 4092 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f
alse, _typeProvider.intType); |
| 4094 classA.accessors = <PropertyAccessorElement> [setterS]; | 4093 classA.accessors = <PropertyAccessorElement> [setterS]; |
| 4095 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 4094 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 4096 classB.mixins = <InterfaceType> [classA.type]; | 4095 classB.mixins = <InterfaceType> [classA.type]; |
| 4097 JUnitTestCase.assertSame(setterS, _inheritanceManager.lookupInheritance(clas
sB, "$setterName=")); | 4096 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="), same(s
etterS)); |
| 4098 _assertNoErrors(classA); | 4097 _assertNoErrors(classA); |
| 4099 _assertNoErrors(classB); | 4098 _assertNoErrors(classB); |
| 4100 } | 4099 } |
| 4101 | 4100 |
| 4102 void test_lookupInheritance_mixin_staticMember() { | 4101 void test_lookupInheritance_mixin_staticMember() { |
| 4103 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4102 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4104 String methodName = "m"; | 4103 String methodName = "m"; |
| 4105 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 4104 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 4106 (methodM as MethodElementImpl).static = true; | 4105 (methodM as MethodElementImpl).static = true; |
| 4107 classA.methods = <MethodElement> [methodM]; | 4106 classA.methods = <MethodElement> [methodM]; |
| 4108 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 4107 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 4109 classB.mixins = <InterfaceType> [classA.type]; | 4108 classB.mixins = <InterfaceType> [classA.type]; |
| 4110 JUnitTestCase.assertNull(_inheritanceManager.lookupInheritance(classB, metho
dName)); | 4109 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull); |
| 4111 _assertNoErrors(classA); | 4110 _assertNoErrors(classA); |
| 4112 _assertNoErrors(classB); | 4111 _assertNoErrors(classB); |
| 4113 } | 4112 } |
| 4114 | 4113 |
| 4115 void test_lookupInheritance_noMember() { | 4114 void test_lookupInheritance_noMember() { |
| 4116 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4115 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4117 JUnitTestCase.assertNull(_inheritanceManager.lookupInheritance(classA, "a"))
; | 4116 expect(_inheritanceManager.lookupInheritance(classA, "a"), isNull); |
| 4118 _assertNoErrors(classA); | 4117 _assertNoErrors(classA); |
| 4119 } | 4118 } |
| 4120 | 4119 |
| 4121 void test_lookupInheritance_superclass_getter() { | 4120 void test_lookupInheritance_superclass_getter() { |
| 4122 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4121 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4123 String getterName = "g"; | 4122 String getterName = "g"; |
| 4124 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); | 4123 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); |
| 4125 classA.accessors = <PropertyAccessorElement> [getterG]; | 4124 classA.accessors = <PropertyAccessorElement> [getterG]; |
| 4126 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 4125 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 4127 JUnitTestCase.assertSame(getterG, _inheritanceManager.lookupInheritance(clas
sB, getterName)); | 4126 expect(_inheritanceManager.lookupInheritance(classB, getterName), same(gette
rG)); |
| 4128 _assertNoErrors(classA); | 4127 _assertNoErrors(classA); |
| 4129 _assertNoErrors(classB); | 4128 _assertNoErrors(classB); |
| 4130 } | 4129 } |
| 4131 | 4130 |
| 4132 void test_lookupInheritance_superclass_infiniteLoop() { | 4131 void test_lookupInheritance_superclass_infiniteLoop() { |
| 4133 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4132 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4134 classA.supertype = classA.type; | 4133 classA.supertype = classA.type; |
| 4135 JUnitTestCase.assertNull(_inheritanceManager.lookupInheritance(classA, "name
")); | 4134 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull); |
| 4136 _assertNoErrors(classA); | 4135 _assertNoErrors(classA); |
| 4137 } | 4136 } |
| 4138 | 4137 |
| 4139 void test_lookupInheritance_superclass_infiniteLoop2() { | 4138 void test_lookupInheritance_superclass_infiniteLoop2() { |
| 4140 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4139 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4141 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 4140 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 4142 classA.supertype = classB.type; | 4141 classA.supertype = classB.type; |
| 4143 classB.supertype = classA.type; | 4142 classB.supertype = classA.type; |
| 4144 JUnitTestCase.assertNull(_inheritanceManager.lookupInheritance(classA, "name
")); | 4143 expect(_inheritanceManager.lookupInheritance(classA, "name"), isNull); |
| 4145 _assertNoErrors(classA); | 4144 _assertNoErrors(classA); |
| 4146 _assertNoErrors(classB); | 4145 _assertNoErrors(classB); |
| 4147 } | 4146 } |
| 4148 | 4147 |
| 4149 void test_lookupInheritance_superclass_method() { | 4148 void test_lookupInheritance_superclass_method() { |
| 4150 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4149 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4151 String methodName = "m"; | 4150 String methodName = "m"; |
| 4152 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 4151 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 4153 classA.methods = <MethodElement> [methodM]; | 4152 classA.methods = <MethodElement> [methodM]; |
| 4154 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 4153 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 4155 JUnitTestCase.assertSame(methodM, _inheritanceManager.lookupInheritance(clas
sB, methodName)); | 4154 expect(_inheritanceManager.lookupInheritance(classB, methodName), same(metho
dM)); |
| 4156 _assertNoErrors(classA); | 4155 _assertNoErrors(classA); |
| 4157 _assertNoErrors(classB); | 4156 _assertNoErrors(classB); |
| 4158 } | 4157 } |
| 4159 | 4158 |
| 4160 void test_lookupInheritance_superclass_setter() { | 4159 void test_lookupInheritance_superclass_setter() { |
| 4161 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4160 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4162 String setterName = "s"; | 4161 String setterName = "s"; |
| 4163 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f
alse, _typeProvider.intType); | 4162 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f
alse, _typeProvider.intType); |
| 4164 classA.accessors = <PropertyAccessorElement> [setterS]; | 4163 classA.accessors = <PropertyAccessorElement> [setterS]; |
| 4165 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 4164 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 4166 JUnitTestCase.assertSame(setterS, _inheritanceManager.lookupInheritance(clas
sB, "$setterName=")); | 4165 expect(_inheritanceManager.lookupInheritance(classB, "$setterName="), same(s
etterS)); |
| 4167 _assertNoErrors(classA); | 4166 _assertNoErrors(classA); |
| 4168 _assertNoErrors(classB); | 4167 _assertNoErrors(classB); |
| 4169 } | 4168 } |
| 4170 | 4169 |
| 4171 void test_lookupInheritance_superclass_staticMember() { | 4170 void test_lookupInheritance_superclass_staticMember() { |
| 4172 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4171 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4173 String methodName = "m"; | 4172 String methodName = "m"; |
| 4174 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 4173 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 4175 (methodM as MethodElementImpl).static = true; | 4174 (methodM as MethodElementImpl).static = true; |
| 4176 classA.methods = <MethodElement> [methodM]; | 4175 classA.methods = <MethodElement> [methodM]; |
| 4177 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 4176 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 4178 JUnitTestCase.assertNull(_inheritanceManager.lookupInheritance(classB, metho
dName)); | 4177 expect(_inheritanceManager.lookupInheritance(classB, methodName), isNull); |
| 4179 _assertNoErrors(classA); | 4178 _assertNoErrors(classA); |
| 4180 _assertNoErrors(classB); | 4179 _assertNoErrors(classB); |
| 4181 } | 4180 } |
| 4182 | 4181 |
| 4183 void test_lookupMember_getter() { | 4182 void test_lookupMember_getter() { |
| 4184 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4183 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4185 String getterName = "g"; | 4184 String getterName = "g"; |
| 4186 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); | 4185 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, f
alse, _typeProvider.intType); |
| 4187 classA.accessors = <PropertyAccessorElement> [getterG]; | 4186 classA.accessors = <PropertyAccessorElement> [getterG]; |
| 4188 JUnitTestCase.assertSame(getterG, _inheritanceManager.lookupMember(classA, g
etterName)); | 4187 expect(_inheritanceManager.lookupMember(classA, getterName), same(getterG)); |
| 4189 _assertNoErrors(classA); | 4188 _assertNoErrors(classA); |
| 4190 } | 4189 } |
| 4191 | 4190 |
| 4192 void test_lookupMember_getter_static() { | 4191 void test_lookupMember_getter_static() { |
| 4193 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4192 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4194 String getterName = "g"; | 4193 String getterName = "g"; |
| 4195 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, t
rue, _typeProvider.intType); | 4194 PropertyAccessorElement getterG = ElementFactory.getterElement(getterName, t
rue, _typeProvider.intType); |
| 4196 classA.accessors = <PropertyAccessorElement> [getterG]; | 4195 classA.accessors = <PropertyAccessorElement> [getterG]; |
| 4197 JUnitTestCase.assertNull(_inheritanceManager.lookupMember(classA, getterName
)); | 4196 expect(_inheritanceManager.lookupMember(classA, getterName), isNull); |
| 4198 _assertNoErrors(classA); | 4197 _assertNoErrors(classA); |
| 4199 } | 4198 } |
| 4200 | 4199 |
| 4201 void test_lookupMember_method() { | 4200 void test_lookupMember_method() { |
| 4202 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4201 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4203 String methodName = "m"; | 4202 String methodName = "m"; |
| 4204 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 4203 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 4205 classA.methods = <MethodElement> [methodM]; | 4204 classA.methods = <MethodElement> [methodM]; |
| 4206 JUnitTestCase.assertSame(methodM, _inheritanceManager.lookupMember(classA, m
ethodName)); | 4205 expect(_inheritanceManager.lookupMember(classA, methodName), same(methodM)); |
| 4207 _assertNoErrors(classA); | 4206 _assertNoErrors(classA); |
| 4208 } | 4207 } |
| 4209 | 4208 |
| 4210 void test_lookupMember_method_static() { | 4209 void test_lookupMember_method_static() { |
| 4211 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4210 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4212 String methodName = "m"; | 4211 String methodName = "m"; |
| 4213 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); | 4212 MethodElement methodM = ElementFactory.methodElement(methodName, _typeProvid
er.intType, []); |
| 4214 (methodM as MethodElementImpl).static = true; | 4213 (methodM as MethodElementImpl).static = true; |
| 4215 classA.methods = <MethodElement> [methodM]; | 4214 classA.methods = <MethodElement> [methodM]; |
| 4216 JUnitTestCase.assertNull(_inheritanceManager.lookupMember(classA, methodName
)); | 4215 expect(_inheritanceManager.lookupMember(classA, methodName), isNull); |
| 4217 _assertNoErrors(classA); | 4216 _assertNoErrors(classA); |
| 4218 } | 4217 } |
| 4219 | 4218 |
| 4220 void test_lookupMember_noMember() { | 4219 void test_lookupMember_noMember() { |
| 4221 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4220 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4222 JUnitTestCase.assertNull(_inheritanceManager.lookupMember(classA, "a")); | 4221 expect(_inheritanceManager.lookupMember(classA, "a"), isNull); |
| 4223 _assertNoErrors(classA); | 4222 _assertNoErrors(classA); |
| 4224 } | 4223 } |
| 4225 | 4224 |
| 4226 void test_lookupMember_setter() { | 4225 void test_lookupMember_setter() { |
| 4227 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4226 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4228 String setterName = "s"; | 4227 String setterName = "s"; |
| 4229 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f
alse, _typeProvider.intType); | 4228 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, f
alse, _typeProvider.intType); |
| 4230 classA.accessors = <PropertyAccessorElement> [setterS]; | 4229 classA.accessors = <PropertyAccessorElement> [setterS]; |
| 4231 JUnitTestCase.assertSame(setterS, _inheritanceManager.lookupMember(classA, "
$setterName=")); | 4230 expect(_inheritanceManager.lookupMember(classA, "$setterName="), same(setter
S)); |
| 4232 _assertNoErrors(classA); | 4231 _assertNoErrors(classA); |
| 4233 } | 4232 } |
| 4234 | 4233 |
| 4235 void test_lookupMember_setter_static() { | 4234 void test_lookupMember_setter_static() { |
| 4236 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4235 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4237 String setterName = "s"; | 4236 String setterName = "s"; |
| 4238 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, t
rue, _typeProvider.intType); | 4237 PropertyAccessorElement setterS = ElementFactory.setterElement(setterName, t
rue, _typeProvider.intType); |
| 4239 classA.accessors = <PropertyAccessorElement> [setterS]; | 4238 classA.accessors = <PropertyAccessorElement> [setterS]; |
| 4240 JUnitTestCase.assertNull(_inheritanceManager.lookupMember(classA, setterName
)); | 4239 expect(_inheritanceManager.lookupMember(classA, setterName), isNull); |
| 4241 _assertNoErrors(classA); | 4240 _assertNoErrors(classA); |
| 4242 } | 4241 } |
| 4243 | 4242 |
| 4244 void test_lookupOverrides_noParentClasses() { | 4243 void test_lookupOverrides_noParentClasses() { |
| 4245 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4244 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4246 String methodName = "m"; | 4245 String methodName = "m"; |
| 4247 MethodElementImpl methodM = ElementFactory.methodElement(methodName, _typePr
ovider.intType, []); | 4246 MethodElementImpl methodM = ElementFactory.methodElement(methodName, _typePr
ovider.intType, []); |
| 4248 classA.methods = <MethodElement> [methodM]; | 4247 classA.methods = <MethodElement> [methodM]; |
| 4249 EngineTestCase.assertSizeOfList(0, _inheritanceManager.lookupOverrides(class
A, methodName)); | 4248 EngineTestCase.assertSizeOfList(0, _inheritanceManager.lookupOverrides(class
A, methodName)); |
| 4250 _assertNoErrors(classA); | 4249 _assertNoErrors(classA); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4349 library lib; | 4348 library lib; |
| 4350 part 'first.dart'; | 4349 part 'first.dart'; |
| 4351 part 'second.dart';'''); | 4350 part 'second.dart';'''); |
| 4352 addSource("/first.dart", r''' | 4351 addSource("/first.dart", r''' |
| 4353 part of lib; | 4352 part of lib; |
| 4354 int get V => 0;'''); | 4353 int get V => 0;'''); |
| 4355 addSource("/second.dart", r''' | 4354 addSource("/second.dart", r''' |
| 4356 part of lib; | 4355 part of lib; |
| 4357 void set V(int v) {}'''); | 4356 void set V(int v) {}'''); |
| 4358 LibraryElement element = _buildLibrary(librarySource, []); | 4357 LibraryElement element = _buildLibrary(librarySource, []); |
| 4359 JUnitTestCase.assertNotNull(element); | 4358 expect(element, isNotNull); |
| 4360 List<CompilationUnitElement> sourcedUnits = element.parts; | 4359 List<CompilationUnitElement> sourcedUnits = element.parts; |
| 4361 EngineTestCase.assertLength(2, sourcedUnits); | 4360 EngineTestCase.assertLength(2, sourcedUnits); |
| 4362 List<PropertyAccessorElement> firstAccessors = sourcedUnits[0].accessors; | 4361 List<PropertyAccessorElement> firstAccessors = sourcedUnits[0].accessors; |
| 4363 EngineTestCase.assertLength(1, firstAccessors); | 4362 EngineTestCase.assertLength(1, firstAccessors); |
| 4364 List<PropertyAccessorElement> secondAccessors = sourcedUnits[1].accessors; | 4363 List<PropertyAccessorElement> secondAccessors = sourcedUnits[1].accessors; |
| 4365 EngineTestCase.assertLength(1, secondAccessors); | 4364 EngineTestCase.assertLength(1, secondAccessors); |
| 4366 JUnitTestCase.assertSame(firstAccessors[0].variable, secondAccessors[0].vari
able); | 4365 expect(secondAccessors[0].variable, same(firstAccessors[0].variable)); |
| 4367 } | 4366 } |
| 4368 | 4367 |
| 4369 void test_empty() { | 4368 void test_empty() { |
| 4370 Source librarySource = addSource("/lib.dart", "library lib;"); | 4369 Source librarySource = addSource("/lib.dart", "library lib;"); |
| 4371 LibraryElement element = _buildLibrary(librarySource, []); | 4370 LibraryElement element = _buildLibrary(librarySource, []); |
| 4372 JUnitTestCase.assertNotNull(element); | 4371 expect(element, isNotNull); |
| 4373 JUnitTestCase.assertEquals("lib", element.name); | 4372 expect(element.name, "lib"); |
| 4374 JUnitTestCase.assertNull(element.entryPoint); | 4373 expect(element.entryPoint, isNull); |
| 4375 EngineTestCase.assertLength(0, element.importedLibraries); | 4374 EngineTestCase.assertLength(0, element.importedLibraries); |
| 4376 EngineTestCase.assertLength(0, element.imports); | 4375 EngineTestCase.assertLength(0, element.imports); |
| 4377 JUnitTestCase.assertSame(element, element.library); | 4376 expect(element.library, same(element)); |
| 4378 EngineTestCase.assertLength(0, element.prefixes); | 4377 EngineTestCase.assertLength(0, element.prefixes); |
| 4379 EngineTestCase.assertLength(0, element.parts); | 4378 EngineTestCase.assertLength(0, element.parts); |
| 4380 CompilationUnitElement unit = element.definingCompilationUnit; | 4379 CompilationUnitElement unit = element.definingCompilationUnit; |
| 4381 JUnitTestCase.assertNotNull(unit); | 4380 expect(unit, isNotNull); |
| 4382 JUnitTestCase.assertEquals("lib.dart", unit.name); | 4381 expect(unit.name, "lib.dart"); |
| 4383 JUnitTestCase.assertEquals(element, unit.library); | 4382 expect(unit.library, element); |
| 4384 EngineTestCase.assertLength(0, unit.accessors); | 4383 EngineTestCase.assertLength(0, unit.accessors); |
| 4385 EngineTestCase.assertLength(0, unit.functions); | 4384 EngineTestCase.assertLength(0, unit.functions); |
| 4386 EngineTestCase.assertLength(0, unit.functionTypeAliases); | 4385 EngineTestCase.assertLength(0, unit.functionTypeAliases); |
| 4387 EngineTestCase.assertLength(0, unit.types); | 4386 EngineTestCase.assertLength(0, unit.types); |
| 4388 EngineTestCase.assertLength(0, unit.topLevelVariables); | 4387 EngineTestCase.assertLength(0, unit.topLevelVariables); |
| 4389 } | 4388 } |
| 4390 | 4389 |
| 4391 void test_missingLibraryDirectiveWithPart() { | 4390 void test_missingLibraryDirectiveWithPart() { |
| 4392 addSource("/a.dart", "part of lib;"); | 4391 addSource("/a.dart", "part of lib;"); |
| 4393 Source librarySource = addSource("/lib.dart", "part 'a.dart';"); | 4392 Source librarySource = addSource("/lib.dart", "part 'a.dart';"); |
| 4394 LibraryElement element = _buildLibrary(librarySource, [ResolverErrorCode.MIS
SING_LIBRARY_DIRECTIVE_WITH_PART]); | 4393 LibraryElement element = _buildLibrary(librarySource, [ResolverErrorCode.MIS
SING_LIBRARY_DIRECTIVE_WITH_PART]); |
| 4395 JUnitTestCase.assertNotNull(element); | 4394 expect(element, isNotNull); |
| 4396 } | 4395 } |
| 4397 | 4396 |
| 4398 void test_missingPartOfDirective() { | 4397 void test_missingPartOfDirective() { |
| 4399 addSource("/a.dart", "class A {}"); | 4398 addSource("/a.dart", "class A {}"); |
| 4400 Source librarySource = addSource("/lib.dart", r''' | 4399 Source librarySource = addSource("/lib.dart", r''' |
| 4401 library lib; | 4400 library lib; |
| 4402 | 4401 |
| 4403 part 'a.dart';'''); | 4402 part 'a.dart';'''); |
| 4404 LibraryElement element = _buildLibrary(librarySource, [CompileTimeErrorCode.
PART_OF_NON_PART]); | 4403 LibraryElement element = _buildLibrary(librarySource, [CompileTimeErrorCode.
PART_OF_NON_PART]); |
| 4405 JUnitTestCase.assertNotNull(element); | 4404 expect(element, isNotNull); |
| 4406 } | 4405 } |
| 4407 | 4406 |
| 4408 void test_multipleFiles() { | 4407 void test_multipleFiles() { |
| 4409 Source librarySource = addSource("/lib.dart", r''' | 4408 Source librarySource = addSource("/lib.dart", r''' |
| 4410 library lib; | 4409 library lib; |
| 4411 part 'first.dart'; | 4410 part 'first.dart'; |
| 4412 part 'second.dart'; | 4411 part 'second.dart'; |
| 4413 | 4412 |
| 4414 class A {}'''); | 4413 class A {}'''); |
| 4415 addSource("/first.dart", r''' | 4414 addSource("/first.dart", r''' |
| 4416 part of lib; | 4415 part of lib; |
| 4417 class B {}'''); | 4416 class B {}'''); |
| 4418 addSource("/second.dart", r''' | 4417 addSource("/second.dart", r''' |
| 4419 part of lib; | 4418 part of lib; |
| 4420 class C {}'''); | 4419 class C {}'''); |
| 4421 LibraryElement element = _buildLibrary(librarySource, []); | 4420 LibraryElement element = _buildLibrary(librarySource, []); |
| 4422 JUnitTestCase.assertNotNull(element); | 4421 expect(element, isNotNull); |
| 4423 List<CompilationUnitElement> sourcedUnits = element.parts; | 4422 List<CompilationUnitElement> sourcedUnits = element.parts; |
| 4424 EngineTestCase.assertLength(2, sourcedUnits); | 4423 EngineTestCase.assertLength(2, sourcedUnits); |
| 4425 _assertTypes(element.definingCompilationUnit, ["A"]); | 4424 _assertTypes(element.definingCompilationUnit, ["A"]); |
| 4426 if (sourcedUnits[0].name == "first.dart") { | 4425 if (sourcedUnits[0].name == "first.dart") { |
| 4427 _assertTypes(sourcedUnits[0], ["B"]); | 4426 _assertTypes(sourcedUnits[0], ["B"]); |
| 4428 _assertTypes(sourcedUnits[1], ["C"]); | 4427 _assertTypes(sourcedUnits[1], ["C"]); |
| 4429 } else { | 4428 } else { |
| 4430 _assertTypes(sourcedUnits[0], ["C"]); | 4429 _assertTypes(sourcedUnits[0], ["C"]); |
| 4431 _assertTypes(sourcedUnits[1], ["B"]); | 4430 _assertTypes(sourcedUnits[1], ["B"]); |
| 4432 } | 4431 } |
| 4433 } | 4432 } |
| 4434 | 4433 |
| 4435 void test_singleFile() { | 4434 void test_singleFile() { |
| 4436 Source librarySource = addSource("/lib.dart", r''' | 4435 Source librarySource = addSource("/lib.dart", r''' |
| 4437 library lib; | 4436 library lib; |
| 4438 | 4437 |
| 4439 class A {}'''); | 4438 class A {}'''); |
| 4440 LibraryElement element = _buildLibrary(librarySource, []); | 4439 LibraryElement element = _buildLibrary(librarySource, []); |
| 4441 JUnitTestCase.assertNotNull(element); | 4440 expect(element, isNotNull); |
| 4442 _assertTypes(element.definingCompilationUnit, ["A"]); | 4441 _assertTypes(element.definingCompilationUnit, ["A"]); |
| 4443 } | 4442 } |
| 4444 | 4443 |
| 4445 /** | 4444 /** |
| 4446 * Add a source file to the content provider. The file path should be absolute
. | 4445 * Add a source file to the content provider. The file path should be absolute
. |
| 4447 * | 4446 * |
| 4448 * @param filePath the path of the file being added | 4447 * @param filePath the path of the file being added |
| 4449 * @param contents the contents to be returned by the content provider for the
specified file | 4448 * @param contents the contents to be returned by the content provider for the
specified file |
| 4450 * @return the source object representing the added file | 4449 * @return the source object representing the added file |
| 4451 */ | 4450 */ |
| 4452 Source addSource(String filePath, String contents) { | 4451 Source addSource(String filePath, String contents) { |
| 4453 Source source = new FileBasedSource.con1(FileUtilities2.createFile(filePath)
); | 4452 Source source = new FileBasedSource.con1(FileUtilities2.createFile(filePath)
); |
| 4454 _context.setContents(source, contents); | 4453 _context.setContents(source, contents); |
| 4455 return source; | 4454 return source; |
| 4456 } | 4455 } |
| 4457 | 4456 |
| 4458 @override | 4457 @override |
| 4459 void tearDown() { | 4458 void tearDown() { |
| 4460 _context = null; | 4459 _context = null; |
| 4461 super.tearDown(); | 4460 super.tearDown(); |
| 4462 } | 4461 } |
| 4463 | 4462 |
| 4464 /** | 4463 /** |
| 4465 * Ensure that there are elements representing all of the types in the given a
rray of type names. | 4464 * Ensure that there are elements representing all of the types in the given a
rray of type names. |
| 4466 * | 4465 * |
| 4467 * @param unit the compilation unit containing the types | 4466 * @param unit the compilation unit containing the types |
| 4468 * @param typeNames the names of the types that should be found | 4467 * @param typeNames the names of the types that should be found |
| 4469 */ | 4468 */ |
| 4470 void _assertTypes(CompilationUnitElement unit, List<String> typeNames) { | 4469 void _assertTypes(CompilationUnitElement unit, List<String> typeNames) { |
| 4471 JUnitTestCase.assertNotNull(unit); | 4470 expect(unit, isNotNull); |
| 4472 List<ClassElement> types = unit.types; | 4471 List<ClassElement> types = unit.types; |
| 4473 EngineTestCase.assertLength(typeNames.length, types); | 4472 EngineTestCase.assertLength(typeNames.length, types); |
| 4474 for (ClassElement type in types) { | 4473 for (ClassElement type in types) { |
| 4475 JUnitTestCase.assertNotNull(type); | 4474 expect(type, isNotNull); |
| 4476 String actualTypeName = type.displayName; | 4475 String actualTypeName = type.displayName; |
| 4477 bool wasExpected = false; | 4476 bool wasExpected = false; |
| 4478 for (String expectedTypeName in typeNames) { | 4477 for (String expectedTypeName in typeNames) { |
| 4479 if (expectedTypeName == actualTypeName) { | 4478 if (expectedTypeName == actualTypeName) { |
| 4480 wasExpected = true; | 4479 wasExpected = true; |
| 4481 } | 4480 } |
| 4482 } | 4481 } |
| 4483 if (!wasExpected) { | 4482 if (!wasExpected) { |
| 4484 JUnitTestCase.fail("Found unexpected type $actualTypeName"); | 4483 fail("Found unexpected type $actualTypeName"); |
| 4485 } | 4484 } |
| 4486 } | 4485 } |
| 4487 } | 4486 } |
| 4488 | 4487 |
| 4489 /** | 4488 /** |
| 4490 * Build the element model for the library whose defining compilation unit has
the given source. | 4489 * Build the element model for the library whose defining compilation unit has
the given source. |
| 4491 * | 4490 * |
| 4492 * @param librarySource the source of the defining compilation unit for the li
brary | 4491 * @param librarySource the source of the defining compilation unit for the li
brary |
| 4493 * @param expectedErrorCodes the errors that are expected to be found while bu
ilding the element | 4492 * @param expectedErrorCodes the errors that are expected to be found while bu
ilding the element |
| 4494 * model | 4493 * model |
| (...skipping 27 matching lines...) Expand all Loading... |
| 4522 (importedLibrary1.definingCompilationUnit as CompilationUnitElementImpl).typ
es = <ClassElement> [typeA, typeB1]; | 4521 (importedLibrary1.definingCompilationUnit as CompilationUnitElementImpl).typ
es = <ClassElement> [typeA, typeB1]; |
| 4523 ImportElementImpl import1 = ElementFactory.importFor(importedLibrary1, null,
[]); | 4522 ImportElementImpl import1 = ElementFactory.importFor(importedLibrary1, null,
[]); |
| 4524 LibraryElement importedLibrary2 = createTestLibrary(context, "imported2", []
); | 4523 LibraryElement importedLibrary2 = createTestLibrary(context, "imported2", []
); |
| 4525 (importedLibrary2.definingCompilationUnit as CompilationUnitElementImpl).typ
es = <ClassElement> [typeB2, typeC]; | 4524 (importedLibrary2.definingCompilationUnit as CompilationUnitElementImpl).typ
es = <ClassElement> [typeB2, typeC]; |
| 4526 ImportElementImpl import2 = ElementFactory.importFor(importedLibrary2, null,
[]); | 4525 ImportElementImpl import2 = ElementFactory.importFor(importedLibrary2, null,
[]); |
| 4527 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing"
, []); | 4526 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing"
, []); |
| 4528 importingLibrary.imports = <ImportElement> [import1, import2]; | 4527 importingLibrary.imports = <ImportElement> [import1, import2]; |
| 4529 { | 4528 { |
| 4530 GatheringErrorListener errorListener = new GatheringErrorListener(); | 4529 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 4531 Scope scope = new LibraryImportScope(importingLibrary, errorListener); | 4530 Scope scope = new LibraryImportScope(importingLibrary, errorListener); |
| 4532 JUnitTestCase.assertEquals(typeA, scope.lookup(AstFactory.identifier3(type
NameA), importingLibrary)); | 4531 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary),
typeA); |
| 4533 errorListener.assertNoErrors(); | 4532 errorListener.assertNoErrors(); |
| 4534 JUnitTestCase.assertEquals(typeC, scope.lookup(AstFactory.identifier3(type
NameC), importingLibrary)); | 4533 expect(scope.lookup(AstFactory.identifier3(typeNameC), importingLibrary),
typeC); |
| 4535 errorListener.assertNoErrors(); | 4534 errorListener.assertNoErrors(); |
| 4536 Element element = scope.lookup(AstFactory.identifier3(typeNameB), importin
gLibrary); | 4535 Element element = scope.lookup(AstFactory.identifier3(typeNameB), importin
gLibrary); |
| 4537 errorListener.assertErrorsWithCodes([StaticWarningCode.AMBIGUOUS_IMPORT]); | 4536 errorListener.assertErrorsWithCodes([StaticWarningCode.AMBIGUOUS_IMPORT]); |
| 4538 EngineTestCase.assertInstanceOf((obj) => obj is MultiplyDefinedElement, Mu
ltiplyDefinedElement, element); | 4537 EngineTestCase.assertInstanceOf((obj) => obj is MultiplyDefinedElement, Mu
ltiplyDefinedElement, element); |
| 4539 List<Element> conflictingElements = (element as MultiplyDefinedElement).co
nflictingElements; | 4538 List<Element> conflictingElements = (element as MultiplyDefinedElement).co
nflictingElements; |
| 4540 EngineTestCase.assertLength(2, conflictingElements); | 4539 EngineTestCase.assertLength(2, conflictingElements); |
| 4541 if (identical(conflictingElements[0], typeB1)) { | 4540 if (identical(conflictingElements[0], typeB1)) { |
| 4542 JUnitTestCase.assertSame(typeB2, conflictingElements[1]); | 4541 expect(conflictingElements[1], same(typeB2)); |
| 4543 } else if (identical(conflictingElements[0], typeB2)) { | 4542 } else if (identical(conflictingElements[0], typeB2)) { |
| 4544 JUnitTestCase.assertSame(typeB1, conflictingElements[1]); | 4543 expect(conflictingElements[1], same(typeB1)); |
| 4545 } else { | 4544 } else { |
| 4546 JUnitTestCase.assertSame(typeB1, conflictingElements[0]); | 4545 expect(conflictingElements[0], same(typeB1)); |
| 4547 } | 4546 } |
| 4548 } | 4547 } |
| 4549 { | 4548 { |
| 4550 GatheringErrorListener errorListener = new GatheringErrorListener(); | 4549 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 4551 Scope scope = new LibraryImportScope(importingLibrary, errorListener); | 4550 Scope scope = new LibraryImportScope(importingLibrary, errorListener); |
| 4552 Identifier identifier = AstFactory.identifier3(typeNameB); | 4551 Identifier identifier = AstFactory.identifier3(typeNameB); |
| 4553 AstFactory.methodDeclaration(null, AstFactory.typeName3(identifier, []), n
ull, null, AstFactory.identifier3("foo"), null); | 4552 AstFactory.methodDeclaration(null, AstFactory.typeName3(identifier, []), n
ull, null, AstFactory.identifier3("foo"), null); |
| 4554 Element element = scope.lookup(identifier, importingLibrary); | 4553 Element element = scope.lookup(identifier, importingLibrary); |
| 4555 errorListener.assertErrorsWithCodes([StaticWarningCode.AMBIGUOUS_IMPORT]); | 4554 errorListener.assertErrorsWithCodes([StaticWarningCode.AMBIGUOUS_IMPORT]); |
| 4556 EngineTestCase.assertInstanceOf((obj) => obj is MultiplyDefinedElement, Mu
ltiplyDefinedElement, element); | 4555 EngineTestCase.assertInstanceOf((obj) => obj is MultiplyDefinedElement, Mu
ltiplyDefinedElement, element); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4569 String importedTypeName = "A"; | 4568 String importedTypeName = "A"; |
| 4570 ClassElement importedType = new ClassElementImpl.forNode(AstFactory.identifi
er3(importedTypeName)); | 4569 ClassElement importedType = new ClassElementImpl.forNode(AstFactory.identifi
er3(importedTypeName)); |
| 4571 LibraryElement importedLibrary = createTestLibrary(context, "imported", []); | 4570 LibraryElement importedLibrary = createTestLibrary(context, "imported", []); |
| 4572 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type
s = <ClassElement> [importedType]; | 4571 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type
s = <ClassElement> [importedType]; |
| 4573 LibraryElementImpl definingLibrary = createTestLibrary(context, "importing",
[]); | 4572 LibraryElementImpl definingLibrary = createTestLibrary(context, "importing",
[]); |
| 4574 ImportElementImpl importElement = new ImportElementImpl(0); | 4573 ImportElementImpl importElement = new ImportElementImpl(0); |
| 4575 importElement.importedLibrary = importedLibrary; | 4574 importElement.importedLibrary = importedLibrary; |
| 4576 definingLibrary.imports = <ImportElement> [importElement]; | 4575 definingLibrary.imports = <ImportElement> [importElement]; |
| 4577 GatheringErrorListener errorListener = new GatheringErrorListener(); | 4576 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 4578 Scope scope = new LibraryImportScope(definingLibrary, errorListener); | 4577 Scope scope = new LibraryImportScope(definingLibrary, errorListener); |
| 4579 JUnitTestCase.assertEquals(importedType, scope.lookup(AstFactory.identifier3
(importedTypeName), definingLibrary)); | 4578 expect(scope.lookup(AstFactory.identifier3(importedTypeName), definingLibrar
y), importedType); |
| 4580 } | 4579 } |
| 4581 | 4580 |
| 4582 void test_getErrorListener() { | 4581 void test_getErrorListener() { |
| 4583 LibraryElement definingLibrary = createDefaultTestLibrary(); | 4582 LibraryElement definingLibrary = createDefaultTestLibrary(); |
| 4584 GatheringErrorListener errorListener = new GatheringErrorListener(); | 4583 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 4585 LibraryImportScope scope = new LibraryImportScope(definingLibrary, errorList
ener); | 4584 LibraryImportScope scope = new LibraryImportScope(definingLibrary, errorList
ener); |
| 4586 JUnitTestCase.assertEquals(errorListener, scope.errorListener); | 4585 expect(scope.errorListener, errorListener); |
| 4587 } | 4586 } |
| 4588 | 4587 |
| 4589 void test_nonConflictingImports_fromSdk() { | 4588 void test_nonConflictingImports_fromSdk() { |
| 4590 AnalysisContext context = AnalysisContextFactory.contextWithCore(); | 4589 AnalysisContext context = AnalysisContextFactory.contextWithCore(); |
| 4591 String typeName = "List"; | 4590 String typeName = "List"; |
| 4592 ClassElement type = ElementFactory.classElement2(typeName, []); | 4591 ClassElement type = ElementFactory.classElement2(typeName, []); |
| 4593 LibraryElement importedLibrary = createTestLibrary(context, "lib", []); | 4592 LibraryElement importedLibrary = createTestLibrary(context, "lib", []); |
| 4594 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type
s = <ClassElement> [type]; | 4593 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type
s = <ClassElement> [type]; |
| 4595 ImportElementImpl importCore = ElementFactory.importFor(context.getLibraryEl
ement(context.sourceFactory.forUri("dart:core")), null, []); | 4594 ImportElementImpl importCore = ElementFactory.importFor(context.getLibraryEl
ement(context.sourceFactory.forUri("dart:core")), null, []); |
| 4596 ImportElementImpl importLib = ElementFactory.importFor(importedLibrary, null
, []); | 4595 ImportElementImpl importLib = ElementFactory.importFor(importedLibrary, null
, []); |
| 4597 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing"
, []); | 4596 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing"
, []); |
| 4598 importingLibrary.imports = <ImportElement> [importCore, importLib]; | 4597 importingLibrary.imports = <ImportElement> [importCore, importLib]; |
| 4599 GatheringErrorListener errorListener = new GatheringErrorListener(); | 4598 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 4600 Scope scope = new LibraryImportScope(importingLibrary, errorListener); | 4599 Scope scope = new LibraryImportScope(importingLibrary, errorListener); |
| 4601 JUnitTestCase.assertEquals(type, scope.lookup(AstFactory.identifier3(typeNam
e), importingLibrary)); | 4600 expect(scope.lookup(AstFactory.identifier3(typeName), importingLibrary), typ
e); |
| 4602 errorListener.assertErrorsWithCodes([StaticWarningCode.CONFLICTING_DART_IMPO
RT]); | 4601 errorListener.assertErrorsWithCodes([StaticWarningCode.CONFLICTING_DART_IMPO
RT]); |
| 4603 } | 4602 } |
| 4604 | 4603 |
| 4605 void test_nonConflictingImports_sameElement() { | 4604 void test_nonConflictingImports_sameElement() { |
| 4606 AnalysisContext context = new AnalysisContextImpl(); | 4605 AnalysisContext context = new AnalysisContextImpl(); |
| 4607 context.sourceFactory = new SourceFactory([]); | 4606 context.sourceFactory = new SourceFactory([]); |
| 4608 String typeNameA = "A"; | 4607 String typeNameA = "A"; |
| 4609 String typeNameB = "B"; | 4608 String typeNameB = "B"; |
| 4610 ClassElement typeA = ElementFactory.classElement2(typeNameA, []); | 4609 ClassElement typeA = ElementFactory.classElement2(typeNameA, []); |
| 4611 ClassElement typeB = ElementFactory.classElement2(typeNameB, []); | 4610 ClassElement typeB = ElementFactory.classElement2(typeNameB, []); |
| 4612 LibraryElement importedLibrary = createTestLibrary(context, "imported", []); | 4611 LibraryElement importedLibrary = createTestLibrary(context, "imported", []); |
| 4613 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type
s = <ClassElement> [typeA, typeB]; | 4612 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type
s = <ClassElement> [typeA, typeB]; |
| 4614 ImportElementImpl import1 = ElementFactory.importFor(importedLibrary, null,
[]); | 4613 ImportElementImpl import1 = ElementFactory.importFor(importedLibrary, null,
[]); |
| 4615 ImportElementImpl import2 = ElementFactory.importFor(importedLibrary, null,
[]); | 4614 ImportElementImpl import2 = ElementFactory.importFor(importedLibrary, null,
[]); |
| 4616 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing"
, []); | 4615 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing"
, []); |
| 4617 importingLibrary.imports = <ImportElement> [import1, import2]; | 4616 importingLibrary.imports = <ImportElement> [import1, import2]; |
| 4618 GatheringErrorListener errorListener = new GatheringErrorListener(); | 4617 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 4619 Scope scope = new LibraryImportScope(importingLibrary, errorListener); | 4618 Scope scope = new LibraryImportScope(importingLibrary, errorListener); |
| 4620 JUnitTestCase.assertEquals(typeA, scope.lookup(AstFactory.identifier3(typeNa
meA), importingLibrary)); | 4619 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary), ty
peA); |
| 4621 errorListener.assertNoErrors(); | 4620 errorListener.assertNoErrors(); |
| 4622 JUnitTestCase.assertEquals(typeB, scope.lookup(AstFactory.identifier3(typeNa
meB), importingLibrary)); | 4621 expect(scope.lookup(AstFactory.identifier3(typeNameB), importingLibrary), ty
peB); |
| 4623 errorListener.assertNoErrors(); | 4622 errorListener.assertNoErrors(); |
| 4624 } | 4623 } |
| 4625 | 4624 |
| 4626 void test_prefixedAndNonPrefixed() { | 4625 void test_prefixedAndNonPrefixed() { |
| 4627 AnalysisContext context = new AnalysisContextImpl(); | 4626 AnalysisContext context = new AnalysisContextImpl(); |
| 4628 context.sourceFactory = new SourceFactory([]); | 4627 context.sourceFactory = new SourceFactory([]); |
| 4629 String typeName = "C"; | 4628 String typeName = "C"; |
| 4630 String prefixName = "p"; | 4629 String prefixName = "p"; |
| 4631 ClassElement prefixedType = ElementFactory.classElement2(typeName, []); | 4630 ClassElement prefixedType = ElementFactory.classElement2(typeName, []); |
| 4632 ClassElement nonPrefixedType = ElementFactory.classElement2(typeName, []); | 4631 ClassElement nonPrefixedType = ElementFactory.classElement2(typeName, []); |
| 4633 LibraryElement prefixedLibrary = createTestLibrary(context, "import.prefixed
", []); | 4632 LibraryElement prefixedLibrary = createTestLibrary(context, "import.prefixed
", []); |
| 4634 (prefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type
s = <ClassElement> [prefixedType]; | 4633 (prefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type
s = <ClassElement> [prefixedType]; |
| 4635 ImportElementImpl prefixedImport = ElementFactory.importFor(prefixedLibrary,
ElementFactory.prefix(prefixName), []); | 4634 ImportElementImpl prefixedImport = ElementFactory.importFor(prefixedLibrary,
ElementFactory.prefix(prefixName), []); |
| 4636 LibraryElement nonPrefixedLibrary = createTestLibrary(context, "import.nonPr
efixed", []); | 4635 LibraryElement nonPrefixedLibrary = createTestLibrary(context, "import.nonPr
efixed", []); |
| 4637 (nonPrefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl).t
ypes = <ClassElement> [nonPrefixedType]; | 4636 (nonPrefixedLibrary.definingCompilationUnit as CompilationUnitElementImpl).t
ypes = <ClassElement> [nonPrefixedType]; |
| 4638 ImportElementImpl nonPrefixedImport = ElementFactory.importFor(nonPrefixedLi
brary, null, []); | 4637 ImportElementImpl nonPrefixedImport = ElementFactory.importFor(nonPrefixedLi
brary, null, []); |
| 4639 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing"
, []); | 4638 LibraryElementImpl importingLibrary = createTestLibrary(context, "importing"
, []); |
| 4640 importingLibrary.imports = <ImportElement> [prefixedImport, nonPrefixedImpor
t]; | 4639 importingLibrary.imports = <ImportElement> [prefixedImport, nonPrefixedImpor
t]; |
| 4641 GatheringErrorListener errorListener = new GatheringErrorListener(); | 4640 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 4642 Scope scope = new LibraryImportScope(importingLibrary, errorListener); | 4641 Scope scope = new LibraryImportScope(importingLibrary, errorListener); |
| 4643 Element prefixedElement = scope.lookup(AstFactory.identifier5(prefixName, ty
peName), importingLibrary); | 4642 Element prefixedElement = scope.lookup(AstFactory.identifier5(prefixName, ty
peName), importingLibrary); |
| 4644 errorListener.assertNoErrors(); | 4643 errorListener.assertNoErrors(); |
| 4645 JUnitTestCase.assertSame(prefixedType, prefixedElement); | 4644 expect(prefixedElement, same(prefixedType)); |
| 4646 Element nonPrefixedElement = scope.lookup(AstFactory.identifier3(typeName),
importingLibrary); | 4645 Element nonPrefixedElement = scope.lookup(AstFactory.identifier3(typeName),
importingLibrary); |
| 4647 errorListener.assertNoErrors(); | 4646 errorListener.assertNoErrors(); |
| 4648 JUnitTestCase.assertSame(nonPrefixedType, nonPrefixedElement); | 4647 expect(nonPrefixedElement, same(nonPrefixedType)); |
| 4649 } | 4648 } |
| 4650 } | 4649 } |
| 4651 | 4650 |
| 4652 class LibraryResolver2Test extends ResolverTestCase { | 4651 class LibraryResolver2Test extends ResolverTestCase { |
| 4653 LibraryResolver2 _resolver; | 4652 LibraryResolver2 _resolver; |
| 4654 | 4653 |
| 4655 Source _coreLibrarySource; | 4654 Source _coreLibrarySource; |
| 4656 | 4655 |
| 4657 @override | 4656 @override |
| 4658 void setUp() { | 4657 void setUp() { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4747 String importedTypeName = "A"; | 4746 String importedTypeName = "A"; |
| 4748 ClassElement importedType = new ClassElementImpl.forNode(AstFactory.identifi
er3(importedTypeName)); | 4747 ClassElement importedType = new ClassElementImpl.forNode(AstFactory.identifi
er3(importedTypeName)); |
| 4749 LibraryElement importedLibrary = createTestLibrary(context, "imported", []); | 4748 LibraryElement importedLibrary = createTestLibrary(context, "imported", []); |
| 4750 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type
s = <ClassElement> [importedType]; | 4749 (importedLibrary.definingCompilationUnit as CompilationUnitElementImpl).type
s = <ClassElement> [importedType]; |
| 4751 LibraryElementImpl definingLibrary = createTestLibrary(context, "importing",
[]); | 4750 LibraryElementImpl definingLibrary = createTestLibrary(context, "importing",
[]); |
| 4752 ImportElementImpl importElement = new ImportElementImpl(0); | 4751 ImportElementImpl importElement = new ImportElementImpl(0); |
| 4753 importElement.importedLibrary = importedLibrary; | 4752 importElement.importedLibrary = importedLibrary; |
| 4754 definingLibrary.imports = <ImportElement> [importElement]; | 4753 definingLibrary.imports = <ImportElement> [importElement]; |
| 4755 GatheringErrorListener errorListener = new GatheringErrorListener(); | 4754 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 4756 Scope scope = new LibraryScope(definingLibrary, errorListener); | 4755 Scope scope = new LibraryScope(definingLibrary, errorListener); |
| 4757 JUnitTestCase.assertEquals(importedType, scope.lookup(AstFactory.identifier3
(importedTypeName), definingLibrary)); | 4756 expect(scope.lookup(AstFactory.identifier3(importedTypeName), definingLibrar
y), importedType); |
| 4758 } | 4757 } |
| 4759 | 4758 |
| 4760 void test_getErrorListener() { | 4759 void test_getErrorListener() { |
| 4761 LibraryElement definingLibrary = createDefaultTestLibrary(); | 4760 LibraryElement definingLibrary = createDefaultTestLibrary(); |
| 4762 GatheringErrorListener errorListener = new GatheringErrorListener(); | 4761 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 4763 LibraryScope scope = new LibraryScope(definingLibrary, errorListener); | 4762 LibraryScope scope = new LibraryScope(definingLibrary, errorListener); |
| 4764 JUnitTestCase.assertEquals(errorListener, scope.errorListener); | 4763 expect(scope.errorListener, errorListener); |
| 4765 } | 4764 } |
| 4766 } | 4765 } |
| 4767 | 4766 |
| 4768 class LibraryTest extends EngineTestCase { | 4767 class LibraryTest extends EngineTestCase { |
| 4769 /** | 4768 /** |
| 4770 * The error listener to which all errors will be reported. | 4769 * The error listener to which all errors will be reported. |
| 4771 */ | 4770 */ |
| 4772 GatheringErrorListener _errorListener; | 4771 GatheringErrorListener _errorListener; |
| 4773 | 4772 |
| 4774 /** | 4773 /** |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4789 @override | 4788 @override |
| 4790 void setUp() { | 4789 void setUp() { |
| 4791 _sourceFactory = new SourceFactory([new FileUriResolver()]); | 4790 _sourceFactory = new SourceFactory([new FileUriResolver()]); |
| 4792 _analysisContext = new AnalysisContextImpl(); | 4791 _analysisContext = new AnalysisContextImpl(); |
| 4793 _analysisContext.sourceFactory = _sourceFactory; | 4792 _analysisContext.sourceFactory = _sourceFactory; |
| 4794 _errorListener = new GatheringErrorListener(); | 4793 _errorListener = new GatheringErrorListener(); |
| 4795 _library = _createLibrary("/lib.dart"); | 4794 _library = _createLibrary("/lib.dart"); |
| 4796 } | 4795 } |
| 4797 | 4796 |
| 4798 void test_getExplicitlyImportsCore() { | 4797 void test_getExplicitlyImportsCore() { |
| 4799 JUnitTestCase.assertFalse(_library.explicitlyImportsCore); | 4798 expect(_library.explicitlyImportsCore, isFalse); |
| 4800 _errorListener.assertNoErrors(); | 4799 _errorListener.assertNoErrors(); |
| 4801 } | 4800 } |
| 4802 | 4801 |
| 4803 void test_getExports() { | 4802 void test_getExports() { |
| 4804 EngineTestCase.assertLength(0, _library.exports); | 4803 EngineTestCase.assertLength(0, _library.exports); |
| 4805 _errorListener.assertNoErrors(); | 4804 _errorListener.assertNoErrors(); |
| 4806 } | 4805 } |
| 4807 | 4806 |
| 4808 void test_getImports() { | 4807 void test_getImports() { |
| 4809 EngineTestCase.assertLength(0, _library.imports); | 4808 EngineTestCase.assertLength(0, _library.imports); |
| 4810 _errorListener.assertNoErrors(); | 4809 _errorListener.assertNoErrors(); |
| 4811 } | 4810 } |
| 4812 | 4811 |
| 4813 void test_getImportsAndExports() { | 4812 void test_getImportsAndExports() { |
| 4814 _library.importedLibraries = <Library> [_createLibrary("/imported.dart")]; | 4813 _library.importedLibraries = <Library> [_createLibrary("/imported.dart")]; |
| 4815 _library.exportedLibraries = <Library> [_createLibrary("/exported.dart")]; | 4814 _library.exportedLibraries = <Library> [_createLibrary("/exported.dart")]; |
| 4816 EngineTestCase.assertLength(2, _library.importsAndExports); | 4815 EngineTestCase.assertLength(2, _library.importsAndExports); |
| 4817 _errorListener.assertNoErrors(); | 4816 _errorListener.assertNoErrors(); |
| 4818 } | 4817 } |
| 4819 | 4818 |
| 4820 void test_getLibraryScope() { | 4819 void test_getLibraryScope() { |
| 4821 LibraryElementImpl element = new LibraryElementImpl.forNode(_analysisContext
, AstFactory.libraryIdentifier2(["lib"])); | 4820 LibraryElementImpl element = new LibraryElementImpl.forNode(_analysisContext
, AstFactory.libraryIdentifier2(["lib"])); |
| 4822 element.definingCompilationUnit = new CompilationUnitElementImpl("lib.dart")
; | 4821 element.definingCompilationUnit = new CompilationUnitElementImpl("lib.dart")
; |
| 4823 _library.libraryElement = element; | 4822 _library.libraryElement = element; |
| 4824 JUnitTestCase.assertNotNull(_library.libraryScope); | 4823 expect(_library.libraryScope, isNotNull); |
| 4825 _errorListener.assertNoErrors(); | 4824 _errorListener.assertNoErrors(); |
| 4826 } | 4825 } |
| 4827 | 4826 |
| 4828 void test_getLibrarySource() { | 4827 void test_getLibrarySource() { |
| 4829 JUnitTestCase.assertNotNull(_library.librarySource); | 4828 expect(_library.librarySource, isNotNull); |
| 4830 } | 4829 } |
| 4831 | 4830 |
| 4832 void test_setExplicitlyImportsCore() { | 4831 void test_setExplicitlyImportsCore() { |
| 4833 _library.explicitlyImportsCore = true; | 4832 _library.explicitlyImportsCore = true; |
| 4834 JUnitTestCase.assertTrue(_library.explicitlyImportsCore); | 4833 expect(_library.explicitlyImportsCore, isTrue); |
| 4835 _errorListener.assertNoErrors(); | 4834 _errorListener.assertNoErrors(); |
| 4836 } | 4835 } |
| 4837 | 4836 |
| 4838 void test_setExportedLibraries() { | 4837 void test_setExportedLibraries() { |
| 4839 Library exportLibrary = _createLibrary("/exported.dart"); | 4838 Library exportLibrary = _createLibrary("/exported.dart"); |
| 4840 _library.exportedLibraries = <Library> [exportLibrary]; | 4839 _library.exportedLibraries = <Library> [exportLibrary]; |
| 4841 List<Library> exports = _library.exports; | 4840 List<Library> exports = _library.exports; |
| 4842 EngineTestCase.assertLength(1, exports); | 4841 EngineTestCase.assertLength(1, exports); |
| 4843 JUnitTestCase.assertSame(exportLibrary, exports[0]); | 4842 expect(exports[0], same(exportLibrary)); |
| 4844 _errorListener.assertNoErrors(); | 4843 _errorListener.assertNoErrors(); |
| 4845 } | 4844 } |
| 4846 | 4845 |
| 4847 void test_setImportedLibraries() { | 4846 void test_setImportedLibraries() { |
| 4848 Library importLibrary = _createLibrary("/imported.dart"); | 4847 Library importLibrary = _createLibrary("/imported.dart"); |
| 4849 _library.importedLibraries = <Library> [importLibrary]; | 4848 _library.importedLibraries = <Library> [importLibrary]; |
| 4850 List<Library> imports = _library.imports; | 4849 List<Library> imports = _library.imports; |
| 4851 EngineTestCase.assertLength(1, imports); | 4850 EngineTestCase.assertLength(1, imports); |
| 4852 JUnitTestCase.assertSame(importLibrary, imports[0]); | 4851 expect(imports[0], same(importLibrary)); |
| 4853 _errorListener.assertNoErrors(); | 4852 _errorListener.assertNoErrors(); |
| 4854 } | 4853 } |
| 4855 | 4854 |
| 4856 void test_setLibraryElement() { | 4855 void test_setLibraryElement() { |
| 4857 LibraryElementImpl element = new LibraryElementImpl.forNode(_analysisContext
, AstFactory.libraryIdentifier2(["lib"])); | 4856 LibraryElementImpl element = new LibraryElementImpl.forNode(_analysisContext
, AstFactory.libraryIdentifier2(["lib"])); |
| 4858 _library.libraryElement = element; | 4857 _library.libraryElement = element; |
| 4859 JUnitTestCase.assertSame(element, _library.libraryElement); | 4858 expect(_library.libraryElement, same(element)); |
| 4860 } | 4859 } |
| 4861 | 4860 |
| 4862 @override | 4861 @override |
| 4863 void tearDown() { | 4862 void tearDown() { |
| 4864 _errorListener = null; | 4863 _errorListener = null; |
| 4865 _sourceFactory = null; | 4864 _sourceFactory = null; |
| 4866 _analysisContext = null; | 4865 _analysisContext = null; |
| 4867 _library = null; | 4866 _library = null; |
| 4868 super.tearDown(); | 4867 super.tearDown(); |
| 4869 } | 4868 } |
| 4870 | 4869 |
| 4871 Library _createLibrary(String definingCompilationUnitPath) => new Library(_ana
lysisContext, _errorListener, new FileBasedSource.con1(FileUtilities2.createFile
(definingCompilationUnitPath))); | 4870 Library _createLibrary(String definingCompilationUnitPath) => new Library(_ana
lysisContext, _errorListener, new FileBasedSource.con1(FileUtilities2.createFile
(definingCompilationUnitPath))); |
| 4872 } | 4871 } |
| 4873 | 4872 |
| 4874 class MemberMapTest extends JUnitTestCase { | 4873 class MemberMapTest { |
| 4875 /** | 4874 /** |
| 4876 * The null type. | 4875 * The null type. |
| 4877 */ | 4876 */ |
| 4878 InterfaceType _nullType; | 4877 InterfaceType _nullType; |
| 4879 | 4878 |
| 4880 @override | |
| 4881 void setUp() { | 4879 void setUp() { |
| 4882 _nullType = new TestTypeProvider().nullType; | 4880 _nullType = new TestTypeProvider().nullType; |
| 4883 } | 4881 } |
| 4884 | 4882 |
| 4885 void test_MemberMap_copyConstructor() { | 4883 void test_MemberMap_copyConstructor() { |
| 4886 MethodElement m1 = ElementFactory.methodElement("m1", _nullType, []); | 4884 MethodElement m1 = ElementFactory.methodElement("m1", _nullType, []); |
| 4887 MethodElement m2 = ElementFactory.methodElement("m2", _nullType, []); | 4885 MethodElement m2 = ElementFactory.methodElement("m2", _nullType, []); |
| 4888 MethodElement m3 = ElementFactory.methodElement("m3", _nullType, []); | 4886 MethodElement m3 = ElementFactory.methodElement("m3", _nullType, []); |
| 4889 MemberMap map = new MemberMap(); | 4887 MemberMap map = new MemberMap(); |
| 4890 map.put(m1.name, m1); | 4888 map.put(m1.name, m1); |
| 4891 map.put(m2.name, m2); | 4889 map.put(m2.name, m2); |
| 4892 map.put(m3.name, m3); | 4890 map.put(m3.name, m3); |
| 4893 MemberMap copy = new MemberMap.con2(map); | 4891 MemberMap copy = new MemberMap.con2(map); |
| 4894 JUnitTestCase.assertEquals(map.size, copy.size); | 4892 expect(copy.size, map.size); |
| 4895 JUnitTestCase.assertEquals(m1, copy.get(m1.name)); | 4893 expect(copy.get(m1.name), m1); |
| 4896 JUnitTestCase.assertEquals(m2, copy.get(m2.name)); | 4894 expect(copy.get(m2.name), m2); |
| 4897 JUnitTestCase.assertEquals(m3, copy.get(m3.name)); | 4895 expect(copy.get(m3.name), m3); |
| 4898 } | 4896 } |
| 4899 | 4897 |
| 4900 void test_MemberMap_override() { | 4898 void test_MemberMap_override() { |
| 4901 MethodElement m1 = ElementFactory.methodElement("m", _nullType, []); | 4899 MethodElement m1 = ElementFactory.methodElement("m", _nullType, []); |
| 4902 MethodElement m2 = ElementFactory.methodElement("m", _nullType, []); | 4900 MethodElement m2 = ElementFactory.methodElement("m", _nullType, []); |
| 4903 MemberMap map = new MemberMap(); | 4901 MemberMap map = new MemberMap(); |
| 4904 map.put(m1.name, m1); | 4902 map.put(m1.name, m1); |
| 4905 map.put(m2.name, m2); | 4903 map.put(m2.name, m2); |
| 4906 JUnitTestCase.assertEquals(1, map.size); | 4904 expect(map.size, 1); |
| 4907 JUnitTestCase.assertEquals(m2, map.get("m")); | 4905 expect(map.get("m"), m2); |
| 4908 } | 4906 } |
| 4909 | 4907 |
| 4910 void test_MemberMap_put() { | 4908 void test_MemberMap_put() { |
| 4911 MethodElement m1 = ElementFactory.methodElement("m1", _nullType, []); | 4909 MethodElement m1 = ElementFactory.methodElement("m1", _nullType, []); |
| 4912 MemberMap map = new MemberMap(); | 4910 MemberMap map = new MemberMap(); |
| 4913 JUnitTestCase.assertEquals(0, map.size); | 4911 expect(map.size, 0); |
| 4914 map.put(m1.name, m1); | 4912 map.put(m1.name, m1); |
| 4915 JUnitTestCase.assertEquals(1, map.size); | 4913 expect(map.size, 1); |
| 4916 JUnitTestCase.assertEquals(m1, map.get("m1")); | 4914 expect(map.get("m1"), m1); |
| 4917 } | 4915 } |
| 4918 } | 4916 } |
| 4919 | 4917 |
| 4920 class NonHintCodeTest extends ResolverTestCase { | 4918 class NonHintCodeTest extends ResolverTestCase { |
| 4921 void test_deadCode_deadBlock_conditionalElse_debugConst() { | 4919 void test_deadCode_deadBlock_conditionalElse_debugConst() { |
| 4922 Source source = addSource(r''' | 4920 Source source = addSource(r''' |
| 4923 const bool DEBUG = true; | 4921 const bool DEBUG = true; |
| 4924 f() { | 4922 f() { |
| 4925 DEBUG ? 1 : 2; | 4923 DEBUG ? 1 : 2; |
| 4926 }'''); | 4924 }'''); |
| (...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5914 | 5912 |
| 5915 RecursiveAstVisitor_SimpleResolverTest_test_localVariable_types_invoked(this.S
impleResolverTest_this, this.found, this.thrownException) : super(); | 5913 RecursiveAstVisitor_SimpleResolverTest_test_localVariable_types_invoked(this.S
impleResolverTest_this, this.found, this.thrownException) : super(); |
| 5916 | 5914 |
| 5917 @override | 5915 @override |
| 5918 Object visitSimpleIdentifier(SimpleIdentifier node) { | 5916 Object visitSimpleIdentifier(SimpleIdentifier node) { |
| 5919 if (node.name == "myVar" && node.parent is MethodInvocation) { | 5917 if (node.name == "myVar" && node.parent is MethodInvocation) { |
| 5920 try { | 5918 try { |
| 5921 found[0] = true; | 5919 found[0] = true; |
| 5922 // check static type | 5920 // check static type |
| 5923 DartType staticType = node.staticType; | 5921 DartType staticType = node.staticType; |
| 5924 JUnitTestCase.assertSame(SimpleResolverTest_this.typeProvider.dynamicTyp
e, staticType); | 5922 expect(staticType, same(SimpleResolverTest_this.typeProvider.dynamicType
)); |
| 5925 // check propagated type | 5923 // check propagated type |
| 5926 FunctionType propagatedType = node.propagatedType as FunctionType; | 5924 FunctionType propagatedType = node.propagatedType as FunctionType; |
| 5927 JUnitTestCase.assertEquals(SimpleResolverTest_this.typeProvider.stringTy
pe, propagatedType.returnType); | 5925 expect(propagatedType.returnType, SimpleResolverTest_this.typeProvider.s
tringType); |
| 5928 } on AnalysisException catch (e, stackTrace) { | 5926 } on AnalysisException catch (e, stackTrace) { |
| 5929 thrownException[0] = new CaughtException(e, stackTrace); | 5927 thrownException[0] = new CaughtException(e, stackTrace); |
| 5930 } | 5928 } |
| 5931 } | 5929 } |
| 5932 return null; | 5930 return null; |
| 5933 } | 5931 } |
| 5934 } | 5932 } |
| 5935 | 5933 |
| 5936 /** | 5934 /** |
| 5937 * Instances of the class `ResolutionVerifier` verify that all of the nodes in a
n AST | 5935 * Instances of the class `ResolutionVerifier` verify that all of the nodes in a
n AST |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5982 buffer.write(_unresolvedNodes.length); | 5980 buffer.write(_unresolvedNodes.length); |
| 5983 buffer.writeln(" nodes:"); | 5981 buffer.writeln(" nodes:"); |
| 5984 _printNodes(buffer, _unresolvedNodes); | 5982 _printNodes(buffer, _unresolvedNodes); |
| 5985 } | 5983 } |
| 5986 if (!_wrongTypedNodes.isEmpty) { | 5984 if (!_wrongTypedNodes.isEmpty) { |
| 5987 buffer.write("Resolved "); | 5985 buffer.write("Resolved "); |
| 5988 buffer.write(_wrongTypedNodes.length); | 5986 buffer.write(_wrongTypedNodes.length); |
| 5989 buffer.writeln(" to the wrong type of element:"); | 5987 buffer.writeln(" to the wrong type of element:"); |
| 5990 _printNodes(buffer, _wrongTypedNodes); | 5988 _printNodes(buffer, _wrongTypedNodes); |
| 5991 } | 5989 } |
| 5992 JUnitTestCase.fail(buffer.toString()); | 5990 fail(buffer.toString()); |
| 5993 } | 5991 } |
| 5994 } | 5992 } |
| 5995 | 5993 |
| 5996 @override | 5994 @override |
| 5997 Object visitAnnotation(Annotation node) { | 5995 Object visitAnnotation(Annotation node) { |
| 5998 node.visitChildren(this); | 5996 node.visitChildren(this); |
| 5999 ElementAnnotation elementAnnotation = node.elementAnnotation; | 5997 ElementAnnotation elementAnnotation = node.elementAnnotation; |
| 6000 if (elementAnnotation == null) { | 5998 if (elementAnnotation == null) { |
| 6001 if (_knownExceptions == null || !_knownExceptions.contains(node)) { | 5999 if (_knownExceptions == null || !_knownExceptions.contains(node)) { |
| 6002 _unresolvedNodes.add(node); | 6000 _unresolvedNodes.add(node); |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6532 void test_scopeFor_MethodDeclaration_body() { | 6530 void test_scopeFor_MethodDeclaration_body() { |
| 6533 GatheringErrorListener listener = new GatheringErrorListener(); | 6531 GatheringErrorListener listener = new GatheringErrorListener(); |
| 6534 Scope scope = ScopeBuilder.scopeFor(_createResolvedMethodDeclaration().body,
listener); | 6532 Scope scope = ScopeBuilder.scopeFor(_createResolvedMethodDeclaration().body,
listener); |
| 6535 EngineTestCase.assertInstanceOf((obj) => obj is FunctionScope, FunctionScope
, scope); | 6533 EngineTestCase.assertInstanceOf((obj) => obj is FunctionScope, FunctionScope
, scope); |
| 6536 } | 6534 } |
| 6537 | 6535 |
| 6538 void test_scopeFor_notInCompilationUnit() { | 6536 void test_scopeFor_notInCompilationUnit() { |
| 6539 GatheringErrorListener listener = new GatheringErrorListener(); | 6537 GatheringErrorListener listener = new GatheringErrorListener(); |
| 6540 try { | 6538 try { |
| 6541 ScopeBuilder.scopeFor(AstFactory.identifier3("x"), listener); | 6539 ScopeBuilder.scopeFor(AstFactory.identifier3("x"), listener); |
| 6542 JUnitTestCase.fail("Expected AnalysisException"); | 6540 fail("Expected AnalysisException"); |
| 6543 } on AnalysisException catch (exception) { | 6541 } on AnalysisException catch (exception) { |
| 6544 // Expected | 6542 // Expected |
| 6545 } | 6543 } |
| 6546 } | 6544 } |
| 6547 | 6545 |
| 6548 void test_scopeFor_null() { | 6546 void test_scopeFor_null() { |
| 6549 GatheringErrorListener listener = new GatheringErrorListener(); | 6547 GatheringErrorListener listener = new GatheringErrorListener(); |
| 6550 try { | 6548 try { |
| 6551 ScopeBuilder.scopeFor(null, listener); | 6549 ScopeBuilder.scopeFor(null, listener); |
| 6552 JUnitTestCase.fail("Expected AnalysisException"); | 6550 fail("Expected AnalysisException"); |
| 6553 } on AnalysisException catch (exception) { | 6551 } on AnalysisException catch (exception) { |
| 6554 // Expected | 6552 // Expected |
| 6555 } | 6553 } |
| 6556 } | 6554 } |
| 6557 | 6555 |
| 6558 void test_scopeFor_unresolved() { | 6556 void test_scopeFor_unresolved() { |
| 6559 GatheringErrorListener listener = new GatheringErrorListener(); | 6557 GatheringErrorListener listener = new GatheringErrorListener(); |
| 6560 try { | 6558 try { |
| 6561 ScopeBuilder.scopeFor(AstFactory.compilationUnit(), listener); | 6559 ScopeBuilder.scopeFor(AstFactory.compilationUnit(), listener); |
| 6562 JUnitTestCase.fail("Expected AnalysisException"); | 6560 fail("Expected AnalysisException"); |
| 6563 } on AnalysisException catch (exception) { | 6561 } on AnalysisException catch (exception) { |
| 6564 // Expected | 6562 // Expected |
| 6565 } | 6563 } |
| 6566 } | 6564 } |
| 6567 | 6565 |
| 6568 ClassDeclaration _createResolvedClassDeclaration() { | 6566 ClassDeclaration _createResolvedClassDeclaration() { |
| 6569 CompilationUnit unit = _createResolvedCompilationUnit(); | 6567 CompilationUnit unit = _createResolvedCompilationUnit(); |
| 6570 String className = "C"; | 6568 String className = "C"; |
| 6571 ClassDeclaration classNode = AstFactory.classDeclaration(null, className, As
tFactory.typeParameterList([]), null, null, null, []); | 6569 ClassDeclaration classNode = AstFactory.classDeclaration(null, className, As
tFactory.typeParameterList([]), null, null, null, []); |
| 6572 unit.declarations.add(classNode); | 6570 unit.declarations.add(classNode); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6656 VariableElement element1 = ElementFactory.localVariableElement(AstFactory.id
entifier3("v1")); | 6654 VariableElement element1 = ElementFactory.localVariableElement(AstFactory.id
entifier3("v1")); |
| 6657 VariableElement element2 = ElementFactory.localVariableElement(AstFactory.id
entifier3("v2")); | 6655 VariableElement element2 = ElementFactory.localVariableElement(AstFactory.id
entifier3("v2")); |
| 6658 scope.define(element1); | 6656 scope.define(element1); |
| 6659 scope.define(element2); | 6657 scope.define(element2); |
| 6660 errorListener.assertNoErrors(); | 6658 errorListener.assertNoErrors(); |
| 6661 } | 6659 } |
| 6662 | 6660 |
| 6663 void test_getErrorListener() { | 6661 void test_getErrorListener() { |
| 6664 GatheringErrorListener errorListener = new GatheringErrorListener(); | 6662 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 6665 ScopeTest_TestScope scope = new ScopeTest_TestScope(errorListener); | 6663 ScopeTest_TestScope scope = new ScopeTest_TestScope(errorListener); |
| 6666 JUnitTestCase.assertEquals(errorListener, scope.errorListener); | 6664 expect(scope.errorListener, errorListener); |
| 6667 } | 6665 } |
| 6668 | 6666 |
| 6669 void test_isPrivateName_nonPrivate() { | 6667 void test_isPrivateName_nonPrivate() { |
| 6670 JUnitTestCase.assertFalse(Scope.isPrivateName("Public")); | 6668 expect(Scope.isPrivateName("Public"), isFalse); |
| 6671 } | 6669 } |
| 6672 | 6670 |
| 6673 void test_isPrivateName_private() { | 6671 void test_isPrivateName_private() { |
| 6674 JUnitTestCase.assertTrue(Scope.isPrivateName("_Private")); | 6672 expect(Scope.isPrivateName("_Private"), isTrue); |
| 6675 } | 6673 } |
| 6676 } | 6674 } |
| 6677 | 6675 |
| 6678 /** | 6676 /** |
| 6679 * A non-abstract subclass that can be used for testing purposes. | 6677 * A non-abstract subclass that can be used for testing purposes. |
| 6680 */ | 6678 */ |
| 6681 class ScopeTest_TestScope extends Scope { | 6679 class ScopeTest_TestScope extends Scope { |
| 6682 /** | 6680 /** |
| 6683 * The listener that is to be informed when an error is encountered. | 6681 * The listener that is to be informed when an error is encountered. |
| 6684 */ | 6682 */ |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6844 AssignmentExpression assignment; | 6842 AssignmentExpression assignment; |
| 6845 { | 6843 { |
| 6846 FunctionElement mainElement = unit.functions[0]; | 6844 FunctionElement mainElement = unit.functions[0]; |
| 6847 FunctionBody mainBody = mainElement.node.functionExpression.body; | 6845 FunctionBody mainBody = mainElement.node.functionExpression.body; |
| 6848 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; | 6846 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; |
| 6849 ExpressionStatement expressionStatement = statement as ExpressionStatement
; | 6847 ExpressionStatement expressionStatement = statement as ExpressionStatement
; |
| 6850 assignment = expressionStatement.expression as AssignmentExpression; | 6848 assignment = expressionStatement.expression as AssignmentExpression; |
| 6851 } | 6849 } |
| 6852 // get parameter | 6850 // get parameter |
| 6853 Expression rhs = assignment.rightHandSide; | 6851 Expression rhs = assignment.rightHandSide; |
| 6854 JUnitTestCase.assertNull(rhs.staticParameterElement); | 6852 expect(rhs.staticParameterElement, isNull); |
| 6855 ParameterElement parameter = rhs.propagatedParameterElement; | 6853 ParameterElement parameter = rhs.propagatedParameterElement; |
| 6856 JUnitTestCase.assertNotNull(parameter); | 6854 expect(parameter, isNotNull); |
| 6857 JUnitTestCase.assertEquals("x", parameter.displayName); | 6855 expect(parameter.displayName, "x"); |
| 6858 // validate | 6856 // validate |
| 6859 ClassElement classA = unit.types[0]; | 6857 ClassElement classA = unit.types[0]; |
| 6860 PropertyAccessorElement setter = classA.accessors[0]; | 6858 PropertyAccessorElement setter = classA.accessors[0]; |
| 6861 JUnitTestCase.assertSame(parameter, setter.parameters[0]); | 6859 expect(setter.parameters[0], same(parameter)); |
| 6862 } | 6860 } |
| 6863 | 6861 |
| 6864 void test_argumentResolution_setter_propagated_propertyAccess() { | 6862 void test_argumentResolution_setter_propagated_propertyAccess() { |
| 6865 Source source = addSource(r''' | 6863 Source source = addSource(r''' |
| 6866 main() { | 6864 main() { |
| 6867 var a = new A(); | 6865 var a = new A(); |
| 6868 a.b.sss = 0; | 6866 a.b.sss = 0; |
| 6869 } | 6867 } |
| 6870 class A { | 6868 class A { |
| 6871 B b = new B(); | 6869 B b = new B(); |
| 6872 } | 6870 } |
| 6873 class B { | 6871 class B { |
| 6874 set sss(x) {} | 6872 set sss(x) {} |
| 6875 }'''); | 6873 }'''); |
| 6876 LibraryElement library = resolve(source); | 6874 LibraryElement library = resolve(source); |
| 6877 CompilationUnitElement unit = library.definingCompilationUnit; | 6875 CompilationUnitElement unit = library.definingCompilationUnit; |
| 6878 // find "a.b.sss = 0" | 6876 // find "a.b.sss = 0" |
| 6879 AssignmentExpression assignment; | 6877 AssignmentExpression assignment; |
| 6880 { | 6878 { |
| 6881 FunctionElement mainElement = unit.functions[0]; | 6879 FunctionElement mainElement = unit.functions[0]; |
| 6882 FunctionBody mainBody = mainElement.node.functionExpression.body; | 6880 FunctionBody mainBody = mainElement.node.functionExpression.body; |
| 6883 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; | 6881 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; |
| 6884 ExpressionStatement expressionStatement = statement as ExpressionStatement
; | 6882 ExpressionStatement expressionStatement = statement as ExpressionStatement
; |
| 6885 assignment = expressionStatement.expression as AssignmentExpression; | 6883 assignment = expressionStatement.expression as AssignmentExpression; |
| 6886 } | 6884 } |
| 6887 // get parameter | 6885 // get parameter |
| 6888 Expression rhs = assignment.rightHandSide; | 6886 Expression rhs = assignment.rightHandSide; |
| 6889 JUnitTestCase.assertNull(rhs.staticParameterElement); | 6887 expect(rhs.staticParameterElement, isNull); |
| 6890 ParameterElement parameter = rhs.propagatedParameterElement; | 6888 ParameterElement parameter = rhs.propagatedParameterElement; |
| 6891 JUnitTestCase.assertNotNull(parameter); | 6889 expect(parameter, isNotNull); |
| 6892 JUnitTestCase.assertEquals("x", parameter.displayName); | 6890 expect(parameter.displayName, "x"); |
| 6893 // validate | 6891 // validate |
| 6894 ClassElement classB = unit.types[1]; | 6892 ClassElement classB = unit.types[1]; |
| 6895 PropertyAccessorElement setter = classB.accessors[0]; | 6893 PropertyAccessorElement setter = classB.accessors[0]; |
| 6896 JUnitTestCase.assertSame(parameter, setter.parameters[0]); | 6894 expect(setter.parameters[0], same(parameter)); |
| 6897 } | 6895 } |
| 6898 | 6896 |
| 6899 void test_argumentResolution_setter_static() { | 6897 void test_argumentResolution_setter_static() { |
| 6900 Source source = addSource(r''' | 6898 Source source = addSource(r''' |
| 6901 main() { | 6899 main() { |
| 6902 A a = new A(); | 6900 A a = new A(); |
| 6903 a.sss = 0; | 6901 a.sss = 0; |
| 6904 } | 6902 } |
| 6905 class A { | 6903 class A { |
| 6906 set sss(x) {} | 6904 set sss(x) {} |
| 6907 }'''); | 6905 }'''); |
| 6908 LibraryElement library = resolve(source); | 6906 LibraryElement library = resolve(source); |
| 6909 CompilationUnitElement unit = library.definingCompilationUnit; | 6907 CompilationUnitElement unit = library.definingCompilationUnit; |
| 6910 // find "a.sss = 0" | 6908 // find "a.sss = 0" |
| 6911 AssignmentExpression assignment; | 6909 AssignmentExpression assignment; |
| 6912 { | 6910 { |
| 6913 FunctionElement mainElement = unit.functions[0]; | 6911 FunctionElement mainElement = unit.functions[0]; |
| 6914 FunctionBody mainBody = mainElement.node.functionExpression.body; | 6912 FunctionBody mainBody = mainElement.node.functionExpression.body; |
| 6915 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; | 6913 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; |
| 6916 ExpressionStatement expressionStatement = statement as ExpressionStatement
; | 6914 ExpressionStatement expressionStatement = statement as ExpressionStatement
; |
| 6917 assignment = expressionStatement.expression as AssignmentExpression; | 6915 assignment = expressionStatement.expression as AssignmentExpression; |
| 6918 } | 6916 } |
| 6919 // get parameter | 6917 // get parameter |
| 6920 Expression rhs = assignment.rightHandSide; | 6918 Expression rhs = assignment.rightHandSide; |
| 6921 ParameterElement parameter = rhs.staticParameterElement; | 6919 ParameterElement parameter = rhs.staticParameterElement; |
| 6922 JUnitTestCase.assertNotNull(parameter); | 6920 expect(parameter, isNotNull); |
| 6923 JUnitTestCase.assertEquals("x", parameter.displayName); | 6921 expect(parameter.displayName, "x"); |
| 6924 // validate | 6922 // validate |
| 6925 ClassElement classA = unit.types[0]; | 6923 ClassElement classA = unit.types[0]; |
| 6926 PropertyAccessorElement setter = classA.accessors[0]; | 6924 PropertyAccessorElement setter = classA.accessors[0]; |
| 6927 JUnitTestCase.assertSame(parameter, setter.parameters[0]); | 6925 expect(setter.parameters[0], same(parameter)); |
| 6928 } | 6926 } |
| 6929 | 6927 |
| 6930 void test_argumentResolution_setter_static_propertyAccess() { | 6928 void test_argumentResolution_setter_static_propertyAccess() { |
| 6931 Source source = addSource(r''' | 6929 Source source = addSource(r''' |
| 6932 main() { | 6930 main() { |
| 6933 A a = new A(); | 6931 A a = new A(); |
| 6934 a.b.sss = 0; | 6932 a.b.sss = 0; |
| 6935 } | 6933 } |
| 6936 class A { | 6934 class A { |
| 6937 B b = new B(); | 6935 B b = new B(); |
| 6938 } | 6936 } |
| 6939 class B { | 6937 class B { |
| 6940 set sss(x) {} | 6938 set sss(x) {} |
| 6941 }'''); | 6939 }'''); |
| 6942 LibraryElement library = resolve(source); | 6940 LibraryElement library = resolve(source); |
| 6943 CompilationUnitElement unit = library.definingCompilationUnit; | 6941 CompilationUnitElement unit = library.definingCompilationUnit; |
| 6944 // find "a.b.sss = 0" | 6942 // find "a.b.sss = 0" |
| 6945 AssignmentExpression assignment; | 6943 AssignmentExpression assignment; |
| 6946 { | 6944 { |
| 6947 FunctionElement mainElement = unit.functions[0]; | 6945 FunctionElement mainElement = unit.functions[0]; |
| 6948 FunctionBody mainBody = mainElement.node.functionExpression.body; | 6946 FunctionBody mainBody = mainElement.node.functionExpression.body; |
| 6949 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; | 6947 Statement statement = (mainBody as BlockFunctionBody).block.statements[1]; |
| 6950 ExpressionStatement expressionStatement = statement as ExpressionStatement
; | 6948 ExpressionStatement expressionStatement = statement as ExpressionStatement
; |
| 6951 assignment = expressionStatement.expression as AssignmentExpression; | 6949 assignment = expressionStatement.expression as AssignmentExpression; |
| 6952 } | 6950 } |
| 6953 // get parameter | 6951 // get parameter |
| 6954 Expression rhs = assignment.rightHandSide; | 6952 Expression rhs = assignment.rightHandSide; |
| 6955 ParameterElement parameter = rhs.staticParameterElement; | 6953 ParameterElement parameter = rhs.staticParameterElement; |
| 6956 JUnitTestCase.assertNotNull(parameter); | 6954 expect(parameter, isNotNull); |
| 6957 JUnitTestCase.assertEquals("x", parameter.displayName); | 6955 expect(parameter.displayName, "x"); |
| 6958 // validate | 6956 // validate |
| 6959 ClassElement classB = unit.types[1]; | 6957 ClassElement classB = unit.types[1]; |
| 6960 PropertyAccessorElement setter = classB.accessors[0]; | 6958 PropertyAccessorElement setter = classB.accessors[0]; |
| 6961 JUnitTestCase.assertSame(parameter, setter.parameters[0]); | 6959 expect(setter.parameters[0], same(parameter)); |
| 6962 } | 6960 } |
| 6963 | 6961 |
| 6964 void test_class_definesCall() { | 6962 void test_class_definesCall() { |
| 6965 Source source = addSource(r''' | 6963 Source source = addSource(r''' |
| 6966 class A { | 6964 class A { |
| 6967 int call(int x) { return x; } | 6965 int call(int x) { return x; } |
| 6968 } | 6966 } |
| 6969 int f(A a) { | 6967 int f(A a) { |
| 6970 return a(0); | 6968 return a(0); |
| 6971 }'''); | 6969 }'''); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7028 } | 7026 } |
| 7029 | 7027 |
| 7030 void test_entryPoint_exported() { | 7028 void test_entryPoint_exported() { |
| 7031 addNamedSource("/two.dart", r''' | 7029 addNamedSource("/two.dart", r''' |
| 7032 library two; | 7030 library two; |
| 7033 main() {}'''); | 7031 main() {}'''); |
| 7034 Source source = addNamedSource("/one.dart", r''' | 7032 Source source = addNamedSource("/one.dart", r''' |
| 7035 library one; | 7033 library one; |
| 7036 export 'two.dart';'''); | 7034 export 'two.dart';'''); |
| 7037 LibraryElement library = resolve(source); | 7035 LibraryElement library = resolve(source); |
| 7038 JUnitTestCase.assertNotNull(library); | 7036 expect(library, isNotNull); |
| 7039 FunctionElement main = library.entryPoint; | 7037 FunctionElement main = library.entryPoint; |
| 7040 JUnitTestCase.assertNotNull(main); | 7038 expect(main, isNotNull); |
| 7041 JUnitTestCase.assertNotSame(library, main.library); | 7039 expect(main.library, isNot(same(library))); |
| 7042 assertNoErrors(source); | 7040 assertNoErrors(source); |
| 7043 verify([source]); | 7041 verify([source]); |
| 7044 } | 7042 } |
| 7045 | 7043 |
| 7046 void test_entryPoint_local() { | 7044 void test_entryPoint_local() { |
| 7047 Source source = addNamedSource("/one.dart", r''' | 7045 Source source = addNamedSource("/one.dart", r''' |
| 7048 library one; | 7046 library one; |
| 7049 main() {}'''); | 7047 main() {}'''); |
| 7050 LibraryElement library = resolve(source); | 7048 LibraryElement library = resolve(source); |
| 7051 JUnitTestCase.assertNotNull(library); | 7049 expect(library, isNotNull); |
| 7052 FunctionElement main = library.entryPoint; | 7050 FunctionElement main = library.entryPoint; |
| 7053 JUnitTestCase.assertNotNull(main); | 7051 expect(main, isNotNull); |
| 7054 JUnitTestCase.assertSame(library, main.library); | 7052 expect(main.library, same(library)); |
| 7055 assertNoErrors(source); | 7053 assertNoErrors(source); |
| 7056 verify([source]); | 7054 verify([source]); |
| 7057 } | 7055 } |
| 7058 | 7056 |
| 7059 void test_entryPoint_none() { | 7057 void test_entryPoint_none() { |
| 7060 Source source = addNamedSource("/one.dart", "library one;"); | 7058 Source source = addNamedSource("/one.dart", "library one;"); |
| 7061 LibraryElement library = resolve(source); | 7059 LibraryElement library = resolve(source); |
| 7062 JUnitTestCase.assertNotNull(library); | 7060 expect(library, isNotNull); |
| 7063 JUnitTestCase.assertNull(library.entryPoint); | 7061 expect(library.entryPoint, isNull); |
| 7064 assertNoErrors(source); | 7062 assertNoErrors(source); |
| 7065 verify([source]); | 7063 verify([source]); |
| 7066 } | 7064 } |
| 7067 | 7065 |
| 7068 void test_extractedMethodAsConstant() { | 7066 void test_extractedMethodAsConstant() { |
| 7069 Source source = addSource(r''' | 7067 Source source = addSource(r''' |
| 7070 abstract class Comparable<T> { | 7068 abstract class Comparable<T> { |
| 7071 int compareTo(T other); | 7069 int compareTo(T other); |
| 7072 static int compare(Comparable a, Comparable b) => a.compareTo(b); | 7070 static int compare(Comparable a, Comparable b) => a.compareTo(b); |
| 7073 } | 7071 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7141 resolve(source); | 7139 resolve(source); |
| 7142 assertErrors(source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES])
; | 7140 assertErrors(source, [StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES])
; |
| 7143 verify([source]); | 7141 verify([source]); |
| 7144 } | 7142 } |
| 7145 | 7143 |
| 7146 void test_hasReferenceToSuper() { | 7144 void test_hasReferenceToSuper() { |
| 7147 Source source = addSource(r''' | 7145 Source source = addSource(r''' |
| 7148 class A {} | 7146 class A {} |
| 7149 class B {toString() => super.toString();}'''); | 7147 class B {toString() => super.toString();}'''); |
| 7150 LibraryElement library = resolve(source); | 7148 LibraryElement library = resolve(source); |
| 7151 JUnitTestCase.assertNotNull(library); | 7149 expect(library, isNotNull); |
| 7152 CompilationUnitElement unit = library.definingCompilationUnit; | 7150 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7153 JUnitTestCase.assertNotNull(unit); | 7151 expect(unit, isNotNull); |
| 7154 List<ClassElement> classes = unit.types; | 7152 List<ClassElement> classes = unit.types; |
| 7155 EngineTestCase.assertLength(2, classes); | 7153 EngineTestCase.assertLength(2, classes); |
| 7156 JUnitTestCase.assertFalse(classes[0].hasReferenceToSuper); | 7154 expect(classes[0].hasReferenceToSuper, isFalse); |
| 7157 JUnitTestCase.assertTrue(classes[1].hasReferenceToSuper); | 7155 expect(classes[1].hasReferenceToSuper, isTrue); |
| 7158 assertNoErrors(source); | 7156 assertNoErrors(source); |
| 7159 verify([source]); | 7157 verify([source]); |
| 7160 } | 7158 } |
| 7161 | 7159 |
| 7162 void test_import_hide() { | 7160 void test_import_hide() { |
| 7163 addNamedSource("lib1.dart", r''' | 7161 addNamedSource("lib1.dart", r''' |
| 7164 library lib1; | 7162 library lib1; |
| 7165 set foo(value) {} | 7163 set foo(value) {} |
| 7166 class A {}'''); | 7164 class A {}'''); |
| 7167 addNamedSource("lib2.dart", r''' | 7165 addNamedSource("lib2.dart", r''' |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7271 resolve(source); | 7269 resolve(source); |
| 7272 assertNoErrors(source); | 7270 assertNoErrors(source); |
| 7273 verify([source]); | 7271 verify([source]); |
| 7274 } | 7272 } |
| 7275 | 7273 |
| 7276 void test_isValidMixin_badSuperclass() { | 7274 void test_isValidMixin_badSuperclass() { |
| 7277 Source source = addSource(r''' | 7275 Source source = addSource(r''' |
| 7278 class A extends B {} | 7276 class A extends B {} |
| 7279 class B {}'''); | 7277 class B {}'''); |
| 7280 LibraryElement library = resolve(source); | 7278 LibraryElement library = resolve(source); |
| 7281 JUnitTestCase.assertNotNull(library); | 7279 expect(library, isNotNull); |
| 7282 CompilationUnitElement unit = library.definingCompilationUnit; | 7280 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7283 JUnitTestCase.assertNotNull(unit); | 7281 expect(unit, isNotNull); |
| 7284 List<ClassElement> classes = unit.types; | 7282 List<ClassElement> classes = unit.types; |
| 7285 EngineTestCase.assertLength(2, classes); | 7283 EngineTestCase.assertLength(2, classes); |
| 7286 JUnitTestCase.assertFalse(classes[0].isValidMixin); | 7284 expect(classes[0].isValidMixin, isFalse); |
| 7287 assertNoErrors(source); | 7285 assertNoErrors(source); |
| 7288 verify([source]); | 7286 verify([source]); |
| 7289 } | 7287 } |
| 7290 | 7288 |
| 7291 void test_isValidMixin_constructor() { | 7289 void test_isValidMixin_constructor() { |
| 7292 Source source = addSource(r''' | 7290 Source source = addSource(r''' |
| 7293 class A { | 7291 class A { |
| 7294 A() {} | 7292 A() {} |
| 7295 }'''); | 7293 }'''); |
| 7296 LibraryElement library = resolve(source); | 7294 LibraryElement library = resolve(source); |
| 7297 JUnitTestCase.assertNotNull(library); | 7295 expect(library, isNotNull); |
| 7298 CompilationUnitElement unit = library.definingCompilationUnit; | 7296 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7299 JUnitTestCase.assertNotNull(unit); | 7297 expect(unit, isNotNull); |
| 7300 List<ClassElement> classes = unit.types; | 7298 List<ClassElement> classes = unit.types; |
| 7301 EngineTestCase.assertLength(1, classes); | 7299 EngineTestCase.assertLength(1, classes); |
| 7302 JUnitTestCase.assertFalse(classes[0].isValidMixin); | 7300 expect(classes[0].isValidMixin, isFalse); |
| 7303 assertNoErrors(source); | 7301 assertNoErrors(source); |
| 7304 verify([source]); | 7302 verify([source]); |
| 7305 } | 7303 } |
| 7306 | 7304 |
| 7307 void test_isValidMixin_super() { | 7305 void test_isValidMixin_super() { |
| 7308 Source source = addSource(r''' | 7306 Source source = addSource(r''' |
| 7309 class A { | 7307 class A { |
| 7310 toString() { | 7308 toString() { |
| 7311 return super.toString(); | 7309 return super.toString(); |
| 7312 } | 7310 } |
| 7313 }'''); | 7311 }'''); |
| 7314 LibraryElement library = resolve(source); | 7312 LibraryElement library = resolve(source); |
| 7315 JUnitTestCase.assertNotNull(library); | 7313 expect(library, isNotNull); |
| 7316 CompilationUnitElement unit = library.definingCompilationUnit; | 7314 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7317 JUnitTestCase.assertNotNull(unit); | 7315 expect(unit, isNotNull); |
| 7318 List<ClassElement> classes = unit.types; | 7316 List<ClassElement> classes = unit.types; |
| 7319 EngineTestCase.assertLength(1, classes); | 7317 EngineTestCase.assertLength(1, classes); |
| 7320 JUnitTestCase.assertFalse(classes[0].isValidMixin); | 7318 expect(classes[0].isValidMixin, isFalse); |
| 7321 assertNoErrors(source); | 7319 assertNoErrors(source); |
| 7322 verify([source]); | 7320 verify([source]); |
| 7323 } | 7321 } |
| 7324 | 7322 |
| 7325 void test_isValidMixin_valid() { | 7323 void test_isValidMixin_valid() { |
| 7326 Source source = addSource("class A {}"); | 7324 Source source = addSource("class A {}"); |
| 7327 LibraryElement library = resolve(source); | 7325 LibraryElement library = resolve(source); |
| 7328 JUnitTestCase.assertNotNull(library); | 7326 expect(library, isNotNull); |
| 7329 CompilationUnitElement unit = library.definingCompilationUnit; | 7327 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7330 JUnitTestCase.assertNotNull(unit); | 7328 expect(unit, isNotNull); |
| 7331 List<ClassElement> classes = unit.types; | 7329 List<ClassElement> classes = unit.types; |
| 7332 EngineTestCase.assertLength(1, classes); | 7330 EngineTestCase.assertLength(1, classes); |
| 7333 JUnitTestCase.assertTrue(classes[0].isValidMixin); | 7331 expect(classes[0].isValidMixin, isTrue); |
| 7334 assertNoErrors(source); | 7332 assertNoErrors(source); |
| 7335 verify([source]); | 7333 verify([source]); |
| 7336 } | 7334 } |
| 7337 | 7335 |
| 7338 void test_labels_switch() { | 7336 void test_labels_switch() { |
| 7339 Source source = addSource(r''' | 7337 Source source = addSource(r''' |
| 7340 void doSwitch(int target) { | 7338 void doSwitch(int target) { |
| 7341 switch (target) { | 7339 switch (target) { |
| 7342 l0: case 0: | 7340 l0: case 0: |
| 7343 continue l1; | 7341 continue l1; |
| 7344 l1: case 1: | 7342 l1: case 1: |
| 7345 continue l0; | 7343 continue l0; |
| 7346 default: | 7344 default: |
| 7347 continue l1; | 7345 continue l1; |
| 7348 } | 7346 } |
| 7349 }'''); | 7347 }'''); |
| 7350 LibraryElement library = resolve(source); | 7348 LibraryElement library = resolve(source); |
| 7351 JUnitTestCase.assertNotNull(library); | 7349 expect(library, isNotNull); |
| 7352 assertNoErrors(source); | 7350 assertNoErrors(source); |
| 7353 verify([source]); | 7351 verify([source]); |
| 7354 } | 7352 } |
| 7355 | 7353 |
| 7356 void test_localVariable_types_invoked() { | 7354 void test_localVariable_types_invoked() { |
| 7357 Source source = addSource(r''' | 7355 Source source = addSource(r''' |
| 7358 const A = null; | 7356 const A = null; |
| 7359 main() { | 7357 main() { |
| 7360 var myVar = (int p) => 'foo'; | 7358 var myVar = (int p) => 'foo'; |
| 7361 myVar(42); | 7359 myVar(42); |
| 7362 }'''); | 7360 }'''); |
| 7363 LibraryElement library = resolve(source); | 7361 LibraryElement library = resolve(source); |
| 7364 JUnitTestCase.assertNotNull(library); | 7362 expect(library, isNotNull); |
| 7365 CompilationUnit unit = analysisContext.getResolvedCompilationUnit(source, li
brary); | 7363 CompilationUnit unit = analysisContext.getResolvedCompilationUnit(source, li
brary); |
| 7366 JUnitTestCase.assertNotNull(unit); | 7364 expect(unit, isNotNull); |
| 7367 List<bool> found = [false]; | 7365 List<bool> found = [false]; |
| 7368 List<CaughtException> thrownException = new List<CaughtException>(1); | 7366 List<CaughtException> thrownException = new List<CaughtException>(1); |
| 7369 unit.accept(new RecursiveAstVisitor_SimpleResolverTest_test_localVariable_ty
pes_invoked(this, found, thrownException)); | 7367 unit.accept(new RecursiveAstVisitor_SimpleResolverTest_test_localVariable_ty
pes_invoked(this, found, thrownException)); |
| 7370 if (thrownException[0] != null) { | 7368 if (thrownException[0] != null) { |
| 7371 throw new AnalysisException("Exception", new CaughtException(thrownExcepti
on[0], null)); | 7369 throw new AnalysisException("Exception", new CaughtException(thrownExcepti
on[0], null)); |
| 7372 } | 7370 } |
| 7373 JUnitTestCase.assertTrue(found[0]); | 7371 expect(found[0], isTrue); |
| 7374 } | 7372 } |
| 7375 | 7373 |
| 7376 void test_metadata_class() { | 7374 void test_metadata_class() { |
| 7377 Source source = addSource(r''' | 7375 Source source = addSource(r''' |
| 7378 const A = null; | 7376 const A = null; |
| 7379 @A class C<A> {}'''); | 7377 @A class C<A> {}'''); |
| 7380 LibraryElement library = resolve(source); | 7378 LibraryElement library = resolve(source); |
| 7381 JUnitTestCase.assertNotNull(library); | 7379 expect(library, isNotNull); |
| 7382 CompilationUnitElement unitElement = library.definingCompilationUnit; | 7380 CompilationUnitElement unitElement = library.definingCompilationUnit; |
| 7383 JUnitTestCase.assertNotNull(unitElement); | 7381 expect(unitElement, isNotNull); |
| 7384 List<ClassElement> classes = unitElement.types; | 7382 List<ClassElement> classes = unitElement.types; |
| 7385 EngineTestCase.assertLength(1, classes); | 7383 EngineTestCase.assertLength(1, classes); |
| 7386 List<ElementAnnotation> annotations = classes[0].metadata; | 7384 List<ElementAnnotation> annotations = classes[0].metadata; |
| 7387 EngineTestCase.assertLength(1, annotations); | 7385 EngineTestCase.assertLength(1, annotations); |
| 7388 assertNoErrors(source); | 7386 assertNoErrors(source); |
| 7389 verify([source]); | 7387 verify([source]); |
| 7390 CompilationUnit unit = resolveCompilationUnit(source, library); | 7388 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 7391 NodeList<CompilationUnitMember> declarations = unit.declarations; | 7389 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 7392 EngineTestCase.assertSizeOfList(2, declarations); | 7390 EngineTestCase.assertSizeOfList(2, declarations); |
| 7393 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration).v
ariables.variables[0].name.staticElement; | 7391 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration).v
ariables.variables[0].name.staticElement; |
| 7394 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, Pro
pertyInducingElement, expectedElement); | 7392 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, Pro
pertyInducingElement, expectedElement); |
| 7395 expectedElement = (expectedElement as PropertyInducingElement).getter; | 7393 expectedElement = (expectedElement as PropertyInducingElement).getter; |
| 7396 Element actualElement = (declarations[1] as ClassDeclaration).metadata[0].na
me.staticElement; | 7394 Element actualElement = (declarations[1] as ClassDeclaration).metadata[0].na
me.staticElement; |
| 7397 JUnitTestCase.assertSame(expectedElement, actualElement); | 7395 expect(actualElement, same(expectedElement)); |
| 7398 } | 7396 } |
| 7399 | 7397 |
| 7400 void test_metadata_field() { | 7398 void test_metadata_field() { |
| 7401 Source source = addSource(r''' | 7399 Source source = addSource(r''' |
| 7402 const A = null; | 7400 const A = null; |
| 7403 class C { | 7401 class C { |
| 7404 @A int f; | 7402 @A int f; |
| 7405 }'''); | 7403 }'''); |
| 7406 LibraryElement library = resolve(source); | 7404 LibraryElement library = resolve(source); |
| 7407 JUnitTestCase.assertNotNull(library); | 7405 expect(library, isNotNull); |
| 7408 CompilationUnitElement unit = library.definingCompilationUnit; | 7406 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7409 JUnitTestCase.assertNotNull(unit); | 7407 expect(unit, isNotNull); |
| 7410 List<ClassElement> classes = unit.types; | 7408 List<ClassElement> classes = unit.types; |
| 7411 EngineTestCase.assertLength(1, classes); | 7409 EngineTestCase.assertLength(1, classes); |
| 7412 FieldElement field = classes[0].fields[0]; | 7410 FieldElement field = classes[0].fields[0]; |
| 7413 List<ElementAnnotation> annotations = field.metadata; | 7411 List<ElementAnnotation> annotations = field.metadata; |
| 7414 EngineTestCase.assertLength(1, annotations); | 7412 EngineTestCase.assertLength(1, annotations); |
| 7415 assertNoErrors(source); | 7413 assertNoErrors(source); |
| 7416 verify([source]); | 7414 verify([source]); |
| 7417 } | 7415 } |
| 7418 | 7416 |
| 7419 void test_metadata_fieldFormalParameter() { | 7417 void test_metadata_fieldFormalParameter() { |
| 7420 Source source = addSource(r''' | 7418 Source source = addSource(r''' |
| 7421 const A = null; | 7419 const A = null; |
| 7422 class C { | 7420 class C { |
| 7423 int f; | 7421 int f; |
| 7424 C(@A this.f); | 7422 C(@A this.f); |
| 7425 }'''); | 7423 }'''); |
| 7426 LibraryElement library = resolve(source); | 7424 LibraryElement library = resolve(source); |
| 7427 JUnitTestCase.assertNotNull(library); | 7425 expect(library, isNotNull); |
| 7428 CompilationUnitElement unit = library.definingCompilationUnit; | 7426 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7429 JUnitTestCase.assertNotNull(unit); | 7427 expect(unit, isNotNull); |
| 7430 List<ClassElement> classes = unit.types; | 7428 List<ClassElement> classes = unit.types; |
| 7431 EngineTestCase.assertLength(1, classes); | 7429 EngineTestCase.assertLength(1, classes); |
| 7432 List<ConstructorElement> constructors = classes[0].constructors; | 7430 List<ConstructorElement> constructors = classes[0].constructors; |
| 7433 EngineTestCase.assertLength(1, constructors); | 7431 EngineTestCase.assertLength(1, constructors); |
| 7434 List<ParameterElement> parameters = constructors[0].parameters; | 7432 List<ParameterElement> parameters = constructors[0].parameters; |
| 7435 EngineTestCase.assertLength(1, parameters); | 7433 EngineTestCase.assertLength(1, parameters); |
| 7436 List<ElementAnnotation> annotations = parameters[0].metadata; | 7434 List<ElementAnnotation> annotations = parameters[0].metadata; |
| 7437 EngineTestCase.assertLength(1, annotations); | 7435 EngineTestCase.assertLength(1, annotations); |
| 7438 assertNoErrors(source); | 7436 assertNoErrors(source); |
| 7439 verify([source]); | 7437 verify([source]); |
| 7440 } | 7438 } |
| 7441 | 7439 |
| 7442 void test_metadata_function() { | 7440 void test_metadata_function() { |
| 7443 Source source = addSource(r''' | 7441 Source source = addSource(r''' |
| 7444 const A = null; | 7442 const A = null; |
| 7445 @A f() {}'''); | 7443 @A f() {}'''); |
| 7446 LibraryElement library = resolve(source); | 7444 LibraryElement library = resolve(source); |
| 7447 JUnitTestCase.assertNotNull(library); | 7445 expect(library, isNotNull); |
| 7448 CompilationUnitElement unit = library.definingCompilationUnit; | 7446 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7449 JUnitTestCase.assertNotNull(unit); | 7447 expect(unit, isNotNull); |
| 7450 List<FunctionElement> functions = unit.functions; | 7448 List<FunctionElement> functions = unit.functions; |
| 7451 EngineTestCase.assertLength(1, functions); | 7449 EngineTestCase.assertLength(1, functions); |
| 7452 List<ElementAnnotation> annotations = functions[0].metadata; | 7450 List<ElementAnnotation> annotations = functions[0].metadata; |
| 7453 EngineTestCase.assertLength(1, annotations); | 7451 EngineTestCase.assertLength(1, annotations); |
| 7454 assertNoErrors(source); | 7452 assertNoErrors(source); |
| 7455 verify([source]); | 7453 verify([source]); |
| 7456 } | 7454 } |
| 7457 | 7455 |
| 7458 void test_metadata_functionTypedParameter() { | 7456 void test_metadata_functionTypedParameter() { |
| 7459 Source source = addSource(r''' | 7457 Source source = addSource(r''' |
| 7460 const A = null; | 7458 const A = null; |
| 7461 f(@A int p(int x)) {}'''); | 7459 f(@A int p(int x)) {}'''); |
| 7462 LibraryElement library = resolve(source); | 7460 LibraryElement library = resolve(source); |
| 7463 JUnitTestCase.assertNotNull(library); | 7461 expect(library, isNotNull); |
| 7464 CompilationUnitElement unit = library.definingCompilationUnit; | 7462 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7465 JUnitTestCase.assertNotNull(unit); | 7463 expect(unit, isNotNull); |
| 7466 List<FunctionElement> functions = unit.functions; | 7464 List<FunctionElement> functions = unit.functions; |
| 7467 EngineTestCase.assertLength(1, functions); | 7465 EngineTestCase.assertLength(1, functions); |
| 7468 List<ParameterElement> parameters = functions[0].parameters; | 7466 List<ParameterElement> parameters = functions[0].parameters; |
| 7469 EngineTestCase.assertLength(1, parameters); | 7467 EngineTestCase.assertLength(1, parameters); |
| 7470 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 7468 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 7471 EngineTestCase.assertLength(1, annotations1); | 7469 EngineTestCase.assertLength(1, annotations1); |
| 7472 assertNoErrors(source); | 7470 assertNoErrors(source); |
| 7473 verify([source]); | 7471 verify([source]); |
| 7474 } | 7472 } |
| 7475 | 7473 |
| 7476 void test_metadata_libraryDirective() { | 7474 void test_metadata_libraryDirective() { |
| 7477 Source source = addSource(r''' | 7475 Source source = addSource(r''' |
| 7478 @A library lib; | 7476 @A library lib; |
| 7479 const A = null;'''); | 7477 const A = null;'''); |
| 7480 LibraryElement library = resolve(source); | 7478 LibraryElement library = resolve(source); |
| 7481 JUnitTestCase.assertNotNull(library); | 7479 expect(library, isNotNull); |
| 7482 List<ElementAnnotation> annotations = library.metadata; | 7480 List<ElementAnnotation> annotations = library.metadata; |
| 7483 EngineTestCase.assertLength(1, annotations); | 7481 EngineTestCase.assertLength(1, annotations); |
| 7484 assertNoErrors(source); | 7482 assertNoErrors(source); |
| 7485 verify([source]); | 7483 verify([source]); |
| 7486 } | 7484 } |
| 7487 | 7485 |
| 7488 void test_metadata_method() { | 7486 void test_metadata_method() { |
| 7489 Source source = addSource(r''' | 7487 Source source = addSource(r''' |
| 7490 const A = null; | 7488 const A = null; |
| 7491 class C { | 7489 class C { |
| 7492 @A void m() {} | 7490 @A void m() {} |
| 7493 }'''); | 7491 }'''); |
| 7494 LibraryElement library = resolve(source); | 7492 LibraryElement library = resolve(source); |
| 7495 JUnitTestCase.assertNotNull(library); | 7493 expect(library, isNotNull); |
| 7496 CompilationUnitElement unit = library.definingCompilationUnit; | 7494 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7497 JUnitTestCase.assertNotNull(unit); | 7495 expect(unit, isNotNull); |
| 7498 List<ClassElement> classes = unit.types; | 7496 List<ClassElement> classes = unit.types; |
| 7499 EngineTestCase.assertLength(1, classes); | 7497 EngineTestCase.assertLength(1, classes); |
| 7500 MethodElement method = classes[0].methods[0]; | 7498 MethodElement method = classes[0].methods[0]; |
| 7501 List<ElementAnnotation> annotations = method.metadata; | 7499 List<ElementAnnotation> annotations = method.metadata; |
| 7502 EngineTestCase.assertLength(1, annotations); | 7500 EngineTestCase.assertLength(1, annotations); |
| 7503 assertNoErrors(source); | 7501 assertNoErrors(source); |
| 7504 verify([source]); | 7502 verify([source]); |
| 7505 } | 7503 } |
| 7506 | 7504 |
| 7507 void test_metadata_namedParameter() { | 7505 void test_metadata_namedParameter() { |
| 7508 Source source = addSource(r''' | 7506 Source source = addSource(r''' |
| 7509 const A = null; | 7507 const A = null; |
| 7510 f({@A int p : 0}) {}'''); | 7508 f({@A int p : 0}) {}'''); |
| 7511 LibraryElement library = resolve(source); | 7509 LibraryElement library = resolve(source); |
| 7512 JUnitTestCase.assertNotNull(library); | 7510 expect(library, isNotNull); |
| 7513 CompilationUnitElement unit = library.definingCompilationUnit; | 7511 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7514 JUnitTestCase.assertNotNull(unit); | 7512 expect(unit, isNotNull); |
| 7515 List<FunctionElement> functions = unit.functions; | 7513 List<FunctionElement> functions = unit.functions; |
| 7516 EngineTestCase.assertLength(1, functions); | 7514 EngineTestCase.assertLength(1, functions); |
| 7517 List<ParameterElement> parameters = functions[0].parameters; | 7515 List<ParameterElement> parameters = functions[0].parameters; |
| 7518 EngineTestCase.assertLength(1, parameters); | 7516 EngineTestCase.assertLength(1, parameters); |
| 7519 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 7517 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 7520 EngineTestCase.assertLength(1, annotations1); | 7518 EngineTestCase.assertLength(1, annotations1); |
| 7521 assertNoErrors(source); | 7519 assertNoErrors(source); |
| 7522 verify([source]); | 7520 verify([source]); |
| 7523 } | 7521 } |
| 7524 | 7522 |
| 7525 void test_metadata_positionalParameter() { | 7523 void test_metadata_positionalParameter() { |
| 7526 Source source = addSource(r''' | 7524 Source source = addSource(r''' |
| 7527 const A = null; | 7525 const A = null; |
| 7528 f([@A int p = 0]) {}'''); | 7526 f([@A int p = 0]) {}'''); |
| 7529 LibraryElement library = resolve(source); | 7527 LibraryElement library = resolve(source); |
| 7530 JUnitTestCase.assertNotNull(library); | 7528 expect(library, isNotNull); |
| 7531 CompilationUnitElement unit = library.definingCompilationUnit; | 7529 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7532 JUnitTestCase.assertNotNull(unit); | 7530 expect(unit, isNotNull); |
| 7533 List<FunctionElement> functions = unit.functions; | 7531 List<FunctionElement> functions = unit.functions; |
| 7534 EngineTestCase.assertLength(1, functions); | 7532 EngineTestCase.assertLength(1, functions); |
| 7535 List<ParameterElement> parameters = functions[0].parameters; | 7533 List<ParameterElement> parameters = functions[0].parameters; |
| 7536 EngineTestCase.assertLength(1, parameters); | 7534 EngineTestCase.assertLength(1, parameters); |
| 7537 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 7535 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 7538 EngineTestCase.assertLength(1, annotations1); | 7536 EngineTestCase.assertLength(1, annotations1); |
| 7539 assertNoErrors(source); | 7537 assertNoErrors(source); |
| 7540 verify([source]); | 7538 verify([source]); |
| 7541 } | 7539 } |
| 7542 | 7540 |
| 7543 void test_metadata_simpleParameter() { | 7541 void test_metadata_simpleParameter() { |
| 7544 Source source = addSource(r''' | 7542 Source source = addSource(r''' |
| 7545 const A = null; | 7543 const A = null; |
| 7546 f(@A p1, @A int p2) {}'''); | 7544 f(@A p1, @A int p2) {}'''); |
| 7547 LibraryElement library = resolve(source); | 7545 LibraryElement library = resolve(source); |
| 7548 JUnitTestCase.assertNotNull(library); | 7546 expect(library, isNotNull); |
| 7549 CompilationUnitElement unit = library.definingCompilationUnit; | 7547 CompilationUnitElement unit = library.definingCompilationUnit; |
| 7550 JUnitTestCase.assertNotNull(unit); | 7548 expect(unit, isNotNull); |
| 7551 List<FunctionElement> functions = unit.functions; | 7549 List<FunctionElement> functions = unit.functions; |
| 7552 EngineTestCase.assertLength(1, functions); | 7550 EngineTestCase.assertLength(1, functions); |
| 7553 List<ParameterElement> parameters = functions[0].parameters; | 7551 List<ParameterElement> parameters = functions[0].parameters; |
| 7554 EngineTestCase.assertLength(2, parameters); | 7552 EngineTestCase.assertLength(2, parameters); |
| 7555 List<ElementAnnotation> annotations1 = parameters[0].metadata; | 7553 List<ElementAnnotation> annotations1 = parameters[0].metadata; |
| 7556 EngineTestCase.assertLength(1, annotations1); | 7554 EngineTestCase.assertLength(1, annotations1); |
| 7557 List<ElementAnnotation> annotations2 = parameters[1].metadata; | 7555 List<ElementAnnotation> annotations2 = parameters[1].metadata; |
| 7558 EngineTestCase.assertLength(1, annotations2); | 7556 EngineTestCase.assertLength(1, annotations2); |
| 7559 assertNoErrors(source); | 7557 assertNoErrors(source); |
| 7560 verify([source]); | 7558 verify([source]); |
| 7561 } | 7559 } |
| 7562 | 7560 |
| 7563 void test_metadata_typedef() { | 7561 void test_metadata_typedef() { |
| 7564 Source source = addSource(r''' | 7562 Source source = addSource(r''' |
| 7565 const A = null; | 7563 const A = null; |
| 7566 @A typedef F<A>();'''); | 7564 @A typedef F<A>();'''); |
| 7567 LibraryElement library = resolve(source); | 7565 LibraryElement library = resolve(source); |
| 7568 JUnitTestCase.assertNotNull(library); | 7566 expect(library, isNotNull); |
| 7569 CompilationUnitElement unitElement = library.definingCompilationUnit; | 7567 CompilationUnitElement unitElement = library.definingCompilationUnit; |
| 7570 JUnitTestCase.assertNotNull(unitElement); | 7568 expect(unitElement, isNotNull); |
| 7571 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases; | 7569 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases; |
| 7572 EngineTestCase.assertLength(1, aliases); | 7570 EngineTestCase.assertLength(1, aliases); |
| 7573 List<ElementAnnotation> annotations = aliases[0].metadata; | 7571 List<ElementAnnotation> annotations = aliases[0].metadata; |
| 7574 EngineTestCase.assertLength(1, annotations); | 7572 EngineTestCase.assertLength(1, annotations); |
| 7575 assertNoErrors(source); | 7573 assertNoErrors(source); |
| 7576 verify([source]); | 7574 verify([source]); |
| 7577 CompilationUnit unit = resolveCompilationUnit(source, library); | 7575 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 7578 NodeList<CompilationUnitMember> declarations = unit.declarations; | 7576 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 7579 EngineTestCase.assertSizeOfList(2, declarations); | 7577 EngineTestCase.assertSizeOfList(2, declarations); |
| 7580 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration).v
ariables.variables[0].name.staticElement; | 7578 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration).v
ariables.variables[0].name.staticElement; |
| 7581 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, Pro
pertyInducingElement, expectedElement); | 7579 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, Pro
pertyInducingElement, expectedElement); |
| 7582 expectedElement = (expectedElement as PropertyInducingElement).getter; | 7580 expectedElement = (expectedElement as PropertyInducingElement).getter; |
| 7583 Element actualElement = (declarations[1] as FunctionTypeAlias).metadata[0].n
ame.staticElement; | 7581 Element actualElement = (declarations[1] as FunctionTypeAlias).metadata[0].n
ame.staticElement; |
| 7584 JUnitTestCase.assertSame(expectedElement, actualElement); | 7582 expect(actualElement, same(expectedElement)); |
| 7585 } | 7583 } |
| 7586 | 7584 |
| 7587 void test_method_fromMixin() { | 7585 void test_method_fromMixin() { |
| 7588 Source source = addSource(r''' | 7586 Source source = addSource(r''' |
| 7589 class B { | 7587 class B { |
| 7590 bar() => 1; | 7588 bar() => 1; |
| 7591 } | 7589 } |
| 7592 class A { | 7590 class A { |
| 7593 foo() => 2; | 7591 foo() => 2; |
| 7594 } | 7592 } |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7707 * parameters at that index. Arguments that should not be resolved to a parame
ter because of an | 7705 * parameters at that index. Arguments that should not be resolved to a parame
ter because of an |
| 7708 * error can be denoted by including a negative index in the array of indices. | 7706 * error can be denoted by including a negative index in the array of indices. |
| 7709 * | 7707 * |
| 7710 * @param source the source to be resolved | 7708 * @param source the source to be resolved |
| 7711 * @param indices the array of indices used to associate arguments with parame
ters | 7709 * @param indices the array of indices used to associate arguments with parame
ters |
| 7712 * @throws Exception if the source could not be resolved or if the structure o
f the source is not | 7710 * @throws Exception if the source could not be resolved or if the structure o
f the source is not |
| 7713 * valid | 7711 * valid |
| 7714 */ | 7712 */ |
| 7715 void _validateArgumentResolution(Source source, List<int> indices) { | 7713 void _validateArgumentResolution(Source source, List<int> indices) { |
| 7716 LibraryElement library = resolve(source); | 7714 LibraryElement library = resolve(source); |
| 7717 JUnitTestCase.assertNotNull(library); | 7715 expect(library, isNotNull); |
| 7718 ClassElement classElement = library.definingCompilationUnit.types[0]; | 7716 ClassElement classElement = library.definingCompilationUnit.types[0]; |
| 7719 List<ParameterElement> parameters = classElement.methods[1].parameters; | 7717 List<ParameterElement> parameters = classElement.methods[1].parameters; |
| 7720 CompilationUnit unit = resolveCompilationUnit(source, library); | 7718 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 7721 JUnitTestCase.assertNotNull(unit); | 7719 expect(unit, isNotNull); |
| 7722 ClassDeclaration classDeclaration = unit.declarations[0] as ClassDeclaration
; | 7720 ClassDeclaration classDeclaration = unit.declarations[0] as ClassDeclaration
; |
| 7723 MethodDeclaration methodDeclaration = classDeclaration.members[0] as MethodD
eclaration; | 7721 MethodDeclaration methodDeclaration = classDeclaration.members[0] as MethodD
eclaration; |
| 7724 Block block = (methodDeclaration.body as BlockFunctionBody).block; | 7722 Block block = (methodDeclaration.body as BlockFunctionBody).block; |
| 7725 ExpressionStatement statement = block.statements[0] as ExpressionStatement; | 7723 ExpressionStatement statement = block.statements[0] as ExpressionStatement; |
| 7726 MethodInvocation invocation = statement.expression as MethodInvocation; | 7724 MethodInvocation invocation = statement.expression as MethodInvocation; |
| 7727 NodeList<Expression> arguments = invocation.argumentList.arguments; | 7725 NodeList<Expression> arguments = invocation.argumentList.arguments; |
| 7728 int argumentCount = arguments.length; | 7726 int argumentCount = arguments.length; |
| 7729 JUnitTestCase.assertEquals(indices.length, argumentCount); | 7727 expect(argumentCount, indices.length); |
| 7730 for (int i = 0; i < argumentCount; i++) { | 7728 for (int i = 0; i < argumentCount; i++) { |
| 7731 Expression argument = arguments[i]; | 7729 Expression argument = arguments[i]; |
| 7732 ParameterElement element = argument.staticParameterElement; | 7730 ParameterElement element = argument.staticParameterElement; |
| 7733 int index = indices[i]; | 7731 int index = indices[i]; |
| 7734 if (index < 0) { | 7732 if (index < 0) { |
| 7735 JUnitTestCase.assertNull(element); | 7733 expect(element, isNull); |
| 7736 } else { | 7734 } else { |
| 7737 JUnitTestCase.assertSame(parameters[index], element); | 7735 expect(element, same(parameters[index])); |
| 7738 } | 7736 } |
| 7739 } | 7737 } |
| 7740 } | 7738 } |
| 7741 } | 7739 } |
| 7742 | 7740 |
| 7743 class SourceContainer_ChangeSetTest_test_toString implements SourceContainer { | 7741 class SourceContainer_ChangeSetTest_test_toString implements SourceContainer { |
| 7744 @override | 7742 @override |
| 7745 bool contains(Source source) => false; | 7743 bool contains(Source source) => false; |
| 7746 } | 7744 } |
| 7747 | 7745 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 7760 * The analyzer being used to analyze the test cases. | 7758 * The analyzer being used to analyze the test cases. |
| 7761 */ | 7759 */ |
| 7762 StaticTypeAnalyzer _analyzer; | 7760 StaticTypeAnalyzer _analyzer; |
| 7763 | 7761 |
| 7764 /** | 7762 /** |
| 7765 * The type provider used to access the types. | 7763 * The type provider used to access the types. |
| 7766 */ | 7764 */ |
| 7767 TestTypeProvider _typeProvider; | 7765 TestTypeProvider _typeProvider; |
| 7768 | 7766 |
| 7769 void fail_visitFunctionExpressionInvocation() { | 7767 void fail_visitFunctionExpressionInvocation() { |
| 7770 JUnitTestCase.fail("Not yet tested"); | 7768 fail("Not yet tested"); |
| 7771 _listener.assertNoErrors(); | 7769 _listener.assertNoErrors(); |
| 7772 } | 7770 } |
| 7773 | 7771 |
| 7774 void fail_visitMethodInvocation() { | 7772 void fail_visitMethodInvocation() { |
| 7775 JUnitTestCase.fail("Not yet tested"); | 7773 fail("Not yet tested"); |
| 7776 _listener.assertNoErrors(); | 7774 _listener.assertNoErrors(); |
| 7777 } | 7775 } |
| 7778 | 7776 |
| 7779 void fail_visitSimpleIdentifier() { | 7777 void fail_visitSimpleIdentifier() { |
| 7780 JUnitTestCase.fail("Not yet tested"); | 7778 fail("Not yet tested"); |
| 7781 _listener.assertNoErrors(); | 7779 _listener.assertNoErrors(); |
| 7782 } | 7780 } |
| 7783 | 7781 |
| 7784 @override | 7782 @override |
| 7785 void setUp() { | 7783 void setUp() { |
| 7786 _listener = new GatheringErrorListener(); | 7784 _listener = new GatheringErrorListener(); |
| 7787 _typeProvider = new TestTypeProvider(); | 7785 _typeProvider = new TestTypeProvider(); |
| 7788 _analyzer = _createAnalyzer(); | 7786 _analyzer = _createAnalyzer(); |
| 7789 } | 7787 } |
| 7790 | 7788 |
| 7791 void test_visitAdjacentStrings() { | 7789 void test_visitAdjacentStrings() { |
| 7792 // "a" "b" | 7790 // "a" "b" |
| 7793 Expression node = AstFactory.adjacentStrings([_resolvedString("a"), _resolve
dString("b")]); | 7791 Expression node = AstFactory.adjacentStrings([_resolvedString("a"), _resolve
dString("b")]); |
| 7794 JUnitTestCase.assertSame(_typeProvider.stringType, _analyze(node)); | 7792 expect(_analyze(node), same(_typeProvider.stringType)); |
| 7795 _listener.assertNoErrors(); | 7793 _listener.assertNoErrors(); |
| 7796 } | 7794 } |
| 7797 | 7795 |
| 7798 void test_visitAsExpression() { | 7796 void test_visitAsExpression() { |
| 7799 // class A { ... this as B ... } | 7797 // class A { ... this as B ... } |
| 7800 // class B extends A {} | 7798 // class B extends A {} |
| 7801 ClassElement superclass = ElementFactory.classElement2("A", []); | 7799 ClassElement superclass = ElementFactory.classElement2("A", []); |
| 7802 InterfaceType superclassType = superclass.type; | 7800 InterfaceType superclassType = superclass.type; |
| 7803 ClassElement subclass = ElementFactory.classElement("B", superclassType, [])
; | 7801 ClassElement subclass = ElementFactory.classElement("B", superclassType, [])
; |
| 7804 Expression node = AstFactory.asExpression(AstFactory.thisExpression(), AstFa
ctory.typeName(subclass, [])); | 7802 Expression node = AstFactory.asExpression(AstFactory.thisExpression(), AstFa
ctory.typeName(subclass, [])); |
| 7805 JUnitTestCase.assertSame(subclass.type, _analyze3(node, superclassType)); | 7803 expect(_analyze3(node, superclassType), same(subclass.type)); |
| 7806 _listener.assertNoErrors(); | 7804 _listener.assertNoErrors(); |
| 7807 } | 7805 } |
| 7808 | 7806 |
| 7809 void test_visitAssignmentExpression_compound() { | 7807 void test_visitAssignmentExpression_compound() { |
| 7810 // i += 1 | 7808 // i += 1 |
| 7811 InterfaceType numType = _typeProvider.numType; | 7809 InterfaceType numType = _typeProvider.numType; |
| 7812 SimpleIdentifier identifier = _resolvedVariable(_typeProvider.intType, "i"); | 7810 SimpleIdentifier identifier = _resolvedVariable(_typeProvider.intType, "i"); |
| 7813 AssignmentExpression node = AstFactory.assignmentExpression(identifier, Toke
nType.PLUS_EQ, _resolvedInteger(1)); | 7811 AssignmentExpression node = AstFactory.assignmentExpression(identifier, Toke
nType.PLUS_EQ, _resolvedInteger(1)); |
| 7814 MethodElement plusMethod = getMethod(numType, "+"); | 7812 MethodElement plusMethod = getMethod(numType, "+"); |
| 7815 node.staticElement = plusMethod; | 7813 node.staticElement = plusMethod; |
| 7816 JUnitTestCase.assertSame(numType, _analyze(node)); | 7814 expect(_analyze(node), same(numType)); |
| 7817 _listener.assertNoErrors(); | 7815 _listener.assertNoErrors(); |
| 7818 } | 7816 } |
| 7819 | 7817 |
| 7820 void test_visitAssignmentExpression_simple() { | 7818 void test_visitAssignmentExpression_simple() { |
| 7821 // i = 0 | 7819 // i = 0 |
| 7822 InterfaceType intType = _typeProvider.intType; | 7820 InterfaceType intType = _typeProvider.intType; |
| 7823 Expression node = AstFactory.assignmentExpression(_resolvedVariable(intType,
"i"), TokenType.EQ, _resolvedInteger(0)); | 7821 Expression node = AstFactory.assignmentExpression(_resolvedVariable(intType,
"i"), TokenType.EQ, _resolvedInteger(0)); |
| 7824 JUnitTestCase.assertSame(intType, _analyze(node)); | 7822 expect(_analyze(node), same(intType)); |
| 7825 _listener.assertNoErrors(); | 7823 _listener.assertNoErrors(); |
| 7826 } | 7824 } |
| 7827 | 7825 |
| 7828 void test_visitBinaryExpression_equals() { | 7826 void test_visitBinaryExpression_equals() { |
| 7829 // 2 == 3 | 7827 // 2 == 3 |
| 7830 Expression node = AstFactory.binaryExpression(_resolvedInteger(2), TokenType
.EQ_EQ, _resolvedInteger(3)); | 7828 Expression node = AstFactory.binaryExpression(_resolvedInteger(2), TokenType
.EQ_EQ, _resolvedInteger(3)); |
| 7831 JUnitTestCase.assertSame(_typeProvider.boolType, _analyze(node)); | 7829 expect(_analyze(node), same(_typeProvider.boolType)); |
| 7832 _listener.assertNoErrors(); | 7830 _listener.assertNoErrors(); |
| 7833 } | 7831 } |
| 7834 | 7832 |
| 7835 void test_visitBinaryExpression_logicalAnd() { | 7833 void test_visitBinaryExpression_logicalAnd() { |
| 7836 // false && true | 7834 // false && true |
| 7837 Expression node = AstFactory.binaryExpression(AstFactory.booleanLiteral(fals
e), TokenType.AMPERSAND_AMPERSAND, AstFactory.booleanLiteral(true)); | 7835 Expression node = AstFactory.binaryExpression(AstFactory.booleanLiteral(fals
e), TokenType.AMPERSAND_AMPERSAND, AstFactory.booleanLiteral(true)); |
| 7838 JUnitTestCase.assertSame(_typeProvider.boolType, _analyze(node)); | 7836 expect(_analyze(node), same(_typeProvider.boolType)); |
| 7839 _listener.assertNoErrors(); | 7837 _listener.assertNoErrors(); |
| 7840 } | 7838 } |
| 7841 | 7839 |
| 7842 void test_visitBinaryExpression_logicalOr() { | 7840 void test_visitBinaryExpression_logicalOr() { |
| 7843 // false || true | 7841 // false || true |
| 7844 Expression node = AstFactory.binaryExpression(AstFactory.booleanLiteral(fals
e), TokenType.BAR_BAR, AstFactory.booleanLiteral(true)); | 7842 Expression node = AstFactory.binaryExpression(AstFactory.booleanLiteral(fals
e), TokenType.BAR_BAR, AstFactory.booleanLiteral(true)); |
| 7845 JUnitTestCase.assertSame(_typeProvider.boolType, _analyze(node)); | 7843 expect(_analyze(node), same(_typeProvider.boolType)); |
| 7846 _listener.assertNoErrors(); | 7844 _listener.assertNoErrors(); |
| 7847 } | 7845 } |
| 7848 | 7846 |
| 7849 void test_visitBinaryExpression_notEquals() { | 7847 void test_visitBinaryExpression_notEquals() { |
| 7850 // 2 != 3 | 7848 // 2 != 3 |
| 7851 Expression node = AstFactory.binaryExpression(_resolvedInteger(2), TokenType
.BANG_EQ, _resolvedInteger(3)); | 7849 Expression node = AstFactory.binaryExpression(_resolvedInteger(2), TokenType
.BANG_EQ, _resolvedInteger(3)); |
| 7852 JUnitTestCase.assertSame(_typeProvider.boolType, _analyze(node)); | 7850 expect(_analyze(node), same(_typeProvider.boolType)); |
| 7853 _listener.assertNoErrors(); | 7851 _listener.assertNoErrors(); |
| 7854 } | 7852 } |
| 7855 | 7853 |
| 7856 void test_visitBinaryExpression_plusID() { | 7854 void test_visitBinaryExpression_plusID() { |
| 7857 // 1 + 2.0 | 7855 // 1 + 2.0 |
| 7858 BinaryExpression node = AstFactory.binaryExpression(_resolvedInteger(1), Tok
enType.PLUS, _resolvedDouble(2.0)); | 7856 BinaryExpression node = AstFactory.binaryExpression(_resolvedInteger(1), Tok
enType.PLUS, _resolvedDouble(2.0)); |
| 7859 node.staticElement = getMethod(_typeProvider.numType, "+"); | 7857 node.staticElement = getMethod(_typeProvider.numType, "+"); |
| 7860 JUnitTestCase.assertSame(_typeProvider.doubleType, _analyze(node)); | 7858 expect(_analyze(node), same(_typeProvider.doubleType)); |
| 7861 _listener.assertNoErrors(); | 7859 _listener.assertNoErrors(); |
| 7862 } | 7860 } |
| 7863 | 7861 |
| 7864 void test_visitBinaryExpression_plusII() { | 7862 void test_visitBinaryExpression_plusII() { |
| 7865 // 1 + 2 | 7863 // 1 + 2 |
| 7866 BinaryExpression node = AstFactory.binaryExpression(_resolvedInteger(1), Tok
enType.PLUS, _resolvedInteger(2)); | 7864 BinaryExpression node = AstFactory.binaryExpression(_resolvedInteger(1), Tok
enType.PLUS, _resolvedInteger(2)); |
| 7867 node.staticElement = getMethod(_typeProvider.numType, "+"); | 7865 node.staticElement = getMethod(_typeProvider.numType, "+"); |
| 7868 JUnitTestCase.assertSame(_typeProvider.intType, _analyze(node)); | 7866 expect(_analyze(node), same(_typeProvider.intType)); |
| 7869 _listener.assertNoErrors(); | 7867 _listener.assertNoErrors(); |
| 7870 } | 7868 } |
| 7871 | 7869 |
| 7872 void test_visitBinaryExpression_slash() { | 7870 void test_visitBinaryExpression_slash() { |
| 7873 // 2 / 2 | 7871 // 2 / 2 |
| 7874 BinaryExpression node = AstFactory.binaryExpression(_resolvedInteger(2), Tok
enType.SLASH, _resolvedInteger(2)); | 7872 BinaryExpression node = AstFactory.binaryExpression(_resolvedInteger(2), Tok
enType.SLASH, _resolvedInteger(2)); |
| 7875 node.staticElement = getMethod(_typeProvider.numType, "/"); | 7873 node.staticElement = getMethod(_typeProvider.numType, "/"); |
| 7876 JUnitTestCase.assertSame(_typeProvider.doubleType, _analyze(node)); | 7874 expect(_analyze(node), same(_typeProvider.doubleType)); |
| 7877 _listener.assertNoErrors(); | 7875 _listener.assertNoErrors(); |
| 7878 } | 7876 } |
| 7879 | 7877 |
| 7880 void test_visitBinaryExpression_star_notSpecial() { | 7878 void test_visitBinaryExpression_star_notSpecial() { |
| 7881 // class A { | 7879 // class A { |
| 7882 // A operator *(double value); | 7880 // A operator *(double value); |
| 7883 // } | 7881 // } |
| 7884 // (a as A) * 2.0 | 7882 // (a as A) * 2.0 |
| 7885 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 7883 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 7886 InterfaceType typeA = classA.type; | 7884 InterfaceType typeA = classA.type; |
| 7887 MethodElement operator = ElementFactory.methodElement("*", typeA, [_typeProv
ider.doubleType]); | 7885 MethodElement operator = ElementFactory.methodElement("*", typeA, [_typeProv
ider.doubleType]); |
| 7888 classA.methods = <MethodElement> [operator]; | 7886 classA.methods = <MethodElement> [operator]; |
| 7889 BinaryExpression node = AstFactory.binaryExpression(AstFactory.asExpression(
AstFactory.identifier3("a"), AstFactory.typeName(classA, [])), TokenType.PLUS, _
resolvedDouble(2.0)); | 7887 BinaryExpression node = AstFactory.binaryExpression(AstFactory.asExpression(
AstFactory.identifier3("a"), AstFactory.typeName(classA, [])), TokenType.PLUS, _
resolvedDouble(2.0)); |
| 7890 node.staticElement = operator; | 7888 node.staticElement = operator; |
| 7891 JUnitTestCase.assertSame(typeA, _analyze(node)); | 7889 expect(_analyze(node), same(typeA)); |
| 7892 _listener.assertNoErrors(); | 7890 _listener.assertNoErrors(); |
| 7893 } | 7891 } |
| 7894 | 7892 |
| 7895 void test_visitBinaryExpression_starID() { | 7893 void test_visitBinaryExpression_starID() { |
| 7896 // 1 * 2.0 | 7894 // 1 * 2.0 |
| 7897 BinaryExpression node = AstFactory.binaryExpression(_resolvedInteger(1), Tok
enType.PLUS, _resolvedDouble(2.0)); | 7895 BinaryExpression node = AstFactory.binaryExpression(_resolvedInteger(1), Tok
enType.PLUS, _resolvedDouble(2.0)); |
| 7898 node.staticElement = getMethod(_typeProvider.numType, "*"); | 7896 node.staticElement = getMethod(_typeProvider.numType, "*"); |
| 7899 JUnitTestCase.assertSame(_typeProvider.doubleType, _analyze(node)); | 7897 expect(_analyze(node), same(_typeProvider.doubleType)); |
| 7900 _listener.assertNoErrors(); | 7898 _listener.assertNoErrors(); |
| 7901 } | 7899 } |
| 7902 | 7900 |
| 7903 void test_visitBooleanLiteral_false() { | 7901 void test_visitBooleanLiteral_false() { |
| 7904 // false | 7902 // false |
| 7905 Expression node = AstFactory.booleanLiteral(false); | 7903 Expression node = AstFactory.booleanLiteral(false); |
| 7906 JUnitTestCase.assertSame(_typeProvider.boolType, _analyze(node)); | 7904 expect(_analyze(node), same(_typeProvider.boolType)); |
| 7907 _listener.assertNoErrors(); | 7905 _listener.assertNoErrors(); |
| 7908 } | 7906 } |
| 7909 | 7907 |
| 7910 void test_visitBooleanLiteral_true() { | 7908 void test_visitBooleanLiteral_true() { |
| 7911 // true | 7909 // true |
| 7912 Expression node = AstFactory.booleanLiteral(true); | 7910 Expression node = AstFactory.booleanLiteral(true); |
| 7913 JUnitTestCase.assertSame(_typeProvider.boolType, _analyze(node)); | 7911 expect(_analyze(node), same(_typeProvider.boolType)); |
| 7914 _listener.assertNoErrors(); | 7912 _listener.assertNoErrors(); |
| 7915 } | 7913 } |
| 7916 | 7914 |
| 7917 void test_visitCascadeExpression() { | 7915 void test_visitCascadeExpression() { |
| 7918 // a..length | 7916 // a..length |
| 7919 Expression node = AstFactory.cascadeExpression(_resolvedString("a"), [AstFac
tory.propertyAccess2(null, "length")]); | 7917 Expression node = AstFactory.cascadeExpression(_resolvedString("a"), [AstFac
tory.propertyAccess2(null, "length")]); |
| 7920 JUnitTestCase.assertSame(_typeProvider.stringType, _analyze(node)); | 7918 expect(_analyze(node), same(_typeProvider.stringType)); |
| 7921 _listener.assertNoErrors(); | 7919 _listener.assertNoErrors(); |
| 7922 } | 7920 } |
| 7923 | 7921 |
| 7924 void test_visitConditionalExpression_differentTypes() { | 7922 void test_visitConditionalExpression_differentTypes() { |
| 7925 // true ? 1.0 : 0 | 7923 // true ? 1.0 : 0 |
| 7926 Expression node = AstFactory.conditionalExpression(AstFactory.booleanLiteral
(true), _resolvedDouble(1.0), _resolvedInteger(0)); | 7924 Expression node = AstFactory.conditionalExpression(AstFactory.booleanLiteral
(true), _resolvedDouble(1.0), _resolvedInteger(0)); |
| 7927 JUnitTestCase.assertSame(_typeProvider.numType, _analyze(node)); | 7925 expect(_analyze(node), same(_typeProvider.numType)); |
| 7928 _listener.assertNoErrors(); | 7926 _listener.assertNoErrors(); |
| 7929 } | 7927 } |
| 7930 | 7928 |
| 7931 void test_visitConditionalExpression_sameTypes() { | 7929 void test_visitConditionalExpression_sameTypes() { |
| 7932 // true ? 1 : 0 | 7930 // true ? 1 : 0 |
| 7933 Expression node = AstFactory.conditionalExpression(AstFactory.booleanLiteral
(true), _resolvedInteger(1), _resolvedInteger(0)); | 7931 Expression node = AstFactory.conditionalExpression(AstFactory.booleanLiteral
(true), _resolvedInteger(1), _resolvedInteger(0)); |
| 7934 JUnitTestCase.assertSame(_typeProvider.intType, _analyze(node)); | 7932 expect(_analyze(node), same(_typeProvider.intType)); |
| 7935 _listener.assertNoErrors(); | 7933 _listener.assertNoErrors(); |
| 7936 } | 7934 } |
| 7937 | 7935 |
| 7938 void test_visitDoubleLiteral() { | 7936 void test_visitDoubleLiteral() { |
| 7939 // 4.33 | 7937 // 4.33 |
| 7940 Expression node = AstFactory.doubleLiteral(4.33); | 7938 Expression node = AstFactory.doubleLiteral(4.33); |
| 7941 JUnitTestCase.assertSame(_typeProvider.doubleType, _analyze(node)); | 7939 expect(_analyze(node), same(_typeProvider.doubleType)); |
| 7942 _listener.assertNoErrors(); | 7940 _listener.assertNoErrors(); |
| 7943 } | 7941 } |
| 7944 | 7942 |
| 7945 void test_visitFunctionExpression_named_block() { | 7943 void test_visitFunctionExpression_named_block() { |
| 7946 // ({p1 : 0, p2 : 0}) {} | 7944 // ({p1 : 0, p2 : 0}) {} |
| 7947 DartType dynamicType = _typeProvider.dynamicType; | 7945 DartType dynamicType = _typeProvider.dynamicType; |
| 7948 FormalParameter p1 = AstFactory.namedFormalParameter(AstFactory.simpleFormal
Parameter3("p1"), _resolvedInteger(0)); | 7946 FormalParameter p1 = AstFactory.namedFormalParameter(AstFactory.simpleFormal
Parameter3("p1"), _resolvedInteger(0)); |
| 7949 _setType(p1, dynamicType); | 7947 _setType(p1, dynamicType); |
| 7950 FormalParameter p2 = AstFactory.namedFormalParameter(AstFactory.simpleFormal
Parameter3("p2"), _resolvedInteger(0)); | 7948 FormalParameter p2 = AstFactory.namedFormalParameter(AstFactory.simpleFormal
Parameter3("p2"), _resolvedInteger(0)); |
| 7951 _setType(p2, dynamicType); | 7949 _setType(p2, dynamicType); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8091 } | 8089 } |
| 8092 | 8090 |
| 8093 void test_visitIndexExpression_getter() { | 8091 void test_visitIndexExpression_getter() { |
| 8094 // List a; | 8092 // List a; |
| 8095 // a[2] | 8093 // a[2] |
| 8096 InterfaceType listType = _typeProvider.listType; | 8094 InterfaceType listType = _typeProvider.listType; |
| 8097 SimpleIdentifier identifier = _resolvedVariable(listType, "a"); | 8095 SimpleIdentifier identifier = _resolvedVariable(listType, "a"); |
| 8098 IndexExpression node = AstFactory.indexExpression(identifier, _resolvedInteg
er(2)); | 8096 IndexExpression node = AstFactory.indexExpression(identifier, _resolvedInteg
er(2)); |
| 8099 MethodElement indexMethod = listType.element.methods[0]; | 8097 MethodElement indexMethod = listType.element.methods[0]; |
| 8100 node.staticElement = indexMethod; | 8098 node.staticElement = indexMethod; |
| 8101 JUnitTestCase.assertSame(listType.typeArguments[0], _analyze(node)); | 8099 expect(_analyze(node), same(listType.typeArguments[0])); |
| 8102 _listener.assertNoErrors(); | 8100 _listener.assertNoErrors(); |
| 8103 } | 8101 } |
| 8104 | 8102 |
| 8105 void test_visitIndexExpression_setter() { | 8103 void test_visitIndexExpression_setter() { |
| 8106 // List a; | 8104 // List a; |
| 8107 // a[2] = 0 | 8105 // a[2] = 0 |
| 8108 InterfaceType listType = _typeProvider.listType; | 8106 InterfaceType listType = _typeProvider.listType; |
| 8109 SimpleIdentifier identifier = _resolvedVariable(listType, "a"); | 8107 SimpleIdentifier identifier = _resolvedVariable(listType, "a"); |
| 8110 IndexExpression node = AstFactory.indexExpression(identifier, _resolvedInteg
er(2)); | 8108 IndexExpression node = AstFactory.indexExpression(identifier, _resolvedInteg
er(2)); |
| 8111 MethodElement indexMethod = listType.element.methods[1]; | 8109 MethodElement indexMethod = listType.element.methods[1]; |
| 8112 node.staticElement = indexMethod; | 8110 node.staticElement = indexMethod; |
| 8113 AstFactory.assignmentExpression(node, TokenType.EQ, AstFactory.integer(0)); | 8111 AstFactory.assignmentExpression(node, TokenType.EQ, AstFactory.integer(0)); |
| 8114 JUnitTestCase.assertSame(listType.typeArguments[0], _analyze(node)); | 8112 expect(_analyze(node), same(listType.typeArguments[0])); |
| 8115 _listener.assertNoErrors(); | 8113 _listener.assertNoErrors(); |
| 8116 } | 8114 } |
| 8117 | 8115 |
| 8118 void test_visitIndexExpression_typeParameters() { | 8116 void test_visitIndexExpression_typeParameters() { |
| 8119 // List<int> list = ... | 8117 // List<int> list = ... |
| 8120 // list[0] | 8118 // list[0] |
| 8121 InterfaceType intType = _typeProvider.intType; | 8119 InterfaceType intType = _typeProvider.intType; |
| 8122 InterfaceType listType = _typeProvider.listType; | 8120 InterfaceType listType = _typeProvider.listType; |
| 8123 // (int) -> E | 8121 // (int) -> E |
| 8124 MethodElement methodElement = getMethod(listType, "[]"); | 8122 MethodElement methodElement = getMethod(listType, "[]"); |
| 8125 // "list" has type List<int> | 8123 // "list" has type List<int> |
| 8126 SimpleIdentifier identifier = AstFactory.identifier3("list"); | 8124 SimpleIdentifier identifier = AstFactory.identifier3("list"); |
| 8127 InterfaceType listOfIntType = listType.substitute4(<DartType> [intType]); | 8125 InterfaceType listOfIntType = listType.substitute4(<DartType> [intType]); |
| 8128 identifier.staticType = listOfIntType; | 8126 identifier.staticType = listOfIntType; |
| 8129 // list[0] has MethodElement element (int) -> E | 8127 // list[0] has MethodElement element (int) -> E |
| 8130 IndexExpression indexExpression = AstFactory.indexExpression(identifier, Ast
Factory.integer(0)); | 8128 IndexExpression indexExpression = AstFactory.indexExpression(identifier, Ast
Factory.integer(0)); |
| 8131 MethodElement indexMethod = MethodMember.from(methodElement, listOfIntType); | 8129 MethodElement indexMethod = MethodMember.from(methodElement, listOfIntType); |
| 8132 indexExpression.staticElement = indexMethod; | 8130 indexExpression.staticElement = indexMethod; |
| 8133 // analyze and assert result of the index expression | 8131 // analyze and assert result of the index expression |
| 8134 JUnitTestCase.assertSame(intType, _analyze(indexExpression)); | 8132 expect(_analyze(indexExpression), same(intType)); |
| 8135 _listener.assertNoErrors(); | 8133 _listener.assertNoErrors(); |
| 8136 } | 8134 } |
| 8137 | 8135 |
| 8138 void test_visitIndexExpression_typeParameters_inSetterContext() { | 8136 void test_visitIndexExpression_typeParameters_inSetterContext() { |
| 8139 // List<int> list = ... | 8137 // List<int> list = ... |
| 8140 // list[0] = 0; | 8138 // list[0] = 0; |
| 8141 InterfaceType intType = _typeProvider.intType; | 8139 InterfaceType intType = _typeProvider.intType; |
| 8142 InterfaceType listType = _typeProvider.listType; | 8140 InterfaceType listType = _typeProvider.listType; |
| 8143 // (int, E) -> void | 8141 // (int, E) -> void |
| 8144 MethodElement methodElement = getMethod(listType, "[]="); | 8142 MethodElement methodElement = getMethod(listType, "[]="); |
| 8145 // "list" has type List<int> | 8143 // "list" has type List<int> |
| 8146 SimpleIdentifier identifier = AstFactory.identifier3("list"); | 8144 SimpleIdentifier identifier = AstFactory.identifier3("list"); |
| 8147 InterfaceType listOfIntType = listType.substitute4(<DartType> [intType]); | 8145 InterfaceType listOfIntType = listType.substitute4(<DartType> [intType]); |
| 8148 identifier.staticType = listOfIntType; | 8146 identifier.staticType = listOfIntType; |
| 8149 // list[0] has MethodElement element (int) -> E | 8147 // list[0] has MethodElement element (int) -> E |
| 8150 IndexExpression indexExpression = AstFactory.indexExpression(identifier, Ast
Factory.integer(0)); | 8148 IndexExpression indexExpression = AstFactory.indexExpression(identifier, Ast
Factory.integer(0)); |
| 8151 MethodElement indexMethod = MethodMember.from(methodElement, listOfIntType); | 8149 MethodElement indexMethod = MethodMember.from(methodElement, listOfIntType); |
| 8152 indexExpression.staticElement = indexMethod; | 8150 indexExpression.staticElement = indexMethod; |
| 8153 // list[0] should be in a setter context | 8151 // list[0] should be in a setter context |
| 8154 AstFactory.assignmentExpression(indexExpression, TokenType.EQ, AstFactory.in
teger(0)); | 8152 AstFactory.assignmentExpression(indexExpression, TokenType.EQ, AstFactory.in
teger(0)); |
| 8155 // analyze and assert result of the index expression | 8153 // analyze and assert result of the index expression |
| 8156 JUnitTestCase.assertSame(intType, _analyze(indexExpression)); | 8154 expect(_analyze(indexExpression), same(intType)); |
| 8157 _listener.assertNoErrors(); | 8155 _listener.assertNoErrors(); |
| 8158 } | 8156 } |
| 8159 | 8157 |
| 8160 void test_visitInstanceCreationExpression_named() { | 8158 void test_visitInstanceCreationExpression_named() { |
| 8161 // new C.m() | 8159 // new C.m() |
| 8162 ClassElementImpl classElement = ElementFactory.classElement2("C", []); | 8160 ClassElementImpl classElement = ElementFactory.classElement2("C", []); |
| 8163 String constructorName = "m"; | 8161 String constructorName = "m"; |
| 8164 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas
sElement, constructorName, []); | 8162 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas
sElement, constructorName, []); |
| 8165 constructor.returnType = classElement.type; | 8163 constructor.returnType = classElement.type; |
| 8166 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); | 8164 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); |
| 8167 constructor.type = constructorType; | 8165 constructor.type = constructorType; |
| 8168 classElement.constructors = <ConstructorElement> [constructor]; | 8166 classElement.constructors = <ConstructorElement> [constructor]; |
| 8169 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(nul
l, AstFactory.typeName(classElement, []), [AstFactory.identifier3(constructorNam
e)]); | 8167 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(nul
l, AstFactory.typeName(classElement, []), [AstFactory.identifier3(constructorNam
e)]); |
| 8170 node.staticElement = constructor; | 8168 node.staticElement = constructor; |
| 8171 JUnitTestCase.assertSame(classElement.type, _analyze(node)); | 8169 expect(_analyze(node), same(classElement.type)); |
| 8172 _listener.assertNoErrors(); | 8170 _listener.assertNoErrors(); |
| 8173 } | 8171 } |
| 8174 | 8172 |
| 8175 void test_visitInstanceCreationExpression_typeParameters() { | 8173 void test_visitInstanceCreationExpression_typeParameters() { |
| 8176 // new C<I>() | 8174 // new C<I>() |
| 8177 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]); | 8175 ClassElementImpl elementC = ElementFactory.classElement2("C", ["E"]); |
| 8178 ClassElementImpl elementI = ElementFactory.classElement2("I", []); | 8176 ClassElementImpl elementI = ElementFactory.classElement2("I", []); |
| 8179 ConstructorElementImpl constructor = ElementFactory.constructorElement2(elem
entC, null, []); | 8177 ConstructorElementImpl constructor = ElementFactory.constructorElement2(elem
entC, null, []); |
| 8180 elementC.constructors = <ConstructorElement> [constructor]; | 8178 elementC.constructors = <ConstructorElement> [constructor]; |
| 8181 constructor.returnType = elementC.type; | 8179 constructor.returnType = elementC.type; |
| 8182 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); | 8180 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); |
| 8183 constructor.type = constructorType; | 8181 constructor.type = constructorType; |
| 8184 TypeName typeName = AstFactory.typeName(elementC, [AstFactory.typeName(eleme
ntI, [])]); | 8182 TypeName typeName = AstFactory.typeName(elementC, [AstFactory.typeName(eleme
ntI, [])]); |
| 8185 typeName.type = elementC.type.substitute4(<DartType> [elementI.type]); | 8183 typeName.type = elementC.type.substitute4(<DartType> [elementI.type]); |
| 8186 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(nul
l, typeName, []); | 8184 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(nul
l, typeName, []); |
| 8187 node.staticElement = constructor; | 8185 node.staticElement = constructor; |
| 8188 InterfaceType interfaceType = _analyze(node) as InterfaceType; | 8186 InterfaceType interfaceType = _analyze(node) as InterfaceType; |
| 8189 List<DartType> typeArgs = interfaceType.typeArguments; | 8187 List<DartType> typeArgs = interfaceType.typeArguments; |
| 8190 JUnitTestCase.assertEquals(1, typeArgs.length); | 8188 expect(typeArgs.length, 1); |
| 8191 JUnitTestCase.assertEquals(elementI.type, typeArgs[0]); | 8189 expect(typeArgs[0], elementI.type); |
| 8192 _listener.assertNoErrors(); | 8190 _listener.assertNoErrors(); |
| 8193 } | 8191 } |
| 8194 | 8192 |
| 8195 void test_visitInstanceCreationExpression_unnamed() { | 8193 void test_visitInstanceCreationExpression_unnamed() { |
| 8196 // new C() | 8194 // new C() |
| 8197 ClassElementImpl classElement = ElementFactory.classElement2("C", []); | 8195 ClassElementImpl classElement = ElementFactory.classElement2("C", []); |
| 8198 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas
sElement, null, []); | 8196 ConstructorElementImpl constructor = ElementFactory.constructorElement2(clas
sElement, null, []); |
| 8199 constructor.returnType = classElement.type; | 8197 constructor.returnType = classElement.type; |
| 8200 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); | 8198 FunctionTypeImpl constructorType = new FunctionTypeImpl.con1(constructor); |
| 8201 constructor.type = constructorType; | 8199 constructor.type = constructorType; |
| 8202 classElement.constructors = <ConstructorElement> [constructor]; | 8200 classElement.constructors = <ConstructorElement> [constructor]; |
| 8203 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(nul
l, AstFactory.typeName(classElement, []), []); | 8201 InstanceCreationExpression node = AstFactory.instanceCreationExpression2(nul
l, AstFactory.typeName(classElement, []), []); |
| 8204 node.staticElement = constructor; | 8202 node.staticElement = constructor; |
| 8205 JUnitTestCase.assertSame(classElement.type, _analyze(node)); | 8203 expect(_analyze(node), same(classElement.type)); |
| 8206 _listener.assertNoErrors(); | 8204 _listener.assertNoErrors(); |
| 8207 } | 8205 } |
| 8208 | 8206 |
| 8209 void test_visitIntegerLiteral() { | 8207 void test_visitIntegerLiteral() { |
| 8210 // 42 | 8208 // 42 |
| 8211 Expression node = _resolvedInteger(42); | 8209 Expression node = _resolvedInteger(42); |
| 8212 JUnitTestCase.assertSame(_typeProvider.intType, _analyze(node)); | 8210 expect(_analyze(node), same(_typeProvider.intType)); |
| 8213 _listener.assertNoErrors(); | 8211 _listener.assertNoErrors(); |
| 8214 } | 8212 } |
| 8215 | 8213 |
| 8216 void test_visitIsExpression_negated() { | 8214 void test_visitIsExpression_negated() { |
| 8217 // a is! String | 8215 // a is! String |
| 8218 Expression node = AstFactory.isExpression(_resolvedString("a"), true, AstFac
tory.typeName4("String", [])); | 8216 Expression node = AstFactory.isExpression(_resolvedString("a"), true, AstFac
tory.typeName4("String", [])); |
| 8219 JUnitTestCase.assertSame(_typeProvider.boolType, _analyze(node)); | 8217 expect(_analyze(node), same(_typeProvider.boolType)); |
| 8220 _listener.assertNoErrors(); | 8218 _listener.assertNoErrors(); |
| 8221 } | 8219 } |
| 8222 | 8220 |
| 8223 void test_visitIsExpression_notNegated() { | 8221 void test_visitIsExpression_notNegated() { |
| 8224 // a is String | 8222 // a is String |
| 8225 Expression node = AstFactory.isExpression(_resolvedString("a"), false, AstFa
ctory.typeName4("String", [])); | 8223 Expression node = AstFactory.isExpression(_resolvedString("a"), false, AstFa
ctory.typeName4("String", [])); |
| 8226 JUnitTestCase.assertSame(_typeProvider.boolType, _analyze(node)); | 8224 expect(_analyze(node), same(_typeProvider.boolType)); |
| 8227 _listener.assertNoErrors(); | 8225 _listener.assertNoErrors(); |
| 8228 } | 8226 } |
| 8229 | 8227 |
| 8230 void test_visitListLiteral_empty() { | 8228 void test_visitListLiteral_empty() { |
| 8231 // [] | 8229 // [] |
| 8232 Expression node = AstFactory.listLiteral([]); | 8230 Expression node = AstFactory.listLiteral([]); |
| 8233 DartType resultType = _analyze(node); | 8231 DartType resultType = _analyze(node); |
| 8234 _assertType2(_typeProvider.listType.substitute4(<DartType> [_typeProvider.dy
namicType]), resultType); | 8232 _assertType2(_typeProvider.listType.substitute4(<DartType> [_typeProvider.dy
namicType]), resultType); |
| 8235 _listener.assertNoErrors(); | 8233 _listener.assertNoErrors(); |
| 8236 } | 8234 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 8262 void test_visitMethodInvocation_then() { | 8260 void test_visitMethodInvocation_then() { |
| 8263 // then() | 8261 // then() |
| 8264 Expression node = AstFactory.methodInvocation(null, "then", []); | 8262 Expression node = AstFactory.methodInvocation(null, "then", []); |
| 8265 _analyze(node); | 8263 _analyze(node); |
| 8266 _listener.assertNoErrors(); | 8264 _listener.assertNoErrors(); |
| 8267 } | 8265 } |
| 8268 | 8266 |
| 8269 void test_visitNamedExpression() { | 8267 void test_visitNamedExpression() { |
| 8270 // n: a | 8268 // n: a |
| 8271 Expression node = AstFactory.namedExpression2("n", _resolvedString("a")); | 8269 Expression node = AstFactory.namedExpression2("n", _resolvedString("a")); |
| 8272 JUnitTestCase.assertSame(_typeProvider.stringType, _analyze(node)); | 8270 expect(_analyze(node), same(_typeProvider.stringType)); |
| 8273 _listener.assertNoErrors(); | 8271 _listener.assertNoErrors(); |
| 8274 } | 8272 } |
| 8275 | 8273 |
| 8276 void test_visitNullLiteral() { | 8274 void test_visitNullLiteral() { |
| 8277 // null | 8275 // null |
| 8278 Expression node = AstFactory.nullLiteral(); | 8276 Expression node = AstFactory.nullLiteral(); |
| 8279 JUnitTestCase.assertSame(_typeProvider.bottomType, _analyze(node)); | 8277 expect(_analyze(node), same(_typeProvider.bottomType)); |
| 8280 _listener.assertNoErrors(); | 8278 _listener.assertNoErrors(); |
| 8281 } | 8279 } |
| 8282 | 8280 |
| 8283 void test_visitParenthesizedExpression() { | 8281 void test_visitParenthesizedExpression() { |
| 8284 // (0) | 8282 // (0) |
| 8285 Expression node = AstFactory.parenthesizedExpression(_resolvedInteger(0)); | 8283 Expression node = AstFactory.parenthesizedExpression(_resolvedInteger(0)); |
| 8286 JUnitTestCase.assertSame(_typeProvider.intType, _analyze(node)); | 8284 expect(_analyze(node), same(_typeProvider.intType)); |
| 8287 _listener.assertNoErrors(); | 8285 _listener.assertNoErrors(); |
| 8288 } | 8286 } |
| 8289 | 8287 |
| 8290 void test_visitPostfixExpression_minusMinus() { | 8288 void test_visitPostfixExpression_minusMinus() { |
| 8291 // 0-- | 8289 // 0-- |
| 8292 PostfixExpression node = AstFactory.postfixExpression(_resolvedInteger(0), T
okenType.MINUS_MINUS); | 8290 PostfixExpression node = AstFactory.postfixExpression(_resolvedInteger(0), T
okenType.MINUS_MINUS); |
| 8293 JUnitTestCase.assertSame(_typeProvider.intType, _analyze(node)); | 8291 expect(_analyze(node), same(_typeProvider.intType)); |
| 8294 _listener.assertNoErrors(); | 8292 _listener.assertNoErrors(); |
| 8295 } | 8293 } |
| 8296 | 8294 |
| 8297 void test_visitPostfixExpression_plusPlus() { | 8295 void test_visitPostfixExpression_plusPlus() { |
| 8298 // 0++ | 8296 // 0++ |
| 8299 PostfixExpression node = AstFactory.postfixExpression(_resolvedInteger(0), T
okenType.PLUS_PLUS); | 8297 PostfixExpression node = AstFactory.postfixExpression(_resolvedInteger(0), T
okenType.PLUS_PLUS); |
| 8300 JUnitTestCase.assertSame(_typeProvider.intType, _analyze(node)); | 8298 expect(_analyze(node), same(_typeProvider.intType)); |
| 8301 _listener.assertNoErrors(); | 8299 _listener.assertNoErrors(); |
| 8302 } | 8300 } |
| 8303 | 8301 |
| 8304 void test_visitPrefixedIdentifier_getter() { | 8302 void test_visitPrefixedIdentifier_getter() { |
| 8305 DartType boolType = _typeProvider.boolType; | 8303 DartType boolType = _typeProvider.boolType; |
| 8306 PropertyAccessorElementImpl getter = ElementFactory.getterElement("b", false
, boolType); | 8304 PropertyAccessorElementImpl getter = ElementFactory.getterElement("b", false
, boolType); |
| 8307 PrefixedIdentifier node = AstFactory.identifier5("a", "b"); | 8305 PrefixedIdentifier node = AstFactory.identifier5("a", "b"); |
| 8308 node.identifier.staticElement = getter; | 8306 node.identifier.staticElement = getter; |
| 8309 JUnitTestCase.assertSame(boolType, _analyze(node)); | 8307 expect(_analyze(node), same(boolType)); |
| 8310 _listener.assertNoErrors(); | 8308 _listener.assertNoErrors(); |
| 8311 } | 8309 } |
| 8312 | 8310 |
| 8313 void test_visitPrefixedIdentifier_setter() { | 8311 void test_visitPrefixedIdentifier_setter() { |
| 8314 DartType boolType = _typeProvider.boolType; | 8312 DartType boolType = _typeProvider.boolType; |
| 8315 FieldElementImpl field = ElementFactory.fieldElement("b", false, false, fals
e, boolType); | 8313 FieldElementImpl field = ElementFactory.fieldElement("b", false, false, fals
e, boolType); |
| 8316 PropertyAccessorElement setter = field.setter; | 8314 PropertyAccessorElement setter = field.setter; |
| 8317 PrefixedIdentifier node = AstFactory.identifier5("a", "b"); | 8315 PrefixedIdentifier node = AstFactory.identifier5("a", "b"); |
| 8318 node.identifier.staticElement = setter; | 8316 node.identifier.staticElement = setter; |
| 8319 JUnitTestCase.assertSame(boolType, _analyze(node)); | 8317 expect(_analyze(node), same(boolType)); |
| 8320 _listener.assertNoErrors(); | 8318 _listener.assertNoErrors(); |
| 8321 } | 8319 } |
| 8322 | 8320 |
| 8323 void test_visitPrefixedIdentifier_variable() { | 8321 void test_visitPrefixedIdentifier_variable() { |
| 8324 VariableElementImpl variable = ElementFactory.localVariableElement2("b"); | 8322 VariableElementImpl variable = ElementFactory.localVariableElement2("b"); |
| 8325 variable.type = _typeProvider.boolType; | 8323 variable.type = _typeProvider.boolType; |
| 8326 PrefixedIdentifier node = AstFactory.identifier5("a", "b"); | 8324 PrefixedIdentifier node = AstFactory.identifier5("a", "b"); |
| 8327 node.identifier.staticElement = variable; | 8325 node.identifier.staticElement = variable; |
| 8328 JUnitTestCase.assertSame(_typeProvider.boolType, _analyze(node)); | 8326 expect(_analyze(node), same(_typeProvider.boolType)); |
| 8329 _listener.assertNoErrors(); | 8327 _listener.assertNoErrors(); |
| 8330 } | 8328 } |
| 8331 | 8329 |
| 8332 void test_visitPrefixExpression_bang() { | 8330 void test_visitPrefixExpression_bang() { |
| 8333 // !0 | 8331 // !0 |
| 8334 PrefixExpression node = AstFactory.prefixExpression(TokenType.BANG, _resolve
dInteger(0)); | 8332 PrefixExpression node = AstFactory.prefixExpression(TokenType.BANG, _resolve
dInteger(0)); |
| 8335 JUnitTestCase.assertSame(_typeProvider.boolType, _analyze(node)); | 8333 expect(_analyze(node), same(_typeProvider.boolType)); |
| 8336 _listener.assertNoErrors(); | 8334 _listener.assertNoErrors(); |
| 8337 } | 8335 } |
| 8338 | 8336 |
| 8339 void test_visitPrefixExpression_minus() { | 8337 void test_visitPrefixExpression_minus() { |
| 8340 // -0 | 8338 // -0 |
| 8341 PrefixExpression node = AstFactory.prefixExpression(TokenType.MINUS, _resolv
edInteger(0)); | 8339 PrefixExpression node = AstFactory.prefixExpression(TokenType.MINUS, _resolv
edInteger(0)); |
| 8342 MethodElement minusMethod = getMethod(_typeProvider.numType, "-"); | 8340 MethodElement minusMethod = getMethod(_typeProvider.numType, "-"); |
| 8343 node.staticElement = minusMethod; | 8341 node.staticElement = minusMethod; |
| 8344 JUnitTestCase.assertSame(_typeProvider.numType, _analyze(node)); | 8342 expect(_analyze(node), same(_typeProvider.numType)); |
| 8345 _listener.assertNoErrors(); | 8343 _listener.assertNoErrors(); |
| 8346 } | 8344 } |
| 8347 | 8345 |
| 8348 void test_visitPrefixExpression_minusMinus() { | 8346 void test_visitPrefixExpression_minusMinus() { |
| 8349 // --0 | 8347 // --0 |
| 8350 PrefixExpression node = AstFactory.prefixExpression(TokenType.MINUS_MINUS, _
resolvedInteger(0)); | 8348 PrefixExpression node = AstFactory.prefixExpression(TokenType.MINUS_MINUS, _
resolvedInteger(0)); |
| 8351 MethodElement minusMethod = getMethod(_typeProvider.numType, "-"); | 8349 MethodElement minusMethod = getMethod(_typeProvider.numType, "-"); |
| 8352 node.staticElement = minusMethod; | 8350 node.staticElement = minusMethod; |
| 8353 JUnitTestCase.assertSame(_typeProvider.intType, _analyze(node)); | 8351 expect(_analyze(node), same(_typeProvider.intType)); |
| 8354 _listener.assertNoErrors(); | 8352 _listener.assertNoErrors(); |
| 8355 } | 8353 } |
| 8356 | 8354 |
| 8357 void test_visitPrefixExpression_not() { | 8355 void test_visitPrefixExpression_not() { |
| 8358 // !true | 8356 // !true |
| 8359 Expression node = AstFactory.prefixExpression(TokenType.BANG, AstFactory.boo
leanLiteral(true)); | 8357 Expression node = AstFactory.prefixExpression(TokenType.BANG, AstFactory.boo
leanLiteral(true)); |
| 8360 JUnitTestCase.assertSame(_typeProvider.boolType, _analyze(node)); | 8358 expect(_analyze(node), same(_typeProvider.boolType)); |
| 8361 _listener.assertNoErrors(); | 8359 _listener.assertNoErrors(); |
| 8362 } | 8360 } |
| 8363 | 8361 |
| 8364 void test_visitPrefixExpression_plusPlus() { | 8362 void test_visitPrefixExpression_plusPlus() { |
| 8365 // ++0 | 8363 // ++0 |
| 8366 PrefixExpression node = AstFactory.prefixExpression(TokenType.PLUS_PLUS, _re
solvedInteger(0)); | 8364 PrefixExpression node = AstFactory.prefixExpression(TokenType.PLUS_PLUS, _re
solvedInteger(0)); |
| 8367 MethodElement plusMethod = getMethod(_typeProvider.numType, "+"); | 8365 MethodElement plusMethod = getMethod(_typeProvider.numType, "+"); |
| 8368 node.staticElement = plusMethod; | 8366 node.staticElement = plusMethod; |
| 8369 JUnitTestCase.assertSame(_typeProvider.intType, _analyze(node)); | 8367 expect(_analyze(node), same(_typeProvider.intType)); |
| 8370 _listener.assertNoErrors(); | 8368 _listener.assertNoErrors(); |
| 8371 } | 8369 } |
| 8372 | 8370 |
| 8373 void test_visitPrefixExpression_tilde() { | 8371 void test_visitPrefixExpression_tilde() { |
| 8374 // ~0 | 8372 // ~0 |
| 8375 PrefixExpression node = AstFactory.prefixExpression(TokenType.TILDE, _resolv
edInteger(0)); | 8373 PrefixExpression node = AstFactory.prefixExpression(TokenType.TILDE, _resolv
edInteger(0)); |
| 8376 MethodElement tildeMethod = getMethod(_typeProvider.intType, "~"); | 8374 MethodElement tildeMethod = getMethod(_typeProvider.intType, "~"); |
| 8377 node.staticElement = tildeMethod; | 8375 node.staticElement = tildeMethod; |
| 8378 JUnitTestCase.assertSame(_typeProvider.intType, _analyze(node)); | 8376 expect(_analyze(node), same(_typeProvider.intType)); |
| 8379 _listener.assertNoErrors(); | 8377 _listener.assertNoErrors(); |
| 8380 } | 8378 } |
| 8381 | 8379 |
| 8382 void test_visitPropertyAccess_propagated_getter() { | 8380 void test_visitPropertyAccess_propagated_getter() { |
| 8383 DartType boolType = _typeProvider.boolType; | 8381 DartType boolType = _typeProvider.boolType; |
| 8384 PropertyAccessorElementImpl getter = ElementFactory.getterElement("b", false
, boolType); | 8382 PropertyAccessorElementImpl getter = ElementFactory.getterElement("b", false
, boolType); |
| 8385 PropertyAccess node = AstFactory.propertyAccess2(AstFactory.identifier3("a")
, "b"); | 8383 PropertyAccess node = AstFactory.propertyAccess2(AstFactory.identifier3("a")
, "b"); |
| 8386 node.propertyName.propagatedElement = getter; | 8384 node.propertyName.propagatedElement = getter; |
| 8387 JUnitTestCase.assertSame(boolType, _analyze2(node, false)); | 8385 expect(_analyze2(node, false), same(boolType)); |
| 8388 _listener.assertNoErrors(); | 8386 _listener.assertNoErrors(); |
| 8389 } | 8387 } |
| 8390 | 8388 |
| 8391 void test_visitPropertyAccess_propagated_setter() { | 8389 void test_visitPropertyAccess_propagated_setter() { |
| 8392 DartType boolType = _typeProvider.boolType; | 8390 DartType boolType = _typeProvider.boolType; |
| 8393 FieldElementImpl field = ElementFactory.fieldElement("b", false, false, fals
e, boolType); | 8391 FieldElementImpl field = ElementFactory.fieldElement("b", false, false, fals
e, boolType); |
| 8394 PropertyAccessorElement setter = field.setter; | 8392 PropertyAccessorElement setter = field.setter; |
| 8395 PropertyAccess node = AstFactory.propertyAccess2(AstFactory.identifier3("a")
, "b"); | 8393 PropertyAccess node = AstFactory.propertyAccess2(AstFactory.identifier3("a")
, "b"); |
| 8396 node.propertyName.propagatedElement = setter; | 8394 node.propertyName.propagatedElement = setter; |
| 8397 JUnitTestCase.assertSame(boolType, _analyze2(node, false)); | 8395 expect(_analyze2(node, false), same(boolType)); |
| 8398 _listener.assertNoErrors(); | 8396 _listener.assertNoErrors(); |
| 8399 } | 8397 } |
| 8400 | 8398 |
| 8401 void test_visitPropertyAccess_static_getter() { | 8399 void test_visitPropertyAccess_static_getter() { |
| 8402 DartType boolType = _typeProvider.boolType; | 8400 DartType boolType = _typeProvider.boolType; |
| 8403 PropertyAccessorElementImpl getter = ElementFactory.getterElement("b", false
, boolType); | 8401 PropertyAccessorElementImpl getter = ElementFactory.getterElement("b", false
, boolType); |
| 8404 PropertyAccess node = AstFactory.propertyAccess2(AstFactory.identifier3("a")
, "b"); | 8402 PropertyAccess node = AstFactory.propertyAccess2(AstFactory.identifier3("a")
, "b"); |
| 8405 node.propertyName.staticElement = getter; | 8403 node.propertyName.staticElement = getter; |
| 8406 JUnitTestCase.assertSame(boolType, _analyze(node)); | 8404 expect(_analyze(node), same(boolType)); |
| 8407 _listener.assertNoErrors(); | 8405 _listener.assertNoErrors(); |
| 8408 } | 8406 } |
| 8409 | 8407 |
| 8410 void test_visitPropertyAccess_static_setter() { | 8408 void test_visitPropertyAccess_static_setter() { |
| 8411 DartType boolType = _typeProvider.boolType; | 8409 DartType boolType = _typeProvider.boolType; |
| 8412 FieldElementImpl field = ElementFactory.fieldElement("b", false, false, fals
e, boolType); | 8410 FieldElementImpl field = ElementFactory.fieldElement("b", false, false, fals
e, boolType); |
| 8413 PropertyAccessorElement setter = field.setter; | 8411 PropertyAccessorElement setter = field.setter; |
| 8414 PropertyAccess node = AstFactory.propertyAccess2(AstFactory.identifier3("a")
, "b"); | 8412 PropertyAccess node = AstFactory.propertyAccess2(AstFactory.identifier3("a")
, "b"); |
| 8415 node.propertyName.staticElement = setter; | 8413 node.propertyName.staticElement = setter; |
| 8416 JUnitTestCase.assertSame(boolType, _analyze(node)); | 8414 expect(_analyze(node), same(boolType)); |
| 8417 _listener.assertNoErrors(); | 8415 _listener.assertNoErrors(); |
| 8418 } | 8416 } |
| 8419 | 8417 |
| 8420 void test_visitSimpleStringLiteral() { | 8418 void test_visitSimpleStringLiteral() { |
| 8421 // "a" | 8419 // "a" |
| 8422 Expression node = _resolvedString("a"); | 8420 Expression node = _resolvedString("a"); |
| 8423 JUnitTestCase.assertSame(_typeProvider.stringType, _analyze(node)); | 8421 expect(_analyze(node), same(_typeProvider.stringType)); |
| 8424 _listener.assertNoErrors(); | 8422 _listener.assertNoErrors(); |
| 8425 } | 8423 } |
| 8426 | 8424 |
| 8427 void test_visitStringInterpolation() { | 8425 void test_visitStringInterpolation() { |
| 8428 // "a${'b'}c" | 8426 // "a${'b'}c" |
| 8429 Expression node = AstFactory.string([ | 8427 Expression node = AstFactory.string([ |
| 8430 AstFactory.interpolationString("a", "a"), | 8428 AstFactory.interpolationString("a", "a"), |
| 8431 AstFactory.interpolationExpression(_resolvedString("b")), | 8429 AstFactory.interpolationExpression(_resolvedString("b")), |
| 8432 AstFactory.interpolationString("c", "c")]); | 8430 AstFactory.interpolationString("c", "c")]); |
| 8433 JUnitTestCase.assertSame(_typeProvider.stringType, _analyze(node)); | 8431 expect(_analyze(node), same(_typeProvider.stringType)); |
| 8434 _listener.assertNoErrors(); | 8432 _listener.assertNoErrors(); |
| 8435 } | 8433 } |
| 8436 | 8434 |
| 8437 void test_visitSuperExpression() { | 8435 void test_visitSuperExpression() { |
| 8438 // super | 8436 // super |
| 8439 InterfaceType superType = ElementFactory.classElement2("A", []).type; | 8437 InterfaceType superType = ElementFactory.classElement2("A", []).type; |
| 8440 InterfaceType thisType = ElementFactory.classElement("B", superType, []).typ
e; | 8438 InterfaceType thisType = ElementFactory.classElement("B", superType, []).typ
e; |
| 8441 Expression node = AstFactory.superExpression(); | 8439 Expression node = AstFactory.superExpression(); |
| 8442 JUnitTestCase.assertSame(thisType, _analyze3(node, thisType)); | 8440 expect(_analyze3(node, thisType), same(thisType)); |
| 8443 _listener.assertNoErrors(); | 8441 _listener.assertNoErrors(); |
| 8444 } | 8442 } |
| 8445 | 8443 |
| 8446 void test_visitSymbolLiteral() { | 8444 void test_visitSymbolLiteral() { |
| 8447 JUnitTestCase.assertSame(_typeProvider.symbolType, _analyze(AstFactory.symbo
lLiteral(["a"]))); | 8445 expect(_analyze(AstFactory.symbolLiteral(["a"])), same(_typeProvider.symbolT
ype)); |
| 8448 } | 8446 } |
| 8449 | 8447 |
| 8450 void test_visitThisExpression() { | 8448 void test_visitThisExpression() { |
| 8451 // this | 8449 // this |
| 8452 InterfaceType thisType = ElementFactory.classElement("B", ElementFactory.cla
ssElement2("A", []).type, []).type; | 8450 InterfaceType thisType = ElementFactory.classElement("B", ElementFactory.cla
ssElement2("A", []).type, []).type; |
| 8453 Expression node = AstFactory.thisExpression(); | 8451 Expression node = AstFactory.thisExpression(); |
| 8454 JUnitTestCase.assertSame(thisType, _analyze3(node, thisType)); | 8452 expect(_analyze3(node, thisType), same(thisType)); |
| 8455 _listener.assertNoErrors(); | 8453 _listener.assertNoErrors(); |
| 8456 } | 8454 } |
| 8457 | 8455 |
| 8458 void test_visitThrowExpression_withoutValue() { | 8456 void test_visitThrowExpression_withoutValue() { |
| 8459 // throw | 8457 // throw |
| 8460 Expression node = AstFactory.throwExpression(); | 8458 Expression node = AstFactory.throwExpression(); |
| 8461 JUnitTestCase.assertSame(_typeProvider.bottomType, _analyze(node)); | 8459 expect(_analyze(node), same(_typeProvider.bottomType)); |
| 8462 _listener.assertNoErrors(); | 8460 _listener.assertNoErrors(); |
| 8463 } | 8461 } |
| 8464 | 8462 |
| 8465 void test_visitThrowExpression_withValue() { | 8463 void test_visitThrowExpression_withValue() { |
| 8466 // throw 0 | 8464 // throw 0 |
| 8467 Expression node = AstFactory.throwExpression2(_resolvedInteger(0)); | 8465 Expression node = AstFactory.throwExpression2(_resolvedInteger(0)); |
| 8468 JUnitTestCase.assertSame(_typeProvider.bottomType, _analyze(node)); | 8466 expect(_analyze(node), same(_typeProvider.bottomType)); |
| 8469 _listener.assertNoErrors(); | 8467 _listener.assertNoErrors(); |
| 8470 } | 8468 } |
| 8471 | 8469 |
| 8472 /** | 8470 /** |
| 8473 * Return the type associated with the given expression after the static type
analyzer has | 8471 * Return the type associated with the given expression after the static type
analyzer has |
| 8474 * computed a type for it. | 8472 * computed a type for it. |
| 8475 * | 8473 * |
| 8476 * @param node the expression with which the type is associated | 8474 * @param node the expression with which the type is associated |
| 8477 * @return the type associated with the expression | 8475 * @return the type associated with the expression |
| 8478 */ | 8476 */ |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8547 void _assertFunctionType(DartType expectedReturnType, List<DartType> expectedN
ormalTypes, List<DartType> expectedOptionalTypes, Map<String, DartType> expected
NamedTypes, DartType actualType) { | 8545 void _assertFunctionType(DartType expectedReturnType, List<DartType> expectedN
ormalTypes, List<DartType> expectedOptionalTypes, Map<String, DartType> expected
NamedTypes, DartType actualType) { |
| 8548 EngineTestCase.assertInstanceOf((obj) => obj is FunctionType, FunctionType,
actualType); | 8546 EngineTestCase.assertInstanceOf((obj) => obj is FunctionType, FunctionType,
actualType); |
| 8549 FunctionType functionType = actualType as FunctionType; | 8547 FunctionType functionType = actualType as FunctionType; |
| 8550 List<DartType> normalTypes = functionType.normalParameterTypes; | 8548 List<DartType> normalTypes = functionType.normalParameterTypes; |
| 8551 if (expectedNormalTypes == null) { | 8549 if (expectedNormalTypes == null) { |
| 8552 EngineTestCase.assertLength(0, normalTypes); | 8550 EngineTestCase.assertLength(0, normalTypes); |
| 8553 } else { | 8551 } else { |
| 8554 int expectedCount = expectedNormalTypes.length; | 8552 int expectedCount = expectedNormalTypes.length; |
| 8555 EngineTestCase.assertLength(expectedCount, normalTypes); | 8553 EngineTestCase.assertLength(expectedCount, normalTypes); |
| 8556 for (int i = 0; i < expectedCount; i++) { | 8554 for (int i = 0; i < expectedCount; i++) { |
| 8557 JUnitTestCase.assertSame(expectedNormalTypes[i], normalTypes[i]); | 8555 expect(normalTypes[i], same(expectedNormalTypes[i])); |
| 8558 } | 8556 } |
| 8559 } | 8557 } |
| 8560 List<DartType> optionalTypes = functionType.optionalParameterTypes; | 8558 List<DartType> optionalTypes = functionType.optionalParameterTypes; |
| 8561 if (expectedOptionalTypes == null) { | 8559 if (expectedOptionalTypes == null) { |
| 8562 EngineTestCase.assertLength(0, optionalTypes); | 8560 EngineTestCase.assertLength(0, optionalTypes); |
| 8563 } else { | 8561 } else { |
| 8564 int expectedCount = expectedOptionalTypes.length; | 8562 int expectedCount = expectedOptionalTypes.length; |
| 8565 EngineTestCase.assertLength(expectedCount, optionalTypes); | 8563 EngineTestCase.assertLength(expectedCount, optionalTypes); |
| 8566 for (int i = 0; i < expectedCount; i++) { | 8564 for (int i = 0; i < expectedCount; i++) { |
| 8567 JUnitTestCase.assertSame(expectedOptionalTypes[i], optionalTypes[i]); | 8565 expect(optionalTypes[i], same(expectedOptionalTypes[i])); |
| 8568 } | 8566 } |
| 8569 } | 8567 } |
| 8570 Map<String, DartType> namedTypes = functionType.namedParameterTypes; | 8568 Map<String, DartType> namedTypes = functionType.namedParameterTypes; |
| 8571 if (expectedNamedTypes == null) { | 8569 if (expectedNamedTypes == null) { |
| 8572 EngineTestCase.assertSizeOfMap(0, namedTypes); | 8570 EngineTestCase.assertSizeOfMap(0, namedTypes); |
| 8573 } else { | 8571 } else { |
| 8574 EngineTestCase.assertSizeOfMap(expectedNamedTypes.length, namedTypes); | 8572 EngineTestCase.assertSizeOfMap(expectedNamedTypes.length, namedTypes); |
| 8575 expectedNamedTypes.forEach((String name, DartType type) { | 8573 expectedNamedTypes.forEach((String name, DartType type) { |
| 8576 JUnitTestCase.assertSame(type, namedTypes[name]); | 8574 expect(namedTypes[name], same(type)); |
| 8577 }); | 8575 }); |
| 8578 } | 8576 } |
| 8579 JUnitTestCase.assertSame(expectedReturnType, functionType.returnType); | 8577 expect(functionType.returnType, same(expectedReturnType)); |
| 8580 } | 8578 } |
| 8581 | 8579 |
| 8582 void _assertType(InterfaceTypeImpl expectedType, InterfaceTypeImpl actualType)
{ | 8580 void _assertType(InterfaceTypeImpl expectedType, InterfaceTypeImpl actualType)
{ |
| 8583 JUnitTestCase.assertEquals(expectedType.displayName, actualType.displayName)
; | 8581 expect(actualType.displayName, expectedType.displayName); |
| 8584 JUnitTestCase.assertEquals(expectedType.element, actualType.element); | 8582 expect(actualType.element, expectedType.element); |
| 8585 List<DartType> expectedArguments = expectedType.typeArguments; | 8583 List<DartType> expectedArguments = expectedType.typeArguments; |
| 8586 int length = expectedArguments.length; | 8584 int length = expectedArguments.length; |
| 8587 List<DartType> actualArguments = actualType.typeArguments; | 8585 List<DartType> actualArguments = actualType.typeArguments; |
| 8588 EngineTestCase.assertLength(length, actualArguments); | 8586 EngineTestCase.assertLength(length, actualArguments); |
| 8589 for (int i = 0; i < length; i++) { | 8587 for (int i = 0; i < length; i++) { |
| 8590 _assertType2(expectedArguments[i], actualArguments[i]); | 8588 _assertType2(expectedArguments[i], actualArguments[i]); |
| 8591 } | 8589 } |
| 8592 } | 8590 } |
| 8593 | 8591 |
| 8594 void _assertType2(DartType expectedType, DartType actualType) { | 8592 void _assertType2(DartType expectedType, DartType actualType) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8734 typedef Foo(); | 8732 typedef Foo(); |
| 8735 main() { | 8733 main() { |
| 8736 Foo foo; | 8734 Foo foo; |
| 8737 foo(); | 8735 foo(); |
| 8738 } | 8736 } |
| 8739 """; | 8737 """; |
| 8740 _resolveTestUnit(code); | 8738 _resolveTestUnit(code); |
| 8741 // "foo" should be resolved to the "Foo" type | 8739 // "foo" should be resolved to the "Foo" type |
| 8742 SimpleIdentifier identifier = _findIdentifier("foo();"); | 8740 SimpleIdentifier identifier = _findIdentifier("foo();"); |
| 8743 DartType type = identifier.staticType; | 8741 DartType type = identifier.staticType; |
| 8744 _ut.expect(type, new _ut.isInstanceOf<FunctionType>()); | 8742 expect(type, new isInstanceOf<FunctionType>()); |
| 8745 } | 8743 } |
| 8746 | 8744 |
| 8747 void test_MethodInvocation_nameType_parameter_FunctionTypeAlias() { | 8745 void test_MethodInvocation_nameType_parameter_FunctionTypeAlias() { |
| 8748 String code = r""" | 8746 String code = r""" |
| 8749 typedef Foo(); | 8747 typedef Foo(); |
| 8750 main(Foo foo) { | 8748 main(Foo foo) { |
| 8751 foo(); | 8749 foo(); |
| 8752 } | 8750 } |
| 8753 """; | 8751 """; |
| 8754 _resolveTestUnit(code); | 8752 _resolveTestUnit(code); |
| 8755 // "foo" should be resolved to the "Foo" type | 8753 // "foo" should be resolved to the "Foo" type |
| 8756 SimpleIdentifier identifier = _findIdentifier("foo();"); | 8754 SimpleIdentifier identifier = _findIdentifier("foo();"); |
| 8757 DartType type = identifier.staticType; | 8755 DartType type = identifier.staticType; |
| 8758 _ut.expect(type, new _ut.isInstanceOf<FunctionType>()); | 8756 expect(type, new isInstanceOf<FunctionType>()); |
| 8759 } | 8757 } |
| 8760 | 8758 |
| 8761 void test_MethodInvocation_nameType_parameter_propagatedType() { | 8759 void test_MethodInvocation_nameType_parameter_propagatedType() { |
| 8762 String code = r""" | 8760 String code = r""" |
| 8763 typedef Foo(); | 8761 typedef Foo(); |
| 8764 main(p) { | 8762 main(p) { |
| 8765 if (p is Foo) { | 8763 if (p is Foo) { |
| 8766 p(); | 8764 p(); |
| 8767 } | 8765 } |
| 8768 } | 8766 } |
| 8769 """; | 8767 """; |
| 8770 _resolveTestUnit(code); | 8768 _resolveTestUnit(code); |
| 8771 SimpleIdentifier identifier = _findIdentifier("p()"); | 8769 SimpleIdentifier identifier = _findIdentifier("p()"); |
| 8772 _ut.expect(identifier.staticType, DynamicTypeImpl.instance); | 8770 expect(identifier.staticType, DynamicTypeImpl.instance); |
| 8773 { | 8771 { |
| 8774 FunctionType type = identifier.propagatedType; | 8772 FunctionType type = identifier.propagatedType; |
| 8775 _ut.expect(type, _ut.isNotNull); | 8773 expect(type, isNotNull); |
| 8776 _ut.expect(type.name, 'Foo'); | 8774 expect(type.name, 'Foo'); |
| 8777 } | 8775 } |
| 8778 } | 8776 } |
| 8779 | 8777 |
| 8780 SimpleIdentifier _findIdentifier(String search) { | 8778 SimpleIdentifier _findIdentifier(String search) { |
| 8781 SimpleIdentifier identifier = EngineTestCase.findNode( | 8779 SimpleIdentifier identifier = EngineTestCase.findNode( |
| 8782 testUnit, | 8780 testUnit, |
| 8783 testCode, | 8781 testCode, |
| 8784 search, | 8782 search, |
| 8785 (node) => node is SimpleIdentifier); | 8783 (node) => node is SimpleIdentifier); |
| 8786 return identifier; | 8784 return identifier; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8887 buffer.write(", "); | 8885 buffer.write(", "); |
| 8888 buffer.write(expression.propagatedType.displayName); | 8886 buffer.write(expression.propagatedType.displayName); |
| 8889 buffer.writeln("]"); | 8887 buffer.writeln("]"); |
| 8890 buffer.write(" "); | 8888 buffer.write(" "); |
| 8891 buffer.write(_getFileName(expression)); | 8889 buffer.write(_getFileName(expression)); |
| 8892 buffer.write(" : "); | 8890 buffer.write(" : "); |
| 8893 buffer.write(expression.offset); | 8891 buffer.write(expression.offset); |
| 8894 buffer.writeln(")"); | 8892 buffer.writeln(")"); |
| 8895 } | 8893 } |
| 8896 } | 8894 } |
| 8897 JUnitTestCase.fail(buffer.toString()); | 8895 fail(buffer.toString()); |
| 8898 } | 8896 } |
| 8899 } | 8897 } |
| 8900 | 8898 |
| 8901 @override | 8899 @override |
| 8902 Object visitBreakStatement(BreakStatement node) => null; | 8900 Object visitBreakStatement(BreakStatement node) => null; |
| 8903 | 8901 |
| 8904 @override | 8902 @override |
| 8905 Object visitCommentReference(CommentReference node) => null; | 8903 Object visitCommentReference(CommentReference node) => null; |
| 8906 | 8904 |
| 8907 @override | 8905 @override |
| (...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9682 functionType.typeArguments = typeArguments; | 9680 functionType.typeArguments = typeArguments; |
| 9683 } | 9681 } |
| 9684 } | 9682 } |
| 9685 } | 9683 } |
| 9686 | 9684 |
| 9687 class TypeOverrideManagerTest extends EngineTestCase { | 9685 class TypeOverrideManagerTest extends EngineTestCase { |
| 9688 void test_exitScope_noScopes() { | 9686 void test_exitScope_noScopes() { |
| 9689 TypeOverrideManager manager = new TypeOverrideManager(); | 9687 TypeOverrideManager manager = new TypeOverrideManager(); |
| 9690 try { | 9688 try { |
| 9691 manager.exitScope(); | 9689 manager.exitScope(); |
| 9692 JUnitTestCase.fail("Expected IllegalStateException"); | 9690 fail("Expected IllegalStateException"); |
| 9693 } on IllegalStateException catch (exception) { | 9691 } on IllegalStateException catch (exception) { |
| 9694 // Expected | 9692 // Expected |
| 9695 } | 9693 } |
| 9696 } | 9694 } |
| 9697 | 9695 |
| 9698 void test_exitScope_oneScope() { | 9696 void test_exitScope_oneScope() { |
| 9699 TypeOverrideManager manager = new TypeOverrideManager(); | 9697 TypeOverrideManager manager = new TypeOverrideManager(); |
| 9700 manager.enterScope(); | 9698 manager.enterScope(); |
| 9701 manager.exitScope(); | 9699 manager.exitScope(); |
| 9702 try { | 9700 try { |
| 9703 manager.exitScope(); | 9701 manager.exitScope(); |
| 9704 JUnitTestCase.fail("Expected IllegalStateException"); | 9702 fail("Expected IllegalStateException"); |
| 9705 } on IllegalStateException catch (exception) { | 9703 } on IllegalStateException catch (exception) { |
| 9706 // Expected | 9704 // Expected |
| 9707 } | 9705 } |
| 9708 } | 9706 } |
| 9709 | 9707 |
| 9710 void test_exitScope_twoScopes() { | 9708 void test_exitScope_twoScopes() { |
| 9711 TypeOverrideManager manager = new TypeOverrideManager(); | 9709 TypeOverrideManager manager = new TypeOverrideManager(); |
| 9712 manager.enterScope(); | 9710 manager.enterScope(); |
| 9713 manager.exitScope(); | 9711 manager.exitScope(); |
| 9714 manager.enterScope(); | 9712 manager.enterScope(); |
| 9715 manager.exitScope(); | 9713 manager.exitScope(); |
| 9716 try { | 9714 try { |
| 9717 manager.exitScope(); | 9715 manager.exitScope(); |
| 9718 JUnitTestCase.fail("Expected IllegalStateException"); | 9716 fail("Expected IllegalStateException"); |
| 9719 } on IllegalStateException catch (exception) { | 9717 } on IllegalStateException catch (exception) { |
| 9720 // Expected | 9718 // Expected |
| 9721 } | 9719 } |
| 9722 } | 9720 } |
| 9723 | 9721 |
| 9724 void test_getType_enclosedOverride() { | 9722 void test_getType_enclosedOverride() { |
| 9725 TypeOverrideManager manager = new TypeOverrideManager(); | 9723 TypeOverrideManager manager = new TypeOverrideManager(); |
| 9726 LocalVariableElementImpl element = ElementFactory.localVariableElement2("v")
; | 9724 LocalVariableElementImpl element = ElementFactory.localVariableElement2("v")
; |
| 9727 InterfaceType type = ElementFactory.classElement2("C", []).type; | 9725 InterfaceType type = ElementFactory.classElement2("C", []).type; |
| 9728 manager.enterScope(); | 9726 manager.enterScope(); |
| 9729 manager.setType(element, type); | 9727 manager.setType(element, type); |
| 9730 manager.enterScope(); | 9728 manager.enterScope(); |
| 9731 JUnitTestCase.assertSame(type, manager.getType(element)); | 9729 expect(manager.getType(element), same(type)); |
| 9732 } | 9730 } |
| 9733 | 9731 |
| 9734 void test_getType_immediateOverride() { | 9732 void test_getType_immediateOverride() { |
| 9735 TypeOverrideManager manager = new TypeOverrideManager(); | 9733 TypeOverrideManager manager = new TypeOverrideManager(); |
| 9736 LocalVariableElementImpl element = ElementFactory.localVariableElement2("v")
; | 9734 LocalVariableElementImpl element = ElementFactory.localVariableElement2("v")
; |
| 9737 InterfaceType type = ElementFactory.classElement2("C", []).type; | 9735 InterfaceType type = ElementFactory.classElement2("C", []).type; |
| 9738 manager.enterScope(); | 9736 manager.enterScope(); |
| 9739 manager.setType(element, type); | 9737 manager.setType(element, type); |
| 9740 JUnitTestCase.assertSame(type, manager.getType(element)); | 9738 expect(manager.getType(element), same(type)); |
| 9741 } | 9739 } |
| 9742 | 9740 |
| 9743 void test_getType_noOverride() { | 9741 void test_getType_noOverride() { |
| 9744 TypeOverrideManager manager = new TypeOverrideManager(); | 9742 TypeOverrideManager manager = new TypeOverrideManager(); |
| 9745 manager.enterScope(); | 9743 manager.enterScope(); |
| 9746 JUnitTestCase.assertNull(manager.getType(ElementFactory.localVariableElement
2("v"))); | 9744 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); |
| 9747 } | 9745 } |
| 9748 | 9746 |
| 9749 void test_getType_noScope() { | 9747 void test_getType_noScope() { |
| 9750 TypeOverrideManager manager = new TypeOverrideManager(); | 9748 TypeOverrideManager manager = new TypeOverrideManager(); |
| 9751 JUnitTestCase.assertNull(manager.getType(ElementFactory.localVariableElement
2("v"))); | 9749 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); |
| 9752 } | 9750 } |
| 9753 } | 9751 } |
| 9754 | 9752 |
| 9755 | 9753 |
| 9756 class TypePropagationTest extends ResolverTestCase { | 9754 class TypePropagationTest extends ResolverTestCase { |
| 9757 void fail_mergePropagatedTypesAtJoinPoint_1() { | 9755 void fail_mergePropagatedTypesAtJoinPoint_1() { |
| 9758 // https://code.google.com/p/dart/issues/detail?id=19929 | 9756 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 9759 _assertTypeOfMarkedExpression(r''' | 9757 _assertTypeOfMarkedExpression(r''' |
| 9760 f1(x) { | 9758 f1(x) { |
| 9761 var y = []; | 9759 var y = []; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9834 d = false; | 9832 d = false; |
| 9835 } else { | 9833 } else { |
| 9836 x = ''; | 9834 x = ''; |
| 9837 c = true; | 9835 c = true; |
| 9838 continue; | 9836 continue; |
| 9839 } | 9837 } |
| 9840 x; // marker | 9838 x; // marker |
| 9841 } | 9839 } |
| 9842 }'''; | 9840 }'''; |
| 9843 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; | 9841 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; |
| 9844 JUnitTestCase.assertTrue(typeProvider.intType.isSubtypeOf(t)); | 9842 expect(typeProvider.intType.isSubtypeOf(t), isTrue); |
| 9845 JUnitTestCase.assertTrue(typeProvider.stringType.isSubtypeOf(t)); | 9843 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); |
| 9846 } | 9844 } |
| 9847 | 9845 |
| 9848 void fail_mergePropagatedTypesAtJoinPoint_8() { | 9846 void fail_mergePropagatedTypesAtJoinPoint_8() { |
| 9849 // https://code.google.com/p/dart/issues/detail?id=19929 | 9847 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 9850 // | 9848 // |
| 9851 // In nested loops [breaks]s are unsafe for the purposes of [isAbruptTermina
tionStatement]. | 9849 // In nested loops [breaks]s are unsafe for the purposes of [isAbruptTermina
tionStatement]. |
| 9852 // | 9850 // |
| 9853 // This is a combination of 6 and 7: we use an unlabeled [break] | 9851 // This is a combination of 6 and 7: we use an unlabeled [break] |
| 9854 // like a continue for the outer loop / like a labeled [break] to | 9852 // like a continue for the outer loop / like a labeled [break] to |
| 9855 // jump just above the [if]. | 9853 // jump just above the [if]. |
| 9856 String code = r''' | 9854 String code = r''' |
| 9857 f() { | 9855 f() { |
| 9858 var x = 0; | 9856 var x = 0; |
| 9859 var c = false; | 9857 var c = false; |
| 9860 var d = true; | 9858 var d = true; |
| 9861 while (d) { | 9859 while (d) { |
| 9862 while (d) { | 9860 while (d) { |
| 9863 if (c) { | 9861 if (c) { |
| 9864 d = false; | 9862 d = false; |
| 9865 } else { | 9863 } else { |
| 9866 x = ''; | 9864 x = ''; |
| 9867 c = true; | 9865 c = true; |
| 9868 break; | 9866 break; |
| 9869 } | 9867 } |
| 9870 x; // marker | 9868 x; // marker |
| 9871 } | 9869 } |
| 9872 } | 9870 } |
| 9873 }'''; | 9871 }'''; |
| 9874 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; | 9872 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; |
| 9875 JUnitTestCase.assertTrue(typeProvider.intType.isSubtypeOf(t)); | 9873 expect(typeProvider.intType.isSubtypeOf(t), isTrue); |
| 9876 JUnitTestCase.assertTrue(typeProvider.stringType.isSubtypeOf(t)); | 9874 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); |
| 9877 } | 9875 } |
| 9878 | 9876 |
| 9879 void fail_propagatedReturnType_functionExpression() { | 9877 void fail_propagatedReturnType_functionExpression() { |
| 9880 // TODO(scheglov) disabled because we don't resolve function expression | 9878 // TODO(scheglov) disabled because we don't resolve function expression |
| 9881 String code = r''' | 9879 String code = r''' |
| 9882 main() { | 9880 main() { |
| 9883 var v = (() {return 42;})(); | 9881 var v = (() {return 42;})(); |
| 9884 }'''; | 9882 }'''; |
| 9885 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); | 9883 _assertPropagatedReturnType(code, typeProvider.dynamicType, typeProvider.int
Type); |
| 9886 } | 9884 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 9901 assertNoErrors(source); | 9899 assertNoErrors(source); |
| 9902 verify([source]); | 9900 verify([source]); |
| 9903 CompilationUnit unit = resolveCompilationUnit(source, library); | 9901 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9904 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 9902 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 9905 InterfaceType typeA = classA.element.type; | 9903 InterfaceType typeA = classA.element.type; |
| 9906 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 9904 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 9907 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 9905 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 9908 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 9906 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 9909 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; | 9907 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; |
| 9910 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 9908 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 9911 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 9909 expect(variableName.propagatedType, same(typeA)); |
| 9912 } | 9910 } |
| 9913 | 9911 |
| 9914 void test_assert() { | 9912 void test_assert() { |
| 9915 Source source = addSource(r''' | 9913 Source source = addSource(r''' |
| 9916 class A {} | 9914 class A {} |
| 9917 A f(var p) { | 9915 A f(var p) { |
| 9918 assert (p is A); | 9916 assert (p is A); |
| 9919 return p; | 9917 return p; |
| 9920 }'''); | 9918 }'''); |
| 9921 LibraryElement library = resolve(source); | 9919 LibraryElement library = resolve(source); |
| 9922 assertNoErrors(source); | 9920 assertNoErrors(source); |
| 9923 verify([source]); | 9921 verify([source]); |
| 9924 CompilationUnit unit = resolveCompilationUnit(source, library); | 9922 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9925 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 9923 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 9926 InterfaceType typeA = classA.element.type; | 9924 InterfaceType typeA = classA.element.type; |
| 9927 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 9925 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 9928 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 9926 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 9929 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 9927 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 9930 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 9928 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 9931 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 9929 expect(variableName.propagatedType, same(typeA)); |
| 9932 } | 9930 } |
| 9933 | 9931 |
| 9934 void test_assignment() { | 9932 void test_assignment() { |
| 9935 Source source = addSource(r''' | 9933 Source source = addSource(r''' |
| 9936 f() { | 9934 f() { |
| 9937 var v; | 9935 var v; |
| 9938 v = 0; | 9936 v = 0; |
| 9939 return v; | 9937 return v; |
| 9940 }'''); | 9938 }'''); |
| 9941 LibraryElement library = resolve(source); | 9939 LibraryElement library = resolve(source); |
| 9942 assertNoErrors(source); | 9940 assertNoErrors(source); |
| 9943 verify([source]); | 9941 verify([source]); |
| 9944 CompilationUnit unit = resolveCompilationUnit(source, library); | 9942 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9945 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 9943 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 9946 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 9944 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 9947 ReturnStatement statement = body.block.statements[2] as ReturnStatement; | 9945 ReturnStatement statement = body.block.statements[2] as ReturnStatement; |
| 9948 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 9946 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 9949 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType); | 9947 expect(variableName.propagatedType, same(typeProvider.intType)); |
| 9950 } | 9948 } |
| 9951 | 9949 |
| 9952 void test_assignment_afterInitializer() { | 9950 void test_assignment_afterInitializer() { |
| 9953 Source source = addSource(r''' | 9951 Source source = addSource(r''' |
| 9954 f() { | 9952 f() { |
| 9955 var v = 0; | 9953 var v = 0; |
| 9956 v = 1.0; | 9954 v = 1.0; |
| 9957 return v; | 9955 return v; |
| 9958 }'''); | 9956 }'''); |
| 9959 LibraryElement library = resolve(source); | 9957 LibraryElement library = resolve(source); |
| 9960 assertNoErrors(source); | 9958 assertNoErrors(source); |
| 9961 verify([source]); | 9959 verify([source]); |
| 9962 CompilationUnit unit = resolveCompilationUnit(source, library); | 9960 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 9963 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 9961 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 9964 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 9962 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 9965 ReturnStatement statement = body.block.statements[2] as ReturnStatement; | 9963 ReturnStatement statement = body.block.statements[2] as ReturnStatement; |
| 9966 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 9964 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 9967 JUnitTestCase.assertSame(typeProvider.doubleType, variableName.propagatedTyp
e); | 9965 expect(variableName.propagatedType, same(typeProvider.doubleType)); |
| 9968 } | 9966 } |
| 9969 | 9967 |
| 9970 void test_assignment_null() { | 9968 void test_assignment_null() { |
| 9971 String code = r''' | 9969 String code = r''' |
| 9972 main() { | 9970 main() { |
| 9973 int v; // declare | 9971 int v; // declare |
| 9974 v = null; | 9972 v = null; |
| 9975 return v; // return | 9973 return v; // return |
| 9976 }'''; | 9974 }'''; |
| 9977 CompilationUnit unit; | 9975 CompilationUnit unit; |
| 9978 { | 9976 { |
| 9979 Source source = addSource(code); | 9977 Source source = addSource(code); |
| 9980 LibraryElement library = resolve(source); | 9978 LibraryElement library = resolve(source); |
| 9981 assertNoErrors(source); | 9979 assertNoErrors(source); |
| 9982 verify([source]); | 9980 verify([source]); |
| 9983 unit = resolveCompilationUnit(source, library); | 9981 unit = resolveCompilationUnit(source, library); |
| 9984 } | 9982 } |
| 9985 { | 9983 { |
| 9986 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v; // d
eclare", (node) => node is SimpleIdentifier); | 9984 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v; // d
eclare", (node) => node is SimpleIdentifier); |
| 9987 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); | 9985 expect(identifier.staticType, same(typeProvider.intType)); |
| 9988 JUnitTestCase.assertSame(null, identifier.propagatedType); | 9986 expect(identifier.propagatedType, same(null)); |
| 9989 } | 9987 } |
| 9990 { | 9988 { |
| 9991 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v = nul
l;", (node) => node is SimpleIdentifier); | 9989 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v = nul
l;", (node) => node is SimpleIdentifier); |
| 9992 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); | 9990 expect(identifier.staticType, same(typeProvider.intType)); |
| 9993 JUnitTestCase.assertSame(null, identifier.propagatedType); | 9991 expect(identifier.propagatedType, same(null)); |
| 9994 } | 9992 } |
| 9995 { | 9993 { |
| 9996 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v; // r
eturn", (node) => node is SimpleIdentifier); | 9994 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v; // r
eturn", (node) => node is SimpleIdentifier); |
| 9997 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); | 9995 expect(identifier.staticType, same(typeProvider.intType)); |
| 9998 JUnitTestCase.assertSame(null, identifier.propagatedType); | 9996 expect(identifier.propagatedType, same(null)); |
| 9999 } | 9997 } |
| 10000 } | 9998 } |
| 10001 | 9999 |
| 10002 void test_CanvasElement_getContext() { | 10000 void test_CanvasElement_getContext() { |
| 10003 String code = r''' | 10001 String code = r''' |
| 10004 import 'dart:html'; | 10002 import 'dart:html'; |
| 10005 main(CanvasElement canvas) { | 10003 main(CanvasElement canvas) { |
| 10006 var context = canvas.getContext('2d'); | 10004 var context = canvas.getContext('2d'); |
| 10007 }'''; | 10005 }'''; |
| 10008 Source source = addSource(code); | 10006 Source source = addSource(code); |
| 10009 LibraryElement library = resolve(source); | 10007 LibraryElement library = resolve(source); |
| 10010 assertNoErrors(source); | 10008 assertNoErrors(source); |
| 10011 verify([source]); | 10009 verify([source]); |
| 10012 CompilationUnit unit = resolveCompilationUnit(source, library); | 10010 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10013 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "context",
(node) => node is SimpleIdentifier); | 10011 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "context",
(node) => node is SimpleIdentifier); |
| 10014 JUnitTestCase.assertEquals("CanvasRenderingContext2D", identifier.propagated
Type.name); | 10012 expect(identifier.propagatedType.name, "CanvasRenderingContext2D"); |
| 10015 } | 10013 } |
| 10016 | 10014 |
| 10017 void test_finalPropertyInducingVariable_classMember_instance() { | 10015 void test_finalPropertyInducingVariable_classMember_instance() { |
| 10018 addNamedSource("/lib.dart", r''' | 10016 addNamedSource("/lib.dart", r''' |
| 10019 class A { | 10017 class A { |
| 10020 final v = 0; | 10018 final v = 0; |
| 10021 }'''); | 10019 }'''); |
| 10022 String code = r''' | 10020 String code = r''' |
| 10023 import 'lib.dart'; | 10021 import 'lib.dart'; |
| 10024 f(A a) { | 10022 f(A a) { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10100 }'''; | 10098 }'''; |
| 10101 Source source = addSource(code); | 10099 Source source = addSource(code); |
| 10102 LibraryElement library = resolve(source); | 10100 LibraryElement library = resolve(source); |
| 10103 assertNoErrors(source); | 10101 assertNoErrors(source); |
| 10104 verify([source]); | 10102 verify([source]); |
| 10105 CompilationUnit unit = resolveCompilationUnit(source, library); | 10103 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10106 InterfaceType stringType = typeProvider.stringType; | 10104 InterfaceType stringType = typeProvider.stringType; |
| 10107 // in the declaration | 10105 // in the declaration |
| 10108 { | 10106 { |
| 10109 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e in",
(node) => node is SimpleIdentifier); | 10107 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e in",
(node) => node is SimpleIdentifier); |
| 10110 JUnitTestCase.assertSame(stringType, identifier.propagatedType); | 10108 expect(identifier.propagatedType, same(stringType)); |
| 10111 } | 10109 } |
| 10112 // in the loop body | 10110 // in the loop body |
| 10113 { | 10111 { |
| 10114 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e;", (n
ode) => node is SimpleIdentifier); | 10112 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "e;", (n
ode) => node is SimpleIdentifier); |
| 10115 JUnitTestCase.assertSame(stringType, identifier.propagatedType); | 10113 expect(identifier.propagatedType, same(stringType)); |
| 10116 } | 10114 } |
| 10117 } | 10115 } |
| 10118 | 10116 |
| 10119 void test_functionExpression_asInvocationArgument() { | 10117 void test_functionExpression_asInvocationArgument() { |
| 10120 String code = r''' | 10118 String code = r''' |
| 10121 class MyMap<K, V> { | 10119 class MyMap<K, V> { |
| 10122 forEach(f(K key, V value)) {} | 10120 forEach(f(K key, V value)) {} |
| 10123 } | 10121 } |
| 10124 f(MyMap<int, String> m) { | 10122 f(MyMap<int, String> m) { |
| 10125 m.forEach((k, v) { | 10123 m.forEach((k, v) { |
| 10126 k; | 10124 k; |
| 10127 v; | 10125 v; |
| 10128 }); | 10126 }); |
| 10129 }'''; | 10127 }'''; |
| 10130 Source source = addSource(code); | 10128 Source source = addSource(code); |
| 10131 LibraryElement library = resolve(source); | 10129 LibraryElement library = resolve(source); |
| 10132 assertNoErrors(source); | 10130 assertNoErrors(source); |
| 10133 verify([source]); | 10131 verify([source]); |
| 10134 CompilationUnit unit = resolveCompilationUnit(source, library); | 10132 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10135 // k | 10133 // k |
| 10136 DartType intType = typeProvider.intType; | 10134 DartType intType = typeProvider.intType; |
| 10137 FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", (nod
e) => node is SimpleFormalParameter); | 10135 FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", (nod
e) => node is SimpleFormalParameter); |
| 10138 JUnitTestCase.assertSame(intType, kParameter.identifier.propagatedType); | 10136 expect(kParameter.identifier.propagatedType, same(intType)); |
| 10139 SimpleIdentifier kIdentifier = EngineTestCase.findNode(unit, code, "k;", (no
de) => node is SimpleIdentifier); | 10137 SimpleIdentifier kIdentifier = EngineTestCase.findNode(unit, code, "k;", (no
de) => node is SimpleIdentifier); |
| 10140 JUnitTestCase.assertSame(intType, kIdentifier.propagatedType); | 10138 expect(kIdentifier.propagatedType, same(intType)); |
| 10141 JUnitTestCase.assertSame(typeProvider.dynamicType, kIdentifier.staticType); | 10139 expect(kIdentifier.staticType, same(typeProvider.dynamicType)); |
| 10142 // v | 10140 // v |
| 10143 DartType stringType = typeProvider.stringType; | 10141 DartType stringType = typeProvider.stringType; |
| 10144 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); | 10142 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); |
| 10145 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); | 10143 expect(vParameter.identifier.propagatedType, same(stringType)); |
| 10146 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); | 10144 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); |
| 10147 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); | 10145 expect(vIdentifier.propagatedType, same(stringType)); |
| 10148 JUnitTestCase.assertSame(typeProvider.dynamicType, vIdentifier.staticType); | 10146 expect(vIdentifier.staticType, same(typeProvider.dynamicType)); |
| 10149 } | 10147 } |
| 10150 | 10148 |
| 10151 void test_functionExpression_asInvocationArgument_fromInferredInvocation() { | 10149 void test_functionExpression_asInvocationArgument_fromInferredInvocation() { |
| 10152 String code = r''' | 10150 String code = r''' |
| 10153 class MyMap<K, V> { | 10151 class MyMap<K, V> { |
| 10154 forEach(f(K key, V value)) {} | 10152 forEach(f(K key, V value)) {} |
| 10155 } | 10153 } |
| 10156 f(MyMap<int, String> m) { | 10154 f(MyMap<int, String> m) { |
| 10157 var m2 = m; | 10155 var m2 = m; |
| 10158 m2.forEach((k, v) {}); | 10156 m2.forEach((k, v) {}); |
| 10159 }'''; | 10157 }'''; |
| 10160 Source source = addSource(code); | 10158 Source source = addSource(code); |
| 10161 LibraryElement library = resolve(source); | 10159 LibraryElement library = resolve(source); |
| 10162 assertNoErrors(source); | 10160 assertNoErrors(source); |
| 10163 verify([source]); | 10161 verify([source]); |
| 10164 CompilationUnit unit = resolveCompilationUnit(source, library); | 10162 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10165 // k | 10163 // k |
| 10166 DartType intType = typeProvider.intType; | 10164 DartType intType = typeProvider.intType; |
| 10167 FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", (nod
e) => node is SimpleFormalParameter); | 10165 FormalParameter kParameter = EngineTestCase.findNode(unit, code, "k, ", (nod
e) => node is SimpleFormalParameter); |
| 10168 JUnitTestCase.assertSame(intType, kParameter.identifier.propagatedType); | 10166 expect(kParameter.identifier.propagatedType, same(intType)); |
| 10169 // v | 10167 // v |
| 10170 DartType stringType = typeProvider.stringType; | 10168 DartType stringType = typeProvider.stringType; |
| 10171 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); | 10169 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); |
| 10172 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); | 10170 expect(vParameter.identifier.propagatedType, same(stringType)); |
| 10173 } | 10171 } |
| 10174 | 10172 |
| 10175 void test_functionExpression_asInvocationArgument_functionExpressionInvocation
() { | 10173 void test_functionExpression_asInvocationArgument_functionExpressionInvocation
() { |
| 10176 String code = r''' | 10174 String code = r''' |
| 10177 main() { | 10175 main() { |
| 10178 (f(String value)) {} ((v) { | 10176 (f(String value)) {} ((v) { |
| 10179 v; | 10177 v; |
| 10180 }); | 10178 }); |
| 10181 }'''; | 10179 }'''; |
| 10182 Source source = addSource(code); | 10180 Source source = addSource(code); |
| 10183 LibraryElement library = resolve(source); | 10181 LibraryElement library = resolve(source); |
| 10184 assertNoErrors(source); | 10182 assertNoErrors(source); |
| 10185 verify([source]); | 10183 verify([source]); |
| 10186 CompilationUnit unit = resolveCompilationUnit(source, library); | 10184 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10187 // v | 10185 // v |
| 10188 DartType dynamicType = typeProvider.dynamicType; | 10186 DartType dynamicType = typeProvider.dynamicType; |
| 10189 DartType stringType = typeProvider.stringType; | 10187 DartType stringType = typeProvider.stringType; |
| 10190 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is FormalParameter); | 10188 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is FormalParameter); |
| 10191 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); | 10189 expect(vParameter.identifier.propagatedType, same(stringType)); |
| 10192 JUnitTestCase.assertSame(dynamicType, vParameter.identifier.staticType); | 10190 expect(vParameter.identifier.staticType, same(dynamicType)); |
| 10193 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); | 10191 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); |
| 10194 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); | 10192 expect(vIdentifier.propagatedType, same(stringType)); |
| 10195 JUnitTestCase.assertSame(dynamicType, vIdentifier.staticType); | 10193 expect(vIdentifier.staticType, same(dynamicType)); |
| 10196 } | 10194 } |
| 10197 | 10195 |
| 10198 void test_functionExpression_asInvocationArgument_keepIfLessSpecific() { | 10196 void test_functionExpression_asInvocationArgument_keepIfLessSpecific() { |
| 10199 String code = r''' | 10197 String code = r''' |
| 10200 class MyList { | 10198 class MyList { |
| 10201 forEach(f(Object value)) {} | 10199 forEach(f(Object value)) {} |
| 10202 } | 10200 } |
| 10203 f(MyList list) { | 10201 f(MyList list) { |
| 10204 list.forEach((int v) { | 10202 list.forEach((int v) { |
| 10205 v; | 10203 v; |
| 10206 }); | 10204 }); |
| 10207 }'''; | 10205 }'''; |
| 10208 Source source = addSource(code); | 10206 Source source = addSource(code); |
| 10209 LibraryElement library = resolve(source); | 10207 LibraryElement library = resolve(source); |
| 10210 assertNoErrors(source); | 10208 assertNoErrors(source); |
| 10211 verify([source]); | 10209 verify([source]); |
| 10212 CompilationUnit unit = resolveCompilationUnit(source, library); | 10210 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10213 // v | 10211 // v |
| 10214 DartType intType = typeProvider.intType; | 10212 DartType intType = typeProvider.intType; |
| 10215 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); | 10213 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); |
| 10216 JUnitTestCase.assertSame(null, vParameter.identifier.propagatedType); | 10214 expect(vParameter.identifier.propagatedType, same(null)); |
| 10217 JUnitTestCase.assertSame(intType, vParameter.identifier.staticType); | 10215 expect(vParameter.identifier.staticType, same(intType)); |
| 10218 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); | 10216 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); |
| 10219 JUnitTestCase.assertSame(intType, vIdentifier.staticType); | 10217 expect(vIdentifier.staticType, same(intType)); |
| 10220 JUnitTestCase.assertSame(null, vIdentifier.propagatedType); | 10218 expect(vIdentifier.propagatedType, same(null)); |
| 10221 } | 10219 } |
| 10222 | 10220 |
| 10223 void test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() { | 10221 void test_functionExpression_asInvocationArgument_notSubtypeOfStaticType() { |
| 10224 String code = r''' | 10222 String code = r''' |
| 10225 class A { | 10223 class A { |
| 10226 m(void f(int i)) {} | 10224 m(void f(int i)) {} |
| 10227 } | 10225 } |
| 10228 x() { | 10226 x() { |
| 10229 A a = new A(); | 10227 A a = new A(); |
| 10230 a.m(() => 0); | 10228 a.m(() => 0); |
| 10231 }'''; | 10229 }'''; |
| 10232 Source source = addSource(code); | 10230 Source source = addSource(code); |
| 10233 LibraryElement library = resolve(source); | 10231 LibraryElement library = resolve(source); |
| 10234 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); | 10232 assertErrors(source, [StaticWarningCode.ARGUMENT_TYPE_NOT_ASSIGNABLE]); |
| 10235 verify([source]); | 10233 verify([source]); |
| 10236 CompilationUnit unit = resolveCompilationUnit(source, library); | 10234 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10237 // () => 0 | 10235 // () => 0 |
| 10238 FunctionExpression functionExpression = EngineTestCase.findNode(unit, code,
"() => 0)", (node) => node is FunctionExpression); | 10236 FunctionExpression functionExpression = EngineTestCase.findNode(unit, code,
"() => 0)", (node) => node is FunctionExpression); |
| 10239 JUnitTestCase.assertSame(0, (functionExpression.staticType as FunctionType).
parameters.length); | 10237 expect((functionExpression.staticType as FunctionType).parameters.length, sa
me(0)); |
| 10240 JUnitTestCase.assertSame(null, functionExpression.propagatedType); | 10238 expect(functionExpression.propagatedType, same(null)); |
| 10241 } | 10239 } |
| 10242 | 10240 |
| 10243 void test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() { | 10241 void test_functionExpression_asInvocationArgument_replaceIfMoreSpecific() { |
| 10244 String code = r''' | 10242 String code = r''' |
| 10245 class MyList<E> { | 10243 class MyList<E> { |
| 10246 forEach(f(E value)) {} | 10244 forEach(f(E value)) {} |
| 10247 } | 10245 } |
| 10248 f(MyList<String> list) { | 10246 f(MyList<String> list) { |
| 10249 list.forEach((Object v) { | 10247 list.forEach((Object v) { |
| 10250 v; | 10248 v; |
| 10251 }); | 10249 }); |
| 10252 }'''; | 10250 }'''; |
| 10253 Source source = addSource(code); | 10251 Source source = addSource(code); |
| 10254 LibraryElement library = resolve(source); | 10252 LibraryElement library = resolve(source); |
| 10255 assertNoErrors(source); | 10253 assertNoErrors(source); |
| 10256 verify([source]); | 10254 verify([source]); |
| 10257 CompilationUnit unit = resolveCompilationUnit(source, library); | 10255 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10258 // v | 10256 // v |
| 10259 DartType stringType = typeProvider.stringType; | 10257 DartType stringType = typeProvider.stringType; |
| 10260 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); | 10258 FormalParameter vParameter = EngineTestCase.findNode(unit, code, "v)", (node
) => node is SimpleFormalParameter); |
| 10261 JUnitTestCase.assertSame(stringType, vParameter.identifier.propagatedType); | 10259 expect(vParameter.identifier.propagatedType, same(stringType)); |
| 10262 JUnitTestCase.assertSame(typeProvider.objectType, vParameter.identifier.stat
icType); | 10260 expect(vParameter.identifier.staticType, same(typeProvider.objectType)); |
| 10263 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); | 10261 SimpleIdentifier vIdentifier = EngineTestCase.findNode(unit, code, "v;", (no
de) => node is SimpleIdentifier); |
| 10264 JUnitTestCase.assertSame(stringType, vIdentifier.propagatedType); | 10262 expect(vIdentifier.propagatedType, same(stringType)); |
| 10265 } | 10263 } |
| 10266 | 10264 |
| 10267 void test_Future_then() { | 10265 void test_Future_then() { |
| 10268 String code = r''' | 10266 String code = r''' |
| 10269 import 'dart:async'; | 10267 import 'dart:async'; |
| 10270 main(Future<int> firstFuture) { | 10268 main(Future<int> firstFuture) { |
| 10271 firstFuture.then((p1) { | 10269 firstFuture.then((p1) { |
| 10272 return 1.0; | 10270 return 1.0; |
| 10273 }).then((p2) { | 10271 }).then((p2) { |
| 10274 return new Future<String>.value('str'); | 10272 return new Future<String>.value('str'); |
| 10275 }).then((p3) { | 10273 }).then((p3) { |
| 10276 }); | 10274 }); |
| 10277 }'''; | 10275 }'''; |
| 10278 Source source = addSource(code); | 10276 Source source = addSource(code); |
| 10279 LibraryElement library = resolve(source); | 10277 LibraryElement library = resolve(source); |
| 10280 assertNoErrors(source); | 10278 assertNoErrors(source); |
| 10281 verify([source]); | 10279 verify([source]); |
| 10282 CompilationUnit unit = resolveCompilationUnit(source, library); | 10280 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10283 // p1 | 10281 // p1 |
| 10284 FormalParameter p1 = EngineTestCase.findNode(unit, code, "p1) {", (node) =>
node is SimpleFormalParameter); | 10282 FormalParameter p1 = EngineTestCase.findNode(unit, code, "p1) {", (node) =>
node is SimpleFormalParameter); |
| 10285 JUnitTestCase.assertSame(typeProvider.intType, p1.identifier.propagatedType)
; | 10283 expect(p1.identifier.propagatedType, same(typeProvider.intType)); |
| 10286 // p2 | 10284 // p2 |
| 10287 FormalParameter p2 = EngineTestCase.findNode(unit, code, "p2) {", (node) =>
node is SimpleFormalParameter); | 10285 FormalParameter p2 = EngineTestCase.findNode(unit, code, "p2) {", (node) =>
node is SimpleFormalParameter); |
| 10288 JUnitTestCase.assertSame(typeProvider.doubleType, p2.identifier.propagatedTy
pe); | 10286 expect(p2.identifier.propagatedType, same(typeProvider.doubleType)); |
| 10289 // p3 | 10287 // p3 |
| 10290 FormalParameter p3 = EngineTestCase.findNode(unit, code, "p3) {", (node) =>
node is SimpleFormalParameter); | 10288 FormalParameter p3 = EngineTestCase.findNode(unit, code, "p3) {", (node) =>
node is SimpleFormalParameter); |
| 10291 JUnitTestCase.assertSame(typeProvider.stringType, p3.identifier.propagatedTy
pe); | 10289 expect(p3.identifier.propagatedType, same(typeProvider.stringType)); |
| 10292 } | 10290 } |
| 10293 | 10291 |
| 10294 void test_initializer() { | 10292 void test_initializer() { |
| 10295 Source source = addSource(r''' | 10293 Source source = addSource(r''' |
| 10296 f() { | 10294 f() { |
| 10297 var v = 0; | 10295 var v = 0; |
| 10298 return v; | 10296 return v; |
| 10299 }'''); | 10297 }'''); |
| 10300 LibraryElement library = resolve(source); | 10298 LibraryElement library = resolve(source); |
| 10301 assertNoErrors(source); | 10299 assertNoErrors(source); |
| 10302 verify([source]); | 10300 verify([source]); |
| 10303 CompilationUnit unit = resolveCompilationUnit(source, library); | 10301 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10304 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 10302 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 10305 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10303 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10306 NodeList<Statement> statements = body.block.statements; | 10304 NodeList<Statement> statements = body.block.statements; |
| 10307 // Type of 'v' in declaration. | 10305 // Type of 'v' in declaration. |
| 10308 { | 10306 { |
| 10309 VariableDeclarationStatement statement = statements[0] as VariableDeclarat
ionStatement; | 10307 VariableDeclarationStatement statement = statements[0] as VariableDeclarat
ionStatement; |
| 10310 SimpleIdentifier variableName = statement.variables.variables[0].name; | 10308 SimpleIdentifier variableName = statement.variables.variables[0].name; |
| 10311 JUnitTestCase.assertSame(typeProvider.dynamicType, variableName.staticType
); | 10309 expect(variableName.staticType, same(typeProvider.dynamicType)); |
| 10312 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType
); | 10310 expect(variableName.propagatedType, same(typeProvider.intType)); |
| 10313 } | 10311 } |
| 10314 // Type of 'v' in reference. | 10312 // Type of 'v' in reference. |
| 10315 { | 10313 { |
| 10316 ReturnStatement statement = statements[1] as ReturnStatement; | 10314 ReturnStatement statement = statements[1] as ReturnStatement; |
| 10317 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10315 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10318 JUnitTestCase.assertSame(typeProvider.intType, variableName.propagatedType
); | 10316 expect(variableName.propagatedType, same(typeProvider.intType)); |
| 10319 } | 10317 } |
| 10320 } | 10318 } |
| 10321 | 10319 |
| 10322 void test_initializer_dereference() { | 10320 void test_initializer_dereference() { |
| 10323 Source source = addSource(r''' | 10321 Source source = addSource(r''' |
| 10324 f() { | 10322 f() { |
| 10325 var v = 'String'; | 10323 var v = 'String'; |
| 10326 v. | 10324 v. |
| 10327 }'''); | 10325 }'''); |
| 10328 LibraryElement library = resolve(source); | 10326 LibraryElement library = resolve(source); |
| 10329 CompilationUnit unit = resolveCompilationUnit(source, library); | 10327 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10330 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 10328 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 10331 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10329 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10332 ExpressionStatement statement = body.block.statements[1] as ExpressionStatem
ent; | 10330 ExpressionStatement statement = body.block.statements[1] as ExpressionStatem
ent; |
| 10333 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; | 10331 PrefixedIdentifier invocation = statement.expression as PrefixedIdentifier; |
| 10334 SimpleIdentifier variableName = invocation.prefix; | 10332 SimpleIdentifier variableName = invocation.prefix; |
| 10335 JUnitTestCase.assertSame(typeProvider.stringType, variableName.propagatedTyp
e); | 10333 expect(variableName.propagatedType, same(typeProvider.stringType)); |
| 10336 } | 10334 } |
| 10337 | 10335 |
| 10338 void test_initializer_null() { | 10336 void test_initializer_null() { |
| 10339 String code = r''' | 10337 String code = r''' |
| 10340 main() { | 10338 main() { |
| 10341 int v = null; | 10339 int v = null; |
| 10342 return v; // marker | 10340 return v; // marker |
| 10343 }'''; | 10341 }'''; |
| 10344 CompilationUnit unit; | 10342 CompilationUnit unit; |
| 10345 { | 10343 { |
| 10346 Source source = addSource(code); | 10344 Source source = addSource(code); |
| 10347 LibraryElement library = resolve(source); | 10345 LibraryElement library = resolve(source); |
| 10348 assertNoErrors(source); | 10346 assertNoErrors(source); |
| 10349 verify([source]); | 10347 verify([source]); |
| 10350 unit = resolveCompilationUnit(source, library); | 10348 unit = resolveCompilationUnit(source, library); |
| 10351 } | 10349 } |
| 10352 { | 10350 { |
| 10353 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v = nul
l;", (node) => node is SimpleIdentifier); | 10351 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v = nul
l;", (node) => node is SimpleIdentifier); |
| 10354 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); | 10352 expect(identifier.staticType, same(typeProvider.intType)); |
| 10355 JUnitTestCase.assertSame(null, identifier.propagatedType); | 10353 expect(identifier.propagatedType, same(null)); |
| 10356 } | 10354 } |
| 10357 { | 10355 { |
| 10358 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v; // m
arker", (node) => node is SimpleIdentifier); | 10356 SimpleIdentifier identifier = EngineTestCase.findNode(unit, code, "v; // m
arker", (node) => node is SimpleIdentifier); |
| 10359 JUnitTestCase.assertSame(typeProvider.intType, identifier.staticType); | 10357 expect(identifier.staticType, same(typeProvider.intType)); |
| 10360 JUnitTestCase.assertSame(null, identifier.propagatedType); | 10358 expect(identifier.propagatedType, same(null)); |
| 10361 } | 10359 } |
| 10362 } | 10360 } |
| 10363 | 10361 |
| 10364 void test_is_conditional() { | 10362 void test_is_conditional() { |
| 10365 Source source = addSource(r''' | 10363 Source source = addSource(r''' |
| 10366 class A {} | 10364 class A {} |
| 10367 A f(var p) { | 10365 A f(var p) { |
| 10368 return (p is A) ? p : null; | 10366 return (p is A) ? p : null; |
| 10369 }'''); | 10367 }'''); |
| 10370 LibraryElement library = resolve(source); | 10368 LibraryElement library = resolve(source); |
| 10371 assertNoErrors(source); | 10369 assertNoErrors(source); |
| 10372 verify([source]); | 10370 verify([source]); |
| 10373 CompilationUnit unit = resolveCompilationUnit(source, library); | 10371 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10374 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10372 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10375 InterfaceType typeA = classA.element.type; | 10373 InterfaceType typeA = classA.element.type; |
| 10376 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10374 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10377 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10375 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10378 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 10376 ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| 10379 ConditionalExpression conditional = statement.expression as ConditionalExpre
ssion; | 10377 ConditionalExpression conditional = statement.expression as ConditionalExpre
ssion; |
| 10380 SimpleIdentifier variableName = conditional.thenExpression as SimpleIdentifi
er; | 10378 SimpleIdentifier variableName = conditional.thenExpression as SimpleIdentifi
er; |
| 10381 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10379 expect(variableName.propagatedType, same(typeA)); |
| 10382 } | 10380 } |
| 10383 | 10381 |
| 10384 void test_is_if() { | 10382 void test_is_if() { |
| 10385 Source source = addSource(r''' | 10383 Source source = addSource(r''' |
| 10386 class A {} | 10384 class A {} |
| 10387 A f(var p) { | 10385 A f(var p) { |
| 10388 if (p is A) { | 10386 if (p is A) { |
| 10389 return p; | 10387 return p; |
| 10390 } else { | 10388 } else { |
| 10391 return null; | 10389 return null; |
| 10392 } | 10390 } |
| 10393 }'''); | 10391 }'''); |
| 10394 LibraryElement library = resolve(source); | 10392 LibraryElement library = resolve(source); |
| 10395 assertNoErrors(source); | 10393 assertNoErrors(source); |
| 10396 verify([source]); | 10394 verify([source]); |
| 10397 CompilationUnit unit = resolveCompilationUnit(source, library); | 10395 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10398 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10396 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10399 InterfaceType typeA = classA.element.type; | 10397 InterfaceType typeA = classA.element.type; |
| 10400 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10398 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10401 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10399 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10402 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 10400 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 10403 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; | 10401 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; |
| 10404 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10402 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10405 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10403 expect(variableName.propagatedType, same(typeA)); |
| 10406 } | 10404 } |
| 10407 | 10405 |
| 10408 void test_is_if_lessSpecific() { | 10406 void test_is_if_lessSpecific() { |
| 10409 Source source = addSource(r''' | 10407 Source source = addSource(r''' |
| 10410 class A {} | 10408 class A {} |
| 10411 A f(A p) { | 10409 A f(A p) { |
| 10412 if (p is String) { | 10410 if (p is String) { |
| 10413 return p; | 10411 return p; |
| 10414 } else { | 10412 } else { |
| 10415 return null; | 10413 return null; |
| 10416 } | 10414 } |
| 10417 }'''); | 10415 }'''); |
| 10418 LibraryElement library = resolve(source); | 10416 LibraryElement library = resolve(source); |
| 10419 assertNoErrors(source); | 10417 assertNoErrors(source); |
| 10420 verify([source]); | 10418 verify([source]); |
| 10421 CompilationUnit unit = resolveCompilationUnit(source, library); | 10419 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10422 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().ge
t(0); | 10420 // ClassDeclaration classA = (ClassDeclaration) unit.getDeclarations().ge
t(0); |
| 10423 // InterfaceType typeA = classA.getElement().getType(); | 10421 // InterfaceType typeA = classA.getElement().getType(); |
| 10424 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10422 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10425 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10423 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10426 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 10424 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 10427 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; | 10425 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; |
| 10428 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10426 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10429 JUnitTestCase.assertSame(null, variableName.propagatedType); | 10427 expect(variableName.propagatedType, same(null)); |
| 10430 } | 10428 } |
| 10431 | 10429 |
| 10432 void test_is_if_logicalAnd() { | 10430 void test_is_if_logicalAnd() { |
| 10433 Source source = addSource(r''' | 10431 Source source = addSource(r''' |
| 10434 class A {} | 10432 class A {} |
| 10435 A f(var p) { | 10433 A f(var p) { |
| 10436 if (p is A && p != null) { | 10434 if (p is A && p != null) { |
| 10437 return p; | 10435 return p; |
| 10438 } else { | 10436 } else { |
| 10439 return null; | 10437 return null; |
| 10440 } | 10438 } |
| 10441 }'''); | 10439 }'''); |
| 10442 LibraryElement library = resolve(source); | 10440 LibraryElement library = resolve(source); |
| 10443 assertNoErrors(source); | 10441 assertNoErrors(source); |
| 10444 verify([source]); | 10442 verify([source]); |
| 10445 CompilationUnit unit = resolveCompilationUnit(source, library); | 10443 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10446 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10444 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10447 InterfaceType typeA = classA.element.type; | 10445 InterfaceType typeA = classA.element.type; |
| 10448 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10446 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10449 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10447 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10450 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 10448 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 10451 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; | 10449 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; |
| 10452 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10450 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10453 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10451 expect(variableName.propagatedType, same(typeA)); |
| 10454 } | 10452 } |
| 10455 | 10453 |
| 10456 void test_is_postConditional() { | 10454 void test_is_postConditional() { |
| 10457 Source source = addSource(r''' | 10455 Source source = addSource(r''' |
| 10458 class A {} | 10456 class A {} |
| 10459 A f(var p) { | 10457 A f(var p) { |
| 10460 A a = (p is A) ? p : throw null; | 10458 A a = (p is A) ? p : throw null; |
| 10461 return p; | 10459 return p; |
| 10462 }'''); | 10460 }'''); |
| 10463 LibraryElement library = resolve(source); | 10461 LibraryElement library = resolve(source); |
| 10464 assertNoErrors(source); | 10462 assertNoErrors(source); |
| 10465 verify([source]); | 10463 verify([source]); |
| 10466 CompilationUnit unit = resolveCompilationUnit(source, library); | 10464 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10467 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10465 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10468 InterfaceType typeA = classA.element.type; | 10466 InterfaceType typeA = classA.element.type; |
| 10469 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10467 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10470 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10468 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10471 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10469 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10472 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10470 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10473 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10471 expect(variableName.propagatedType, same(typeA)); |
| 10474 } | 10472 } |
| 10475 | 10473 |
| 10476 void test_is_postIf() { | 10474 void test_is_postIf() { |
| 10477 Source source = addSource(r''' | 10475 Source source = addSource(r''' |
| 10478 class A {} | 10476 class A {} |
| 10479 A f(var p) { | 10477 A f(var p) { |
| 10480 if (p is A) { | 10478 if (p is A) { |
| 10481 A a = p; | 10479 A a = p; |
| 10482 } else { | 10480 } else { |
| 10483 return null; | 10481 return null; |
| 10484 } | 10482 } |
| 10485 return p; | 10483 return p; |
| 10486 }'''); | 10484 }'''); |
| 10487 LibraryElement library = resolve(source); | 10485 LibraryElement library = resolve(source); |
| 10488 assertNoErrors(source); | 10486 assertNoErrors(source); |
| 10489 verify([source]); | 10487 verify([source]); |
| 10490 CompilationUnit unit = resolveCompilationUnit(source, library); | 10488 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10491 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10489 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10492 InterfaceType typeA = classA.element.type; | 10490 InterfaceType typeA = classA.element.type; |
| 10493 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10491 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10494 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10492 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10495 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10493 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10496 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10494 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10497 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10495 expect(variableName.propagatedType, same(typeA)); |
| 10498 } | 10496 } |
| 10499 | 10497 |
| 10500 void test_is_subclass() { | 10498 void test_is_subclass() { |
| 10501 Source source = addSource(r''' | 10499 Source source = addSource(r''' |
| 10502 class A {} | 10500 class A {} |
| 10503 class B extends A { | 10501 class B extends A { |
| 10504 B m() => this; | 10502 B m() => this; |
| 10505 } | 10503 } |
| 10506 A f(A p) { | 10504 A f(A p) { |
| 10507 if (p is B) { | 10505 if (p is B) { |
| 10508 return p.m(); | 10506 return p.m(); |
| 10509 } | 10507 } |
| 10510 return p; | 10508 return p; |
| 10511 }'''); | 10509 }'''); |
| 10512 LibraryElement library = resolve(source); | 10510 LibraryElement library = resolve(source); |
| 10513 assertNoErrors(source); | 10511 assertNoErrors(source); |
| 10514 CompilationUnit unit = resolveCompilationUnit(source, library); | 10512 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10515 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; | 10513 FunctionDeclaration function = unit.declarations[2] as FunctionDeclaration; |
| 10516 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10514 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10517 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 10515 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 10518 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; | 10516 ReturnStatement statement = (ifStatement.thenStatement as Block).statements[
0] as ReturnStatement; |
| 10519 MethodInvocation invocation = statement.expression as MethodInvocation; | 10517 MethodInvocation invocation = statement.expression as MethodInvocation; |
| 10520 JUnitTestCase.assertNotNull(invocation.methodName.propagatedElement); | 10518 expect(invocation.methodName.propagatedElement, isNotNull); |
| 10521 } | 10519 } |
| 10522 | 10520 |
| 10523 void test_is_while() { | 10521 void test_is_while() { |
| 10524 Source source = addSource(r''' | 10522 Source source = addSource(r''' |
| 10525 class A {} | 10523 class A {} |
| 10526 A f(var p) { | 10524 A f(var p) { |
| 10527 while (p is A) { | 10525 while (p is A) { |
| 10528 return p; | 10526 return p; |
| 10529 } | 10527 } |
| 10530 return p; | 10528 return p; |
| 10531 }'''); | 10529 }'''); |
| 10532 LibraryElement library = resolve(source); | 10530 LibraryElement library = resolve(source); |
| 10533 assertNoErrors(source); | 10531 assertNoErrors(source); |
| 10534 verify([source]); | 10532 verify([source]); |
| 10535 CompilationUnit unit = resolveCompilationUnit(source, library); | 10533 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10536 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10534 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10537 InterfaceType typeA = classA.element.type; | 10535 InterfaceType typeA = classA.element.type; |
| 10538 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10536 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10539 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10537 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10540 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; | 10538 WhileStatement whileStatement = body.block.statements[0] as WhileStatement; |
| 10541 ReturnStatement statement = (whileStatement.body as Block).statements[0] as
ReturnStatement; | 10539 ReturnStatement statement = (whileStatement.body as Block).statements[0] as
ReturnStatement; |
| 10542 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10540 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10543 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10541 expect(variableName.propagatedType, same(typeA)); |
| 10544 } | 10542 } |
| 10545 | 10543 |
| 10546 void test_isNot_conditional() { | 10544 void test_isNot_conditional() { |
| 10547 Source source = addSource(r''' | 10545 Source source = addSource(r''' |
| 10548 class A {} | 10546 class A {} |
| 10549 A f(var p) { | 10547 A f(var p) { |
| 10550 return (p is! A) ? null : p; | 10548 return (p is! A) ? null : p; |
| 10551 }'''); | 10549 }'''); |
| 10552 LibraryElement library = resolve(source); | 10550 LibraryElement library = resolve(source); |
| 10553 assertNoErrors(source); | 10551 assertNoErrors(source); |
| 10554 verify([source]); | 10552 verify([source]); |
| 10555 CompilationUnit unit = resolveCompilationUnit(source, library); | 10553 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10556 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10554 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10557 InterfaceType typeA = classA.element.type; | 10555 InterfaceType typeA = classA.element.type; |
| 10558 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10556 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10559 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10557 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10560 ReturnStatement statement = body.block.statements[0] as ReturnStatement; | 10558 ReturnStatement statement = body.block.statements[0] as ReturnStatement; |
| 10561 ConditionalExpression conditional = statement.expression as ConditionalExpre
ssion; | 10559 ConditionalExpression conditional = statement.expression as ConditionalExpre
ssion; |
| 10562 SimpleIdentifier variableName = conditional.elseExpression as SimpleIdentifi
er; | 10560 SimpleIdentifier variableName = conditional.elseExpression as SimpleIdentifi
er; |
| 10563 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10561 expect(variableName.propagatedType, same(typeA)); |
| 10564 } | 10562 } |
| 10565 | 10563 |
| 10566 void test_isNot_if() { | 10564 void test_isNot_if() { |
| 10567 Source source = addSource(r''' | 10565 Source source = addSource(r''' |
| 10568 class A {} | 10566 class A {} |
| 10569 A f(var p) { | 10567 A f(var p) { |
| 10570 if (p is! A) { | 10568 if (p is! A) { |
| 10571 return null; | 10569 return null; |
| 10572 } else { | 10570 } else { |
| 10573 return p; | 10571 return p; |
| 10574 } | 10572 } |
| 10575 }'''); | 10573 }'''); |
| 10576 LibraryElement library = resolve(source); | 10574 LibraryElement library = resolve(source); |
| 10577 assertNoErrors(source); | 10575 assertNoErrors(source); |
| 10578 verify([source]); | 10576 verify([source]); |
| 10579 CompilationUnit unit = resolveCompilationUnit(source, library); | 10577 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10580 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10578 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10581 InterfaceType typeA = classA.element.type; | 10579 InterfaceType typeA = classA.element.type; |
| 10582 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10580 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10583 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10581 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10584 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 10582 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 10585 ReturnStatement statement = (ifStatement.elseStatement as Block).statements[
0] as ReturnStatement; | 10583 ReturnStatement statement = (ifStatement.elseStatement as Block).statements[
0] as ReturnStatement; |
| 10586 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10584 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10587 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10585 expect(variableName.propagatedType, same(typeA)); |
| 10588 } | 10586 } |
| 10589 | 10587 |
| 10590 void test_isNot_if_logicalOr() { | 10588 void test_isNot_if_logicalOr() { |
| 10591 Source source = addSource(r''' | 10589 Source source = addSource(r''' |
| 10592 class A {} | 10590 class A {} |
| 10593 A f(var p) { | 10591 A f(var p) { |
| 10594 if (p is! A || null == p) { | 10592 if (p is! A || null == p) { |
| 10595 return null; | 10593 return null; |
| 10596 } else { | 10594 } else { |
| 10597 return p; | 10595 return p; |
| 10598 } | 10596 } |
| 10599 }'''); | 10597 }'''); |
| 10600 LibraryElement library = resolve(source); | 10598 LibraryElement library = resolve(source); |
| 10601 assertNoErrors(source); | 10599 assertNoErrors(source); |
| 10602 CompilationUnit unit = resolveCompilationUnit(source, library); | 10600 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10603 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10601 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10604 InterfaceType typeA = classA.element.type; | 10602 InterfaceType typeA = classA.element.type; |
| 10605 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10603 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10606 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10604 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10607 IfStatement ifStatement = body.block.statements[0] as IfStatement; | 10605 IfStatement ifStatement = body.block.statements[0] as IfStatement; |
| 10608 ReturnStatement statement = (ifStatement.elseStatement as Block).statements[
0] as ReturnStatement; | 10606 ReturnStatement statement = (ifStatement.elseStatement as Block).statements[
0] as ReturnStatement; |
| 10609 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10607 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10610 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10608 expect(variableName.propagatedType, same(typeA)); |
| 10611 } | 10609 } |
| 10612 | 10610 |
| 10613 void test_isNot_postConditional() { | 10611 void test_isNot_postConditional() { |
| 10614 Source source = addSource(r''' | 10612 Source source = addSource(r''' |
| 10615 class A {} | 10613 class A {} |
| 10616 A f(var p) { | 10614 A f(var p) { |
| 10617 A a = (p is! A) ? throw null : p; | 10615 A a = (p is! A) ? throw null : p; |
| 10618 return p; | 10616 return p; |
| 10619 }'''); | 10617 }'''); |
| 10620 LibraryElement library = resolve(source); | 10618 LibraryElement library = resolve(source); |
| 10621 assertNoErrors(source); | 10619 assertNoErrors(source); |
| 10622 verify([source]); | 10620 verify([source]); |
| 10623 CompilationUnit unit = resolveCompilationUnit(source, library); | 10621 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10624 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10622 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10625 InterfaceType typeA = classA.element.type; | 10623 InterfaceType typeA = classA.element.type; |
| 10626 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10624 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10627 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10625 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10628 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10626 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10629 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10627 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10630 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10628 expect(variableName.propagatedType, same(typeA)); |
| 10631 } | 10629 } |
| 10632 | 10630 |
| 10633 void test_isNot_postIf() { | 10631 void test_isNot_postIf() { |
| 10634 Source source = addSource(r''' | 10632 Source source = addSource(r''' |
| 10635 class A {} | 10633 class A {} |
| 10636 A f(var p) { | 10634 A f(var p) { |
| 10637 if (p is! A) { | 10635 if (p is! A) { |
| 10638 return null; | 10636 return null; |
| 10639 } | 10637 } |
| 10640 return p; | 10638 return p; |
| 10641 }'''); | 10639 }'''); |
| 10642 LibraryElement library = resolve(source); | 10640 LibraryElement library = resolve(source); |
| 10643 assertNoErrors(source); | 10641 assertNoErrors(source); |
| 10644 verify([source]); | 10642 verify([source]); |
| 10645 CompilationUnit unit = resolveCompilationUnit(source, library); | 10643 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10646 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; | 10644 ClassDeclaration classA = unit.declarations[0] as ClassDeclaration; |
| 10647 InterfaceType typeA = classA.element.type; | 10645 InterfaceType typeA = classA.element.type; |
| 10648 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; | 10646 FunctionDeclaration function = unit.declarations[1] as FunctionDeclaration; |
| 10649 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10647 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10650 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10648 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10651 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; | 10649 SimpleIdentifier variableName = statement.expression as SimpleIdentifier; |
| 10652 JUnitTestCase.assertSame(typeA, variableName.propagatedType); | 10650 expect(variableName.propagatedType, same(typeA)); |
| 10653 } | 10651 } |
| 10654 | 10652 |
| 10655 void test_issue20904BuggyTypePromotionAtIfJoin_2() { | 10653 void test_issue20904BuggyTypePromotionAtIfJoin_2() { |
| 10656 // https://code.google.com/p/dart/issues/detail?id=20904 | 10654 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 10657 enableUnionTypes(false); | 10655 enableUnionTypes(false); |
| 10658 String code = r''' | 10656 String code = r''' |
| 10659 f(var message) { | 10657 f(var message) { |
| 10660 if (message is Function) { | 10658 if (message is Function) { |
| 10661 message = ''; | 10659 message = ''; |
| 10662 } | 10660 } |
| 10663 message; // marker | 10661 message; // marker |
| 10664 }'''; | 10662 }'''; |
| 10665 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; | 10663 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; |
| 10666 JUnitTestCase.assertFalse(typeProvider.stringType == t); | 10664 expect(typeProvider.stringType == t, isFalse); |
| 10667 JUnitTestCase.assertFalse(typeProvider.functionType == t); | 10665 expect(typeProvider.functionType == t, isFalse); |
| 10668 } | 10666 } |
| 10669 | 10667 |
| 10670 void test_issue20904BuggyTypePromotionAtIfJoin_5() { | 10668 void test_issue20904BuggyTypePromotionAtIfJoin_5() { |
| 10671 // https://code.google.com/p/dart/issues/detail?id=20904 | 10669 // https://code.google.com/p/dart/issues/detail?id=20904 |
| 10672 // | 10670 // |
| 10673 // This is not an example of the 20904 bug, but rather, | 10671 // This is not an example of the 20904 bug, but rather, |
| 10674 // an example of something that one obvious fix changes inadvertently: we | 10672 // an example of something that one obvious fix changes inadvertently: we |
| 10675 // want to avoid using type information from is-checks when it | 10673 // want to avoid using type information from is-checks when it |
| 10676 // loses precision. I can't see how to get a bad hint this way, since | 10674 // loses precision. I can't see how to get a bad hint this way, since |
| 10677 // it seems the propagated type is not used to generate hints when a | 10675 // it seems the propagated type is not used to generate hints when a |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10727 return v[2]; | 10725 return v[2]; |
| 10728 }'''); | 10726 }'''); |
| 10729 LibraryElement library = resolve(source); | 10727 LibraryElement library = resolve(source); |
| 10730 assertNoErrors(source); | 10728 assertNoErrors(source); |
| 10731 verify([source]); | 10729 verify([source]); |
| 10732 CompilationUnit unit = resolveCompilationUnit(source, library); | 10730 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10733 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 10731 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 10734 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10732 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10735 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10733 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10736 IndexExpression indexExpression = statement.expression as IndexExpression; | 10734 IndexExpression indexExpression = statement.expression as IndexExpression; |
| 10737 JUnitTestCase.assertNull(indexExpression.propagatedType); | 10735 expect(indexExpression.propagatedType, isNull); |
| 10738 } | 10736 } |
| 10739 | 10737 |
| 10740 void test_listLiteral_same() { | 10738 void test_listLiteral_same() { |
| 10741 Source source = addSource(r''' | 10739 Source source = addSource(r''' |
| 10742 f() { | 10740 f() { |
| 10743 var v = [0, 1, 2]; | 10741 var v = [0, 1, 2]; |
| 10744 return v[2]; | 10742 return v[2]; |
| 10745 }'''); | 10743 }'''); |
| 10746 LibraryElement library = resolve(source); | 10744 LibraryElement library = resolve(source); |
| 10747 assertNoErrors(source); | 10745 assertNoErrors(source); |
| 10748 verify([source]); | 10746 verify([source]); |
| 10749 CompilationUnit unit = resolveCompilationUnit(source, library); | 10747 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10750 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 10748 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 10751 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10749 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10752 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10750 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10753 IndexExpression indexExpression = statement.expression as IndexExpression; | 10751 IndexExpression indexExpression = statement.expression as IndexExpression; |
| 10754 JUnitTestCase.assertNull(indexExpression.propagatedType); | 10752 expect(indexExpression.propagatedType, isNull); |
| 10755 Expression v = indexExpression.target; | 10753 Expression v = indexExpression.target; |
| 10756 InterfaceType propagatedType = v.propagatedType as InterfaceType; | 10754 InterfaceType propagatedType = v.propagatedType as InterfaceType; |
| 10757 JUnitTestCase.assertSame(typeProvider.listType.element, propagatedType.eleme
nt); | 10755 expect(propagatedType.element, same(typeProvider.listType.element)); |
| 10758 List<DartType> typeArguments = propagatedType.typeArguments; | 10756 List<DartType> typeArguments = propagatedType.typeArguments; |
| 10759 EngineTestCase.assertLength(1, typeArguments); | 10757 EngineTestCase.assertLength(1, typeArguments); |
| 10760 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[0]); | 10758 expect(typeArguments[0], same(typeProvider.dynamicType)); |
| 10761 } | 10759 } |
| 10762 | 10760 |
| 10763 void test_mapLiteral_different() { | 10761 void test_mapLiteral_different() { |
| 10764 Source source = addSource(r''' | 10762 Source source = addSource(r''' |
| 10765 f() { | 10763 f() { |
| 10766 var v = {'0' : 0, 1 : '1', '2' : 2}; | 10764 var v = {'0' : 0, 1 : '1', '2' : 2}; |
| 10767 return v; | 10765 return v; |
| 10768 }'''); | 10766 }'''); |
| 10769 LibraryElement library = resolve(source); | 10767 LibraryElement library = resolve(source); |
| 10770 assertNoErrors(source); | 10768 assertNoErrors(source); |
| 10771 verify([source]); | 10769 verify([source]); |
| 10772 CompilationUnit unit = resolveCompilationUnit(source, library); | 10770 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10773 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 10771 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 10774 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10772 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10775 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10773 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10776 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; | 10774 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; |
| 10777 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; | 10775 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; |
| 10778 JUnitTestCase.assertSame(typeProvider.mapType.element, propagatedType.elemen
t); | 10776 expect(propagatedType.element, same(typeProvider.mapType.element)); |
| 10779 List<DartType> typeArguments = propagatedType.typeArguments; | 10777 List<DartType> typeArguments = propagatedType.typeArguments; |
| 10780 EngineTestCase.assertLength(2, typeArguments); | 10778 EngineTestCase.assertLength(2, typeArguments); |
| 10781 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[0]); | 10779 expect(typeArguments[0], same(typeProvider.dynamicType)); |
| 10782 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[1]); | 10780 expect(typeArguments[1], same(typeProvider.dynamicType)); |
| 10783 } | 10781 } |
| 10784 | 10782 |
| 10785 void test_mapLiteral_same() { | 10783 void test_mapLiteral_same() { |
| 10786 Source source = addSource(r''' | 10784 Source source = addSource(r''' |
| 10787 f() { | 10785 f() { |
| 10788 var v = {'a' : 0, 'b' : 1, 'c' : 2}; | 10786 var v = {'a' : 0, 'b' : 1, 'c' : 2}; |
| 10789 return v; | 10787 return v; |
| 10790 }'''); | 10788 }'''); |
| 10791 LibraryElement library = resolve(source); | 10789 LibraryElement library = resolve(source); |
| 10792 assertNoErrors(source); | 10790 assertNoErrors(source); |
| 10793 verify([source]); | 10791 verify([source]); |
| 10794 CompilationUnit unit = resolveCompilationUnit(source, library); | 10792 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10795 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; | 10793 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; |
| 10796 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; | 10794 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo
dy; |
| 10797 ReturnStatement statement = body.block.statements[1] as ReturnStatement; | 10795 ReturnStatement statement = body.block.statements[1] as ReturnStatement; |
| 10798 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; | 10796 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; |
| 10799 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; | 10797 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; |
| 10800 JUnitTestCase.assertSame(typeProvider.mapType.element, propagatedType.elemen
t); | 10798 expect(propagatedType.element, same(typeProvider.mapType.element)); |
| 10801 List<DartType> typeArguments = propagatedType.typeArguments; | 10799 List<DartType> typeArguments = propagatedType.typeArguments; |
| 10802 EngineTestCase.assertLength(2, typeArguments); | 10800 EngineTestCase.assertLength(2, typeArguments); |
| 10803 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[0]); | 10801 expect(typeArguments[0], same(typeProvider.dynamicType)); |
| 10804 JUnitTestCase.assertSame(typeProvider.dynamicType, typeArguments[1]); | 10802 expect(typeArguments[1], same(typeProvider.dynamicType)); |
| 10805 } | 10803 } |
| 10806 | 10804 |
| 10807 void test_mergePropagatedTypesAtJoinPoint_4() { | 10805 void test_mergePropagatedTypesAtJoinPoint_4() { |
| 10808 // https://code.google.com/p/dart/issues/detail?id=19929 | 10806 // https://code.google.com/p/dart/issues/detail?id=19929 |
| 10809 _assertTypeOfMarkedExpression(r''' | 10807 _assertTypeOfMarkedExpression(r''' |
| 10810 f5(x) { | 10808 f5(x) { |
| 10811 var y = []; | 10809 var y = []; |
| 10812 if (x) { | 10810 if (x) { |
| 10813 y = 0; | 10811 y = 0; |
| 10814 } else { | 10812 } else { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 10835 L: | 10833 L: |
| 10836 if (c) { | 10834 if (c) { |
| 10837 } else { | 10835 } else { |
| 10838 x = ''; | 10836 x = ''; |
| 10839 c = true; | 10837 c = true; |
| 10840 break L; | 10838 break L; |
| 10841 } | 10839 } |
| 10842 x; // marker | 10840 x; // marker |
| 10843 }'''; | 10841 }'''; |
| 10844 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; | 10842 DartType t = _findMarkedIdentifier(code, "; // marker").propagatedType; |
| 10845 JUnitTestCase.assertTrue(typeProvider.intType.isSubtypeOf(t)); | 10843 expect(typeProvider.intType.isSubtypeOf(t), isTrue); |
| 10846 JUnitTestCase.assertTrue(typeProvider.stringType.isSubtypeOf(t)); | 10844 expect(typeProvider.stringType.isSubtypeOf(t), isTrue); |
| 10847 } | 10845 } |
| 10848 | 10846 |
| 10849 void test_objectMethodOnDynamicExpression_doubleEquals() { | 10847 void test_objectMethodOnDynamicExpression_doubleEquals() { |
| 10850 // https://code.google.com/p/dart/issues/detail?id=20342 | 10848 // https://code.google.com/p/dart/issues/detail?id=20342 |
| 10851 // | 10849 // |
| 10852 // This was not actually part of Issue 20342, since the spec specifies a | 10850 // This was not actually part of Issue 20342, since the spec specifies a |
| 10853 // static type of [bool] for [==] comparison and the implementation | 10851 // static type of [bool] for [==] comparison and the implementation |
| 10854 // was already consistent with the spec there. But, it's another | 10852 // was already consistent with the spec there. But, it's another |
| 10855 // [Object] method, so it's included here. | 10853 // [Object] method, so it's included here. |
| 10856 _assertTypeOfMarkedExpression(r''' | 10854 _assertTypeOfMarkedExpression(r''' |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10977 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3]; | 10975 return [v1, v2, v3, v4, v5, v6, v7, m1, b1, b2, b3]; |
| 10978 }'''); | 10976 }'''); |
| 10979 LibraryElement library = resolve(source); | 10977 LibraryElement library = resolve(source); |
| 10980 assertNoErrors(source); | 10978 assertNoErrors(source); |
| 10981 verify([source]); | 10979 verify([source]); |
| 10982 CompilationUnit unit = resolveCompilationUnit(source, library); | 10980 CompilationUnit unit = resolveCompilationUnit(source, library); |
| 10983 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration; | 10981 FunctionDeclaration main = unit.declarations[0] as FunctionDeclaration; |
| 10984 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; | 10982 BlockFunctionBody body = main.functionExpression.body as BlockFunctionBody; |
| 10985 ReturnStatement statement = body.block.statements[11] as ReturnStatement; | 10983 ReturnStatement statement = body.block.statements[11] as ReturnStatement; |
| 10986 NodeList<Expression> elements = (statement.expression as ListLiteral).elemen
ts; | 10984 NodeList<Expression> elements = (statement.expression as ListLiteral).elemen
ts; |
| 10987 JUnitTestCase.assertEquals("AnchorElement", elements[0].propagatedType.name)
; | 10985 expect(elements[0].propagatedType.name, "AnchorElement"); |
| 10988 JUnitTestCase.assertEquals("AnchorElement", elements[1].propagatedType.name)
; | 10986 expect(elements[1].propagatedType.name, "AnchorElement"); |
| 10989 JUnitTestCase.assertEquals("BodyElement", elements[2].propagatedType.name); | 10987 expect(elements[2].propagatedType.name, "BodyElement"); |
| 10990 JUnitTestCase.assertEquals("ButtonElement", elements[3].propagatedType.name)
; | 10988 expect(elements[3].propagatedType.name, "ButtonElement"); |
| 10991 JUnitTestCase.assertEquals("DivElement", elements[4].propagatedType.name); | 10989 expect(elements[4].propagatedType.name, "DivElement"); |
| 10992 JUnitTestCase.assertEquals("InputElement", elements[5].propagatedType.name); | 10990 expect(elements[5].propagatedType.name, "InputElement"); |
| 10993 JUnitTestCase.assertEquals("SelectElement", elements[6].propagatedType.name)
; | 10991 expect(elements[6].propagatedType.name, "SelectElement"); |
| 10994 JUnitTestCase.assertEquals("DivElement", elements[7].propagatedType.name); | 10992 expect(elements[7].propagatedType.name, "DivElement"); |
| 10995 JUnitTestCase.assertEquals("Element", elements[8].propagatedType.name); | 10993 expect(elements[8].propagatedType.name, "Element"); |
| 10996 JUnitTestCase.assertEquals("Element", elements[9].propagatedType.name); | 10994 expect(elements[9].propagatedType.name, "Element"); |
| 10997 JUnitTestCase.assertEquals("Element", elements[10].propagatedType.name); | 10995 expect(elements[10].propagatedType.name, "Element"); |
| 10998 } | 10996 } |
| 10999 | 10997 |
| 11000 /** | 10998 /** |
| 11001 * @param code the code that assigns the value to the variable "v", no matter
how. We check that | 10999 * @param code the code that assigns the value to the variable "v", no matter
how. We check that |
| 11002 * "v" has expected static and propagated type. | 11000 * "v" has expected static and propagated type. |
| 11003 */ | 11001 */ |
| 11004 void _assertPropagatedReturnType(String code, DartType expectedStaticType, Dar
tType expectedPropagatedType) { | 11002 void _assertPropagatedReturnType(String code, DartType expectedStaticType, Dar
tType expectedPropagatedType) { |
| 11005 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v = "); | 11003 SimpleIdentifier identifier = _findMarkedIdentifier(code, "v = "); |
| 11006 JUnitTestCase.assertSame(expectedStaticType, identifier.staticType); | 11004 expect(identifier.staticType, same(expectedStaticType)); |
| 11007 JUnitTestCase.assertSame(expectedPropagatedType, identifier.propagatedType); | 11005 expect(identifier.propagatedType, same(expectedPropagatedType)); |
| 11008 } | 11006 } |
| 11009 | 11007 |
| 11010 /** | 11008 /** |
| 11011 * Check the static and propagated types of the expression marked with "; // m
arker" comment. | 11009 * Check the static and propagated types of the expression marked with "; // m
arker" comment. |
| 11012 * | 11010 * |
| 11013 * @param code source code to analyze, with the expression to check marked wit
h "// marker". | 11011 * @param code source code to analyze, with the expression to check marked wit
h "// marker". |
| 11014 * @param expectedStaticType if non-null, check actual static type is equal to
this. | 11012 * @param expectedStaticType if non-null, check actual static type is equal to
this. |
| 11015 * @param expectedPropagatedType if non-null, check actual static type is equa
l to this. | 11013 * @param expectedPropagatedType if non-null, check actual static type is equa
l to this. |
| 11016 * @throws Exception | 11014 * @throws Exception |
| 11017 */ | 11015 */ |
| 11018 void _assertTypeOfMarkedExpression(String code, DartType expectedStaticType, D
artType expectedPropagatedType) { | 11016 void _assertTypeOfMarkedExpression(String code, DartType expectedStaticType, D
artType expectedPropagatedType) { |
| 11019 SimpleIdentifier identifier = _findMarkedIdentifier(code, "; // marker"); | 11017 SimpleIdentifier identifier = _findMarkedIdentifier(code, "; // marker"); |
| 11020 if (expectedStaticType != null) { | 11018 if (expectedStaticType != null) { |
| 11021 JUnitTestCase.assertEquals(expectedStaticType, identifier.staticType); | 11019 expect(identifier.staticType, expectedStaticType); |
| 11022 } | 11020 } |
| 11023 if (expectedPropagatedType != null) { | 11021 if (expectedPropagatedType != null) { |
| 11024 JUnitTestCase.assertEquals(expectedPropagatedType, identifier.propagatedTy
pe); | 11022 expect(identifier.propagatedType, expectedPropagatedType); |
| 11025 } | 11023 } |
| 11026 } | 11024 } |
| 11027 | 11025 |
| 11028 /** | 11026 /** |
| 11029 * Return the `SimpleIdentifier` marked by `marker`. The source code must have
no | 11027 * Return the `SimpleIdentifier` marked by `marker`. The source code must have
no |
| 11030 * errors and be verifiable. | 11028 * errors and be verifiable. |
| 11031 * | 11029 * |
| 11032 * @param code source code to analyze. | 11030 * @param code source code to analyze. |
| 11033 * @param marker marker identifying sought after expression in source code. | 11031 * @param marker marker identifying sought after expression in source code. |
| 11034 * @return expression marked by the marker. | 11032 * @return expression marked by the marker. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11084 stackTraceType.element, | 11082 stackTraceType.element, |
| 11085 stringType.element, | 11083 stringType.element, |
| 11086 symbolType.element, | 11084 symbolType.element, |
| 11087 typeType.element]; | 11085 typeType.element]; |
| 11088 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode(new Analysis
ContextImpl(), AstFactory.libraryIdentifier2(["dart.core"])); | 11086 LibraryElementImpl coreLibrary = new LibraryElementImpl.forNode(new Analysis
ContextImpl(), AstFactory.libraryIdentifier2(["dart.core"])); |
| 11089 coreLibrary.definingCompilationUnit = coreUnit; | 11087 coreLibrary.definingCompilationUnit = coreUnit; |
| 11090 // | 11088 // |
| 11091 // Create a type provider and ensure that it can return the expected types. | 11089 // Create a type provider and ensure that it can return the expected types. |
| 11092 // | 11090 // |
| 11093 TypeProviderImpl provider = new TypeProviderImpl(coreLibrary); | 11091 TypeProviderImpl provider = new TypeProviderImpl(coreLibrary); |
| 11094 JUnitTestCase.assertSame(boolType, provider.boolType); | 11092 expect(provider.boolType, same(boolType)); |
| 11095 JUnitTestCase.assertNotNull(provider.bottomType); | 11093 expect(provider.bottomType, isNotNull); |
| 11096 JUnitTestCase.assertSame(doubleType, provider.doubleType); | 11094 expect(provider.doubleType, same(doubleType)); |
| 11097 JUnitTestCase.assertNotNull(provider.dynamicType); | 11095 expect(provider.dynamicType, isNotNull); |
| 11098 JUnitTestCase.assertSame(functionType, provider.functionType); | 11096 expect(provider.functionType, same(functionType)); |
| 11099 JUnitTestCase.assertSame(intType, provider.intType); | 11097 expect(provider.intType, same(intType)); |
| 11100 JUnitTestCase.assertSame(listType, provider.listType); | 11098 expect(provider.listType, same(listType)); |
| 11101 JUnitTestCase.assertSame(mapType, provider.mapType); | 11099 expect(provider.mapType, same(mapType)); |
| 11102 JUnitTestCase.assertSame(objectType, provider.objectType); | 11100 expect(provider.objectType, same(objectType)); |
| 11103 JUnitTestCase.assertSame(stackTraceType, provider.stackTraceType); | 11101 expect(provider.stackTraceType, same(stackTraceType)); |
| 11104 JUnitTestCase.assertSame(stringType, provider.stringType); | 11102 expect(provider.stringType, same(stringType)); |
| 11105 JUnitTestCase.assertSame(symbolType, provider.symbolType); | 11103 expect(provider.symbolType, same(symbolType)); |
| 11106 JUnitTestCase.assertSame(typeType, provider.typeType); | 11104 expect(provider.typeType, same(typeType)); |
| 11107 } | 11105 } |
| 11108 | 11106 |
| 11109 ClassElement _classElement(String typeName, InterfaceType superclassType, List
<String> parameterNames) { | 11107 ClassElement _classElement(String typeName, InterfaceType superclassType, List
<String> parameterNames) { |
| 11110 ClassElementImpl element = new ClassElementImpl.forNode(AstFactory.identifie
r3(typeName)); | 11108 ClassElementImpl element = new ClassElementImpl.forNode(AstFactory.identifie
r3(typeName)); |
| 11111 element.supertype = superclassType; | 11109 element.supertype = superclassType; |
| 11112 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(element); | 11110 InterfaceTypeImpl type = new InterfaceTypeImpl.con1(element); |
| 11113 element.type = type; | 11111 element.type = type; |
| 11114 int count = parameterNames.length; | 11112 int count = parameterNames.length; |
| 11115 if (count > 0) { | 11113 if (count > 0) { |
| 11116 List<TypeParameterElementImpl> typeParameters = new List<TypeParameterElem
entImpl>(count); | 11114 List<TypeParameterElementImpl> typeParameters = new List<TypeParameterElem
entImpl>(count); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11149 * The visitor used to resolve types needed to form the type hierarchy. | 11147 * The visitor used to resolve types needed to form the type hierarchy. |
| 11150 */ | 11148 */ |
| 11151 TypeResolverVisitor _visitor; | 11149 TypeResolverVisitor _visitor; |
| 11152 | 11150 |
| 11153 /** | 11151 /** |
| 11154 * The visitor used to resolve types needed to form the type hierarchy. | 11152 * The visitor used to resolve types needed to form the type hierarchy. |
| 11155 */ | 11153 */ |
| 11156 ImplicitConstructorBuilder _implicitConstructorBuilder; | 11154 ImplicitConstructorBuilder _implicitConstructorBuilder; |
| 11157 | 11155 |
| 11158 void fail_visitConstructorDeclaration() { | 11156 void fail_visitConstructorDeclaration() { |
| 11159 JUnitTestCase.fail("Not yet tested"); | 11157 fail("Not yet tested"); |
| 11160 _listener.assertNoErrors(); | 11158 _listener.assertNoErrors(); |
| 11161 } | 11159 } |
| 11162 | 11160 |
| 11163 void fail_visitFunctionDeclaration() { | 11161 void fail_visitFunctionDeclaration() { |
| 11164 JUnitTestCase.fail("Not yet tested"); | 11162 fail("Not yet tested"); |
| 11165 _listener.assertNoErrors(); | 11163 _listener.assertNoErrors(); |
| 11166 } | 11164 } |
| 11167 | 11165 |
| 11168 void fail_visitFunctionTypeAlias() { | 11166 void fail_visitFunctionTypeAlias() { |
| 11169 JUnitTestCase.fail("Not yet tested"); | 11167 fail("Not yet tested"); |
| 11170 _listener.assertNoErrors(); | 11168 _listener.assertNoErrors(); |
| 11171 } | 11169 } |
| 11172 | 11170 |
| 11173 void fail_visitFunctionTypedFormalParameter() { | 11171 void fail_visitFunctionTypedFormalParameter() { |
| 11174 JUnitTestCase.fail("Not yet tested"); | 11172 fail("Not yet tested"); |
| 11175 _listener.assertNoErrors(); | 11173 _listener.assertNoErrors(); |
| 11176 } | 11174 } |
| 11177 | 11175 |
| 11178 void fail_visitMethodDeclaration() { | 11176 void fail_visitMethodDeclaration() { |
| 11179 JUnitTestCase.fail("Not yet tested"); | 11177 fail("Not yet tested"); |
| 11180 _listener.assertNoErrors(); | 11178 _listener.assertNoErrors(); |
| 11181 } | 11179 } |
| 11182 | 11180 |
| 11183 void fail_visitVariableDeclaration() { | 11181 void fail_visitVariableDeclaration() { |
| 11184 JUnitTestCase.fail("Not yet tested"); | 11182 fail("Not yet tested"); |
| 11185 ClassElement type = ElementFactory.classElement2("A", []); | 11183 ClassElement type = ElementFactory.classElement2("A", []); |
| 11186 VariableDeclaration node = AstFactory.variableDeclaration("a"); | 11184 VariableDeclaration node = AstFactory.variableDeclaration("a"); |
| 11187 AstFactory.variableDeclarationList(null, AstFactory.typeName(type, []), [nod
e]); | 11185 AstFactory.variableDeclarationList(null, AstFactory.typeName(type, []), [nod
e]); |
| 11188 //resolve(node); | 11186 //resolve(node); |
| 11189 JUnitTestCase.assertSame(type.type, node.name.staticType); | 11187 expect(node.name.staticType, same(type.type)); |
| 11190 _listener.assertNoErrors(); | 11188 _listener.assertNoErrors(); |
| 11191 } | 11189 } |
| 11192 | 11190 |
| 11193 @override | 11191 @override |
| 11194 void setUp() { | 11192 void setUp() { |
| 11195 _listener = new GatheringErrorListener(); | 11193 _listener = new GatheringErrorListener(); |
| 11196 SourceFactory factory = new SourceFactory([new FileUriResolver()]); | 11194 SourceFactory factory = new SourceFactory([new FileUriResolver()]); |
| 11197 AnalysisContextImpl context = new AnalysisContextImpl(); | 11195 AnalysisContextImpl context = new AnalysisContextImpl(); |
| 11198 context.sourceFactory = factory; | 11196 context.sourceFactory = factory; |
| 11199 Source librarySource = new FileBasedSource.con1(FileUtilities2.createFile("/
lib.dart")); | 11197 Source librarySource = new FileBasedSource.con1(FileUtilities2.createFile("/
lib.dart")); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11259 ClassElement elementA = ElementFactory.classElement2("A", []); | 11257 ClassElement elementA = ElementFactory.classElement2("A", []); |
| 11260 ClassElement elementB = ElementFactory.classElement2("B", []); | 11258 ClassElement elementB = ElementFactory.classElement2("B", []); |
| 11261 ClassElement elementC = ElementFactory.classElement2("C", []); | 11259 ClassElement elementC = ElementFactory.classElement2("C", []); |
| 11262 ClassElement elementD = ElementFactory.classElement2("D", []); | 11260 ClassElement elementD = ElementFactory.classElement2("D", []); |
| 11263 ExtendsClause extendsClause = AstFactory.extendsClause(AstFactory.typeName(e
lementB, [])); | 11261 ExtendsClause extendsClause = AstFactory.extendsClause(AstFactory.typeName(e
lementB, [])); |
| 11264 WithClause withClause = AstFactory.withClause([AstFactory.typeName(elementC,
[])]); | 11262 WithClause withClause = AstFactory.withClause([AstFactory.typeName(elementC,
[])]); |
| 11265 ImplementsClause implementsClause = AstFactory.implementsClause([AstFactory.
typeName(elementD, [])]); | 11263 ImplementsClause implementsClause = AstFactory.implementsClause([AstFactory.
typeName(elementD, [])]); |
| 11266 ClassDeclaration declaration = AstFactory.classDeclaration(null, "A", null,
extendsClause, withClause, implementsClause, []); | 11264 ClassDeclaration declaration = AstFactory.classDeclaration(null, "A", null,
extendsClause, withClause, implementsClause, []); |
| 11267 declaration.name.staticElement = elementA; | 11265 declaration.name.staticElement = elementA; |
| 11268 _resolveNode(declaration, [elementA, elementB, elementC, elementD]); | 11266 _resolveNode(declaration, [elementA, elementB, elementC, elementD]); |
| 11269 JUnitTestCase.assertSame(elementB.type, elementA.supertype); | 11267 expect(elementA.supertype, same(elementB.type)); |
| 11270 List<InterfaceType> mixins = elementA.mixins; | 11268 List<InterfaceType> mixins = elementA.mixins; |
| 11271 EngineTestCase.assertLength(1, mixins); | 11269 EngineTestCase.assertLength(1, mixins); |
| 11272 JUnitTestCase.assertSame(elementC.type, mixins[0]); | 11270 expect(mixins[0], same(elementC.type)); |
| 11273 List<InterfaceType> interfaces = elementA.interfaces; | 11271 List<InterfaceType> interfaces = elementA.interfaces; |
| 11274 EngineTestCase.assertLength(1, interfaces); | 11272 EngineTestCase.assertLength(1, interfaces); |
| 11275 JUnitTestCase.assertSame(elementD.type, interfaces[0]); | 11273 expect(interfaces[0], same(elementD.type)); |
| 11276 _listener.assertNoErrors(); | 11274 _listener.assertNoErrors(); |
| 11277 } | 11275 } |
| 11278 | 11276 |
| 11279 void test_visitClassDeclaration_instanceMemberCollidesWithClass() { | 11277 void test_visitClassDeclaration_instanceMemberCollidesWithClass() { |
| 11280 // class A {} | 11278 // class A {} |
| 11281 // class B extends A { | 11279 // class B extends A { |
| 11282 // void A() {} | 11280 // void A() {} |
| 11283 // } | 11281 // } |
| 11284 ClassElementImpl elementA = ElementFactory.classElement2("A", []); | 11282 ClassElementImpl elementA = ElementFactory.classElement2("A", []); |
| 11285 ClassElementImpl elementB = ElementFactory.classElement2("B", []); | 11283 ClassElementImpl elementB = ElementFactory.classElement2("B", []); |
| 11286 elementB.methods = <MethodElement> [ElementFactory.methodElement("A", VoidTy
peImpl.instance, [])]; | 11284 elementB.methods = <MethodElement> [ElementFactory.methodElement("A", VoidTy
peImpl.instance, [])]; |
| 11287 ExtendsClause extendsClause = AstFactory.extendsClause(AstFactory.typeName(e
lementA, [])); | 11285 ExtendsClause extendsClause = AstFactory.extendsClause(AstFactory.typeName(e
lementA, [])); |
| 11288 ClassDeclaration declaration = AstFactory.classDeclaration(null, "B", null,
extendsClause, null, null, []); | 11286 ClassDeclaration declaration = AstFactory.classDeclaration(null, "B", null,
extendsClause, null, null, []); |
| 11289 declaration.name.staticElement = elementB; | 11287 declaration.name.staticElement = elementB; |
| 11290 _resolveNode(declaration, [elementA, elementB]); | 11288 _resolveNode(declaration, [elementA, elementB]); |
| 11291 JUnitTestCase.assertSame(elementA.type, elementB.supertype); | 11289 expect(elementB.supertype, same(elementA.type)); |
| 11292 _listener.assertNoErrors(); | 11290 _listener.assertNoErrors(); |
| 11293 } | 11291 } |
| 11294 | 11292 |
| 11295 void test_visitClassTypeAlias() { | 11293 void test_visitClassTypeAlias() { |
| 11296 // class A = B with C implements D; | 11294 // class A = B with C implements D; |
| 11297 ClassElement elementA = ElementFactory.classElement2("A", []); | 11295 ClassElement elementA = ElementFactory.classElement2("A", []); |
| 11298 ClassElement elementB = ElementFactory.classElement2("B", []); | 11296 ClassElement elementB = ElementFactory.classElement2("B", []); |
| 11299 ClassElement elementC = ElementFactory.classElement2("C", []); | 11297 ClassElement elementC = ElementFactory.classElement2("C", []); |
| 11300 ClassElement elementD = ElementFactory.classElement2("D", []); | 11298 ClassElement elementD = ElementFactory.classElement2("D", []); |
| 11301 WithClause withClause = AstFactory.withClause([AstFactory.typeName(elementC,
[])]); | 11299 WithClause withClause = AstFactory.withClause([AstFactory.typeName(elementC,
[])]); |
| 11302 ImplementsClause implementsClause = AstFactory.implementsClause([AstFactory.
typeName(elementD, [])]); | 11300 ImplementsClause implementsClause = AstFactory.implementsClause([AstFactory.
typeName(elementD, [])]); |
| 11303 ClassTypeAlias alias = AstFactory.classTypeAlias("A", null, null, AstFactory
.typeName(elementB, []), withClause, implementsClause); | 11301 ClassTypeAlias alias = AstFactory.classTypeAlias("A", null, null, AstFactory
.typeName(elementB, []), withClause, implementsClause); |
| 11304 alias.name.staticElement = elementA; | 11302 alias.name.staticElement = elementA; |
| 11305 _resolveNode(alias, [elementA, elementB, elementC, elementD]); | 11303 _resolveNode(alias, [elementA, elementB, elementC, elementD]); |
| 11306 JUnitTestCase.assertSame(elementB.type, elementA.supertype); | 11304 expect(elementA.supertype, same(elementB.type)); |
| 11307 List<InterfaceType> mixins = elementA.mixins; | 11305 List<InterfaceType> mixins = elementA.mixins; |
| 11308 EngineTestCase.assertLength(1, mixins); | 11306 EngineTestCase.assertLength(1, mixins); |
| 11309 JUnitTestCase.assertSame(elementC.type, mixins[0]); | 11307 expect(mixins[0], same(elementC.type)); |
| 11310 List<InterfaceType> interfaces = elementA.interfaces; | 11308 List<InterfaceType> interfaces = elementA.interfaces; |
| 11311 EngineTestCase.assertLength(1, interfaces); | 11309 EngineTestCase.assertLength(1, interfaces); |
| 11312 JUnitTestCase.assertSame(elementD.type, interfaces[0]); | 11310 expect(interfaces[0], same(elementD.type)); |
| 11313 _listener.assertNoErrors(); | 11311 _listener.assertNoErrors(); |
| 11314 } | 11312 } |
| 11315 | 11313 |
| 11316 void test_visitFieldFormalParameter_functionType() { | 11314 void test_visitFieldFormalParameter_functionType() { |
| 11317 InterfaceType intType = _typeProvider.intType; | 11315 InterfaceType intType = _typeProvider.intType; |
| 11318 TypeName intTypeName = AstFactory.typeName4("int", []); | 11316 TypeName intTypeName = AstFactory.typeName4("int", []); |
| 11319 String innerParameterName = "a"; | 11317 String innerParameterName = "a"; |
| 11320 SimpleFormalParameter parameter = AstFactory.simpleFormalParameter3(innerPar
ameterName); | 11318 SimpleFormalParameter parameter = AstFactory.simpleFormalParameter3(innerPar
ameterName); |
| 11321 parameter.identifier.staticElement = ElementFactory.requiredParameter(innerP
arameterName); | 11319 parameter.identifier.staticElement = ElementFactory.requiredParameter(innerP
arameterName); |
| 11322 String outerParameterName = "p"; | 11320 String outerParameterName = "p"; |
| 11323 FormalParameter node = AstFactory.fieldFormalParameter(null, intTypeName, ou
terParameterName, AstFactory.formalParameterList([parameter])); | 11321 FormalParameter node = AstFactory.fieldFormalParameter(null, intTypeName, ou
terParameterName, AstFactory.formalParameterList([parameter])); |
| 11324 node.identifier.staticElement = ElementFactory.requiredParameter(outerParame
terName); | 11322 node.identifier.staticElement = ElementFactory.requiredParameter(outerParame
terName); |
| 11325 DartType parameterType = _resolveFormalParameter(node, [intType.element]); | 11323 DartType parameterType = _resolveFormalParameter(node, [intType.element]); |
| 11326 EngineTestCase.assertInstanceOf((obj) => obj is FunctionType, FunctionType,
parameterType); | 11324 EngineTestCase.assertInstanceOf((obj) => obj is FunctionType, FunctionType,
parameterType); |
| 11327 FunctionType functionType = parameterType as FunctionType; | 11325 FunctionType functionType = parameterType as FunctionType; |
| 11328 JUnitTestCase.assertSame(intType, functionType.returnType); | 11326 expect(functionType.returnType, same(intType)); |
| 11329 EngineTestCase.assertLength(1, functionType.parameters); | 11327 EngineTestCase.assertLength(1, functionType.parameters); |
| 11330 _listener.assertNoErrors(); | 11328 _listener.assertNoErrors(); |
| 11331 } | 11329 } |
| 11332 | 11330 |
| 11333 void test_visitFieldFormalParameter_noType() { | 11331 void test_visitFieldFormalParameter_noType() { |
| 11334 String parameterName = "p"; | 11332 String parameterName = "p"; |
| 11335 FormalParameter node = AstFactory.fieldFormalParameter(Keyword.VAR, null, pa
rameterName); | 11333 FormalParameter node = AstFactory.fieldFormalParameter(Keyword.VAR, null, pa
rameterName); |
| 11336 node.identifier.staticElement = ElementFactory.requiredParameter(parameterNa
me); | 11334 node.identifier.staticElement = ElementFactory.requiredParameter(parameterNa
me); |
| 11337 JUnitTestCase.assertSame(_typeProvider.dynamicType, _resolveFormalParameter(
node, [])); | 11335 expect(_resolveFormalParameter(node, []), same(_typeProvider.dynamicType)); |
| 11338 _listener.assertNoErrors(); | 11336 _listener.assertNoErrors(); |
| 11339 } | 11337 } |
| 11340 | 11338 |
| 11341 void test_visitFieldFormalParameter_type() { | 11339 void test_visitFieldFormalParameter_type() { |
| 11342 InterfaceType intType = _typeProvider.intType; | 11340 InterfaceType intType = _typeProvider.intType; |
| 11343 TypeName intTypeName = AstFactory.typeName4("int", []); | 11341 TypeName intTypeName = AstFactory.typeName4("int", []); |
| 11344 String parameterName = "p"; | 11342 String parameterName = "p"; |
| 11345 FormalParameter node = AstFactory.fieldFormalParameter(null, intTypeName, pa
rameterName); | 11343 FormalParameter node = AstFactory.fieldFormalParameter(null, intTypeName, pa
rameterName); |
| 11346 node.identifier.staticElement = ElementFactory.requiredParameter(parameterNa
me); | 11344 node.identifier.staticElement = ElementFactory.requiredParameter(parameterNa
me); |
| 11347 JUnitTestCase.assertSame(intType, _resolveFormalParameter(node, [intType.ele
ment])); | 11345 expect(_resolveFormalParameter(node, [intType.element]), same(intType)); |
| 11348 _listener.assertNoErrors(); | 11346 _listener.assertNoErrors(); |
| 11349 } | 11347 } |
| 11350 | 11348 |
| 11351 void test_visitSimpleFormalParameter_noType() { | 11349 void test_visitSimpleFormalParameter_noType() { |
| 11352 // p | 11350 // p |
| 11353 FormalParameter node = AstFactory.simpleFormalParameter3("p"); | 11351 FormalParameter node = AstFactory.simpleFormalParameter3("p"); |
| 11354 node.identifier.staticElement = new ParameterElementImpl.forNode(AstFactory.
identifier3("p")); | 11352 node.identifier.staticElement = new ParameterElementImpl.forNode(AstFactory.
identifier3("p")); |
| 11355 JUnitTestCase.assertSame(_typeProvider.dynamicType, _resolveFormalParameter(
node, [])); | 11353 expect(_resolveFormalParameter(node, []), same(_typeProvider.dynamicType)); |
| 11356 _listener.assertNoErrors(); | 11354 _listener.assertNoErrors(); |
| 11357 } | 11355 } |
| 11358 | 11356 |
| 11359 void test_visitSimpleFormalParameter_type() { | 11357 void test_visitSimpleFormalParameter_type() { |
| 11360 // int p | 11358 // int p |
| 11361 InterfaceType intType = _typeProvider.intType; | 11359 InterfaceType intType = _typeProvider.intType; |
| 11362 ClassElement intElement = intType.element; | 11360 ClassElement intElement = intType.element; |
| 11363 FormalParameter node = AstFactory.simpleFormalParameter4(AstFactory.typeName
(intElement, []), "p"); | 11361 FormalParameter node = AstFactory.simpleFormalParameter4(AstFactory.typeName
(intElement, []), "p"); |
| 11364 SimpleIdentifier identifier = node.identifier; | 11362 SimpleIdentifier identifier = node.identifier; |
| 11365 ParameterElementImpl element = new ParameterElementImpl.forNode(identifier); | 11363 ParameterElementImpl element = new ParameterElementImpl.forNode(identifier); |
| 11366 identifier.staticElement = element; | 11364 identifier.staticElement = element; |
| 11367 JUnitTestCase.assertSame(intType, _resolveFormalParameter(node, [intElement]
)); | 11365 expect(_resolveFormalParameter(node, [intElement]), same(intType)); |
| 11368 _listener.assertNoErrors(); | 11366 _listener.assertNoErrors(); |
| 11369 } | 11367 } |
| 11370 | 11368 |
| 11371 void test_visitTypeName_noParameters_noArguments() { | 11369 void test_visitTypeName_noParameters_noArguments() { |
| 11372 ClassElement classA = ElementFactory.classElement2("A", []); | 11370 ClassElement classA = ElementFactory.classElement2("A", []); |
| 11373 TypeName typeName = AstFactory.typeName(classA, []); | 11371 TypeName typeName = AstFactory.typeName(classA, []); |
| 11374 typeName.type = null; | 11372 typeName.type = null; |
| 11375 _resolveNode(typeName, [classA]); | 11373 _resolveNode(typeName, [classA]); |
| 11376 JUnitTestCase.assertSame(classA.type, typeName.type); | 11374 expect(typeName.type, same(classA.type)); |
| 11377 _listener.assertNoErrors(); | 11375 _listener.assertNoErrors(); |
| 11378 } | 11376 } |
| 11379 | 11377 |
| 11380 void test_visitTypeName_parameters_arguments() { | 11378 void test_visitTypeName_parameters_arguments() { |
| 11381 ClassElement classA = ElementFactory.classElement2("A", ["E"]); | 11379 ClassElement classA = ElementFactory.classElement2("A", ["E"]); |
| 11382 ClassElement classB = ElementFactory.classElement2("B", []); | 11380 ClassElement classB = ElementFactory.classElement2("B", []); |
| 11383 TypeName typeName = AstFactory.typeName(classA, [AstFactory.typeName(classB,
[])]); | 11381 TypeName typeName = AstFactory.typeName(classA, [AstFactory.typeName(classB,
[])]); |
| 11384 typeName.type = null; | 11382 typeName.type = null; |
| 11385 _resolveNode(typeName, [classA, classB]); | 11383 _resolveNode(typeName, [classA, classB]); |
| 11386 InterfaceType resultType = typeName.type as InterfaceType; | 11384 InterfaceType resultType = typeName.type as InterfaceType; |
| 11387 JUnitTestCase.assertSame(classA, resultType.element); | 11385 expect(resultType.element, same(classA)); |
| 11388 List<DartType> resultArguments = resultType.typeArguments; | 11386 List<DartType> resultArguments = resultType.typeArguments; |
| 11389 EngineTestCase.assertLength(1, resultArguments); | 11387 EngineTestCase.assertLength(1, resultArguments); |
| 11390 JUnitTestCase.assertSame(classB.type, resultArguments[0]); | 11388 expect(resultArguments[0], same(classB.type)); |
| 11391 _listener.assertNoErrors(); | 11389 _listener.assertNoErrors(); |
| 11392 } | 11390 } |
| 11393 | 11391 |
| 11394 void test_visitTypeName_parameters_noArguments() { | 11392 void test_visitTypeName_parameters_noArguments() { |
| 11395 ClassElement classA = ElementFactory.classElement2("A", ["E"]); | 11393 ClassElement classA = ElementFactory.classElement2("A", ["E"]); |
| 11396 TypeName typeName = AstFactory.typeName(classA, []); | 11394 TypeName typeName = AstFactory.typeName(classA, []); |
| 11397 typeName.type = null; | 11395 typeName.type = null; |
| 11398 _resolveNode(typeName, [classA]); | 11396 _resolveNode(typeName, [classA]); |
| 11399 InterfaceType resultType = typeName.type as InterfaceType; | 11397 InterfaceType resultType = typeName.type as InterfaceType; |
| 11400 JUnitTestCase.assertSame(classA, resultType.element); | 11398 expect(resultType.element, same(classA)); |
| 11401 List<DartType> resultArguments = resultType.typeArguments; | 11399 List<DartType> resultArguments = resultType.typeArguments; |
| 11402 EngineTestCase.assertLength(1, resultArguments); | 11400 EngineTestCase.assertLength(1, resultArguments); |
| 11403 JUnitTestCase.assertSame(DynamicTypeImpl.instance, resultArguments[0]); | 11401 expect(resultArguments[0], same(DynamicTypeImpl.instance)); |
| 11404 _listener.assertNoErrors(); | 11402 _listener.assertNoErrors(); |
| 11405 } | 11403 } |
| 11406 | 11404 |
| 11407 void test_visitTypeName_void() { | 11405 void test_visitTypeName_void() { |
| 11408 ClassElement classA = ElementFactory.classElement2("A", []); | 11406 ClassElement classA = ElementFactory.classElement2("A", []); |
| 11409 TypeName typeName = AstFactory.typeName4("void", []); | 11407 TypeName typeName = AstFactory.typeName4("void", []); |
| 11410 _resolveNode(typeName, [classA]); | 11408 _resolveNode(typeName, [classA]); |
| 11411 JUnitTestCase.assertSame(VoidTypeImpl.instance, typeName.type); | 11409 expect(typeName.type, same(VoidTypeImpl.instance)); |
| 11412 _listener.assertNoErrors(); | 11410 _listener.assertNoErrors(); |
| 11413 } | 11411 } |
| 11414 | 11412 |
| 11415 /** | 11413 /** |
| 11416 * Analyze the given catch clause and assert that the types of the parameters
have been set to the | 11414 * Analyze the given catch clause and assert that the types of the parameters
have been set to the |
| 11417 * given types. The types can be null if the catch clause does not have the co
rresponding | 11415 * given types. The types can be null if the catch clause does not have the co
rresponding |
| 11418 * parameter. | 11416 * parameter. |
| 11419 * | 11417 * |
| 11420 * @param node the catch clause to be analyzed | 11418 * @param node the catch clause to be analyzed |
| 11421 * @param exceptionType the expected type of the exception parameter | 11419 * @param exceptionType the expected type of the exception parameter |
| 11422 * @param stackTraceType the expected type of the stack trace parameter | 11420 * @param stackTraceType the expected type of the stack trace parameter |
| 11423 * @param definedElements the elements that are to be defined in the scope in
which the element is | 11421 * @param definedElements the elements that are to be defined in the scope in
which the element is |
| 11424 * being resolved | 11422 * being resolved |
| 11425 */ | 11423 */ |
| 11426 void _resolveCatchClause(CatchClause node, DartType exceptionType, InterfaceTy
pe stackTraceType, List<Element> definedElements) { | 11424 void _resolveCatchClause(CatchClause node, DartType exceptionType, InterfaceTy
pe stackTraceType, List<Element> definedElements) { |
| 11427 _resolveNode(node, definedElements); | 11425 _resolveNode(node, definedElements); |
| 11428 SimpleIdentifier exceptionParameter = node.exceptionParameter; | 11426 SimpleIdentifier exceptionParameter = node.exceptionParameter; |
| 11429 if (exceptionParameter != null) { | 11427 if (exceptionParameter != null) { |
| 11430 JUnitTestCase.assertSame(exceptionType, exceptionParameter.staticType); | 11428 expect(exceptionParameter.staticType, same(exceptionType)); |
| 11431 } | 11429 } |
| 11432 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; | 11430 SimpleIdentifier stackTraceParameter = node.stackTraceParameter; |
| 11433 if (stackTraceParameter != null) { | 11431 if (stackTraceParameter != null) { |
| 11434 JUnitTestCase.assertSame(stackTraceType, stackTraceParameter.staticType); | 11432 expect(stackTraceParameter.staticType, same(stackTraceType)); |
| 11435 } | 11433 } |
| 11436 } | 11434 } |
| 11437 | 11435 |
| 11438 /** | 11436 /** |
| 11439 * Return the type associated with the given parameter after the static type a
nalyzer has computed | 11437 * Return the type associated with the given parameter after the static type a
nalyzer has computed |
| 11440 * a type for it. | 11438 * a type for it. |
| 11441 * | 11439 * |
| 11442 * @param node the parameter with which the type is associated | 11440 * @param node the parameter with which the type is associated |
| 11443 * @param definedElements the elements that are to be defined in the scope in
which the element is | 11441 * @param definedElements the elements that are to be defined in the scope in
which the element is |
| 11444 * being resolved | 11442 * being resolved |
| (...skipping 16 matching lines...) Expand all Loading... |
| 11461 void _resolveNode(AstNode node, List<Element> definedElements) { | 11459 void _resolveNode(AstNode node, List<Element> definedElements) { |
| 11462 for (Element element in definedElements) { | 11460 for (Element element in definedElements) { |
| 11463 _library.libraryScope.define(element); | 11461 _library.libraryScope.define(element); |
| 11464 } | 11462 } |
| 11465 node.accept(_visitor); | 11463 node.accept(_visitor); |
| 11466 node.accept(_implicitConstructorBuilder); | 11464 node.accept(_implicitConstructorBuilder); |
| 11467 } | 11465 } |
| 11468 } | 11466 } |
| 11469 | 11467 |
| 11470 main() { | 11468 main() { |
| 11471 _ut.groupSep = ' | '; | 11469 groupSep = ' | '; |
| 11472 runReflectiveTests(AnalysisDeltaTest); | 11470 runReflectiveTests(AnalysisDeltaTest); |
| 11473 runReflectiveTests(ChangeSetTest); | 11471 runReflectiveTests(ChangeSetTest); |
| 11474 runReflectiveTests(EnclosedScopeTest); | 11472 runReflectiveTests(EnclosedScopeTest); |
| 11475 runReflectiveTests(LibraryImportScopeTest); | 11473 runReflectiveTests(LibraryImportScopeTest); |
| 11476 runReflectiveTests(LibraryScopeTest); | 11474 runReflectiveTests(LibraryScopeTest); |
| 11477 runReflectiveTests(ScopeBuilderTest); | 11475 runReflectiveTests(ScopeBuilderTest); |
| 11478 runReflectiveTests(ScopeTest); | 11476 runReflectiveTests(ScopeTest); |
| 11479 runReflectiveTests(DeclarationMatcherTest); | 11477 runReflectiveTests(DeclarationMatcherTest); |
| 11480 runReflectiveTests(ElementResolverTest); | 11478 runReflectiveTests(ElementResolverTest); |
| 11481 runReflectiveTests(IncrementalResolverTest); | 11479 runReflectiveTests(IncrementalResolverTest); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 11492 runReflectiveTests(TypeResolverVisitorTest); | 11490 runReflectiveTests(TypeResolverVisitorTest); |
| 11493 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); | 11491 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); |
| 11494 runReflectiveTests(ErrorResolverTest); | 11492 runReflectiveTests(ErrorResolverTest); |
| 11495 runReflectiveTests(HintCodeTest); | 11493 runReflectiveTests(HintCodeTest); |
| 11496 runReflectiveTests(MemberMapTest); | 11494 runReflectiveTests(MemberMapTest); |
| 11497 runReflectiveTests(NonHintCodeTest); | 11495 runReflectiveTests(NonHintCodeTest); |
| 11498 runReflectiveTests(SimpleResolverTest); | 11496 runReflectiveTests(SimpleResolverTest); |
| 11499 runReflectiveTests(StrictModeTest); | 11497 runReflectiveTests(StrictModeTest); |
| 11500 runReflectiveTests(TypePropagationTest); | 11498 runReflectiveTests(TypePropagationTest); |
| 11501 } | 11499 } |
| OLD | NEW |