diff method
calculates a diff between oldApi
and newApi
Implementation
PackageApiDiffResult diff({
required PackageApi oldApi,
required PackageApi newApi,
}) {
if (oldApi.packageName != newApi.packageName) {
throw PackageApiDiffError(
message:
'Got different packages. Can\'t create diff. Old Package = "${oldApi.packageName}", New Package = "${newApi.packageName}"');
}
if (!SetEquality<PackageApiSemantics>()
.equals(oldApi.semantics, newApi.semantics)) {
throw PackageApiDiffError(
message:
'Given models have different semantics. Old Package: ${oldApi.semantics}, New Package: ${newApi.semantics}');
}
try {
final changes = [
..._calculateInterfacesDiff(
oldApi.interfaceDeclarations,
newApi.interfaceDeclarations,
Stack<Declaration>(),
isExperimental: false,
typeHierarchy: newApi.typeHierarchy,
),
..._calculateExecutablesDiff(
oldApi.executableDeclarations,
newApi.executableDeclarations,
Stack<Declaration>(),
isExperimental: false,
typeHierarchy: newApi.typeHierarchy,
),
..._calculateFieldsDiff(
oldApi.fieldDeclarations,
newApi.fieldDeclarations,
Stack<Declaration>(),
isExperimental: false,
typeHierarchy: newApi.typeHierarchy,
),
..._calculateIOSPlatformConstraintsDiff(
oldApi.iosPlatformConstraints,
newApi.iosPlatformConstraints,
isExperimental: false,
),
..._calculateAndroidPlatformConstraintsDiff(
oldApi.androidPlatformConstraints,
newApi.androidPlatformConstraints,
isExperimental: false,
),
..._calculateSdkDiff(
oldApi,
newApi,
isExperimental: false,
doCheckSdkVersion: options.doCheckSdkVersion,
),
..._calculatePackageDependenciesDiff(
oldApi,
newApi,
isExperimental: false,
),
];
return PackageApiDiffResult()..addApiChanges(changes);
} on Object catch (e, t) {
throw PackageApiDiffError(
message: 'Error while creating the diff: $e $t');
}
}