-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JavaBackend replaced with CodeGenerator
Signed-off-by: hurelhuyag <hurelhuyag@gmail.com>
- Loading branch information
1 parent
c60961a
commit d188d51
Showing
13 changed files
with
161 additions
and
37 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
src/main/java/io/vlingo/xoom/schemata/codegen/DomainEventArguments.java
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,50 @@ | ||
package io.vlingo.xoom.schemata.codegen; | ||
|
||
import io.vlingo.xoom.schemata.codegen.ast.FieldDefinition; | ||
import io.vlingo.xoom.schemata.codegen.ast.types.TypeDefinition; | ||
import io.vlingo.xoom.schemata.codegen.ast.values.Value; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class DomainEventArguments { | ||
|
||
public final String namespace; | ||
public final String version; | ||
public final List<Property> properties; | ||
public final String typeName; | ||
|
||
public DomainEventArguments(String language, String fqdn, String version, TypeDefinition node) { | ||
this.namespace = extractNamespace(fqdn); | ||
this.typeName = node.typeName; | ||
this.version = version; | ||
this.properties = extractProperties(language, node); | ||
} | ||
|
||
public static class Property { | ||
public final String type; | ||
public final String name; | ||
public final Object value; | ||
|
||
public Property(String type, String name, Object value) { | ||
this.type = type; | ||
this.name = name; | ||
this.value = value; | ||
} | ||
} | ||
|
||
private String extractNamespace(String fqdn) { | ||
int i = fqdn.indexOf(':', fqdn.indexOf(':') + 1) + 1; | ||
int j = fqdn.indexOf(':', i); | ||
return fqdn.substring(i, j) + ".model"; | ||
} | ||
|
||
private List<Property> extractProperties(String language, TypeDefinition root) { | ||
TypeMap typeMap = TypeMap.valueOf(language); | ||
return root.children.stream() | ||
.map(node -> (FieldDefinition) node) | ||
.map(node -> new Property(typeMap.typeOf(node.type.name()), node.name, | ||
node.defaultValue.map(Value::value).orElse(null))) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
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
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
59 changes: 59 additions & 0 deletions
59
src/main/java/io/vlingo/xoom/schemata/codegen/TypeMap.java
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,59 @@ | ||
package io.vlingo.xoom.schemata.codegen; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public enum TypeMap { | ||
|
||
java(ofMapEntries( | ||
"boolean", "boolean", | ||
"byte", "byte", | ||
"char", "char", | ||
"short", "short", | ||
"int", "int", | ||
"long", "long", | ||
"float", "float", | ||
"double", "double", | ||
"string", "String", | ||
"type", "String", | ||
"version", "int", | ||
"timestamp", "long" | ||
)), | ||
csharp(ofMapEntries( | ||
"boolean", "bool", | ||
"byte", "byte", | ||
"char", "char", | ||
"short", "short", | ||
"int", "int", | ||
"long", "long", | ||
"float", "float", | ||
"double", "double", | ||
"type", "string", | ||
"version", "int", | ||
"timestamp", "long" | ||
)); | ||
|
||
final Map<String, String> types; | ||
|
||
TypeMap(Map<String, String> types) { | ||
this.types = Collections.unmodifiableMap(types); | ||
} | ||
|
||
public String typeOf(String type){ | ||
return types.getOrDefault(type, type); | ||
} | ||
|
||
private static Map<String, String> ofMapEntries(String ... entries) { | ||
if (entries.length % 2 != 0){ | ||
throw new IllegalArgumentException("parameters must even"); | ||
} | ||
Map<String, String> result = new HashMap<>(); | ||
for (int i=0; i<entries.length-1; i+=2){ | ||
String key = entries[i]; | ||
String val = entries[i+1]; | ||
result.put(key, val); | ||
} | ||
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
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
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
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
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,20 +1,21 @@ | ||
package ${package}; | ||
package ${namespace}; | ||
|
||
import io.vlingo.xoom.common.version.SemanticVersion; | ||
import io.vlingo.xoom.lattice.model.DomainEvent; | ||
|
||
public final class ${typeName} extends DomainEvent { | ||
|
||
public final int semanticVersion; | ||
|
||
<#list children as p> | ||
public final ${p.type.name()} ${p.name}; | ||
<#list properties as p> | ||
public <#if !p.value??>final </#if>${p.type} ${p.name}<#if p.value??> = ${p.value}</#if>; | ||
</#list> | ||
|
||
public ${typeName}(<#list children as p>final ${p.type.name()} ${p.name}<#if p?has_next>, </#if></#list>) { | ||
this.semanticVersion = SemanticVersion.toValue("1.0.0"); | ||
<#list children as p> | ||
public ${typeName}(<#list properties as p><#if p.name != 'eventVersion'>final ${p.type} ${p.name}<#if p?has_next>, </#if></#if></#list>) { | ||
<#list properties as p> | ||
<#if p.name = 'eventVersion'> | ||
this.${p.name} = SemanticVersion.toValue("${version}"); | ||
<#else> | ||
this.${p.name} = ${p.name}; | ||
</#if> | ||
</#list> | ||
} | ||
} |
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
<root level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
</configuration> | ||
</configuration> |
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
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
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