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
No related branches found
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
name = name.substring(0, 1).toUpperCase() + name.substring(1);
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,61 +121,68 @@ aspect EcoreToGrammar {
for (EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatureList()) {
if (eStructuralFeature.isEReference()) {
EReference eReference = eStructuralFeature.asEReference();
if (!eReference.getContainment() && !eReference.getDerived() && !(eReference.hasEOpposite() && !eReference.getEOpposite().getContainment())) {
if (eReference.hasEOpposite() && !eReference.getEOpposite().getDerived()) {
// bidirectional relation
// only add the bidirectional relation once
if (this.hashCode() < eReference.getEOpposite().hashCode()) {
BidirectionalRelation relation = new BidirectionalRelation();
// skip containment references and derived references
if (!eReference.getContainment() && !eReference.getDerived()) {
NavigableRole left;
// is this a normal, list, or opt role?
if (eReference.many()) {
left = new ListRole();
} else {
if (eReference.required()) {
left = new NormalRole();
// 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 (eReference.hashCode() < eReference.getEOpposite().hashCode()) {
BidirectionalRelation relation = new BidirectionalRelation();
NavigableRole left;
// is this a normal, list, or opt role?
if (eReference.many()) {
left = new ListRole();
} else {
left = new OptRole();
if (eReference.required()) {
left = new NormalRole();
} else {
left = new OptRole();
}
}
}
left.setName(eReference.grammarName());
left.setName(eReference.grammarName(false));
if (eClassToTypeDecl.containsKey(eClass)) {
left.setType(eClassToTypeDecl.get(eClass));
} else {
EClassifier eType = eClass;
throw new RuntimeException("EClassifier " + (eType == null ? "null" : eType.getName()) + " not found in classifier map.");
}
if (eClassToTypeDecl.containsKey(eClass)) {
left.setType(eClassToTypeDecl.get(eClass));
} else {
EClassifier eType = eClass;
throw new RuntimeException("EClassifier " + (eType == null ? "null" : eType.getName()) + " not found in classifier map.");
}
relation.setLeft(left);
relation.setLeft(left);
NavigableRole right;
// is this a normal, list, or opt role?
if (eReference.getEOpposite().many()) {
right = new ListRole();
} else {
if (eReference.getEOpposite().required()) {
right = new NormalRole();
NavigableRole right;
// is this a normal, list, or opt role?
if (eReference.getEOpposite().many()) {
right = new ListRole();
} else {
right = new OptRole();
if (eReference.getEOpposite().required()) {
right = new NormalRole();
} else {
right = new OptRole();
}
}
}
right.setName(eReference.getEOpposite().grammarName());
right.setName(eReference.getEOpposite().grammarName(false));
if (eClassToTypeDecl.containsKey(eReference.getEType())) {
right.setType(eClassToTypeDecl.get(eReference.getEType()));
} else {
EClassifier eType = eReference.getEType();
throw new RuntimeException("EClassifier " + (eType == null ? "null" : eType.getName()) + " not found in classifier map.");
}
if (eClassToTypeDecl.containsKey(eReference.getEType())) {
right.setType(eClassToTypeDecl.get(eReference.getEType()));
} else {
EClassifier eType = eReference.getEType();
throw new RuntimeException("EClassifier " + (eType == null ? "null" : eType.getName()) + " not found in classifier map.");
}
relation.setRight(right);
relation.setRight(right);
grammar.addRelation(relation);
grammar.addRelation(relation);
}
}
} else {
......@@ -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