| 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_engine.dart'; | 9 import 'package:analyzer/src/generated/java_engine.dart'; |
| 10 import 'package:analyzer/src/generated/java_engine_io.dart'; | 10 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| (...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 TestSource source2 = new TestSource('/2.dart'); | 329 TestSource source2 = new TestSource('/2.dart'); |
| 330 TestSource source3 = new TestSource('/3.dart'); | 330 TestSource source3 = new TestSource('/3.dart'); |
| 331 | 331 |
| 332 void test_getAddedSources() { | 332 void test_getAddedSources() { |
| 333 AnalysisDelta delta = new AnalysisDelta(); | 333 AnalysisDelta delta = new AnalysisDelta(); |
| 334 delta.setAnalysisLevel(source1, AnalysisLevel.ALL); | 334 delta.setAnalysisLevel(source1, AnalysisLevel.ALL); |
| 335 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS); | 335 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS); |
| 336 delta.setAnalysisLevel(source3, AnalysisLevel.NONE); | 336 delta.setAnalysisLevel(source3, AnalysisLevel.NONE); |
| 337 List<Source> addedSources = delta.addedSources; | 337 List<Source> addedSources = delta.addedSources; |
| 338 expect(addedSources, hasLength(2)); | 338 expect(addedSources, hasLength(2)); |
| 339 EngineTestCase.assertContains(addedSources, [source1, source2]); | 339 expect(addedSources, unorderedEquals([source1, source2])); |
| 340 } | 340 } |
| 341 | 341 |
| 342 void test_getAnalysisLevels() { | 342 void test_getAnalysisLevels() { |
| 343 AnalysisDelta delta = new AnalysisDelta(); | 343 AnalysisDelta delta = new AnalysisDelta(); |
| 344 expect(delta.analysisLevels.length, 0); | 344 expect(delta.analysisLevels.length, 0); |
| 345 } | 345 } |
| 346 | 346 |
| 347 void test_setAnalysisLevel() { | 347 void test_setAnalysisLevel() { |
| 348 AnalysisDelta delta = new AnalysisDelta(); | 348 AnalysisDelta delta = new AnalysisDelta(); |
| 349 delta.setAnalysisLevel(source1, AnalysisLevel.ALL); | 349 delta.setAnalysisLevel(source1, AnalysisLevel.ALL); |
| (...skipping 3901 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4251 | 4251 |
| 4252 void test_lookupOverrides_overrideBaseClass() { | 4252 void test_lookupOverrides_overrideBaseClass() { |
| 4253 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4253 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4254 String methodName = "m"; | 4254 String methodName = "m"; |
| 4255 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ
eProvider.intType, []); | 4255 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ
eProvider.intType, []); |
| 4256 classA.methods = <MethodElement> [methodMinA]; | 4256 classA.methods = <MethodElement> [methodMinA]; |
| 4257 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 4257 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 4258 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ
eProvider.intType, []); | 4258 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ
eProvider.intType, []); |
| 4259 classB.methods = <MethodElement> [methodMinB]; | 4259 classB.methods = <MethodElement> [methodMinB]; |
| 4260 List<ExecutableElement> overrides = _inheritanceManager.lookupOverrides(clas
sB, methodName); | 4260 List<ExecutableElement> overrides = _inheritanceManager.lookupOverrides(clas
sB, methodName); |
| 4261 EngineTestCase.assertEqualsIgnoreOrder(<Object> [methodMinA], overrides); | 4261 expect(overrides, unorderedEquals([methodMinA])); |
| 4262 _assertNoErrors(classA); | 4262 _assertNoErrors(classA); |
| 4263 _assertNoErrors(classB); | 4263 _assertNoErrors(classB); |
| 4264 } | 4264 } |
| 4265 | 4265 |
| 4266 void test_lookupOverrides_overrideInterface() { | 4266 void test_lookupOverrides_overrideInterface() { |
| 4267 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4267 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4268 String methodName = "m"; | 4268 String methodName = "m"; |
| 4269 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ
eProvider.intType, []); | 4269 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ
eProvider.intType, []); |
| 4270 classA.methods = <MethodElement> [methodMinA]; | 4270 classA.methods = <MethodElement> [methodMinA]; |
| 4271 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 4271 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 4272 classB.interfaces = <InterfaceType> [classA.type]; | 4272 classB.interfaces = <InterfaceType> [classA.type]; |
| 4273 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ
eProvider.intType, []); | 4273 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ
eProvider.intType, []); |
| 4274 classB.methods = <MethodElement> [methodMinB]; | 4274 classB.methods = <MethodElement> [methodMinB]; |
| 4275 List<ExecutableElement> overrides = _inheritanceManager.lookupOverrides(clas
sB, methodName); | 4275 List<ExecutableElement> overrides = _inheritanceManager.lookupOverrides(clas
sB, methodName); |
| 4276 EngineTestCase.assertEqualsIgnoreOrder(<Object> [methodMinA], overrides); | 4276 expect(overrides, unorderedEquals([methodMinA])); |
| 4277 _assertNoErrors(classA); | 4277 _assertNoErrors(classA); |
| 4278 _assertNoErrors(classB); | 4278 _assertNoErrors(classB); |
| 4279 } | 4279 } |
| 4280 | 4280 |
| 4281 void test_lookupOverrides_overrideTwoInterfaces() { | 4281 void test_lookupOverrides_overrideTwoInterfaces() { |
| 4282 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 4282 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 4283 String methodName = "m"; | 4283 String methodName = "m"; |
| 4284 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ
eProvider.intType, []); | 4284 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ
eProvider.intType, []); |
| 4285 classA.methods = <MethodElement> [methodMinA]; | 4285 classA.methods = <MethodElement> [methodMinA]; |
| 4286 ClassElementImpl classB = ElementFactory.classElement2("B", []); | 4286 ClassElementImpl classB = ElementFactory.classElement2("B", []); |
| 4287 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ
eProvider.doubleType, []); | 4287 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ
eProvider.doubleType, []); |
| 4288 classB.methods = <MethodElement> [methodMinB]; | 4288 classB.methods = <MethodElement> [methodMinB]; |
| 4289 ClassElementImpl classC = ElementFactory.classElement2("C", []); | 4289 ClassElementImpl classC = ElementFactory.classElement2("C", []); |
| 4290 classC.interfaces = <InterfaceType> [classA.type, classB.type]; | 4290 classC.interfaces = <InterfaceType> [classA.type, classB.type]; |
| 4291 MethodElementImpl methodMinC = ElementFactory.methodElement(methodName, _typ
eProvider.numType, []); | 4291 MethodElementImpl methodMinC = ElementFactory.methodElement(methodName, _typ
eProvider.numType, []); |
| 4292 classC.methods = <MethodElement> [methodMinC]; | 4292 classC.methods = <MethodElement> [methodMinC]; |
| 4293 List<ExecutableElement> overrides = _inheritanceManager.lookupOverrides(clas
sC, methodName); | 4293 List<ExecutableElement> overrides = _inheritanceManager.lookupOverrides(clas
sC, methodName); |
| 4294 EngineTestCase.assertEqualsIgnoreOrder(<Object> [methodMinA, methodMinB], ov
errides); | 4294 expect(overrides, unorderedEquals([methodMinA, methodMinB])); |
| 4295 _assertNoErrors(classA); | 4295 _assertNoErrors(classA); |
| 4296 _assertNoErrors(classB); | 4296 _assertNoErrors(classB); |
| 4297 _assertNoErrors(classC); | 4297 _assertNoErrors(classC); |
| 4298 } | 4298 } |
| 4299 | 4299 |
| 4300 void _assertErrors(ClassElement classElt, List<ErrorCode> expectedErrorCodes)
{ | 4300 void _assertErrors(ClassElement classElt, List<ErrorCode> expectedErrorCodes)
{ |
| 4301 GatheringErrorListener errorListener = new GatheringErrorListener(); | 4301 GatheringErrorListener errorListener = new GatheringErrorListener(); |
| 4302 HashSet<AnalysisError> actualErrors = _inheritanceManager.getErrors(classElt
); | 4302 HashSet<AnalysisError> actualErrors = _inheritanceManager.getErrors(classElt
); |
| 4303 if (actualErrors != null) { | 4303 if (actualErrors != null) { |
| 4304 for (AnalysisError error in actualErrors) { | 4304 for (AnalysisError error in actualErrors) { |
| (...skipping 4866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9171 // class A extends B | 9171 // class A extends B |
| 9172 // class B extends A | 9172 // class B extends A |
| 9173 // | 9173 // |
| 9174 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 9174 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 9175 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 9175 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 9176 classA.supertype = classB.type; | 9176 classA.supertype = classB.type; |
| 9177 _definingCompilationUnit.types = <ClassElement> [classA, classB]; | 9177 _definingCompilationUnit.types = <ClassElement> [classA, classB]; |
| 9178 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class
A); | 9178 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class
A); |
| 9179 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); | 9179 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); |
| 9180 expect(subtypesOfA, hasLength(2)); | 9180 expect(subtypesOfA, hasLength(2)); |
| 9181 EngineTestCase.assertContains(arraySubtypesOfA, [classA, classB]); | 9181 expect(arraySubtypesOfA, unorderedEquals([classA, classB])); |
| 9182 } | 9182 } |
| 9183 | 9183 |
| 9184 void test_computeAllSubtypes_manyRecursiveSubtypes() { | 9184 void test_computeAllSubtypes_manyRecursiveSubtypes() { |
| 9185 // | 9185 // |
| 9186 // class A | 9186 // class A |
| 9187 // class B extends A | 9187 // class B extends A |
| 9188 // class C extends B | 9188 // class C extends B |
| 9189 // class D extends B | 9189 // class D extends B |
| 9190 // class E extends B | 9190 // class E extends B |
| 9191 // | 9191 // |
| 9192 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 9192 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 9193 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 9193 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 9194 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); | 9194 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); |
| 9195 ClassElementImpl classD = ElementFactory.classElement("D", classB.type, []); | 9195 ClassElementImpl classD = ElementFactory.classElement("D", classB.type, []); |
| 9196 ClassElementImpl classE = ElementFactory.classElement("E", classB.type, []); | 9196 ClassElementImpl classE = ElementFactory.classElement("E", classB.type, []); |
| 9197 _definingCompilationUnit.types = <ClassElement> [classA, classB, classC, cla
ssD, classE]; | 9197 _definingCompilationUnit.types = <ClassElement> [classA, classB, classC, cla
ssD, classE]; |
| 9198 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class
A); | 9198 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class
A); |
| 9199 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); | 9199 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); |
| 9200 HashSet<ClassElement> subtypesOfB = _subtypeManager.computeAllSubtypes(class
B); | 9200 HashSet<ClassElement> subtypesOfB = _subtypeManager.computeAllSubtypes(class
B); |
| 9201 List<ClassElement> arraySubtypesOfB = new List.from(subtypesOfB); | 9201 List<ClassElement> arraySubtypesOfB = new List.from(subtypesOfB); |
| 9202 expect(subtypesOfA, hasLength(4)); | 9202 expect(subtypesOfA, hasLength(4)); |
| 9203 EngineTestCase.assertContains(arraySubtypesOfA, [classB, classC, classD, cla
ssE]); | 9203 expect(arraySubtypesOfA, unorderedEquals([classB, classC, classD, classE])); |
| 9204 expect(subtypesOfB, hasLength(3)); | 9204 expect(subtypesOfB, hasLength(3)); |
| 9205 EngineTestCase.assertContains(arraySubtypesOfB, [classC, classD, classE]); | 9205 expect(arraySubtypesOfB, unorderedEquals([classC, classD, classE])); |
| 9206 } | 9206 } |
| 9207 | 9207 |
| 9208 void test_computeAllSubtypes_noSubtypes() { | 9208 void test_computeAllSubtypes_noSubtypes() { |
| 9209 // | 9209 // |
| 9210 // class A | 9210 // class A |
| 9211 // | 9211 // |
| 9212 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 9212 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 9213 _definingCompilationUnit.types = <ClassElement> [classA]; | 9213 _definingCompilationUnit.types = <ClassElement> [classA]; |
| 9214 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class
A); | 9214 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class
A); |
| 9215 expect(subtypesOfA, hasLength(0)); | 9215 expect(subtypesOfA, hasLength(0)); |
| 9216 } | 9216 } |
| 9217 | 9217 |
| 9218 void test_computeAllSubtypes_oneSubtype() { | 9218 void test_computeAllSubtypes_oneSubtype() { |
| 9219 // | 9219 // |
| 9220 // class A | 9220 // class A |
| 9221 // class B extends A | 9221 // class B extends A |
| 9222 // | 9222 // |
| 9223 ClassElementImpl classA = ElementFactory.classElement2("A", []); | 9223 ClassElementImpl classA = ElementFactory.classElement2("A", []); |
| 9224 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); | 9224 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); |
| 9225 _definingCompilationUnit.types = <ClassElement> [classA, classB]; | 9225 _definingCompilationUnit.types = <ClassElement> [classA, classB]; |
| 9226 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class
A); | 9226 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class
A); |
| 9227 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); | 9227 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); |
| 9228 expect(subtypesOfA, hasLength(1)); | 9228 expect(subtypesOfA, hasLength(1)); |
| 9229 EngineTestCase.assertContains(arraySubtypesOfA, [classB]); | 9229 expect(arraySubtypesOfA, unorderedEquals([classB])); |
| 9230 } | 9230 } |
| 9231 | 9231 |
| 9232 @override | 9232 @override |
| 9233 void setUp() { | 9233 void setUp() { |
| 9234 super.setUp(); | 9234 super.setUp(); |
| 9235 AnalysisContextImpl context = AnalysisContextFactory.contextWithCore(); | 9235 AnalysisContextImpl context = AnalysisContextFactory.contextWithCore(); |
| 9236 FileBasedSource source = new FileBasedSource.con1(FileUtilities2.createFile(
"/test.dart")); | 9236 FileBasedSource source = new FileBasedSource.con1(FileUtilities2.createFile(
"/test.dart")); |
| 9237 _definingCompilationUnit = new CompilationUnitElementImpl("test.dart"); | 9237 _definingCompilationUnit = new CompilationUnitElementImpl("test.dart"); |
| 9238 _definingCompilationUnit.source = source; | 9238 _definingCompilationUnit.source = source; |
| 9239 LibraryElementImpl definingLibrary = ElementFactory.library(context, "test")
; | 9239 LibraryElementImpl definingLibrary = ElementFactory.library(context, "test")
; |
| (...skipping 2250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11490 runReflectiveTests(TypeResolverVisitorTest); | 11490 runReflectiveTests(TypeResolverVisitorTest); |
| 11491 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); | 11491 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); |
| 11492 runReflectiveTests(ErrorResolverTest); | 11492 runReflectiveTests(ErrorResolverTest); |
| 11493 runReflectiveTests(HintCodeTest); | 11493 runReflectiveTests(HintCodeTest); |
| 11494 runReflectiveTests(MemberMapTest); | 11494 runReflectiveTests(MemberMapTest); |
| 11495 runReflectiveTests(NonHintCodeTest); | 11495 runReflectiveTests(NonHintCodeTest); |
| 11496 runReflectiveTests(SimpleResolverTest); | 11496 runReflectiveTests(SimpleResolverTest); |
| 11497 runReflectiveTests(StrictModeTest); | 11497 runReflectiveTests(StrictModeTest); |
| 11498 runReflectiveTests(TypePropagationTest); | 11498 runReflectiveTests(TypePropagationTest); |
| 11499 } | 11499 } |
| OLD | NEW |