Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
ecore2relast
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
ecore2relast
Commits
aa9660c2
Commit
aa9660c2
authored
5 years ago
by
Johannes Mey
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/jastadd/grammar/EcoreToGrammar.jrag
+54
-45
54 additions, 45 deletions
src/main/jastadd/grammar/EcoreToGrammar.jrag
with
54 additions
and
45 deletions
src/main/jastadd/grammar/EcoreToGrammar.jrag
+
54
−
45
View file @
aa9660c2
...
...
@@ -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));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment