Skip to content

Commit 4b06c68

Browse files
authored
Workaround for isInSdk (#1654)
* Make PackageMeta.fromElement work without isInSdk * Tests were verifying the wrong thing.
1 parent 865b502 commit 4b06c68

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

lib/src/model.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,8 +2014,6 @@ class Library extends ModelElement with Categorization {
20142014

20152015
bool get isAnonymous => element.name == null || element.name.isEmpty;
20162016

2017-
bool get isInSdk => _libraryElement.isInSdk;
2018-
20192017
@override
20202018
String get kind => 'library';
20212019

lib/src/package_meta.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ abstract class PackageMeta {
2222

2323
/// Use this instead of fromDir where possible.
2424
factory PackageMeta.fromElement(LibraryElement libraryElement) {
25-
if (libraryElement.isInSdk) return new PackageMeta.fromDir(getSdkDir());
25+
// Workaround for dart-lang/sdk#32707. Replace with isInSdk once that works.
26+
if (libraryElement.source.uri.scheme == 'dart') return new PackageMeta.fromDir(getSdkDir());
2627
return new PackageMeta.fromDir(
2728
new File(pathLib.canonicalize(libraryElement.source.fullName)).parent);
2829
}

test/dartdoc_test.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,24 +122,23 @@ void main() {
122122
expect(p.libraries.map((lib) => lib.name).contains('dart:core'), isTrue);
123123
expect(p.libraries.map((lib) => lib.name).contains('dart:async'), isTrue);
124124
expect(p.libraries.map((lib) => lib.name).contains('dart:bear'), isTrue);
125-
expect(p.packages.length, equals(2));
126-
// Things that do not override the core SDK belong in their own package?
125+
expect(p.packages.length, equals(1));
126+
// Things that do not override the core SDK do not belong in their own package.
127127
expect(p.packages["Dart"].isSdk, isTrue);
128-
expect(p.packages["test_package_embedder_yaml"].isSdk, isFalse);
129-
expect(
130-
p.publicLibraries,
131-
everyElement((Library l) =>
132-
(l.element as LibraryElement).isInSdk == l.packageMeta.isSdk));
128+
expect(p.packages["test_package_embedder_yaml"], isNull);
129+
// Should be true once dart-lang/sdk#32707 is fixed.
130+
//expect(
131+
// p.publicLibraries,
132+
// everyElement((Library l) =>
133+
// (l.element as LibraryElement).isInSdk == l.packageMeta.isSdk));
133134
// Ensure that we actually parsed some source by checking for
134135
// the 'Bear' class.
135136
Library dart_bear =
136137
p.libraries.firstWhere((lib) => lib.name == 'dart:bear');
137138
expect(dart_bear, isNotNull);
138139
expect(
139140
dart_bear.allClasses.map((cls) => cls.name).contains('Bear'), isTrue);
140-
expect(p.packages["test_package_embedder_yaml"].publicLibraries,
141-
contains(dart_bear));
142-
expect(p.packages["Dart"].publicLibraries, hasLength(2));
141+
expect(p.packages["Dart"].publicLibraries, hasLength(3));
143142
});
144143
});
145144
}

0 commit comments

Comments
 (0)