Skip to content

Upgrade to analyzer 0.39.2+1 and fix using deprecated APIs. #2093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'dart:collection';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/nullability_suffix.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/generated/type_system.dart';
import 'package:dartdoc/src/model/model.dart';
import 'package:dartdoc/src/render/element_type_renderer.dart';

Expand Down Expand Up @@ -278,8 +279,8 @@ abstract class DefinedElementType extends ElementType {
DartType get instantiatedType {
if (_instantiatedType == null) {
if (!interfaceType.typeArguments.every((t) => t is InterfaceType)) {
_instantiatedType =
packageGraph.typeSystem.instantiateToBounds(interfaceType);
var typeSystem = library.element.typeSystem as TypeSystemImpl;
_instantiatedType = typeSystem.instantiateToBounds(interfaceType);
} else {
_instantiatedType = interfaceType;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/model/extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Extension extends Container

/// The instantiated to bounds [extendedType] of this extension is a subtype of
/// [t].
bool isSubtypeOf(DefinedElementType t) => packageGraph.typeSystem
bool isSubtypeOf(DefinedElementType t) => library.typeSystem
.isSubtypeOf(extendedType.instantiatedType, t.instantiatedType);

bool isBoundSupertypeTo(DefinedElementType t) =>
Expand All @@ -52,7 +52,7 @@ class Extension extends Container
visited.add(superType);
if (superClass == extendedType.type.element &&
(superType == extendedType.instantiatedType ||
packageGraph.typeSystem
library.typeSystem
.isSubtypeOf(superType, extendedType.instantiatedType))) {
return true;
}
Expand Down
29 changes: 15 additions & 14 deletions lib/src/model/library.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type_system.dart';
import 'package:analyzer/dart/element/visitor.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
Expand Down Expand Up @@ -77,11 +78,11 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
// Initialize the list of elements defined in this library and
// exported via its export directives.
Set<Element> exportedAndLocalElements =
_libraryElement.exportNamespace.definedNames.values.toSet();
element.exportNamespace.definedNames.values.toSet();
// TODO(jcollins-g): Consider switch to [_libraryElement.topLevelElements].
exportedAndLocalElements
.addAll(getDefinedElements(_libraryElement.definingCompilationUnit));
for (CompilationUnitElement cu in _libraryElement.parts) {
.addAll(getDefinedElements(element.definingCompilationUnit));
for (CompilationUnitElement cu in element.parts) {
exportedAndLocalElements.addAll(getDefinedElements(cu));
}
_exportedAndLocalElements = exportedAndLocalElements.toList();
Expand All @@ -105,7 +106,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {

List<String> _allOriginalModelElementNames;

bool get isInSdk => _libraryElement.isInSdk;
bool get isInSdk => element.isInSdk;

final Package _package;

Expand Down Expand Up @@ -160,11 +161,14 @@ class Library extends ModelElement with Categorization, TopLevelContainer {

@override
CompilationUnitElement get compilationUnitElement =>
(element as LibraryElement).definingCompilationUnit;
element.definingCompilationUnit;

@override
Iterable<Class> get classes => allClasses.where((c) => !c.isErrorOrException);

@override
LibraryElement get element => super.element;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. though there should be no reason for the _libraryElement member at this point. Can you remove and change references?


List<Extension> _extensions;

@override
Expand Down Expand Up @@ -240,10 +244,8 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
if (_importedExportedLibraries == null) {
_importedExportedLibraries = Set();
Set<LibraryElement> importedExportedLibraryElements = Set();
importedExportedLibraryElements
.addAll((element as LibraryElement).importedLibraries);
importedExportedLibraryElements
.addAll((element as LibraryElement).exportedLibraries);
importedExportedLibraryElements.addAll(element.importedLibraries);
importedExportedLibraryElements.addAll(element.exportedLibraries);
for (LibraryElement l in importedExportedLibraryElements) {
Library lib = ModelElement.from(l, library, packageGraph);
_importedExportedLibraries.add(lib);
Expand All @@ -260,7 +262,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
if (_prefixToLibrary == null) {
_prefixToLibrary = {};
// It is possible to have overlapping prefixes.
for (ImportElement i in (element as LibraryElement).imports) {
for (ImportElement i in element.imports) {
// Ignore invalid imports.
if (i.prefix?.name != null && i.importedLibrary != null) {
_prefixToLibrary.putIfAbsent(i.prefix?.name, () => Set());
Expand Down Expand Up @@ -401,8 +403,7 @@ class Library extends ModelElement with Categorization, TopLevelContainer {

InheritanceManager3 get inheritanceManager {
if (_inheritanceManager == null) {
var typeSystem = element.context.typeSystem;
_inheritanceManager = InheritanceManager3(typeSystem);
_inheritanceManager = InheritanceManager3();
}
return _inheritanceManager;
}
Expand Down Expand Up @@ -479,6 +480,8 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
return _typedefs;
}

TypeSystem get typeSystem => element.typeSystem;

List<Class> _classes;

List<Class> get allClasses {
Expand All @@ -493,8 +496,6 @@ class Library extends ModelElement with Categorization, TopLevelContainer {
return _classes;
}

LibraryElement get _libraryElement => (element as LibraryElement);

Class getClassByName(String name) {
return allClasses.firstWhere((it) => it.name == name, orElse: () => null);
}
Expand Down
5 changes: 2 additions & 3 deletions lib/src/model/model_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -666,9 +666,8 @@ abstract class ModelElement extends Canonicalization

if (candidateLibraries != null) {
candidateLibraries = candidateLibraries.where((l) {
Element lookup = (l.element as LibraryElement)
.exportNamespace
.definedNames[topLevelElement?.name];
Element lookup =
l.element.exportNamespace.definedNames[topLevelElement?.name];
if (lookup is PropertyAccessorElement) {
lookup = (lookup as PropertyAccessorElement).variable;
}
Expand Down
7 changes: 1 addition & 6 deletions lib/src/model/package_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,7 @@ class PackageBuilder {
RendererFactory rendererFactory = HtmlRenderFactory();

PackageGraph newGraph = PackageGraph.UninitializedPackageGraph(
config,
driver,
await driver.currentSession.typeSystem,
sdk,
hasEmbedderSdkFiles,
rendererFactory);
config, driver, sdk, hasEmbedderSdkFiles, rendererFactory);
await getLibraries(newGraph);
await newGraph.initializePackageGraph();
return newGraph;
Expand Down
8 changes: 3 additions & 5 deletions lib/src/model/package_graph.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:analyzer/src/dart/element/member.dart';
import 'package:analyzer/src/generated/sdk.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/generated/source_io.dart';
import 'package:analyzer/src/generated/type_system.dart' show Dart2TypeSystem;
import 'package:collection/collection.dart';
import 'package:dartdoc/src/dartdoc_options.dart';
import 'package:dartdoc/src/model/model.dart';
Expand All @@ -25,8 +24,8 @@ import 'package:dartdoc/src/tuple.dart';
import 'package:dartdoc/src/warnings.dart';

class PackageGraph {
PackageGraph.UninitializedPackageGraph(this.config, this.driver,
this.typeSystem, this.sdk, this.hasEmbedderSdk, this.rendererFactory)
PackageGraph.UninitializedPackageGraph(this.config, this.driver, this.sdk,
this.hasEmbedderSdk, this.rendererFactory)
: packageMeta = config.topLevelPackageMeta,
session = driver.currentSession {
_packageWarningCounter = PackageWarningCounter(this);
Expand Down Expand Up @@ -232,7 +231,6 @@ class PackageGraph {
/// TODO(brianwilkerson) Replace the driver with the session.
final AnalysisDriver driver;
final AnalysisSession session;
final Dart2TypeSystem typeSystem;
final DartSdk sdk;

Map<Source, SdkLibrary> _sdkLibrarySources;
Expand Down Expand Up @@ -678,7 +676,7 @@ class PackageGraph {
static Element getBasestElement(Element possibleMember) {
Element element = possibleMember;
while (element is Member) {
element = (element as Member).baseElement;
element = (element as Member).declaration;
}
return element;
}
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: '>=2.6.0 <3.0.0'

dependencies:
analyzer: ^0.39.1
analyzer: ^0.39.2+1
args: '>=1.5.0 <2.0.0'
collection: ^1.2.0
crypto: ^2.0.6
Expand Down