Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ object ModelBuilder {
val className =
if (fqn.name.contains("Action")) fqn.name + "Impl"
else fqn.name + "Action"
val interfaceName = "Abstract" + baseClassName
val abstractActionName = "Abstract" + baseClassName
val handlerName = baseClassName + "Handler"
val providerName = baseClassName + "Provider"

Expand Down Expand Up @@ -252,7 +252,15 @@ object ModelBuilder {
streamedInput: Boolean,
streamedOutput: Boolean,
inFromTopic: Boolean,
outToTopic: Boolean)
outToTopic: Boolean) {

def isUnary: Boolean = !streamedInput && !streamedOutput
def isStreamIn: Boolean = streamedInput && !streamedOutput
def isStreamOut: Boolean = !streamedInput && streamedOutput
def isStreamInOut: Boolean = streamedInput && streamedOutput
def hasStream: Boolean = isStreamIn || isStreamOut || isStreamInOut

}

object Command {
def from(method: Descriptors.MethodDescriptor)(implicit fqnExtractor: FullyQualifiedNameExtractor): Command = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ object ActionServiceSourceGenerator {
sourceDirectory.resolve(packagePath.resolve(service.className + ".java"))

val interfaceSourcePath =
generatedSourceDirectory.resolve(packagePath.resolve(service.interfaceName + ".java"))
generatedSourceDirectory.resolve(packagePath.resolve(service.abstractActionName + ".java"))

interfaceSourcePath.getParent.toFile.mkdirs()
Files.write(interfaceSourcePath, abstractActionSource(service).getBytes(Charsets.UTF_8))
Expand All @@ -73,14 +73,8 @@ object ActionServiceSourceGenerator {
List(implSourcePath, interfaceSourcePath, providerSourcePath, handlerSourcePath)
}

private def isUnary(cmd: ModelBuilder.Command): Boolean = !cmd.streamedInput && !cmd.streamedOutput
private def isStreamIn(cmd: ModelBuilder.Command): Boolean = cmd.streamedInput && !cmd.streamedOutput
private def isStreamOut(cmd: ModelBuilder.Command): Boolean = !cmd.streamedInput && cmd.streamedOutput
private def isStreamInOut(cmd: ModelBuilder.Command): Boolean = cmd.streamedInput && cmd.streamedOutput
private def hasStream(cmd: ModelBuilder.Command): Boolean = isStreamIn(cmd) || isStreamOut(cmd) || isStreamInOut(cmd)
Comment on lines -76 to -80
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved into Command as we need it now in two different generators (Java and Scala)


private def streamImports(commands: Iterable[ModelBuilder.Command]): Seq[String] = {
if (commands.exists(c => hasStream(c)))
if (commands.exists(_.hasStream))
"akka.NotUsed" :: "akka.stream.javadsl.Source" :: Nil
else
Nil
Expand All @@ -102,7 +96,7 @@ object ActionServiceSourceGenerator {
val inputTypeFullName = cmd.inputType.fullName
val outputType = cmd.outputType.fullName

if (isUnary(cmd)) {
if (cmd.isUnary) {
val jsonTopicHint = {
// note: the somewhat funky indenting is on purpose to lf+indent only if comment present
if (cmd.inFromTopic && cmd.inputType.fullQualifiedName == "com.google.protobuf.Any")
Expand All @@ -119,14 +113,14 @@ object ActionServiceSourceGenerator {
|public Effect<$outputType> ${lowerFirst(methodName)}($inputTypeFullName $input) {
| ${jsonTopicHint}throw new RuntimeException("The command handler for `$methodName` is not implemented, yet");
|}""".stripMargin
} else if (isStreamOut(cmd)) {
} else if (cmd.isStreamOut) {
s"""
|/** Handler for "$methodName". */
|@Override
|public Source<Effect<$outputType>, NotUsed> ${lowerFirst(methodName)}($inputTypeFullName $input) {
| throw new RuntimeException("The command handler for `$methodName` is not implemented, yet");
|}""".stripMargin
} else if (isStreamIn(cmd)) {
} else if (cmd.isStreamIn) {
s"""
|/** Handler for "$methodName". */
|@Override
Expand All @@ -150,7 +144,7 @@ object ActionServiceSourceGenerator {
|$imports
|
|/** An action. */
|public class $className extends ${service.interfaceName} {
|public class $className extends ${service.abstractActionName} {
|
| public $className(ActionCreationContext creationContext) {}
|
Expand All @@ -173,15 +167,15 @@ object ActionServiceSourceGenerator {
val inputTypeFullName = cmd.inputType.fullName
val outputType = cmd.outputType.fullName

if (isUnary(cmd)) {
if (cmd.isUnary) {
s"""|/** Handler for "$methodName". */
|public abstract Effect<$outputType> ${lowerFirst(methodName)}($inputTypeFullName $input);""".stripMargin
} else if (isStreamOut(cmd)) {
} else if (cmd.isStreamOut) {
s"""
|/** Handler for "$methodName". */
|public abstract Source<Effect<$outputType>, NotUsed> ${lowerFirst(
methodName)}($inputTypeFullName $input);""".stripMargin
} else if (isStreamIn(cmd)) {
} else if (cmd.isStreamIn) {
s"""
|/** Handler for "$methodName". */
|public abstract Effect<$outputType> ${lowerFirst(
Expand All @@ -201,7 +195,7 @@ object ActionServiceSourceGenerator {
|$imports
|
|/** An action. */
|public abstract class ${service.interfaceName} extends Action {
|public abstract class ${service.abstractActionName} extends Action {
|
| ${Format.indent(methods, 2)}
|}""".stripMargin
Expand All @@ -212,7 +206,7 @@ object ActionServiceSourceGenerator {
val className = service.className
val packageName = service.fqn.parent.javaPackage

val unaryCases = service.commands.filter(isUnary).map { cmd =>
val unaryCases = service.commands.filter(_.isUnary).map { cmd =>
val methodName = cmd.name
val inputTypeFullName = cmd.inputType.fullName

Expand All @@ -222,7 +216,7 @@ object ActionServiceSourceGenerator {
|""".stripMargin
}

val streamOutCases = service.commands.filter(isStreamOut).map { cmd =>
val streamOutCases = service.commands.filter(_.isStreamOut).map { cmd =>
val methodName = cmd.name
val inputTypeFullName = cmd.inputType.fullName

Expand All @@ -232,7 +226,7 @@ object ActionServiceSourceGenerator {
|""".stripMargin
}

val streamInCases = service.commands.filter(isStreamIn).map { cmd =>
val streamInCases = service.commands.filter(_.isStreamIn).map { cmd =>
val methodName = cmd.name
val inputTypeFullName = cmd.inputType.fullName

Expand All @@ -242,7 +236,7 @@ object ActionServiceSourceGenerator {
|""".stripMargin
}

val streamInOutCases = service.commands.filter(isStreamInOut).map { cmd =>
val streamInOutCases = service.commands.filter(_.isStreamInOut).map { cmd =>
val methodName = cmd.name
val inputTypeFullName = cmd.inputType.fullName

Expand Down
Loading