Skip to content

Commit

Permalink
Merge pull request #102 from uber/generator-rename_pluginizable-master
Browse files Browse the repository at this point in the history
Rename all Pluginizable to Pluginized
  • Loading branch information
Rudro Samanta authored Jun 27, 2018
2 parents 76b0be5 + 4f21dcf commit be5621c
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Foundation
/// representation does not have the reference between the pluginized component
/// and its non-core one. Since it is the pure AST representation, it only
/// has the type name of the non-core component.
class PluginizableASTComponent {
class PluginizedASTComponent {
/// The actual data of this component.
let data: ASTComponent
/// The type name of the plugin extension.
Expand All @@ -34,8 +34,8 @@ class PluginizableASTComponent {
var pluginExtension: PluginExtension?

/// Convert the mutable reference type into a thread-safe value type.
var valueType: PluginizableComponent {
return PluginizableComponent(data: data.valueType, nonCoreComponent: nonCoreComponent!.valueType, pluginExtension: pluginExtension!)
var valueType: PluginizedComponent {
return PluginizedComponent(data: data.valueType, nonCoreComponent: nonCoreComponent!.valueType, pluginExtension: pluginExtension!)
}

/// Initializer.
Expand All @@ -53,7 +53,7 @@ class PluginizableASTComponent {

/// A data model representing an extended component that may be a pluginized
/// component with a referenced non-core component.
struct PluginizableComponent {
struct PluginizedComponent {
/// The actual data of this component.
let data: Component
/// The non-core component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import Foundation

/// An extended data model representing a node in the dependency graph.
/// The components may be pluginized components or regular ones.
struct PluginizableDependencyGraphNode {
/// The list of pluginizable components in this node.
let pluginizableComponents: [PluginizableASTComponent]
struct PluginizedDependencyGraphNode {
/// The list of pluginized components in this node.
let pluginizedComponents: [PluginizedASTComponent]
/// The list of non-core components in this node.
let nonCoreComponents: [ASTComponent]
/// The list of plugin extensions in this node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Foundation
/// The entry utility for the parsing phase. The parser deeply scans a
/// directory and parses the relevant Swift source files, and finally
/// outputs the dependency graph.
class PluginizableDependencyGraphParser {
class PluginizedDependencyGraphParser {

/// Parse all the Swift sources within the directory of given URL,
/// excluding any file that contains a suffix specified in the given
Expand All @@ -34,47 +34,47 @@ class PluginizableDependencyGraphParser {
/// data models and sorted import statements.
/// - throws: `DependencyGraphParserError.timeout` if parsing a Swift
/// source timed out.
func parse(from rootUrl: URL, excludingFilesWithSuffixes exclusionSuffixes: [String] = [], using executor: SequenceExecutor) throws -> ([Component], [PluginizableComponent], [String]) {
func parse(from rootUrl: URL, excludingFilesWithSuffixes exclusionSuffixes: [String] = [], using executor: SequenceExecutor) throws -> ([Component], [PluginizedComponent], [String]) {
let urlHandles: [UrlSequenceHandle] = enqueueParsingTasks(with: rootUrl, excludingFilesWithSuffixes: exclusionSuffixes, using: executor)
let (pluginizableComponents, nonCoreComponents, pluginExtensions, components, dependencies, imports) = try collectDataModels(with: urlHandles)
return process(pluginizableComponents, nonCoreComponents, pluginExtensions, components, dependencies, imports)
let (pluginizedComponents, nonCoreComponents, pluginExtensions, components, dependencies, imports) = try collectDataModels(with: urlHandles)
return process(pluginizedComponents, nonCoreComponents, pluginExtensions, components, dependencies, imports)
}

// MARK: - Private

private func enqueueParsingTasks(with rootUrl: URL, excludingFilesWithSuffixes exclusionSuffixes: [String], using executor: SequenceExecutor) -> [(SequenceExecutionHandle<PluginizableDependencyGraphNode>, URL)] {
var taskHandleTuples = [(handle: SequenceExecutionHandle<PluginizableDependencyGraphNode>, fileUrl: URL)]()
private func enqueueParsingTasks(with rootUrl: URL, excludingFilesWithSuffixes exclusionSuffixes: [String], using executor: SequenceExecutor) -> [(SequenceExecutionHandle<PluginizedDependencyGraphNode>, URL)] {
var taskHandleTuples = [(handle: SequenceExecutionHandle<PluginizedDependencyGraphNode>, fileUrl: URL)]()

// Enumerate all files and execute parsing sequences concurrently.
let enumerator = FileEnumerator()
enumerator.enumerate(from: rootUrl) { (fileUrl: URL) in
let task = PluginizableFileFilterTask(url: fileUrl, exclusionSuffixes: exclusionSuffixes)
let task = PluginizedFileFilterTask(url: fileUrl, exclusionSuffixes: exclusionSuffixes)
let taskHandle = executor.executeSequence(from: task, with: nextExecution(after:with:))
taskHandleTuples.append((taskHandle, fileUrl))
}

return taskHandleTuples
}

private func nextExecution(after currentTask: Task, with currentResult: Any) -> SequenceExecution<PluginizableDependencyGraphNode> {
if currentTask is PluginizableFileFilterTask, let filterResult = currentResult as? FilterResult {
private func nextExecution(after currentTask: Task, with currentResult: Any) -> SequenceExecution<PluginizedDependencyGraphNode> {
if currentTask is PluginizedFileFilterTask, let filterResult = currentResult as? FilterResult {
switch filterResult {
case .shouldParse(let url, let content):
return .continueSequence(ASTProducerTask(sourceUrl: url, sourceContent: content))
case .skip:
return .endOfSequence(PluginizableDependencyGraphNode(pluginizableComponents: [], nonCoreComponents: [], pluginExtensions: [], components: [], dependencies: [], imports: []))
return .endOfSequence(PluginizedDependencyGraphNode(pluginizedComponents: [], nonCoreComponents: [], pluginExtensions: [], components: [], dependencies: [], imports: []))
}
} else if currentTask is ASTProducerTask, let ast = currentResult as? AST {
return .continueSequence(PluginizableASTParserTask(ast: ast))
} else if currentTask is PluginizableASTParserTask, let node = currentResult as? PluginizableDependencyGraphNode {
return .continueSequence(PluginizedASTParserTask(ast: ast))
} else if currentTask is PluginizedASTParserTask, let node = currentResult as? PluginizedDependencyGraphNode {
return .endOfSequence(node)
} else {
fatalError("Unhandled task \(currentTask) with result \(currentResult)")
}
}

private func collectDataModels(with urlHandles: [UrlSequenceHandle]) throws -> ([PluginizableASTComponent], [ASTComponent], [PluginExtension], [ASTComponent], [Dependency], Set<String>) {
var pluginizableComponents = [PluginizableASTComponent]()
private func collectDataModels(with urlHandles: [UrlSequenceHandle]) throws -> ([PluginizedASTComponent], [ASTComponent], [PluginExtension], [ASTComponent], [Dependency], Set<String>) {
var pluginizedComponents = [PluginizedASTComponent]()
var nonCoreComponents = [ASTComponent]()
var pluginExtensions = [PluginExtension]()
var components = [ASTComponent]()
Expand All @@ -83,7 +83,7 @@ class PluginizableDependencyGraphParser {
for urlHandle in urlHandles {
do {
let node = try urlHandle.handle.await(withTimeout: 30)
pluginizableComponents.append(contentsOf: node.pluginizableComponents)
pluginizedComponents.append(contentsOf: node.pluginizedComponents)
nonCoreComponents.append(contentsOf: node.nonCoreComponents)
pluginExtensions.append(contentsOf: node.pluginExtensions)
components.append(contentsOf: node.components)
Expand All @@ -97,21 +97,21 @@ class PluginizableDependencyGraphParser {
fatalError("Unhandled task execution error \(error)")
}
}
return (pluginizableComponents, nonCoreComponents, pluginExtensions, components, dependencies, imports)
return (pluginizedComponents, nonCoreComponents, pluginExtensions, components, dependencies, imports)
}

private func process(_ pluginizableComponents: [PluginizableASTComponent], _ nonCoreComponents: [ASTComponent], _ pluginExtensions: [PluginExtension], _ components: [ASTComponent], _ dependencies: [Dependency], _ imports: Set<String>) -> ([Component], [PluginizableComponent], [String]) {
private func process(_ pluginizedComponents: [PluginizedASTComponent], _ nonCoreComponents: [ASTComponent], _ pluginExtensions: [PluginExtension], _ components: [ASTComponent], _ dependencies: [Dependency], _ imports: Set<String>) -> ([Component], [PluginizedComponent], [String]) {
var allComponents = nonCoreComponents + components
let pluginizableComponentData = pluginizableComponents.map { (component: PluginizableASTComponent) -> ASTComponent in
let pluginizedComponentData = pluginizedComponents.map { (component: PluginizedASTComponent) -> ASTComponent in
component.data
}
allComponents.append(contentsOf: pluginizableComponentData)
allComponents.append(contentsOf: pluginizedComponentData)
let processors: [Processor] = [
DuplicateValidator(components: allComponents, dependencies: dependencies),
ParentLinker(components: allComponents),
DependencyLinker(components: allComponents, dependencies: dependencies),
NonCoreComponentLinker(pluginizableComponents: pluginizableComponents, nonCoreComponents: nonCoreComponents),
PluginExtensionLinker(pluginizableComponents: pluginizableComponents, pluginExtensions: pluginExtensions)
NonCoreComponentLinker(pluginizedComponents: pluginizedComponents, nonCoreComponents: nonCoreComponents),
PluginExtensionLinker(pluginizedComponents: pluginizedComponents, pluginExtensions: pluginExtensions)
]
for processor in processors {
do {
Expand All @@ -124,12 +124,12 @@ class PluginizableDependencyGraphParser {
let valueTypeComponents = components.map { (astComponent: ASTComponent) -> Component in
astComponent.valueType
}
let valueTypePluginizedComponents = pluginizableComponents.map { (astComponent: PluginizableASTComponent) -> PluginizableComponent in
let valueTypePluginizedComponents = pluginizedComponents.map { (astComponent: PluginizedASTComponent) -> PluginizedComponent in
return astComponent.valueType
}
let sortedImports = imports.sorted()
return (valueTypeComponents, valueTypePluginizedComponents, sortedImports)
}
}

private typealias UrlSequenceHandle = (handle: SequenceExecutionHandle<PluginizableDependencyGraphNode>, fileUrl: URL)
private typealias UrlSequenceHandle = (handle: SequenceExecutionHandle<PluginizedDependencyGraphNode>, fileUrl: URL)
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

import Foundation

/// A processor that links non-core components to pluginizable components
/// A processor that links non-core components to pluginized components
/// based on type name.
class NonCoreComponentLinker: Processor {

/// Initializer.
///
/// - parameter pluginizableComponents: The pluginizable components to
/// - parameter pluginizedComponents: The pluginized components to
/// link with non-core components.
/// - parameter nonCoreComponents: The non-core components to link.
init(pluginizableComponents: [PluginizableASTComponent], nonCoreComponents: [ASTComponent]) {
self.pluginizableComponents = pluginizableComponents
init(pluginizedComponents: [PluginizedASTComponent], nonCoreComponents: [ASTComponent]) {
self.pluginizedComponents = pluginizedComponents
self.nonCoreComponents = nonCoreComponents
}

Expand All @@ -40,16 +40,16 @@ class NonCoreComponentLinker: Processor {
nonCoreMap[nonCoreComponent.name] = nonCoreComponent
}

for pluginizableComponent in pluginizableComponents {
pluginizableComponent.nonCoreComponent = nonCoreMap[pluginizableComponent.nonCoreComponentType]
if pluginizableComponent.nonCoreComponent == nil {
throw ProcessingError.fail("Cannot find \(pluginizableComponent.data.name)'s non-core component with type name \(pluginizableComponent.nonCoreComponentType)")
for pluginizedComponent in pluginizedComponents {
pluginizedComponent.nonCoreComponent = nonCoreMap[pluginizedComponent.nonCoreComponentType]
if pluginizedComponent.nonCoreComponent == nil {
throw ProcessingError.fail("Cannot find \(pluginizedComponent.data.name)'s non-core component with type name \(pluginizedComponent.nonCoreComponentType)")
}
}
}

// MARK: - Private

private let pluginizableComponents: [PluginizableASTComponent]
private let pluginizedComponents: [PluginizedASTComponent]
private let nonCoreComponents: [ASTComponent]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

import Foundation

/// A processor that links pluginizable components with their plugin
/// A processor that links pluginized components with their plugin
/// extensions based on type name.
class PluginExtensionLinker: Processor {

/// Initializer.
///
/// - parameter pluginizableComponents: The pluginizable components to
/// - parameter pluginizedComponents: The pluginized components to
/// link with plugin extensions.
/// - parameter pluginExtensions: The non-core components to link.
init(pluginizableComponents: [PluginizableASTComponent], pluginExtensions: [PluginExtension]) {
self.pluginizableComponents = pluginizableComponents
init(pluginizedComponents: [PluginizedASTComponent], pluginExtensions: [PluginExtension]) {
self.pluginizedComponents = pluginizedComponents
self.pluginExtensions = pluginExtensions
}

Expand All @@ -40,16 +40,16 @@ class PluginExtensionLinker: Processor {
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)")
for pluginizedComponent in pluginizedComponents {
pluginizedComponent.pluginExtension = extensionMap[pluginizedComponent.pluginExtensionType]
if pluginizedComponent.pluginExtension == nil {
throw ProcessingError.fail("Cannot find \(pluginizedComponent.data.name)'s plugin extension with type name \(pluginizedComponent.pluginExtensionType)")
}
}
}

// MARK: - Private

private let pluginizableComponents: [PluginizableASTComponent]
private let pluginizedComponents: [PluginizedASTComponent]
private let pluginExtensions: [PluginExtension]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import SourceKittenFramework

/// The extended AST parser task that parses all components, dependency
/// protocols and import statements, including pluginized components.
class PluginizableASTParserTask: AbstractTask<PluginizableDependencyGraphNode> {
class PluginizedASTParserTask: AbstractTask<PluginizedDependencyGraphNode> {

/// Initializer.
///
Expand All @@ -31,19 +31,19 @@ class PluginizableASTParserTask: AbstractTask<PluginizableDependencyGraphNode> {
/// Execute the task and returns the dependency graph data model.
///
/// - returns: Parsed `PluginizedDependencyGraphNode`.
override func execute() -> PluginizableDependencyGraphNode {
override func execute() -> PluginizedDependencyGraphNode {
let baseTask = ASTParserTask(ast: ast)
let baseNode = baseTask.execute()
let (pluginizedComponents, nonCoreComponents, pluginExtensions) = parsePluginizedStructures()
return PluginizableDependencyGraphNode(pluginizableComponents: pluginizedComponents, nonCoreComponents: nonCoreComponents, pluginExtensions: pluginExtensions, components: baseNode.components, dependencies: baseNode.dependencies, imports: baseNode.imports)
return PluginizedDependencyGraphNode(pluginizedComponents: pluginizedComponents, nonCoreComponents: nonCoreComponents, pluginExtensions: pluginExtensions, components: baseNode.components, dependencies: baseNode.dependencies, imports: baseNode.imports)
}

// MARK: - Private

private let ast: AST

private func parsePluginizedStructures() -> ([PluginizableASTComponent], [ASTComponent], [PluginExtension]) {
var pluginizedComponents = [PluginizableASTComponent]()
private func parsePluginizedStructures() -> ([PluginizedASTComponent], [ASTComponent], [PluginExtension]) {
var pluginizedComponents = [PluginizedASTComponent]()
var nonCoreComponents = [ASTComponent]()
var pluginExtensions = [PluginExtension]()

Expand All @@ -53,7 +53,7 @@ class PluginizableASTParserTask: AbstractTask<PluginizableDependencyGraphNode> {
if substructure.isPluginizedComponent {
let (dependencyProtocolName, pluginExtensionName, nonCoreComponentName) = substructure.pluginizedGenerics
let component = ASTComponent(name: substructure.name, dependencyProtocolName: dependencyProtocolName, properties: substructure.properties, expressionCallTypeNames: substructure.expressionCallNames)
pluginizedComponents.append(PluginizableASTComponent(data: component, pluginExtensionType: pluginExtensionName, nonCoreComponentType: nonCoreComponentName))
pluginizedComponents.append(PluginizedASTComponent(data: component, pluginExtensionType: pluginExtensionName, nonCoreComponentType: nonCoreComponentName))
} else if substructure.isNonCoreComponent {
let dependencyProtocolName = substructure.dependencyProtocolName(for: "NonCoreComponent")
let component = ASTComponent(name: substructure.name, dependencyProtocolName: dependencyProtocolName, properties: substructure.properties, expressionCallTypeNames: substructure.expressionCallNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Foundation
/// to determine if the file needs to be parsed for AST. If the file should
/// This task extends the Needle `FileFilterTask` to support pluginized and
/// non-core component types.
class PluginizableFileFilterTask: AbstractTask<FilterResult> {
class PluginizedFileFilterTask: AbstractTask<FilterResult> {

/// Initializer.
///
Expand Down
7 changes: 7 additions & 0 deletions Generator/Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ XCTMain([
testCase(DuplicateValidatorTests.allTests),
testCase(FileFilterTaskTests.allTests),
testCase(SequenceExecutorTests.allTests),
testCase(PluginizableASTParserTaskTests.allTests),
testCase(PluginizableFileFilterTaskTests.allTests),
testCase(NonCoreComponentLinkerTests.allTests),
testCase(PluginExtensionLinkerTests.allTests),
testCase(DependencyLinkerTests.allTests),
testCase(ParentLinkerTests.allTests),
testCase(PluginizableDependencyGraphParserTests.allTests),
])
Loading

0 comments on commit be5621c

Please sign in to comment.