Skip to content

Commit

Permalink
The drawer in the zoo cleans the annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jlcanovas committed Dec 5, 2014
1 parent be64369 commit 8f87e82
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.EcorePackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.emftools.emf2gv.graphdesc.GraphdescPackage;
Expand Down Expand Up @@ -76,8 +78,23 @@ else if (file.isFile() && file.getName().endsWith("ecore") && (overwrite || !pic
e.printStackTrace();
}

List<EObject> elements = new ArrayList<>();
List<EObject> elementsToUnset = new ArrayList<>();
TreeIterator<EObject> treeIt = res.getAllContents();
while(treeIt.hasNext()) {
EObject eObject = treeIt.next();
EStructuralFeature esf = eObject.eClass().getEStructuralFeature("eAnnotations");
if(esf != null && eObject.eIsSet(esf)) {
elementsToUnset.add(eObject);
}
}

for(EObject eObject : elementsToUnset) {
EStructuralFeature esf = eObject.eClass().getEStructuralFeature("eAnnotations");
eObject.eUnset(esf);
}

List<EObject> elements = new ArrayList<>();
treeIt = res.getAllContents();
while(treeIt.hasNext()) {
EObject eObject = treeIt.next();
elements.add(eObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ public String getSourceName(EClass modelElement) {
EAnnotation annotation = getCoverageAnnotation(modelElement);
return annotation.getDetails().get(SOURCE_NAME_TAG);
}

/**
* Remove all the annotations. Be careful, the method returns the same epackage.
*
* @param ePackage
* @return
*/
public EPackage cleanAnnotations(EPackage ePackage) {
for(EClassifier eClassifier : ePackage.getEClassifiers()) {
eClassifier.getEAnnotations().clear();
if (eClassifier instanceof EClass) {
EClass eClass = (EClass) eClassifier;
for(EStructuralFeature eStructuralFeature : eClass.getEStructuralFeatures()) {
eStructuralFeature.getEAnnotations().clear();
}
}
}
return ePackage;
}

}

0 comments on commit 8f87e82

Please sign in to comment.