Search in sources :

Example 21 with TModule

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);
}
Also used : TestSuite(org.eclipse.n4js.tester.domain.TestSuite) ID(org.eclipse.n4js.tester.domain.ID) UUID.randomUUID(java.util.UUID.randomUUID) TModule(org.eclipse.n4js.ts.types.TModule) URI(org.eclipse.emf.common.util.URI) TestTree(org.eclipse.n4js.tester.domain.TestTree)

Example 22 with TModule

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;
}
Also used : IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) TModule(org.eclipse.n4js.ts.types.TModule) URI(org.eclipse.emf.common.util.URI)

Example 23 with TModule

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;
}
Also used : TModule(org.eclipse.n4js.ts.types.TModule)

Example 24 with TModule

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));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) TModule(org.eclipse.n4js.ts.types.TModule)

Example 25 with TModule

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));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) TModule(org.eclipse.n4js.ts.types.TModule)

Aggregations

TModule (org.eclipse.n4js.ts.types.TModule)48 EObject (org.eclipse.emf.ecore.EObject)12 Resource (org.eclipse.emf.ecore.resource.Resource)8 URI (org.eclipse.emf.common.util.URI)7 Type (org.eclipse.n4js.ts.types.Type)7 TMember (org.eclipse.n4js.ts.types.TMember)6 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)5 InternalEObject (org.eclipse.emf.ecore.InternalEObject)4 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)4 Script (org.eclipse.n4js.n4JS.Script)4 IN4JSProject (org.eclipse.n4js.projectModel.IN4JSProject)4 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)4 N4JSResource (org.eclipse.n4js.resource.N4JSResource)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 CoreException (org.eclipse.core.runtime.CoreException)2 XMIResource (org.eclipse.emf.ecore.xmi.XMIResource)2 XMIResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)2 ImportDeclaration (org.eclipse.n4js.n4JS.ImportDeclaration)2 ContainerType (org.eclipse.n4js.ts.types.ContainerType)2