package hu.bme.mit.mondo.integration.incquery.hawk;

import org.apache.log4j.Logger;
import org.eclipse.incquery.runtime.api.IncQueryEngine;
import org.eclipse.incquery.runtime.api.scope.IBaseIndex;
import org.eclipse.incquery.runtime.api.scope.IEngineContext;
import org.eclipse.incquery.runtime.exception.IncQueryException;
import org.eclipse.incquery.runtime.matchers.context.IQueryRuntimeContext;

import uk.ac.york.mondo.integration.api.Hawk.Client;

public class HawkEngineContext implements IEngineContext {

	protected HawkScope hawkScope;
	protected HawkQueryRuntimeContext<?> hawkQueryRuntimeContext;

	protected IncQueryEngine engine;
	protected Logger logger;
	protected Client client;

	public HawkEngineContext(final HawkScope hawkScope, final IncQueryEngine engine, final Logger logger, final Client client) {
		this.hawkScope = hawkScope;
		this.client = client;
	}

	// TODO: Marton should have a look at this (no initializeBackends method anymore in IEngineContext?)

//	@Override
//	public void initializeBackends(final IQueryBackendInitializer initializer) throws IncQueryException {
//		HawkResource hawkResource = null;
//		outer: for (final Notifier notifier : hawkScope.getScopeRoots()) {
//			if (notifier instanceof HawkResource) {
//				hawkResource = (HawkResource) notifier;
//				break;
//			}
//
//			if (notifier instanceof ResourceSet) {
//				for (final Resource resource : ((ResourceSet) notifier).getResources()) {
//					if (resource instanceof HawkResource) {
//						hawkResource = (HawkResource) resource;
//						break outer;
//					}
//				}
//			}
//		}
//		if (hawkResource == null) {
//			final String msg = "Could not find a HawkResource in the HawkScope.";
//			throw new IncQueryException(msg, msg);
//		}
//
//		if (hawkQueryRuntimeContext == null) {
//			hawkQueryRuntimeContext = new HawkQueryRuntimeContext<>(hawkResource, logger);
//			initializer.initializeWith(hawkQueryRuntimeContext);
//		}
//	}

	@Override
	public IBaseIndex getBaseIndex() throws IncQueryException {
		return new HawkBaseIndex();
	}

	@Override
	public void dispose() {
		if (hawkQueryRuntimeContext != null) {
			hawkQueryRuntimeContext.dispose();
		}

		this.engine = null;
		this.logger = null;
	}

	@Override
	public IQueryRuntimeContext getQueryRuntimeContext() throws IncQueryException {
		return hawkQueryRuntimeContext;
	}

}

@@ -78,16 +78,162 @@
 Logger;%0A
+import org.eclipse.emf.common.notify.Notifier;%0Aimport org.eclipse.emf.ecore.resource.Resource;%0Aimport org.eclipse.emf.ecore.resource.ResourceSet;%0A
 import o
@@ -480,70 +480,37 @@
 org.
-eclipse.incquery.runtime.matchers.context.IQueryRuntimeContext
+hawk.emfresource.HawkResource
 ;%0A%0Ai
@@ -993,113 +993,8 @@
 %09%7D%0A%0A
-%09// TODO: Marton should have a look at this (no initializeBackends method anymore in IEngineContext?)%0A%0A//
 %09@Ov
@@ -1000,18 +1000,16 @@
 verride%0A
-//
 %09public 
@@ -1103,18 +1103,16 @@
 ption %7B%0A
-//
 %09%09HawkRe
@@ -1139,18 +1139,16 @@
 = null;%0A
-//
 %09%09outer:
@@ -1208,18 +1208,16 @@
 ts()) %7B%0A
-//
 %09%09%09if (n
@@ -1247,26 +1247,24 @@
 Resource) %7B%0A
-//
 %09%09%09%09hawkReso
@@ -1291,26 +1291,24 @@
 ) notifier;%0A
-//
 %09%09%09%09break;%0A/
@@ -1310,20 +1310,14 @@
 ak;%0A
-//
 %09%09%09%7D%0A
-//%0A//
+%0A
 %09%09%09i
@@ -1350,26 +1350,24 @@
 ourceSet) %7B%0A
-//
 %09%09%09%09for (fin
@@ -1428,26 +1428,24 @@
 ources()) %7B%0A
-//
 %09%09%09%09%09if (res
@@ -1477,18 +1477,16 @@
 urce) %7B%0A
-//
 %09%09%09%09%09%09ha
@@ -1523,18 +1523,16 @@
 source;%0A
-//
 %09%09%09%09%09%09br
@@ -1546,40 +1546,30 @@
 er;%0A
-//
 %09%09%09%09%09%7D%0A
-//
 %09%09%09%09%7D%0A
-//
 %09%09%09%7D%0A
-//
 %09%09%7D%0A
-//
 %09%09if
@@ -1594,18 +1594,16 @@
 null) %7B%0A
-//
 %09%09%09final
@@ -1667,18 +1667,16 @@
 cope.%22;%0A
-//
 %09%09%09throw
@@ -1713,19 +1713,13 @@
 g);%0A
-//
 %09%09%7D%0A
-//%0A//
+%0A
 %09%09if
@@ -1755,18 +1755,16 @@
 null) %7B%0A
-//
 %09%09%09hawkQ
@@ -1837,18 +1837,16 @@
 ogger);%0A
-//
 %09%09%09initi
@@ -1897,16 +1897,12 @@
 t);%0A
-//
 %09%09%7D%0A
-//
 %09%7D%0A%0A
@@ -2179,136 +2179,6 @@
 %09%7D%0A%0A
-%09@Override%0A%09public IQueryRuntimeContext getQueryRuntimeContext() throws IncQueryException %7B%0A%09%09return hawkQueryRuntimeContext;%0A%09%7D%0A%0A
 %7D%0A

fix compilation after new IQ update site