diff --git a/CHANGELOG.md b/CHANGELOG.md index 111f64f3d0..15b09c12a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Gluecodium project Release Notes +## Unreleased +### Bug fixes: + * Dart: removed generation of redundant import for constants declared with external types. The redundant import caused linter warnings. + ## 13.10.1 Release date 2024-12-12 ### Bug fixes: diff --git a/functional-tests/functional/input/lime/DartExternalTypes.lime b/functional-tests/functional/input/lime/DartExternalTypes.lime index fb7b090527..3cd7c59975 100644 --- a/functional-tests/functional/input/lime/DartExternalTypes.lime +++ b/functional-tests/functional/input/lime/DartExternalTypes.lime @@ -93,3 +93,9 @@ struct VeryBoolean { value: Boolean constructor make(value: Boolean) } + +@Java(Skip) @Swift(Skip) +struct ExternalDartConstants { + const Small: Rectangle = {0, 0, 1, 1} + const Big: Rectangle = {0, 0, 10, 10} +} diff --git a/gluecodium/src/main/java/com/here/gluecodium/generator/dart/DartImportResolver.kt b/gluecodium/src/main/java/com/here/gluecodium/generator/dart/DartImportResolver.kt index 5760dd0c3e..fbac249431 100644 --- a/gluecodium/src/main/java/com/here/gluecodium/generator/dart/DartImportResolver.kt +++ b/gluecodium/src/main/java/com/here/gluecodium/generator/dart/DartImportResolver.kt @@ -50,7 +50,7 @@ internal class DartImportResolver( resolveTypeImports(limeElement.type) + resolveConversionImports(limeElement) + listOfNotNull(lazyListImport.takeIf { limeElement.attributes.have(LimeAttributeType.OPTIMIZED) }) is LimeType -> resolveTypeImports(limeElement) + resolveConversionImports(limeElement) - is LimeConstant -> resolveTypeImports(limeElement.typeRef.type) + is LimeConstant -> resolveTypeImports(limeElement.typeRef.type, skipHelpers = true) is LimeValue -> resolveValueImports(limeElement) is LimeNamedElement -> listOf(createImport(limeElement)) else -> emptyList() diff --git a/gluecodium/src/test/resources/smoke/external_types/input/DartExternalTypes.lime b/gluecodium/src/test/resources/smoke/external_types/input/DartExternalTypes.lime index 59615199e9..11e04716d3 100644 --- a/gluecodium/src/test/resources/smoke/external_types/input/DartExternalTypes.lime +++ b/gluecodium/src/test/resources/smoke/external_types/input/DartExternalTypes.lime @@ -89,3 +89,9 @@ struct DartExternalCtor { `field`: String constructor make(`field`: String) } + +@Java(Skip) @Swift(Skip) +struct ExternalDartConstants { + const Small: Rectangle = {0, 0, 1, 1} + const Big: Rectangle = {0, 0, 10, 10} +} diff --git a/gluecodium/src/test/resources/smoke/external_types/output/dart/lib/src/smoke/external_dart_constants.dart b/gluecodium/src/test/resources/smoke/external_types/output/dart/lib/src/smoke/external_dart_constants.dart new file mode 100644 index 0000000000..419f13dcef --- /dev/null +++ b/gluecodium/src/test/resources/smoke/external_types/output/dart/lib/src/smoke/external_dart_constants.dart @@ -0,0 +1,80 @@ + + +import 'dart:ffi'; +import 'dart:math' as math; +import 'package:library/src/_library_context.dart' as __lib; + + +class ExternalDartConstants { + static final math.Rectangle small = math.Rectangle(0, 0, 1, 1); + + static final math.Rectangle big = math.Rectangle(0, 0, 10, 10); + +} + + +// ExternalDartConstants "private" section, not exported. + +final _smokeExternaldartconstantsCreateHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction< + Pointer Function(), + Pointer Function() + >('library_smoke_ExternalDartConstants_create_handle')); +final _smokeExternaldartconstantsReleaseHandle = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction< + Void Function(Pointer), + void Function(Pointer) + >('library_smoke_ExternalDartConstants_release_handle')); + + + +Pointer smokeExternaldartconstantsToFfi(ExternalDartConstants value) { + final _result = _smokeExternaldartconstantsCreateHandle(); + return _result; +} + +ExternalDartConstants smokeExternaldartconstantsFromFfi(Pointer handle) { + try { + return ExternalDartConstants( + ); + } finally { + } +} + +void smokeExternaldartconstantsReleaseFfiHandle(Pointer handle) => _smokeExternaldartconstantsReleaseHandle(handle); + +// Nullable ExternalDartConstants + +final _smokeExternaldartconstantsCreateHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction< + Pointer Function(Pointer), + Pointer Function(Pointer) + >('library_smoke_ExternalDartConstants_create_handle_nullable')); +final _smokeExternaldartconstantsReleaseHandleNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction< + Void Function(Pointer), + void Function(Pointer) + >('library_smoke_ExternalDartConstants_release_handle_nullable')); +final _smokeExternaldartconstantsGetValueNullable = __lib.catchArgumentError(() => __lib.nativeLibrary.lookupFunction< + Pointer Function(Pointer), + Pointer Function(Pointer) + >('library_smoke_ExternalDartConstants_get_value_nullable')); + +Pointer smokeExternaldartconstantsToFfiNullable(ExternalDartConstants? value) { + if (value == null) return Pointer.fromAddress(0); + final _handle = smokeExternaldartconstantsToFfi(value); + final result = _smokeExternaldartconstantsCreateHandleNullable(_handle); + smokeExternaldartconstantsReleaseFfiHandle(_handle); + return result; +} + +ExternalDartConstants? smokeExternaldartconstantsFromFfiNullable(Pointer handle) { + if (handle.address == 0) return null; + final _handle = _smokeExternaldartconstantsGetValueNullable(handle); + final result = smokeExternaldartconstantsFromFfi(_handle); + smokeExternaldartconstantsReleaseFfiHandle(_handle); + return result; +} + +void smokeExternaldartconstantsReleaseFfiHandleNullable(Pointer handle) => + _smokeExternaldartconstantsReleaseHandleNullable(handle); + +// End of ExternalDartConstants "private" section. + +