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 { ...@@ -3,7 +3,7 @@ aspect EcoreToGrammar {
/** /**
* transform the name of the ecore reference into a name that generates a nice API for JastAdd * 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(); String name = getName();
if (name == null || name.isEmpty()) { if (name == null || name.isEmpty()) {
...@@ -16,7 +16,9 @@ aspect EcoreToGrammar { ...@@ -16,7 +16,9 @@ aspect EcoreToGrammar {
} }
// upper case it // upper case it
if (enforceUpperCase) {
name = name.substring(0, 1).toUpperCase() + name.substring(1); name = name.substring(0, 1).toUpperCase() + name.substring(1);
}
// remove plural s // remove plural s
if (many() && name.endsWith("s")) { if (many() && name.endsWith("s")) {
...@@ -96,7 +98,7 @@ aspect EcoreToGrammar { ...@@ -96,7 +98,7 @@ aspect EcoreToGrammar {
throw new RuntimeException("EClassifier " + (eType == null ? "null" : eType.getName()) + " not found in classifier map"); 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()); component.setNTA(containmentReference.getDerived());
typeDecl.addComponent(component); typeDecl.addComponent(component);
...@@ -119,12 +121,18 @@ aspect EcoreToGrammar { ...@@ -119,12 +121,18 @@ aspect EcoreToGrammar {
for (EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatureList()) { for (EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatureList()) {
if (eStructuralFeature.isEReference()) { if (eStructuralFeature.isEReference()) {
EReference eReference = eStructuralFeature.asEReference(); 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 (eReference.hasEOpposite() && !eReference.getEOpposite().getDerived()) {
// if the opposite is a containment relation, we skip it
if (!eReference.getEOpposite().getContainment()) {
// bidirectional relation // bidirectional relation
// only add the bidirectional relation once // only add the bidirectional relation once
if (this.hashCode() < eReference.getEOpposite().hashCode()) { if (eReference.hashCode() < eReference.getEOpposite().hashCode()) {
BidirectionalRelation relation = new BidirectionalRelation(); BidirectionalRelation relation = new BidirectionalRelation();
NavigableRole left; NavigableRole left;
...@@ -139,7 +147,7 @@ aspect EcoreToGrammar { ...@@ -139,7 +147,7 @@ aspect EcoreToGrammar {
} }
} }
left.setName(eReference.grammarName()); left.setName(eReference.grammarName(false));
if (eClassToTypeDecl.containsKey(eClass)) { if (eClassToTypeDecl.containsKey(eClass)) {
left.setType(eClassToTypeDecl.get(eClass)); left.setType(eClassToTypeDecl.get(eClass));
...@@ -162,7 +170,7 @@ aspect EcoreToGrammar { ...@@ -162,7 +170,7 @@ aspect EcoreToGrammar {
} }
} }
right.setName(eReference.getEOpposite().grammarName()); right.setName(eReference.getEOpposite().grammarName(false));
if (eClassToTypeDecl.containsKey(eReference.getEType())) { if (eClassToTypeDecl.containsKey(eReference.getEType())) {
right.setType(eClassToTypeDecl.get(eReference.getEType())); right.setType(eClassToTypeDecl.get(eReference.getEType()));
...@@ -175,6 +183,7 @@ aspect EcoreToGrammar { ...@@ -175,6 +183,7 @@ aspect EcoreToGrammar {
grammar.addRelation(relation); grammar.addRelation(relation);
} }
}
} else { } else {
DirectedRelation relation = new DirectedRelation(); DirectedRelation relation = new DirectedRelation();
...@@ -190,7 +199,7 @@ aspect EcoreToGrammar { ...@@ -190,7 +199,7 @@ aspect EcoreToGrammar {
} }
} }
source.setName(eReference.grammarName()); source.setName(eReference.grammarName(false));
if (eClassToTypeDecl.containsKey(eClass)) { if (eClassToTypeDecl.containsKey(eClass)) {
source.setType(eClassToTypeDecl.get(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