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 !21. 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 {
return result;
}
syn MappingDefinition EndpointDefinition.tryResolveMappingByToken(String id) {
for (MappingDefinition mappingDefinition : ragconnect().allMappingDefinitionList()) {
for (MappingDefinition mappingDefinition : ragconnect().givenMappingDefinitionList()) {
if (mappingDefinition.getID().equals(id)) {
return mappingDefinition;
}
......
......@@ -99,8 +99,8 @@ aspect RagConnectNavigation {
return result;
}
//--- allMappingDefinitionList ---
syn List<MappingDefinition> RagConnect.allMappingDefinitionList() {
//--- givenMappingDefinitionList ---
syn List<MappingDefinition> RagConnect.givenMappingDefinitionList() {
List<MappingDefinition> result = new ArrayList<>();
for (ConnectSpecification spec : getConnectSpecificationFileList()) {
spec.getMappingDefinitionList().forEach(result::add);
......
......@@ -2,4 +2,6 @@ aspect Util {
static String ASTNode.capitalize(String s) {
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
- [NEW in 1.0.0] no complete intermediate structure, but instead single nodes where applicable
*/
aspect NewStuff {
syn List<TypeComponent> RagConnect.rootTypeComponentList() {
syn List<TypeComponent> RagConnect.rootTypeComponents() {
List<TypeComponent> result = new ArrayList<>();
for (Component child : rootNode.getComponentList()) {
if (child.isTypeComponent()) {
......@@ -13,6 +13,7 @@ aspect NewStuff {
}
return result;
}
syn boolean RagConnect.hasRootTypeComponents() = !rootTypeComponents().isEmpty();
// inh boolean TypeComponent.isFirst();
// eq RagConnect.getRootTypeComponentList(int i).isFirst() = i == 0;
......@@ -172,14 +173,14 @@ aspect NewStuff {
} else {
result = new MTokenReceiveDefinition();
}
} else if (getEndpointTarget().isTokenEndpointTarget()) {
} else if (getEndpointTarget().isTypeEndpointTarget()) {
if (getSend()) {
result = new MTypeSendDefinition();
} else {
result = new MTypeReceiveDefinition();
}
} else {
throw new RuntimeException("Unknown endpoint target type for " + this);
throw new RuntimeException("Unknown endpoint target type: " + getEndpointTarget());
}
result.setEndpointDefinition(this);
for (MappingDefinition def : effectiveMappings()) {
......@@ -200,16 +201,8 @@ aspect NewStuff {
return result;
}
syn List<TypeComponent> RagConnect.rootTypeComponents() {
List<TypeComponent> result = new ArrayList<>();
for (Component child : rootNode.getComponentList()) {
if (child.isTypeComponent()) {
result.add(child.asTypeComponent());
}
}
return result;
}
syn JastAddList<MInnerMappingDefinition> EndpointDefinition.innerMappingDefinitions() = toMustache().getInnerMappingDefinitionList();
syn boolean EndpointDefinition.hasTypeEndpointTarget() = getEndpointTarget().isTypeEndpointTarget();
}
aspect OldStuff { // copied unchanged, but should work
......@@ -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();
mf.setObjectHandler(roh);
......
......@@ -263,9 +263,9 @@ aspect Mappings {
return getEndpointTarget().targetTypeName();
} else {
if (getSend()) {
return getMappingList().get(0).getFromType().prettyPrint();
} else {
return getMappingList().get(getMappingList().size() - 1).getToType().prettyPrint();
} else {
return getMappingList().get(0).getFromType().prettyPrint();
}
}
}
......@@ -326,7 +326,7 @@ aspect Mappings {
syn java.util.List<MappingDefinition> RagConnect.allMappingDefinitions() {
java.util.List<MappingDefinition> result = new java.util.ArrayList<>();
// user-defined mappings
allMappingDefinitionList().iterator().forEachRemaining(result::add);
givenMappingDefinitionList().iterator().forEachRemaining(result::add);
// byte[] <-> primitive conversion
result.add(defaultBytesToBooleanMapping());
result.add(defaultBytesToIntMapping());
......
......@@ -2,8 +2,8 @@ aspect RagConnectHandler {
{{#Handlers}}
{{#InUse}}
private {{ClassName}} {{rootNodeName}}.{{FieldName}} = {{{Construction}}};
{{#hasRootTypeComponents}}inh {{ClassName}} ASTNode.{{AttributeName}}();{{/hasRootTypeComponents}}
{{#rootTypeComponents}}
{{#first}}inh {{ClassName}} ASTNode.{{AttributeName}}();{{/first}}
eq {{rootNodeName}}.get{{name}}().{{AttributeName}}() = {{FieldName}};
{{/rootTypeComponents}}
syn {{ClassName}} {{rootNodeName}}.{{AttributeName}}() = {{FieldName}};
......
{{{lastDefinitionToType}}} {{lastResult}};
try {
{{#InnerMappingDefinitions}}
{{#innerMappingDefinitions}}
{{^last}}{{{toType}}} {{/last}}{{outputVarName}} = {{methodName}}({{inputVarName}});
{{/InnerMappingDefinitions}}
{{/innerMappingDefinitions}}
} catch (RagConnectRejectMappingException e) {
// do not print message in case of rejection
{{preemptiveReturn}}
......
{{#usesMqtt}}{{> mqtt}}{{/usesMqtt}}
{{> handler}}
aspect RagConnect {
{{#TokenReceiveDefinitions}}
{{> receiveDefinition}}
{{/TokenReceiveDefinitions}}
{{#TokenSendDefinitions}}
{{#allEndpointDefinitionList}}
{{#Send}}
{{> sendDefinition}}
{{/TokenSendDefinitions}}
{{#TypeReceiveDefinitions}}
{{/Send}}
{{^Send}}
{{> receiveDefinition}}
{{/TypeReceiveDefinitions}}
{{#TypeSendDefinitions}}
{{> sendDefinition}}
{{/TypeSendDefinitions}}
{{/Send}}
{{/allEndpointDefinitionList}}
class RagConnectRejectMappingException extends RuntimeException {}
private static void ASTNode.reject() {
throw new RagConnectRejectMappingException();
}
{{#MappingDefinitions}}
{{#allMappingDefinitions}}
{{#isUsed}}
{{> mappingDefinition}}
{{/isUsed}}
{{/MappingDefinitions}}
{{/allMappingDefinitions}}
{{#DependencyDefinitions}}
{{#allDependencyDefinitionList}}
{{> dependencyDefinition}}
{{/DependencyDefinitions}}
{{/allDependencyDefinitionList}}
{{#tokenComponentsThatNeedProxy}}
{{> tokenComponent}}
......
......@@ -13,55 +13,55 @@ private int {{parentTypeName}}.{{resolveInListMethodName}}(String topic) {
/**
* Connects the receive endpoint {{entityName}}.
{{#typeIsList}}{{#isWithAdd}}
{{#typeIsList}}{{#WithAdd}}
* New values are appended to the end of the list.
{{/isWithAdd}}{{/typeIsList}}
{{/WithAdd}}{{/typeIsList}}
* @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)
{{/isWithAdd}}{{/IndexBasedListAccess}}{{/typeIsList}}
{{/WithAdd}}{{/IndexBasedListAccess}}{{/typeIsList}}
* @return true if connect was successful, false otherwise
* @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) -> {
{{> mappingApplication}}
{{#loggingEnabledForReads}}
System.out.println("[Receive] " + {{connectParameterName}} + " -> {{entityName}} = " + {{lastResult}});
{{/loggingEnabledForReads}}
{{#isTypeEndpointDefinition}}
{{#hasTypeEndpointTarget}}
{{lastResult}}.treeResolveAll();
{{#typeIsList}}
{{^IndexBasedListAccess}}
{{#isWithAdd}}
{{#WithAdd}}
{{getterMethod}}().addAll({{lastResult}});
{{/isWithAdd}}
{{^isWithAdd}}
{{/WithAdd}}
{{^WithAdd}}
set{{entityName}}({{lastResult}});
{{/isWithAdd}}
{{/WithAdd}}
{{/IndexBasedListAccess}}
{{#IndexBasedListAccess}}
{{lastResult}}.set{{idTokenName}}(topic);
{{#isWithAdd}}
{{#WithAdd}}
{{getterMethod}}().add({{lastResult}});
{{/isWithAdd}}
{{^isWithAdd}}
{{/WithAdd}}
{{^WithAdd}}
set{{entityName}}({{lastResult}}, index);
{{/isWithAdd}}
{{/WithAdd}}
{{/IndexBasedListAccess}}
{{/typeIsList}}
{{^typeIsList}}
set{{entityName}}({{lastResult}});
{{/typeIsList}}
{{/isTypeEndpointDefinition}}
{{^isTypeEndpointDefinition}}
{{/hasTypeEndpointTarget}}
{{^hasTypeEndpointTarget}}
set{{entityName}}({{lastResult}});
{{/isTypeEndpointDefinition}}
{{/hasTypeEndpointTarget}}
};
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).
* @param {{connectParameterName}} string describing protocol and path as an URI
......@@ -84,7 +84,7 @@ public boolean {{parentTypeName}}.{{connectMethod}}(String {{connectParameterNam
};
return {{internalConnectMethod}}({{connectParameterName}}, consumer);
}
{{/isWithAdd}}{{/IndexBasedListAccess}}{{/typeIsList}}
{{/WithAdd}}{{/IndexBasedListAccess}}{{/typeIsList}}
private boolean {{parentTypeName}}.{{internalConnectMethod}}(String {{connectParameterName}},
java.util.function.BiConsumer<String, byte[]> consumer) throws java.io.IOException {
......
public {{parentTypeName}} {{parentTypeName}}.set{{name}}({{javaType}} value) {
set{{internalName}}(value);
{{#DependencyDefinitions}}
{{#DependencySourceDefinitions}}
for ({{targetParentTypeName}} target : get{{internalRelationPrefix}}TargetList()) {
{{#targetEndpointDefinition}}
if (target.{{updateMethod}}()) {
......@@ -8,7 +8,7 @@ public {{parentTypeName}} {{parentTypeName}}.set{{name}}({{javaType}} value) {
}
{{/targetEndpointDefinition}}
}
{{/DependencyDefinitions}}
{{/DependencySourceDefinitions}}
{{#normalTokenSendDef}}
if ({{updateMethod}}()) {
{{writeMethod}}();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment