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

Testing default only write.

- base: fixed bug when multiple dependency definitions have same source (used to generate multiple getter/setter)
- added test case for writing all supported types for default mapping definitions
- inherited attributes for token-attributes are not supported (because no "$token_reset()" is generated by JastAdd)
- added short test descriptions
parent ed94e814
......@@ -15,6 +15,10 @@ aspect Navigation {
syn boolean Component.isTypeComponent() = false;
eq TypeComponent.isTypeComponent() = true;
// --- asTypeComponent (should be in preprocessor) ---
syn TypeComponent Component.asTypeComponent() = null;
eq TypeComponent.asTypeComponent() = this;
// --- isWriteToMqttDefinition ---
syn boolean UpdateDefinition.isWriteToMqttDefinition() = false;
eq WriteToMqttDefinition.isWriteToMqttDefinition() = true;
......@@ -38,4 +42,10 @@ aspect Navigation {
// --- isDefaultMappingDefinition ---
syn boolean MappingDefinition.isDefaultMappingDefinition() = false;
eq DefaultMappingDefinition.isDefaultMappingDefinition() = true;
// --- allTokenComponents ---
coll java.util.Set<TokenComponent> Program.allTokenComponents() [new java.util.HashSet<>()] root Program;
TokenComponent contributes this
to Program.allTokenComponents()
for program();
}
......@@ -101,6 +101,9 @@ aspect AspectGeneration {
for (DependencyDefinition def : getDependencyDefinitionList()) {
def.generateAspect(sb);
}
for (TokenComponent token : getProgram().allTokenComponents()) {
token.generateAspect(sb);
}
sb.append("}\n");
}
......@@ -235,27 +238,40 @@ aspect AspectGeneration {
.append(dependencyMethod()).append("(").append(sourceParentTypeName).append(" source) {\n");
sb.append(ind(2)).append("add").append(internalRelationPrefix()).append("Source(source);\n");
sb.append(ind(1)).append("}\n\n");
}
void TokenComponent.generateAspect(StringBuilder sb) {
if (getDependencySourceDefinitionList().isEmpty()) { return; }
String parentTypeName = containingTypeDecl().getName();
// virtual setter
sb.append(ind(1)).append("public ").append(sourceParentTypeName).append(" ")
.append(sourceParentTypeName).append(".set").append(getSource().getName()).append("(");
getSource().getJavaTypeUse().generateAbstractGrammar(sb);
sb.append(ind(1)).append("public ").append(parentTypeName).append(" ")
.append(parentTypeName).append(".set").append(getName()).append("(");
getJavaTypeUse().generateAbstractGrammar(sb);
sb.append(" value) {\n");
sb.append(ind(2)).append("set").append(internalTokenName()).append("(value);\n");
sb.append(ind(2)).append("for (").append(targetParentTypeName).append(" target : get")
.append(internalRelationPrefix()).append("TargetList()) {\n");
sb.append(ind(3)).append("if (target.").append(targetUpdateDefinition().updateMethod()).append("()) {\n");
sb.append(ind(4)).append("target.").append(targetUpdateDefinition().writeMethod()).append("();\n");
sb.append(ind(3)).append("}\n");
sb.append(ind(2)).append("}\n");
sb.append(ind(2)).append("set").append(internalName()).append("(value);\n");
for (DependencyDefinition dependencyDefinition : getDependencySourceDefinitionList()) {
String targetParentTypeName = dependencyDefinition.getTarget().containingTypeDecl().getName();
sb.append(ind(2)).append("for (").append(targetParentTypeName).append(" target : get")
.append(dependencyDefinition.internalRelationPrefix()).append("TargetList()) {\n");
sb.append(ind(3)).append("if (target.")
.append(dependencyDefinition.targetUpdateDefinition().updateMethod())
.append("()) {\n");
sb.append(ind(4)).append("target.")
.append(dependencyDefinition.targetUpdateDefinition().writeMethod())
.append("();\n");
sb.append(ind(3)).append("}\n");
sb.append(ind(2)).append("}\n");
}
sb.append(ind(2)).append("return this;\n");
sb.append(ind(1)).append("}\n\n");
// virtual getter
sb.append(ind(1)).append("public ");
getSource().getJavaTypeUse().generateAbstractGrammar(sb);
sb.append(" ").append(sourceParentTypeName).append(".get").append(getSource().getName()).append("() {\n");
sb.append(ind(2)).append("return get").append(internalTokenName()).append("();\n");
getJavaTypeUse().generateAbstractGrammar(sb);
sb.append(" ").append(parentTypeName).append(".get").append(getName()).append("() {\n");
sb.append(ind(2)).append("return get").append(internalName()).append("();\n");
sb.append(ind(1)).append("}\n\n");
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment