Skip to content

Commit

Permalink
Require analyzer 6.10.0, stop using deprecated properties of LibraryE…
Browse files Browse the repository at this point in the history
…lement. (#3899)

* Require analyzer 6.10.0, stop using deprecated properties of LibraryElement.
* Use language 3.7.0
  • Loading branch information
scheglov authored Oct 8, 2024
1 parent 5df03dd commit 9d9b00c
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 24 deletions.
25 changes: 16 additions & 9 deletions lib/src/generator/templates.runtime_renderers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15829,6 +15829,7 @@ const _invisibleGetters = {
'scope'
},
'CompilationUnitElement': {
'accessibleExtensions',
'accessors',
'classes',
'enclosingElement',
Expand All @@ -15845,6 +15846,7 @@ const _invisibleGetters = {
'mixins',
'parts',
'runtimeType',
'scope',
'session',
'topLevelVariables',
'typeAliases'
Expand Down Expand Up @@ -15888,6 +15890,7 @@ const _invisibleGetters = {
'alias',
'element',
'element2',
'element3',
'extensionTypeErasure',
'hashCode',
'isBottom',
Expand Down Expand Up @@ -16033,15 +16036,15 @@ const _invisibleGetters = {
'ExecutableMember': {
'augmentationSubstitution',
'children',
'children3',
'children2',
'context',
'declaration',
'displayName',
'documentationComment',
'element',
'enclosingElement',
'enclosingElement2',
'enclosingElement3',
'enclosingFragment',
'formalParameters',
'hasAlwaysThrows',
'hasDeprecated',
'hasDoNotStore',
Expand Down Expand Up @@ -16087,27 +16090,27 @@ const _invisibleGetters = {
'isSynthetic',
'kind',
'library',
'libraryFragment',
'library2',
'librarySource',
'location',
'metadata',
'name',
'nameLength',
'nameOffset',
'nextFragment',
'nonSynthetic',
'nonSynthetic2',
'parameters',
'parameters2',
'previousFragment',
'returnType',
'runtimeType',
'session',
'sinceSdkVersion',
'substitution',
'type',
'typeParameters'
'typeParameters',
'typeParameters2'
},
'Expression': {
'correspondingParameter',
'hashCode',
'inConstantContext',
'isAssignable',
Expand Down Expand Up @@ -16166,6 +16169,7 @@ const _invisibleGetters = {
'FunctionType': {
'element',
'element2',
'formalParameters',
'hashCode',
'namedParameterTypes',
'normalParameterNames',
Expand All @@ -16175,7 +16179,8 @@ const _invisibleGetters = {
'parameters',
'returnType',
'runtimeType',
'typeFormals'
'typeFormals',
'typeParameters'
},
'FunctionTypedElement': {
'hashCode',
Expand Down Expand Up @@ -16432,6 +16437,7 @@ const _invisibleGetters = {
'ParameterElement': {
'declaration',
'defaultValueCode',
'element',
'hasDefaultValue',
'hashCode',
'isCovariant',
Expand Down Expand Up @@ -16459,6 +16465,7 @@ const _invisibleGetters = {
'defaultValueCode',
'displayName',
'documentationComment',
'element',
'enclosingElement',
'enclosingElement3',
'hasAlwaysThrows',
Expand Down
6 changes: 3 additions & 3 deletions lib/src/model/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Library extends ModelElement
var localElements = {
// TODO(jcollins-g): Consider switch to `element.topLevelElements`.
..._getDefinedElements(element.definingCompilationUnit),
...element.parts
...element.definingCompilationUnit.parts
.map((e) => e.uri)
.whereType<DirectiveUriWithUnit>()
.map((part) => part.unit)
Expand Down Expand Up @@ -96,7 +96,7 @@ class Library extends ModelElement

/// Allow scope for Libraries.
@override
Scope get scope => element.scope;
Scope get scope => element.definingCompilationUnit.scope;

bool get isInSdk => element.isInSdk;

Expand Down Expand Up @@ -142,7 +142,7 @@ class Library extends ModelElement
Map<String, Set<Library>> get _prefixToLibrary {
var prefixToLibrary = <String, Set<Library>>{};
// It is possible to have overlapping prefixes.
for (var i in element.libraryImports) {
for (var i in element.definingCompilationUnit.libraryImports) {
var prefixName = i.prefix?.element.name;
// Ignore invalid imports.
if (prefixName != null && i.importedLibrary != null) {
Expand Down
10 changes: 4 additions & 6 deletions lib/src/model/package_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -561,19 +561,17 @@ extension on Set<String> {

if (add(path)) {
var libraryImports = switch (element) {
LibraryElement(:var libraryImports) ||
CompilationUnitElement(:var libraryImports) =>
libraryImports,
LibraryElement() => element.definingCompilationUnit.libraryImports,
CompilationUnitElement(:var libraryImports) => libraryImports,
_ => const <LibraryImportElement>[],
};
for (var import in libraryImports) {
addFilesReferencedBy(import.importedLibrary);
}

var libraryExports = switch (element) {
LibraryElement(:var libraryExports) ||
CompilationUnitElement(:var libraryExports) =>
libraryExports,
LibraryElement() => element.definingCompilationUnit.libraryExports,
CompilationUnitElement(:var libraryExports) => libraryExports,
_ => const <LibraryExportElement>[],
};
for (var export in libraryExports) {
Expand Down
3 changes: 2 additions & 1 deletion lib/src/model/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ class PackageGraph with CommentReferable, Nameable {
alreadyTagged.add(key);
// Mark that `publicLibrary` exports `libraryElement`.
_libraryExports.putIfAbsent(libraryElement, () => {}).add(publicLibrary);
for (var exportedElement in libraryElement.libraryExports) {
for (var exportedElement
in libraryElement.definingCompilationUnit.libraryExports) {
var exportedLibrary = exportedElement.exportedLibrary;
if (exportedLibrary != null) {
// Follow the exports down; as `publicLibrary` exports `libraryElement`,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/prefix.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Prefix extends ModelElement with HasNoPage {
// TODO(jcollins-g): consider connecting PrefixElement to the imported library
// in analyzer?
late final Library associatedLibrary = getModelForElement(library
.element.libraryImports
.element.definingCompilationUnit.libraryImports
.firstWhere((i) => i.prefix?.element == element)
.importedLibrary!) as Library;

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:
sdk: ^3.2.0

dependencies:
analyzer: ^6.9.0
analyzer: ^6.10.0
args: ^2.4.1
collection: ^1.17.0
crypto: ^3.0.3
Expand Down
2 changes: 1 addition & 1 deletion test/dartdoc_test_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class DartdocTestBase {

String get dartCoreUrlPrefix => 'https://api.dart.dev/stable/3.2.0/dart-core';

String get sdkConstraint => '>=3.6.0 <4.0.0';
String get sdkConstraint => '>=3.7.0 <4.0.0';

List<String> get experiments => ['enhanced-parts', 'wildcard-variables'];

Expand Down
10 changes: 8 additions & 2 deletions test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,14 @@ void main() async {
test('can import other libraries with unusual URIs', () {
final fakeLibraryImportedExported = <Library>{
for (final l in <LibraryElement>{
...fakeLibrary.element.importedLibraries,
...fakeLibrary.element.exportedLibraries
...fakeLibrary.element.definingCompilationUnit.libraryImports
.map((import) => import.uri)
.whereType<DirectiveUriWithLibrary>()
.map((uri) => uri.library),
...fakeLibrary.element.definingCompilationUnit.libraryExports
.map((import) => import.uri)
.whereType<DirectiveUriWithLibrary>()
.map((uri) => uri.library)
})
packageGraph.getModelForElement(l) as Library
};
Expand Down

0 comments on commit 9d9b00c

Please sign in to comment.