Skip to content

Commit 8f87e82

Browse files
committed
The drawer in the zoo cleans the annotations
1 parent be64369 commit 8f87e82

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

fr.inria.atlanmod.json.discoverer.zoo/src/fr/inria/atlanmod/json/discoverer/zoo/ModelDrawer.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
import org.eclipse.emf.common.util.TreeIterator;
2222
import org.eclipse.emf.common.util.URI;
2323
import org.eclipse.emf.ecore.EObject;
24+
import org.eclipse.emf.ecore.EStructuralFeature;
2425
import org.eclipse.emf.ecore.EcorePackage;
2526
import org.eclipse.emf.ecore.resource.Resource;
2627
import org.eclipse.emf.ecore.resource.ResourceSet;
2728
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
29+
import org.eclipse.emf.ecore.util.EcoreUtil;
2830
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
2931
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
3032
import org.emftools.emf2gv.graphdesc.GraphdescPackage;
@@ -76,8 +78,23 @@ else if (file.isFile() && file.getName().endsWith("ecore") && (overwrite || !pic
7678
e.printStackTrace();
7779
}
7880

79-
List<EObject> elements = new ArrayList<>();
81+
List<EObject> elementsToUnset = new ArrayList<>();
8082
TreeIterator<EObject> treeIt = res.getAllContents();
83+
while(treeIt.hasNext()) {
84+
EObject eObject = treeIt.next();
85+
EStructuralFeature esf = eObject.eClass().getEStructuralFeature("eAnnotations");
86+
if(esf != null && eObject.eIsSet(esf)) {
87+
elementsToUnset.add(eObject);
88+
}
89+
}
90+
91+
for(EObject eObject : elementsToUnset) {
92+
EStructuralFeature esf = eObject.eClass().getEStructuralFeature("eAnnotations");
93+
eObject.eUnset(esf);
94+
}
95+
96+
List<EObject> elements = new ArrayList<>();
97+
treeIt = res.getAllContents();
8198
while(treeIt.hasNext()) {
8299
EObject eObject = treeIt.next();
83100
elements.add(eObject);

fr.inria.atlanmod.json.discoverer/src/fr/inria/atlanmod/discoverer/AnnotationHelper.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,25 @@ public String getSourceName(EClass modelElement) {
145145
EAnnotation annotation = getCoverageAnnotation(modelElement);
146146
return annotation.getDetails().get(SOURCE_NAME_TAG);
147147
}
148+
149+
/**
150+
* Remove all the annotations. Be careful, the method returns the same epackage.
151+
*
152+
* @param ePackage
153+
* @return
154+
*/
155+
public EPackage cleanAnnotations(EPackage ePackage) {
156+
for(EClassifier eClassifier : ePackage.getEClassifiers()) {
157+
eClassifier.getEAnnotations().clear();
158+
if (eClassifier instanceof EClass) {
159+
EClass eClass = (EClass) eClassifier;
160+
for(EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatures()) {
161+
eStructuralFeature.getEAnnotations().clear();
162+
}
163+
}
164+
}
165+
return ePackage;
166+
}
148167

149168
}
150169

0 commit comments

Comments
 (0)