-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
@Swift(OptionSet)
attribute (#1461)
Added support for `@Swift(OptionSet)` attribute. An enum marked with this attribute is generated as a Swift `struct` conforming to `OptionSet` protocol. Moreover, for each such enum `Foo`, any LIME usage of `Set<Foo>` will be `Foo` itself in Swift, per the use pattern for `OptionSet`. Resolves: #1197 Signed-off-by: Daniel Kamkha <daniel.kamkha@here.com> Signed-off-by: Daniel Kamkha <daniel.kamkha@here.com>
- Loading branch information
1 parent
ada4902
commit 65c4c39
Showing
19 changed files
with
428 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (C) 2016-2022 HERE Europe B.V. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# License-Filename: LICENSE | ||
|
||
package test | ||
|
||
@Swift(OptionSet) | ||
enum EnumOptionSet { | ||
ONE = 1, | ||
TWO = 2, | ||
THREE = 4 | ||
} | ||
|
||
@Swift(OptionSet) | ||
enum EnumOptionSetComments { | ||
ONE = 1, | ||
@Deprecated | ||
TWO = 2, | ||
// Foo bar | ||
THREE = 4 | ||
} | ||
|
||
struct UseEnumOptionSet { | ||
setField: Set<EnumOptionSet> | ||
setFieldEmpty: Set<EnumOptionSet> = [] | ||
setFieldValue: Set<EnumOptionSet> = [EnumOptionSet.ONE, EnumOptionSet.THREE] | ||
static fun roundTrip(input: Set<EnumOptionSet>): Set<EnumOptionSet> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
gluecodium/src/main/resources/templates/swift/EnumOptionSetDefinition.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{{!! | ||
! | ||
! Copyright (C) 2016-2022 HERE Europe B.V. | ||
! | ||
! Licensed under the Apache License, Version 2.0 (the "License"); | ||
! you may not use this file except in compliance with the License. | ||
! You may obtain a copy of the License at | ||
! | ||
! http://www.apache.org/licenses/LICENSE-2.0 | ||
! | ||
! Unless required by applicable law or agreed to in writing, software | ||
! distributed under the License is distributed on an "AS IS" BASIS, | ||
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
! See the License for the specific language governing permissions and | ||
! limitations under the License. | ||
! | ||
! SPDX-License-Identifier: Apache-2.0 | ||
! License-Filename: LICENSE | ||
! | ||
!}} | ||
{{>swift/TypeVisibility}} struct {{resolveName}}{{#if external.swift.converter}}_internal{{/if}} : OptionSet, CaseIterable, Codable { | ||
public let rawValue: UInt32 | ||
public init(rawValue: UInt32) { | ||
self.rawValue = rawValue | ||
} | ||
|
||
{{#set enum=this}}{{#enumerators}} | ||
{{prefixPartial "optionSetEnumerator" " "}} | ||
{{/enumerators}}{{/set}} | ||
|
||
{{resolveName "visibility"}} static var allCases: [{{resolveName}}] { | ||
return [{{#enumerators}}.{{resolveName}}{{#if iter.hasNext}}, {{/if}}{{/enumerators}}] | ||
} | ||
} | ||
{{!! | ||
}}{{+optionSetEnumerator}} | ||
{{>swift/SwiftComment}}{{>swift/SwiftAttributes}} | ||
{{resolveName "visibility"}} static let {{resolveName}} = {{!! | ||
}}{{#if isAlias}}{{resolveName explicitValue}}{{/if}}{{!! | ||
}}{{#unless isAlias}}{{resolveName enum}}(rawValue: {{resolveName explicitValue}}){{/unless}} | ||
{{/optionSetEnumerator}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
gluecodium/src/test/resources/smoke/enums/input/EnumOptionSet.lime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (C) 2016-2022 HERE Europe B.V. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# License-Filename: LICENSE | ||
|
||
package smoke | ||
|
||
@Swift(OptionSet) | ||
enum EnumOptionSet { | ||
ONE = 1, | ||
TWO = 2, | ||
THREE = 4 | ||
} | ||
|
||
@Swift(OptionSet) | ||
enum EnumOptionSetComments { | ||
ONE = 1, | ||
@Deprecated | ||
TWO = 2, | ||
// Foo bar | ||
THREE = 4 | ||
} | ||
|
||
struct UseEnumOptionSet { | ||
setField: Set<EnumOptionSet> | ||
setFieldEmpty: Set<EnumOptionSet> = [] | ||
setFieldValue: Set<EnumOptionSet> = [EnumOptionSet.ONE, EnumOptionSet.THREE] | ||
static fun roundTrip(input: Set<EnumOptionSet>): Set<EnumOptionSet> | ||
} |
Oops, something went wrong.