[bugzilla 398498] Fixing an issue in WorkspaceAdapter when Intent
commands are executed in different threads

Make sure that the transaction is available before executing the command
diff --git a/plugins/org.eclipse.mylyn.docs.intent.client.compiler/src/org/eclipse/mylyn/docs/intent/client/compiler/ModelingUnitCompiler.java b/plugins/org.eclipse.mylyn.docs.intent.client.compiler/src/org/eclipse/mylyn/docs/intent/client/compiler/ModelingUnitCompiler.java
index dc44bd9..fb5d8bb 100644
--- a/plugins/org.eclipse.mylyn.docs.intent.client.compiler/src/org/eclipse/mylyn/docs/intent/client/compiler/ModelingUnitCompiler.java
+++ b/plugins/org.eclipse.mylyn.docs.intent.client.compiler/src/org/eclipse/mylyn/docs/intent/client/compiler/ModelingUnitCompiler.java
@@ -378,17 +378,21 @@
 	private boolean validateGeneratedElement(EObject generatedElement) {
 		UnitInstruction instanciation = informationHolder
 				.getInstanciationInstructionByCreatedElement(generatedElement);
-		GeneratedElementValidator validator = new GeneratedElementValidator(instanciation, generatedElement);
-		Diagnostic diagnostic;
-		boolean hasErrors = false;
-		try {
-			diagnostic = validator.validate();
-			informationHolder.registerDiagnosticAsCompilationStatusList(generatedElement, diagnostic);
-		} catch (CompilationException e) {
-			informationHolder.registerCompilationExceptionAsCompilationStatus(e);
-			hasErrors = true;
+		if (instanciation != null) {
+			GeneratedElementValidator validator = new GeneratedElementValidator(instanciation,
+					generatedElement);
+			Diagnostic diagnostic;
+			boolean hasErrors = false;
+			try {
+				diagnostic = validator.validate();
+				informationHolder.registerDiagnosticAsCompilationStatusList(generatedElement, diagnostic);
+			} catch (CompilationException e) {
+				informationHolder.registerCompilationExceptionAsCompilationStatus(e);
+				hasErrors = true;
+			}
+			return !hasErrors;
 		}
-		return !hasErrors;
+		return false;
 	}
 
 }
diff --git a/plugins/org.eclipse.mylyn.docs.intent.client.compiler/src/org/eclipse/mylyn/docs/intent/client/compiler/utils/IntentCompilerInformationHolder.java b/plugins/org.eclipse.mylyn.docs.intent.client.compiler/src/org/eclipse/mylyn/docs/intent/client/compiler/utils/IntentCompilerInformationHolder.java
index 837067b..7642fc5 100644
--- a/plugins/org.eclipse.mylyn.docs.intent.client.compiler/src/org/eclipse/mylyn/docs/intent/client/compiler/utils/IntentCompilerInformationHolder.java
+++ b/plugins/org.eclipse.mylyn.docs.intent.client.compiler/src/org/eclipse/mylyn/docs/intent/client/compiler/utils/IntentCompilerInformationHolder.java
@@ -1,594 +1,597 @@
-/*******************************************************************************

- * Copyright (c) 2010, 2011 Obeo.

- * All rights reserved. This program and the accompanying materials

- * are made available under the terms of the Eclipse Public License v1.0

- * which accompanies this distribution, and is available at

- * http://www.eclipse.org/legal/epl-v10.html

- * 

- * Contributors:

- *     Obeo - initial API and implementation

- *******************************************************************************/

-package org.eclipse.mylyn.docs.intent.client.compiler.utils;

-

-import com.google.common.base.Predicate;

-import com.google.common.collect.Iterables;

-import com.google.common.collect.Sets;

-

-import java.util.Collection;

-import java.util.Iterator;

-import java.util.List;

-import java.util.Map.Entry;

-import java.util.Set;

-

-import org.eclipse.emf.common.util.BasicEList;

-import org.eclipse.emf.common.util.Diagnostic;

-import org.eclipse.emf.common.util.EList;

-import org.eclipse.emf.ecore.EClassifier;

-import org.eclipse.emf.ecore.EObject;

-import org.eclipse.mylyn.docs.intent.client.compiler.errors.CompilationException;

-import org.eclipse.mylyn.docs.intent.client.compiler.errors.InvalidValueException;

-import org.eclipse.mylyn.docs.intent.core.compiler.CompilationInformationHolder;

-import org.eclipse.mylyn.docs.intent.core.compiler.CompilationMessageType;

-import org.eclipse.mylyn.docs.intent.core.compiler.CompilationStatus;

-import org.eclipse.mylyn.docs.intent.core.compiler.CompilationStatusManager;

-import org.eclipse.mylyn.docs.intent.core.compiler.CompilerFactory;

-import org.eclipse.mylyn.docs.intent.core.compiler.StringToEObjectMap;

-import org.eclipse.mylyn.docs.intent.core.compiler.UnresolvedContributionHolder;

-import org.eclipse.mylyn.docs.intent.core.compiler.UnresolvedReferenceHolder;

-import org.eclipse.mylyn.docs.intent.core.genericunit.UnitInstruction;

-import org.eclipse.mylyn.docs.intent.core.modelingunit.ContributionInstruction;

-import org.eclipse.mylyn.docs.intent.core.modelingunit.InstanciationInstruction;

-import org.eclipse.mylyn.docs.intent.core.modelingunit.ModelingUnit;

-import org.eclipse.mylyn.docs.intent.core.modelingunit.ModelingUnitInstruction;

-import org.eclipse.mylyn.docs.intent.core.modelingunit.ResourceDeclaration;

-

-/**

- * Class storing all the informations that can be needed by any entity of the compilation process.

- * 

- * @author <a href="mailto:alex.lagarde@obeo.fr">Alex Lagarde</a>

- */

-public final class IntentCompilerInformationHolder {

-

-	/**

-	 * Current instance of the information Holder (singleton).

-	 */

-	private static IntentCompilerInformationHolder currentInstance;

-

-	/**

-	 * The informationHolder used to store informations.

-	 */

-	private CompilationInformationHolder informationHolder;

-

-	/**

-	 * List of the currentImportedPackages.

-	 */

-	private List<String> currentImportedPackages;

-

-	private CompilationStatusManager statusManager;

-

-	/**

-	 * IntentCompilerInformationHolder constructor.

-	 */

-	private IntentCompilerInformationHolder() {

-		this.informationHolder = CompilerFactory.eINSTANCE.createCompilationInformationHolder();

-	}

-

-	/**

-	 * Returns the current instance of the information Holder (singleton).

-	 * 

-	 * @return the current instance of the information Holder (singleton)

-	 */

-	public static IntentCompilerInformationHolder getInstance() {

-		if (currentInstance == null) {

-			currentInstance = new IntentCompilerInformationHolder();

-		}

-		return currentInstance;

-	}

-

-	/**

-	 * Initialize this IntentCompilerInformationHolder by clearing all informations.

-	 */

-	public void initialize() {

-		informationHolder = CompilerFactory.eINSTANCE.createCompilationInformationHolder();

-

-		if (statusManager == null) {

-			statusManager = CompilerFactory.eINSTANCE.createCompilationStatusManager();

-		} else {

-			statusManager.getCompilationStatusList().clear();

-			statusManager.getModelingUnitToStatusList().clear();

-		}

-	}

-

-	public CompilationStatusManager getStatusManager() {

-		return statusManager;

-	}

-

-	/**

-	 * Add the given element to the current created element list.

-	 * 

-	 * @param instruction

-	 *            the instruction that declared this element

-	 * @param createdElement

-	 *            the element to register

-	 */

-	public void addCreatedElementsToCurrentList(UnitInstruction instruction, EObject createdElement) {

-		if (createdElement != null) {

-			this.getCurrentCreatedElements().add(createdElement);

-			BasicEList<UnitInstruction> unitInstructions = new BasicEList<UnitInstruction>();

-			unitInstructions.add(instruction);

-			this.informationHolder.getCreatedElementsToInstructions().put(createdElement, unitInstructions);

-		}

-	}

-

-	/**

-	 * Resolves the contributed instanciation instruction.

-	 * 

-	 * @param contributionInstruction

-	 *            the contribution instruction

-	 */

-	private void referenceContributionInstruction(ContributionInstruction contributionInstruction) {

-		if (contributionInstruction.getContributionReference() != null

-				&& contributionInstruction.getContributionReference().getReferencedInstruction() != null) {

-

-			Iterator<Entry<EObject, EList<UnitInstruction>>> entryIterator = this.informationHolder

-					.getCreatedElementsToInstructions().entrySet().iterator();

-			ModelingUnitInstruction targetInstanciationInstruction = contributionInstruction

-					.getContributionReference().getReferencedInstruction();

-			boolean instanciationInstructionFound = false;

-			while (entryIterator.hasNext() && !instanciationInstructionFound) {

-				Entry<EObject, EList<UnitInstruction>> entry = entryIterator.next();

-				if (entry.getValue().contains(targetInstanciationInstruction)) {

-					entry.getValue().add(contributionInstruction);

-					instanciationInstructionFound = true;

-				}

-			}

-		}

-	}

-

-	/**

-	 * Returns the instruction that declared the given element.

-	 * 

-	 * @param createdElement

-	 *            the element to inspect

-	 * @return the instruction that declared the given element

-	 */

-	public UnitInstruction getInstanciationInstructionByCreatedElement(EObject createdElement) {

-		return this.informationHolder.getCreatedElementsToInstructions().get(createdElement).iterator()

-				.next();

-	}

-

-	/**

-	 * Returns the instruction related to the given element.

-	 * 

-	 * @param createdElement

-	 *            the created element

-	 * @return the related instructions

-	 */

-	public Collection<UnitInstruction> getAllInstructionsByCreatedElement(EObject createdElement) {

-		return this.informationHolder.getCreatedElementsToInstructions().get(createdElement);

-	}

-

-	/**

-	 * Returns all the Instanciation instructions that have a non-null name (e.g new EClass e1 {}).

-	 * 

-	 * @return all the instanciation instructions that have a non-null name (e.g new EClass e1 {})

-	 */

-	public Set<UnitInstruction> getAllInstanciationsInstructions() {

-		return Sets.newLinkedHashSet(Iterables.filter(

-				Iterables.concat(this.informationHolder.getCreatedElementsToInstructions().values()),

-				new Predicate<UnitInstruction>() {

-

-					public boolean apply(UnitInstruction instruction) {

-						return instruction instanceof InstanciationInstruction

-								&& ((InstanciationInstruction)instruction).getName() != null;

-					}

-				}));

-	}

-

-	/**

-	 * Returns the object associated to the given name (used for resolving reference).

-	 * 

-	 * @param type

-	 *            the type of the researched element.

-	 * @param name

-	 *            Name of the searched object.

-	 * @return the object associated to the given name

-	 */

-	public Object getCreatedInstanceByName(EClassifier type, String name) {

-		Object createdInstance = null;

-		if (type != null) {

-			return this.informationHolder.getTypeToNameToElementsMap().get(type).getNameToElement().get(name);

-		} else {

-			// If type is null we search this instance for any type

-			for (EClassifier possibleType : this.informationHolder.getTypeToNameToElementsMap().keySet()) {

-				createdInstance = this.informationHolder.getTypeToNameToElementsMap().get(possibleType)

-						.getNameToElement().get(name);

-				if (createdInstance != null) {

-					break;

-				}

-			}

-			return createdInstance;

-		}

-	}

-

-	/**

-	 * Add the given resource (which is empty) to the map.

-	 * 

-	 * @param resource

-	 *            the resource to map with the given element

-	 */

-	public void addResource(ResourceDeclaration resource) {

-		if (this.informationHolder.getResourceToContainedElements().get(resource) == null) {

-			this.informationHolder.getResourceToContainedElements().put(resource, new BasicEList<EObject>());

-		}

-	}

-

-	/**

-	 * Add the given generated element to the given resource's content list.

-	 * 

-	 * @param resource

-	 *            the resource to map with the given element

-	 * @param newContainedElement

-	 *            the element to map with the given resource

-	 */

-	public void addResourceToGeneratedElementMapping(ResourceDeclaration resource, EObject newContainedElement) {

-		if (this.informationHolder.getResourceToContainedElements().get(resource) == null) {

-			this.informationHolder.getResourceToContainedElements().put(resource, new BasicEList<EObject>());

-		}

-		this.informationHolder.getResourceToContainedElements().get(resource).add(newContainedElement);

-

-	}

-

-	/**

-	 * Returns the declared resources.

-	 * 

-	 * @return the declared resources.

-	 */

-	public Set<ResourceDeclaration> getDeclaredResources() {

-		return this.informationHolder.getResourceToContainedElements().keySet();

-	}

-

-	/**

-	 * Returns the given's resource content (generated elements).

-	 * 

-	 * @param resource

-	 *            the resource to inspect

-	 * @return the given's resource content (generated elements)

-	 */

-	public EList<EObject> getResourceContent(ResourceDeclaration resource) {

-		return this.informationHolder.getResourceToContainedElements().get(resource);

-	}

-

-	/**

-	 * Add to the unresolvedReference list of the given element the given referenceHolder.

-	 * 

-	 * @param generatedElement

-	 *            the element that contains the unresolved reference to add

-	 * @param referenceHolder

-	 *            the referenceHolder containing the feature containing the unresolved reference and the

-	 *            textual value of it

-	 */

-	public void addUnresolvedReference(EObject generatedElement, UnresolvedReferenceHolder referenceHolder) {

-		if (this.informationHolder.getElementToUnresolvedReferenceMap().get(generatedElement) == null) {

-			this.informationHolder.getElementToUnresolvedReferenceMap().put(generatedElement,

-					new BasicEList<UnresolvedReferenceHolder>());

-		}

-		this.informationHolder.getElementToUnresolvedReferenceMap().get(generatedElement)

-				.add(referenceHolder);

-	}

-

-	/**

-	 * Returns a list containing the unresolved references for the given element.

-	 * 

-	 * @param elementContainingUnresolvedReference

-	 *            the element to inspect

-	 * @return a list containing the unresolved references for the given element

-	 */

-	public EList<UnresolvedReferenceHolder> getUnresolvedReferencesByGeneratedElement(

-			EObject elementContainingUnresolvedReference) {

-		EList<UnresolvedReferenceHolder> unresolvedRefs = this.informationHolder

-				.getElementToUnresolvedReferenceMap().get(elementContainingUnresolvedReference);

-		if (unresolvedRefs == null) {

-			unresolvedRefs = new BasicEList<UnresolvedReferenceHolder>();

-		}

-		return unresolvedRefs;

-	}

-

-	/**

-	 * Sets the list of current imported packages (URIs form).

-	 * 

-	 * @param importedPackages

-	 *            the list of current imported packages (URIs form)

-	 */

-	public void setCurrentImportedPackages(List<String> importedPackages) {

-		this.currentImportedPackages = importedPackages;

-	}

-

-	/**

-	 * Returns the list of current imported packages (URIs form).

-	 * 

-	 * @return the list of current imported packages (URIs form)

-	 */

-	public List<String> getCurrentImportedPackages() {

-		return currentImportedPackages;

-	}

-

-	public List<EObject> getCurrentCreatedElements() {

-		return this.informationHolder.getCurrentGeneratedElementList();

-	}

-

-	/**

-	 * Try to add the given createdElement identified by the given name ; throws an exception if an element

-	 * has already been registered with this name.

-	 * 

-	 * @param name

-	 *            name (identifier) of the element to register

-	 * @param createdElement

-	 *            the createdElement

-	 * @param instruction

-	 *            the instruction that declared this element

-	 */

-	public void addNameToCreatedElementEntry(String name, EObject createdElement,

-			InstanciationInstruction instruction) {

-		if (name != null) {

-			StringToEObjectMap nameToElement = this.informationHolder.getTypeToNameToElementsMap().get(

-					createdElement.eClass());

-			if (nameToElement == null) {

-				nameToElement = CompilerFactory.eINSTANCE.createStringToEObjectMap();

-				this.informationHolder.getTypeToNameToElementsMap().put(createdElement.eClass(),

-						nameToElement);

-			}

-

-			// If an element has already been registered with this name

-			if (nameToElement.getNameToElement().get(name) != null) {

-				throw new InvalidValueException(instruction, "The name " + name

-						+ " has already been used to identify an element.");

-			}

-

-			// Otherwise, we register the given element

-			nameToElement.getNameToElement().put(name, createdElement);

-		}

-		this.addCreatedElementsToCurrentList(instruction, createdElement);

-	}

-

-	/**

-	 * Checks if a contribution is unresolved.

-	 * 

-	 * @param contributionInstruction

-	 *            the contribution instruction

-	 * @return true if the contribution can be resolved

-	 */

-	public boolean isUnresolvedContribution(ContributionInstruction contributionInstruction) {

-		boolean isUnresolved = this.informationHolder.getUnresolvedContributions().get(

-				contributionInstruction.getContributionReference().getIntentHref()) == null;

-		if (!isUnresolved) {

-			isUnresolved = true;

-			for (UnresolvedContributionHolder holder : this.informationHolder.getUnresolvedContributions()

-					.get(contributionInstruction.getContributionReference().getIntentHref())) {

-				if (holder.getReferencedContribution() == contributionInstruction) {

-					isUnresolved = isUnresolved && !holder.isResolved();

-				}

-			}

-		}

-		return isUnresolved;

-	}

-

-	/**

-	 * Returns the unresolved contributions associated to the contributed element matching the given name.

-	 * 

-	 * @param contributedElementName

-	 *            the element name

-	 * @return the unresolved contributions

-	 */

-	public EList<UnresolvedContributionHolder> getContributionsAssociatedTo(String contributedElementName) {

-		if (this.informationHolder.getUnresolvedContributions().get(contributedElementName) != null) {

-			return new BasicEList<UnresolvedContributionHolder>(this.informationHolder

-					.getUnresolvedContributions().get(contributedElementName));

-

-		}

-		return new BasicEList<UnresolvedContributionHolder>();

-	}

-

-	/**

-	 * Return the list of unresolved contribution instructions for the element with the given name.

-	 * 

-	 * @param contributedElementName

-	 *            the name of the element that is associated with unresolved contribution exceptions.

-	 * @return the list of unresolved contribution instructions for the element with the given name

-	 */

-	public EList<UnresolvedContributionHolder> getUnresolvedContributions(String contributedElementName) {

-

-		if (this.informationHolder.getUnresolvedContributions().get(contributedElementName) != null) {

-			return this.informationHolder.getUnresolvedContributions().get(contributedElementName);

-		}

-		return new BasicEList<UnresolvedContributionHolder>();

-	}

-

-	/**

-	 * Returns the textual reference that remained unresolved for contribution instructions.

-	 * 

-	 * @return the textual reference that remained unresolved for contribution instructions

-	 */

-	public Set<String> getAllUnresolvedContributionsNames() {

-		return this.informationHolder.getUnresolvedContributions().keySet();

-	}

-

-	/**

-	 * returns the validation informations related to the createdElements.

-	 * 

-	 * @return a mapping between ModelingUnits and the validation informations related to the createdElements

-	 */

-	public EList<CompilationStatus> getCompilationStatusList() {

-		return this.statusManager.getCompilationStatusList();

-	}

-

-	/**

-	 * Registers the given compilationException as a new CompilationStatus.

-	 * 

-	 * @param compilationException

-	 *            the compilation Exception to register

-	 */

-	public void registerCompilationExceptionAsCompilationStatus(CompilationException compilationException) {

-

-		EList<CompilationStatus> compilationStatusList = new BasicEList<CompilationStatus>();

-

-		// Step 1 : we convert each the CompilationException in a CompilationStatus

-		CompilationStatus newStatus = CompilerFactory.eINSTANCE.createCompilationStatus();

-		newStatus.setMessage(compilationException.getMessage());

-		newStatus.setSeverity(CompilationStatusConverter

-				.createStatusSeverityFromCompilationExceptionErrorType(compilationException.getType()));

-		newStatus.setType(CompilationStatusConverter

-				.createStatusTypeFromCompilationExceptionErrorType(compilationException.getType()));

-		newStatus.setTarget(compilationException.getInvalidInstruction());

-

-		// and add this status to the diagnostic list.

-		compilationStatusList.add(newStatus);

-

-		// Step 2 : we register the new Diagnostics in the informationHolder

-		addStatusListToInformationHolder(

-				getModelingUnitForInstruction(compilationException.getInvalidInstruction()),

-				compilationStatusList);

-	}

-

-	/**

-	 * Register the given diagnostic for the given generatedElement as a new CompilationStatus.

-	 * 

-	 * @param generatedElement

-	 *            the generatedElement containing diagnostic errors

-	 * @param diagnostic

-	 *            the diagnostic to register

-	 */

-	public void registerDiagnosticAsCompilationStatusList(EObject generatedElement, Diagnostic diagnostic) {

-		EList<CompilationStatus> compilationStatusList = new BasicEList<CompilationStatus>();

-		for (Diagnostic subDiagnostic : diagnostic.getChildren()) {

-			// Step 1 : we convert each sub-diagnostic in a CompilationStatus

-			CompilationStatus newStatus = CompilerFactory.eINSTANCE.createCompilationStatus();

-			newStatus.setMessage(subDiagnostic.getMessage());

-			newStatus.setSeverity(CompilationStatusConverter

-					.createStatusSeverityFromDiagnosticSeverity(subDiagnostic));

-			newStatus.setType(CompilationMessageType.VALIDATION_ERROR);

-			newStatus.setTarget(this.getInstanciationInstructionByCreatedElement(generatedElement));

-

-			// and add this status to the diagnostic list.

-			compilationStatusList.add(newStatus);

-		}

-

-		// Step 2 : we register the new Diagnostics in the informationHolder

-		addStatusListToInformationHolder(

-				getModelingUnitForInstruction(getInstanciationInstructionByCreatedElement(generatedElement)),

-				compilationStatusList);

-

-	}

-

-	/**

-	 * Adds the given list of compilation status to the global status list and the map

-	 * ModelingUnitToStatusList.

-	 * 

-	 * @param unit

-	 *            the modeling unit containing the given status list

-	 * @param compilationStatusList

-	 *            the list of status to add

-	 */

-	private void addStatusListToInformationHolder(ModelingUnit unit,

-			EList<CompilationStatus> compilationStatusList) {

-		if (unit != null) {

-			// First in the general Status List

-			this.statusManager.getCompilationStatusList().addAll(compilationStatusList);

-

-			// Then in the ModelingUnit to StatusList map.

-			if (this.statusManager.getModelingUnitToStatusList().get(unit) == null) {

-				this.statusManager.getModelingUnitToStatusList().put(unit,

-						new BasicEList<CompilationStatus>());

-			}

-			this.statusManager.getModelingUnitToStatusList().get(unit).addAll(compilationStatusList);

-		}

-	}

-

-	/**

-	 * Returns the modeling unit associated to the given instruction.

-	 * 

-	 * @param instruction

-	 *            the instruction to inspect

-	 * @return the modeling unit associated to the given instruction

-	 */

-	private ModelingUnit getModelingUnitForInstruction(UnitInstruction instruction) {

-		ModelingUnit foundModelingUnit = null;

-		if (instruction != null) {

-

-			foundModelingUnit = (ModelingUnit)instruction.getUnit();

-			UnitInstruction parentInstruction = instruction;

-

-			while (foundModelingUnit == null) {

-				parentInstruction = (UnitInstruction)parentInstruction.eContainer();

-				if (parentInstruction != null) {

-					foundModelingUnit = (ModelingUnit)parentInstruction.getUnit();

-				} else {

-					foundModelingUnit = null;

-				}

-			}

-		}

-		return foundModelingUnit;

-	}

-

-	/**

-	 * Add to the mapping between textual reference and contribution instructions the given contribution

-	 * instruction.

-	 * 

-	 * @param instanceTextualReference

-	 *            The textual reference to the contributed instance

-	 * @param contributionInstruction

-	 *            the contribution instruction to add to the unresolvedCOntribution.

-	 */

-	public void addUnresolvedContribution(String instanceTextualReference,

-			ContributionInstruction contributionInstruction) {

-		if (this.informationHolder.getUnresolvedContributions().get(instanceTextualReference) == null) {

-			this.informationHolder.getUnresolvedContributions().put(instanceTextualReference,

-					new BasicEList<UnresolvedContributionHolder>());

-		}

-

-		if (!isRegisteredUnresolvedContribution(contributionInstruction)) {

-			UnresolvedContributionHolder holder = CompilerFactory.eINSTANCE

-					.createUnresolvedContributionHolder();

-			holder.setResolved(false);

-			holder.setReferencedContribution(contributionInstruction);

-

-			this.informationHolder.getUnresolvedContributions().get(instanceTextualReference).add(holder);

-		}

-	}

-

-	/**

-	 * Checks whether a contribution is registered or not.

-	 * 

-	 * @param contributionInstruction

-	 *            the contribution

-	 * @return true if the contribution is already registered as unresolved

-	 */

-	public boolean isRegisteredUnresolvedContribution(ContributionInstruction contributionInstruction) {

-		boolean isRegistered = false;

-		for (UnresolvedContributionHolder holder : this.informationHolder.getUnresolvedContributions().get(

-				contributionInstruction.getContributionReference().getIntentHref())) {

-			isRegistered = isRegistered || (holder.getReferencedContribution() == contributionInstruction);

-		}

-		return isRegistered;

-	}

-

-	/**

-	 * Sets the given contribution instruction as resolved (i.e. remove it from its

-	 * unresolvedContributionHolder) ; if the unresolvedContributionHolder associated to the textual reference

-	 * is empty, we remove it from the map.

-	 * 

-	 * @param contributionInstruction

-	 *            the contributionInstruction to consider as resolved.

-	 */

-	public void setContributionInstructionAsResolved(ContributionInstruction contributionInstruction) {

-		for (UnresolvedContributionHolder holder : informationHolder.getUnresolvedContributions().get(

-				contributionInstruction.getContributionReference().getIntentHref())) {

-

-			if (holder.getReferencedContribution() == contributionInstruction) {

-				holder.setResolved(true);

-			}

-		}

-		referenceContributionInstruction(contributionInstruction);

-	}

-

-}

+/*******************************************************************************
+ * Copyright (c) 2010, 2011 Obeo.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * 
+ * Contributors:
+ *     Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.docs.intent.client.compiler.utils;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.emf.common.util.BasicEList;
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.mylyn.docs.intent.client.compiler.errors.CompilationException;
+import org.eclipse.mylyn.docs.intent.client.compiler.errors.InvalidValueException;
+import org.eclipse.mylyn.docs.intent.core.compiler.CompilationInformationHolder;
+import org.eclipse.mylyn.docs.intent.core.compiler.CompilationMessageType;
+import org.eclipse.mylyn.docs.intent.core.compiler.CompilationStatus;
+import org.eclipse.mylyn.docs.intent.core.compiler.CompilationStatusManager;
+import org.eclipse.mylyn.docs.intent.core.compiler.CompilerFactory;
+import org.eclipse.mylyn.docs.intent.core.compiler.StringToEObjectMap;
+import org.eclipse.mylyn.docs.intent.core.compiler.UnresolvedContributionHolder;
+import org.eclipse.mylyn.docs.intent.core.compiler.UnresolvedReferenceHolder;
+import org.eclipse.mylyn.docs.intent.core.genericunit.UnitInstruction;
+import org.eclipse.mylyn.docs.intent.core.modelingunit.ContributionInstruction;
+import org.eclipse.mylyn.docs.intent.core.modelingunit.InstanciationInstruction;
+import org.eclipse.mylyn.docs.intent.core.modelingunit.ModelingUnit;
+import org.eclipse.mylyn.docs.intent.core.modelingunit.ModelingUnitInstruction;
+import org.eclipse.mylyn.docs.intent.core.modelingunit.ResourceDeclaration;
+
+/**
+ * Class storing all the informations that can be needed by any entity of the compilation process.
+ * 
+ * @author <a href="mailto:alex.lagarde@obeo.fr">Alex Lagarde</a>
+ */
+public final class IntentCompilerInformationHolder {
+
+	/**
+	 * Current instance of the information Holder (singleton).
+	 */
+	private static IntentCompilerInformationHolder currentInstance;
+
+	/**
+	 * The informationHolder used to store informations.
+	 */
+	private CompilationInformationHolder informationHolder;
+
+	/**
+	 * List of the currentImportedPackages.
+	 */
+	private List<String> currentImportedPackages;
+
+	private CompilationStatusManager statusManager;
+
+	/**
+	 * IntentCompilerInformationHolder constructor.
+	 */
+	private IntentCompilerInformationHolder() {
+		this.informationHolder = CompilerFactory.eINSTANCE.createCompilationInformationHolder();
+	}
+
+	/**
+	 * Returns the current instance of the information Holder (singleton).
+	 * 
+	 * @return the current instance of the information Holder (singleton)
+	 */
+	public static IntentCompilerInformationHolder getInstance() {
+		if (currentInstance == null) {
+			currentInstance = new IntentCompilerInformationHolder();
+		}
+		return currentInstance;
+	}
+
+	/**
+	 * Initialize this IntentCompilerInformationHolder by clearing all informations.
+	 */
+	public void initialize() {
+		informationHolder = CompilerFactory.eINSTANCE.createCompilationInformationHolder();
+
+		if (statusManager == null) {
+			statusManager = CompilerFactory.eINSTANCE.createCompilationStatusManager();
+		} else {
+			statusManager.getCompilationStatusList().clear();
+			statusManager.getModelingUnitToStatusList().clear();
+		}
+	}
+
+	public CompilationStatusManager getStatusManager() {
+		return statusManager;
+	}
+
+	/**
+	 * Add the given element to the current created element list.
+	 * 
+	 * @param instruction
+	 *            the instruction that declared this element
+	 * @param createdElement
+	 *            the element to register
+	 */
+	public void addCreatedElementsToCurrentList(UnitInstruction instruction, EObject createdElement) {
+		if (createdElement != null) {
+			this.getCurrentCreatedElements().add(createdElement);
+			BasicEList<UnitInstruction> unitInstructions = new BasicEList<UnitInstruction>();
+			unitInstructions.add(instruction);
+			this.informationHolder.getCreatedElementsToInstructions().put(createdElement, unitInstructions);
+		}
+	}
+
+	/**
+	 * Resolves the contributed instanciation instruction.
+	 * 
+	 * @param contributionInstruction
+	 *            the contribution instruction
+	 */
+	private void referenceContributionInstruction(ContributionInstruction contributionInstruction) {
+		if (contributionInstruction.getContributionReference() != null
+				&& contributionInstruction.getContributionReference().getReferencedInstruction() != null) {
+
+			Iterator<Entry<EObject, EList<UnitInstruction>>> entryIterator = this.informationHolder
+					.getCreatedElementsToInstructions().entrySet().iterator();
+			ModelingUnitInstruction targetInstanciationInstruction = contributionInstruction
+					.getContributionReference().getReferencedInstruction();
+			boolean instanciationInstructionFound = false;
+			while (entryIterator.hasNext() && !instanciationInstructionFound) {
+				Entry<EObject, EList<UnitInstruction>> entry = entryIterator.next();
+				if (entry.getValue().contains(targetInstanciationInstruction)) {
+					entry.getValue().add(contributionInstruction);
+					instanciationInstructionFound = true;
+				}
+			}
+		}
+	}
+
+	/**
+	 * Returns the instruction that declared the given element.
+	 * 
+	 * @param createdElement
+	 *            the element to inspect
+	 * @return the instruction that declared the given element
+	 */
+	public UnitInstruction getInstanciationInstructionByCreatedElement(EObject createdElement) {
+		if (this.informationHolder.getCreatedElementsToInstructions().get(createdElement) != null) {
+			return this.informationHolder.getCreatedElementsToInstructions().get(createdElement).iterator()
+					.next();
+		}
+		return null;
+	}
+
+	/**
+	 * Returns the instruction related to the given element.
+	 * 
+	 * @param createdElement
+	 *            the created element
+	 * @return the related instructions
+	 */
+	public Collection<UnitInstruction> getAllInstructionsByCreatedElement(EObject createdElement) {
+		return this.informationHolder.getCreatedElementsToInstructions().get(createdElement);
+	}
+
+	/**
+	 * Returns all the Instanciation instructions that have a non-null name (e.g new EClass e1 {}).
+	 * 
+	 * @return all the instanciation instructions that have a non-null name (e.g new EClass e1 {})
+	 */
+	public Set<UnitInstruction> getAllInstanciationsInstructions() {
+		return Sets.newLinkedHashSet(Iterables.filter(
+				Iterables.concat(this.informationHolder.getCreatedElementsToInstructions().values()),
+				new Predicate<UnitInstruction>() {
+
+					public boolean apply(UnitInstruction instruction) {
+						return instruction instanceof InstanciationInstruction
+								&& ((InstanciationInstruction)instruction).getName() != null;
+					}
+				}));
+	}
+
+	/**
+	 * Returns the object associated to the given name (used for resolving reference).
+	 * 
+	 * @param type
+	 *            the type of the researched element.
+	 * @param name
+	 *            Name of the searched object.
+	 * @return the object associated to the given name
+	 */
+	public Object getCreatedInstanceByName(EClassifier type, String name) {
+		Object createdInstance = null;
+		if (type != null) {
+			return this.informationHolder.getTypeToNameToElementsMap().get(type).getNameToElement().get(name);
+		} else {
+			// If type is null we search this instance for any type
+			for (EClassifier possibleType : this.informationHolder.getTypeToNameToElementsMap().keySet()) {
+				createdInstance = this.informationHolder.getTypeToNameToElementsMap().get(possibleType)
+						.getNameToElement().get(name);
+				if (createdInstance != null) {
+					break;
+				}
+			}
+			return createdInstance;
+		}
+	}
+
+	/**
+	 * Add the given resource (which is empty) to the map.
+	 * 
+	 * @param resource
+	 *            the resource to map with the given element
+	 */
+	public void addResource(ResourceDeclaration resource) {
+		if (this.informationHolder.getResourceToContainedElements().get(resource) == null) {
+			this.informationHolder.getResourceToContainedElements().put(resource, new BasicEList<EObject>());
+		}
+	}
+
+	/**
+	 * Add the given generated element to the given resource's content list.
+	 * 
+	 * @param resource
+	 *            the resource to map with the given element
+	 * @param newContainedElement
+	 *            the element to map with the given resource
+	 */
+	public void addResourceToGeneratedElementMapping(ResourceDeclaration resource, EObject newContainedElement) {
+		if (this.informationHolder.getResourceToContainedElements().get(resource) == null) {
+			this.informationHolder.getResourceToContainedElements().put(resource, new BasicEList<EObject>());
+		}
+		this.informationHolder.getResourceToContainedElements().get(resource).add(newContainedElement);
+
+	}
+
+	/**
+	 * Returns the declared resources.
+	 * 
+	 * @return the declared resources.
+	 */
+	public Set<ResourceDeclaration> getDeclaredResources() {
+		return this.informationHolder.getResourceToContainedElements().keySet();
+	}
+
+	/**
+	 * Returns the given's resource content (generated elements).
+	 * 
+	 * @param resource
+	 *            the resource to inspect
+	 * @return the given's resource content (generated elements)
+	 */
+	public EList<EObject> getResourceContent(ResourceDeclaration resource) {
+		return this.informationHolder.getResourceToContainedElements().get(resource);
+	}
+
+	/**
+	 * Add to the unresolvedReference list of the given element the given referenceHolder.
+	 * 
+	 * @param generatedElement
+	 *            the element that contains the unresolved reference to add
+	 * @param referenceHolder
+	 *            the referenceHolder containing the feature containing the unresolved reference and the
+	 *            textual value of it
+	 */
+	public void addUnresolvedReference(EObject generatedElement, UnresolvedReferenceHolder referenceHolder) {
+		if (this.informationHolder.getElementToUnresolvedReferenceMap().get(generatedElement) == null) {
+			this.informationHolder.getElementToUnresolvedReferenceMap().put(generatedElement,
+					new BasicEList<UnresolvedReferenceHolder>());
+		}
+		this.informationHolder.getElementToUnresolvedReferenceMap().get(generatedElement)
+				.add(referenceHolder);
+	}
+
+	/**
+	 * Returns a list containing the unresolved references for the given element.
+	 * 
+	 * @param elementContainingUnresolvedReference
+	 *            the element to inspect
+	 * @return a list containing the unresolved references for the given element
+	 */
+	public EList<UnresolvedReferenceHolder> getUnresolvedReferencesByGeneratedElement(
+			EObject elementContainingUnresolvedReference) {
+		EList<UnresolvedReferenceHolder> unresolvedRefs = this.informationHolder
+				.getElementToUnresolvedReferenceMap().get(elementContainingUnresolvedReference);
+		if (unresolvedRefs == null) {
+			unresolvedRefs = new BasicEList<UnresolvedReferenceHolder>();
+		}
+		return unresolvedRefs;
+	}
+
+	/**
+	 * Sets the list of current imported packages (URIs form).
+	 * 
+	 * @param importedPackages
+	 *            the list of current imported packages (URIs form)
+	 */
+	public void setCurrentImportedPackages(List<String> importedPackages) {
+		this.currentImportedPackages = importedPackages;
+	}
+
+	/**
+	 * Returns the list of current imported packages (URIs form).
+	 * 
+	 * @return the list of current imported packages (URIs form)
+	 */
+	public List<String> getCurrentImportedPackages() {
+		return currentImportedPackages;
+	}
+
+	public List<EObject> getCurrentCreatedElements() {
+		return this.informationHolder.getCurrentGeneratedElementList();
+	}
+
+	/**
+	 * Try to add the given createdElement identified by the given name ; throws an exception if an element
+	 * has already been registered with this name.
+	 * 
+	 * @param name
+	 *            name (identifier) of the element to register
+	 * @param createdElement
+	 *            the createdElement
+	 * @param instruction
+	 *            the instruction that declared this element
+	 */
+	public void addNameToCreatedElementEntry(String name, EObject createdElement,
+			InstanciationInstruction instruction) {
+		if (name != null) {
+			StringToEObjectMap nameToElement = this.informationHolder.getTypeToNameToElementsMap().get(
+					createdElement.eClass());
+			if (nameToElement == null) {
+				nameToElement = CompilerFactory.eINSTANCE.createStringToEObjectMap();
+				this.informationHolder.getTypeToNameToElementsMap().put(createdElement.eClass(),
+						nameToElement);
+			}
+
+			// If an element has already been registered with this name
+			if (nameToElement.getNameToElement().get(name) != null) {
+				throw new InvalidValueException(instruction, "The name " + name
+						+ " has already been used to identify an element.");
+			}
+
+			// Otherwise, we register the given element
+			nameToElement.getNameToElement().put(name, createdElement);
+		}
+		this.addCreatedElementsToCurrentList(instruction, createdElement);
+	}
+
+	/**
+	 * Checks if a contribution is unresolved.
+	 * 
+	 * @param contributionInstruction
+	 *            the contribution instruction
+	 * @return true if the contribution can be resolved
+	 */
+	public boolean isUnresolvedContribution(ContributionInstruction contributionInstruction) {
+		boolean isUnresolved = this.informationHolder.getUnresolvedContributions().get(
+				contributionInstruction.getContributionReference().getIntentHref()) == null;
+		if (!isUnresolved) {
+			isUnresolved = true;
+			for (UnresolvedContributionHolder holder : this.informationHolder.getUnresolvedContributions()
+					.get(contributionInstruction.getContributionReference().getIntentHref())) {
+				if (holder.getReferencedContribution() == contributionInstruction) {
+					isUnresolved = isUnresolved && !holder.isResolved();
+				}
+			}
+		}
+		return isUnresolved;
+	}
+
+	/**
+	 * Returns the unresolved contributions associated to the contributed element matching the given name.
+	 * 
+	 * @param contributedElementName
+	 *            the element name
+	 * @return the unresolved contributions
+	 */
+	public EList<UnresolvedContributionHolder> getContributionsAssociatedTo(String contributedElementName) {
+		if (this.informationHolder.getUnresolvedContributions().get(contributedElementName) != null) {
+			return new BasicEList<UnresolvedContributionHolder>(this.informationHolder
+					.getUnresolvedContributions().get(contributedElementName));
+
+		}
+		return new BasicEList<UnresolvedContributionHolder>();
+	}
+
+	/**
+	 * Return the list of unresolved contribution instructions for the element with the given name.
+	 * 
+	 * @param contributedElementName
+	 *            the name of the element that is associated with unresolved contribution exceptions.
+	 * @return the list of unresolved contribution instructions for the element with the given name
+	 */
+	public EList<UnresolvedContributionHolder> getUnresolvedContributions(String contributedElementName) {
+
+		if (this.informationHolder.getUnresolvedContributions().get(contributedElementName) != null) {
+			return this.informationHolder.getUnresolvedContributions().get(contributedElementName);
+		}
+		return new BasicEList<UnresolvedContributionHolder>();
+	}
+
+	/**
+	 * Returns the textual reference that remained unresolved for contribution instructions.
+	 * 
+	 * @return the textual reference that remained unresolved for contribution instructions
+	 */
+	public Set<String> getAllUnresolvedContributionsNames() {
+		return this.informationHolder.getUnresolvedContributions().keySet();
+	}
+
+	/**
+	 * returns the validation informations related to the createdElements.
+	 * 
+	 * @return a mapping between ModelingUnits and the validation informations related to the createdElements
+	 */
+	public EList<CompilationStatus> getCompilationStatusList() {
+		return this.statusManager.getCompilationStatusList();
+	}
+
+	/**
+	 * Registers the given compilationException as a new CompilationStatus.
+	 * 
+	 * @param compilationException
+	 *            the compilation Exception to register
+	 */
+	public void registerCompilationExceptionAsCompilationStatus(CompilationException compilationException) {
+
+		EList<CompilationStatus> compilationStatusList = new BasicEList<CompilationStatus>();
+
+		// Step 1 : we convert each the CompilationException in a CompilationStatus
+		CompilationStatus newStatus = CompilerFactory.eINSTANCE.createCompilationStatus();
+		newStatus.setMessage(compilationException.getMessage());
+		newStatus.setSeverity(CompilationStatusConverter
+				.createStatusSeverityFromCompilationExceptionErrorType(compilationException.getType()));
+		newStatus.setType(CompilationStatusConverter
+				.createStatusTypeFromCompilationExceptionErrorType(compilationException.getType()));
+		newStatus.setTarget(compilationException.getInvalidInstruction());
+
+		// and add this status to the diagnostic list.
+		compilationStatusList.add(newStatus);
+
+		// Step 2 : we register the new Diagnostics in the informationHolder
+		addStatusListToInformationHolder(
+				getModelingUnitForInstruction(compilationException.getInvalidInstruction()),
+				compilationStatusList);
+	}
+
+	/**
+	 * Register the given diagnostic for the given generatedElement as a new CompilationStatus.
+	 * 
+	 * @param generatedElement
+	 *            the generatedElement containing diagnostic errors
+	 * @param diagnostic
+	 *            the diagnostic to register
+	 */
+	public void registerDiagnosticAsCompilationStatusList(EObject generatedElement, Diagnostic diagnostic) {
+		EList<CompilationStatus> compilationStatusList = new BasicEList<CompilationStatus>();
+		for (Diagnostic subDiagnostic : diagnostic.getChildren()) {
+			// Step 1 : we convert each sub-diagnostic in a CompilationStatus
+			CompilationStatus newStatus = CompilerFactory.eINSTANCE.createCompilationStatus();
+			newStatus.setMessage(subDiagnostic.getMessage());
+			newStatus.setSeverity(CompilationStatusConverter
+					.createStatusSeverityFromDiagnosticSeverity(subDiagnostic));
+			newStatus.setType(CompilationMessageType.VALIDATION_ERROR);
+			newStatus.setTarget(this.getInstanciationInstructionByCreatedElement(generatedElement));
+
+			// and add this status to the diagnostic list.
+			compilationStatusList.add(newStatus);
+		}
+
+		// Step 2 : we register the new Diagnostics in the informationHolder
+		addStatusListToInformationHolder(
+				getModelingUnitForInstruction(getInstanciationInstructionByCreatedElement(generatedElement)),
+				compilationStatusList);
+
+	}
+
+	/**
+	 * Adds the given list of compilation status to the global status list and the map
+	 * ModelingUnitToStatusList.
+	 * 
+	 * @param unit
+	 *            the modeling unit containing the given status list
+	 * @param compilationStatusList
+	 *            the list of status to add
+	 */
+	private void addStatusListToInformationHolder(ModelingUnit unit,
+			EList<CompilationStatus> compilationStatusList) {
+		if (unit != null) {
+			// First in the general Status List
+			this.statusManager.getCompilationStatusList().addAll(compilationStatusList);
+
+			// Then in the ModelingUnit to StatusList map.
+			if (this.statusManager.getModelingUnitToStatusList().get(unit) == null) {
+				this.statusManager.getModelingUnitToStatusList().put(unit,
+						new BasicEList<CompilationStatus>());
+			}
+			this.statusManager.getModelingUnitToStatusList().get(unit).addAll(compilationStatusList);
+		}
+	}
+
+	/**
+	 * Returns the modeling unit associated to the given instruction.
+	 * 
+	 * @param instruction
+	 *            the instruction to inspect
+	 * @return the modeling unit associated to the given instruction
+	 */
+	private ModelingUnit getModelingUnitForInstruction(UnitInstruction instruction) {
+		ModelingUnit foundModelingUnit = null;
+		if (instruction != null) {
+
+			foundModelingUnit = (ModelingUnit)instruction.getUnit();
+			UnitInstruction parentInstruction = instruction;
+
+			while (foundModelingUnit == null) {
+				parentInstruction = (UnitInstruction)parentInstruction.eContainer();
+				if (parentInstruction != null) {
+					foundModelingUnit = (ModelingUnit)parentInstruction.getUnit();
+				} else {
+					foundModelingUnit = null;
+				}
+			}
+		}
+		return foundModelingUnit;
+	}
+
+	/**
+	 * Add to the mapping between textual reference and contribution instructions the given contribution
+	 * instruction.
+	 * 
+	 * @param instanceTextualReference
+	 *            The textual reference to the contributed instance
+	 * @param contributionInstruction
+	 *            the contribution instruction to add to the unresolvedCOntribution.
+	 */
+	public void addUnresolvedContribution(String instanceTextualReference,
+			ContributionInstruction contributionInstruction) {
+		if (this.informationHolder.getUnresolvedContributions().get(instanceTextualReference) == null) {
+			this.informationHolder.getUnresolvedContributions().put(instanceTextualReference,
+					new BasicEList<UnresolvedContributionHolder>());
+		}
+
+		if (!isRegisteredUnresolvedContribution(contributionInstruction)) {
+			UnresolvedContributionHolder holder = CompilerFactory.eINSTANCE
+					.createUnresolvedContributionHolder();
+			holder.setResolved(false);
+			holder.setReferencedContribution(contributionInstruction);
+
+			this.informationHolder.getUnresolvedContributions().get(instanceTextualReference).add(holder);
+		}
+	}
+
+	/**
+	 * Checks whether a contribution is registered or not.
+	 * 
+	 * @param contributionInstruction
+	 *            the contribution
+	 * @return true if the contribution is already registered as unresolved
+	 */
+	public boolean isRegisteredUnresolvedContribution(ContributionInstruction contributionInstruction) {
+		boolean isRegistered = false;
+		for (UnresolvedContributionHolder holder : this.informationHolder.getUnresolvedContributions().get(
+				contributionInstruction.getContributionReference().getIntentHref())) {
+			isRegistered = isRegistered || (holder.getReferencedContribution() == contributionInstruction);
+		}
+		return isRegistered;
+	}
+
+	/**
+	 * Sets the given contribution instruction as resolved (i.e. remove it from its
+	 * unresolvedContributionHolder) ; if the unresolvedContributionHolder associated to the textual reference
+	 * is empty, we remove it from the map.
+	 * 
+	 * @param contributionInstruction
+	 *            the contributionInstruction to consider as resolved.
+	 */
+	public void setContributionInstructionAsResolved(ContributionInstruction contributionInstruction) {
+		for (UnresolvedContributionHolder holder : informationHolder.getUnresolvedContributions().get(
+				contributionInstruction.getContributionReference().getIntentHref())) {
+
+			if (holder.getReferencedContribution() == contributionInstruction) {
+				holder.setResolved(true);
+			}
+		}
+		referenceContributionInstruction(contributionInstruction);
+	}
+
+}
diff --git a/plugins/org.eclipse.mylyn.docs.intent.client.synchronizer/src/org/eclipse/mylyn/docs/intent/client/synchronizer/synchronizer/IntentSynchronizer.java b/plugins/org.eclipse.mylyn.docs.intent.client.synchronizer/src/org/eclipse/mylyn/docs/intent/client/synchronizer/synchronizer/IntentSynchronizer.java
index 6d0e2bf..29b341c 100644
--- a/plugins/org.eclipse.mylyn.docs.intent.client.synchronizer/src/org/eclipse/mylyn/docs/intent/client/synchronizer/synchronizer/IntentSynchronizer.java
+++ b/plugins/org.eclipse.mylyn.docs.intent.client.synchronizer/src/org/eclipse/mylyn/docs/intent/client/synchronizer/synchronizer/IntentSynchronizer.java
@@ -39,7 +39,6 @@
 import org.eclipse.mylyn.docs.intent.client.synchronizer.strategy.SynchronizerStrategy;
 import org.eclipse.mylyn.docs.intent.collab.common.logger.IIntentLogger.LogType;
 import org.eclipse.mylyn.docs.intent.collab.common.logger.IntentLogger;
-import org.eclipse.mylyn.docs.intent.collab.handlers.adapters.IntentCommand;
 import org.eclipse.mylyn.docs.intent.collab.handlers.adapters.RepositoryAdapter;
 import org.eclipse.mylyn.docs.intent.compare.utils.EMFCompareUtils;
 import org.eclipse.mylyn.docs.intent.core.compiler.CompilationMessageType;
@@ -250,14 +249,8 @@
 		if (internalResource == null) {
 			final List<Resource> result = new ArrayList<Resource>();
 			final Resource finalExternalResource = externalResource;
-			adapter.execute(new IntentCommand() {
-
-				public void execute() {
-					result.add(synchronizerStrategy.handleNullInternalResource(
-							indexEntry.getGeneratedResourcePath(), finalExternalResource));
-
-				}
-			});
+			result.add(synchronizerStrategy.handleNullInternalResource(indexEntry.getGeneratedResourcePath(),
+					finalExternalResource));
 			if (!result.isEmpty()) {
 				internalResource = result.get(0);
 			}
@@ -268,18 +261,12 @@
 		if (externalResource == null) {
 			final List<Resource> result = new ArrayList<Resource>();
 			final Resource finalInternalResource = internalResource;
-			adapter.execute(new IntentCommand() {
-
-				public void execute() {
-					Resource handleNullExternalResource = synchronizerStrategy.handleNullExternalResource(
-							indexEntry.getResourceDeclaration(), finalInternalResource, (String)indexEntry
-									.getResourceDeclaration().getUri());
-					if (handleNullExternalResource != null) {
-						result.add(handleNullExternalResource);
-					}
-
-				}
-			});
+			Resource handleNullExternalResource = synchronizerStrategy.handleNullExternalResource(indexEntry
+					.getResourceDeclaration(), finalInternalResource, (String)indexEntry
+					.getResourceDeclaration().getUri());
+			if (handleNullExternalResource != null) {
+				result.add(handleNullExternalResource);
+			}
 			if (!result.isEmpty()) {
 				externalResource = result.get(0);
 			} else {
diff --git a/plugins/org.eclipse.mylyn.docs.intent.collab.ide/src/org/eclipse/mylyn/docs/intent/collab/ide/adapters/WorkspaceAdapter.java b/plugins/org.eclipse.mylyn.docs.intent.collab.ide/src/org/eclipse/mylyn/docs/intent/collab/ide/adapters/WorkspaceAdapter.java
index 53736d7..42fd16b 100644
--- a/plugins/org.eclipse.mylyn.docs.intent.collab.ide/src/org/eclipse/mylyn/docs/intent/collab/ide/adapters/WorkspaceAdapter.java
+++ b/plugins/org.eclipse.mylyn.docs.intent.collab.ide/src/org/eclipse/mylyn/docs/intent/collab/ide/adapters/WorkspaceAdapter.java
@@ -41,6 +41,7 @@
 import org.eclipse.emf.ecore.xmi.impl.XMLParserPoolImpl;
 import org.eclipse.emf.transaction.RecordingCommand;
 import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.impl.InternalTransactionalEditingDomain;
 import org.eclipse.mylyn.docs.intent.collab.handlers.adapters.IntentCommand;
 import org.eclipse.mylyn.docs.intent.collab.handlers.adapters.ReadOnlyException;
 import org.eclipse.mylyn.docs.intent.collab.handlers.adapters.RepositoryAdapter;
@@ -613,16 +614,31 @@
 	 * @see org.eclipse.mylyn.docs.intent.collab.handlers.adapters.RepositoryAdapter#execute(org.eclipse.mylyn.docs.intent.collab.handlers.adapters.IntentCommand)
 	 */
 	public void execute(final IntentCommand command) {
+		// Step 1: create a recording command encapsulating the Intent command
 		final TransactionalEditingDomain editingDomain = repository.getEditingDomain();
-		RecordingCommand recordingCommand = new RecordingCommand(editingDomain) {
+		final RecordingCommand recordingCommand = new RecordingCommand(editingDomain) {
 			@Override
 			protected void doExecute() {
 				command.execute();
 			}
 		};
-		// first we check that the repository has not been disposed
+
+		// Step 2: make sure a command is not already running
 		final CommandStack commandStack = editingDomain.getCommandStack();
+		// Check that the repository has not been disposed
 		if (commandStack != null) {
+			// Check that change recorder is not already recording
+			long timeout = System.currentTimeMillis();
+			while (((InternalTransactionalEditingDomain)editingDomain).getChangeRecorder().isRecording()
+					&& System.currentTimeMillis() < timeout + 15000) {
+				try {
+					Thread.sleep(TIME_TO_WAIT_BEFORE_CHECKING_SESSIONDELTA);
+				} catch (InterruptedException e) {
+					// Command will be executed
+				}
+			}
+
+			// Step 3: execute command
 			try {
 				commandStack.execute(recordingCommand);
 			} catch (NullPointerException e) {
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/repository/IntentURITest.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/repository/IntentURITest.java
index ab18e92..e629895 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/repository/IntentURITest.java
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/unit/repository/IntentURITest.java
@@ -42,7 +42,6 @@
 	public void testIntentURIHandlerOnIntentDocument() {
 		setUpIntentProject("intentProject", "data/unit/documents/scenario/abstract_resources.intent");
 		ResourceSetImpl rs = new ResourceSetImpl();
-		waitForCompiler();
 
 		// Check 1: URI like intent:/intentProject should return a Resource containing the intent document
 		URI intentDocumentResourceURI = URI.createURI("intent:/intentProject");
@@ -115,4 +114,14 @@
 		}
 	}
 
+	/**
+	 * {@inheritDoc}
+	 * 
+	 * @see org.eclipse.mylyn.docs.intent.client.ui.test.util.AbstractIntentUITest#additionalSetUpOperations()
+	 */
+	@Override
+	protected void additionalSetUpOperations() {
+		waitForCompiler();
+		waitForSynchronizer();
+	}
 }
diff --git a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/RepositoryListenerForTests.java b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/RepositoryListenerForTests.java
index 284f188..82ce1ff 100644
--- a/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/RepositoryListenerForTests.java
+++ b/tests/org.eclipse.mylyn.docs.intent.client.ui.test/src/org/eclipse/mylyn/docs/intent/client/ui/test/util/RepositoryListenerForTests.java
@@ -120,17 +120,23 @@
 	 * Waits for a message sent by the given client. Returns true if the message was sent, false if it did not

 	 * after a certain delay.

 	 * 

+	 * @param shouldBeNotified

+	 *            if client is expected to be notified

 	 * @param clientIdentifier

 	 *            the client identifier (e.g. "Indexer", "Compiler")

 	 * @return true if the message was sent by the expected client, false if it did not after a certain delay

 	 */

-	public boolean waitForModificationOn(String clientIdentifier) {

+	public boolean waitForModificationOn(boolean shouldBeNotified, String clientIdentifier) {

 		long startTime = System.currentTimeMillis();

 		boolean timeOutDetected = false;

+		long timeOutDelay = TIME_OUT_DELAY;

+		if (shouldBeNotified) {

+			timeOutDelay = timeOutDelay * 4;

+		}

 		try {

 			while (!hasReceivedMessage(clientIdentifier) && !timeOutDetected) {

 				Thread.sleep(WAITING_STEP_DELAY);

-				timeOutDetected = System.currentTimeMillis() - startTime > TIME_OUT_DELAY;

+				timeOutDetected = System.currentTimeMillis() - startTime > timeOutDelay;

 			}

 			Thread.sleep(WAITING_STEP_DELAY);

 			return !timeOutDetected;