Remove unused SubtypeManager.
R=brianwilkerson@google.com
Change-Id: I4ec2bec51912817621361bf170257c6dfe972189
Reviewed-on: https://dart-review.googlesource.com/75123
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 7d74d96..8eed8da 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -7850,175 +7850,6 @@
}
/**
- * Instances of this class manage the knowledge of what the set of subtypes are for a given type.
- */
-class SubtypeManager {
- /**
- * A map between [ClassElement]s and a set of [ClassElement]s that are subtypes of the
- * key.
- */
- Map<ClassElement, HashSet<ClassElement>> _subtypeMap =
- new HashMap<ClassElement, HashSet<ClassElement>>();
-
- /**
- * The set of all [LibraryElement]s that have been visited by the manager. This is used both
- * to prevent infinite loops in the recursive methods, and also as a marker for the scope of the
- * libraries visited by this manager.
- */
- HashSet<LibraryElement> _visitedLibraries = new HashSet<LibraryElement>();
-
- /**
- * Given some [ClassElement], return the set of all subtypes, and subtypes of subtypes.
- *
- * @param classElement the class to recursively return the set of subtypes of
- */
- HashSet<ClassElement> computeAllSubtypes(ClassElement classElement) {
- // Ensure that we have generated the subtype map for the library
- _computeSubtypesInLibrary(classElement.library);
- // use the subtypeMap to compute the set of all subtypes and subtype's
- // subtypes
- HashSet<ClassElement> allSubtypes = new HashSet<ClassElement>();
- _safelyComputeAllSubtypes(
- classElement, new HashSet<ClassElement>(), allSubtypes);
- return allSubtypes;
- }
-
- /**
- * Given some [LibraryElement], visit all of the types in the library, the passed library,
- * and any imported libraries, will be in the [visitedLibraries] set.
- *
- * @param libraryElement the library to visit, it it hasn't been visited already
- */
- void ensureLibraryVisited(LibraryElement libraryElement) {
- _computeSubtypesInLibrary(libraryElement);
- }
-
- /**
- * Given some [ClassElement], this method adds all of the pairs combinations of itself and
- * all of its supertypes to the [subtypeMap] map.
- *
- * @param classElement the class element
- */
- void _computeSubtypesInClass(ClassElement classElement) {
- InterfaceType supertypeType = classElement.supertype;
- if (supertypeType != null) {
- ClassElement supertypeElement = supertypeType.element;
- if (supertypeElement != null) {
- _putInSubtypeMap(supertypeElement, classElement);
- }
- }
- List<InterfaceType> interfaceTypes = classElement.interfaces;
- int interfaceLength = interfaceTypes.length;
- for (int i = 0; i < interfaceLength; i++) {
- InterfaceType interfaceType = interfaceTypes[i];
- ClassElement interfaceElement = interfaceType.element;
- if (interfaceElement != null) {
- _putInSubtypeMap(interfaceElement, classElement);
- }
- }
- List<InterfaceType> mixinTypes = classElement.mixins;
- int mixinLength = mixinTypes.length;
- for (int i = 0; i < mixinLength; i++) {
- InterfaceType mixinType = mixinTypes[i];
- ClassElement mixinElement = mixinType.element;
- if (mixinElement != null) {
- _putInSubtypeMap(mixinElement, classElement);
- }
- }
- }
-
- /**
- * Given some [CompilationUnitElement], this method calls
- * [computeAllSubtypes] on all of the [ClassElement]s in the
- * compilation unit.
- *
- * @param unitElement the compilation unit element
- */
- void _computeSubtypesInCompilationUnit(CompilationUnitElement unitElement) {
- List<ClassElement> classElements = unitElement.types;
- int length = classElements.length;
- for (int i = 0; i < length; i++) {
- ClassElement classElement = classElements[i];
- _computeSubtypesInClass(classElement);
- }
- }
-
- /**
- * Given some [LibraryElement], this method calls
- * [computeAllSubtypes] on all of the [ClassElement]s in the
- * compilation unit, and itself for all imported and exported libraries. All visited libraries are
- * added to the [visitedLibraries] set.
- *
- * @param libraryElement the library element
- */
- void _computeSubtypesInLibrary(LibraryElement libraryElement) {
- if (libraryElement == null || _visitedLibraries.contains(libraryElement)) {
- return;
- }
- _visitedLibraries.add(libraryElement);
- _computeSubtypesInCompilationUnit(libraryElement.definingCompilationUnit);
- List<CompilationUnitElement> parts = libraryElement.parts;
- int partLength = parts.length;
- for (int i = 0; i < partLength; i++) {
- CompilationUnitElement part = parts[i];
- _computeSubtypesInCompilationUnit(part);
- }
- List<LibraryElement> imports = libraryElement.importedLibraries;
- int importLength = imports.length;
- for (int i = 0; i < importLength; i++) {
- LibraryElement importElt = imports[i];
- _computeSubtypesInLibrary(importElt.library);
- }
- List<LibraryElement> exports = libraryElement.exportedLibraries;
- int exportLength = exports.length;
- for (int i = 0; i < exportLength; i++) {
- LibraryElement exportElt = exports[i];
- _computeSubtypesInLibrary(exportElt.library);
- }
- }
-
- /**
- * Add some key/ value pair into the [subtypeMap] map.
- *
- * @param supertypeElement the key for the [subtypeMap] map
- * @param subtypeElement the value for the [subtypeMap] map
- */
- void _putInSubtypeMap(
- ClassElement supertypeElement, ClassElement subtypeElement) {
- HashSet<ClassElement> subtypes = _subtypeMap[supertypeElement];
- if (subtypes == null) {
- subtypes = new HashSet<ClassElement>();
- _subtypeMap[supertypeElement] = subtypes;
- }
- subtypes.add(subtypeElement);
- }
-
- /**
- * Given some [ClassElement] and a [HashSet<ClassElement>], this method recursively
- * adds all of the subtypes of the [ClassElement] to the passed array.
- *
- * @param classElement the type to compute the set of subtypes of
- * @param visitedClasses the set of class elements that this method has already recursively seen
- * @param allSubtypes the computed set of subtypes of the passed class element
- */
- void _safelyComputeAllSubtypes(ClassElement classElement,
- HashSet<ClassElement> visitedClasses, HashSet<ClassElement> allSubtypes) {
- if (!visitedClasses.add(classElement)) {
- // if this class has already been called on this class element
- return;
- }
- HashSet<ClassElement> subtypes = _subtypeMap[classElement];
- if (subtypes == null) {
- return;
- }
- for (ClassElement subtype in subtypes) {
- _safelyComputeAllSubtypes(subtype, visitedClasses, allSubtypes);
- }
- allSubtypes.addAll(subtypes);
- }
-}
-
-/**
* Instances of the class `ToDoFinder` find to-do comments in Dart code.
*/
class ToDoFinder {
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index 0b44b59..0f806d1 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -49,7 +49,6 @@
defineReflectiveTests(PrefixedNamespaceTest);
defineReflectiveTests(ScopeTest);
defineReflectiveTests(StrictModeTest);
- defineReflectiveTests(SubtypeManagerTest);
defineReflectiveTests(TypeOverrideManagerTest);
defineReflectiveTests(TypePropagationTest);
defineReflectiveTests(TypeProviderImplTest);
@@ -752,107 +751,6 @@
}
@reflectiveTest
-class SubtypeManagerTest {
- /**
- * The inheritance manager being tested.
- */
- SubtypeManager _subtypeManager;
-
- /**
- * The compilation unit element containing all of the types setup in each test.
- */
- CompilationUnitElementImpl _definingCompilationUnit;
-
- void setUp() {
- MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
- AnalysisContext context = AnalysisContextFactory.contextWithCore(
- resourceProvider: resourceProvider);
- Source source = new FileSource(resourceProvider.getFile("/test.dart"));
- _definingCompilationUnit = new CompilationUnitElementImpl("test.dart");
- _definingCompilationUnit.librarySource =
- _definingCompilationUnit.source = source;
- LibraryElementImpl definingLibrary =
- ElementFactory.library(context, "test");
- definingLibrary.definingCompilationUnit = _definingCompilationUnit;
- _subtypeManager = new SubtypeManager();
- }
-
- void test_computeAllSubtypes_infiniteLoop() {
- //
- // class A extends B
- // class B extends A
- //
- ClassElementImpl classA = ElementFactory.classElement2("A");
- ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
- classA.supertype = classB.type;
- _definingCompilationUnit.types = <ClassElement>[classA, classB];
- HashSet<ClassElement> subtypesOfA =
- _subtypeManager.computeAllSubtypes(classA);
- List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
- expect(subtypesOfA, hasLength(2));
- expect(arraySubtypesOfA, unorderedEquals([classA, classB]));
- }
-
- void test_computeAllSubtypes_manyRecursiveSubtypes() {
- //
- // class A
- // class B extends A
- // class C extends B
- // class D extends B
- // class E extends B
- //
- ClassElementImpl classA = ElementFactory.classElement2("A");
- ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
- ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
- ClassElementImpl classD = ElementFactory.classElement("D", classB.type);
- ClassElementImpl classE = ElementFactory.classElement("E", classB.type);
- _definingCompilationUnit.types = <ClassElement>[
- classA,
- classB,
- classC,
- classD,
- classE
- ];
- HashSet<ClassElement> subtypesOfA =
- _subtypeManager.computeAllSubtypes(classA);
- List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
- HashSet<ClassElement> subtypesOfB =
- _subtypeManager.computeAllSubtypes(classB);
- List<ClassElement> arraySubtypesOfB = new List.from(subtypesOfB);
- expect(subtypesOfA, hasLength(4));
- expect(arraySubtypesOfA, unorderedEquals([classB, classC, classD, classE]));
- expect(subtypesOfB, hasLength(3));
- expect(arraySubtypesOfB, unorderedEquals([classC, classD, classE]));
- }
-
- void test_computeAllSubtypes_noSubtypes() {
- //
- // class A
- //
- ClassElementImpl classA = ElementFactory.classElement2("A");
- _definingCompilationUnit.types = <ClassElement>[classA];
- HashSet<ClassElement> subtypesOfA =
- _subtypeManager.computeAllSubtypes(classA);
- expect(subtypesOfA, hasLength(0));
- }
-
- void test_computeAllSubtypes_oneSubtype() {
- //
- // class A
- // class B extends A
- //
- ClassElementImpl classA = ElementFactory.classElement2("A");
- ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
- _definingCompilationUnit.types = <ClassElement>[classA, classB];
- HashSet<ClassElement> subtypesOfA =
- _subtypeManager.computeAllSubtypes(classA);
- List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
- expect(subtypesOfA, hasLength(1));
- expect(arraySubtypesOfA, unorderedEquals([classB]));
- }
-}
-
-@reflectiveTest
class TypeOverrideManagerTest extends EngineTestCase {
void test_exitScope_noScopes() {
TypeOverrideManager manager = new TypeOverrideManager();