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));
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations