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 @@ -16,15 +16,15 @@

package com.lightbend.akkasls.codegen

object Syntax {
object Format {

val break = "\n"

def indent(lines: Iterable[String], num: Int): String =
indent(lines.mkString(break), num)

/*
* Be mindful that `Syntax.indent` does not indent the first line,
* Be mindful that `Format.indent` does not indent the first line,
* so the invocation itself needs to be indented as required.
*
* Empty lines are not indented either.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ object ActionServiceSourceGenerator {
|
| public $className(ActionCreationContext creationContext) {}
|
| ${Syntax.indent(methods, 2)}
| ${Format.indent(methods, 2)}
|}
|""".stripMargin
}
Expand Down Expand Up @@ -203,7 +203,7 @@ object ActionServiceSourceGenerator {
|/** An action. */
|public abstract class ${service.interfaceName} extends Action {
|
| ${Syntax.indent(methods, 2)}
| ${Format.indent(methods, 2)}
|}""".stripMargin
}

Expand Down Expand Up @@ -277,7 +277,7 @@ object ActionServiceSourceGenerator {
| @Override
| public Action.Effect<?> handleUnary(String commandName, MessageEnvelope<Object> message) {
| switch (commandName) {
| ${Syntax.indent(unaryCases, 6)}
| ${Format.indent(unaryCases, 6)}
| default:
| throw new ActionHandler.HandlerNotFound(commandName);
| }
Expand All @@ -286,7 +286,7 @@ object ActionServiceSourceGenerator {
| @Override
| public Source<Action.Effect<?>, NotUsed> handleStreamedOut(String commandName, MessageEnvelope<Object> message) {
| switch (commandName) {
| ${Syntax.indent(streamOutCases, 6)}
| ${Format.indent(streamOutCases, 6)}
| default:
| throw new ActionHandler.HandlerNotFound(commandName);
| }
Expand All @@ -295,7 +295,7 @@ object ActionServiceSourceGenerator {
| @Override
| public Action.Effect<?> handleStreamedIn(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| switch (commandName) {
| ${Syntax.indent(streamInCases, 6)}
| ${Format.indent(streamInCases, 6)}
| default:
| throw new ActionHandler.HandlerNotFound(commandName);
| }
Expand All @@ -304,7 +304,7 @@ object ActionServiceSourceGenerator {
| @Override
| public Source<Action.Effect<?>, NotUsed> handleStreamed(String commandName, Source<MessageEnvelope<Object>, NotUsed> stream) {
| switch (commandName) {
| ${Syntax.indent(streamInOutCases, 6)}
| ${Format.indent(streamInOutCases, 6)}
| default:
| throw new ActionHandler.HandlerNotFound(commandName);
| }
Expand Down Expand Up @@ -385,7 +385,7 @@ object ActionServiceSourceGenerator {
| @Override
| public final Descriptors.FileDescriptor[] additionalDescriptors() {
| return new Descriptors.FileDescriptor[] {
| ${Syntax.indent(descriptors.mkString(",\n"), 6)}
| ${Format.indent(descriptors.mkString(",\n"), 6)}
| };
| }
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,15 @@ object EntityServiceSourceGenerator {
|
| @Override
| public $stateType handleEvent($stateType state, Object event) {
| ${Syntax.indent(eventCases, 4)}
| ${Format.indent(eventCases, 4)}
| }
|
| @Override
| public EventSourcedEntity.Effect<?> handleCommand(
| String commandName, $stateType state, Object command, CommandContext context) {
| switch (commandName) {
|
| ${Syntax.indent(commandCases, 6)}
| ${Format.indent(commandCases, 6)}
|
| default:
| throw new EventSourcedEntityHandler.CommandHandlerNotFound(commandName);
Expand Down Expand Up @@ -298,7 +298,7 @@ object EntityServiceSourceGenerator {
| @Override
| public final Descriptors.FileDescriptor[] additionalDescriptors() {
| return new Descriptors.FileDescriptor[] {
| ${Syntax.indent(descriptors.mkString(",\n"), 6)}
| ${Format.indent(descriptors.mkString(",\n"), 6)}
| };
| }
|}
Expand Down Expand Up @@ -368,9 +368,9 @@ object EntityServiceSourceGenerator {
| throw new UnsupportedOperationException("Not implemented yet, replace with your empty entity state");
| }
|
| ${Syntax.indent(commandHandlers, num = 2)}
| ${Format.indent(commandHandlers, num = 2)}
|
| ${Syntax.indent(eventHandlers, num = 2)}
| ${Format.indent(eventHandlers, num = 2)}
|
|}
|""".stripMargin
Expand Down Expand Up @@ -453,9 +453,9 @@ object EntityServiceSourceGenerator {
|/** An event sourced entity. */
|public abstract class Abstract${className} extends EventSourcedEntity<${qualifiedType(entity.state.fqn)}> {
|
| ${Syntax.indent(commandHandlers, num = 2)}
| ${Format.indent(commandHandlers, num = 2)}
|
| ${Syntax.indent(eventHandlers, num = 2)}
| ${Format.indent(eventHandlers, num = 2)}
|
|}""".stripMargin
}
Expand Down Expand Up @@ -531,7 +531,7 @@ object EntityServiceSourceGenerator {
| client = ${serviceName}Client.create(testkit.getGrpcClientSettings(), testkit.getActorSystem());
| }
|
| ${Syntax.indent(testCases, num = 2)}
| ${Format.indent(testCases, num = 2)}
|}
|""".stripMargin
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ object EventSourcedEntityTestKitGenerator {
| }
|
| private $stateClassName handleEvent($stateClassName state, Object event) {
| ${Syntax.indent(generateHandleEvents(entity.events), 4)}
| ${Format.indent(generateHandleEvents(entity.events), 4)}
| }
|
| private <Reply> EventSourcedResult<Reply> interpretEffects(EventSourcedEntity.Effect<Reply> effect) {
Expand All @@ -148,7 +148,7 @@ object EventSourcedEntityTestKitGenerator {
| return new EventSourcedResultImpl(effect, state);
| }
|
| ${Syntax.indent(generateServices(service), 2)}
| ${Format.indent(generateServices(service), 2)}
|}
|""".stripMargin
}
Expand Down Expand Up @@ -254,7 +254,7 @@ object EventSourcedEntityTestKitGenerator {
| // assertEquals(expectedResponse, actualResponse);
| }
|
| ${Syntax.indent(dummyTestCases, 2)}
| ${Format.indent(dummyTestCases, 2)}
|
|}
|""".stripMargin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.lightbend.akkasls.codegen.java

import com.lightbend.akkasls.codegen.ModelBuilder
import com.lightbend.akkasls.codegen.Syntax
import com.lightbend.akkasls.codegen.Format

object ReplicatedEntitySourceGenerator {
import SourceGenerator._
Expand Down Expand Up @@ -75,7 +75,7 @@ object ReplicatedEntitySourceGenerator {
| this.entityId = context.entityId();
| }
|$emptyValue
| ${Syntax.indent(methods, num = 2)}
| ${Format.indent(methods, num = 2)}
|}
|""".stripMargin
}
Expand Down Expand Up @@ -127,7 +127,7 @@ object ReplicatedEntitySourceGenerator {
| String commandName, $parameterizedDataType data, Object command, CommandContext context) {
| switch (commandName) {
|
| ${Syntax.indent(commandCases, 6)}
| ${Format.indent(commandCases, 6)}
|
| default:
| throw new ReplicatedEntityHandler.CommandHandlerNotFound(commandName);
Expand Down Expand Up @@ -225,7 +225,7 @@ object ReplicatedEntitySourceGenerator {
| @Override
| public final Descriptors.FileDescriptor[] additionalDescriptors() {
| return new Descriptors.FileDescriptor[] {
| ${Syntax.indent(descriptors.mkString(",\n"), 6)}
| ${Format.indent(descriptors.mkString(",\n"), 6)}
| };
| }
|}
Expand Down Expand Up @@ -272,7 +272,7 @@ object ReplicatedEntitySourceGenerator {
|/** A replicated entity. */
|public abstract class Abstract$className extends $baseClass$typeArguments {
|
| ${Syntax.indent(methods, 2)}
| ${Format.indent(methods, 2)}
|
|}
|""".stripMargin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ object SourceGenerator {
| ${creatorParameters.mkString(",\n ")}) {
| AkkaServerless akkaServerless = new AkkaServerless();
| return akkaServerless
| ${Syntax.indent(registrations, 6)};
| ${Format.indent(registrations, 6)};
| }
|}
|""".stripMargin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.lightbend.akkasls.codegen.java

import com.lightbend.akkasls.codegen.ModelBuilder
import com.lightbend.akkasls.codegen.Syntax
import com.lightbend.akkasls.codegen.Format

object ValueEntitySourceGenerator {
import SourceGenerator._
Expand Down Expand Up @@ -68,7 +68,7 @@ object ValueEntitySourceGenerator {
| throw new UnsupportedOperationException("Not implemented yet, replace with your empty entity state");
| }
|
| ${Syntax.indent(methods, num = 2)}
| ${Format.indent(methods, num = 2)}
|}
|""".stripMargin
}
Expand Down Expand Up @@ -119,7 +119,7 @@ object ValueEntitySourceGenerator {
| String commandName, $stateType state, Object command, CommandContext context) {
| switch (commandName) {
|
| ${Syntax.indent(commandCases, 6)}
| ${Format.indent(commandCases, 6)}
|
| default:
| throw new ValueEntityHandler.CommandHandlerNotFound(commandName);
Expand Down Expand Up @@ -212,7 +212,7 @@ object ValueEntitySourceGenerator {
| @Override
| public final Descriptors.FileDescriptor[] additionalDescriptors() {
| return new Descriptors.FileDescriptor[] {
| ${Syntax.indent(descriptors.mkString(",\n"), 6)}
| ${Format.indent(descriptors.mkString(",\n"), 6)}
| };
| }
|}
Expand Down Expand Up @@ -256,7 +256,7 @@ object ValueEntitySourceGenerator {
|/** A value entity. */
|public abstract class Abstract$className extends ValueEntity<$stateType> {
|
| ${Syntax.indent(methods, 2)}
| ${Format.indent(methods, 2)}
|
|}
|""".stripMargin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.lightbend.akkasls.codegen.java

import com.google.common.base.Charsets
import com.lightbend.akkasls.codegen.ModelBuilder
import com.lightbend.akkasls.codegen.Syntax
import com.lightbend.akkasls.codegen.Format

import java.nio.file.Files
import java.nio.file.Path
Expand Down Expand Up @@ -138,7 +138,7 @@ object ValueEntityTestKitGenerator {
| return result;
| }
|
| ${Syntax.indent(generateServices(service), 2)}
| ${Format.indent(generateServices(service), 2)}
|}
|""".stripMargin
}
Expand Down Expand Up @@ -218,7 +218,7 @@ object ValueEntityTestKitGenerator {
| // assertEquals(expectedState, testKit.getState());
| }
|
| ${Syntax.indent(dummyTestCases, 2)}
| ${Format.indent(dummyTestCases, 2)}
|
|}
|""".stripMargin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ object ViewServiceSourceGenerator {
| Object event) {
|
| switch (eventName) {
| ${Syntax.indent(cases, 6)}
| ${Format.indent(cases, 6)}
|
| default:
| throw new UpdateHandlerNotFound(eventName);
Expand Down Expand Up @@ -227,7 +227,7 @@ object ViewServiceSourceGenerator {
|
| public ${view.className}(ViewContext context) {}
|$emptyState
| ${Syntax.indent(handlers, 2)}
| ${Format.indent(handlers, 2)}
|}
|""".stripMargin
}
Expand Down Expand Up @@ -260,7 +260,7 @@ object ViewServiceSourceGenerator {
|
|public abstract class ${view.abstractViewName} extends View<${qualifiedType(view.state.fqn)}> {
|$emptyState
| ${Syntax.indent(handlers, 2)}
| ${Format.indent(handlers, 2)}
|}
|""".stripMargin
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
* limitations under the License.
*/

import com.lightbend.akkasls.codegen.Syntax
import com.lightbend.akkasls.codegen.Format

class SyntaxSpec extends munit.FunSuite {
class FormatSpec extends munit.FunSuite {

test("indenting should leave alone the first line") {

Expand All @@ -28,7 +28,7 @@ class SyntaxSpec extends munit.FunSuite {
s"""
|a
|
| ${Syntax.indent(method, 2)}
| ${Format.indent(method, 2)}
|b
""".stripMargin

Expand Down