Skip to content
Snippets Groups Projects
Commit ec1229b9 authored by René Schöne's avatar René Schöne
Browse files

working on concise grammar

- remove automatic boxing of collections
- fix a couple of errors
parent d613fb71
No related branches found
No related tags found
2 merge requests!22Resolve "Feature: Add context-free connect",!21Resolve "Make grammar(s) more concise"
Pipeline #12005 passed
This commit is part of merge request !22. Comments created here will be created in the context of that merge request.
Showing with 50 additions and 69 deletions
...@@ -9,7 +9,7 @@ aspect RagConnectNameResolution { ...@@ -9,7 +9,7 @@ aspect RagConnectNameResolution {
return result; return result;
} }
syn MappingDefinition EndpointDefinition.tryResolveMappingByToken(String id) { syn MappingDefinition EndpointDefinition.tryResolveMappingByToken(String id) {
for (MappingDefinition mappingDefinition : ragconnect().allMappingDefinitionList()) { for (MappingDefinition mappingDefinition : ragconnect().givenMappingDefinitionList()) {
if (mappingDefinition.getID().equals(id)) { if (mappingDefinition.getID().equals(id)) {
return mappingDefinition; return mappingDefinition;
} }
......
...@@ -99,8 +99,8 @@ aspect RagConnectNavigation { ...@@ -99,8 +99,8 @@ aspect RagConnectNavigation {
return result; return result;
} }
//--- allMappingDefinitionList --- //--- givenMappingDefinitionList ---
syn List<MappingDefinition> RagConnect.allMappingDefinitionList() { syn List<MappingDefinition> RagConnect.givenMappingDefinitionList() {
List<MappingDefinition> result = new ArrayList<>(); List<MappingDefinition> result = new ArrayList<>();
for (ConnectSpecification spec : getConnectSpecificationFileList()) { for (ConnectSpecification spec : getConnectSpecificationFileList()) {
spec.getMappingDefinitionList().forEach(result::add); spec.getMappingDefinitionList().forEach(result::add);
......
...@@ -2,4 +2,6 @@ aspect Util { ...@@ -2,4 +2,6 @@ aspect Util {
static String ASTNode.capitalize(String s) { static String ASTNode.capitalize(String s) {
return Character.toUpperCase(s.charAt(0)) + s.substring(1); return Character.toUpperCase(s.charAt(0)) + s.substring(1);
} }
protected T JastAddList.firstChild() { return getChild(0); }
protected T JastAddList.lastChild() { return getChild(getNumChild() - 1); }
} }
...@@ -4,7 +4,7 @@ Design considerations ...@@ -4,7 +4,7 @@ Design considerations
- [NEW in 1.0.0] no complete intermediate structure, but instead single nodes where applicable - [NEW in 1.0.0] no complete intermediate structure, but instead single nodes where applicable
*/ */
aspect NewStuff { aspect NewStuff {
syn List<TypeComponent> RagConnect.rootTypeComponentList() { syn List<TypeComponent> RagConnect.rootTypeComponents() {
List<TypeComponent> result = new ArrayList<>(); List<TypeComponent> result = new ArrayList<>();
for (Component child : rootNode.getComponentList()) { for (Component child : rootNode.getComponentList()) {
if (child.isTypeComponent()) { if (child.isTypeComponent()) {
...@@ -13,6 +13,7 @@ aspect NewStuff { ...@@ -13,6 +13,7 @@ aspect NewStuff {
} }
return result; return result;
} }
syn boolean RagConnect.hasRootTypeComponents() = !rootTypeComponents().isEmpty();
// inh boolean TypeComponent.isFirst(); // inh boolean TypeComponent.isFirst();
// eq RagConnect.getRootTypeComponentList(int i).isFirst() = i == 0; // eq RagConnect.getRootTypeComponentList(int i).isFirst() = i == 0;
...@@ -172,14 +173,14 @@ aspect NewStuff { ...@@ -172,14 +173,14 @@ aspect NewStuff {
} else { } else {
result = new MTokenReceiveDefinition(); result = new MTokenReceiveDefinition();
} }
} else if (getEndpointTarget().isTokenEndpointTarget()) { } else if (getEndpointTarget().isTypeEndpointTarget()) {
if (getSend()) { if (getSend()) {
result = new MTypeSendDefinition(); result = new MTypeSendDefinition();
} else { } else {
result = new MTypeReceiveDefinition(); result = new MTypeReceiveDefinition();
} }
} else { } else {
throw new RuntimeException("Unknown endpoint target type for " + this); throw new RuntimeException("Unknown endpoint target type: " + getEndpointTarget());
} }
result.setEndpointDefinition(this); result.setEndpointDefinition(this);
for (MappingDefinition def : effectiveMappings()) { for (MappingDefinition def : effectiveMappings()) {
...@@ -200,16 +201,8 @@ aspect NewStuff { ...@@ -200,16 +201,8 @@ aspect NewStuff {
return result; return result;
} }
syn List<TypeComponent> RagConnect.rootTypeComponents() { syn JastAddList<MInnerMappingDefinition> EndpointDefinition.innerMappingDefinitions() = toMustache().getInnerMappingDefinitionList();
List<TypeComponent> result = new ArrayList<>(); syn boolean EndpointDefinition.hasTypeEndpointTarget() = getEndpointTarget().isTypeEndpointTarget();
for (Component child : rootNode.getComponentList()) {
if (child.isTypeComponent()) {
result.add(child.asTypeComponent());
}
}
return result;
}
} }
aspect OldStuff { // copied unchanged, but should work aspect OldStuff { // copied unchanged, but should work
...@@ -292,13 +285,6 @@ aspect AspectGeneration { ...@@ -292,13 +285,6 @@ aspect AspectGeneration {
} }
}; };
} }
@Override
public Object coerce(Object object) {
if (object instanceof Collection) {
return new com.github.mustachejava.util.DecoratedCollection((Collection) object);
}
return super.coerce(object);
}
}; };
com.github.mustachejava.DefaultMustacheFactory mf = new com.github.mustachejava.DefaultMustacheFactory(); com.github.mustachejava.DefaultMustacheFactory mf = new com.github.mustachejava.DefaultMustacheFactory();
mf.setObjectHandler(roh); mf.setObjectHandler(roh);
......
...@@ -263,9 +263,9 @@ aspect Mappings { ...@@ -263,9 +263,9 @@ aspect Mappings {
return getEndpointTarget().targetTypeName(); return getEndpointTarget().targetTypeName();
} else { } else {
if (getSend()) { if (getSend()) {
return getMappingList().get(0).getFromType().prettyPrint();
} else {
return getMappingList().get(getMappingList().size() - 1).getToType().prettyPrint(); return getMappingList().get(getMappingList().size() - 1).getToType().prettyPrint();
} else {
return getMappingList().get(0).getFromType().prettyPrint();
} }
} }
} }
...@@ -326,7 +326,7 @@ aspect Mappings { ...@@ -326,7 +326,7 @@ aspect Mappings {
syn java.util.List<MappingDefinition> RagConnect.allMappingDefinitions() { syn java.util.List<MappingDefinition> RagConnect.allMappingDefinitions() {
java.util.List<MappingDefinition> result = new java.util.ArrayList<>(); java.util.List<MappingDefinition> result = new java.util.ArrayList<>();
// user-defined mappings // user-defined mappings
allMappingDefinitionList().iterator().forEachRemaining(result::add); givenMappingDefinitionList().iterator().forEachRemaining(result::add);
// byte[] <-> primitive conversion // byte[] <-> primitive conversion
result.add(defaultBytesToBooleanMapping()); result.add(defaultBytesToBooleanMapping());
result.add(defaultBytesToIntMapping()); result.add(defaultBytesToIntMapping());
......
...@@ -2,8 +2,8 @@ aspect RagConnectHandler { ...@@ -2,8 +2,8 @@ aspect RagConnectHandler {
{{#Handlers}} {{#Handlers}}
{{#InUse}} {{#InUse}}
private {{ClassName}} {{rootNodeName}}.{{FieldName}} = {{{Construction}}}; private {{ClassName}} {{rootNodeName}}.{{FieldName}} = {{{Construction}}};
{{#hasRootTypeComponents}}inh {{ClassName}} ASTNode.{{AttributeName}}();{{/hasRootTypeComponents}}
{{#rootTypeComponents}} {{#rootTypeComponents}}
{{#first}}inh {{ClassName}} ASTNode.{{AttributeName}}();{{/first}}
eq {{rootNodeName}}.get{{name}}().{{AttributeName}}() = {{FieldName}}; eq {{rootNodeName}}.get{{name}}().{{AttributeName}}() = {{FieldName}};
{{/rootTypeComponents}} {{/rootTypeComponents}}
syn {{ClassName}} {{rootNodeName}}.{{AttributeName}}() = {{FieldName}}; syn {{ClassName}} {{rootNodeName}}.{{AttributeName}}() = {{FieldName}};
......
{{{lastDefinitionToType}}} {{lastResult}}; {{{lastDefinitionToType}}} {{lastResult}};
try { try {
{{#InnerMappingDefinitions}} {{#innerMappingDefinitions}}
{{^last}}{{{toType}}} {{/last}}{{outputVarName}} = {{methodName}}({{inputVarName}}); {{^last}}{{{toType}}} {{/last}}{{outputVarName}} = {{methodName}}({{inputVarName}});
{{/InnerMappingDefinitions}} {{/innerMappingDefinitions}}
} catch (RagConnectRejectMappingException e) { } catch (RagConnectRejectMappingException e) {
// do not print message in case of rejection // do not print message in case of rejection
{{preemptiveReturn}} {{preemptiveReturn}}
......
{{#usesMqtt}}{{> mqtt}}{{/usesMqtt}} {{#usesMqtt}}{{> mqtt}}{{/usesMqtt}}
{{> handler}} {{> handler}}
aspect RagConnect { aspect RagConnect {
{{#TokenReceiveDefinitions}} {{#allEndpointDefinitionList}}
{{> receiveDefinition}} {{#Send}}
{{/TokenReceiveDefinitions}}
{{#TokenSendDefinitions}}
{{> sendDefinition}} {{> sendDefinition}}
{{/TokenSendDefinitions}} {{/Send}}
{{^Send}}
{{#TypeReceiveDefinitions}}
{{> receiveDefinition}} {{> receiveDefinition}}
{{/TypeReceiveDefinitions}} {{/Send}}
{{/allEndpointDefinitionList}}
{{#TypeSendDefinitions}}
{{> sendDefinition}}
{{/TypeSendDefinitions}}
class RagConnectRejectMappingException extends RuntimeException {} class RagConnectRejectMappingException extends RuntimeException {}
private static void ASTNode.reject() { private static void ASTNode.reject() {
throw new RagConnectRejectMappingException(); throw new RagConnectRejectMappingException();
} }
{{#MappingDefinitions}} {{#allMappingDefinitions}}
{{#isUsed}} {{#isUsed}}
{{> mappingDefinition}} {{> mappingDefinition}}
{{/isUsed}} {{/isUsed}}
{{/MappingDefinitions}} {{/allMappingDefinitions}}
{{#DependencyDefinitions}} {{#allDependencyDefinitionList}}
{{> dependencyDefinition}} {{> dependencyDefinition}}
{{/DependencyDefinitions}} {{/allDependencyDefinitionList}}
{{#tokenComponentsThatNeedProxy}} {{#tokenComponentsThatNeedProxy}}
{{> tokenComponent}} {{> tokenComponent}}
......
...@@ -13,55 +13,55 @@ private int {{parentTypeName}}.{{resolveInListMethodName}}(String topic) { ...@@ -13,55 +13,55 @@ private int {{parentTypeName}}.{{resolveInListMethodName}}(String topic) {
/** /**
* Connects the receive endpoint {{entityName}}. * Connects the receive endpoint {{entityName}}.
{{#typeIsList}}{{#isWithAdd}} {{#typeIsList}}{{#WithAdd}}
* New values are appended to the end of the list. * New values are appended to the end of the list.
{{/isWithAdd}}{{/typeIsList}} {{/WithAdd}}{{/typeIsList}}
* @param {{connectParameterName}} string describing protocol and path as an URI * @param {{connectParameterName}} string describing protocol and path as an URI
{{#typeIsList}}{{#IndexBasedListAccess}}{{^isWithAdd}} {{#typeIsList}}{{#IndexBasedListAccess}}{{^WithAdd}}
* @param index index of node in list to connect (the list is expected to have enough elements) * @param index index of node in list to connect (the list is expected to have enough elements)
{{/isWithAdd}}{{/IndexBasedListAccess}}{{/typeIsList}} {{/WithAdd}}{{/IndexBasedListAccess}}{{/typeIsList}}
* @return true if connect was successful, false otherwise * @return true if connect was successful, false otherwise
* @throws java.io.IOException if connect failed * @throws java.io.IOException if connect failed
*/ */
public boolean {{parentTypeName}}.{{connectMethod}}(String {{connectParameterName}}{{#typeIsList}}{{#IndexBasedListAccess}}{{^isWithAdd}}, int index{{/isWithAdd}}{{/IndexBasedListAccess}}{{/typeIsList}}) throws java.io.IOException { public boolean {{parentTypeName}}.{{connectMethod}}(String {{connectParameterName}}{{#typeIsList}}{{#IndexBasedListAccess}}{{^WithAdd}}, int index{{/WithAdd}}{{/IndexBasedListAccess}}{{/typeIsList}}) throws java.io.IOException {
java.util.function.BiConsumer<String, byte[]> consumer = (topic, message) -> { java.util.function.BiConsumer<String, byte[]> consumer = (topic, message) -> {
{{> mappingApplication}} {{> mappingApplication}}
{{#loggingEnabledForReads}} {{#loggingEnabledForReads}}
System.out.println("[Receive] " + {{connectParameterName}} + " -> {{entityName}} = " + {{lastResult}}); System.out.println("[Receive] " + {{connectParameterName}} + " -> {{entityName}} = " + {{lastResult}});
{{/loggingEnabledForReads}} {{/loggingEnabledForReads}}
{{#isTypeEndpointDefinition}} {{#hasTypeEndpointTarget}}
{{lastResult}}.treeResolveAll(); {{lastResult}}.treeResolveAll();
{{#typeIsList}} {{#typeIsList}}
{{^IndexBasedListAccess}} {{^IndexBasedListAccess}}
{{#isWithAdd}} {{#WithAdd}}
{{getterMethod}}().addAll({{lastResult}}); {{getterMethod}}().addAll({{lastResult}});
{{/isWithAdd}} {{/WithAdd}}
{{^isWithAdd}} {{^WithAdd}}
set{{entityName}}({{lastResult}}); set{{entityName}}({{lastResult}});
{{/isWithAdd}} {{/WithAdd}}
{{/IndexBasedListAccess}} {{/IndexBasedListAccess}}
{{#IndexBasedListAccess}} {{#IndexBasedListAccess}}
{{lastResult}}.set{{idTokenName}}(topic); {{lastResult}}.set{{idTokenName}}(topic);
{{#isWithAdd}} {{#WithAdd}}
{{getterMethod}}().add({{lastResult}}); {{getterMethod}}().add({{lastResult}});
{{/isWithAdd}} {{/WithAdd}}
{{^isWithAdd}} {{^WithAdd}}
set{{entityName}}({{lastResult}}, index); set{{entityName}}({{lastResult}}, index);
{{/isWithAdd}} {{/WithAdd}}
{{/IndexBasedListAccess}} {{/IndexBasedListAccess}}
{{/typeIsList}} {{/typeIsList}}
{{^typeIsList}} {{^typeIsList}}
set{{entityName}}({{lastResult}}); set{{entityName}}({{lastResult}});
{{/typeIsList}} {{/typeIsList}}
{{/isTypeEndpointDefinition}} {{/hasTypeEndpointTarget}}
{{^isTypeEndpointDefinition}} {{^hasTypeEndpointTarget}}
set{{entityName}}({{lastResult}}); set{{entityName}}({{lastResult}});
{{/isTypeEndpointDefinition}} {{/hasTypeEndpointTarget}}
}; };
return {{internalConnectMethod}}({{connectParameterName}}, consumer); return {{internalConnectMethod}}({{connectParameterName}}, consumer);
} }
{{#typeIsList}}{{#IndexBasedListAccess}}{{^isWithAdd}} {{#typeIsList}}{{#IndexBasedListAccess}}{{^WithAdd}}
/** /**
* Connects the receive endpoint {{entityName}} using a "wildcard" URI (if supported by the chosen protocol). * Connects the receive endpoint {{entityName}} using a "wildcard" URI (if supported by the chosen protocol).
* @param {{connectParameterName}} string describing protocol and path as an URI * @param {{connectParameterName}} string describing protocol and path as an URI
...@@ -84,7 +84,7 @@ public boolean {{parentTypeName}}.{{connectMethod}}(String {{connectParameterNam ...@@ -84,7 +84,7 @@ public boolean {{parentTypeName}}.{{connectMethod}}(String {{connectParameterNam
}; };
return {{internalConnectMethod}}({{connectParameterName}}, consumer); return {{internalConnectMethod}}({{connectParameterName}}, consumer);
} }
{{/isWithAdd}}{{/IndexBasedListAccess}}{{/typeIsList}} {{/WithAdd}}{{/IndexBasedListAccess}}{{/typeIsList}}
private boolean {{parentTypeName}}.{{internalConnectMethod}}(String {{connectParameterName}}, private boolean {{parentTypeName}}.{{internalConnectMethod}}(String {{connectParameterName}},
java.util.function.BiConsumer<String, byte[]> consumer) throws java.io.IOException { java.util.function.BiConsumer<String, byte[]> consumer) throws java.io.IOException {
......
public {{parentTypeName}} {{parentTypeName}}.set{{name}}({{javaType}} value) { public {{parentTypeName}} {{parentTypeName}}.set{{name}}({{javaType}} value) {
set{{internalName}}(value); set{{internalName}}(value);
{{#DependencyDefinitions}} {{#DependencySourceDefinitions}}
for ({{targetParentTypeName}} target : get{{internalRelationPrefix}}TargetList()) { for ({{targetParentTypeName}} target : get{{internalRelationPrefix}}TargetList()) {
{{#targetEndpointDefinition}} {{#targetEndpointDefinition}}
if (target.{{updateMethod}}()) { if (target.{{updateMethod}}()) {
...@@ -8,7 +8,7 @@ public {{parentTypeName}} {{parentTypeName}}.set{{name}}({{javaType}} value) { ...@@ -8,7 +8,7 @@ public {{parentTypeName}} {{parentTypeName}}.set{{name}}({{javaType}} value) {
} }
{{/targetEndpointDefinition}} {{/targetEndpointDefinition}}
} }
{{/DependencyDefinitions}} {{/DependencySourceDefinitions}}
{{#normalTokenSendDef}} {{#normalTokenSendDef}}
if ({{updateMethod}}()) { if ({{updateMethod}}()) {
{{writeMethod}}(); {{writeMethod}}();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment