/*
Copyright (c) 2016, Rockwell Collins.
Developed with the sponsorship of Defense Advanced Research Projects Agency (DARPA).

Permission is hereby granted, free of charge, to any person obtaining a copy of this data, 
including any software or models in source or binary form, as well as any drawings, specifications, 
and documentation (collectively "the Data"), to deal in the Data without restriction, including
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, 
and/or sell copies of the Data, and to permit persons to whom the Data is furnished to do so, 
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or 
substantial portions of the Data.

THE DATA IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT 
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
IN NO EVENT SHALL THE AUTHORS, SPONSORS, DEVELOPERS, CONTRIBUTORS, OR COPYRIGHT HOLDERS BE LIABLE 
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 
ARISING FROM, OUT OF OR IN CONNECTION WITH THE DATA OR THE USE OR OTHER DEALINGS IN THE DATA.
*/

package com.rockwellcollins.atc.tcg.util;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.osate.aadl2.Classifier;
import org.osate.aadl2.ComponentImplementation;
import org.osate.xtext.aadl2.properties.util.EMFIndexRetrieval;

import com.rockwellcollins.atc.tcg.TcgException;

public class TcgUtils {

	public static String getNestedMessages(Throwable e) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		while (e != null) {
			if (e.getMessage() != null && !e.getMessage().isEmpty()) {
				pw.println(e.getMessage());
			}
			e = e.getCause();
		}
		pw.close();
		return sw.toString();
	}

	public static ComponentImplementation getComponentImplFromString(String qualifiedName) {
		Classifier cl = EMFIndexRetrieval.getClassifierInWorkspace(qualifiedName);
		if (cl instanceof ComponentImplementation) {
			return (ComponentImplementation)cl;
		} else {
			throw new TcgException("Error: test suite implementation under test: [" + qualifiedName + "] does not correspond to any " + 
		     "system implementation in the workspace.\n");
		}
	}
}

@@ -17,9 +17,9 @@
  201
-6
+8
 , Ro
@@ -210,17 +210,16 @@
 is data,
- 
 %0Aincludi
@@ -310,17 +310,16 @@
 cations,
- 
 %0Aand doc
@@ -498,17 +498,16 @@
 license,
- 
 %0Aand/or 
@@ -592,17 +592,16 @@
 o do so,
- 
 %0Asubject
@@ -719,17 +719,16 @@
 opies or
- 
 %0Asubstan
@@ -852,17 +852,16 @@
  BUT NOT
- 
 %0ALIMITED
@@ -952,17 +952,16 @@
 NGEMENT.
- 
 %0AIN NO E
@@ -1050,17 +1050,16 @@
 E LIABLE
- 
 %0AFOR ANY
@@ -1146,17 +1146,16 @@
 HERWISE,
- 
 %0AARISING
@@ -1345,16 +1345,119 @@
 Writer;%0A
+import java.util.HashSet;%0A%0Aimport org.eclipse.core.resources.IFile;%0Aimport org.osate.aadl2.AadlPackage;
 %0Aimport 
@@ -1553,52 +1553,73 @@
 ate.
-xtext.aadl2.properties.util.EMFIndexRetrieva
+aadl2.ModelUnit;%0Aimport org.osate.aadl2.modelsupport.util.AadlUti
 l;%0A%0A
@@ -2112,67 +2112,415 @@
 %7B%0A%09%09
-Classifier cl = EMFIndexRetrieval.getClassifierInWorkspace(
+HashSet%3CIFile%3E files = org.osate.aadl2.modelsupport.modeltraversal.TraverseWorkspace.getAadlFilesInWorkspace();%0A%09%09for (IFile file : files) %7B%0A%09%09%09ModelUnit target = (ModelUnit) AadlUtil.getElement(file);%0A%09%09%09if (target instanceof AadlPackage) %7B%0A%09%09%09%09Classifier cl = org.osate.aadl2.modelsupport.scoping.Aadl2GlobalScopeUtil.get(target,%0A%09%09%09%09%09%09org.osate.aadl2.Aadl2Package.eINSTANCE.getComponentImplementation(), 
 qual
@@ -2531,16 +2531,18 @@
 dName);%0A
+%09%09
 %09%09if (cl
@@ -2583,16 +2583,18 @@
 n) %7B%0A%09%09%09
+%09
+%09
 return (
@@ -2621,24 +2621,28 @@
 ion)
+ 
 cl;%0A%09%09
-%7D else %7B%0A%09
+%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A
 %09%09th
@@ -2726,17 +2726,21 @@
 fiedName
- 
+%0A%09%09%09%09
 + %22%5D doe
@@ -2771,16 +2771,8 @@
 %22 + 
-%0A%09%09     
 %22sys
@@ -2813,17 +2813,13 @@
 e.%5Cn%22);%0A
-%09%09%7D%0A
 %09%7D%0A%7D%0A

Replace use of deprecated EMFIndexRetrieval in TCG