Fix generating relay delegate methods with return values
This commit is contained in:
parent
348e176f89
commit
3212e54bf5
|
@ -1,3 +1,17 @@
|
||||||
|
<%
|
||||||
|
func methodDeclaration(_ method: SourceryRuntime.Method, newName: String) -> String {
|
||||||
|
var result = newName
|
||||||
|
if method.throws {
|
||||||
|
result = result + " throws"
|
||||||
|
} else if method.rethrows {
|
||||||
|
result = result + " rethrows"
|
||||||
|
}
|
||||||
|
if method.returnTypeName.isVoid {
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
return result + " -> \(method.returnTypeName)"
|
||||||
|
}
|
||||||
|
-%>
|
||||||
<% for type in types.implementing["AutoGenerateProtocolDelegate"] {
|
<% for type in types.implementing["AutoGenerateProtocolDelegate"] {
|
||||||
guard let replaceOf = type.annotations["replaceOf"] as? String else { continue }
|
guard let replaceOf = type.annotations["replaceOf"] as? String else { continue }
|
||||||
guard let replaceWith = type.annotations["replaceWith"] as? String else { continue }
|
guard let replaceWith = type.annotations["replaceWith"] as? String else { continue }
|
||||||
|
@ -5,7 +19,7 @@
|
||||||
guard let aProtocol = types.protocols.first(where: { $0.name == protocolToGenerate }) else { continue } -%>
|
guard let aProtocol = types.protocols.first(where: { $0.name == protocolToGenerate }) else { continue } -%>
|
||||||
// sourcery:inline:<%= type.name %>.AutoGenerateProtocolDelegate
|
// sourcery:inline:<%= type.name %>.AutoGenerateProtocolDelegate
|
||||||
<% for method in aProtocol.methods { -%>
|
<% for method in aProtocol.methods { -%>
|
||||||
<%= method.name.replacingOccurrences(of: replaceOf, with: replaceWith) %>
|
<%= methodDeclaration(method, newName: method.name.replacingOccurrences(of: replaceOf, with: replaceWith)) %>
|
||||||
<% } -%>
|
<% } -%>
|
||||||
// sourcery:end
|
// sourcery:end
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
|
@ -6,6 +6,9 @@ func methodDeclaration(_ method: SourceryRuntime.Method) -> String {
|
||||||
} else if method.rethrows {
|
} else if method.rethrows {
|
||||||
result = result + " rethrows"
|
result = result + " rethrows"
|
||||||
}
|
}
|
||||||
|
if method.returnTypeName.isVoid {
|
||||||
|
return result
|
||||||
|
}
|
||||||
return result + " -> \(method.returnTypeName)"
|
return result + " -> \(method.returnTypeName)"
|
||||||
}
|
}
|
||||||
-%>
|
-%>
|
||||||
|
@ -42,7 +45,7 @@ func methodCall(
|
||||||
guard let aProtocol = types.protocols.first(where: { $0.name == protocolToGenerate }) else { continue } -%>
|
guard let aProtocol = types.protocols.first(where: { $0.name == protocolToGenerate }) else { continue } -%>
|
||||||
// sourcery:inline:<%= type.name %>.AutoGenerateProtocolRelayDelegate
|
// sourcery:inline:<%= type.name %>.AutoGenerateProtocolRelayDelegate
|
||||||
<% for method in aProtocol.methods { -%>
|
<% for method in aProtocol.methods { -%>
|
||||||
func <%= method.name -%> {
|
func <%= methodDeclaration(method) -%> {
|
||||||
<%= methodCall(method, replaceOf: replaceOf, replaceWith: replaceWith) %>
|
<%= methodCall(method, replaceOf: replaceOf, replaceWith: replaceWith) %>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue