package com.redhat.ceylon.eclipse.core.builder;

import static java.lang.Math.max;

import java.util.List;
import java.util.Set;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

import com.redhat.ceylon.compiler.typechecker.TypeChecker;
import com.redhat.ceylon.compiler.typechecker.model.Module;
import com.redhat.ceylon.compiler.typechecker.model.Package;

final class WarmupJob extends Job {
	private final TypeChecker typeChecker;

	WarmupJob(String name, TypeChecker typeChecker) {
		super("Warming up completion processor for " + name);
		this.typeChecker = typeChecker;
	}

	@Override
	protected IStatus run(IProgressMonitor monitor) {
		monitor.beginTask("Warming up completion processor", 100000);
		Set<Module> modules = typeChecker.getPhasedUnits().getModuleManager()
				.getContext().getModules().getListOfModules();
		monitor.worked(10000);
		for (Module m: modules) {
			List<Package> packages = m.getAllPackages();
			for (Package p: packages) {
				p.getMembers();
			}
			monitor.worked(90000/max(modules.size(),1));
			if (monitor.isCanceled()) {
				return Status.CANCEL_STATUS;
			}
		}
		monitor.done();
		return Status.OK_STATUS;
	}
}
@@ -77,16 +77,66 @@
 h.max;%0A%0A
+import java.util.ConcurrentModificationException;%0A
 import j
@@ -1026,16 +1026,28 @@
 000);%0A%09%09
+try %7B%0A%09%09    
 for (Mod
@@ -1066,17 +1066,24 @@
 es) %7B%0A%09%09
-%09
+        
 List%3CPac
@@ -1121,17 +1121,24 @@
 es();%0A%09%09
-%09
+        
 for (Pac
@@ -1159,18 +1159,28 @@
 es) %7B%0A%09%09
-%09%09
+            
 p.getMem
@@ -1193,14 +1193,28 @@
 ;%0A%09%09
-%09%7D%0A%09%09%09
+        %7D%0A%09%09        
 moni
@@ -1256,17 +1256,24 @@
 ,1));%0A%09%09
-%09
+        
 if (moni
@@ -1294,18 +1294,28 @@
 ()) %7B%0A%09%09
-%09%09
+            
 return S
@@ -1337,18 +1337,135 @@
 ATUS;%0A%09%09
-%09%7D
+        %7D%0A%09%09    %7D%0A%09%09%7D%0A%09%09catch (ConcurrentModificationException cme) %7B%0A%09%09    //expected, if a build starts during warmup
 %0A%09%09%7D%0A%09%09m

fix (ahem) #582