package com.temenos.interaction.rimdsl.scoping;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.naming.IQualifiedNameProvider.AbstractImpl;
import org.eclipse.xtext.naming.QualifiedName;

import com.temenos.interaction.rimdsl.rim.DomainDeclaration;
import com.temenos.interaction.rimdsl.rim.Event;
import com.temenos.interaction.rimdsl.rim.ResourceInteractionModel;

/**
 * IRIS QualifiedNameProvider.
 * 
 * Don't use the DefaultDeclarativeQualifiedNameProvider, as its polymorphic
 * thing seems to be a slower (measured), and its cache seems to have memory
 * impacts; simply coding this out explicit/clear seems to be better.
 * 
 * @see http://www.eclipse.org/Xtext/documentation.html#scoping
 * 
 * @author Michael Vorburger
 */
public class RIMDslQualifiedNameProvider extends AbstractImpl {

	@Override
	public QualifiedName getFullyQualifiedName(EObject obj) {
		if (obj instanceof DomainDeclaration) {
			DomainDeclaration d = (DomainDeclaration) obj;
			return QualifiedName.create(d.getName());
		} else if (obj instanceof Event) {
			Event e = (Event) obj;
			ResourceInteractionModel parent = (ResourceInteractionModel) e.eContainer();
			return QualifiedName.create(parent.getName(), e.getName());
		// TODO more ... } else if (obj instanceof Event) {
		}
		return null;
	}

}

@@ -197,16 +197,67 @@
 dName;%0A%0A
+import com.temenos.interaction.rimdsl.rim.Command;%0A
 import c
@@ -358,16 +358,68 @@
 .Event;%0A
+import com.temenos.interaction.rimdsl.rim.Relation;%0A
 import c
@@ -477,16 +477,65 @@
 onModel;
+%0Aimport com.temenos.interaction.rimdsl.rim.State;
 %0A%0A/**%0A *
@@ -1031,16 +1031,61 @@
  obj) %7B%0A
+%09%09QualifiedName partialQualifiedName = null;%0A
 %09%09if (ob
@@ -1245,42 +1245,35 @@
 eof 
-Event) %7B%0A%09%09%09Event e = (Event) obj;
+ResourceInteractionModel) %7B
 %0A%09%09%09
@@ -1297,22 +1297,17 @@
 onModel 
-parent
+r
  = (Reso
@@ -1332,144 +1332,856 @@
 el) 
-e.eContainer();%0A%09%09%09return QualifiedName.create(parent.getName(), e.getName());%0A%09%09// TODO more ... %7D else if (obj instanceof Event) %7B%0A%09%09%7D
+obj;%0A%09%09%09partialQualifiedName = QualifiedName.create(r.getName());%0A%09%09%7D else if (obj instanceof State) %7B%0A%09%09%09State s = (State) obj;%0A%09%09%09partialQualifiedName = QualifiedName.create(s.getName());%0A%09%09%7D else if (obj instanceof Event) %7B%0A%09%09%09Event e = (Event) obj;%0A%09%09%09return QualifiedName.create(e.getName());%0A%09%09%7D else if (obj instanceof Command) %7B%0A%09%09%09Command c = (Command) obj;%0A%09%09%09return QualifiedName.create(c.getName());%0A%09%09%7D else if (obj instanceof Relation) %7B%0A%09%09%09Relation r = (Relation) obj;%0A%09%09%09return QualifiedName.create(r.getName());%0A%09%09%7D%0A%09%09%0A%09%09if (partialQualifiedName != null) %7B%0A%09%09%09EObject temp = obj;%0A%09%09%09while (temp.eContainer() != null) %7B%0A%09%09%09%09temp = temp.eContainer();%0A%09%09%09%09QualifiedName parentsQualifiedName = getFullyQualifiedName(temp);%0A%09%09%09%09if (parentsQualifiedName != null)%0A%09%09%09%09%09return parentsQualifiedName.append(partialQualifiedName);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09
 %0A%09%09r

Fix / complete implementation for RIMDslQualifiedNameProvider; closes #88