Commit 70506fc3 authored by René Schöne's avatar René Schöne
Browse files

working on concise grammar

- reorder attributes in Generation.jadd to match mustache files and types
- fixed yaml generation (tested locally only)
parent c0d2b529
Pipeline #12051 passed with stages
in 9 minutes and 47 seconds
......@@ -58,9 +58,6 @@ aspect Analysis {
}
}
// --- shouldSendValue ---
syn boolean EndpointDefinition.shouldSendValue() = getSend() && getEndpointTarget().entityIsNormalAttribute();
syn boolean EndpointTarget.entityIsNormalAttribute();
eq TokenEndpointTarget.entityIsNormalAttribute() = !getToken().getNTA();
eq TypeEndpointTarget.entityIsNormalAttribute() = !getType().getNTA();
......@@ -76,11 +73,4 @@ aspect Analysis {
to MappingDefinition.effectiveUsedAt()
for each effectiveMappings();
// --- typeIsList ---
syn boolean EndpointDefinition.typeIsList() = getEndpointTarget().typeIsList();
syn boolean EndpointTarget.typeIsList() = false;
eq TypeEndpointTarget.typeIsList() {
return getType().isListComponent();
}
}
aspect ConfigurationShortcuts {
syn boolean RagConnect.loggingEnabledForReads() = getConfiguration().getLoggingEnabledForReads();
syn boolean RagConnect.loggingEnabledForWrites() = getConfiguration().getLoggingEnabledForWrites();
syn boolean RagConnect.loggingEnabledForIncremental() = getConfiguration().getLoggingEnabledForIncremental();
syn TypeDecl RagConnect.rootNode() = getConfiguration().getRootNode();
syn String RagConnect.JastAddList() = getConfiguration().getJastAddList();
syn boolean RagConnect.incrementalOptionActive() = getConfiguration().getIncrementalOptionActive();
syn boolean RagConnect.experimentalJastAdd329() = getConfiguration().getExperimentalJastAdd329();
}
......@@ -72,14 +72,6 @@ aspect RagConnectNavigation {
// return containedFile().getFileName();
}
//--- allEndpointDefinitionList ---
syn List<EndpointDefinition> RagConnect.allEndpointDefinitionList() {
List<EndpointDefinition> result = new ArrayList<>();
for (ConnectSpecification spec : getConnectSpecificationFileList()) {
spec.getEndpointDefinitionList().forEach(result::add);
}
return result;
}
//--- allEndpointTargetList ---
syn List<EndpointTarget> RagConnect.allEndpointTargetList() {
......@@ -90,14 +82,6 @@ aspect RagConnectNavigation {
return result;
}
//--- allDependencyDefinitionList ---
syn List<DependencyDefinition> RagConnect.allDependencyDefinitionList() {
List<DependencyDefinition> result = new ArrayList<>();
for (ConnectSpecification spec : getConnectSpecificationFileList()) {
spec.getDependencyDefinitionList().forEach(result::add);
}
return result;
}
//--- givenMappingDefinitionList ---
syn List<MappingDefinition> RagConnect.givenMappingDefinitionList() {
......@@ -108,26 +92,6 @@ aspect RagConnectNavigation {
return result;
}
// --- targetEndpointDefinition ---
syn EndpointDefinition DependencyDefinition.targetEndpointDefinition() {
// resolve definition in here, as we do not need resolveMethod in any other place (yet)
for (EndpointDefinition endpointDefinition : ragconnect().allEndpointDefinitionList()) {
if (!endpointDefinition.getSend()) {
continue;
}
EndpointTarget endpointTarget = endpointDefinition.getEndpointTarget();
if (endpointTarget.isTokenEndpointTarget() &&
endpointTarget.asTokenEndpointTarget().getToken().equals(this.getTarget())) {
return endpointDefinition;
}
if (endpointTarget.isTypeEndpointTarget() &&
endpointTarget.asTypeEndpointTarget().getType().equals(this.getTarget())) {
return endpointDefinition;
}
}
return null;
}
// --- effectiveJavaTypeUse (should be in preprocessor) ---
syn lazy JavaTypeUse TokenComponent.effectiveJavaTypeUse() = hasJavaTypeUse() ? getJavaTypeUse() : new SimpleJavaTypeUse("String");
......
......@@ -68,18 +68,18 @@ aspect DefaultMappings {
}
syn nta DefaultMappingDefinition RagConnect.defaultBytesToListTreeMapping(String typeName) {
return treeDefaultMappingDefinition("byte[]", JastAddList() + "<" + typeName + ">",
return treeDefaultMappingDefinition("byte[]", configJastAddList() + "<" + typeName + ">",
"String content = new String(input);\n" +
"com.fasterxml.jackson.databind.ObjectMapper mapper = new com.fasterxml.jackson.databind.ObjectMapper();\n" +
"com.fasterxml.jackson.core.JsonFactory factory = new com.fasterxml.jackson.core.JsonFactory();\n" +
"com.fasterxml.jackson.core.JsonParser parser = factory.createParser(content);\n" +
JastAddList() + "<" + typeName + ">" + " result = " + typeName + ".deserializeList((com.fasterxml.jackson.databind.node.ArrayNode)mapper.readTree(parser));\n" +
configJastAddList() + "<" + typeName + ">" + " result = " + typeName + ".deserializeList((com.fasterxml.jackson.databind.node.ArrayNode)mapper.readTree(parser));\n" +
"parser.close();\n" +
"return result;"
);
}
syn nta DefaultMappingDefinition RagConnect.defaultListTreeToBytesMapping() {
return treeDefaultMappingDefinition(JastAddList(), "byte[]",
return treeDefaultMappingDefinition(configJastAddList(), "byte[]",
"java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();\n" +
"com.fasterxml.jackson.core.JsonFactory factory = new com.fasterxml.jackson.core.JsonFactory();\n" +
"com.fasterxml.jackson.core.JsonGenerator generator = factory.createGenerator(outputStream, com.fasterxml.jackson.core.JsonEncoding.UTF8);\n" +
......
aspect MustacheNodesToYAML {
syn Document RagConnect.toYAML() {
Document doc = new Document();
MappingElement root = new MappingElement();
root.put("rootNodeName", rootNodeName());
root.put("closeMethodName", closeMethodName());
root.put("loggingEnabledForReads", loggingEnabledForReads());
root.put("loggingEnabledForWrites", loggingEnabledForWrites());
// rootTypeComponents
ListElement rootTypeComponents = new ListElement();
for (TypeComponent comp : rootTypeComponents()) {
MappingElement inner = new MappingElement();
rootTypeComponents.addElement(inner);
}
root.put("RootTypeComponents", rootTypeComponents);
// allEndpointDefinitionList
ListElement endpointDefinitions = new ListElement();
for (EndpointDefinition def : allEndpointDefinitionList()) {
endpointDefinitions.addElement(def.toYAML());
}
root.put("allEndpointDefinitionList", endpointDefinitions);
// allMappingDefinitions
ListElement mappingDefinitions = new ListElement();
for (MappingDefinition def : allMappingDefinitions()) {
mappingDefinitions.addElement(def.toYAML());
}
root.put("allMappingDefinitions", mappingDefinitions);
// allDependencyDefinitionList
ListElement dependencyDefinitions = new ListElement();
for (DependencyDefinition def : allDependencyDefinitionList()) {
dependencyDefinitions.addElement(def.toYAML());
}
root.put("allDependencyDefinitionList", dependencyDefinitions);
// tokenComponentsThatNeedProxy
ListElement tokenComponents = new ListElement();
for (TokenComponent comp : tokenComponentsThatNeedProxy()) {
tokenComponents.addElement(comp.toYAML());
}
root.put("tokenComponentsThatNeedProxy", tokenComponents);
// Handlers
ListElement handlers = new ListElement();
for (Handler handler : getHandlerList()) {
handlers.add(handler.toYAML()
// .put("rootTypeComponents", rootTypeComponents.treeCopy())
// .put("hasRootTypeComponents", hasRootTypeComponents())
);
}
root.put("Handlers", handlers);
root.put("mqttHandler", mqttHandler().toYAML());
root.put("restHandler", restHandler().toYAML());
doc.setRootElement(root);
return doc;
}
syn MappingElement EndpointDefinition.toYAML() {
MappingElement result = new MappingElement();
result.put("AlwaysApply", getAlwaysApply());
result.put("IndexBasedListAccess", getIndexBasedListAccess());
result.put("WithAdd", getWithAdd());
result.put("Send", getSend());
result.put("preemptiveExpectedValue", preemptiveExpectedValue());
result.put("preemptiveReturn", preemptiveReturn());
result.put("firstInputVarName", firstInputVarName());
result.put("updateMethodName", updateMethodName());
result.put("writeMethodName", writeMethodName());
result.put("parentTypeName", parentTypeName());
result.put("entityName", entityName());
result.put("getterMethodName", getterMethodName());
result.put("uniqueSuffix", uniqueSuffix());
result.put("connectParameterName", connectParameterName());
result.put("connectMethodName", connectMethodName());
result.put("internalConnectMethodName", internalConnectMethodName());
result.put("disconnectMethodName", disconnectMethodName());
result.put("typeDeclName", typeDeclName());
result.put("lastDefinition", lastDefinition().getMappingDefinition().toYAML().treeCopy());
result.put("lastDefinitionToType", lastDefinitionToType());
result.put("lastResult", lastResult());
result.put("condition", sanitizeValueForYAML(condition()));
result.put("senderName", senderName());
result.put("lastValue", lastValue());
result.put("tokenResetMethodName", tokenResetMethodName());
result.put("resolveInListMethodName", resolveInListMethodName());
result.put("idTokenName", idTokenName());
result.put("InnerMappingDefinitions", innerMappingDefinitionsAsListElement());
getEndpointTarget().addToYAML(result);
return result;
}
abstract void EndpointTarget.addToYAML(MappingElement result);
void TokenEndpointTarget.addToYAML(MappingElement result) {
result.put("tokenName", containingEndpointDefinition().tokenName());
}
void TypeEndpointTarget.addToYAML(MappingElement result) {
result.put("typeName", containingEndpointDefinition().typeName());
result.put("typeIsList", typeIsList());
}
void UntypedEndpointTarget.addToYAML(MappingElement result) {
}
syn Element MappingDefinition.toYAML() {
MappingElement result = new MappingElement();
result.put("toType", toType());
result.put("methodName", methodName());
result.put("fromType", fromType());
result.put("fromVariableName", getFromVariableName());
result.put("content", sanitizeValueForYAML(getContent()));
return result;
}
syn Element DependencyDefinition.toYAML() {
MappingElement result = new MappingElement();
result.put("targetParentTypeName", targetParentTypeName());
result.put("dependencyMethodName", dependencyMethodName());
result.put("sourceParentTypeName", sourceParentTypeName());
result.put("internalRelationPrefix", internalRelationPrefix());
return result;
}
syn Element TokenComponent.toYAML() {
MappingElement result = new MappingElement();
result.put("parentTypeName", parentTypeName());
result.put("name", getName());
result.put("javaType", javaType());
result.put("internalName", internalName());
ListElement dependencyDefinitions = new ListElement();
for (DependencyDefinition def : getDependencySourceDefinitionList()) {
MappingElement inner = new MappingElement();
inner.put("targetParentTypeName", def.targetParentTypeName());
inner.put("internalRelationPrefix", def.internalRelationPrefix());
MappingElement targetEndpointDefinition = new MappingElement();
targetEndpointDefinition.put("updateMethodName", def.targetEndpointDefinition().updateMethodName());
targetEndpointDefinition.put("writeMethodName", def.targetEndpointDefinition().writeMethodName());
inner.put("targetEndpointDefinition", targetEndpointDefinition);
dependencyDefinitions.addElement(inner);
}
result.put("DependencyDefinitions", dependencyDefinitions);
return result;
}
ListElement EndpointDefinition.innerMappingDefinitionsAsListElement() {
ListElement innerMappingDefinitions = new ListElement();
for (MInnerMappingDefinition def : innerMappingDefinitions()) {
MappingElement inner = new MappingElement();
inner.put("toType", def.toType());
inner.put("methodName", def.methodName());
inner.put("inputVarName", def.inputVarName());
inner.put("outputVarName", def.outputVarName());
inner.put("last", def.isLast());
innerMappingDefinitions.addElement(inner);
}
return innerMappingDefinitions;
}
syn MappingElement Handler.toYAML() {
MappingElement result = new MappingElement();
result.put("ClassName", getClassName());
result.put("ConstructionSnippet", ConstructionSnippet());
result.put("AttributeName", AttributeName());
result.put("FieldName", FieldName());
result.put("InUse", getInUse());
return result;
}
protected String ASTNode.sanitizeValueForYAML(String value) {
return value.replace("\"", "\\\"").replace("\n", "\\n");
}
}
aspect Navigation {
eq Document.getChild().program() = null;
eq Document.getChild().ragconnect() = null;
eq Document.getChild().containedFile() = null;
eq Document.containedFileName() = getFileName();
}
aspect MustacheNodesToYAML {
syn Document RagConnect.toYAML() {
Document doc = new Document();
MappingElement root = new MappingElement();
// grammar children
ListElement handlersElement = new ListElement();
for (Handler handler : getHandlerList()) {
handlersElement.add(handler.toYAML());
}
root.put("Handlers" , handlersElement);
// shared
root.put("configIncrementalOptionActive" , configIncrementalOptionActive());
root.put("configLoggingEnabledForIncremental" , configLoggingEnabledForIncremental());
root.put("configExperimentalJastAdd329" , configExperimentalJastAdd329());
root.put("rootNodeName" , rootNodeName());
// handler
root.put("closeMethodName" , closeMethodName());
root.put("hasRootTypeComponents" , hasRootTypeComponents());
ListElement rootTypeComponentsElement = new ListElement();
for (TypeComponent comp : rootTypeComponents()) {
rootTypeComponentsElement.addElement(comp.toYAML());
}
root.put("rootTypeComponents" , rootTypeComponentsElement);
// listAspect
root.put("configJastAddList" , configJastAddList());
root.put("hasTreeListEndpoints" , hasTreeListEndpoints());
ListElement typesForReceivingListEndpointsElement = new ListElement();
for (TypeDecl typeDecl : typesForReceivingListEndpoints()) {
typesForReceivingListEndpointsElement.addElement(typeDecl.toYAML());
}
root.put("typesForReceivingListEndpoints" , typesForReceivingListEndpointsElement);
// ragconnect
ListElement dependencyDefinitionsElement = new ListElement();
for (DependencyDefinition def : allDependencyDefinitionList()) {
dependencyDefinitionsElement.addElement(def.toYAML());
}
root.put("allDependencyDefinitionList" , dependencyDefinitionsElement);
ListElement endpointDefinitionsElement = new ListElement();
for (EndpointDefinition def : allEndpointDefinitionList()) {
endpointDefinitionsElement.addElement(def.toYAML());
}
root.put("allEndpointDefinitionList" , endpointDefinitionsElement);
ListElement mappingDefinitionsElement = new ListElement();
for (MappingDefinition def : allMappingDefinitions()) {
mappingDefinitionsElement.addElement(def.toYAML());
}
root.put("allMappingDefinitions" , mappingDefinitionsElement);
ListElement tokenComponentsElement = new ListElement();
for (TokenComponent comp : tokenComponentsThatNeedProxy()) {
tokenComponentsElement.addElement(comp.toYAML());
}
root.put("tokenComponentsThatNeedProxy" , tokenComponentsElement);
// receive
root.put("configLoggingEnabledForReads" , configLoggingEnabledForReads());
// send
root.put("configLoggingEnabledForWrites" , configLoggingEnabledForWrites());
// from Handlers.jrag
root.put("mqttHandler" , mqttHandler().toYAML());
root.put("restHandler" , restHandler().toYAML());
doc.setRootElement(root);
return doc;
}
syn MappingElement EndpointDefinition.toYAML() {
MappingElement result = new MappingElement();
// grammar children
result.put("AlwaysApply" , getAlwaysApply());
result.put("IndexBasedListAccess" , getIndexBasedListAccess());
result.put("WithAdd" , getWithAdd());
result.put("Send" , getSend());
// shared
result.put("lastResult" , lastResult());
// mapping
result.put("condition" , sanitizeValueForYAML(condition()));
ListElement innerMappingDefinitions = new ListElement();
for (MInnerMappingDefinition def : innerMappingDefinitions()) {
innerMappingDefinitions.addElement(def.toYAML());
}
result.put("innerMappingDefinitions" , innerMappingDefinitions);
result.put("lastDefinitionToType" , lastDefinitionToType());
result.put("preemptiveReturn" , preemptiveReturn());
// receive + send
result.put("connectMethodName" , connectMethodName());
result.put("connectParameterName" , connectParameterName());
result.put("disconnectMethodName" , disconnectMethodName());
result.put("entityName" , entityName());
result.put("getterMethodName" , getterMethodName());
result.put("parentTypeName" , parentTypeName());
if (getSend()) {
result.put("lastValue" , lastValue());
result.put("senderName" , senderName());
result.put("shouldSendValue" , shouldSendValue());
result.put("tokenResetMethodName" , tokenResetMethodName());
result.put("updateMethodName" , updateMethodName());
result.put("writeMethodName" , writeMethodName());
} else {
result.put("hasTypeEndpointTarget" , hasTypeEndpointTarget());
result.put("idTokenName" , idTokenName());
result.put("internalConnectMethodName" , internalConnectMethodName());
result.put("resolveInListMethodName" , resolveInListMethodName());
result.put("typeIsList" , getEndpointTarget().typeIsList());
}
return result;
}
void UntypedEndpointTarget.addToYAML(MappingElement result) {
// empty
}
syn Element MInnerMappingDefinition.toYAML() {
MappingElement result = new MappingElement();
result.put("last" , isLast());
result.put("inputVarName" , inputVarName());
result.put("methodName" , methodName());
result.put("outputVarName" , outputVarName());
result.put("toType" , toType());
return result;
}
syn Element MappingDefinition.toYAML() {
MappingElement result = new MappingElement();
// grammar children
result.put("FromVariableName" , getFromVariableName());
result.put("Content" , sanitizeValueForYAML(getContent()));
// mapping
result.put("fromType" , fromType());
result.put("methodName" , methodName());
result.put("toType" , toType());
// ragconnect
result.put("isUsed" , isUsed());
return result;
}
syn Element DependencyDefinition.toYAML() {
MappingElement result = new MappingElement();
// dependencyDefinition
result.put("dependencyMethodName" , dependencyMethodName());
result.put("internalRelationPrefix" , internalRelationPrefix());
result.put("sourceParentTypeName" , sourceParentTypeName());
result.put("targetParentTypeName" , targetParentTypeName());
// tokenComponent
result.put("targetEndpointDefinition" , targetEndpointDefinition().toYAML());
return result;
}
syn Element TokenComponent.toYAML() {
MappingElement result = new MappingElement();
result.put("Name" , getName());
ListElement dependencySourceDefinitions = new ListElement();
for (DependencyDefinition def : getDependencySourceDefinitionList()) {
dependencySourceDefinitions.add(def.toYAML());
}
result.put("DependencySourceDefinitions" , dependencySourceDefinitions);
result.put("javaType" , javaType());
result.put("normalTokenSendDef" , normalTokenSendDef().toYAML());
result.put("parentTypeName" , parentTypeName());
return result;
}
syn MappingElement Handler.toYAML() {
MappingElement result = new MappingElement();
result.put("ClassName" , getClassName());
result.put("InUse" , getInUse());
result.put("attributeName" , attributeName());
result.put("constructionSnippet" , constructionSnippet());
result.put("fieldName" , fieldName());
result.put("setupWaitUntilReadyMethodName" , setupWaitUntilReadyMethodName());
return result;
}
syn MappingElement TypeComponent.toYAML() {
return new MappingElement().put("Name", getName());
}
syn MappingElement TypeDecl.toYAML() {
return new MappingElement().put("Name", getName());
}
protected StringElement ASTNode.sanitizeValueForYAML(String value) {
return StringElement.of(value.replace("\"" , "\\\"").replace("\n" , "\\n"));
}
}
aspect Navigation {
eq Document.getChild().program() = null;
eq Document.getChild().ragconnect() = null;
eq Document.getChild().containedFile() = null;
eq Document.containedFileName() = getFileName();
}
{{#hasTreeListEndpoints}}
public void {{JastAddList}}.serialize(com.fasterxml.jackson.core.JsonGenerator g) throws SerializationException {
public void {{configJastAddList}}.serialize(com.fasterxml.jackson.core.JsonGenerator g) throws SerializationException {
try {
g.writeStartArray();
for (T child : this) {
......@@ -7,13 +7,13 @@ public void {{JastAddList}}.serialize(com.fasterxml.jackson.core.JsonGenerator g
}
g.writeEndArray();
} catch (java.io.IOException e) {
throw new SerializationException("unable to serialize {{JastAddList}}", e);
throw new SerializationException("unable to serialize {{configJastAddList}}", e);
}
}
{{#typesForReceivingListEndpoints}}
public static {{JastAddList}}<{{Name}}> {{Name}}.deserializeList(com.fasterxml.jackson.databind.node.ArrayNode node) throws DeserializationException {
{{JastAddList}}<{{Name}}> result = new {{JastAddList}}<>();
public static {{configJastAddList}}<{{Name}}> {{Name}}.deserializeList(com.fasterxml.jackson.databind.node.ArrayNode node) throws DeserializationException {
{{configJastAddList}}<{{Name}}> result = new {{configJastAddList}}<>();
for (java.util.Iterator<com.fasterxml.jackson.databind.JsonNode> it = node.elements(); it.hasNext();) {
com.fasterxml.jackson.databind.JsonNode element = it.next();
result.add(deserialize(element));
......
aspect RagConnectHandler {
{{#Handlers}}
{{#InUse}}
private {{ClassName}} {{rootNodeName}}.{{FieldName}} = {{{ConstructionSnippet}}};
{{#hasRootTypeComponents}}inh {{ClassName}} ASTNode.{{AttributeName}}();{{/hasRootTypeComponents}}
private {{ClassName}} {{rootNodeName}}.{{fieldName}} = {{{constructionSnippet}}};
{{#hasRootTypeComponents}}inh {{ClassName}} ASTNode.{{attributeName}}();{{/hasRootTypeComponents}}
{{#rootTypeComponents}}
eq {{rootNodeName}}.get{{name}}().{{AttributeName}}() = {{FieldName}};
eq {{rootNodeName}}.get{{Name}}().{{attributeName}}() = {{fieldName}};
{{/rootTypeComponents}}
syn {{ClassName}} {{rootNodeName}}.{{AttributeName}}() = {{FieldName}};
syn {{ClassName}} {{rootNodeName}}.{{attributeName}}() = {{fieldName}};
{{/InUse}}
{{/Handlers}}
public void {{rootNodeName}}.{{closeMethodName}}() {
{{#Handlers}}
{{#InUse}}{{FieldName}}.close();{{/InUse}}
{{#InUse}}{{fieldName}}.close();{{/InUse}}
{{/Handlers}}
}
{{#mqttHandler}}
{{#InUse}}
public void {{rootNodeName}}.{{SetupWaitUntilReadyMethodName}}(long time, java.util.concurrent.TimeUnit unit) {
{{FieldName}}.setupWaitUntilReady(time, unit);
public void {{rootNodeName}}.{{setupWaitUntilReadyMethodName}}(long time, java.util.concurrent.TimeUnit unit) {
{{fieldName}}.setupWaitUntilReady(time, unit);
}
{{/InUse}}
{{/mqttHandler}}
......
......@@ -10,8 +10,8 @@ try {
e.printStackTrace();
{{preemptiveReturn}}
}
{{^alwaysApply}}
{{^AlwaysApply}}
if ({{{condition}}}) {
{{preemptiveReturn}}
}
{{/alwaysApply}}
{{/AlwaysApply}}
protected static {{{toType}}} ASTNode.{{methodName}}({{{fromType}}} {{fromVariableName}}) throws Exception {
{{{content}}}
protected static {{{toType}}} ASTNode.{{methodName}}({{{fromType}}} {{FromVariableName}}) throws Exception {
{{{Content}}}
}
......@@ -31,7 +31,7 @@ aspect RagConnect {
{{> ListAspect}}
public void {{rootNodeName}}.ragconnectCheckIncremental() {
{{#incrementalOptionActive}}
{{#configIncrementalOptionActive}}
// check if --tracing is active
trace().getReceiver();
// check if tracing of INC_FLUSH_ATTR is possible, i.e., if --tracing=flush
......@@ -40,11 +40,11 @@ aspect RagConnect {
mayHaveRewrite();
// check if --incremental is active
Object checkIncremental = inc_throwAway_visited;
{{/incrementalOptionActive}}
{{/configIncrementalOptionActive}}
}
}
{{#incrementalOptionActive}}
{{#configIncrementalOptionActive}}
aspect RagConnectObserver {