use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class TestDiscoveryHelper method collectTests.
private TestTree collectTests(final ResourceSet resSet, final IResourceDescriptions index, final URI... locations) {
// create test cases (aggregated in test suites)
final List<TestSuite> suites = newArrayList();
// create MultiMap from trimmed(!) URI -> original URIs for this prefix URI
final List<URI> testLocations = collectDistinctTestLocations(index, resSet, locations);
final HashMultimap<URI, URI> testLocationMapping = createTestLocationMapping(testLocations);
final Map<URI, TModule> moduleUri2Modules = loadModules(testLocationMapping.asMap().keySet(), index, resSet);
for (final URI moduleLocation : testLocationMapping.keys()) {
final TModule module = moduleUri2Modules.get(moduleLocation);
if (null == module) {
// Assuming broken AST.
continue;
}
// make sure trimmed URIs processed before non-trimmed ones, in other words we collects all tests for
// test modules first, then later we can skip individual test collecting for test methods.
// so we can make sure, iff there are more than one elements in the list, and the first one equals to
// the module location URI (with any fragments), we can skip the processing, since the whole module
// contains the individual test locations
final List<URI> testLocationsForModule = newArrayList(testLocationMapping.get(moduleLocation));
testLocationsForModule.sort(URI_COMPARATOR);
if (testLocationsForModule.get(0).equals(moduleLocation)) {
// The first item is referencing the entire module
// --> collect all test methods in module and ignore remaining URIs
suites.addAll(collectSuitsForModule(module));
} else {
// we have URIs pointing to individual test methods -> collect all URIs
for (final URI uri : testLocationsForModule) {
suites.addAll(collectSuitsForMethod(uri, module));
}
}
}
// TODO what should be the name of the test tree is multiple test locations are available?
// Improve the way how we got the name of the test tree.
final ID sessionId = createTestSessionId();
String name = valueOf(sessionId);
if (locations.length > 0) {
final URI uri = locations[0];
name = valueOf(uri.trimFragment()).replaceFirst("platform:/resource/", "");
// name = name.replace("." + N4JS_FILE_EXTENSION, "");
if (name.lastIndexOf('.') > 0) {
name = name.substring(0, name.lastIndexOf('.'));
}
// Assuming one single test case.
if (uri.hasFragment() && !suites.isEmpty() && !suites.get(0).getTestCases().isEmpty()) {
name = name + "#" + suites.get(0).getTestCases().get(0).getDisplayName();
}
}
return new TestTree(sessionId, suites, name);
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class TestDiscoveryHelper method loadModules.
private Map<URI, TModule> loadModules(final Iterable<URI> moduleUris, final IResourceDescriptions index, final ResourceSet resSet) {
final Map<URI, TModule> uri2Modules = newHashMap();
for (final URI moduleUri : moduleUris) {
final IResourceDescription resDesc = index.getResourceDescription(moduleUri);
uri2Modules.put(moduleUri, n4jsCore.loadModuleFromIndex(resSet, resDesc, false));
}
return uri2Modules;
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class N4JSDirtyStateEditorSupport method equalDescriptions.
private boolean equalDescriptions(IEObjectDescription newDescription, IEObjectDescription oldDescription, URI uri) {
if (!newDescription.getQualifiedName().equals(oldDescription.getQualifiedName())) {
return false;
}
if (!newDescription.getEClass().equals(oldDescription.getEClass())) {
return false;
}
if (!newDescription.getEObjectURI().equals(oldDescription.getEObjectURI())) {
return false;
}
if (TypesPackage.Literals.TMODULE == newDescription.getEClass()) {
String newModule = newDescription.getUserData(UserdataMapper.USERDATA_KEY_SERIALIZED_SCRIPT);
String oldModule = oldDescription.getUserData(UserdataMapper.USERDATA_KEY_SERIALIZED_SCRIPT);
if (newModule == null || oldModule == null) {
return true;
}
if (!newModule.equals(oldModule)) {
TModule newModuleObj = UserdataMapper.getDeserializedModuleFromDescription(newDescription, uri);
TModule oldModuleObj = UserdataMapper.getDeserializedModuleFromDescription(oldDescription, uri);
// we deserialize the TModules and ignore the MD5 Hash
newModuleObj.setAstMD5("");
oldModuleObj.setAstMD5("");
if (!EcoreUtilN4.equalsNonResolving(newModuleObj, oldModuleObj)) {
return false;
}
}
}
// todo compare user data if module
return true;
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class ModuleNamespaceVirtualTypeImpl method setModule.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setModule(TModule newModule) {
TModule oldModule = module;
module = newModule;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, TypesPackage.MODULE_NAMESPACE_VIRTUAL_TYPE__MODULE, oldModule, module));
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class ImportDeclarationImpl method setModule.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setModule(TModule newModule) {
TModule oldModule = module;
module = newModule;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.IMPORT_DECLARATION__MODULE, oldModule, module));
}
Aggregations