Skip to content

Commit 101955c

Browse files
authored
Merge pull request #182 from devmil/fix/181-adding-static-methods-should-not-be-breaking
adding static methods should not be breaking
2 parents 380eb85 + e34f409 commit 101955c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+841
-202
lines changed

.fvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"flutter": "3.19.5",
2+
"flutter": "3.22.2",
33
"flavors": {}
44
}

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Version 0.19.0
44
- introduces `force-use-flutter` option for all commands to force dart_apitool to use the `flutter` command.
55
- extend type usage tracking and fix situations in which types that are used in @visibleForTesting contexts were detected as not exported
6+
- fix: don't treat adding static elements (methods, fields) or consts to a required interface as breaking
67

78
## Version 0.18.0
89
- add missing export to json output for `extract` command

lib/src/analyze/package_api_analyzer.freezed.dart

+14-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ mixin _$FileToAnalyzeEntry {
2121
List<String> get hiddenNames => throw _privateConstructorUsedError;
2222
Set<String> get exportedBy => throw _privateConstructorUsedError;
2323

24-
@JsonKey(ignore: true)
24+
/// Create a copy of _FileToAnalyzeEntry
25+
/// with the given fields replaced by the non-null parameter values.
26+
@JsonKey(includeFromJson: false, includeToJson: false)
2527
_$FileToAnalyzeEntryCopyWith<_FileToAnalyzeEntry> get copyWith =>
2628
throw _privateConstructorUsedError;
2729
}
@@ -49,6 +51,8 @@ class __$FileToAnalyzeEntryCopyWithImpl<$Res, $Val extends _FileToAnalyzeEntry>
4951
// ignore: unused_field
5052
final $Res Function($Val) _then;
5153

54+
/// Create a copy of _FileToAnalyzeEntry
55+
/// with the given fields replaced by the non-null parameter values.
5256
@pragma('vm:prefer-inline')
5357
@override
5458
$Res call({
@@ -101,6 +105,8 @@ class __$$_FileToAnalyzeEntryImplCopyWithImpl<$Res>
101105
$Res Function(_$_FileToAnalyzeEntryImpl) _then)
102106
: super(_value, _then);
103107

108+
/// Create a copy of _FileToAnalyzeEntry
109+
/// with the given fields replaced by the non-null parameter values.
104110
@pragma('vm:prefer-inline')
105111
@override
106112
$Res call({
@@ -198,7 +204,9 @@ class _$_FileToAnalyzeEntryImpl implements __FileToAnalyzeEntry {
198204
const DeepCollectionEquality().hash(_hiddenNames),
199205
const DeepCollectionEquality().hash(_exportedBy));
200206

201-
@JsonKey(ignore: true)
207+
/// Create a copy of _FileToAnalyzeEntry
208+
/// with the given fields replaced by the non-null parameter values.
209+
@JsonKey(includeFromJson: false, includeToJson: false)
202210
@override
203211
@pragma('vm:prefer-inline')
204212
_$$_FileToAnalyzeEntryImplCopyWith<_$_FileToAnalyzeEntryImpl> get copyWith =>
@@ -221,8 +229,11 @@ abstract class __FileToAnalyzeEntry implements _FileToAnalyzeEntry {
221229
List<String> get hiddenNames;
222230
@override
223231
Set<String> get exportedBy;
232+
233+
/// Create a copy of _FileToAnalyzeEntry
234+
/// with the given fields replaced by the non-null parameter values.
224235
@override
225-
@JsonKey(ignore: true)
236+
@JsonKey(includeFromJson: false, includeToJson: false)
226237
_$$_FileToAnalyzeEntryImplCopyWith<_$_FileToAnalyzeEntryImpl> get copyWith =>
227238
throw _privateConstructorUsedError;
228239
}

lib/src/diff/package_api_differ.dart

+37-29
Original file line numberDiff line numberDiff line change
@@ -274,38 +274,44 @@ class PackageApiDiffer {
274274
final changes = <ApiChange>[];
275275
for (final oldEx in executableListDiff.matches.keys) {
276276
final newEx = executableListDiff.matches[oldEx]!;
277-
changes.addAll(_calculateExecutableDiff(
278-
oldEx,
279-
newEx,
280-
context,
281-
isInterfaceRequired: isInterfaceRequired,
282-
isExperimental: newEx.isExperimental || isExperimental,
283-
typeHierarchy: typeHierarchy,
284-
));
277+
changes.addAll(
278+
_calculateExecutableDiff(
279+
oldEx,
280+
newEx,
281+
context,
282+
isInterfaceRequired: isInterfaceRequired,
283+
isExperimental: newEx.isExperimental || isExperimental,
284+
typeHierarchy: typeHierarchy,
285+
),
286+
);
285287
}
286288
for (final removedExecutable in executableListDiff.remainingOld) {
287-
changes.add(ApiChange(
288-
changeCode: ApiChangeCode.ce10,
289-
affectedDeclaration: removedExecutable,
290-
contextTrace: _contextTraceFromStack(context),
291-
type: ApiChangeType.remove,
292-
isExperimental: isExperimental,
293-
changeDescription:
294-
'${_getExecutableTypeName(removedExecutable.type, context.isNotEmpty)} "${removedExecutable.name}" removed',
295-
));
289+
changes.add(
290+
ApiChange(
291+
changeCode: ApiChangeCode.ce10,
292+
affectedDeclaration: removedExecutable,
293+
contextTrace: _contextTraceFromStack(context),
294+
type: ApiChangeType.remove,
295+
isExperimental: isExperimental,
296+
changeDescription:
297+
'${_getExecutableTypeName(removedExecutable.type, context.isNotEmpty)} "${removedExecutable.name}" removed',
298+
),
299+
);
296300
}
297301
for (final addedExecutable in executableListDiff.remainingNew) {
298-
changes.add(ApiChange(
299-
changeCode: ApiChangeCode.ce11,
300-
affectedDeclaration: addedExecutable,
301-
contextTrace: _contextTraceFromStack(context),
302-
type: isInterfaceRequired ?? false
303-
? ApiChangeType.addBreaking
304-
: ApiChangeType.addCompatibleMinor,
305-
isExperimental: isExperimental,
306-
changeDescription:
307-
'${_getExecutableTypeName(addedExecutable.type, context.isNotEmpty)} "${addedExecutable.name}" added${(isInterfaceRequired ?? false) ? ' (required)' : ''}',
308-
));
302+
changes.add(
303+
ApiChange(
304+
changeCode: ApiChangeCode.ce11,
305+
affectedDeclaration: addedExecutable,
306+
contextTrace: _contextTraceFromStack(context),
307+
type: (isInterfaceRequired ?? false) && !addedExecutable.isStatic
308+
? ApiChangeType.addBreaking
309+
: ApiChangeType.addCompatibleMinor,
310+
isExperimental: isExperimental,
311+
changeDescription:
312+
'${_getExecutableTypeName(addedExecutable.type, context.isNotEmpty)} "${addedExecutable.name}" added${(isInterfaceRequired ?? false) ? ' (required)' : ''}',
313+
),
314+
);
309315
}
310316
return changes;
311317
}
@@ -823,7 +829,9 @@ class PackageApiDiffer {
823829
changeCode: ApiChangeCode.cf02,
824830
affectedDeclaration: addedField,
825831
contextTrace: _contextTraceFromStack(context),
826-
type: (isInterfaceRequired ?? false)
832+
type: (isInterfaceRequired ?? false) &&
833+
!addedField.isStatic &&
834+
!addedField.isConst
827835
? ApiChangeType.addBreaking
828836
: ApiChangeType.addCompatibleMinor,
829837
isExperimental: isExperimental,

lib/src/model/executable_declaration.freezed.dart

+48-28
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ mixin _$ExecutableParameterDeclaration {
4040
/// the relative path of the library
4141
String get relativePath => throw _privateConstructorUsedError;
4242

43-
@JsonKey(ignore: true)
43+
/// Create a copy of ExecutableParameterDeclaration
44+
/// with the given fields replaced by the non-null parameter values.
45+
@JsonKey(includeFromJson: false, includeToJson: false)
4446
$ExecutableParameterDeclarationCopyWith<ExecutableParameterDeclaration>
4547
get copyWith => throw _privateConstructorUsedError;
4648
}
@@ -75,6 +77,8 @@ class _$ExecutableParameterDeclarationCopyWithImpl<$Res,
7577
// ignore: unused_field
7678
final $Res Function($Val) _then;
7779

80+
/// Create a copy of ExecutableParameterDeclaration
81+
/// with the given fields replaced by the non-null parameter values.
7882
@pragma('vm:prefer-inline')
7983
@override
8084
$Res call({
@@ -154,6 +158,8 @@ class __$$ExecutableParameterDeclarationImplCopyWithImpl<$Res>
154158
$Res Function(_$ExecutableParameterDeclarationImpl) _then)
155159
: super(_value, _then);
156160

161+
/// Create a copy of ExecutableParameterDeclaration
162+
/// with the given fields replaced by the non-null parameter values.
157163
@pragma('vm:prefer-inline')
158164
@override
159165
$Res call({
@@ -288,7 +294,9 @@ class _$ExecutableParameterDeclarationImpl
288294
typeFullLibraryName,
289295
relativePath);
290296

291-
@JsonKey(ignore: true)
297+
/// Create a copy of ExecutableParameterDeclaration
298+
/// with the given fields replaced by the non-null parameter values.
299+
@JsonKey(includeFromJson: false, includeToJson: false)
292300
@override
293301
@pragma('vm:prefer-inline')
294302
_$$ExecutableParameterDeclarationImplCopyWith<
@@ -311,40 +319,42 @@ abstract class _ExecutableParameterDeclaration
311319
_$ExecutableParameterDeclarationImpl;
312320
const _ExecutableParameterDeclaration._() : super._();
313321

314-
@override
315-
316322
/// whether the parameter is required
317-
bool get isRequired;
318323
@override
324+
bool get isRequired;
319325

320326
/// whether the parameter is named
321-
bool get isNamed;
322327
@override
328+
bool get isNamed;
323329

324330
/// the name of the parameter
325-
String get name;
326331
@override
332+
String get name;
327333

328334
/// whether the parameter is deprecated
329-
bool get isDeprecated;
330335
@override
336+
bool get isDeprecated;
331337

332338
/// whether the parameter is experimental
333-
bool get isExperimental;
334339
@override
340+
bool get isExperimental;
335341

336342
/// type name of this parameter
337-
String get typeName;
338343
@override
344+
String get typeName;
339345

340346
/// the type library path
341-
String? get typeFullLibraryName;
342347
@override
348+
String? get typeFullLibraryName;
343349

344350
/// the relative path of the library
351+
@override
345352
String get relativePath;
353+
354+
/// Create a copy of ExecutableParameterDeclaration
355+
/// with the given fields replaced by the non-null parameter values.
346356
@override
347-
@JsonKey(ignore: true)
357+
@JsonKey(includeFromJson: false, includeToJson: false)
348358
_$$ExecutableParameterDeclarationImplCopyWith<
349359
_$ExecutableParameterDeclarationImpl>
350360
get copyWith => throw _privateConstructorUsedError;
@@ -385,7 +395,9 @@ mixin _$ExecutableDeclaration {
385395
/// the relative path of the library
386396
String get relativePath => throw _privateConstructorUsedError;
387397

388-
@JsonKey(ignore: true)
398+
/// Create a copy of ExecutableDeclaration
399+
/// with the given fields replaced by the non-null parameter values.
400+
@JsonKey(includeFromJson: false, includeToJson: false)
389401
$ExecutableDeclarationCopyWith<ExecutableDeclaration> get copyWith =>
390402
throw _privateConstructorUsedError;
391403
}
@@ -421,6 +433,8 @@ class _$ExecutableDeclarationCopyWithImpl<$Res,
421433
// ignore: unused_field
422434
final $Res Function($Val) _then;
423435

436+
/// Create a copy of ExecutableDeclaration
437+
/// with the given fields replaced by the non-null parameter values.
424438
@pragma('vm:prefer-inline')
425439
@override
426440
$Res call({
@@ -517,6 +531,8 @@ class __$$ExecutableDeclarationImplCopyWithImpl<$Res>
517531
$Res Function(_$ExecutableDeclarationImpl) _then)
518532
: super(_value, _then);
519533

534+
/// Create a copy of ExecutableDeclaration
535+
/// with the given fields replaced by the non-null parameter values.
520536
@pragma('vm:prefer-inline')
521537
@override
522538
$Res call({
@@ -716,7 +732,9 @@ class _$ExecutableDeclarationImpl extends _ExecutableDeclaration {
716732
const DeepCollectionEquality().hash(_entryPoints),
717733
relativePath);
718734

719-
@JsonKey(ignore: true)
735+
/// Create a copy of ExecutableDeclaration
736+
/// with the given fields replaced by the non-null parameter values.
737+
@JsonKey(includeFromJson: false, includeToJson: false)
720738
@override
721739
@pragma('vm:prefer-inline')
722740
_$$ExecutableDeclarationImplCopyWith<_$ExecutableDeclarationImpl>
@@ -739,50 +757,52 @@ abstract class _ExecutableDeclaration extends ExecutableDeclaration {
739757
required final String relativePath}) = _$ExecutableDeclarationImpl;
740758
const _ExecutableDeclaration._() : super._();
741759

742-
@override
743-
744760
/// name of the return type
745-
String get returnTypeName;
746-
@override // full library name of the return type
747-
String? get returnTypeFullLibraryName;
748761
@override
762+
String get returnTypeName; // full library name of the return type
763+
@override
764+
String? get returnTypeFullLibraryName;
749765

750766
/// name of the executable
751-
String get name;
752767
@override
768+
String get name;
753769

754770
/// whether the executable is deprecated
755-
bool get isDeprecated;
756771
@override
772+
bool get isDeprecated;
757773

758774
/// whether the executable is experimental
759-
bool get isExperimental;
760775
@override
776+
bool get isExperimental;
761777

762778
/// list of the executables parameters ([ExecutableOParameterDeclaration]s)
763-
List<ExecutableParameterDeclaration> get parameters;
764779
@override
780+
List<ExecutableParameterDeclaration> get parameters;
765781

766782
/// type parameter names of this executable
767-
List<String> get typeParameterNames;
768783
@override
784+
List<String> get typeParameterNames;
769785

770786
/// type of the executable
771-
ExecutableType get type;
772787
@override
788+
ExecutableType get type;
773789

774790
/// whether the executable is a static method
775-
bool get isStatic;
776791
@override
792+
bool get isStatic;
777793

778794
/// entry points for this executable
779-
Set<String>? get entryPoints;
780795
@override
796+
Set<String>? get entryPoints;
781797

782798
/// the relative path of the library
799+
@override
783800
String get relativePath;
801+
802+
/// Create a copy of ExecutableDeclaration
803+
/// with the given fields replaced by the non-null parameter values.
784804
@override
785-
@JsonKey(ignore: true)
805+
@JsonKey(includeFromJson: false, includeToJson: false)
786806
_$$ExecutableDeclarationImplCopyWith<_$ExecutableDeclarationImpl>
787807
get copyWith => throw _privateConstructorUsedError;
788808
}

lib/src/model/field_declaration.dart

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class FieldDeclaration with _$FieldDeclaration implements Declaration {
3131
/// whether this field is static
3232
required bool isStatic,
3333

34+
/// whether this field is a constant
35+
required bool isConst,
36+
3437
/// whether this field is experimental
3538
required bool isExperimental,
3639

0 commit comments

Comments
 (0)