diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart index 38b40fe703ab..578f72b6b0b4 100644 --- a/pkg/analyzer/lib/src/dart/analysis/driver.dart +++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart @@ -99,7 +99,7 @@ import 'package:meta/meta.dart'; // TODO(scheglov): Clean up the list of implicitly analyzed files. class AnalysisDriver { /// The version of data format, should be incremented on every format change. - static const int DATA_VERSION = 425; + static const int DATA_VERSION = 426; /// The number of exception contexts allowed to write. Once this field is /// zero, we stop writing any new exception contexts in this process. @@ -1374,6 +1374,17 @@ class AnalysisDriver { }, ); + for (var import in library.docImports) { + if (import is LibraryImportWithFile) { + if (import.importedLibrary case var libraryFileKind?) { + await libraryContext.load( + targetLibrary: libraryFileKind, + performance: OperationPerformanceImpl(''), + ); + } + } + } + var analysisOptions = file.analysisOptions; var libraryElement = libraryContext.elementFactory.libraryOfUri2(library.file.uri); diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart index 7bf9c52bc8f5..c3e0b7f90880 100644 --- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart +++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart @@ -204,7 +204,7 @@ abstract class FileKind { List? _libraryExports; List? _libraryImports; List? _partIncludes; - List? _docLibraryImports; + List? _docImports; FileKind({ required this.file, @@ -223,12 +223,12 @@ abstract class FileKind { } /// The import states of each `@docImport` on the library directive. - List get docLibraryImports { - if (_docLibraryImports case var existing?) { + List get docImports { + if (_docImports case var existing?) { return existing; } - return _docLibraryImports = + return _docImports = _unlinkedDocImports.map(_buildLibraryImportState).toFixedList(); } @@ -382,7 +382,7 @@ abstract class FileKind { libraryExports; libraryImports; partIncludes; - docLibraryImports; + docImports; } @mustCallSuper @@ -392,7 +392,7 @@ abstract class FileKind { _libraryExports?.disposeAll(); _libraryImports?.disposeAll(); _partIncludes?.disposeAll(); - _docLibraryImports?.disposeAll(); + _docImports?.disposeAll(); } /// Dispose the containing [LibraryFileKind] cycle. diff --git a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart index 2bde88fb3dfe..f987a76cff9f 100644 --- a/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart +++ b/pkg/analyzer/lib/src/dart/analysis/library_analyzer.dart @@ -185,7 +185,6 @@ class LibraryAnalyzer { ScopeResolverVisitor( fileAnalysis.errorReporter, nameScope: unitElement.scope, - unitElement: unitElement, ), ); @@ -821,7 +820,7 @@ class LibraryAnalyzer { for (var i = 0; i < docImports.length; i++) { _resolveLibraryDocImportDirective( directive: docImports[i].import as ImportDirectiveImpl, - state: fileKind.docLibraryImports[i], + state: fileKind.docImports[i], errorReporter: containerErrorReporter, ); } @@ -855,10 +854,16 @@ class LibraryAnalyzer { _testingData?.recordTypeConstraintGenerationDataForTesting( fileAnalysis.file.uri, inferenceDataForTesting!); + var docImportLibraries = [ + for (var import in _library.docImports) + if (import is LibraryImportWithFile) + _libraryElement.session.elementFactory + .libraryOfUri2(import.importedFile.uri) + ]; unit.accept(ScopeResolverVisitor( fileAnalysis.errorReporter, nameScope: unitElement.scope, - unitElement: unitElement, + docImportLibraries: docImportLibraries, )); // Nothing for RESOLVED_UNIT8? diff --git a/pkg/analyzer/lib/src/dart/analysis/library_graph.dart b/pkg/analyzer/lib/src/dart/analysis/library_graph.dart index 50b3be2dd97c..a4de13384384 100644 --- a/pkg/analyzer/lib/src/dart/analysis/library_graph.dart +++ b/pkg/analyzer/lib/src/dart/analysis/library_graph.dart @@ -195,9 +195,6 @@ class _LibraryNode extends graph.Node<_LibraryNode> { ...fileKind.libraryExports .whereType() .map((export) => export.exportedLibrary), - ...fileKind.docLibraryImports - .whereType() - .map((import) => import.importedLibrary), ]; }) .flattenedToList diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart index acf5f3b11e14..52fde6f5dd42 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -781,19 +781,12 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl List _libraryImports = _Sentinel.libraryImportElement; - /// The libraries imported by this unit with a `@docImport`. - List _docLibraryImports = - _Sentinel.libraryImportElement; - /// The cached list of prefixes from [libraryImports]. List? _libraryImportPrefixes; /// The cached list of prefixes from [prefixes]. List? _libraryImportPrefixes2; - /// The cached list of prefixes from [docLibraryImports]. - List? _docLibraryImportPrefixes; - /// The parts included by this unit. List _parts = const []; @@ -906,23 +899,6 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl @override List get classes2 => classes.cast(); - List get docLibraryImportPrefixes { - return _docLibraryImportPrefixes ??= _buildDocLibraryImportPrefixes(); - } - - List get docLibraryImports { - linkedData?.read(this); - return _docLibraryImports; - } - - set docLibraryImports(List imports) { - _docLibraryImports = imports; - } - - List get docLibraryImports_unresolved { - return _docLibraryImports; - } - @override LibraryElementImpl get element => library; @@ -1323,17 +1299,6 @@ class CompilationUnitElementImpl extends UriReferencedElementImpl ); } - List _buildDocLibraryImportPrefixes() { - var prefixes = {}; - for (var import in docLibraryImports) { - var prefix = import.prefix2?.element; - if (prefix is PrefixElementImpl2) { - prefixes.add(prefix); - } - } - return prefixes.toFixedList(); - } - List _buildLibraryImportPrefixes() { var prefixes = {}; for (var import in libraryImports) { @@ -9414,13 +9379,9 @@ class PrefixElementImpl extends _ExistingElementImpl implements PrefixElement { /// The scope of this prefix, `null` if not set yet. PrefixScope? _scope; - final bool _isDocLibraryImport; - /// Initialize a newly created method element to have the given [name] and /// [nameOffset]. - PrefixElementImpl(String super.name, super.nameOffset, - {super.reference, required bool isDocLibraryImport}) - : _isDocLibraryImport = isDocLibraryImport; + PrefixElementImpl(String super.name, super.nameOffset, {super.reference}); @override List get children2 => const []; @@ -9429,15 +9390,9 @@ class PrefixElementImpl extends _ExistingElementImpl implements PrefixElement { String get displayName => name; PrefixElementImpl2 get element2 { - if (_isDocLibraryImport) { - return enclosingElement3.docLibraryImportPrefixes.firstWhere((element) { - return (element.name3 ?? '') == name; - }); - } else { - return enclosingElement3.prefixes.firstWhere((element) { - return (element.name3 ?? '') == name; - }); - } + return enclosingElement3.prefixes.firstWhere((element) { + return (element.name3 ?? '') == name; + }); } @override @@ -9495,14 +9450,10 @@ class PrefixElementImpl2 extends ElementImpl2 implements PrefixElement2 { PrefixFragmentImpl lastFragment; - final bool _isDocLibraryImport; - PrefixElementImpl2({ required this.reference, required this.firstFragment, - required bool isDocLibraryImport, - }) : lastFragment = firstFragment, - _isDocLibraryImport = isDocLibraryImport { + }) : lastFragment = firstFragment { reference.element2 = this; } @@ -9524,15 +9475,9 @@ class PrefixElementImpl2 extends ElementImpl2 implements PrefixElement2 { @override List get imports { - if (_isDocLibraryImport) { - return firstFragment.enclosingFragment.docLibraryImports - .where((import) => import.prefix2?.element == this) - .toList(); - } else { - return firstFragment.enclosingFragment.libraryImports - .where((import) => import.prefix2?.element == this) - .toList(); - } + return firstFragment.enclosingFragment.libraryImports + .where((import) => import.prefix2?.element == this) + .toList(); } @override diff --git a/pkg/analyzer/lib/src/dart/element/scope.dart b/pkg/analyzer/lib/src/dart/element/scope.dart index db17e38a6c80..b807e3072448 100644 --- a/pkg/analyzer/lib/src/dart/element/scope.dart +++ b/pkg/analyzer/lib/src/dart/element/scope.dart @@ -2,9 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/// @docImport 'package:analyzer/src/generated/resolver.dart'; -library; - import 'package:_fe_analyzer_shared/src/scanner/string_canonicalizer.dart'; import 'package:analyzer/dart/analysis/features.dart'; import 'package:analyzer/dart/element/element.dart'; @@ -30,58 +27,32 @@ class ConstructorInitializerScope extends EnclosedScope { } } -/// The scope that looks up elements in documentation comments. +/// The scope that looks up elements in doc imports. /// /// Attempts to look up elements in its [innerScope] before searching -/// through any doc imports. -class DocumentationCommentScope implements Scope { +/// through the doc imports. +class DocImportScope with _GettersAndSetters implements Scope { /// The scope that will be prioritized in look ups before searching in doc /// imports. /// - /// Will be set for each specific comment scope in the [ScopeResolverVisitor]. + /// Will be set for each specific comment scope in the `ScopeResolverVisitor`. Scope innerScope; - final LibraryFragmentScope? _parent; - - final CompilationUnitElementImpl _fragment; - - final PrefixScope _noPrefixScope; - - final Map _prefixElements = {}; - - factory DocumentationCommentScope( - Scope innerScope, CompilationUnitElementImpl fragment) { - var parent = fragment.enclosingElement3?.scope; - return DocumentationCommentScope._( - innerScope: innerScope, - parent: parent, - fragment: fragment, - noPrefixScope: PrefixScope( - libraryFragment: fragment, - parent: parent?._noPrefixScope, - libraryImports: fragment.docLibraryImports, - prefix: null, - ), - ); - } - - DocumentationCommentScope._({ - required this.innerScope, - required LibraryFragmentScope? parent, - required CompilationUnitElementImpl fragment, - required PrefixScope noPrefixScope, - }) : _parent = parent, - _fragment = fragment, - _noPrefixScope = noPrefixScope { - for (var prefix in fragment.docLibraryImportPrefixes) { - var prefix1 = prefix.asElement; - _prefixElements[prefix1.name] = prefix; - prefix1.scope = PrefixScope( - libraryFragment: fragment, - parent: _getParentPrefixScope(prefix1), - libraryImports: fragment.docLibraryImports, - prefix: prefix1, - ); + DocImportScope(this.innerScope, List docImportLibraries) { + for (var importedLibrary in docImportLibraries) { + if (importedLibrary is LibraryElementImpl) { + // TODO(kallentu): Handle combinators. + for (var exportedReference in importedLibrary.exportedReferences) { + var reference = exportedReference.reference; + var element = importedLibrary.session.elementFactory + .elementOfReference(reference)!; + if (element is PropertyAccessorElement && element.isSetter) { + _addSetter(element); + } else { + _addGetter(element); + } + } + } } } @@ -89,50 +60,10 @@ class DocumentationCommentScope implements Scope { ScopeLookupResult lookup(String id) { var result = innerScope.lookup(id); if (result.getter != null || result.setter != null) return result; - - // Try the combined import scope. - var importResult = _lookupCombined(id); - if (importResult != null) { - return importResult; - } - - // No result. - return ScopeLookupResultImpl(getter: null, setter: null); - } - - PrefixScope? _getParentPrefixScope(PrefixElementImpl prefix) { - var isDeferred = prefix.imports - .any((import) => import.prefix is DeferredImportElementPrefix); - if (isDeferred) { - return null; - } - - for (var scope = _parent; scope != null; scope = scope._parent) { - var parentPrefix = scope._prefixElements[prefix.name]; - if (parentPrefix != null) { - return parentPrefix.scope; - } - } - return null; - } - - ScopeLookupResult? _lookupCombined(String id) { - // Try prefix elements. - if (_fragment.isAllowedAsPrefixElement(id)) { - if (_prefixElements[id] case var prefixElement?) { - var prefix1 = prefixElement.asElement; - return ScopeLookupResultImpl(getter: prefix1, setter: null); - } - } - - // Try imports of the library fragment. - var noPrefixResult = _noPrefixScope.lookup(id); - if (noPrefixResult.getter != null || noPrefixResult.setter != null) { - return noPrefixResult; - } - - // Try the parent's combined import scope. - return _parent?._lookupCombined(id); + return ScopeLookupResultImpl( + getter: _getters[id], + setter: _setters[id], + ); } } @@ -404,9 +335,9 @@ class LibraryDeclarations with _GettersAndSetters { } class LibraryFragmentScope implements Scope { - final LibraryFragmentScope? _parent; - final CompilationUnitElementImpl _fragment; - final PrefixScope _noPrefixScope; + final LibraryFragmentScope? parent; + final CompilationUnitElementImpl fragment; + final PrefixScope noPrefixScope; final Map _prefixElements = {}; @@ -428,7 +359,7 @@ class LibraryFragmentScope implements Scope { fragment: fragment, noPrefixScope: PrefixScope( libraryFragment: fragment, - parent: parent?._noPrefixScope, + parent: parent?.noPrefixScope, libraryImports: fragment.libraryImports, prefix: null, ), @@ -436,31 +367,29 @@ class LibraryFragmentScope implements Scope { } LibraryFragmentScope._({ - required LibraryFragmentScope? parent, - required CompilationUnitElementImpl fragment, - required PrefixScope noPrefixScope, - }) : _parent = parent, - _fragment = fragment, - _noPrefixScope = noPrefixScope { - for (var prefix in _fragment.libraryImportPrefixes) { + required this.parent, + required this.fragment, + required this.noPrefixScope, + }) { + for (var prefix in fragment.libraryImportPrefixes) { _prefixElements[prefix.name] = prefix; prefix.scope = PrefixScope( libraryFragment: fragment, parent: _getParentPrefixScope(prefix), - libraryImports: _fragment.libraryImports, + libraryImports: fragment.libraryImports, prefix: prefix, ); } } - /// The extensions accessible within [_fragment]. + /// The extensions accessible within [fragment]. List get accessibleExtensions { - var libraryDeclarations = _fragment.library.libraryDeclarations; + var libraryDeclarations = fragment.library.libraryDeclarations; return _extensions ??= { ...libraryDeclarations.extensions, - ..._noPrefixScope._extensions, + ...noPrefixScope._extensions, for (var prefix in _prefixElements.values) ...prefix.scope._extensions, - ...?_parent?.accessibleExtensions, + ...?parent?.accessibleExtensions, }.toFixedList(); } @@ -476,7 +405,7 @@ class LibraryFragmentScope implements Scope { } void importsTrackingDestroy() { - _noPrefixScope.importsTrackingDestroy(); + noPrefixScope.importsTrackingDestroy(); for (var prefixElement in _prefixElements.values) { prefixElement.scope.importsTrackingDestroy(); } @@ -486,7 +415,7 @@ class LibraryFragmentScope implements Scope { ImportsTracking importsTrackingInit() { return _importsTracking = ImportsTracking( map: { - null: _noPrefixScope.importsTrackingInit(), + null: noPrefixScope.importsTrackingInit(), for (var prefixElement in _prefixElements.values) prefixElement: prefixElement.scope.importsTrackingInit(), }, @@ -525,7 +454,7 @@ class LibraryFragmentScope implements Scope { return null; } - for (var scope = _parent; scope != null; scope = scope._parent) { + for (var scope = parent; scope != null; scope = scope.parent) { var parentPrefix = scope._prefixElements[prefix.name]; if (parentPrefix != null) { return parentPrefix.scope; @@ -536,7 +465,7 @@ class LibraryFragmentScope implements Scope { ScopeLookupResult? _lookupCombined(String id) { // Try prefix elements. - if (_fragment.isAllowedAsPrefixElement(id)) { + if (_shouldTryPrefixElement(id)) { if (_prefixElements[id] case var prefixElement?) { return ScopeLookupResultImpl( getter: prefixElement, @@ -546,17 +475,17 @@ class LibraryFragmentScope implements Scope { } // Try imports of the library fragment. - var noPrefixResult = _noPrefixScope.lookup(id); + var noPrefixResult = noPrefixScope.lookup(id); if (noPrefixResult.getter != null || noPrefixResult.setter != null) { return noPrefixResult; } // Try the parent's combined import scope. - return _parent?._lookupCombined(id); + return parent?._lookupCombined(id); } ScopeLookupResult? _lookupLibrary(String id) { - var libraryDeclarations = _fragment.library.libraryDeclarations; + var libraryDeclarations = fragment.library.libraryDeclarations; var libraryGetter = libraryDeclarations._getters[id]; var librarySetter = libraryDeclarations._setters[id]; if (libraryGetter != null || librarySetter != null) { @@ -567,6 +496,14 @@ class LibraryFragmentScope implements Scope { } return null; } + + bool _shouldTryPrefixElement(String id) { + if (id == '_') { + var featureSet = fragment.library.featureSet; + return !featureSet.isEnabled(Feature.wildcard_variables); + } + return true; + } } class LocalScope extends EnclosedScope { @@ -886,15 +823,3 @@ mixin _GettersAndSetters { } } } - -extension on CompilationUnitElementImpl { - /// Whether we should try to resolve an element via a prefix named '_' (which - /// depends on whether the 'wildcard-variables' feature is enabled). - bool isAllowedAsPrefixElement(String id) { - if (id == '_') { - var featureSet = library.featureSet; - return !featureSet.isEnabled(Feature.wildcard_variables); - } - return true; - } -} diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart index 5149e927c913..c020b9695bb2 100644 --- a/pkg/analyzer/lib/src/generated/resolver.dart +++ b/pkg/analyzer/lib/src/generated/resolver.dart @@ -4522,7 +4522,7 @@ class ScopeResolverVisitor extends UnifyingAstVisitor { Scope nameScope; /// The scope of libraries imported by `@docImport`s. - final DocumentationCommentScope _docImportScope; + final DocImportScope _docImportScope; /// The scope used to resolve unlabeled `break` and `continue` statements. ImplicitLabelScope _implicitLabelScope = ImplicitLabelScope.ROOT; @@ -4548,8 +4548,8 @@ class ScopeResolverVisitor extends UnifyingAstVisitor { ScopeResolverVisitor( this.errorReporter, { required this.nameScope, - required CompilationUnitElementImpl unitElement, - }) : _docImportScope = DocumentationCommentScope(nameScope, unitElement); + List docImportLibraries = const [], + }) : _docImportScope = DocImportScope(nameScope, docImportLibraries); /// Return the implicit label scope in which the current node is being /// resolved. @@ -5407,7 +5407,7 @@ class ScopeResolverVisitor extends UnifyingAstVisitor { } } - /// Visits a documentation comment with a [DocumentationCommentScope] that encloses the + /// Visits a documentation comment with a [DocImportScope] that encloses the /// current [nameScope]. void _visitDocumentationComment(CommentImpl? node) { if (node == null) return; diff --git a/pkg/analyzer/lib/src/generated/testing/element_factory.dart b/pkg/analyzer/lib/src/generated/testing/element_factory.dart index e265bbe12dd5..61e0852af339 100644 --- a/pkg/analyzer/lib/src/generated/testing/element_factory.dart +++ b/pkg/analyzer/lib/src/generated/testing/element_factory.dart @@ -302,8 +302,7 @@ class ElementFactory { return parameter; } - static PrefixElementImpl prefix(String name) => - PrefixElementImpl(name, 0, isDocLibraryImport: false); + static PrefixElementImpl prefix(String name) => PrefixElementImpl(name, 0); static ParameterElementImpl requiredParameter(String name) { return ParameterElementImpl( diff --git a/pkg/analyzer/lib/src/summary2/ast_resolver.dart b/pkg/analyzer/lib/src/summary2/ast_resolver.dart index b8eef05e10b9..dcdf5feb81f1 100644 --- a/pkg/analyzer/lib/src/summary2/ast_resolver.dart +++ b/pkg/analyzer/lib/src/summary2/ast_resolver.dart @@ -40,7 +40,6 @@ class AstResolver { late final _scopeResolverVisitor = ScopeResolverVisitor( ErrorReporter(_errorListener, _unitElement.source), nameScope: _nameScope, - unitElement: _unitElement, ); late final _flowAnalysis = FlowAnalysisHelper(false, _featureSet, typeSystemOperations: TypeSystemOperations( diff --git a/pkg/analyzer/lib/src/summary2/bundle_reader.dart b/pkg/analyzer/lib/src/summary2/bundle_reader.dart index 7b77438c8f68..e778690fd3f8 100644 --- a/pkg/analyzer/lib/src/summary2/bundle_reader.dart +++ b/pkg/analyzer/lib/src/summary2/bundle_reader.dart @@ -198,13 +198,6 @@ class CompilationUnitElementLinkedData ); } - for (var import in element.docLibraryImports) { - var uri = import.uri; - if (uri is DirectiveUriWithLibraryImpl) { - uri.library = reader.libraryOfUri(uri.source.uri); - } - } - applyConstantOffsets?.perform(); } } @@ -1226,20 +1219,19 @@ class LibraryReader { LibraryImportElementImpl _readImportElement({ required CompilationUnitElementImpl containerUnit, - required bool isDocLibraryImport, }) { var element = LibraryImportElementImpl( combinators: _reader.readTypedList(_readNamespaceCombinator), importKeywordOffset: -1, prefix: _readImportElementPrefix( containerUnit: containerUnit, - isDocLibraryImport: isDocLibraryImport, ), prefix2: _readLibraryImportPrefixFragment( libraryFragment: containerUnit, - isDocLibraryImport: isDocLibraryImport, ), - uri: _readDirectiveUri(containerUnit: containerUnit), + uri: _readDirectiveUri( + containerUnit: containerUnit, + ), ); LibraryImportElementFlags.read(_reader, element); return element; @@ -1247,7 +1239,6 @@ class LibraryReader { ImportElementPrefixImpl? _readImportElementPrefix({ required CompilationUnitElementImpl containerUnit, - required bool isDocLibraryImport, }) { PrefixElementImpl buildElement(String name, Reference reference) { // TODO(scheglov): Make reference required. @@ -1255,12 +1246,7 @@ class LibraryReader { if (existing is PrefixElementImpl) { return existing; } else { - var result = PrefixElementImpl( - name, - -1, - reference: reference, - isDocLibraryImport: isDocLibraryImport, - ); + var result = PrefixElementImpl(name, -1, reference: reference); result.enclosingElement3 = containerUnit; return result; } @@ -1303,7 +1289,6 @@ class LibraryReader { PrefixFragmentImpl? _readLibraryImportPrefixFragment({ required CompilationUnitElementImpl libraryFragment, - required bool isDocLibraryImport, }) { return _reader.readOptionalObject((reader) { var fragmentName = _readFragmentName(); @@ -1321,7 +1306,6 @@ class LibraryReader { element = PrefixElementImpl2( reference: reference, firstFragment: fragment, - isDocLibraryImport: isDocLibraryImport, ); } else { element.addFragment(fragment); @@ -1839,7 +1823,6 @@ class LibraryReader { unitElement.libraryImports = _reader.readTypedList(() { return _readImportElement( containerUnit: unitElement, - isDocLibraryImport: false, ); }); @@ -1849,13 +1832,6 @@ class LibraryReader { ); }); - unitElement.docLibraryImports = _reader.readTypedList(() { - return _readImportElement( - containerUnit: unitElement, - isDocLibraryImport: true, - ); - }); - _readClasses(unitElement, unitReference); _readEnums(unitElement, unitReference); _readExtensions(unitElement, unitReference); diff --git a/pkg/analyzer/lib/src/summary2/bundle_writer.dart b/pkg/analyzer/lib/src/summary2/bundle_writer.dart index 1dc01dc0103e..c2d7a6126efa 100644 --- a/pkg/analyzer/lib/src/summary2/bundle_writer.dart +++ b/pkg/analyzer/lib/src/summary2/bundle_writer.dart @@ -725,7 +725,6 @@ class BundleWriter { // Write the metadata for parts here, even though we write parts below. // The reason is that resolution data must be in a single chunk. _writePartElementsMetadata(unitElement); - _writeList(unitElement.docLibraryImports, _writeImportElement); _writeList(unitElement.classes, _writeClassElement); _writeList(unitElement.enums, _writeEnumElement); diff --git a/pkg/analyzer/lib/src/summary2/informative_data.dart b/pkg/analyzer/lib/src/summary2/informative_data.dart index 2caf51a1d70e..19a45131e085 100644 --- a/pkg/analyzer/lib/src/summary2/informative_data.dart +++ b/pkg/analyzer/lib/src/summary2/informative_data.dart @@ -100,7 +100,6 @@ class InformativeDataApplier { unitElement.setCodeRange(unitInfo.codeOffset, unitInfo.codeLength); unitElement.lineInfo = LineInfo(unitInfo.lineStarts); - _applyToDocImports(unitElement.docLibraryImports_unresolved, unitInfo); _applyToImports(unitElement.libraryImports_unresolved, unitInfo); _applyToExports(unitElement.libraryExports_unresolved, unitInfo); @@ -108,7 +107,6 @@ class InformativeDataApplier { unitInfo.libraryConstantOffsets, (applier) { applier.applyToMetadata(unitElement); - applier.applyToImports(unitElement.docLibraryImports); applier.applyToImports(unitElement.libraryImports); applier.applyToExports(unitElement.libraryExports); applier.applyToParts(unitElement.parts); @@ -339,32 +337,6 @@ class InformativeDataApplier { ); } - void _applyToDocImports( - List imports, - _InfoUnit info, - ) { - forCorrespondingPairs( - imports, - info.docImports, - (element, info) { - element as LibraryImportElementImpl; - element.nameOffset = info.nameOffset; - - var prefixElement = element.prefix?.element; - if (prefixElement is PrefixElementImpl) { - if (prefixElement.nameOffset == -1) { - prefixElement.nameOffset = info.prefixOffset; - } - } - - if (element.prefix2 case var prefixFragment?) { - prefixFragment.nameOffset2 = info.prefixOffset2; - } - _applyToCombinators(element.combinators, info.combinators); - }, - ); - } - void _applyToEnumDeclaration( EnumElement element, _InfoClassDeclaration info, @@ -1464,19 +1436,6 @@ class _InformativeDataWriter { var firstDirective = unit.directives.firstOrNull; _writeDocumentationCommentNode(firstDirective?.documentationComment); - var libraryDirective = - unit.directives.whereType().firstOrNull; - var docImports = libraryDirective?.documentationComment?.docImports; - var docImportDirectives = - docImports?.map((e) => e.import).toList() ?? []; - - sink.writeList2(docImportDirectives, (directive) { - sink.writeUInt30(directive.importKeyword.offset); - sink.writeUInt30(1 + (directive.prefix?.offset ?? -1)); - sink.writeOptionalUInt30(directive.prefix?.token.offsetIfNotEmpty); - _writeCombinators(directive.combinators); - }); - sink.writeList2(unit.directives, (directive) { sink.writeUInt30(directive.importKeyword.offset); sink.writeUInt30(1 + (directive.prefix?.offset ?? -1)); @@ -2068,7 +2027,6 @@ class _InfoUnit { final _InfoLibraryName libraryName; final Uint32List libraryConstantOffsets; final String docComment; - final List<_InfoImport> docImports; final List<_InfoImport> imports; final List<_InfoExport> exports; final List<_InfoPart> parts; @@ -2093,9 +2051,6 @@ class _InfoUnit { libraryName: _InfoLibraryName(reader), libraryConstantOffsets: reader.readUInt30List(), docComment: reader.readStringUtf8(), - docImports: reader.readTypedList( - () => _InfoImport(reader), - ), imports: reader.readTypedList( () => _InfoImport(reader), ), @@ -2148,7 +2103,6 @@ class _InfoUnit { required this.libraryName, required this.libraryConstantOffsets, required this.docComment, - required this.docImports, required this.imports, required this.exports, required this.parts, diff --git a/pkg/analyzer/lib/src/summary2/library_builder.dart b/pkg/analyzer/lib/src/summary2/library_builder.dart index 1415922c8456..1bb119f67b6c 100644 --- a/pkg/analyzer/lib/src/summary2/library_builder.dart +++ b/pkg/analyzer/lib/src/summary2/library_builder.dart @@ -942,7 +942,6 @@ class LibraryBuilder with MacroApplicationsContainer { return _buildLibraryImport( containerUnit: containerUnit, state: state, - isDocLibraryImport: false, ); }).toFixedList(); @@ -953,14 +952,6 @@ class LibraryBuilder with MacroApplicationsContainer { state: partState, ); }).toFixedList(); - - containerUnit.docLibraryImports = kind.docLibraryImports.map((state) { - return _buildLibraryImport( - containerUnit: containerUnit, - state: state, - isDocLibraryImport: true, - ); - }).toFixedList(); } LibraryExportElementImpl _buildLibraryExport(LibraryExportState state) { @@ -1036,14 +1027,12 @@ class LibraryBuilder with MacroApplicationsContainer { LibraryImportElementImpl _buildLibraryImport({ required CompilationUnitElementImpl containerUnit, required LibraryImportState state, - required bool isDocLibraryImport, }) { var importPrefix = state.unlinked.prefix.mapOrNull((unlinked) { var prefix = _buildLibraryImportPrefix( nameOffset: unlinked.nameOffset, name: unlinked.name, containerUnit: containerUnit, - isDocLibraryImport: isDocLibraryImport, ); if (unlinked.deferredOffset != null) { return DeferredImportElementPrefixImpl( @@ -1061,7 +1050,6 @@ class LibraryBuilder with MacroApplicationsContainer { libraryFragment: containerUnit, unlinkedName: unlinked.name, isDeferred: unlinked.deferredOffset != null, - isDocLibraryImport: isDocLibraryImport, ); }); @@ -1140,7 +1128,6 @@ class LibraryBuilder with MacroApplicationsContainer { required int nameOffset, required UnlinkedLibraryImportPrefixName? name, required CompilationUnitElementImpl containerUnit, - required bool isDocLibraryImport, }) { // TODO(scheglov): Make reference required. var containerRef = containerUnit.reference!; @@ -1154,7 +1141,6 @@ class LibraryBuilder with MacroApplicationsContainer { name?.name ?? '', nameOffset, reference: reference, - isDocLibraryImport: isDocLibraryImport, ); result.enclosingElement3 = containerUnit; return result; @@ -1165,7 +1151,6 @@ class LibraryBuilder with MacroApplicationsContainer { required CompilationUnitElementImpl libraryFragment, required UnlinkedLibraryImportPrefixName? unlinkedName, required bool isDeferred, - required bool isDocLibraryImport, }) { var fragment = PrefixFragmentImpl( enclosingFragment: libraryFragment, @@ -1183,7 +1168,6 @@ class LibraryBuilder with MacroApplicationsContainer { element = PrefixElementImpl2( reference: reference, firstFragment: fragment, - isDocLibraryImport: isDocLibraryImport, ); } else { element.addFragment(fragment); diff --git a/pkg/analyzer/test/src/dart/analysis/analyzer_state_printer.dart b/pkg/analyzer/test/src/dart/analysis/analyzer_state_printer.dart index 608846509ee6..18606792a852 100644 --- a/pkg/analyzer/test/src/dart/analysis/analyzer_state_printer.dart +++ b/pkg/analyzer/test/src/dart/analysis/analyzer_state_printer.dart @@ -118,8 +118,8 @@ class AnalyzerStatePrinter { void _writeDocImports(FileKind container) { _writeElements( - 'docLibraryImports', - container.docLibraryImports, + 'docImports', + container.docImports, (import) { expect(import.isDocImport, isTrue); _writeLibraryImport(container, import); diff --git a/pkg/analyzer/test/src/dart/analysis/file_state_test.dart b/pkg/analyzer/test/src/dart/analysis/file_state_test.dart index 16be3a9c7d1a..89a0c120c77e 100644 --- a/pkg/analyzer/test/src/dart/analysis/file_state_test.dart +++ b/pkg/analyzer/test/src/dart/analysis/file_state_test.dart @@ -394,7 +394,7 @@ var x = 0; @reflectiveTest class FileSystemState_BlazeWorkspaceTest extends BlazeWorkspaceResolutionTest { - void test_getFileForUri_hasGenerated_askGeneratedFirst() { + void test_getFileForUri_hasGenerated_askGeneratedFirst() { var relPath = 'dart/my/test/a.dart'; var writablePath = convertPath('$workspaceRootPath/$relPath'); var generatedPath = convertPath('$workspaceRootPath/blaze-bin/$relPath'); @@ -1127,7 +1127,7 @@ files kind: library_0 libraryImports library_1 dart:core synthetic - docLibraryImports + docImports library_3 dart:async library_5 dart:math fileKinds: library_0 @@ -4256,7 +4256,7 @@ files kind: partOfUriKnown_1 uriFile: file_0 library: library_0 - docLibraryImports + docImports library_4 dart:async library_6 dart:math referencingFiles: file_0 @@ -4272,7 +4272,7 @@ part of 'a.dart'; '''); fileStateFor(b).refresh(); - // The API signature of the cycle has changed. + // The API signature of the cycle is the same. assertDriverStateString(testFile, r''' files /home/test/lib/a.dart @@ -4288,7 +4288,7 @@ files cycle_2 dependencies: dart:core libraries: library_0 - apiSignature_1 + apiSignature_0 unlinkedKey: k00 /home/test/lib/b.dart uri: package:test/b.dart @@ -4297,7 +4297,7 @@ files kind: partOfUriKnown_7 uriFile: file_0 library: library_0 - docLibraryImports + docImports library_4 dart:async referencingFiles: file_0 unlinkedKey: k02 @@ -4306,175 +4306,6 @@ elementFactory '''); } - test_part_docImports_nestedPart() async { - newFile('$testPackageLibPath/a.dart', r''' -import 'dart:collection'; -part 'b.dart'; -'''); - - newFile('$testPackageLibPath/b.dart', r''' -part of 'a.dart'; -part 'c.dart'; -'''); - - var c = newFile('$testPackageLibPath/c.dart', r''' -/// @docImport 'dart:async'; -part of 'b.dart'; -'''); - - fileStateFor(c); - - assertDriverStateString(testFile, r''' -files - /home/test/lib/a.dart - uri: package:test/a.dart - current - id: file_0 - kind: library_0 - libraryImports - library_7 dart:collection - library_3 dart:core synthetic - partIncludes - partOfUriKnown_1 - fileKinds: library_0 partOfUriKnown_1 partOfUriKnown_2 - cycle_0 - dependencies: dart:collection dart:core - libraries: library_0 - apiSignature_0 - unlinkedKey: k00 - /home/test/lib/b.dart - uri: package:test/b.dart - current - id: file_1 - kind: partOfUriKnown_1 - uriFile: file_0 - library: library_0 - partIncludes - partOfUriKnown_2 - referencingFiles: file_0 - unlinkedKey: k01 - /home/test/lib/c.dart - uri: package:test/c.dart - current - id: file_2 - kind: partOfUriKnown_2 - uriFile: file_1 - library: library_0 - docLibraryImports - library_5 dart:async - referencingFiles: file_1 - unlinkedKey: k02 -libraryCycles -elementFactory -'''); - - // Add import 'dart:math'. - modifyFile2(c, r''' -/// @docImport 'dart:async'; -/// @docImport 'dart:math'; -part of 'b.dart'; -'''); - fileStateFor(c).refresh(); - - // New library cycle, with new 'apiSignature'. - assertDriverStateString(testFile, r''' -files - /home/test/lib/a.dart - uri: package:test/a.dart - current - id: file_0 - kind: library_0 - libraryImports - library_7 dart:collection - library_3 dart:core synthetic - partIncludes - partOfUriKnown_1 - fileKinds: library_0 partOfUriKnown_1 partOfUriKnown_9 - cycle_3 - dependencies: dart:collection dart:core - libraries: library_0 - apiSignature_1 - unlinkedKey: k00 - /home/test/lib/b.dart - uri: package:test/b.dart - current - id: file_1 - kind: partOfUriKnown_1 - uriFile: file_0 - library: library_0 - partIncludes - partOfUriKnown_9 - referencingFiles: file_0 - unlinkedKey: k01 - /home/test/lib/c.dart - uri: package:test/c.dart - current - id: file_2 - kind: partOfUriKnown_9 - uriFile: file_1 - library: library_0 - docLibraryImports - library_5 dart:async - library_8 dart:math - referencingFiles: file_1 - unlinkedKey: k03 -libraryCycles -elementFactory -'''); - - // Remove import 'dart:math'. - modifyFile2(c, r''' -/// @docImport 'dart:async'; -part of 'b.dart'; -'''); - fileStateFor(c).refresh(); - - // New library cycle, with the initial 'apiSignature'. - assertDriverStateString(testFile, r''' -files - /home/test/lib/a.dart - uri: package:test/a.dart - current - id: file_0 - kind: library_0 - libraryImports - library_7 dart:collection - library_3 dart:core synthetic - partIncludes - partOfUriKnown_1 - fileKinds: library_0 partOfUriKnown_1 partOfUriKnown_10 - cycle_4 - dependencies: dart:collection dart:core - libraries: library_0 - apiSignature_0 - unlinkedKey: k00 - /home/test/lib/b.dart - uri: package:test/b.dart - current - id: file_1 - kind: partOfUriKnown_1 - uriFile: file_0 - library: library_0 - partIncludes - partOfUriKnown_10 - referencingFiles: file_0 - unlinkedKey: k01 - /home/test/lib/c.dart - uri: package:test/c.dart - current - id: file_2 - kind: partOfUriKnown_10 - uriFile: file_1 - library: library_0 - docLibraryImports - library_5 dart:async - referencingFiles: file_1 - unlinkedKey: k02 -libraryCycles -elementFactory -'''); - } - test_part_libraryExports() async { newFile('$testPackageLibPath/a.dart', r''' export 'dart:collection'; @@ -5264,125 +5095,6 @@ elementFactory '''); } - test_refresh_library_docImportedBy_part() { - var a = newFile('$testPackageLibPath/a.dart', r''' -part 'b.dart'; -'''); - - newFile('$testPackageLibPath/b.dart', r''' -/// @docImport 'c.dart'; -part of 'a.dart'; -'''); - - var c = newFile('$testPackageLibPath/c.dart', r''' -class C {} -'''); - - fileStateFor(a); - - // `c.dart` is doc-imported by `b.dart`, so it is a dependency of `a.dart`. - assertDriverStateString(testFile, r''' -files - /home/test/lib/a.dart - uri: package:test/a.dart - current - id: file_0 - kind: library_0 - libraryImports - library_3 dart:core synthetic - partIncludes - partOfUriKnown_1 - fileKinds: library_0 partOfUriKnown_1 - cycle_0 - dependencies: cycle_1 dart:core - libraries: library_0 - apiSignature_0 - unlinkedKey: k00 - /home/test/lib/b.dart - uri: package:test/b.dart - current - id: file_1 - kind: partOfUriKnown_1 - uriFile: file_0 - library: library_0 - docLibraryImports - library_2 - referencingFiles: file_0 - unlinkedKey: k01 - /home/test/lib/c.dart - uri: package:test/c.dart - current - id: file_2 - kind: library_2 - libraryImports - library_3 dart:core synthetic - fileKinds: library_2 - cycle_1 - dependencies: dart:core - libraries: library_2 - apiSignature_1 - users: cycle_0 - referencingFiles: file_1 - unlinkedKey: k02 -libraryCycles -elementFactory -'''); - - newFile(c.path, r''' -class C2 {} -'''); - fileStateFor(c).refresh(); - - // Updated `c.dart` invalidates the library cycle for `a.dart`, both - // have now different signatures. - assertDriverStateString(testFile, r''' -files - /home/test/lib/a.dart - uri: package:test/a.dart - current - id: file_0 - kind: library_0 - libraryImports - library_3 dart:core synthetic - partIncludes - partOfUriKnown_1 - fileKinds: library_0 partOfUriKnown_1 - cycle_3 - dependencies: cycle_4 dart:core - libraries: library_0 - apiSignature_2 - unlinkedKey: k00 - /home/test/lib/b.dart - uri: package:test/b.dart - current - id: file_1 - kind: partOfUriKnown_1 - uriFile: file_0 - library: library_0 - docLibraryImports - library_8 - referencingFiles: file_0 - unlinkedKey: k01 - /home/test/lib/c.dart - uri: package:test/c.dart - current - id: file_2 - kind: library_8 - libraryImports - library_3 dart:core synthetic - fileKinds: library_8 - cycle_4 - dependencies: dart:core - libraries: library_8 - apiSignature_3 - users: cycle_3 - referencingFiles: file_1 - unlinkedKey: k03 -libraryCycles -elementFactory -'''); - } - test_refresh_library_importedBy_part() { var a = newFile('$testPackageLibPath/a.dart', r''' part 'b.dart'; @@ -5399,7 +5111,7 @@ class C {} fileStateFor(a); - // `c.dart` is imported by `b.dart`, so it is a dependency of `a.dart`. + // `c.dart` is imported by `b.dart`, so it is a dependency of `c.dart`. assertDriverStateString(testFile, r''' files /home/test/lib/a.dart diff --git a/pkg/analyzer/test/src/dart/resolution/comment_test.dart b/pkg/analyzer/test/src/dart/resolution/comment_test.dart index 8205094d25f2..2094ebe3fc6f 100644 --- a/pkg/analyzer/test/src/dart/resolution/comment_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/comment_test.dart @@ -743,207 +743,6 @@ CommentReference '''); } - test_docImport_prefix() async { - newFile('$testPackageLibPath/foo.dart', r''' -class A {} -'''); - await assertNoErrorsInCode(r''' -/// @docImport 'foo.dart' as foo; -library; - -/// [foo] -void f() {} -'''); - - assertResolvedNodeText(findNode.commentReference('foo]'), r''' -CommentReference - expression: SimpleIdentifier - token: foo - staticElement: ::@prefix::foo - element: ::@prefix2::foo - staticType: null -'''); - } - - test_docImport_prefix_extension() async { - newFile('$testPackageLibPath/foo.dart', r''' -extension E on int {} -'''); - await assertNoErrorsInCode(r''' -/// @docImport 'foo.dart' as foo; -library; - -/// [foo.E] -void f() {} -'''); - - assertResolvedNodeText(findNode.commentReference('foo.E]'), r''' -CommentReference - expression: PrefixedIdentifier - prefix: SimpleIdentifier - token: foo - staticElement: ::@prefix::foo - element: ::@prefix2::foo - staticType: null - period: . - identifier: SimpleIdentifier - token: E - staticElement: package:test/foo.dart::::@extension::E - element: package:test/foo.dart::@extension::E - staticType: null - staticElement: package:test/foo.dart::::@extension::E - element: package:test/foo.dart::@extension::E - staticType: null -'''); - } - - @FailingTest(reason: 'TODO(srawlins): Add support for parts') - test_docImport_prefix_inPart() async { - newFile('$testPackageLibPath/foo.dart', r''' -class A {} -'''); - newFile('$testPackageLibPath/bar.dart', r''' -/// @docImport 'foo.dart' as foo; -library; -part 'test.dart'; -'''); - await assertNoErrorsInCode(r''' -part of 'bar.dart'; - -/// [foo.A] -void f() {} -'''); - - assertResolvedNodeText(findNode.commentReference('foo.A]'), r''' -CommentReference - expression: PrefixedIdentifier - prefix: SimpleIdentifier - token: foo - staticElement: package:test/bar.dart::::@prefix::foo - element: package:test/bar.dart::::@prefix2::foo - staticType: null - period: . - identifier: SimpleIdentifier - token: A - staticElement: package:test/foo.dart::::@class::A - element: package:test/foo.dart::@class::A - staticType: null - staticElement: package:test/foo.dart::::@class::A - element: package:test/foo.dart::@class::A - staticType: null -'''); - } - - test_docImport_prefix_prefixedIdentifier() async { - newFile('$testPackageLibPath/foo.dart', r''' -class A {} -'''); - await assertNoErrorsInCode(r''' -/// @docImport 'foo.dart' as foo; -library; - -/// [foo.A] -void f() {} -'''); - - assertResolvedNodeText(findNode.commentReference('foo.A]'), r''' -CommentReference - expression: PrefixedIdentifier - prefix: SimpleIdentifier - token: foo - staticElement: ::@prefix::foo - element: ::@prefix2::foo - staticType: null - period: . - identifier: SimpleIdentifier - token: A - staticElement: package:test/foo.dart::::@class::A - element: package:test/foo.dart::@class::A - staticType: null - staticElement: package:test/foo.dart::::@class::A - element: package:test/foo.dart::@class::A - staticType: null -'''); - } - - test_docImport_prefix_propertyAccess() async { - newFile('$testPackageLibPath/foo.dart', r''' -class A { - int x = 1; -} -'''); - await assertNoErrorsInCode(r''' -/// @docImport 'foo.dart' as foo; -library; - -/// [foo.A.x] -void f() {} -'''); - - assertResolvedNodeText(findNode.commentReference('foo.A.x]'), r''' -CommentReference - expression: PropertyAccess - target: PrefixedIdentifier - prefix: SimpleIdentifier - token: foo - staticElement: ::@prefix::foo - element: ::@prefix2::foo - staticType: null - period: . - identifier: SimpleIdentifier - token: A - staticElement: package:test/foo.dart::::@class::A - element: package:test/foo.dart::@class::A - staticType: null - staticElement: package:test/foo.dart::::@class::A - element: package:test/foo.dart::@class::A - staticType: null - operator: . - propertyName: SimpleIdentifier - token: x - staticElement: package:test/foo.dart::::@class::A::@getter::x - element: package:test/foo.dart::::@class::A::@getter::x#element - staticType: null - staticType: null -'''); - } - - test_docImport_prefix_shared() async { - newFile('$testPackageLibPath/foo.dart', r''' -class A {} -'''); - newFile('$testPackageLibPath/bar.dart', r''' -class B {} -'''); - await assertNoErrorsInCode(r''' -/// @docImport 'foo.dart' as foo; -/// @docImport 'bar.dart' as foo; -library; - -/// [foo.A] -void f() {} -'''); - - assertResolvedNodeText(findNode.commentReference('foo.A]'), r''' -CommentReference - expression: PrefixedIdentifier - prefix: SimpleIdentifier - token: foo - staticElement: ::@prefix::foo - element: ::@prefix2::foo - staticType: null - period: . - identifier: SimpleIdentifier - token: A - staticElement: package:test/foo.dart::::@class::A - element: package:test/foo.dart::@class::A - staticType: null - staticElement: package:test/foo.dart::::@class::A - element: package:test/foo.dart::@class::A - staticType: null -'''); - } - test_extension_instanceGetter() async { await assertNoErrorsInCode(''' extension E on int { @@ -2284,32 +2083,6 @@ CommentReference '''); } - @FailingTest(reason: 'TODO(srawlins): Add support for parts') - test_docImport_referencedInPart() async { - newFile('$testPackageLibPath/foo.dart', r''' -class A {} -'''); - newFile('$testPackageLibPath/bar.dart', r''' -/// @docImport 'foo.dart'; -library; -part 'test.dart'; -'''); - await assertNoErrorsInCode(r''' -part of 'bar.dart'; -/// Text [A]. -int x = 1; -'''); - - assertResolvedNodeText(findNode.commentReference('A]'), r''' -CommentReference - expression: SimpleIdentifier - token: A - staticElement: package:test/foo.dart::::@class::A - element: package:test/foo.dart::@class::A - staticType: null -'''); - } - test_newKeyword() async { await assertErrorsInCode(''' class A { diff --git a/pkg/analyzer/test/src/summary/element_text.dart b/pkg/analyzer/test/src/summary/element_text.dart index 8dcfe705c2ba..932b9aa8b476 100644 --- a/pkg/analyzer/test/src/summary/element_text.dart +++ b/pkg/analyzer/test/src/summary/element_text.dart @@ -436,13 +436,6 @@ class _Element2Writer extends _AbstractElementWriter { } } - void _writeDocLibraryImport(LibraryImport e) { - _sink.writeIndentedLine(() { - _writeDirectiveUri(e.uri); - _writeImportElementPrefix((e as LibraryImportElementImpl).prefix2); - }); - } - void _writeDocumentation(String? documentation) { if (documentation != null) { var str = documentation; @@ -1198,20 +1191,9 @@ class _Element2Writer extends _AbstractElementWriter { imports, _writeLibraryImport, ); - _writeList( - 'docLibraryImports', - f.docLibraryImports, - _writeDocLibraryImport, - ); } _writeElementList( 'prefixes', f.library2!, f.prefixes, _writePrefixElement); - _writeElementList( - 'docLibraryImportPrefixes', - f.library2!, - f.docLibraryImportPrefixes, - _writePrefixElement, - ); // _writeList( // 'libraryExports', f.libraryExports, _writeLibraryExportElement); // _writeList('parts', f.parts, _writePartElement); @@ -2434,17 +2416,6 @@ class _ElementWriter extends _AbstractElementWriter { } } - void _writeDocLibraryImportElement(LibraryImportElementImpl e) { - _sink.writeIndentedLine(() { - _writeDirectiveUri(e.uri); - _writeImportElementPrefix(e.prefix); - }); - - _sink.withIndent(() { - _writeReference(e); - }); - } - void _writeDocumentation(Element element) { var documentation = element.documentationComment; if (documentation != null) { @@ -3161,17 +3132,6 @@ class _ElementWriter extends _AbstractElementWriter { }); } - /*void _writePrefixElement2(PrefixElementImpl2 e) { - _sink.writeIndentedLine(() { - _writeName2(e); - }); - - _sink.withIndent(() { - _writeReference(e); - _writeEnclosingElement(e); - }); - }*/ - void _writePropertyAccessorElement(PropertyAccessorElement e) { e as PropertyAccessorElementImpl; @@ -3483,22 +3443,12 @@ class _ElementWriter extends _AbstractElementWriter { return configuration.withSyntheticDartCoreImport || !import.isSynthetic; }).toList(); _writeElements('libraryImports', imports, _writeLibraryImportElement); - _writeElements( - 'docLibraryImports', - e.docLibraryImports, - _writeDocLibraryImportElement, - ); } _writeElements( 'libraryImportPrefixes', e.libraryImportPrefixes, _writePrefixElement, ); - _writeElements( - 'docLibraryImportPrefixes', - e.docLibraryImportPrefixes.map((e) => e.asElement).toList(), - _writePrefixElement, - ); _writeElements( 'libraryExports', e.libraryExports, _writeLibraryExportElement); _writeElements('parts', e.parts, _writePartElement); diff --git a/pkg/analyzer/test/src/summary/elements/library_fragment_test.dart b/pkg/analyzer/test/src/summary/elements/library_fragment_test.dart index c9d7b00f6add..4318ef5ac073 100644 --- a/pkg/analyzer/test/src/summary/elements/library_fragment_test.dart +++ b/pkg/analyzer/test/src/summary/elements/library_fragment_test.dart @@ -23,57 +23,6 @@ main() { } abstract class LibraryFragmentElementTest extends ElementsBaseTest { - test_docImports() async { - newFile('$testPackageLibPath/a.dart', r''' -/// @docImport 'dart:math'; -part of 'test.dart'; -'''); - - var library = await buildLibrary(r''' -/// @docImport 'dart:io'; -library; - -part 'a.dart'; -'''); - - checkElementText(library, r''' -library - reference: - documentationComment: /// @docImport 'dart:io'; - definingUnit: - units - - enclosingElement3: - docLibraryImports - dart:io - parts - part_0 - uri: package:test/a.dart - enclosingElement3: - unit: ::@fragment::package:test/a.dart - ::@fragment::package:test/a.dart - enclosingElement3: - docLibraryImports - dart:math ----------------------------------------- -library - reference: - documentationComment: /// @docImport 'dart:io'; - fragments - - element: - nextFragment: ::@fragment::package:test/a.dart - docLibraryImports - dart:io - ::@fragment::package:test/a.dart - element: - enclosingFragment: - previousFragment: - docLibraryImports - dart:math -'''); - } - test_libraryExports() async { newFile('$testPackageLibPath/a.dart', r''' part of 'test.dart'; diff --git a/pkg/analyzer/test/src/summary/elements/library_import_test.dart b/pkg/analyzer/test/src/summary/elements/library_import_test.dart index ab274e211963..6f4dc9c20fe1 100644 --- a/pkg/analyzer/test/src/summary/elements/library_import_test.dart +++ b/pkg/analyzer/test/src/summary/elements/library_import_test.dart @@ -18,42 +18,6 @@ main() { } abstract class LibraryImportElementTest extends ElementsBaseTest { - test_docImport_prefixed() async { - newFile('$testPackageLibPath/a.dart', 'library a; class C {}'); - var library = await buildLibrary(''' -/// @docImport "a.dart" as a; -library; -'''); - - checkElementText(library, r''' -library - reference: - documentationComment: /// @docImport "a.dart" as a; - definingUnit: - units - - enclosingElement3: - docLibraryImports - package:test/a.dart as a @27 - docLibraryImportPrefixes - a @27 - reference: ::@prefix::a - enclosingElement3: ----------------------------------------- -library - reference: - documentationComment: /// @docImport "a.dart" as a; - fragments - - element: - docLibraryImports - package:test/a.dart as a @27 - docLibraryImportPrefixes - ::@prefix2::a - fragments: @27 -'''); - } - test_import_configurations_useDefault() async { declaredVariables = { 'dart.library.io': 'false', @@ -786,6 +750,10 @@ library newFile('$testPackageLibPath/a.dart', 'library a; class C {}'); var library = await buildLibrary('import "a.dart" as a; a.C c;'); + var prefixElement = + library.definingCompilationUnit.libraryImports[0].prefix!.element; + expect(prefixElement.nameOffset, 19); + checkElementText(library, r''' library reference: