@@ -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 */
0 commit comments