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

converting to new grammar, fixing errors

parent a82df0f9
Pipeline #11987 failed with stages
in 1 minute and 16 seconds
aspect Analysis {
// --- lookupTokenEndpointDefinition ---
inh java.util.List<TokenEndpointDefinition> TokenEndpointDefinition.lookupTokenEndpointDefinitions(TokenComponent token);
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<TokenEndpointDefinition> RagConnect.lookupTokenEndpointDefinitions(TokenComponent token) {
java.util.List<TokenEndpointDefinition> result = new java.util.ArrayList<>();
for (EndpointDefinition def : allEndpointDefinitionList()) {
if (def.isTokenEndpointDefinition() && def.asTokenEndpointDefinition().getToken().equals(token)) {
result.add(def.asTokenEndpointDefinition());
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<TypeEndpointDefinition> TypeEndpointDefinition.lookupTypeEndpointDefinitions(TypeComponent type);
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<TypeEndpointDefinition> RagConnect.lookupTypeEndpointDefinitions(TypeComponent type) {
java.util.List<TypeEndpointDefinition> result = new java.util.ArrayList<>();
for (EndpointDefinition def : allEndpointDefinitionList()) {
if (def.isTypeEndpointDefinition() && def.asTypeEndpointDefinition().getType().equals(type)) {
result.add(def.asTypeEndpointDefinition());
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;
......@@ -37,17 +39,22 @@ aspect Analysis {
}
// --- isAlreadyDefined ---
syn boolean TokenEndpointDefinition.isAlreadyDefined() {
syn boolean EndpointDefinition.isAlreadyDefined() = getEndpointTarget().isAlreadyDefined();
syn boolean EndpointTarget.isAlreadyDefined();
eq TokenEndpointTarget.isAlreadyDefined() {
return lookupTokenEndpointDefinitions(getToken()).stream()
.filter(this::matchesType)
.filter(containingEndpointDefinition()::matchesType)
.count() > 1;
}
eq TypeEndpointTarget.isAlreadyDefined() {
return lookupTypeEndpointDefinitions(getType()).stream()
.filter(containingEndpointDefinition()::matchesType)
.count() > 1;
}
syn boolean DependencyDefinition.isAlreadyDefined() = lookupDependencyDefinition(getSource().containingTypeDecl(), getID()) != this;
// --- matchesType ---
syn boolean TokenEndpointDefinition.matchesType(TokenEndpointDefinition other);
eq ReceiveTokenEndpointDefinition.matchesType(TokenEndpointDefinition other) = other.isReceiveTokenEndpointDefinition();
eq SendTokenEndpointDefinition.matchesType(TokenEndpointDefinition other) = other.isSendTokenEndpointDefinition();
syn boolean EndpointDefinition.matchesType(EndpointDefinition other) = this.getSend() == other.getSend();
// --- assignableTo ---
syn boolean MappingDefinitionType.assignableTo(JavaTypeUse target);
......@@ -81,11 +88,14 @@ aspect Analysis {
}
// --- shouldSendValue ---
syn boolean TokenEndpointDefinition.shouldSendValue() = isSendTokenEndpointDefinition() && !getToken().getNTA();
syn boolean TypeEndpointDefinition.shouldSendValue() = isSendTypeEndpointDefinition() && !getType().getNTA();
syn boolean EndpointDefinition.shouldSendValue() = getSend() && getEndpointTarget().entityIsNormalAttribute();
syn boolean EndpointTarget.entityIsNormalAttribute();
eq TokenEndpointTarget.entityIsNormalAttribute() = !getToken().getNTA();
eq TypeEndpointTarget.entityIsNormalAttribute() = !getType().getNTA();
// --- needProxyToken ---
syn boolean TokenComponent.needProxyToken() = !getDependencySourceDefinitionList().isEmpty() || getTokenEndpointDefinitionList().stream().anyMatch(TokenEndpointDefinition::shouldSendValue);
syn boolean TokenComponent.needProxyToken() = !getDependencySourceDefinitionList().isEmpty() || getTokenEndpointTargetList().stream().map(EndpointTarget::containingEndpointDefinition).anyMatch(EndpointDefinition::shouldSendValue);
// --- effectiveUsedAt ---
coll Set<EndpointDefinition> MappingDefinition.effectiveUsedAt()
......@@ -96,8 +106,9 @@ aspect Analysis {
for each effectiveMappings();
// --- typeIsList ---
syn boolean EndpointDefinition.typeIsList() = false;
eq TypeEndpointDefinition.typeIsList() {
syn boolean EndpointDefinition.typeIsList() = getEndpointTarget().typeIsList();
syn boolean EndpointTarget.typeIsList() = false;
eq TypeEndpointTarget.typeIsList() {
return getType().isListComponent();
}
......
......@@ -3,29 +3,27 @@ aspect Errors {
[new TreeSet<ErrorMessage>()]
root RagConnect;
ReceiveTokenEndpointDefinition contributes error("Receive definition already defined for " + getToken().getName())
EndpointDefinition contributes error("Endpoint definition already defined for " + parentTypeName() + "." + entityName())
when isAlreadyDefined()
to RagConnect.errors();
ReceiveTokenEndpointDefinition contributes error("Receiving target token must not be an NTA token!")
when getToken().getNTA()
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
ReceiveTokenEndpointDefinition contributes error("No suitable default mapping found for type " +
EndpointDefinition contributes error("No suitable default mapping found for type " +
((getMappingList().isEmpty())
? getToken().effectiveJavaTypeUse().prettyPrint()
? token().effectiveJavaTypeUse().prettyPrint()
: getMappingList().get(0).getFromType().prettyPrint()))
when effectiveMappings().get(0) == null
when !getSend() && getEndpointTarget().isTokenEndpointTarget() && effectiveMappings().get(0) == null
to RagConnect.errors();
ReceiveTokenEndpointDefinition contributes error("to-type of last mapping (" + effectiveMappings().get(effectiveMappings().size() - 1).getToType().prettyPrint() + ") not assignable to type of the Token (" + getToken().effectiveJavaTypeUse().prettyPrint() + ")!")
when !effectiveMappings().get(effectiveMappings().size() - 1).getToType().assignableTo(
getToken().effectiveJavaTypeUse())
to RagConnect.errors();
SendTokenEndpointDefinition contributes error("Send definition already defined for " + getToken().getName())
when isAlreadyDefined()
// 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())
......@@ -46,7 +44,6 @@ aspect ErrorHelpers {
}
return false;
}
syn String TokenComponent.parentTypeDeclAndName() = containingTypeDecl().getName() + "." + getName();
}
aspect ErrorMessage {
......
......@@ -43,24 +43,24 @@ aspect RagConnectNavigation {
// --- program ---
eq RagConnect.getChild().program() = getProgram();
eq MRagConnect.getChild().program() = getRagConnect().program();
// --- ragconnect ---
inh RagConnect ASTNode.ragconnect();
eq RagConnect.getChild().ragconnect() = this;
eq MRagConnect.getChild().ragconnect() = getRagConnect();
// --- containedConnectSpecification ---
inh ConnectSpecification ASTNode.containedConnectSpecification();
eq RagConnect.getChild().containedConnectSpecification() = null;
eq MRagConnect.getChild().containedConnectSpecification() = null;
eq Document.getChild().containedConnectSpecification() = null;
eq Program.getChild().containedConnectSpecification() = null;
eq ConnectSpecification.getChild().containedConnectSpecification() = this;
// --- containingEndpointDefinition ---
inh EndpointDefinition EndpointTarget.containingEndpointDefinition();
eq EndpointDefinition.getEndpointTarget().containingEndpointDefinition() = this;
// --- containedFile
eq RagConnect.getChild().containedFile() = null;
eq MRagConnect.getChild().containedFile() = null;
// --- containedFileName ---
eq ConnectSpecificationFile.containedFileName() = getFileName();
......@@ -75,16 +75,25 @@ aspect RagConnectNavigation {
//--- allEndpointDefinitionList ---
syn List<EndpointDefinition> RagConnect.allEndpointDefinitionList() {
List<EndpointDefinition> result = new ArrayList<>();
for (var spec : getConnectSpecificationFileList()) {
for (ConnectSpecification spec : getConnectSpecificationFileList()) {
spec.getEndpointDefinitionList().forEach(result::add);
}
return result;
}
//--- allEndpointTargetList ---
syn List<EndpointTarget> RagConnect.allEndpointTargetList() {
List<EndpointTarget> result = new ArrayList<>();
for (ConnectSpecification spec : getConnectSpecificationFileList()) {
spec.getEndpointDefinitionList().forEach(endpointDef -> result.add(endpointDef.getEndpointTarget()));
}
return result;
}
//--- allDependencyDefinitionList ---
syn List<DependencyDefinition> RagConnect.allDependencyDefinitionList() {
List<DependencyDefinition> result = new ArrayList<>();
for (var spec : getConnectSpecificationFileList()) {
for (ConnectSpecification spec : getConnectSpecificationFileList()) {
spec.getDependencyDefinitionList().forEach(result::add);
}
return result;
......@@ -93,70 +102,24 @@ aspect RagConnectNavigation {
//--- allMappingDefinitionList ---
syn List<MappingDefinition> RagConnect.allMappingDefinitionList() {
List<MappingDefinition> result = new ArrayList<>();
for (var spec : getConnectSpecificationFileList()) {
for (ConnectSpecification spec : getConnectSpecificationFileList()) {
spec.getMappingDefinitionList().forEach(result::add);
}
return result;
}
// --- isTokenEndpointDefinition ---
syn boolean EndpointDefinition.isTokenEndpointDefinition() = false;
eq TokenEndpointDefinition.isTokenEndpointDefinition() = true;
// --- asTokenEndpointDefinition ---
syn TokenEndpointDefinition EndpointDefinition.asTokenEndpointDefinition() = null;
eq TokenEndpointDefinition.asTokenEndpointDefinition() = this;
// --- isTypeEndpointDefinition ---
syn boolean EndpointDefinition.isTypeEndpointDefinition() = false;
eq TypeEndpointDefinition.isTypeEndpointDefinition() = true;
// --- asTypeEndpointDefinition ---
syn TypeEndpointDefinition EndpointDefinition.asTypeEndpointDefinition() = null;
eq TypeEndpointDefinition.asTypeEndpointDefinition() = this;
// --- isReceiveTokenEndpointDefinition ---
syn boolean EndpointDefinition.isReceiveTokenEndpointDefinition() = false;
eq ReceiveTokenEndpointDefinition.isReceiveTokenEndpointDefinition() = true;
// --- asReceiveTokenEndpointDefinition ---
syn ReceiveTokenEndpointDefinition EndpointDefinition.asReceiveTokenEndpointDefinition() = null;
eq ReceiveTokenEndpointDefinition.asReceiveTokenEndpointDefinition() = this;
// --- isSendTokenEndpointDefinition ---
syn boolean EndpointDefinition.isSendTokenEndpointDefinition() = false;
eq SendTokenEndpointDefinition.isSendTokenEndpointDefinition() = true;
// --- asSendTokenEndpointDefinition ---
syn SendTokenEndpointDefinition EndpointDefinition.asSendTokenEndpointDefinition() = null;
eq SendTokenEndpointDefinition.asSendTokenEndpointDefinition() = this;
// --- isReceiveTypeEndpointDefinition ---
syn boolean EndpointDefinition.isReceiveTypeEndpointDefinition() = false;
eq ReceiveTypeEndpointDefinition.isReceiveTypeEndpointDefinition() = true;
// --- asReceiveTypeEndpointDefinition ---
syn ReceiveTypeEndpointDefinition EndpointDefinition.asReceiveTypeEndpointDefinition() = null;
eq ReceiveTypeEndpointDefinition.asReceiveTypeEndpointDefinition() = this;
// --- isSendTypeEndpointDefinition ---
syn boolean EndpointDefinition.isSendTypeEndpointDefinition() = false;
eq SendTypeEndpointDefinition.isSendTypeEndpointDefinition() = true;
// --- asSendTypeEndpointDefinition ---
syn SendTypeEndpointDefinition EndpointDefinition.asSendTypeEndpointDefinition() = null;
eq SendTypeEndpointDefinition.asSendTypeEndpointDefinition() = this;
// --- 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.isSendTokenEndpointDefinition() &&
endpointDefinition.asSendTokenEndpointDefinition().getToken().equals(this.getTarget())) {
if (!endpointDefinition.getSend()) { continue; }
EndpointTarget endpointTarget = endpointDefinition.getEndpointTarget();
if (endpointTarget.isTokenEndpointTarget() &&
endpointTarget.asTokenEndpointTarget().getToken().equals(this.getTarget())) {
return endpointDefinition;
}
if (endpointDefinition.isSendTypeEndpointDefinition() &&
endpointDefinition.asSendTypeEndpointDefinition().getType().equals(this.getTarget())) {
if (endpointTarget.isTypeEndpointTarget() &&
endpointTarget.asTypeEndpointTarget().getType().equals(this.getTarget())) {
return endpointDefinition;
}
}
......@@ -170,13 +133,6 @@ aspect RagConnectNavigation {
syn boolean MappingDefinition.isDefaultMappingDefinition() = false;
eq DefaultMappingDefinition.isDefaultMappingDefinition() = true;
// --- mragconnect ---
inh MRagConnect MHandler.mragconnect();
eq MRagConnect.getHandler().mragconnect() = this;
// --- rootTypeComponents ---
syn JastAddList<MTypeComponent> MHandler.rootTypeComponents() = mragconnect().getRootTypeComponents();
// --- isListComponent --- (defined in PP, but only on TypeComponent)
syn boolean Component.isListComponent() = false;
}
RagConnect ::= ConnectSpecificationFile* Program ;
RagConnect ::= ConnectSpecificationFile* Handler* Program ;
abstract ConnectSpecification ::= EndpointDefinition* DependencyDefinition* MappingDefinition* ;
ConnectSpecificationFile : ConnectSpecification ::= <FileName> ;
abstract EndpointDefinition ::= <AlwaysApply:boolean> ;
EndpointDefinition ::= <AlwaysApply:boolean> <IndexBasedListAccess:boolean> <WithAdd:boolean> <Send:boolean> EndpointTarget ;
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;
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 ;
//rel RelationEndpointTarget.Role <-> Role.RelationEndpointTarget* ;
DependencyDefinition ::= <ID>;
rel DependencyDefinition.Source <-> TokenComponent.DependencySourceDefinition*;
......@@ -29,7 +27,4 @@ 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;
Handler ::= <ClassName> <Construction> <AttributeName> <FieldName> <InUse:boolean>;
......@@ -3,19 +3,21 @@ RagConnect ::= ConnectSpecificationFile* Program ;
abstract ConnectSpecification ::= EndpointDefinition* DependencyDefinition* MappingDefinition* ;
ConnectSpecificationFile : ConnectSpecification ::= <FileName> ;
EndpointDefinition ::= <AlwaysApply:boolean> <IndexBasedListAccess:boolean> <WithAdd:boolean> <Send:boolean> EndpointTarget ;
abstract EndpointDefinition ::= <AlwaysApply:boolean> ;
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
// to be integrated:
//AttributeEndpointTarget : EndpointTarget ::= <Name> ;
//RelationEndpointTarget : EndpointTarget ;
//rel RelationEndpointTarget.Role <-> Role.RelationEndpointTarget* ;
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*;
......@@ -26,3 +28,8 @@ 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;
......@@ -141,7 +141,7 @@ aspect Mappings {
// --- effectiveMappings ---
syn java.util.List<MappingDefinition> EndpointDefinition.effectiveMappings() {
java.util.List<MappingDefinition> result;
if (isReceiveTokenEndpointDefinition() || isReceiveTypeEndpointDefinition()) {
if (!getSend()) {
// if no mappings are specified, or if first mapping is not suitable.
// then prepend the suitable default mapping
if (getMappingList().isEmpty() || !getMappingList().get(0).getFromType().isByteArray()) {
......@@ -151,7 +151,7 @@ aspect Mappings {
} else {
result = getMappingList();
}
} else if (isSendTokenEndpointDefinition() || isSendTypeEndpointDefinition()) {
} else {
// if no mappings are specified, or if last mapping is not suitable
// then append the suitable default mapping
if (getMappingList().isEmpty() || !getMappingList().get(getMappingList().size() - 1).getToType().isByteArray()) {
......@@ -160,8 +160,6 @@ aspect Mappings {
} else {
result = getMappingList();
}
} else {
throw new RuntimeException("Unknown endpoint definition: " + this);
}
return result;
}
......@@ -191,6 +189,12 @@ aspect Mappings {
// --- suitableReceiveDefaultMapping ---
syn DefaultMappingDefinition EndpointDefinition.suitableReceiveDefaultMapping() {
if (getEndpointTarget().isTypeEndpointTarget()) {
try {
TypeDecl typeDecl = program().resolveTypeDecl(targetTypeName());
return typeIsList() && !getIndexBasedListAccess() ? ragconnect().defaultBytesToListTreeMapping(typeDecl.getName()) : ragconnect().defaultBytesToTreeMapping(typeDecl.getName());
} catch (Exception ignore) {}
}
switch (targetTypeName()) {
case "boolean":
case "Boolean": return ragconnect().defaultBytesToBooleanMapping();
......@@ -217,16 +221,15 @@ aspect Mappings {
return null;
}
}
eq TypeEndpointDefinition.suitableReceiveDefaultMapping() {
try {
TypeDecl typeDecl = program().resolveTypeDecl(targetTypeName());
return typeIsList() && !getIndexBasedListAccess() ? ragconnect().defaultBytesToListTreeMapping(typeDecl.getName()) : ragconnect().defaultBytesToTreeMapping(typeDecl.getName());
} catch (Exception ignore) {}
return super.suitableReceiveDefaultMapping();
}
// --- suitableSendDefaultMapping ---
syn DefaultMappingDefinition EndpointDefinition.suitableSendDefaultMapping() {
if (getEndpointTarget().isTypeEndpointTarget()) {
try {
TypeDecl typeDecl = program().resolveTypeDecl(targetTypeName());
return typeIsList() && !getIndexBasedListAccess() ? ragconnect().defaultListTreeToBytesMapping() : ragconnect().defaultTreeToBytesMapping(typeDecl.getName());
} catch (Exception ignore) {}
}
switch (targetTypeName()) {
case "boolean":
case "Boolean": return ragconnect().defaultBooleanToBytesMapping();
......@@ -253,36 +256,22 @@ aspect Mappings {
return null;
}
}
eq TypeEndpointDefinition.suitableSendDefaultMapping() {
try {
TypeDecl typeDecl = program().resolveTypeDecl(targetTypeName());
return typeIsList() && !getIndexBasedListAccess() ? ragconnect().defaultListTreeToBytesMapping() : ragconnect().defaultTreeToBytesMapping(typeDecl.getName());
} catch (Exception ignore) {}
return super.suitableSendDefaultMapping();
}
// --- targetTypeName ---
syn String EndpointDefinition.targetTypeName();
eq ReceiveTokenEndpointDefinition.targetTypeName() {
return getMappingList().isEmpty() ?
getToken().effectiveJavaTypeUse().getName() :
getMappingList().get(0).getFromType().prettyPrint();
}
eq ReceiveTypeEndpointDefinition.targetTypeName() {
return getMappingList().isEmpty() ?
getType().getTypeDecl().getName() :
getMappingList().get(0).getFromType().prettyPrint();
}
eq SendTokenEndpointDefinition.targetTypeName() {
return getMappingList().isEmpty() ?
getToken().effectiveJavaTypeUse().getName() :
getMappingList().get(getMappingList().size() - 1).getToType().prettyPrint();
}
eq SendTypeEndpointDefinition.targetTypeName() {
return getMappingList().isEmpty() ?
getType().getTypeDecl().getName() :
getMappingList().get(getMappingList().size() - 1).getToType().prettyPrint();
syn String EndpointDefinition.targetTypeName() {
if (getMappingList().isEmpty()) {
return getEndpointTarget().targetTypeName();
} else {
if (getSend()) {
return getMappingList().get(0).getFromType().prettyPrint();
} else {
return getMappingList().get(getMappingList().size() - 1).getToType().prettyPrint();
}
}
}
syn String EndpointTarget.targetTypeName();
eq TokenEndpointTarget.targetTypeName() = getToken().effectiveJavaTypeUse().getName();
eq TypeEndpointTarget.targetTypeName() = getType().getTypeDecl().getName();
// eq ReceiveFromRestDefinition.suitableDefaultMapping() {
// String typeName = getMappingList().isEmpty() ?
......
MRagConnect ::= TokenReceiveDefinition:MTokenReceiveDefinition* TokenSendDefinition:MTokenSendDefinition* TypeReceiveDefinition:MTypeReceiveDefinition* TypeSendDefinition:MTypeSendDefinition* MappingDefinition:MMappingDefinition* DependencyDefinition:MDependencyDefinition* RootTypeComponent:MTypeComponent* TokenComponent:MTokenComponent* Handler:MHandler*;
//MRagConnect ::= TokenReceiveDefinition:MTokenReceiveDefinition* TokenSendDefinition:MTokenSendDefinition* TypeReceiveDefinition:MTypeReceiveDefinition* TypeSendDefinition:MTypeSendDefinition* ;
abstract MEndpointDefinition ::= InnerMappingDefinition:MInnerMappingDefinition*;
abstract MTokenEndpointDefinition : MEndpointDefinition;
......@@ -8,21 +8,17 @@ abstract MTypeEndpointDefinition : MEndpointDefinition;
MTypeReceiveDefinition : MTypeEndpointDefinition;
MTypeSendDefinition : MTypeEndpointDefinition;
MMappingDefinition;
//MMappingDefinition;
MInnerMappingDefinition;
MDependencyDefinition;
MTypeComponent;
MTokenComponent;
MHandler ::= <ClassName> <Construction> <AttributeName> <FieldName> <InUse:boolean>;
//MDependencyDefinition;
//MTypeComponent;
//MTokenComponent;
rel MRagConnect.RagConnect -> RagConnect;
rel MInnerMappingDefinition.MMappingDefinition -> MMappingDefinition;
rel MTokenReceiveDefinition.ReceiveTokenEndpointDefinition -> ReceiveTokenEndpointDefinition;
rel MTokenSendDefinition.SendTokenEndpointDefinition -> SendTokenEndpointDefinition;
rel MTypeReceiveDefinition.ReceiveTypeEndpointDefinition -> ReceiveTypeEndpointDefinition;
rel MTypeSendDefinition.SendTypeEndpointDefinition -> SendTypeEndpointDefinition;
rel MMappingDefinition.MappingDefinition -> MappingDefinition;
rel MDependencyDefinition.DependencyDefinition -> DependencyDefinition;
rel MTypeComponent.TypeComponent -> TypeComponent;
rel MTokenComponent.TokenComponent -> TokenComponent;
rel MTokenComponent.DependencyDefinition* -> MDependencyDefinition;
//rel MRagConnect.RagConnect -> RagConnect;
rel MInnerMappingDefinition.MappingDefinition -> MappingDefinition;
rel MEndpointDefinition.EndpointDefinition -> EndpointDefinition;
//rel MMappingDefinition.MappingDefinition -> MappingDefinition;
//rel MDependencyDefinition.DependencyDefinition -> DependencyDefinition;
//rel MTypeComponent.TypeComponent -> TypeComponent;
//rel MTokenComponent.TokenComponent -> TokenComponent;
//rel MTokenComponent.DependencyDefinition* -> MDependencyDefinition;
aspect MustacheNodesToYAML {
syn Document MRagConnect.toYAML() {
Document doc = new Document();
MappingElement root = new MappingElement();
root.put("rootNodeName", rootNodeName());
root.put("closeMethod", closeMethod());
root.put("usesMqtt", usesMqtt);
root.put("usesRest", usesRest);
// mqtt
root.put("mqttHandlerField", mqttHandlerField());
root.put("mqttHandlerAttribute", mqttHandlerAttribute());
root.put("mqttSetupWaitUntilReadyMethod", mqttSetupWaitUntilReadyMethod());
// rootTypeComponents
ListElement rootTypeComponents = new ListElement();
for (MTypeComponent comp : getRootTypeComponentList()) {
MappingElement inner = new MappingElement();
inner.put("first", comp.isFirst());
inner.put("name", comp.name());
rootTypeComponents.addElement(inner);
}
root.put("RootTypeComponents", rootTypeComponents);
// rest
root.put("restHandlerField", restHandlerField());
root.put("restHandlerAttribute", restHandlerAttribute());
// TokenReceiveDefinitions
ListElement receiveDefinitions = new ListElement();
for (MTokenReceiveDefinition def : getTokenReceiveDefinitionList()) {
receiveDefinitions.addElement(def.toYAML());
}
root.put("TokenReceiveDefinitions", receiveDefinitions);
// TokenSendDefinitions
ListElement sendDefinitions = new ListElement();
for (MTokenSendDefinition def : getTokenSendDefinitionList()) {
sendDefinitions.addElement(def.toYAML());
}
root.put("TokenSendDefinitions", sendDefinitions);
// TypeReceiveDefinitions
ListElement typeReceiveDefinitions = new ListElement();
for (MTypeReceiveDefinition def : getTypeReceiveDefinitionList()) {
typeReceiveDefinitions.addElement(def.toYAML());
}
root.put("TypeReceiveDefinitions", typeReceiveDefinitions);
// TypeSendDefinitions
ListElement typeSendDefinitions = new ListElement();
for (MTypeSendDefinition def : getTypeSendDefinitionList()) {
typeSendDefinitions.addElement(def.toYAML());
}
root.put("TypeSendDefinitions", typeSendDefinitions);
// MappingDefinitions
ListElement mappingDefinitions = new ListElement();
for (MMappingDefinition def : getMappingDefinitionList()) {
mappingDefinitions.addElement(def.toYAML());
}
root.put("MappingDefinitions", mappingDefinitions);
// DependencyDefinitions
ListElement dependencyDefinitions = new ListElement();
for (MDependencyDefinition def : getDependencyDefinitionList()) {
dependencyDefinitions.addElement(def.toYAML());
}
root.put("DependencyDefinitions", dependencyDefinitions);
// TokenComponents
ListElement tokenComponents = new ListElement();
for (MTokenComponent comp : getTokenComponentList()) {
tokenComponents.addElement(comp.toYAML());
}
root.put("TokenComponents", tokenComponents);
// Handlers
ListElement handlers = new ListElement();
for (MHandler handler : getHandlerList()) {
handlers.add(handler.toYAML()
.put("rootTokenComponents", rootTypeComponents.treeCopy()) );
}
root.put("Handlers", handlers);
doc.setRootElement(root);