@@ -742,6 +742,12 @@ class DeclarationHelper {
742742 isNotImported: false ,
743743 );
744744 for (var element in namespace.definedNames2.values) {
745+ if (! visibilityTracker.isVisible (
746+ element: element,
747+ importData: importData,
748+ )) {
749+ continue ;
750+ }
745751 switch (element) {
746752 case ClassElement ():
747753 _suggestConstructors (
@@ -947,9 +953,6 @@ class DeclarationHelper {
947953 /// Adds suggestions for any constructors that are imported into the
948954 /// [library] .
949955 void _addImportedConstructors (LibraryElement library) {
950- // TODO(brianwilkerson): This will create suggestions for elements that
951- // conflict with different elements imported from a different library. Not
952- // sure whether that's the desired behavior.
953956 for (var importElement in library.firstFragment.libraryImports) {
954957 var importedLibrary = importElement.importedLibrary;
955958 if (importedLibrary != null ) {
@@ -1793,7 +1796,6 @@ class DeclarationHelper {
17931796 element.constructors,
17941797 importData,
17951798 allowNonFactory: ! element.isAbstract,
1796- checkVisibility: false ,
17971799 );
17981800 }
17991801 }
@@ -1804,7 +1806,6 @@ class DeclarationHelper {
18041806 required ImportData ? importData,
18051807 required bool hasClassName,
18061808 required bool isConstructorRedirect,
1807- bool checkVisibility = true ,
18081809 }) {
18091810 if (mustBeAssignable) {
18101811 return ;
@@ -1813,29 +1814,20 @@ class DeclarationHelper {
18131814 if (! element.isVisibleIn (request.libraryElement)) {
18141815 return ;
18151816 }
1816- if (importData? .isNotImported ?? false ) {
1817- if (checkVisibility &&
1818- ! visibilityTracker.isVisible (
1819- element: element.enclosingElement,
1820- importData: importData,
1821- )) {
1822- // If the constructor is on a class from a not-yet-imported library and
1823- // the class isn't visible, then we shouldn't suggest it.
1824- //
1825- // We could consider computing a prefix and updating the [importData] in
1826- // order to avoid the collision, but we don't currently do that for any
1827- // not-yet-imported elements (nor for imported elements that are
1828- // shadowed by local declarations).
1829- return ;
1830- }
1831- } else {
1832- // Add the class to the visibility tracker so that we will know later that
1833- // any non-imported elements with the same name are not visible.
1834- visibilityTracker.isVisible (
1835- element: element.enclosingElement,
1836- importData: importData,
1837- );
1838- }
1817+ // If the constructor is on a class from a not-yet-imported library and
1818+ // the class isn't visible, then we shouldn't suggest it.
1819+ //
1820+ // We could consider computing a prefix and updating the [importData] in
1821+ // order to avoid the collision, but we don't currently do that for any
1822+ // not-yet-imported elements (nor for imported elements that are
1823+ // shadowed by local declarations).
1824+
1825+ // Add the class to the visibility tracker so that we will know later that
1826+ // any non-imported elements with the same name are not visible.
1827+ visibilityTracker.isVisible (
1828+ element: element.enclosingElement,
1829+ importData: importData,
1830+ );
18391831
18401832 // Use the constructor element's name without the interface type to
18411833 // calculate the matcher score for dot shorthands.
@@ -1868,23 +1860,10 @@ class DeclarationHelper {
18681860 List <ConstructorElement > constructors,
18691861 ImportData ? importData, {
18701862 bool allowNonFactory = true ,
1871- bool checkVisibility = true ,
18721863 }) {
18731864 if (mustBeAssignable) {
18741865 return ;
18751866 }
1876- if (checkVisibility &&
1877- constructors.isNotEmpty &&
1878- ! visibilityTracker.isVisible (
1879- element: constructors.first.enclosingElement,
1880- importData: importData,
1881- )) {
1882- return ;
1883- }
1884-
1885- if (checkVisibility) {
1886- checkVisibility = false ;
1887- }
18881867
18891868 for (var constructor in constructors) {
18901869 if (constructor.isVisibleIn (request.libraryElement) &&
@@ -1894,7 +1873,6 @@ class DeclarationHelper {
18941873 hasClassName: false ,
18951874 importData: importData,
18961875 isConstructorRedirect: false ,
1897- checkVisibility: checkVisibility,
18981876 );
18991877 }
19001878 }
@@ -1972,11 +1950,7 @@ class DeclarationHelper {
19721950 }
19731951 if (! mustBeType) {
19741952 _suggestStaticFields (element.fields, importData);
1975- _suggestConstructors (
1976- element.constructors,
1977- importData,
1978- checkVisibility: false ,
1979- );
1953+ _suggestConstructors (element.constructors, importData);
19801954 }
19811955 }
19821956 }
0 commit comments