def HashMap<String, HashMap<JSONObject, DeclarationInstance>> getVariablesMappings() {
		var HashMap<String, HashMap<JSONObject, DeclarationInstance>> map_var_job_cdi = new HashMap<String, HashMap<JSONObject, DeclarationInstance>>()
		val ArrayList<JSONObject> fiacreVariablesAsJsonObjects = new ArrayList<JSONObject>
		// Get all json objects of vars from the mappings
		// TODO why just flatten doesn't work
		for (element : ( mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof DeclarationInstance].values.map[value|(value as JSONObject).get("vars")])) {
			for (jelement : element as JSONArray) {
				fiacreVariablesAsJsonObjects.add(jelement as JSONObject)
			}
		}
		println("allJsonVariableValues "+fiacreVariablesAsJsonObjects)
		// for each value element generated in the dynamic json 
		// for example "Process_1_vx" = 5 
		for (element : fiacreVariablesAsJsonObjects.map[jvv|jvv.get("flatname")].toSet) {

			// this if allows to eliminate added variables by frac like Main_w1
			if(fiacreVariablesAsJsonObjects.filter[a|a.get("flatname") == element].size > 0) {
				
				// json_object_var is the concerned json object corresponding to the a fiacre variable
				// It may be possible that there is many json_object_var that have the same name 
				// like the fp variable in the clock2.fcr  
				for (json_object_var : fiacreVariablesAsJsonObjects.filter[a|a.get("flatname") == element]) {
					var ArrayList<DeclarationInstance> decls = new ArrayList<DeclarationInstance>
					for (decl : mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof DeclarationInstance].filter [ p1, p2 |
						((p2 as JSONObject).get("vars") as JSONArray).contains(json_object_var)].keySet) 
					{
						decls.add(decl as DeclarationInstance)
					}
					if (decls.filter[decl|decl.variableDeclarationInstances.map[vdi|vdi.variableDeclaration].exists[v|v.name==json_object_var.get("sourcename")]].size>0){
						var HashMap<JSONObject, DeclarationInstance> map = new HashMap<JSONObject, DeclarationInstance>()
						println("declaration instances "+decls.filter[decl|decl.variableDeclarationInstances.map[vdi|vdi.variableDeclaration].exists[v|v.name==json_object_var.get("sourcename")]])
						map.put(json_object_var,decls.filter[decl|decl.variableDeclarationInstances.map[vdi|vdi.variableDeclaration].exists[v|v.name==json_object_var.get("sourcename")]].get(0))
						map_var_job_cdi.put(element as String, map)
					}
				}
			}
		}
		map_var_job_cdi
	}

def extractdoc(XtextResource xtextResource) {

		val Injector injector = FiacreActivator.getInstance().getInjector("fr.irit.fiacre.xtext.Fiacre")

		System.out.println("resource" + xtextResource);

		val IURIEditorOpener editorOpener = injector.getInstance(IURIEditorOpener)
		val XtextEditor xtextEditor = editorOpener.open(xtextResource.URI, true) as XtextEditor
		println("editor 2" + xtextEditor)
		val XtextDocument xtextDocument = xtextEditor.document as XtextDocument
//		System.out.println("document " + xtextDocument);
//		for (var i = 0; i < xtextDocument.getNumberOfLines(); i++) {
//			try {
//				println("getLineLength " + i + " " + xtextDocument.getLineLength(i))
//				println("getLineOffset " + i + " " + xtextDocument.getLineOffset(i))
//			} catch(BadLocationException e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//		}
		val EObjectAtOffsetHelper eObjectAtOffsetHelper = injector.getInstance(EObjectAtOffsetHelper)
		for (var i = 0; i < xtextDocument.getLength(); i++) {
			try {
				val EObject object = eObjectAtOffsetHelper.resolveElementAt(xtextResource, i)
				val EObject object2 = eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, i)
				val EObject object3 = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(xtextResource, i)
				val int line = xtextDocument.getLineOfOffset(i)
				val int column = (i - xtextDocument.getLineOffset(xtextDocument.getLineOfOffset(i)))

				println("----- ")
				print("o " + i + " offset " + xtextDocument.getOffset(line, column))
				print(" (l " + line + " ")
				print("c " + column + ") ")
				print("(el = " + (line + 1) + ", ")
				println("ec = " + (column + 1) + ") ")
				println("object " + object)
				println("cross " + object3)
				println("contained " + object2)
				println("containerStatement " + getStatement(object2))

			} catch(BadLocationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		/*
		 * It exists two kinds of transitions
		 * Global transitions: which can be find in the json model root
		 * and Instance transitions which can be find in the process instances
		 * So from global transitions, we must find the instance transitions
		 * to obtain, after, the locations for each transition 
		 */
		// Get global transitions from the json model
		val JSONArray global_transitions = fiacreStaticJson.get("gtransitions") as JSONArray

		// Get all Instance transitions from the mapping
		val ArrayList<JSONObject> allInstanceTransitions = new ArrayList<JSONObject>()
		for (element : ( mapping.filter[p1, p2|p1 instanceof ProcessDeclarationInstance].values.map[value|(value as JSONObject).get("transitions")])) {
			for (jelement : element as JSONArray) {
				allInstanceTransitions.add(jelement as JSONObject)
			}
		}
		// for each global transition name (a_global_tr_name)
		for (a_global_tr_name : global_transitions.map[agtr|(agtr as JSONObject).get("name")]) {

			// Get the corresponding json object (a_g_tr_jobject) from the global transitions array list
			val JSONObject a_g_tr_jobject = global_transitions.filter[gtr|(gtr as JSONObject).get("name") == a_global_tr_name].get(0) as JSONObject
			println(a_global_tr_name + " " + a_g_tr_jobject)

			// for each instance transition name find in the transitions array of the global transition object
			for (a_i_tr_name : a_g_tr_jobject.get("transitions") as JSONArray) {

				// Get the instance transition object (a_i_tr_jobject)
				val JSONObject a_i_tr_jobject = allInstanceTransitions.filter[aatr|(aatr as JSONObject).get("name") == a_i_tr_name].get(0)

				// Get the Process Declaration Instance that contains the instance transition object (a_i_tr_jobject)
				val c_pdi = mapping.filter[p1, p2|p1 instanceof ProcessDeclarationInstance].filter[p1, p2|((p2 as JSONObject).get("transitions") as JSONArray).contains(a_i_tr_jobject)].keySet.get(0);
				println("process instance " + c_pdi)
				println("tr in process " + a_i_tr_jobject)

				// Get locations of each instance transition
				println("locations " + (a_i_tr_jobject as JSONObject).get("locations"))
				//
				for (a_location_jsonobject : (a_i_tr_jobject as JSONObject).get("locations") as JSONArray) {
					val JSONObject from_location = (a_location_jsonobject as JSONObject).get("from") as JSONObject
					val long line_from = from_location.get("line") as Long
					val long char_from = from_location.get("char") as Long
					val int offset_from = xtextDocument.getOffset(line_from.intValue, char_from.intValue)

					println(line_from + " " + char_from + " " + offset_from)
					val JSONObject to_location = (a_location_jsonobject as JSONObject).get("to") as JSONObject
					val long line_to = to_location.get("line") as Long
					val long char_to = to_location.get("char") as Long
					val int offset_to = xtextDocument.getOffset(line_to.intValue, char_to.intValue)
					println(line_to + " " + char_to + " " + offset_to)
					for (var int i = offset_from; i <= offset_to; i++) {
						val int line = xtextDocument.getLineOfOffset(i)
						val int column = (i - xtextDocument.getLineOffset(xtextDocument.getLineOfOffset(i)))

						val statement = eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, i).getStatement
						if(statement instanceof TransitionSource || statement.isAtomicStatement)
							println("(" + line + ", " + column + ") " + "(" + (line + 1) + ", " + (column + 1) + ") " + statement)
					}
				}
				println(" ")
			}
			println("---")
		}
	}