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

working on concise grammar

- auto-format aspects
- some refactorings for #39
- unified handler setup
- cleanup
- update extending.md for new process (fewer steps now)
parent 8dd7a3fa
Pipeline #12018 passed with stages
in 9 minutes and 44 seconds
# Extending `RagConnect`
To add a new communication protocol, the following locations have to be changed (replace `ABC` and `abc` with the name of the protocol):
To add a new communication protocol, the following locations have to be changed (replace `ABC` and `abc` with the name of the protocol).
Within `ragconnect.base/src/main/resources`:
### Within `ragconnect.base/src/main/resources`
{% raw %}
- Add a new handler `ABCHandler`, if appropriate, similar to the existing handlers
- If further methods are needed for handler initialization, add a new template `abc.mustache` containing those procedures. Add `{{#usesABC}}{{> abc}}{{/usesABC}}` at the top of `ragconnect.mustache` to use this template
- In `receiveDefinition.mustache` and `sendDefinition.mustache`: add a new case in the switch statement defining the logic to happen for both definitions. If the new protocol is close to a PUSH semantic, follow `mqtt`. If it is closer to PULL semantic, follow `rest`.
- Add a new handler `ABCHandler.jadd`, similar to the existing handlers.
- In `handler.mustache`, add further methods if needed for handler usage in the application code (similar to `{{rootNodeName}}.{{SetupWaitUntilReadyMethodName}}` for `mqtt`)
- In `receiveDefinition.mustache` and `sendDefinition.mustache`: add a new case in the switch statements defining the logic to happen upon connect and disconnect for both definitions. If the new protocol is close to a PUSH semantic, follow `mqtt`. If it is closer to PULL semantic, follow `rest`.
{% endraw %}
Within `ragconnect.base/src/main/jastadd`:
### Within `ragconnect.base/src/main/jastadd`
- In `backend/Configuration`:
- Add a new static boolean flag `usesABC` to indicate whether the protocol is used
- In `backend/Generation`:
- Add new attributes for type `MRagConnect` for handler attribute and handler field, if needed
- Add attributes for newly introduced references in changed mustache templates, if any
- Add a newly constructed handler within the definition of `RagConnect.toMustache` with the needed fields (class name, construction snippet, handler attribute, handler field, the boolean flag you just added to Configuration)
- In `backend/MustacheNodesToYAML`:
- Add key-value-pair for `usesABC` (and handler, if any)
- Add key-value-pairs for newly introduced referemces in changed mustache templates, if any
In `Handlers.jrag`: Add a new attribute `RagConnect.abcHandler()` returning the resolved handler
In `ragconnect.base/src/main/java/org/jastadd/ragconnect/compiler/Compiler.java`:
### Within `ragconnect.base/src/main/java/org/jastadd/ragconnect/compiler`
In `Compiler.java`:
- Add a new choice for `--protocols` similar to the existing ones
- Set the flag `usesABC` if the choice is given.
- Add code to add the handler to the list `handlers` if the choice is given, i.e., if `ASTNode.usesABC`
- Add a newly constructed handler in `setConfiguration` with the needed fields (definition file name within `resources` directory, commonly `ABCHandler.jadd`; class name of the handler; unique name for the protocol; whether the handler is used, i.e., if it was given in `--protocols`)
Furthermore, new test cases are appreciated, see [below](#writing-tests).
......@@ -58,7 +50,7 @@ All tests are required to run both locally, and within the CI.
### build.gradle
Use the [PreprocessorPlugin][preprocessor-plugin], the build process can be written concisely in three parts per task:
Using the [PreprocessorPlugin][preprocessor-plugin], the build process can be written concisely in three parts per task:
```groovy
task compileTreeAllowedTokens(type: RagConnectTest) {
......
aspect Analysis {
// --- lookupTokenEndpointDefinition ---
inh java.util.List<EndpointDefinition> EndpointDefinition.lookupTokenEndpointDefinitions(TokenComponent token);
inh java.util.List<EndpointDefinition> EndpointTarget.lookupTokenEndpointDefinitions(TokenComponent token);
eq RagConnect.getConnectSpecificationFile().lookupTokenEndpointDefinitions(TokenComponent token) = lookupTokenEndpointDefinitions(token);
syn java.util.List<EndpointDefinition> RagConnect.lookupTokenEndpointDefinitions(TokenComponent token) {
java.util.List<EndpointDefinition> result = new java.util.ArrayList<>();
for (EndpointTarget target : allEndpointTargetList()) {
if (target.isTokenEndpointTarget() && target.asTokenEndpointTarget().getToken().equals(token)) {
result.add(target.containingEndpointDefinition());
}
}
return result;
}
// --- lookupTypeEndpointDefinition ---
inh java.util.List<EndpointDefinition> EndpointDefinition.lookupTypeEndpointDefinitions(TypeComponent type);
inh java.util.List<EndpointDefinition> EndpointTarget.lookupTypeEndpointDefinitions(TypeComponent type);
eq RagConnect.getConnectSpecificationFile().lookupTypeEndpointDefinitions(TypeComponent type) = lookupTypeEndpointDefinitions(type);
syn java.util.List<EndpointDefinition> RagConnect.lookupTypeEndpointDefinitions(TypeComponent type) {
java.util.List<EndpointDefinition> result = new java.util.ArrayList<>();
for (EndpointTarget target : allEndpointTargetList()) {
if (target.isTypeEndpointTarget() && target.asTypeEndpointTarget().getType().equals(type)) {
result.add(target.containingEndpointDefinition());
}
}
return result;
}
// --- lookupDependencyDefinition ---
inh DependencyDefinition DependencyDefinition.lookupDependencyDefinition(TypeDecl source, String id);
eq RagConnect.getConnectSpecificationFile().lookupDependencyDefinition(TypeDecl source, String id) {
for (DependencyDefinition def : allDependencyDefinitionList()) {
if (def.getID().equals(id) && def.getSource().containingTypeDecl().equals(source)) {
return def;
}
}
return null;
}
// --- isAlreadyDefined ---
syn boolean EndpointDefinition.isAlreadyDefined() = getEndpointTarget().isAlreadyDefined();
syn boolean EndpointTarget.isAlreadyDefined();
eq TokenEndpointTarget.isAlreadyDefined() {
return lookupTokenEndpointDefinitions(getToken()).stream()
.filter(containingEndpointDefinition()::matchesType)
.count() > 1;
.filter(containingEndpointDefinition()::matchesType)
.count() > 1;
}
eq TypeEndpointTarget.isAlreadyDefined() {
return lookupTypeEndpointDefinitions(getType()).stream()
.filter(containingEndpointDefinition()::matchesType)
.count() > 1;
.filter(containingEndpointDefinition()::matchesType)
.count() > 1;
}
syn boolean DependencyDefinition.isAlreadyDefined() = lookupDependencyDefinition(getSource().containingTypeDecl(), getID()) != this;
......@@ -60,7 +21,9 @@ aspect Analysis {
syn boolean MappingDefinitionType.assignableTo(JavaTypeUse target);
eq JavaMappingDefinitionType.assignableTo(JavaTypeUse target) = getType().assignableTo(target);
eq JavaArrayMappingDefinitionType.assignableTo(JavaTypeUse target) {
if (!target.getName().endsWith("[]")) { return false; }
if (!target.getName().endsWith("[]")) {
return false;
}
return getType().assignableTo(new SimpleJavaTypeUse(target.getName().replace("[]", "")));
}
syn boolean JavaTypeUse.assignableTo(JavaTypeUse target) {
......@@ -68,22 +31,30 @@ aspect Analysis {
return target.primitivePrettyPrint().equals(this.primitivePrettyPrint());
}
syn String JavaTypeUse.primitivePrettyPrint() {
switch(getName()) {
switch (getName()) {
case "boolean":
case "Boolean": return "boolean";
case "Boolean":
return "boolean";
case "int":
case "Integer": return "int";
case "Integer":
return "int";
case "short":
case "Short": return "short";
case "Short":
return "short";
case "long":
case "Long": return "long";
case "Long":
return "long";
case "float":
case "Float": return "float";
case "Float":
return "float";
case "double":
case "Double": return "double";
case "Double":
return "double";
case "char":
case "Character": return "char";
default: return getName();
case "Character":
return "char";
default:
return getName();
}
}
......
aspect Configuration {
public static boolean ASTNode.loggingEnabledForReads = false;
public static boolean ASTNode.loggingEnabledForWrites = false;
public static boolean ASTNode.loggingEnabledForIncremental = false;
public static TypeDecl ASTNode.rootNode;
public static String ASTNode.JastAddList = "List";
public static boolean ASTNode.usesMqtt;
public static boolean ASTNode.usesRest;
public static boolean ASTNode.incrementalOptionActive;
public static boolean ASTNode.experimentalJastAdd329;
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();
}
......@@ -3,36 +3,37 @@ aspect Errors {
[new TreeSet<ErrorMessage>()]
root RagConnect;
EndpointDefinition contributes error("Endpoint definition already defined for " + parentTypeName() + "." + entityName())
when isAlreadyDefined()
to RagConnect.errors();
EndpointDefinition contributes error("Endpoint definition already defined for " + parentTypeName() + "." + entityName())
when isAlreadyDefined()
to RagConnect.errors();
EndpointDefinition contributes error("Receiving target token must not be an NTA token!")
when !getSend() && getEndpointTarget().isTokenEndpointTarget() && token().getNTA()
to RagConnect.errors();
EndpointDefinition contributes error("Receiving target token must not be an NTA token!")
when !getSend() && getEndpointTarget().isTokenEndpointTarget() && token().getNTA()
to RagConnect.errors();
// if first mapping is null, then suitableDefaultMapping() == null
EndpointDefinition contributes error("No suitable default mapping found for type " +
// if first mapping is null, then suitableDefaultMapping() == null
EndpointDefinition contributes error("No suitable default mapping found for type " +
((getMappingList().isEmpty())
? token().effectiveJavaTypeUse().prettyPrint()
: getMappingList().get(0).getFromType().prettyPrint()))
when !getSend() && getEndpointTarget().isTokenEndpointTarget() && effectiveMappings().get(0) == null
to RagConnect.errors();
// TODO copy for type endpoint target
EndpointDefinition contributes error("to-type of last mapping (" + effectiveMappings().get(effectiveMappings().size() - 1).getToType().prettyPrint() + ") not assignable to type of the token (" + token().effectiveJavaTypeUse().prettyPrint() + ")!")
when !getSend() && getEndpointTarget().isTokenEndpointTarget() &&
!effectiveMappings().get(effectiveMappings().size() - 1).getToType().assignableTo(
token().effectiveJavaTypeUse())
to RagConnect.errors();
DependencyDefinition contributes error("Dependency definition already defined for " + getSource().containingTypeDecl().getName() + " with name " + getID())
when isAlreadyDefined()
to RagConnect.errors();
DependencyDefinition contributes error("The name of a dependency definition must not be equal to a list-node on the source")
when isAlreadyDefinedAsList()
to RagConnect.errors();
? token().effectiveJavaTypeUse().prettyPrint()
: getMappingList().get(0).getFromType().prettyPrint()))
when !getSend() && getEndpointTarget().isTokenEndpointTarget() && effectiveMappings().get(0) == null
to RagConnect.errors();
EndpointDefinition contributes error("to-type of last mapping (" +
effectiveMappings().get(effectiveMappings().size() - 1).getToType().prettyPrint() +
") not assignable to type of the token (" + token().effectiveJavaTypeUse().prettyPrint() + ")!")
when !getSend() && getEndpointTarget().isTokenEndpointTarget() &&
!effectiveMappings().get(effectiveMappings().size() - 1).getToType().assignableTo(
token().effectiveJavaTypeUse())
to RagConnect.errors();
DependencyDefinition contributes error("Dependency definition already defined for " + getSource().containingTypeDecl().getName() + " with name " + getID())
when isAlreadyDefined()
to RagConnect.errors();
DependencyDefinition contributes error("The name of a dependency definition must not be equal to a list-node on the source")
when isAlreadyDefinedAsList()
to RagConnect.errors();
}
aspect ErrorHelpers {
......@@ -65,12 +66,15 @@ aspect ErrorMessage {
public ASTNode getNode() {
return node;
}
public int getLine() {
return line;
}
public int getCol() {
return col;
}
public String getMessage() {
return message;
}
......@@ -91,7 +95,7 @@ aspect ErrorMessage {
return n;
}
n = col-err.col;
n = col - err.col;
if (n != 0) {
return n;
}
......
aspect RagConnectHandlers {
syn Handler RagConnect.mqttHandler() = resolveHandlerByName("mqtt");
syn Handler RagConnect.restHandler() = resolveHandlerByName("rest");
private Handler RagConnect.resolveHandlerByName(String uniqueName) {
for (Handler handler : getHandlerList()) {
if (uniqueName.equals(handler.getUniqueName())) {
return handler;
}
}
System.err.println("Could not find handler with name '" + uniqueName + "'");
return null;
}
}
aspect RagConnectNameResolution {
// --- lookupTokenEndpointDefinition ---
inh java.util.List<EndpointDefinition> EndpointDefinition.lookupTokenEndpointDefinitions(TokenComponent token);
inh java.util.List<EndpointDefinition> EndpointTarget.lookupTokenEndpointDefinitions(TokenComponent token);
eq RagConnect.getConnectSpecificationFile().lookupTokenEndpointDefinitions(TokenComponent token) = lookupTokenEndpointDefinitions(token);
syn java.util.List<EndpointDefinition> RagConnect.lookupTokenEndpointDefinitions(TokenComponent token) {
java.util.List<EndpointDefinition> result = new java.util.ArrayList<>();
for (EndpointTarget target : allEndpointTargetList()) {
if (target.isTokenEndpointTarget() && target.asTokenEndpointTarget().getToken().equals(token)) {
result.add(target.containingEndpointDefinition());
}
}
return result;
}
// --- lookupTypeEndpointDefinition ---
inh java.util.List<EndpointDefinition> EndpointDefinition.lookupTypeEndpointDefinitions(TypeComponent type);
inh java.util.List<EndpointDefinition> EndpointTarget.lookupTypeEndpointDefinitions(TypeComponent type);
eq RagConnect.getConnectSpecificationFile().lookupTypeEndpointDefinitions(TypeComponent type) = lookupTypeEndpointDefinitions(type);
syn java.util.List<EndpointDefinition> RagConnect.lookupTypeEndpointDefinitions(TypeComponent type) {
java.util.List<EndpointDefinition> result = new java.util.ArrayList<>();
for (EndpointTarget target : allEndpointTargetList()) {
if (target.isTypeEndpointTarget() && target.asTypeEndpointTarget().getType().equals(type)) {
result.add(target.containingEndpointDefinition());
}
}
return result;
}
// --- lookupDependencyDefinition ---
inh DependencyDefinition DependencyDefinition.lookupDependencyDefinition(TypeDecl source, String id);
eq RagConnect.getConnectSpecificationFile().lookupDependencyDefinition(TypeDecl source, String id) {
for (DependencyDefinition def : allDependencyDefinitionList()) {
if (def.getID().equals(id) && def.getSource().containingTypeDecl().equals(source)) {
return def;
}
}
return null;
}
// rel EndpointDefinition.Mapping* -> MappingDefinition
refine RefResolverStubs eq EndpointDefinition.resolveMappingByToken(String id, int position) {
......@@ -64,7 +102,7 @@ aspect RagConnectNameResolution {
}
// rel ___ -> TokenComponent (from relast-preprocessor)
// refine here to have an attribute without writing on stderr if not found
// refine from relast PP here to have an attribute that does not write on stderr if no TokenComponent was found
refine NameResolution eq ASTNode.globallyResolveTokenComponentByToken(String id) {
TokenComponent result = tryGloballyResolveTokenComponentByToken(id);
if (result == null) {
......
......@@ -112,7 +112,9 @@ aspect RagConnectNavigation {
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; }
if (!endpointDefinition.getSend()) {
continue;
}
EndpointTarget endpointTarget = endpointDefinition.getEndpointTarget();
if (endpointTarget.isTokenEndpointTarget() &&
endpointTarget.asTokenEndpointTarget().getToken().equals(this.getTarget())) {
......
RagConnect ::= ConnectSpecificationFile* Handler* Program ;
RagConnect ::= ConnectSpecificationFile* Program Handler* Configuration;
abstract ConnectSpecification ::= EndpointDefinition* DependencyDefinition* MappingDefinition* ;
ConnectSpecificationFile : ConnectSpecification ::= <FileName> ;
abstract ConnectSpecification ::= EndpointDefinition* DependencyDefinition* MappingDefinition*;
ConnectSpecificationFile : ConnectSpecification ::= <FileName>;
EndpointDefinition ::= <AlwaysApply:boolean> <IndexBasedListAccess:boolean> <WithAdd:boolean> <Send:boolean> EndpointTarget ;
EndpointDefinition ::= <AlwaysApply:boolean> <IndexBasedListAccess:boolean> <WithAdd:boolean> <Send:boolean> EndpointTarget;
rel EndpointDefinition.Mapping* <-> MappingDefinition.UsedAt*;
abstract EndpointTarget ;
TokenEndpointTarget : EndpointTarget ;
rel TokenEndpointTarget.Token <-> TokenComponent.TokenEndpointTarget* ;
TypeEndpointTarget : EndpointTarget ;
rel TypeEndpointTarget.Type <-> TypeComponent.TypeEndpointTarget* ;
UntypedEndpointTarget : EndpointTarget ::= <TokenOrType> ; // only used by parser
abstract EndpointTarget;
TokenEndpointTarget : EndpointTarget;
rel TokenEndpointTarget.Token <-> TokenComponent.TokenEndpointTarget*;
TypeEndpointTarget : EndpointTarget;
rel TypeEndpointTarget.Type <-> TypeComponent.TypeEndpointTarget*;
UntypedEndpointTarget : EndpointTarget ::= <TokenOrType>; // only used by parser
// to be integrated:
//AttributeEndpointTarget : EndpointTarget ::= <Name> ;
//RelationEndpointTarget : EndpointTarget ;
......@@ -21,10 +21,19 @@ DependencyDefinition ::= <ID>;
rel DependencyDefinition.Source <-> TokenComponent.DependencySourceDefinition*;
rel DependencyDefinition.Target -> Component;
MappingDefinition ::= <ID> FromType:MappingDefinitionType <FromVariableName> ToType:MappingDefinitionType <Content> ;
MappingDefinition ::= <ID> FromType:MappingDefinitionType <FromVariableName> ToType:MappingDefinitionType <Content>;
abstract MappingDefinitionType ::= ;
JavaMappingDefinitionType : MappingDefinitionType ::= Type:JavaTypeUse ;
JavaArrayMappingDefinitionType : MappingDefinitionType ::= Type:JavaTypeUse ;
DefaultMappingDefinition : MappingDefinition ;
JavaMappingDefinitionType : MappingDefinitionType ::= Type:JavaTypeUse;
JavaArrayMappingDefinitionType : MappingDefinitionType ::= Type:JavaTypeUse;
DefaultMappingDefinition : MappingDefinition;
Handler ::= <ClassName> <Construction> <AttributeName> <FieldName> <InUse:boolean>;
Handler ::= <DefinitionFileName> <ClassName> <UniqueName> <InUse:boolean>;
Configuration ::=
<LoggingEnabledForReads:boolean>
<LoggingEnabledForWrites:boolean>
<LoggingEnabledForIncremental:boolean>
<JastAddList:String>
<IncrementalOptionActive:boolean>
<ExperimentalJastAdd329:boolean>;
rel Configuration.RootNode -> TypeDecl ;
RagConnect ::= ConnectSpecificationFile* Program ;
abstract ConnectSpecification ::= EndpointDefinition* DependencyDefinition* MappingDefinition* ;
ConnectSpecificationFile : ConnectSpecification ::= <FileName> ;
abstract EndpointDefinition ::= <AlwaysApply:boolean> ;
rel EndpointDefinition.Mapping* <-> MappingDefinition.UsedAt*;
abstract TokenEndpointDefinition : EndpointDefinition;
rel TokenEndpointDefinition.Token <-> TokenComponent.TokenEndpointDefinition*;
ReceiveTokenEndpointDefinition : TokenEndpointDefinition;
SendTokenEndpointDefinition : TokenEndpointDefinition;
abstract TypeEndpointDefinition : EndpointDefinition ::= <IndexBasedListAccess:boolean> ;
rel TypeEndpointDefinition.Type <-> TypeComponent.TypeEndpointDefinition*;
ReceiveTypeEndpointDefinition : TypeEndpointDefinition ::= <WithAdd:boolean>;
SendTypeEndpointDefinition : TypeEndpointDefinition;
DependencyDefinition ::= <ID>;
rel DependencyDefinition.Source <-> TokenComponent.DependencySourceDefinition*;
rel DependencyDefinition.Target -> Component;
MappingDefinition ::= <ID> FromType:MappingDefinitionType <FromVariableName> ToType:MappingDefinitionType <Content> ;
abstract MappingDefinitionType ::= ;
JavaMappingDefinitionType : MappingDefinitionType ::= Type:JavaTypeUse ;
JavaArrayMappingDefinitionType : MappingDefinitionType ::= Type:JavaTypeUse ;
DefaultMappingDefinition : MappingDefinition ;
// only used by parser
abstract UntypedEndpointDefinition : EndpointDefinition ::= <TokenOrType> <Indexed:boolean> <WithAdd:boolean> ;
ReceiveUntypedEndpointDefinition : UntypedEndpointDefinition;
SendUntypedEndpointDefinition : UntypedEndpointDefinition;
......@@ -6,7 +6,7 @@ Design considerations
aspect AttributesForMustache {
syn List<TypeComponent> RagConnect.rootTypeComponents() {
List<TypeComponent> result = new ArrayList<>();
for (Component child : rootNode.getComponentList()) {
for (Component child : rootNode().getComponentList()) {
if (child.isTypeComponent()) {
result.add(child.asTypeComponent());
}
......@@ -16,12 +16,11 @@ aspect AttributesForMustache {
syn boolean RagConnect.hasRootTypeComponents() = !rootTypeComponents().isEmpty();
syn String RagConnect.closeMethodName() = "ragconnectCloseConnections";
syn String RagConnect.mqttHandlerAttribute() = "_mqttHandler";
syn String RagConnect.mqttHandlerField() = "_mqttHandler";
syn String RagConnect.mqttSetupWaitUntilReadyMethodName() = "ragconnectSetupMqttWaitUntilReady";
syn String RagConnect.restHandlerAttribute() = "_restHandler";
syn String RagConnect.restHandlerField() = "_restHandler";
syn String Handler.AttributeName() = "_" + getUniqueName() + "Handler";
syn String Handler.FieldName() = "_" + getUniqueName() + "Handler";
syn String Handler.SetupWaitUntilReadyMethodName() = "ragconnectSetup" + capitalize(getUniqueName()) + "WaitUntilReady";
syn String Handler.ConstructionSnippet() = "new " + getClassName() + "(\"Handler for " + ragconnect().rootNodeName() + ".\" + this.hashCode())";
syn boolean RagConnect.hasTreeListEndpoints() {
for (EndpointDefinition endpointDef : allEndpointDefinitionList()) {
......@@ -249,7 +248,7 @@ aspect AttributesForMustache {
aspect AspectGeneration {
// --- rootNodeName ---
syn String ASTNode.rootNodeName() = rootNode.getName();
syn String RagConnect.rootNodeName() = getConfiguration().getRootNode().getName();
}
aspect GrammarGeneration {
......@@ -273,13 +272,13 @@ aspect GrammarGeneration {
return result;
}
// coll java.util.Map<TypeDecl, TokenComponent> RagConnect.additionalTokens() [new java.util.HashMap<>()] with put root RagConnect;
// coll java.util.Map<TypeDecl, TokenComponent> RagConnect.additionalTokens() [new java.util.HashMap<>()] with put root RagConnect;
// TypeEndpointDefinition contributes getTokenToCreate()
// when typeIsList() && !getUseList()
// to RagConnect.additionalTokens()
//// for ragconnect()
// ;
// TypeEndpointDefinition contributes getTokenToCreate()
// when typeIsList() && !getUseList()
// to RagConnect.additionalTokens()
//// for ragconnect()
// ;
syn java.util.Map<TypeDecl, TokenComponent> RagConnect.additionalTokens() {
java.util.Map<TypeDecl, TokenComponent> result = new java.util.HashMap<>();
......
......@@ -47,50 +47,50 @@ aspect DefaultMappings {
syn nta DefaultMappingDefinition RagConnect.defaultBytesToTreeMapping(String typeName) {
return treeDefaultMappingDefinition("byte[]", 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" +
typeName + " result = " + typeName + ".deserialize((com.fasterxml.jackson.databind.JsonNode)mapper.readTree(parser));\n" +
"parser.close();\n" +
"return result;"
"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" +
typeName + " result = " + typeName + ".deserialize((com.fasterxml.jackson.databind.JsonNode)mapper.readTree(parser));\n" +
"parser.close();\n" +
"return result;"
);
}
syn nta DefaultMappingDefinition RagConnect.defaultTreeToBytesMapping(String typeName) {
return treeDefaultMappingDefinition(typeName, "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"+
"input.serialize(generator);\n" +
"generator.flush();\n" +
"return outputStream.toString().getBytes();"
"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" +
"input.serialize(generator);\n" +
"generator.flush();\n" +
"return outputStream.toString().getBytes();"
);
}
syn nta DefaultMappingDefinition RagConnect.defaultBytesToListTreeMapping(String typeName) {
return treeDefaultMappingDefinition("byte[]", JastAddList + "<" + 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" +
"parser.close();\n" +
"return result;"
return treeDefaultMappingDefinition("byte[]", JastAddList() + "<" + 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" +
"parser.close();\n" +
"return result;"
);
}
syn nta DefaultMappingDefinition RagConnect.defaultListTreeToBytesMapping() {
return treeDefaultMappingDefinition(JastAddList, "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"+
"input.serialize(generator);\n" +
"generator.flush();\n" +
"return outputStream.toString().getBytes();"
return treeDefaultMappingDefinition(JastAddList(), "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" +
"input.serialize(generator);\n" +
"generator.flush();\n" +
"return outputStream.toString().getBytes();"
);
}
syn nta DefaultMappingDefinition RagConnect.defaultBooleanToBytesMapping() = baseDefaultMappingDefinition(
"boolean", "byte[]", "return java.nio.ByteBuffer.allocate(1).put((byte) (input ? 1 : 0)).array();");
"boolean", "byte[]", "return java.nio.ByteBuffer.allocate(1).put((byte) (input ? 1 : 0)).array();");
syn nta DefaultMappingDefinition RagConnect.defaultIntToBytesMapping() = baseDefaultMappingDefinition(
"int", "byte[]", "return java.nio.ByteBuffer.allocate(Integer.BYTES).putInt(input).array();");
syn nta DefaultMappingDefinition RagConnect.defaultShortToBytesMapping() = baseDefaultMappingDefinition(
......@@ -168,7 +168,7 @@ aspect Mappings {
syn boolean TokenComponent.isPrimitiveType() = effectiveJavaTypeUse().isPrimitiveType();
syn boolean JavaTypeUse.isPrimitiveType() = false;
eq SimpleJavaTypeUse.isPrimitiveType() {
switch(getName()) {
switch (getName()) {
case "boolean":
case "int":
case "short":
......@@ -176,8 +176,10 @@ aspect Mappings {
case "float":
case "double":
case "char":
case "byte": return true;
default: return false;
case "byte":
return true;
default:
return false;
}
}
syn boolean MappingDefinitionType.isPrimitiveType() = false;
......@@ -193,30 +195,40 @@ aspect Mappings {
try {
TypeDecl typeDecl = program().resolveTypeDecl(targetTypeName());
return typeIsList() && !getIndexBasedListAccess() ? ragconnect().defaultBytesToListTreeMapping(typeDecl.getName()) : ragconnect().defaultBytesToTreeMapping(typeDecl.getName());
} catch (Exception ignore) {}
} catch (Exception ignore) {
}
}
switch (targetTypeName()) {
case "boolean":
case "Boolean": return ragconnect().defaultBytesToBooleanMapping();
case "Boolean":
return ragconnect().defaultBytesToBooleanMapping();
case "int":
case "Integer": return ragconnect().defaultBytesToIntMapping();
case "Integer":
return ragconnect().defaultBytesToIntMapping();
case "short":
case "Short": return ragconnect().defaultBytesToShortMapping();
case "Short":
return ragconnect().defaultBytesToShortMapping();
case "long":