Skip to content
Snippets Groups Projects
Commit aa9660c2 authored by Johannes Mey's avatar Johannes Mey
Browse files

fix bug that disregarded some relations, do not uppercase relation roles

parent 574353e8
Branches
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ aspect EcoreToGrammar {
/**
* transform the name of the ecore reference into a name that generates a nice API for JastAdd
*/
syn String EReference.grammarName() {
syn String EReference.grammarName(boolean enforceUpperCase) {
String name = getName();
if (name == null || name.isEmpty()) {
......@@ -16,7 +16,9 @@ aspect EcoreToGrammar {
}
// upper case it
if (enforceUpperCase) {
name = name.substring(0, 1).toUpperCase() + name.substring(1);
}
// remove plural s
if (many() && name.endsWith("s")) {
......@@ -96,7 +98,7 @@ aspect EcoreToGrammar {
throw new RuntimeException("EClassifier " + (eType == null ? "null" : eType.getName()) + " not found in classifier map");
}
component.setName(containmentReference.grammarName());
component.setName(containmentReference.grammarName(true));
component.setNTA(containmentReference.getDerived());
typeDecl.addComponent(component);
......@@ -119,12 +121,18 @@ aspect EcoreToGrammar {
for (EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatureList()) {
if (eStructuralFeature.isEReference()) {
EReference eReference = eStructuralFeature.asEReference();
if (!eReference.getContainment() && !eReference.getDerived() && !(eReference.hasEOpposite() && !eReference.getEOpposite().getContainment())) {
// skip containment references and derived references
if (!eReference.getContainment() && !eReference.getDerived()) {
// it is a bidirectional relation if it has an opposite that is not derived
if (eReference.hasEOpposite() && !eReference.getEOpposite().getDerived()) {
// if the opposite is a containment relation, we skip it
if (!eReference.getEOpposite().getContainment()) {
// bidirectional relation
// only add the bidirectional relation once
if (this.hashCode() < eReference.getEOpposite().hashCode()) {
if (eReference.hashCode() < eReference.getEOpposite().hashCode()) {
BidirectionalRelation relation = new BidirectionalRelation();
NavigableRole left;
......@@ -139,7 +147,7 @@ aspect EcoreToGrammar {
}
}
left.setName(eReference.grammarName());
left.setName(eReference.grammarName(false));
if (eClassToTypeDecl.containsKey(eClass)) {
left.setType(eClassToTypeDecl.get(eClass));
......@@ -162,7 +170,7 @@ aspect EcoreToGrammar {
}
}
right.setName(eReference.getEOpposite().grammarName());
right.setName(eReference.getEOpposite().grammarName(false));
if (eClassToTypeDecl.containsKey(eReference.getEType())) {
right.setType(eClassToTypeDecl.get(eReference.getEType()));
......@@ -175,6 +183,7 @@ aspect EcoreToGrammar {
grammar.addRelation(relation);
}
}
} else {
DirectedRelation relation = new DirectedRelation();
......@@ -190,7 +199,7 @@ aspect EcoreToGrammar {
}
}
source.setName(eReference.grammarName());
source.setName(eReference.grammarName(false));
if (eClassToTypeDecl.containsKey(eClass)) {
source.setType(eClassToTypeDecl.get(eClass));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment