-
Notifications
You must be signed in to change notification settings - Fork 6
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 #44 from raptorxcz/feature/swift_syntax
Integrate dummy generator
- Loading branch information
Showing
17 changed files
with
659 additions
and
794 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
protocol ArgumentGenerator { | ||
func makeCode(from declaration: ArgumentDeclaration) -> String | ||
} | ||
|
||
final class ArgumentGeneratorImpl: ArgumentGenerator { | ||
private let typeGenerator: TypeGenerator | ||
|
||
init(typeGenerator: TypeGenerator) { | ||
self.typeGenerator = typeGenerator | ||
} | ||
|
||
func makeCode(from declaration: ArgumentDeclaration) -> String { | ||
if let label = declaration.label { | ||
return "\(label) \(declaration.name): \(typeGenerator.makeArgumentCode(from: declaration.type))" | ||
} else { | ||
return "\(declaration.name): \(typeGenerator.makeArgumentCode(from: declaration.type))" | ||
} | ||
} | ||
} |
175 changes: 0 additions & 175 deletions
175
Rubicon/Sources/Rubicon/Generator/CreateDummyInteractor.swift
This file was deleted.
Oops, something went wrong.
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,69 @@ | ||
final class DummyGenerator { | ||
private let protocolGenerator: ProtocolGenerator | ||
private let variableGenerator: VariableGenerator | ||
private let functionGenerator: FunctionGenerator | ||
private let accessLevel: AccessLevel | ||
private let accessLevelGenerator: AccessLevelGenerator | ||
|
||
init( | ||
protocolGenerator: ProtocolGenerator, | ||
variableGenerator: VariableGenerator, | ||
functionGenerator: FunctionGenerator, | ||
accessLevel: AccessLevel, | ||
accessLevelGenerator: AccessLevelGenerator | ||
) { | ||
self.protocolGenerator = protocolGenerator | ||
self.variableGenerator = variableGenerator | ||
self.functionGenerator = functionGenerator | ||
self.accessLevel = accessLevel | ||
self.accessLevelGenerator = accessLevelGenerator | ||
} | ||
|
||
func generate(from protocolType: ProtocolDeclaration) -> String { | ||
let content = generateBody(from: protocolType) | ||
return protocolGenerator.makeProtocol( | ||
from: protocolType, | ||
stub: "Dummy", | ||
content: content.joined(separator: "\n") | ||
) | ||
} | ||
|
||
private func generateBody(from protocolType: ProtocolDeclaration) -> [String] { | ||
var content = [String]() | ||
|
||
if !protocolType.variables.isEmpty { | ||
content += protocolType.variables.map{ | ||
variableGenerator.makeStubCode( | ||
from: $0, | ||
getContent: "\t\t\tfatalError()", | ||
setContent: "\t\t\tfatalError()" | ||
) | ||
} | ||
content.append("") | ||
} | ||
|
||
let initRows = generateInit(for: protocolType) | ||
|
||
if !initRows.isEmpty { | ||
content.append(initRows) | ||
} | ||
|
||
content += protocolType.functions.map { | ||
functionGenerator.makeCode(from: $0, content: "\t\tfatalError()") + "\n" | ||
} | ||
|
||
return content | ||
} | ||
|
||
private func generateInit(for type: ProtocolDeclaration) -> String { | ||
guard accessLevel == .public else { | ||
return "" | ||
} | ||
|
||
return """ | ||
\t\(accessLevelGenerator.makeContentAccessLevel())init() { | ||
\t} | ||
""" | ||
} | ||
} |
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,47 @@ | ||
protocol FunctionGenerator { | ||
func makeCode(from declaration: FunctionDeclaration, content: String) -> String | ||
} | ||
|
||
final class FunctionGeneratorImpl: FunctionGenerator { | ||
private let accessLevelGenerator: AccessLevelGenerator | ||
private let typeGenerator: TypeGenerator | ||
private let argumentGenerator: ArgumentGenerator | ||
|
||
init( | ||
accessLevelGenerator: AccessLevelGenerator, | ||
typeGenerator: TypeGenerator, | ||
argumentGenerator: ArgumentGenerator | ||
) { | ||
self.accessLevelGenerator = accessLevelGenerator | ||
self.typeGenerator = typeGenerator | ||
self.argumentGenerator = argumentGenerator | ||
} | ||
|
||
func makeCode(from declaration: FunctionDeclaration, content: String) -> String { | ||
let returnString = makeReturn(from: declaration) | ||
let arguments = declaration.arguments.map(argumentGenerator.makeCode(from:)).joined(separator: ", ") | ||
return """ | ||
\t\(accessLevelGenerator.makeContentAccessLevel())func \(declaration.name)(\(arguments)) \(returnString){ | ||
\(content) | ||
\t} | ||
""" | ||
} | ||
|
||
private func makeReturn(from declaration: FunctionDeclaration) -> String { | ||
var result = "" | ||
|
||
if declaration.isAsync { | ||
result += "async " | ||
} | ||
|
||
if declaration.isThrowing { | ||
result += "throws " | ||
} | ||
|
||
if let returnType = declaration.returnType { | ||
result += "-> \(typeGenerator.makeVariableCode(from: returnType)) " | ||
} | ||
|
||
return result | ||
} | ||
} |
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,9 +1,14 @@ | ||
protocol TypeGenerator { | ||
func makeVariableCode(from declaration: TypeDeclaration) -> String | ||
func makeArgumentCode(from declaration: TypeDeclaration) -> String | ||
} | ||
|
||
final class TypeGeneratorImpl: TypeGenerator { | ||
func makeVariableCode(from declaration: TypeDeclaration) -> String { | ||
return declaration.name | ||
} | ||
|
||
func makeArgumentCode(from declaration: TypeDeclaration) -> String { | ||
return (declaration.prefix.map(\.rawValue) + [declaration.name]).joined(separator: " ") | ||
} | ||
} |
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.