-
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.
Merge pull request #101 from uber/generator-pluginized_parser-master
Finish PluginizableDependencyGraphParser
- Loading branch information
Showing
16 changed files
with
378 additions
and
19 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
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
55 changes: 55 additions & 0 deletions
55
Generator/Sources/NeedleFramework/Parsing/Pluginized/Processors/PluginExtensionLinker.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,55 @@ | ||
// | ||
// 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 | ||
|
||
/// A processor that links pluginizable components with their plugin | ||
/// extensions based on type name. | ||
class PluginExtensionLinker: Processor { | ||
|
||
/// Initializer. | ||
/// | ||
/// - parameter pluginizableComponents: The pluginizable components to | ||
/// link with plugin extensions. | ||
/// - parameter pluginExtensions: The non-core components to link. | ||
init(pluginizableComponents: [PluginizableASTComponent], pluginExtensions: [PluginExtension]) { | ||
self.pluginizableComponents = pluginizableComponents | ||
self.pluginExtensions = pluginExtensions | ||
} | ||
|
||
/// Process the data models. | ||
/// | ||
/// - throws: `ProcessingError` if some pluginized components cannot | ||
/// find matching plugin extensions. | ||
func process() throws { | ||
var extensionMap = [String: PluginExtension]() | ||
for pluginExtension in pluginExtensions { | ||
extensionMap[pluginExtension.name] = pluginExtension | ||
} | ||
|
||
for pluginizableComponent in pluginizableComponents { | ||
pluginizableComponent.pluginExtension = extensionMap[pluginizableComponent.pluginExtensionType] | ||
if pluginizableComponent.pluginExtension == nil { | ||
throw ProcessingError.fail("Cannot find \(pluginizableComponent.data.name)'s plugin extension with type name \(pluginizableComponent.pluginExtensionType)") | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Private | ||
|
||
private let pluginizableComponents: [PluginizableASTComponent] | ||
private let pluginExtensions: [PluginExtension] | ||
} |
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
4 changes: 4 additions & 0 deletions
4
Generator/Tests/NeedleFrameworkTests/Fixtures/Pluginized/OnlyPluginizedComponent.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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import UIKit | ||
import RIBs; import Foundation | ||
|
||
class ANonCoreComponent: NonCoreComponent<EmptyDependency> {} | ||
|
||
protocol BExtension: PluginExtension {} | ||
|
||
class SomePluginizedCompo: PluginizedComponent<ADependency, BExtension, ANonCoreComponent>, Stuff { | ||
} |
52 changes: 52 additions & 0 deletions
52
Generator/Tests/NeedleFrameworkTests/Parsing/DependencyLinkerTests.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,52 @@ | ||
// | ||
// 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 XCTest | ||
@testable import NeedleFramework | ||
|
||
class DependencyLinkerTests: AbstractParserTests { | ||
|
||
static var allTests = [ | ||
("test_process_withComponents_verifyLinkages", test_process_withComponents_verifyLinkages), | ||
("test_process_withComponentsNoDependency_verifyError", test_process_withComponentsNoDependency_verifyError) | ||
] | ||
|
||
func test_process_withComponents_verifyLinkages() { | ||
let component = ASTComponent(name: "SomeComp", dependencyProtocolName: "ItsDependency", properties: [], expressionCallTypeNames: []) | ||
let dependency = Dependency(name: "ItsDependency", properties: []) | ||
|
||
let linker = DependencyLinker(components: [component], dependencies: [dependency]) | ||
|
||
try! linker.process() | ||
|
||
XCTAssertEqual(component.dependencyProtocol, dependency) | ||
} | ||
|
||
func test_process_withComponentsNoDependency_verifyError() { | ||
let component = ASTComponent(name: "SomeComp", dependencyProtocolName: "ItsDependency", properties: [], expressionCallTypeNames: []) | ||
let dependency = Dependency(name: "WrongDep", properties: []) | ||
|
||
let linker = DependencyLinker(components: [component], dependencies: [dependency]) | ||
|
||
do { | ||
try linker.process() | ||
XCTFail() | ||
} catch ProcessingError.fail(_) { | ||
} catch { | ||
XCTFail() | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
Generator/Tests/NeedleFrameworkTests/Parsing/ParentLinkerTests.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,36 @@ | ||
// | ||
// 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 XCTest | ||
@testable import NeedleFramework | ||
|
||
class ParentLinkerTests: AbstractParserTests { | ||
|
||
static var allTests = [ | ||
("test_process_withComponents_verifyLinkages", test_process_withComponents_verifyLinkages), | ||
] | ||
|
||
func test_process_withComponents_verifyLinkages() { | ||
let parentComponent = ASTComponent(name: "ParentComp", dependencyProtocolName: "Doesn't matter", properties: [], expressionCallTypeNames: ["ChildComp", "someOtherStuff"]) | ||
let childComp = ASTComponent(name: "ChildComp", dependencyProtocolName: "Still doesn't matter", properties: [], expressionCallTypeNames: []) | ||
|
||
let linker = ParentLinker(components: [parentComponent, childComp]) | ||
try! linker.process() | ||
|
||
XCTAssertEqual(childComp.parents.count, 1) | ||
XCTAssertTrue(childComp.parents[0] === parentComponent) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
Generator/Tests/NeedleFrameworkTests/Parsing/Pluginized/NonCoreComponentLinkerTests.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,54 @@ | ||
// | ||
// 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 XCTest | ||
@testable import NeedleFramework | ||
|
||
class NonCoreComponentLinkerTests: AbstractParserTests { | ||
|
||
static var allTests = [ | ||
("test_process_withComponents_verifyLinkages", test_process_withComponents_verifyLinkages), | ||
("test_process_withComponentsNoNonCoreComp_verifyError", test_process_withComponentsNoNonCoreComp_verifyError), | ||
] | ||
|
||
func test_process_withComponents_verifyLinkages() { | ||
let data = ASTComponent(name: "SomePluginizedComp", dependencyProtocolName: "Doesn't matter", properties: [], expressionCallTypeNames: []) | ||
let pluginizedComp = PluginizableASTComponent(data: data, pluginExtensionType: "Doesn't matter", nonCoreComponentType: "SomeComp") | ||
let nonCoreComponent = ASTComponent(name: "SomeComp", dependencyProtocolName: "ItsDependency", properties: [], expressionCallTypeNames: []) | ||
|
||
let linker = NonCoreComponentLinker(pluginizableComponents: [pluginizedComp], nonCoreComponents: [nonCoreComponent]) | ||
|
||
try! linker.process() | ||
|
||
XCTAssertTrue(pluginizedComp.nonCoreComponent === nonCoreComponent) | ||
} | ||
|
||
func test_process_withComponentsNoNonCoreComp_verifyError() { | ||
let data = ASTComponent(name: "SomePluginizedComp", dependencyProtocolName: "Doesn't matter", properties: [], expressionCallTypeNames: []) | ||
let pluginizedComp = PluginizableASTComponent(data: data, pluginExtensionType: "Doesn't matter", nonCoreComponentType: "SomeComp") | ||
let nonCoreComponent = ASTComponent(name: "WrongNonCoreComp", dependencyProtocolName: "ItsDependency", properties: [], expressionCallTypeNames: []) | ||
|
||
let linker = NonCoreComponentLinker(pluginizableComponents: [pluginizedComp], nonCoreComponents: [nonCoreComponent]) | ||
|
||
do { | ||
try linker.process() | ||
XCTFail() | ||
} catch ProcessingError.fail(_) { | ||
} catch { | ||
XCTFail() | ||
} | ||
} | ||
} |
Oops, something went wrong.