Skip to content

Commit 2ea59ef

Browse files
committed
Remove the deprecated requireLibraryDirective param
1 parent 52a727a commit 2ea59ef

File tree

4 files changed

+18
-62
lines changed

4 files changed

+18
-62
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.8.0
2+
3+
* **BREAKING** removed the deprecated `requireLibraryDirective` parameter in
4+
`PartBuilder`.
5+
16
## 0.7.6
27

38
* `TypeChecker` now throws an `UnresolvedAnnotationException` with a more

lib/src/builder.dart

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,24 @@ class _Builder extends Builder {
2929
/// Whether to emit a standalone (non-`part`) file in this builder.
3030
final bool _isStandalone;
3131

32-
final bool _requireLibraryDirective;
33-
3432
final String _header;
3533

3634
@override
3735
final Map<String, List<String>> buildExtensions;
3836

3937
/// Wrap [_generators] to form a [Builder]-compatible API.
40-
_Builder(
41-
this._generators,
38+
_Builder(this._generators,
4239
{String formatOutput(String code),
4340
String generatedExtension: '.g.dart',
4441
List<String> additionalOutputExtensions: const [],
4542
bool isStandalone: false,
46-
@Deprecated(
47-
'Library directives are no longer required for part generation. '
48-
'This option will be removed in v0.8.0.')
49-
bool requireLibraryDirective: false,
5043
String header})
5144
: _generatedExtension = generatedExtension,
5245
buildExtensions = {
5346
'.dart': [generatedExtension]..addAll(additionalOutputExtensions)
5447
},
5548
_isStandalone = isStandalone,
5649
formatOutput = formatOutput ?? _formatter.format,
57-
// ignore: deprecated_member_use
58-
_requireLibraryDirective = requireLibraryDirective,
5950
_header = header ?? defaultFileHeader {
6051
if (_generatedExtension == null) {
6152
throw new ArgumentError.notNull('generatedExtension');
@@ -106,7 +97,6 @@ class _Builder extends Builder {
10697
var name = nameOfPartial(
10798
library,
10899
asset,
109-
allowUnnamedPartials: !_requireLibraryDirective,
110100
);
111101
if (name == null) {
112102
var suggest = suggestLibraryName(asset);
@@ -126,12 +116,13 @@ class _Builder extends Builder {
126116
}
127117

128118
for (var output in generatedOutputs) {
129-
contentBuffer..writeln('')
130-
..writeln(_headerLine)
131-
..writeln('// Generator: ${output.generator}')
132-
..writeln(_headerLine)
133-
..writeln('')
134-
..writeln(output.output);
119+
contentBuffer
120+
..writeln('')
121+
..writeln(_headerLine)
122+
..writeln('// Generator: ${output.generator}')
123+
..writeln(_headerLine)
124+
..writeln('')
125+
..writeln(output.output);
135126
}
136127

137128
var genPartContent = contentBuffer.toString();
@@ -175,32 +166,15 @@ class PartBuilder extends _Builder {
175166
/// [header] is used to specify the content at the top of each generated file.
176167
/// If `null`, the content of [defaultFileHeader] is used.
177168
/// If [header] is an empty `String` no header is added.
178-
///
179-
/// May set [requireLibraryDirective] to `true` in order to opt-out of the
180-
/// Dart `2.0.0-dev` feature of `part of` being usable without an explicit
181-
/// `library` directive. Developers should restrict their `pubspec`
182-
/// accordingly:
183-
/// ```yaml
184-
/// sdk: '>=2.0.0-dev <2.0.0'
185-
/// ```
186-
///
187-
/// This option will be removed in version 0.8.0 of `source_gen`.
188-
PartBuilder(
189-
List<Generator> generators,
169+
PartBuilder(List<Generator> generators,
190170
{String formatOutput(String code),
191171
String generatedExtension: '.g.dart',
192172
List<String> additionalOutputExtensions: const [],
193-
@Deprecated(
194-
'Library directives are no longer required for part generation. '
195-
'This option will be removed in v0.8.0.')
196-
bool requireLibraryDirective: false,
197173
String header})
198174
: super(generators,
199175
formatOutput: formatOutput,
200176
generatedExtension: generatedExtension,
201177
additionalOutputExtensions: additionalOutputExtensions,
202-
// ignore: deprecated_member_use
203-
requireLibraryDirective: requireLibraryDirective,
204178
header: header);
205179
}
206180

lib/src/utils.dart

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,13 @@ String typeNameOf(DartType type) {
6363
/// Returns a name suitable for `part of "..."` when pointing to [element].
6464
///
6565
/// Returns `null` if [element] is missing identifier.
66-
///
67-
/// Starting in `1.25.0`, setting [allowUnnamedPartials] will fallback
68-
/// (actually, preferred) to `'part of "package:foo/path.dart'`, and null will
69-
/// never be returned.
70-
String nameOfPartial(
71-
LibraryElement element,
72-
AssetId source, {
73-
bool allowUnnamedPartials: false,
74-
}) {
66+
String nameOfPartial(LibraryElement element, AssetId source) {
7567
if (element.name != null && element.name.isNotEmpty) {
7668
return element.name;
7769
}
78-
if (allowUnnamedPartials) {
79-
var sourceUrl = p.basename(source.uri.toString());
80-
return '\'$sourceUrl\'';
81-
}
82-
return null;
70+
71+
var sourceUrl = p.basename(source.uri.toString());
72+
return '\'$sourceUrl\'';
8373
}
8474

8575
/// Returns a suggested library identifier based on [source] path and package.

test/builder_test.dart

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,6 @@ void main() {
7979
outputs: {'$pkgName|lib/test_lib.g.dart': _testGenNoLibrary});
8080
});
8181

82-
test(
83-
'Throws when no library identifier and requireLibraryDirective is `true`',
84-
() async {
85-
var sources = _createPackageStub(pkgName, testLibContent: 'class A {}');
86-
var builder = new PartBuilder([const CommentGenerator()],
87-
// ignore: deprecated_member_use
88-
requireLibraryDirective: true);
89-
expect(
90-
testBuilder(builder, sources,
91-
outputs: {'$pkgName|lib/test_lib.g.dart': ''}),
92-
throwsA(const isInstanceOf<InvalidGenerationSourceError>()));
93-
});
94-
9582
test('Does not fail when there is no output', () async {
9683
var sources = _createPackageStub(pkgName, testLibContent: 'class A {}');
9784
var builder = new PartBuilder([const CommentGenerator(forClasses: false)]);

0 commit comments

Comments
 (0)