Skip to content

Update analyzer to 2.1.0 and avoid direct use of pub #2764

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
Aug 26, 2021
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
20 changes: 10 additions & 10 deletions lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class ElementType extends Privacy with CommentReferable, Nameable {
f.element.kind == ElementKind.DYNAMIC ||
f.element.kind == ElementKind.NEVER) {
if (f is FunctionType) {
if (f.aliasElement != null) {
if (f.alias?.element != null) {
return AliasedFunctionTypeElementType(
f, library, packageGraph, returnedFrom);
}
Expand All @@ -44,14 +44,14 @@ abstract class ElementType extends Privacy with CommentReferable, Nameable {
// In that case it is an actual type alias of some kind (generic
// or otherwise. Here however aliasElement signals that this is a
// type referring to an alias.
if (f is! TypeAliasElement && f.aliasElement != null) {
if (f is! TypeAliasElement && f.alias?.element != null) {
return AliasedElementType(
f, library, packageGraph, element, returnedFrom);
}
assert(f is ParameterizedType || f is TypeParameterType);
// TODO(jcollins-g): strip out all the cruft that's accumulated
// here for non-generic type aliases.
var isGenericTypeAlias = f.aliasElement != null && f is! InterfaceType;
var isGenericTypeAlias = f.alias?.element != null && f is! InterfaceType;
if (f is FunctionType) {
assert(f is ParameterizedType);
// This is an indication we have an extremely out of date analyzer....
Expand Down Expand Up @@ -188,8 +188,8 @@ class AliasedFunctionTypeElementType extends FunctionTypeElementType
AliasedFunctionTypeElementType(FunctionType f, Library library,
PackageGraph packageGraph, ElementType returnedFrom)
: super(f, library, packageGraph, returnedFrom) {
assert(type.aliasElement != null);
assert(type.aliasArguments != null);
assert(type.alias?.element != null);
assert(type.alias?.typeArguments != null);
}

@override
Expand Down Expand Up @@ -220,18 +220,18 @@ class ParameterizedElementType extends DefinedElementType with Rendered {
/// A [ElementType] whose underlying type was referrred to by a type alias.
mixin Aliased implements ElementType {
@override
String get name => type.aliasElement.name;
String get name => type.alias.element.name;

@override
bool get isTypedef => true;

ModelElement _aliasElement;
ModelElement get aliasElement => _aliasElement ??=
ModelElement.fromElement(type.aliasElement, packageGraph);
ModelElement.fromElement(type.alias.element, packageGraph);

Iterable<ElementType> _aliasArguments;
Iterable<ElementType> get aliasArguments =>
_aliasArguments ??= type.aliasArguments
_aliasArguments ??= type.alias.typeArguments
.map((f) => ElementType.from(f, library, packageGraph))
.toList(growable: false);
}
Expand All @@ -240,7 +240,7 @@ class AliasedElementType extends ParameterizedElementType with Aliased {
AliasedElementType(ParameterizedType type, Library library,
PackageGraph packageGraph, ModelElement element, ElementType returnedFrom)
: super(type, library, packageGraph, element, returnedFrom) {
assert(type.aliasElement != null);
assert(type.alias?.element != null);
}

@override
Expand Down Expand Up @@ -429,7 +429,7 @@ class CallableElementType extends DefinedElementType with Rendered, Callable {
Iterable<ElementType> _typeArguments;
@override
Iterable<ElementType> get typeArguments =>
_typeArguments ??= (type.aliasArguments ?? [])
_typeArguments ??= (type.alias?.typeArguments ?? [])
.map((f) => ElementType.from(f, library, packageGraph))
.toList(growable: false);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/model/package_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class PubPackageBuilder implements PackageBuilder {
var analysisContext = contextCollection.contextFor(config.inputDir);
var session = analysisContext.currentSession;
// Allow dart source files with inappropriate suffixes (#1897).
final library = await session.getResolvedLibrary2(filePath);
final library = await session.getResolvedLibrary(filePath);
if (library is ResolvedLibraryResult) {
final libraryElement = library.element;
var restoredUri = libraryElement.source.uri.toString();
Expand Down
18 changes: 10 additions & 8 deletions lib/src/package_meta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ class PackageMetaFailure extends DartdocFailure {
}

/// For each list in this list, at least one of the given paths must exist
/// for this to be detected as an SDK.
final List<List<String>> __sdkDirFilePathsPosix = [
/// for this to be detected as an SDK. Update [_writeMockSdkBinFiles] in
/// `test/src/utils.dart` if removing any entries here.
const List<List<String>> _sdkDirFilePathsPosix = [
['bin/dart.bat', 'bin/dart.exe', 'bin/dart'],
['bin/pub.bat', 'bin/pub'],
['include/dart_version.h'],
['lib/core/core.dart'],
];

Expand Down Expand Up @@ -161,15 +162,15 @@ abstract class PubPackageMeta extends PackageMeta {
if (__sdkDirFilePaths == null) {
__sdkDirFilePaths = [];
if (Platform.isWindows) {
for (var paths in __sdkDirFilePathsPosix) {
for (var paths in _sdkDirFilePathsPosix) {
var windowsPaths = [
for (var path in paths)
p.joinAll(p.Context(style: p.Style.posix).split(path)),
];
__sdkDirFilePaths.add(windowsPaths);
}
} else {
__sdkDirFilePaths = __sdkDirFilePathsPosix;
__sdkDirFilePaths = _sdkDirFilePathsPosix;
}
}
return __sdkDirFilePaths;
Expand Down Expand Up @@ -342,12 +343,13 @@ class _FilePackageMeta extends PubPackageMeta {
List<String> parameters;
if (requiresFlutter) {
binPath = p.join(flutterRoot, 'bin', 'flutter');
if (Platform.isWindows) binPath += '.bat';
parameters = ['pub', 'get'];
} else {
binPath = p.join(p.dirname(Platform.resolvedExecutable), 'pub');
parameters = ['get'];
binPath = p.join(p.dirname(Platform.resolvedExecutable), 'dart');
if (Platform.isWindows) binPath += '.exe';
parameters = ['pub', 'get'];
}
if (Platform.isWindows) binPath += '.bat';

var result =
Process.runSync(binPath, parameters, workingDirectory: dir.path);
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.11.99 <3.0.0'

dependencies:
analyzer: ^2.0.0
analyzer: ^2.1.0
args: ^2.0.0
charcode: ^1.2.0
collection: ^1.2.0
Expand Down
3 changes: 2 additions & 1 deletion test/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ Folder writeMockSdkFiles(MockSdk mockSdk) {
void _writeMockSdkBinFiles(Folder root) {
var sdkBinFolder = root.getChildAssumingFolder('bin');
sdkBinFolder.getChildAssumingFile('dart').writeAsStringSync('');
sdkBinFolder.getChildAssumingFile('pub').writeAsStringSync('');
var sdkIncludeFolder = root.getChildAssumingFolder('include');
sdkIncludeFolder.getChildAssumingFile('dart_version.h').writeAsStringSync('');
}

/// Writes a package named [packageName], with [resourceProvider], to the
Expand Down