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

Begin with typeEndpointDefinitions, add more tests, fix some bugs.

- mappings bug fixed: boxed types handled correctly now
- mappings bug fixed: type of last transformation correctly used now
- add junit report to ci
parent 70ccb958
Pipeline #8700 passed with stages
in 7 minutes and 6 seconds
...@@ -21,7 +21,7 @@ build: ...@@ -21,7 +21,7 @@ build:
- ./gradlew --console=plain --no-daemon assemble jar - ./gradlew --console=plain --no-daemon assemble jar
artifacts: artifacts:
paths: paths:
- "/builds/jastadd/ragconnect/ragconnect.base/build/libs/ragconnect-*.jar" - "ragconnect.base/build/libs/ragconnect-*.jar"
expire_in: 1 week expire_in: 1 week
test: test:
...@@ -34,7 +34,7 @@ test: ...@@ -34,7 +34,7 @@ test:
- ./gradlew --console=plain --no-daemon allTests - ./gradlew --console=plain --no-daemon allTests
artifacts: artifacts:
reports: reports:
junit: "/builds/jastadd/ragconnect/ragconnect.tests/build/test-results/test/TEST-*.xml" junit: "ragconnect.tests/build/test-results/test/**/TEST-*.xml"
expire_in: 1 week expire_in: 1 week
publish: publish:
......
...@@ -12,6 +12,19 @@ aspect Analysis { ...@@ -12,6 +12,19 @@ aspect Analysis {
return result; return result;
} }
// --- lookupTypeEndpointDefinition ---
inh java.util.List<TypeEndpointDefinition> TypeEndpointDefinition.lookupTypeEndpointDefinitions(TypeComponent type);
eq RagConnect.getEndpointDefinition().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 : getEndpointDefinitionList()) {
if (def.isTypeEndpointDefinition() && def.asTypeEndpointDefinition().getType().equals(type)) {
result.add(def.asTypeEndpointDefinition());
}
}
return result;
}
// --- lookupDependencyDefinition --- // --- lookupDependencyDefinition ---
inh DependencyDefinition DependencyDefinition.lookupDependencyDefinition(TypeDecl source, String id); inh DependencyDefinition DependencyDefinition.lookupDependencyDefinition(TypeDecl source, String id);
eq RagConnect.getDependencyDefinition().lookupDependencyDefinition(TypeDecl source, String id) { eq RagConnect.getDependencyDefinition().lookupDependencyDefinition(TypeDecl source, String id) {
...@@ -31,10 +44,12 @@ aspect Analysis { ...@@ -31,10 +44,12 @@ aspect Analysis {
} }
syn boolean DependencyDefinition.isAlreadyDefined() = lookupDependencyDefinition(getSource().containingTypeDecl(), getID()) != this; syn boolean DependencyDefinition.isAlreadyDefined() = lookupDependencyDefinition(getSource().containingTypeDecl(), getID()) != this;
// --- matchesType ---
syn boolean TokenEndpointDefinition.matchesType(TokenEndpointDefinition other); syn boolean TokenEndpointDefinition.matchesType(TokenEndpointDefinition other);
eq ReceiveTokenEndpointDefinition.matchesType(TokenEndpointDefinition other) = other.isReceiveTokenEndpointDefinition(); eq ReceiveTokenEndpointDefinition.matchesType(TokenEndpointDefinition other) = other.isReceiveTokenEndpointDefinition();
eq SendTokenEndpointDefinition.matchesType(TokenEndpointDefinition other) = other.isSendTokenEndpointDefinition(); eq SendTokenEndpointDefinition.matchesType(TokenEndpointDefinition other) = other.isSendTokenEndpointDefinition();
// --- assignableTo ---
syn boolean MappingDefinitionType.assignableTo(JavaTypeUse target); syn boolean MappingDefinitionType.assignableTo(JavaTypeUse target);
eq JavaMappingDefinitionType.assignableTo(JavaTypeUse target) = getType().assignableTo(target); eq JavaMappingDefinitionType.assignableTo(JavaTypeUse target) = getType().assignableTo(target);
eq JavaArrayMappingDefinitionType.assignableTo(JavaTypeUse target) { eq JavaArrayMappingDefinitionType.assignableTo(JavaTypeUse target) {
...@@ -65,6 +80,7 @@ aspect Analysis { ...@@ -65,6 +80,7 @@ aspect Analysis {
// --- shouldSendValue --- // --- shouldSendValue ---
syn boolean TokenEndpointDefinition.shouldSendValue() = isSendTokenEndpointDefinition() && !getToken().getNTA(); syn boolean TokenEndpointDefinition.shouldSendValue() = isSendTokenEndpointDefinition() && !getToken().getNTA();
syn boolean TypeEndpointDefinition.shouldSendValue() = isSendTypeEndpointDefinition() && !getType().getNTA();
// --- needProxyToken --- // --- needProxyToken ---
syn boolean TokenComponent.needProxyToken() = !getDependencySourceDefinitionList().isEmpty() || getTokenEndpointDefinitionList().stream().anyMatch(TokenEndpointDefinition::shouldSendValue); syn boolean TokenComponent.needProxyToken() = !getDependencySourceDefinitionList().isEmpty() || getTokenEndpointDefinitionList().stream().anyMatch(TokenEndpointDefinition::shouldSendValue);
......
...@@ -32,6 +32,10 @@ aspect Errors { ...@@ -32,6 +32,10 @@ aspect Errors {
when isAlreadyDefined() when isAlreadyDefined()
to RagConnect.errors(); to RagConnect.errors();
SendTypeEndpointDefinition contributes error("At least one mapping needs to be used")
when effectiveMappings().isEmpty()
to RagConnect.errors();
DependencyDefinition contributes error("Dependency definition already defined for " + getSource().containingTypeDecl().getName() + " with name " + getID()) DependencyDefinition contributes error("Dependency definition already defined for " + getSource().containingTypeDecl().getName() + " with name " + getID())
when isAlreadyDefined() when isAlreadyDefined()
to RagConnect.errors(); to RagConnect.errors();
......
...@@ -11,4 +11,20 @@ aspect NameResolution { ...@@ -11,4 +11,20 @@ aspect NameResolution {
return null; return null;
} }
refine RefResolverStubs eq ASTNode.globallyResolveTypeComponentByToken(String id) {
// return a TypeComponent. id is of the form 'parent_type_name + "." + child_type_name'
int dotIndex = id.indexOf(".");
String parentTypeName = id.substring(0, dotIndex);
String childTypeName = id.substring(dotIndex + 1);
TypeDecl type = program().resolveTypeDecl(parentTypeName);
// iterate over components and find the matching typeComponent
for (Component comp : type.getComponentList()) {
if (comp.isTypeComponent() && comp.getName().equals(childTypeName)) {
return comp.asTypeComponent();
}
}
System.err.println("Could not resolve TypeComponent '" + id + "'.");
return null;
}
} }
...@@ -27,13 +27,13 @@ aspect Navigation { ...@@ -27,13 +27,13 @@ aspect Navigation {
syn TokenEndpointDefinition EndpointDefinition.asTokenEndpointDefinition() = null; syn TokenEndpointDefinition EndpointDefinition.asTokenEndpointDefinition() = null;
eq TokenEndpointDefinition.asTokenEndpointDefinition() = this; eq TokenEndpointDefinition.asTokenEndpointDefinition() = this;
// --- isSendTokenEndpointDefinition --- // --- isTypeEndpointDefinition ---
syn boolean EndpointDefinition.isSendTokenEndpointDefinition() = false; syn boolean EndpointDefinition.isTypeEndpointDefinition() = false;
eq SendTokenEndpointDefinition.isSendTokenEndpointDefinition() = true; eq TypeEndpointDefinition.isTypeEndpointDefinition() = true;
// --- asSendTokenEndpointDefinition --- // --- asTypeEndpointDefinition ---
syn SendTokenEndpointDefinition EndpointDefinition.asSendTokenEndpointDefinition() = null; syn TypeEndpointDefinition EndpointDefinition.asTypeEndpointDefinition() = null;
eq SendTokenEndpointDefinition.asSendTokenEndpointDefinition() = this; eq TypeEndpointDefinition.asTypeEndpointDefinition() = this;
// --- isReceiveTokenEndpointDefinition --- // --- isReceiveTokenEndpointDefinition ---
syn boolean EndpointDefinition.isReceiveTokenEndpointDefinition() = false; syn boolean EndpointDefinition.isReceiveTokenEndpointDefinition() = false;
...@@ -43,6 +43,30 @@ aspect Navigation { ...@@ -43,6 +43,30 @@ aspect Navigation {
syn ReceiveTokenEndpointDefinition EndpointDefinition.asReceiveTokenEndpointDefinition() = null; syn ReceiveTokenEndpointDefinition EndpointDefinition.asReceiveTokenEndpointDefinition() = null;
eq ReceiveTokenEndpointDefinition.asReceiveTokenEndpointDefinition() = this; 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 --- // --- targetEndpointDefinition ---
syn SendTokenEndpointDefinition DependencyDefinition.targetEndpointDefinition() { syn SendTokenEndpointDefinition DependencyDefinition.targetEndpointDefinition() {
// resolve definition in here, as we do not need resolveMethod in any other place (yet) // resolve definition in here, as we do not need resolveMethod in any other place (yet)
......
...@@ -10,6 +10,12 @@ rel TokenEndpointDefinition.Token <-> TokenComponent.TokenEndpointDefinition*; ...@@ -10,6 +10,12 @@ rel TokenEndpointDefinition.Token <-> TokenComponent.TokenEndpointDefinition*;
ReceiveTokenEndpointDefinition : TokenEndpointDefinition; ReceiveTokenEndpointDefinition : TokenEndpointDefinition;
SendTokenEndpointDefinition : TokenEndpointDefinition; SendTokenEndpointDefinition : TokenEndpointDefinition;
abstract TypeEndpointDefinition : EndpointDefinition;
rel TypeEndpointDefinition.Type <-> TypeComponent.TypeEndpointDefinition*;
ReceiveTypeEndpointDefinition : TypeEndpointDefinition;
SendTypeEndpointDefinition : TypeEndpointDefinition;
DependencyDefinition ::= <ID>; DependencyDefinition ::= <ID>;
rel DependencyDefinition.Source <-> TokenComponent.DependencySourceDefinition*; rel DependencyDefinition.Source <-> TokenComponent.DependencySourceDefinition*;
rel DependencyDefinition.Target -> TokenComponent; rel DependencyDefinition.Target -> TokenComponent;
......
...@@ -18,29 +18,42 @@ aspect AttributesForMustache { ...@@ -18,29 +18,42 @@ aspect AttributesForMustache {
// --- MEndpointDefinition --- // --- MEndpointDefinition ---
syn String MEndpointDefinition.preemptiveExpectedValue(); syn String MEndpointDefinition.preemptiveExpectedValue();
syn String MEndpointDefinition.preemptiveReturn(); syn String MEndpointDefinition.preemptiveReturn();
syn TokenEndpointDefinition MEndpointDefinition.endpointDef(); syn EndpointDefinition MEndpointDefinition.endpointDef();
syn String MEndpointDefinition.firstInputVarName(); syn String MEndpointDefinition.firstInputVarName();
syn String MEndpointDefinition.parentTypeName();
syn String MEndpointDefinition.entityName();
eq MEndpointDefinition.getInnerMappingDefinition(int i).isLast() = i == getNumInnerMappingDefinition() - 1; eq MEndpointDefinition.getInnerMappingDefinition(int i).isLast() = i == getNumInnerMappingDefinition() - 1;
eq MEndpointDefinition.getInnerMappingDefinition(int i).inputVarName() = i == 0 ? firstInputVarName() : getInnerMappingDefinition(i - 1).outputVarName(); eq MEndpointDefinition.getInnerMappingDefinition(int i).inputVarName() = i == 0 ? firstInputVarName() : getInnerMappingDefinition(i - 1).outputVarName();
syn String MEndpointDefinition.connectParameterName() = "uriString"; syn String MEndpointDefinition.connectParameterName() = "uriString";
syn String MEndpointDefinition.connectMethod() = "connect" + tokenName(); syn String MEndpointDefinition.connectMethod() = "connect" + entityName();
syn String MEndpointDefinition.disconnectMethod() { syn String MEndpointDefinition.disconnectMethod() {
// if both (send and receive) are defined for the token, ensure methods with different names // if both (send and receive) are defined for the token, ensure methods with different names
String extra = endpointDef().lookupTokenEndpointDefinitions(token()).size() > 1 ? uniqueSuffix() : ""; String extra;
return "disconnect" + extra + tokenName(); if (endpointDef().isTokenEndpointDefinition()) {
extra = endpointDef().asTokenEndpointDefinition().lookupTokenEndpointDefinitions(token()).size() > 1 ? uniqueSuffix() : "";
} else if (endpointDef().isTypeEndpointDefinition()) {
extra = endpointDef().asTypeEndpointDefinition().lookupTypeEndpointDefinitions(type()).size() > 1 ? uniqueSuffix() : "";
} else {
extra = "";
}
return "disconnect" + extra + entityName();
} }
//
syn String MEndpointDefinition.uniqueSuffix(); syn String MEndpointDefinition.uniqueSuffix();
eq MSendDefinition.uniqueSuffix() = "Send"; eq MTokenSendDefinition.uniqueSuffix() = "Send";
eq MReceiveDefinition.uniqueSuffix() = "Receive"; eq MTokenReceiveDefinition.uniqueSuffix() = "Receive";
eq MTypeSendDefinition.uniqueSuffix() = "Send";
eq MTypeReceiveDefinition.uniqueSuffix() = "Receive";
syn TokenComponent MEndpointDefinition.token() = endpointDef().getToken(); // TODO potentially dangerous because asXEndpointDefinition can return null
syn TokenComponent MEndpointDefinition.token() = endpointDef().asTokenEndpointDefinition().getToken();
syn TypeComponent MEndpointDefinition.type() = endpointDef().asTypeEndpointDefinition().getType();
syn boolean MEndpointDefinition.alwaysApply() = endpointDef().getAlwaysApply(); syn boolean MEndpointDefinition.alwaysApply() = endpointDef().getAlwaysApply();
syn String MEndpointDefinition.parentTypeName() = token().containingTypeDecl().getName();
syn String MEndpointDefinition.tokenName() = token().getName(); syn String MEndpointDefinition.tokenName() = token().getName();
syn String MEndpointDefinition.typeName() = type().getName();
syn MInnerMappingDefinition MEndpointDefinition.lastDefinition() = getInnerMappingDefinition(getNumInnerMappingDefinition() - 1); syn MInnerMappingDefinition MEndpointDefinition.lastDefinition() = getInnerMappingDefinition(getNumInnerMappingDefinition() - 1);
syn String MEndpointDefinition.lastDefinitionToType() = lastDefinition().toType(); syn String MEndpointDefinition.lastDefinitionToType() = lastDefinition().toType();
syn String MEndpointDefinition.lastResult() = lastDefinition().outputVarName(); syn String MEndpointDefinition.lastResult() = lastDefinition().outputVarName();
...@@ -51,12 +64,20 @@ aspect AttributesForMustache { ...@@ -51,12 +64,20 @@ aspect AttributesForMustache {
if (token().isPrimitiveType() && lastDefinition().mappingDef().getToType().isPrimitiveType()) { if (token().isPrimitiveType() && lastDefinition().mappingDef().getToType().isPrimitiveType()) {
return preemptiveExpectedValue() + " == " + lastResult(); return preemptiveExpectedValue() + " == " + lastResult();
} }
if (lastDefinition().mappingDef().isDefaultMappingDefinition()) { if (lastDefinition().mappingDef().getToType().isPrimitiveType() || lastDefinition().mappingDef().isDefaultMappingDefinition()) {
return preemptiveExpectedValue() + " != null && " + preemptiveExpectedValue() + ".equals(" + lastResult() + ")"; return preemptiveExpectedValue() + " != null && " + preemptiveExpectedValue() + ".equals(" + lastResult() + ")";
} }
return preemptiveExpectedValue() + " != null ? " + preemptiveExpectedValue() + ".equals(" + lastResult() + ") : " + lastResult() + " == null"; return preemptiveExpectedValue() + " != null ? " + preemptiveExpectedValue() + ".equals(" + lastResult() + ") : " + lastResult() + " == null";
} }
// --- MTokenEndpointDefinition ---
eq MTokenEndpointDefinition.parentTypeName() = token().containingTypeDecl().getName();
eq MTokenEndpointDefinition.entityName() = tokenName();
// --- MTypeEndpointDefinition ---
eq MTypeEndpointDefinition.parentTypeName() = type().containingTypeDecl().getName();
eq MTypeEndpointDefinition.entityName() = typeName();
// --- MInnerMappingDefinition --- // --- MInnerMappingDefinition ---
inh boolean MInnerMappingDefinition.isLast(); inh boolean MInnerMappingDefinition.isLast();
inh String MInnerMappingDefinition.inputVarName(); inh String MInnerMappingDefinition.inputVarName();
...@@ -65,24 +86,43 @@ aspect AttributesForMustache { ...@@ -65,24 +86,43 @@ aspect AttributesForMustache {
syn MappingDefinition MInnerMappingDefinition.mappingDef() = getMMappingDefinition().getMappingDefinition(); syn MappingDefinition MInnerMappingDefinition.mappingDef() = getMMappingDefinition().getMappingDefinition();
syn String MInnerMappingDefinition.outputVarName() = "result" + methodName(); // we do not need "_" in between here, because methodName begins with one syn String MInnerMappingDefinition.outputVarName() = "result" + methodName(); // we do not need "_" in between here, because methodName begins with one
// --- MReceiveDefinition --- // --- MTokenReceiveDefinition ---
eq MReceiveDefinition.preemptiveExpectedValue() = "get" + tokenName() + "()"; eq MTokenReceiveDefinition.preemptiveExpectedValue() = "get" + tokenName() + "()";
eq MReceiveDefinition.preemptiveReturn() = "return;"; eq MTokenReceiveDefinition.preemptiveReturn() = "return;";
eq MReceiveDefinition.endpointDef() = getReceiveTokenEndpointDefinition(); eq MTokenReceiveDefinition.endpointDef() = getReceiveTokenEndpointDefinition();
eq MReceiveDefinition.firstInputVarName() = "message"; eq MTokenReceiveDefinition.firstInputVarName() = "message";
// --- MSendDefinition --- // --- MTokenSendDefinition ---
eq MSendDefinition.preemptiveExpectedValue() = lastValue(); eq MTokenSendDefinition.preemptiveExpectedValue() = lastValue();
eq MSendDefinition.preemptiveReturn() = "return false;"; eq MTokenSendDefinition.preemptiveReturn() = "return false;";
eq MSendDefinition.endpointDef() = getSendTokenEndpointDefinition(); eq MTokenSendDefinition.endpointDef() = getSendTokenEndpointDefinition();
eq MSendDefinition.firstInputVarName() = "get" + tokenName() + "()"; eq MTokenSendDefinition.firstInputVarName() = "get" + tokenName() + "()";
syn String MSendDefinition.sender() = "_sender_" + tokenName(); syn String MTokenSendDefinition.sender() = "_sender_" + tokenName();
syn String MSendDefinition.lastValue() = "_lastValue" + tokenName(); syn String MTokenSendDefinition.lastValue() = "_lastValue" + tokenName();
syn String MSendDefinition.updateMethod() = "_update_" + tokenName(); syn String MTokenSendDefinition.updateMethod() = "_update_" + tokenName();
syn String MSendDefinition.writeMethod() = "_writeLastValue_" + tokenName(); syn String MTokenSendDefinition.writeMethod() = "_writeLastValue_" + tokenName();
syn String MSendDefinition.tokenResetMethod() = "get" + tokenName() + "_reset"; syn String MTokenSendDefinition.tokenResetMethod() = "get" + tokenName() + "_reset";
syn boolean MSendDefinition.shouldSendValue() = endpointDef().shouldSendValue(); syn boolean MTokenSendDefinition.shouldSendValue() = endpointDef().asTokenEndpointDefinition().shouldSendValue();
// MTypeReceiveDefinition
eq MTypeReceiveDefinition.preemptiveExpectedValue() = null;
eq MTypeReceiveDefinition.preemptiveReturn() = null;
eq MTypeReceiveDefinition.endpointDef() = getReceiveTypeEndpointDefinition();
eq MTypeReceiveDefinition.firstInputVarName() = null;
// MTypeSendDefinition
eq MTypeSendDefinition.preemptiveExpectedValue() = null;
eq MTypeSendDefinition.preemptiveReturn() = null;
eq MTypeSendDefinition.endpointDef() = getSendTypeEndpointDefinition();
eq MTypeSendDefinition.firstInputVarName() = null;
syn String MTypeSendDefinition.sender() = "_sender_" + typeName();
syn String MTypeSendDefinition.lastValue() = "_lastValue" + typeName();
syn String MTypeSendDefinition.updateMethod() = "_update_" + typeName();
syn String MTypeSendDefinition.writeMethod() = "_writeLastValue_" + typeName();
syn String MTypeSendDefinition.tokenResetMethod() = "get" + typeName() + "_reset";
syn boolean MTypeSendDefinition.shouldSendValue() = endpointDef().asTypeEndpointDefinition().shouldSendValue();
// --- MMappingDefinition --- // --- MMappingDefinition ---
syn String MMappingDefinition.toType() = getMappingDefinition().getToType().prettyPrint(); syn String MMappingDefinition.toType() = getMappingDefinition().getToType().prettyPrint();
...@@ -96,7 +136,7 @@ aspect AttributesForMustache { ...@@ -96,7 +136,7 @@ aspect AttributesForMustache {
syn String MDependencyDefinition.dependencyMethod() = "add" + capitalize(getDependencyDefinition().getID()); syn String MDependencyDefinition.dependencyMethod() = "add" + capitalize(getDependencyDefinition().getID());
syn String MDependencyDefinition.sourceParentTypeName() = getDependencyDefinition().getSource().containingTypeDecl().getName(); syn String MDependencyDefinition.sourceParentTypeName() = getDependencyDefinition().getSource().containingTypeDecl().getName();
syn String MDependencyDefinition.internalRelationPrefix() = "_internal_" + getDependencyDefinition().getID(); syn String MDependencyDefinition.internalRelationPrefix() = "_internal_" + getDependencyDefinition().getID();
syn nta MSendDefinition MDependencyDefinition.targetEndpointDefinition() { syn nta MTokenSendDefinition MDependencyDefinition.targetEndpointDefinition() {
return getDependencyDefinition().targetEndpointDefinition().toMustache(); return getDependencyDefinition().targetEndpointDefinition().toMustache();
} }
...@@ -110,7 +150,7 @@ aspect AttributesForMustache { ...@@ -110,7 +150,7 @@ aspect AttributesForMustache {
syn String MTokenComponent.javaType() = getTokenComponent().effectiveJavaTypeUse().prettyPrint(); syn String MTokenComponent.javaType() = getTokenComponent().effectiveJavaTypeUse().prettyPrint();
syn String MTokenComponent.internalName() = getTokenComponent().needProxyToken() ? "_internal_" + name() : externalName(); syn String MTokenComponent.internalName() = getTokenComponent().needProxyToken() ? "_internal_" + name() : externalName();
syn String MTokenComponent.externalName() = name(); syn String MTokenComponent.externalName() = name();
syn MSendDefinition MTokenComponent.normalTokenSendDef() { syn MTokenSendDefinition MTokenComponent.normalTokenSendDef() {
for (TokenEndpointDefinition endpointDef : getTokenComponent().getTokenEndpointDefinitionList()) { for (TokenEndpointDefinition endpointDef : getTokenComponent().getTokenEndpointDefinitionList()) {
if (endpointDef.shouldSendValue()) { if (endpointDef.shouldSendValue()) {
return endpointDef.asSendTokenEndpointDefinition().toMustache(); return endpointDef.asSendTokenEndpointDefinition().toMustache();
...@@ -124,11 +164,16 @@ aspect AttributesForMustache { ...@@ -124,11 +164,16 @@ aspect AttributesForMustache {
MRagConnect result = new MRagConnect(); MRagConnect result = new MRagConnect();
result.setRagConnect(this); result.setRagConnect(this);
for (EndpointDefinition def : getEndpointDefinitionList()) { for (EndpointDefinition def : getEndpointDefinitionList()) {
if (def.isSendTokenEndpointDefinition()) { if (def.isReceiveTokenEndpointDefinition()) {
SendTokenEndpointDefinition sendDef = def.asSendTokenEndpointDefinition(); result.addTokenReceiveDefinition(def.asReceiveTokenEndpointDefinition().toMustache());
result.addSendDefinition(sendDef.toMustache()); } else if (def.isSendTokenEndpointDefinition()) {
result.addTokenSendDefinition(def.asSendTokenEndpointDefinition().toMustache());
} else if (def.isReceiveTypeEndpointDefinition()) {
result.addTypeReceiveDefinition(def.asReceiveTypeEndpointDefinition().toMustache());
} else if (def.isSendTypeEndpointDefinition()) {
result.addTypeSendDefinition(def.asSendTypeEndpointDefinition().toMustache());
} else { } else {
result.addReceiveDefinition(def.asReceiveTokenEndpointDefinition().toMustache()); throw new RuntimeException("Unknown endpoint definition: " + def);
} }
} }
for (MappingDefinition def : allMappingDefinitions()) { for (MappingDefinition def : allMappingDefinitions()) {
...@@ -163,20 +208,34 @@ aspect AttributesForMustache { ...@@ -163,20 +208,34 @@ aspect AttributesForMustache {
} }
} }
syn lazy MReceiveDefinition ReceiveTokenEndpointDefinition.toMustache() { syn lazy MTokenReceiveDefinition ReceiveTokenEndpointDefinition.toMustache() {
MReceiveDefinition result = new MReceiveDefinition(); MTokenReceiveDefinition result = new MTokenReceiveDefinition();
result.setReceiveTokenEndpointDefinition(this); result.setReceiveTokenEndpointDefinition(this);
result.addInnerMappings(); result.addInnerMappings();
return result; return result;
} }
syn lazy MSendDefinition SendTokenEndpointDefinition.toMustache() { syn lazy MTokenSendDefinition SendTokenEndpointDefinition.toMustache() {
MSendDefinition result = new MSendDefinition(); MTokenSendDefinition result = new MTokenSendDefinition();
result.setSendTokenEndpointDefinition(this); result.setSendTokenEndpointDefinition(this);
result.addInnerMappings(); result.addInnerMappings();
return result; return result;
} }
syn lazy MTypeReceiveDefinition ReceiveTypeEndpointDefinition.toMustache() {
MTypeReceiveDefinition result = new MTypeReceiveDefinition();
result.setReceiveTypeEndpointDefinition(this);
result.addInnerMappings();
return result;
}
syn lazy MTypeSendDefinition SendTypeEndpointDefinition.toMustache() {
MTypeSendDefinition result = new MTypeSendDefinition();
result.setSendTypeEndpointDefinition(this);
result.addInnerMappings();
return result;
}
syn lazy MMappingDefinition MappingDefinition.toMustache() { syn lazy MMappingDefinition MappingDefinition.toMustache() {
MMappingDefinition result = new MMappingDefinition(); MMappingDefinition result = new MMappingDefinition();
result.setMappingDefinition(this); result.setMappingDefinition(this);
......
...@@ -79,45 +79,33 @@ aspect DefaultMappings { ...@@ -79,45 +79,33 @@ aspect DefaultMappings {
aspect Mappings { aspect Mappings {
// --- effectiveMappings --- // --- effectiveMappings ---
syn java.util.List<MappingDefinition> EndpointDefinition.effectiveMappings(); syn java.util.List<MappingDefinition> EndpointDefinition.effectiveMappings() {
eq ReceiveTokenEndpointDefinition.effectiveMappings() {
// if there is a first mapping, check if it is suitable.
// or if no mappings are specified.
// then prepend the suitable default mapping
java.util.List<MappingDefinition> result; java.util.List<MappingDefinition> result;
if (getMappingList().isEmpty() || !hasSuitableEdgeMapping()) { if (isReceiveTokenEndpointDefinition() || isReceiveTypeEndpointDefinition()) {
// 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()) {
result = new java.util.ArrayList(); result = new java.util.ArrayList();
result.add(suitableDefaultMapping()); result.add(suitableReceiveDefaultMapping());
result.addAll(getMappingList()); result.addAll(getMappingList());
} else { } else {
result = getMappingList(); result = getMappingList();
} }
return result; } else if (isSendTokenEndpointDefinition() || isSendTypeEndpointDefinition()) {
} // if no mappings are specified, or if last mapping is not suitable
eq SendTokenEndpointDefinition.effectiveMappings() {
// if there is a mapping, check if it is suitable.
// or if no mappings are specified.
// then append the suitable default mapping // then append the suitable default mapping
java.util.List<MappingDefinition> result; if (getMappingList().isEmpty() || !getMappingList().get(getMappingList().size() - 1).getToType().isByteArray()) {
if (getMappingList().isEmpty() || !hasSuitableEdgeMapping()) {
result = new java.util.ArrayList(getMappingList()); result = new java.util.ArrayList(getMappingList());
result.add(suitableDefaultMapping()); result.add(suitableSendDefaultMapping());
} else { } else {
result = getMappingList(); result = getMappingList();
} }
} else {
throw new RuntimeException("Unknown endpoint definition: " + this);
}
return result; return result;
} }
// --- hasSuitableEdgeMapping ---
syn boolean TokenEndpointDefinition.hasSuitableEdgeMapping();
eq ReceiveTokenEndpointDefinition.hasSuitableEdgeMapping() = isSuitableEdgeMapping(getMappingList().get(0));
eq SendTokenEndpointDefinition.hasSuitableEdgeMapping() = isSuitableEdgeMapping(getMappingList().get(getMappingList().size() - 1));
// --- isSuitableEdgeMapping(def) ---
syn boolean TokenEndpointDefinition.isSuitableEdgeMapping(MappingDefinition def);
eq ReceiveTokenEndpointDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getFromType().isByteArray();
eq SendTokenEndpointDefinition.isSuitableEdgeMapping(MappingDefinition def) = def.getToType().isByteArray();
// --- isPrimitiveType --- // --- isPrimitiveType ---
syn boolean TokenComponent.isPrimitiveType() = effectiveJavaTypeUse().isPrimitiveType(); syn boolean TokenComponent.isPrimitiveType() = effectiveJavaTypeUse().isPrimitiveType();
syn boolean JavaTypeUse.isPrimitiveType() = false; syn boolean JavaTypeUse.isPrimitiveType() = false;
...@@ -140,13 +128,9 @@ aspect Mappings { ...@@ -140,13 +128,9 @@ aspect Mappings {
syn boolean MappingDefinitionType.isArray() = false; syn boolean MappingDefinitionType.isArray() = false;
eq JavaArrayMappingDefinitionType.isArray() = true; eq JavaArrayMappingDefinitionType.isArray() = true;
// --- suitableDefaultMapping --- // --- suitableReceiveDefaultMapping ---
syn DefaultMappingDefinition EndpointDefinition.suitableDefaultMapping(); syn DefaultMappingDefinition EndpointDefinition.suitableReceiveDefaultMapping() {
eq ReceiveTokenEndpointDefinition.suitableDefaultMapping() { switch (targetTypeName()) {
String typeName = getMappingList().isEmpty() ?
getToken().effectiveJavaTypeUse().getName() :
getMappingList().get(0).getFromType().prettyPrint();
switch(typeName) {
case "int": case "int":
case "Integer": return ragconnect().defaultBytesToIntMapping(); case "Integer": return ragconnect().defaultBytesToIntMapping();
case "short": case "short":
...@@ -163,11 +147,9 @@ aspect Mappings { ...@@ -163,11 +147,9 @@ aspect Mappings {
default: return null; default: return null;
} }
} }
eq SendTokenEndpointDefinition.suitableDefaultMapping() { // --- suitableSendDefaultMapping ---
String typeName = getMappingList().isEmpty() ? syn DefaultMappingDefinition EndpointDefinition.suitableSendDefaultMapping() {
getToken().effectiveJavaTypeUse().getName() : switch (targetTypeName()) {
getMappingList().get(getMappingList().size() - 1).getFromType().prettyPrint();
switch(typeName) {
case "int": case "int":
case "Integer": return ragconnect().defaultIntToBytesMapping(); case "Integer": return ragconnect().defaultIntToBytesMapping();
case "short": case "short":
...@@ -184,6 +166,26 @@ aspect Mappings { ...@@ -184,6 +166,26 @@ aspect Mappings {
default: return null; default: return null;
} }
} }
// --- targetTypeName ---
syn String EndpointDefinition.targetTypeName();
eq ReceiveTokenEndpointDefinition.targetTypeName() {
return getMappingList().isEmpty() ?
getToken().effectiveJavaTypeUse().getName() :
getMappingList().get(0).getFromType().prettyPrint();
}
eq ReceiveTypeEndpointDefinition.targetTypeName() {
return 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().get(getMappingList().size() - 1).getToType().prettyPrint();
}
// eq ReceiveFromRestDefinition.suitableDefaultMapping() { // eq ReceiveFromRestDefinition.suitableDefaultMapping() {
// String typeName = getMappingList().isEmpty() ? // String typeName = getMappingList().isEmpty() ?
// getToken().getJavaTypeUse().getName() : // getToken().getJavaTypeUse().getName() :
......