-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Code generated is guarded so current behavior is not affected - Both paths are generated in the same file, the parsing of the `#if` should not slow things down - Addresses #432
- Loading branch information
Showing
8 changed files
with
308 additions
and
14 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
35 changes: 35 additions & 0 deletions
35
.../Sources/NeedleFramework/Generating/Pluginized/PluginExtensionDynamicSerializerTask.swift
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,35 @@ | ||
// | ||
// PluginExtensionDynamicSerializerTask.swift | ||
// | ||
// | ||
// Created by Rudro Samanta on 7/1/22. | ||
// | ||
|
||
import Concurrency | ||
import Foundation | ||
|
||
/// The task that generates the declaration and registration of the | ||
/// plugin extension provider for a specific pluginized component. | ||
class PluginExtensionDynamicSerializerTask : AbstractTask<SerializedProvider> { | ||
|
||
/// Initializer. | ||
/// | ||
/// - parameter component: The pluginized component that requires the | ||
/// plugin extension provider. | ||
init(component: PluginizedComponent) { | ||
self.component = component | ||
super.init(id: TaskIds.pluginExtensionSerializerTask.rawValue) | ||
} | ||
|
||
/// Execute the task and returns the data model. | ||
/// | ||
/// - returns: The `SerializedProvider`. | ||
override func execute() -> SerializedProvider { | ||
let content = PluginExtensionDynamicContentSerializer(component: component).serialize() | ||
return SerializedProvider(content: content, registration: "", attributes: ProviderAttributes()) | ||
} | ||
|
||
// MARK: - Private | ||
|
||
private let component: PluginizedComponent | ||
} |
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
51 changes: 51 additions & 0 deletions
51
...leFramework/Generating/Pluginized/PluginizedDynamicDependencyProviderSerializerTask.swift
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,51 @@ | ||
// | ||
// Copyright (c) 2018. Uber Technologies | ||
// | ||
// 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. | ||
// | ||
|
||
import Concurrency | ||
import Foundation | ||
|
||
/// The task that serializes a list of pluginized processed dependency | ||
/// providers into exportable foramt. | ||
class PluginizedDynamicDependencyProviderSerializerTask: AbstractTask<[SerializedProvider]> { | ||
|
||
/// Initializer. | ||
/// | ||
/// - parameter providers: The pluginized processed dependency provider | ||
/// to serialize. | ||
init(component: Component, providers: [PluginizedProcessedDependencyProvider]) { | ||
self.component = component | ||
self.providers = providers | ||
super.init(id: TaskIds.pluginizedDependencyProviderSerializerTask.rawValue) | ||
} | ||
|
||
/// Execute the task and returns the in-memory serialized dependency | ||
/// provider data models. | ||
/// | ||
/// - returns: The list of `SerializedProvider`. | ||
override func execute() -> [SerializedProvider] { | ||
guard !providers.isEmpty else { | ||
return [] | ||
} | ||
let serilizer = DependencyPropsSerializer(component: component) | ||
let result = SerializedProvider(content: serilizer.serialize(), registration: "", attributes: ProviderAttributes()) | ||
return [result] | ||
} | ||
|
||
// MARK: - Private | ||
|
||
private let component: Component | ||
private let providers: [PluginizedProcessedDependencyProvider] | ||
} |
67 changes: 67 additions & 0 deletions
67
Generator/Sources/NeedleFramework/Generating/Serializers/DependencyPropsSerializer.swift
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,67 @@ | ||
// | ||
// Copyright (c) 2018. Uber Technologies | ||
// | ||
// 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. | ||
// | ||
|
||
import Foundation | ||
|
||
class DependencyPropsSerializer: Serializer { | ||
|
||
init(component: Component) { | ||
self.component = component | ||
} | ||
|
||
func serialize() -> String { | ||
if component.isLeaf { | ||
return """ | ||
extension \(component.name): Registration { | ||
public func registerItems() { | ||
\(serialize(component.dependency)) | ||
} | ||
} | ||
""" | ||
} else { | ||
return """ | ||
extension \(component.name): Registration { | ||
public func registerItems() { | ||
\(serialize(component.dependency)) | ||
\(serialize(component.properties)) | ||
} | ||
} | ||
""" | ||
} | ||
} | ||
|
||
// MARK: - Private | ||
|
||
private func serialize(_ dependency: Dependency) -> String { | ||
let dependencyName = dependency.name | ||
return dependency.properties.map { property in | ||
return " keyPathToName[\\\(dependencyName).\(property.name)] = \"\(property.name)-\(property.type)\"" | ||
}.joined(separator: "\n") | ||
} | ||
|
||
private func serialize(_ properties: [Property]) -> String { | ||
return properties.filter { property in | ||
!property.isInternal | ||
}.map { property in | ||
return " localTable[\"\(property.name)-\(property.type)\"] = { self.\(property.name) as Any }" | ||
}.joined(separator: "\n") | ||
} | ||
|
||
private let component: Component | ||
} | ||
|
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
Oops, something went wrong.