Skip to content

Commit ddcb8b7

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
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>
1 parent 76091c1 commit ddcb8b7

File tree

2 files changed

+0
-271
lines changed

2 files changed

+0
-271
lines changed

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 0 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -7849,175 +7849,6 @@ abstract class ScopedVisitor extends UnifyingAstVisitor<Object> {
78497849
}
78507850
}
78517851

7852-
/**
7853-
* Instances of this class manage the knowledge of what the set of subtypes are for a given type.
7854-
*/
7855-
class SubtypeManager {
7856-
/**
7857-
* A map between [ClassElement]s and a set of [ClassElement]s that are subtypes of the
7858-
* key.
7859-
*/
7860-
Map<ClassElement, HashSet<ClassElement>> _subtypeMap =
7861-
new HashMap<ClassElement, HashSet<ClassElement>>();
7862-
7863-
/**
7864-
* The set of all [LibraryElement]s that have been visited by the manager. This is used both
7865-
* to prevent infinite loops in the recursive methods, and also as a marker for the scope of the
7866-
* libraries visited by this manager.
7867-
*/
7868-
HashSet<LibraryElement> _visitedLibraries = new HashSet<LibraryElement>();
7869-
7870-
/**
7871-
* Given some [ClassElement], return the set of all subtypes, and subtypes of subtypes.
7872-
*
7873-
* @param classElement the class to recursively return the set of subtypes of
7874-
*/
7875-
HashSet<ClassElement> computeAllSubtypes(ClassElement classElement) {
7876-
// Ensure that we have generated the subtype map for the library
7877-
_computeSubtypesInLibrary(classElement.library);
7878-
// use the subtypeMap to compute the set of all subtypes and subtype's
7879-
// subtypes
7880-
HashSet<ClassElement> allSubtypes = new HashSet<ClassElement>();
7881-
_safelyComputeAllSubtypes(
7882-
classElement, new HashSet<ClassElement>(), allSubtypes);
7883-
return allSubtypes;
7884-
}
7885-
7886-
/**
7887-
* Given some [LibraryElement], visit all of the types in the library, the passed library,
7888-
* and any imported libraries, will be in the [visitedLibraries] set.
7889-
*
7890-
* @param libraryElement the library to visit, it it hasn't been visited already
7891-
*/
7892-
void ensureLibraryVisited(LibraryElement libraryElement) {
7893-
_computeSubtypesInLibrary(libraryElement);
7894-
}
7895-
7896-
/**
7897-
* Given some [ClassElement], this method adds all of the pairs combinations of itself and
7898-
* all of its supertypes to the [subtypeMap] map.
7899-
*
7900-
* @param classElement the class element
7901-
*/
7902-
void _computeSubtypesInClass(ClassElement classElement) {
7903-
InterfaceType supertypeType = classElement.supertype;
7904-
if (supertypeType != null) {
7905-
ClassElement supertypeElement = supertypeType.element;
7906-
if (supertypeElement != null) {
7907-
_putInSubtypeMap(supertypeElement, classElement);
7908-
}
7909-
}
7910-
List<InterfaceType> interfaceTypes = classElement.interfaces;
7911-
int interfaceLength = interfaceTypes.length;
7912-
for (int i = 0; i < interfaceLength; i++) {
7913-
InterfaceType interfaceType = interfaceTypes[i];
7914-
ClassElement interfaceElement = interfaceType.element;
7915-
if (interfaceElement != null) {
7916-
_putInSubtypeMap(interfaceElement, classElement);
7917-
}
7918-
}
7919-
List<InterfaceType> mixinTypes = classElement.mixins;
7920-
int mixinLength = mixinTypes.length;
7921-
for (int i = 0; i < mixinLength; i++) {
7922-
InterfaceType mixinType = mixinTypes[i];
7923-
ClassElement mixinElement = mixinType.element;
7924-
if (mixinElement != null) {
7925-
_putInSubtypeMap(mixinElement, classElement);
7926-
}
7927-
}
7928-
}
7929-
7930-
/**
7931-
* Given some [CompilationUnitElement], this method calls
7932-
* [computeAllSubtypes] on all of the [ClassElement]s in the
7933-
* compilation unit.
7934-
*
7935-
* @param unitElement the compilation unit element
7936-
*/
7937-
void _computeSubtypesInCompilationUnit(CompilationUnitElement unitElement) {
7938-
List<ClassElement> classElements = unitElement.types;
7939-
int length = classElements.length;
7940-
for (int i = 0; i < length; i++) {
7941-
ClassElement classElement = classElements[i];
7942-
_computeSubtypesInClass(classElement);
7943-
}
7944-
}
7945-
7946-
/**
7947-
* Given some [LibraryElement], this method calls
7948-
* [computeAllSubtypes] on all of the [ClassElement]s in the
7949-
* compilation unit, and itself for all imported and exported libraries. All visited libraries are
7950-
* added to the [visitedLibraries] set.
7951-
*
7952-
* @param libraryElement the library element
7953-
*/
7954-
void _computeSubtypesInLibrary(LibraryElement libraryElement) {
7955-
if (libraryElement == null || _visitedLibraries.contains(libraryElement)) {
7956-
return;
7957-
}
7958-
_visitedLibraries.add(libraryElement);
7959-
_computeSubtypesInCompilationUnit(libraryElement.definingCompilationUnit);
7960-
List<CompilationUnitElement> parts = libraryElement.parts;
7961-
int partLength = parts.length;
7962-
for (int i = 0; i < partLength; i++) {
7963-
CompilationUnitElement part = parts[i];
7964-
_computeSubtypesInCompilationUnit(part);
7965-
}
7966-
List<LibraryElement> imports = libraryElement.importedLibraries;
7967-
int importLength = imports.length;
7968-
for (int i = 0; i < importLength; i++) {
7969-
LibraryElement importElt = imports[i];
7970-
_computeSubtypesInLibrary(importElt.library);
7971-
}
7972-
List<LibraryElement> exports = libraryElement.exportedLibraries;
7973-
int exportLength = exports.length;
7974-
for (int i = 0; i < exportLength; i++) {
7975-
LibraryElement exportElt = exports[i];
7976-
_computeSubtypesInLibrary(exportElt.library);
7977-
}
7978-
}
7979-
7980-
/**
7981-
* Add some key/ value pair into the [subtypeMap] map.
7982-
*
7983-
* @param supertypeElement the key for the [subtypeMap] map
7984-
* @param subtypeElement the value for the [subtypeMap] map
7985-
*/
7986-
void _putInSubtypeMap(
7987-
ClassElement supertypeElement, ClassElement subtypeElement) {
7988-
HashSet<ClassElement> subtypes = _subtypeMap[supertypeElement];
7989-
if (subtypes == null) {
7990-
subtypes = new HashSet<ClassElement>();
7991-
_subtypeMap[supertypeElement] = subtypes;
7992-
}
7993-
subtypes.add(subtypeElement);
7994-
}
7995-
7996-
/**
7997-
* Given some [ClassElement] and a [HashSet<ClassElement>], this method recursively
7998-
* adds all of the subtypes of the [ClassElement] to the passed array.
7999-
*
8000-
* @param classElement the type to compute the set of subtypes of
8001-
* @param visitedClasses the set of class elements that this method has already recursively seen
8002-
* @param allSubtypes the computed set of subtypes of the passed class element
8003-
*/
8004-
void _safelyComputeAllSubtypes(ClassElement classElement,
8005-
HashSet<ClassElement> visitedClasses, HashSet<ClassElement> allSubtypes) {
8006-
if (!visitedClasses.add(classElement)) {
8007-
// if this class has already been called on this class element
8008-
return;
8009-
}
8010-
HashSet<ClassElement> subtypes = _subtypeMap[classElement];
8011-
if (subtypes == null) {
8012-
return;
8013-
}
8014-
for (ClassElement subtype in subtypes) {
8015-
_safelyComputeAllSubtypes(subtype, visitedClasses, allSubtypes);
8016-
}
8017-
allSubtypes.addAll(subtypes);
8018-
}
8019-
}
8020-
80217852
/**
80227853
* Instances of the class `ToDoFinder` find to-do comments in Dart code.
80237854
*/

pkg/analyzer/test/generated/resolver_test.dart

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ main() {
4949
defineReflectiveTests(PrefixedNamespaceTest);
5050
defineReflectiveTests(ScopeTest);
5151
defineReflectiveTests(StrictModeTest);
52-
defineReflectiveTests(SubtypeManagerTest);
5352
defineReflectiveTests(TypeOverrideManagerTest);
5453
defineReflectiveTests(TypePropagationTest);
5554
defineReflectiveTests(TypeProviderImplTest);
@@ -751,107 +750,6 @@ int f() {
751750
}
752751
}
753752

754-
@reflectiveTest
755-
class SubtypeManagerTest {
756-
/**
757-
* The inheritance manager being tested.
758-
*/
759-
SubtypeManager _subtypeManager;
760-
761-
/**
762-
* The compilation unit element containing all of the types setup in each test.
763-
*/
764-
CompilationUnitElementImpl _definingCompilationUnit;
765-
766-
void setUp() {
767-
MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
768-
AnalysisContext context = AnalysisContextFactory.contextWithCore(
769-
resourceProvider: resourceProvider);
770-
Source source = new FileSource(resourceProvider.getFile("/test.dart"));
771-
_definingCompilationUnit = new CompilationUnitElementImpl("test.dart");
772-
_definingCompilationUnit.librarySource =
773-
_definingCompilationUnit.source = source;
774-
LibraryElementImpl definingLibrary =
775-
ElementFactory.library(context, "test");
776-
definingLibrary.definingCompilationUnit = _definingCompilationUnit;
777-
_subtypeManager = new SubtypeManager();
778-
}
779-
780-
void test_computeAllSubtypes_infiniteLoop() {
781-
//
782-
// class A extends B
783-
// class B extends A
784-
//
785-
ClassElementImpl classA = ElementFactory.classElement2("A");
786-
ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
787-
classA.supertype = classB.type;
788-
_definingCompilationUnit.types = <ClassElement>[classA, classB];
789-
HashSet<ClassElement> subtypesOfA =
790-
_subtypeManager.computeAllSubtypes(classA);
791-
List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
792-
expect(subtypesOfA, hasLength(2));
793-
expect(arraySubtypesOfA, unorderedEquals([classA, classB]));
794-
}
795-
796-
void test_computeAllSubtypes_manyRecursiveSubtypes() {
797-
//
798-
// class A
799-
// class B extends A
800-
// class C extends B
801-
// class D extends B
802-
// class E extends B
803-
//
804-
ClassElementImpl classA = ElementFactory.classElement2("A");
805-
ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
806-
ClassElementImpl classC = ElementFactory.classElement("C", classB.type);
807-
ClassElementImpl classD = ElementFactory.classElement("D", classB.type);
808-
ClassElementImpl classE = ElementFactory.classElement("E", classB.type);
809-
_definingCompilationUnit.types = <ClassElement>[
810-
classA,
811-
classB,
812-
classC,
813-
classD,
814-
classE
815-
];
816-
HashSet<ClassElement> subtypesOfA =
817-
_subtypeManager.computeAllSubtypes(classA);
818-
List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
819-
HashSet<ClassElement> subtypesOfB =
820-
_subtypeManager.computeAllSubtypes(classB);
821-
List<ClassElement> arraySubtypesOfB = new List.from(subtypesOfB);
822-
expect(subtypesOfA, hasLength(4));
823-
expect(arraySubtypesOfA, unorderedEquals([classB, classC, classD, classE]));
824-
expect(subtypesOfB, hasLength(3));
825-
expect(arraySubtypesOfB, unorderedEquals([classC, classD, classE]));
826-
}
827-
828-
void test_computeAllSubtypes_noSubtypes() {
829-
//
830-
// class A
831-
//
832-
ClassElementImpl classA = ElementFactory.classElement2("A");
833-
_definingCompilationUnit.types = <ClassElement>[classA];
834-
HashSet<ClassElement> subtypesOfA =
835-
_subtypeManager.computeAllSubtypes(classA);
836-
expect(subtypesOfA, hasLength(0));
837-
}
838-
839-
void test_computeAllSubtypes_oneSubtype() {
840-
//
841-
// class A
842-
// class B extends A
843-
//
844-
ClassElementImpl classA = ElementFactory.classElement2("A");
845-
ClassElementImpl classB = ElementFactory.classElement("B", classA.type);
846-
_definingCompilationUnit.types = <ClassElement>[classA, classB];
847-
HashSet<ClassElement> subtypesOfA =
848-
_subtypeManager.computeAllSubtypes(classA);
849-
List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
850-
expect(subtypesOfA, hasLength(1));
851-
expect(arraySubtypesOfA, unorderedEquals([classB]));
852-
}
853-
}
854-
855753
@reflectiveTest
856754
class TypeOverrideManagerTest extends EngineTestCase {
857755
void test_exitScope_noScopes() {

0 commit comments

Comments
 (0)