Search in sources :

Example 26 with TModule

use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.

the class ExportDeclarationImpl method setReexportedFrom.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setReexportedFrom(TModule newReexportedFrom) {
    TModule oldReexportedFrom = reexportedFrom;
    reexportedFrom = newReexportedFrom;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.EXPORT_DECLARATION__REEXPORTED_FROM, oldReexportedFrom, reexportedFrom));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) TModule(org.eclipse.n4js.ts.types.TModule)

Example 27 with TModule

use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.

the class AbstractN4JSCore method loadModuleFromIndex.

@Override
public TModule loadModuleFromIndex(final ResourceSet resourceSet, final IResourceDescription resourceDescription, boolean allowFullLoad) {
    final URI resourceURI = resourceDescription.getURI();
    Resource resource = resourceSet.getResource(resourceURI, false);
    if (resource instanceof N4JSResource) {
        final N4JSResource resourceCasted = (N4JSResource) resource;
        final Script existingScript = resourceCasted.getScript();
        final TModule existingModule = resourceCasted.getModule();
        if (existingModule != null) {
            // -> simply return that
            return existingModule;
        } else if (existingScript != null && !existingScript.eIsProxy()) {
            // resource exists already and it already has its AST loaded (though no TModule yet)
            // -> we have to create the TModule from that AST instead of loading it from index
            // trigger installation of derived state (i.e. types builder)
            resourceCasted.installDerivedState(false);
            return resourceCasted.getModule();
        }
    }
    if (resource == null) {
        resource = resourceSet.createResource(resourceURI);
    }
    if (resource instanceof N4JSResource) {
        if (resource.getContents().isEmpty()) {
            final N4JSResource casted = (N4JSResource) resource;
            try {
                if (casted.loadFromDescription(resourceDescription)) {
                    casted.performPostProcessing();
                    return casted.getModule();
                } else if (allowFullLoad) {
                    casted.unload();
                    casted.load(resourceSet.getLoadOptions());
                    casted.installDerivedState(false);
                    return casted.getModule();
                }
            } catch (final Exception e) {
                casted.unload();
                return null;
            }
        }
    }
    return null;
}
Also used : Script(org.eclipse.n4js.n4JS.Script) N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) N4JSResource(org.eclipse.n4js.resource.N4JSResource) TModule(org.eclipse.n4js.ts.types.TModule) URI(org.eclipse.emf.common.util.URI)

Example 28 with TModule

use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.

the class N4JSPostProcessor method exposeType.

/**
 * If 'object' is a type or a constituent of a type (e.g. field of a class) in 'internalTypes', then move the type
 * to 'exposedInternalTypes'.
 */
private static void exposeType(Object object) {
    if (!(object instanceof EObject) || ((EObject) object).eIsProxy()) {
        return;
    }
    // object might not be a type but reside inside a type, e.g. field of a class
    // --> so search for the root, i.e. the ancestor directly below the TModule
    EObject rootTMP = (EObject) object;
    while (rootTMP != null && !(rootTMP.eContainer() instanceof TModule)) {
        rootTMP = rootTMP.eContainer();
    }
    // must be final for the lambda below
    final EObject root = rootTMP;
    if (root instanceof Type && root.eContainingFeature() == TypesPackage.eINSTANCE.getTModule_InternalTypes()) {
        final TModule module = (TModule) root.eContainer();
        EcoreUtilN4.doWithDeliver(false, () -> {
            module.getExposedInternalTypes().add((Type) root);
        }, module, // note: root already contained in resource, so suppress notifications also in root!
        root);
        // everything referenced by the type we just moved to 'exposedInternalTypes' has to be exposed as well
        // (this is required, for example, if 'root' is a structural type, see:
        // org.eclipse.n4js.xpect.ui.tests/testdata_ui/typesystem/structuralTypeRefWithMembersAcrossFiles/Main.n4js.xt)
        exposeTypesReferencedBy(root);
    }
}
Also used : Type(org.eclipse.n4js.ts.types.Type) EObject(org.eclipse.emf.ecore.EObject) TModule(org.eclipse.n4js.ts.types.TModule)

Example 29 with TModule

use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.

the class ResourceLoadingStatistics method countN4JSResourcesLoadedFromIndex.

private int countN4JSResourcesLoadedFromIndex(ResourceSet resSet) {
    int n = 0;
    for (Resource res : resSet.getResources()) {
        if (!isBuiltInResource(res)) {
            if (res instanceof N4JSResource) {
                final N4JSResource resCasted = (N4JSResource) res;
                final Script script = resCasted.getScript();
                final TModule module = resCasted.getModule();
                if (script != null && script.eIsProxy() && module != null && !module.eIsProxy()) {
                    n++;
                }
            }
        }
    }
    return n;
}
Also used : Script(org.eclipse.n4js.n4JS.Script) N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) N4JSResource(org.eclipse.n4js.resource.N4JSResource) TModule(org.eclipse.n4js.ts.types.TModule)

Example 30 with TModule

use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.

the class TestDiscoveryUIUtils method getLocationForEditorInput.

/**
 * Derives a location URI as expected by {@link TestDiscoveryHelper#collectTests(URI...)} from an editor input.
 */
public static final URI getLocationForEditorInput(IFileEditorInput fileEditorInput) {
    if (null == fileEditorInput) {
        return null;
    }
    final XtextEditor editor = getActiveEditor(XtextEditor.class).orNull();
    if (null != editor && fileEditorInput.equals(editor.getEditorInput())) {
        if (currentThread() == getDefault().getThread()) {
            // Iff accessed from the UI thread
            if (editor.getSelectionProvider().getSelection() instanceof ITextSelection) {
                final ITextSelection textSelection = (ITextSelection) editor.getSelectionProvider().getSelection();
                final EObject selectedElement = getSelectedElement(editor, textSelection);
                if (selectedElement instanceof N4MethodDeclaration) {
                    final N4MethodDeclaration method = (N4MethodDeclaration) selectedElement;
                    if (!method.eIsProxy() && TEST_METHOD.hasAnnotation(method)) {
                        final TModule module = N4JSResource.getModule(method.eResource());
                        if (null != module) {
                            return EcoreUtil.getURI(method);
                        }
                    }
                }
            }
        }
    }
    return getFileURI(fileEditorInput);
}
Also used : XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) EObject(org.eclipse.emf.ecore.EObject) N4MethodDeclaration(org.eclipse.n4js.n4JS.N4MethodDeclaration) TModule(org.eclipse.n4js.ts.types.TModule) ITextSelection(org.eclipse.jface.text.ITextSelection)

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