Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Recursive method deleting empty packages in a model issue
Recursive method deleting empty packages in a model issue [message #661867] Mon, 28 March 2011 06:57 Go to next message
leonard.krpan is currently offline leonard.krpan
Messages: 20
Registered: March 2011
Junior Member
Hello,

this is my recursive function used to delete all empty packages in a model.

	private void removeEmptyPackages() {
		
		TreeIterator<EObject> modelIterator = ecModel.eAllContents();
		
		while( modelIterator.hasNext() ) { // THIS IS LINE 318
		
			EObject currentObject = modelIterator.next();
			
			if( currentObject instanceof EPackage ) {
				
				EPackage currentPackage = (EPackage)currentObject;
				if( currentPackage.getESubpackages().isEmpty() && currentPackage.getEClassifiers().isEmpty() ) {
					
					EPackage superPackage = currentPackage.getESuperPackage();
					if ( superPackage != null ) {
						System.out.println("removing package: " + currentPackage.getName());
						superPackage.getESubpackages().remove(currentPackage);
						removeEmptyPackages(); // THIS IS LINE 329
					} else {
						System.out.println("no super package found for package: " + currentPackage.getName());
						return;
					}
				}
				
			} else {
				continue;
			}
			
		}
		
	}


It seems to run just fine until the last package - that is the deepest element in the model tree - is found, and then...

...
removing package: variable
removing package: commonstructure
no super package found for package: variable
Exception in thread "main" org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBoundsException: index=2, size=0
	at org.eclipse.emf.common.util.BasicEList.get(BasicEList.java:352)
	at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.hasNext(EContentsEList.java:484)
	at org.eclipse.emf.ecore.util.EContentsEList$FeatureIteratorImpl.next(EContentsEList.java:565)
	at org.eclipse.emf.common.util.AbstractTreeIterator.next(AbstractTreeIterator.java:139)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:318)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.removeEmptyPackages(GEngine.java:329)
	at thesis.GEngine.processDiffMapModel(GEngine.java:123)
	at thesis.Main.main(Main.java:60)



commonstrucutre is the last package under the model root and variable is the last package in commonstrucutre. Any frame I drop to, I get an exception as soon I click on step over.

I think the logic here is quite simple but maybe there's an iteration issue when the iterator is used in a recursive call or something?
Re: Recursive method deleting empty packages in a model issue [message #661908 is a reply to message #661867] Mon, 28 March 2011 09:46 Go to previous message
leonard.krpan is currently offline leonard.krpan
Messages: 20
Registered: March 2011
Junior Member
Got an offline answer already. I was told it was not advisable to change the data that the iterator is running on. Also, I'd better use an iterative approach rather than a recursive one for efficiency reasons.
Previous Topic:[EMF Compare] Access EClass name attribute through DiffElement
Next Topic:[EEF] Issue with Map$Entry
Goto Forum:
  


Current Time: Mon Sep 01 07:30:59 EDT 2014

Powered by FUDForum. Page generated in 0.02064 seconds