Skip to content

Commit a62e5f3

Browse files
authored
Update analyzer to 2.1.0 and avoid direct use of pub (#2764)
* Update analyzer to 2.1.0 and avoid direct use of pub * fix windows execution * review comments
1 parent 587a2e2 commit a62e5f3

File tree

5 files changed

+24
-21
lines changed

5 files changed

+24
-21
lines changed

lib/src/element_type.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ abstract class ElementType extends Privacy with CommentReferable, Nameable {
3131
f.element.kind == ElementKind.DYNAMIC ||
3232
f.element.kind == ElementKind.NEVER) {
3333
if (f is FunctionType) {
34-
if (f.aliasElement != null) {
34+
if (f.alias?.element != null) {
3535
return AliasedFunctionTypeElementType(
3636
f, library, packageGraph, returnedFrom);
3737
}
@@ -44,14 +44,14 @@ abstract class ElementType extends Privacy with CommentReferable, Nameable {
4444
// In that case it is an actual type alias of some kind (generic
4545
// or otherwise. Here however aliasElement signals that this is a
4646
// type referring to an alias.
47-
if (f is! TypeAliasElement && f.aliasElement != null) {
47+
if (f is! TypeAliasElement && f.alias?.element != null) {
4848
return AliasedElementType(
4949
f, library, packageGraph, element, returnedFrom);
5050
}
5151
assert(f is ParameterizedType || f is TypeParameterType);
5252
// TODO(jcollins-g): strip out all the cruft that's accumulated
5353
// here for non-generic type aliases.
54-
var isGenericTypeAlias = f.aliasElement != null && f is! InterfaceType;
54+
var isGenericTypeAlias = f.alias?.element != null && f is! InterfaceType;
5555
if (f is FunctionType) {
5656
assert(f is ParameterizedType);
5757
// This is an indication we have an extremely out of date analyzer....
@@ -188,8 +188,8 @@ class AliasedFunctionTypeElementType extends FunctionTypeElementType
188188
AliasedFunctionTypeElementType(FunctionType f, Library library,
189189
PackageGraph packageGraph, ElementType returnedFrom)
190190
: super(f, library, packageGraph, returnedFrom) {
191-
assert(type.aliasElement != null);
192-
assert(type.aliasArguments != null);
191+
assert(type.alias?.element != null);
192+
assert(type.alias?.typeArguments != null);
193193
}
194194

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

225225
@override
226226
bool get isTypedef => true;
227227

228228
ModelElement _aliasElement;
229229
ModelElement get aliasElement => _aliasElement ??=
230-
ModelElement.fromElement(type.aliasElement, packageGraph);
230+
ModelElement.fromElement(type.alias.element, packageGraph);
231231

232232
Iterable<ElementType> _aliasArguments;
233233
Iterable<ElementType> get aliasArguments =>
234-
_aliasArguments ??= type.aliasArguments
234+
_aliasArguments ??= type.alias.typeArguments
235235
.map((f) => ElementType.from(f, library, packageGraph))
236236
.toList(growable: false);
237237
}
@@ -240,7 +240,7 @@ class AliasedElementType extends ParameterizedElementType with Aliased {
240240
AliasedElementType(ParameterizedType type, Library library,
241241
PackageGraph packageGraph, ModelElement element, ElementType returnedFrom)
242242
: super(type, library, packageGraph, element, returnedFrom) {
243-
assert(type.aliasElement != null);
243+
assert(type.alias?.element != null);
244244
}
245245

246246
@override
@@ -429,7 +429,7 @@ class CallableElementType extends DefinedElementType with Rendered, Callable {
429429
Iterable<ElementType> _typeArguments;
430430
@override
431431
Iterable<ElementType> get typeArguments =>
432-
_typeArguments ??= (type.aliasArguments ?? [])
432+
_typeArguments ??= (type.alias?.typeArguments ?? [])
433433
.map((f) => ElementType.from(f, library, packageGraph))
434434
.toList(growable: false);
435435
}

lib/src/model/package_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class PubPackageBuilder implements PackageBuilder {
155155
var analysisContext = contextCollection.contextFor(config.inputDir);
156156
var session = analysisContext.currentSession;
157157
// Allow dart source files with inappropriate suffixes (#1897).
158-
final library = await session.getResolvedLibrary2(filePath);
158+
final library = await session.getResolvedLibrary(filePath);
159159
if (library is ResolvedLibraryResult) {
160160
final libraryElement = library.element;
161161
var restoredUri = libraryElement.source.uri.toString();

lib/src/package_meta.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ class PackageMetaFailure extends DartdocFailure {
2727
}
2828

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

@@ -161,15 +162,15 @@ abstract class PubPackageMeta extends PackageMeta {
161162
if (__sdkDirFilePaths == null) {
162163
__sdkDirFilePaths = [];
163164
if (Platform.isWindows) {
164-
for (var paths in __sdkDirFilePathsPosix) {
165+
for (var paths in _sdkDirFilePathsPosix) {
165166
var windowsPaths = [
166167
for (var path in paths)
167168
p.joinAll(p.Context(style: p.Style.posix).split(path)),
168169
];
169170
__sdkDirFilePaths.add(windowsPaths);
170171
}
171172
} else {
172-
__sdkDirFilePaths = __sdkDirFilePathsPosix;
173+
__sdkDirFilePaths = _sdkDirFilePathsPosix;
173174
}
174175
}
175176
return __sdkDirFilePaths;
@@ -342,12 +343,13 @@ class _FilePackageMeta extends PubPackageMeta {
342343
List<String> parameters;
343344
if (requiresFlutter) {
344345
binPath = p.join(flutterRoot, 'bin', 'flutter');
346+
if (Platform.isWindows) binPath += '.bat';
345347
parameters = ['pub', 'get'];
346348
} else {
347-
binPath = p.join(p.dirname(Platform.resolvedExecutable), 'pub');
348-
parameters = ['get'];
349+
binPath = p.join(p.dirname(Platform.resolvedExecutable), 'dart');
350+
if (Platform.isWindows) binPath += '.exe';
351+
parameters = ['pub', 'get'];
349352
}
350-
if (Platform.isWindows) binPath += '.bat';
351353

352354
var result =
353355
Process.runSync(binPath, parameters, workingDirectory: dir.path);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ environment:
77
sdk: '>=2.11.99 <3.0.0'
88

99
dependencies:
10-
analyzer: ^2.0.0
10+
analyzer: ^2.1.0
1111
args: ^2.0.0
1212
charcode: ^1.2.0
1313
collection: ^1.2.0

test/src/utils.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ Folder writeMockSdkFiles(MockSdk mockSdk) {
134134
void _writeMockSdkBinFiles(Folder root) {
135135
var sdkBinFolder = root.getChildAssumingFolder('bin');
136136
sdkBinFolder.getChildAssumingFile('dart').writeAsStringSync('');
137-
sdkBinFolder.getChildAssumingFile('pub').writeAsStringSync('');
137+
var sdkIncludeFolder = root.getChildAssumingFolder('include');
138+
sdkIncludeFolder.getChildAssumingFile('dart_version.h').writeAsStringSync('');
138139
}
139140

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

0 commit comments

Comments
 (0)