use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class N4JSResource method unloadAST.
/**
* Unloads the AST, but leaves the type model intact. Calling this method puts this resource into the same state as
* if it was loaded from the index.
*
* <ul>
* <li>The AST is discarded and all references to it are proxified.</li>
* <li>The parse result (node model) is set to <code>null</code>.</li>
* <li>All errors and warnings are cleared.</li>
* <li>The flags are set as follows:
* <ul>
* <li><code>reconciled</code> is <code>false</code></li>
* <li><code>fullyInitialized</code> remains unchanged</li>
* <li><code>fullyPostProcessed</code> is set to the same value as <code>fullyInitialized</code></li>
* <li><code>aboutToBeUnloaded</code> is <code>false</code></li>
* <li><code>isInitializing</code> is <code>false</code></li>
* <li><code>isLoading</code> is <code>false</code></li>
* <li><code>isLoaded</code> is <code>false</code></li>
* <li><code>isPostProcessing</code> is <code>false</code></li>
* <li><code>isUpdating</code> is <code>false</code></li>
* <li><code>isLoadedFromStorage</code> is unchanged due to API restrictions</li>
* </ul>
* </li>
* <li>Finally, all lazy proxy information is cleared by calling {@link #clearLazyProxyInformation()}.</li>
* </ul>
* Calling this method takes the resources either to the same state as if it was just created, or to the same state
* as if it was just loaded from a resource description, depending on which state the resource is in.
* <ul>
* <li>If the resource was just <b>created</b>, then it will remain so.</li>
* <li>If the resource was <b>loaded</b>, then it will be taken back to the <b>created</b> state.</li>
* <li>If the resource was <b>initialized</b>, then it will be taken to the <b>loaded from description</b>
* state.</li>
* <li>If the resource was <b>fully processed</b>, then it will be taken to the <b>loaded from description</b>
* state.</li>
* <li>If the resource was <b>loaded from description</b>, then it will remain so.</li>
* </ul>
*/
public void unloadAST() {
if (getScript() == null || getScript().eIsProxy()) {
// have an AST proxy.
return;
}
// Discard AST and proxify all references.
discardAST();
// Discard the parse result (node model).
setParseResult(null);
// Clear errors and warnings.
getErrors().clear();
getWarnings().clear();
fullyPostProcessed = fullyInitialized;
aboutToBeUnloaded = false;
isInitializing = false;
isLoading = false;
isLoaded = false;
isPostProcessing = false;
isUpdating = false;
// We cannot call this method because it is not API. We leave this comment as documentation that the flag
// isLoadedFromStorage should be false at this point.
// setIsLoadedFromStorage(false);
// These are cleared when linking takes place., but we eagerly clear them here as a memory optimization.
clearLazyProxyInformation();
// clear flag 'reconciled' in TModule (if required)
final TModule module = getModule();
if (module != null && module.isReconciled()) {
EcoreUtilN4.doWithDeliver(false, () -> {
module.setReconciled(false);
}, module);
}
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class N4JSResource method discardAST.
/**
* Discard the AST and proxify all referenced nodes. Does nothing if the AST is already unloaded.
*/
private void discardAST() {
EObject script = getScript();
if (script != null && !script.eIsProxy()) {
// Create a proxy for the AST.
InternalEObject scriptProxy = (InternalEObject) EcoreUtil.create(script.eClass());
scriptProxy.eSetProxyURI(EcoreUtil.getURI(script));
TModule module = null;
ModuleAwareContentsList theContents = (ModuleAwareContentsList) contents;
if (isFullyInitialized()) {
module = getModule();
if (module != null && !module.eIsProxy()) {
proxifyASTReferences(module);
module.setAstElement(scriptProxy);
}
}
// Unload the AST.
unloadElements(theContents.subList(0, 1));
theContents.sneakyClear();
if (module != null) {
theContents.sneakyAdd(scriptProxy);
theContents.sneakyAdd(module);
} else {
// there was no module (not even a proxy)
// -> don't add the script proxy
// (i.e. transition from resource load state "Loaded" to "Created", not to "Loaded from Description")
}
// Clear AST meta cache and Xtext cache
this.setASTMetaInfoCache(null);
getCache().clear(this);
}
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class UserdataMapper method getDeserializedModuleFromDescriptionAsString.
/**
* <b>ONLY INTENDED FOR TESTS OR DEBUGGING. DON'T USE IN PRODUCTION CODE.</b>
* <p>
* Same as {@link #getDeserializedModuleFromDescription(IEObjectDescription, URI)}, but always returns the module as
* an XMI-serialized string.
*/
public static String getDeserializedModuleFromDescriptionAsString(IEObjectDescription eObjectDescription, URI uri) throws IOException {
final TModule module = getDeserializedModuleFromDescription(eObjectDescription, uri);
final XMIResource resourceForUserData = new XMIResourceImpl(uri);
resourceForUserData.getContents().add(module);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
resourceForUserData.save(baos, getOptions(uri, false));
return baos.toString(TRANSFORMATION_CHARSET_NAME);
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class MemberVisibilityChecker method isVisible.
/**
* Returns the MemberVisibility of the <i>member</i> of the <i>receiverType</> in the given <i>context</i>
* <i>supercall</i> indicates if the target of the context is the super type.
*/
private MemberVisibility isVisible(EObject context, TypeRef receiverType, TMember member, boolean supercall) {
// special case: union types
if (receiverType instanceof UnionTypeExpression) {
// because we use the combined accessibility for all members
for (TypeRef currUnitedTypeRef : ((UnionTypeExpression) receiverType).getTypeRefs()) if (!isVisible(context, currUnitedTypeRef, member, supercall).visibility)
return new MemberVisibility(false);
return new MemberVisibility(true);
}
// standard case:
Resource contextResource = context.eResource();
N4TypeDefinition typeDefiningContainer = EcoreUtil2.getContainerOfType(context, N4TypeDefinition.class);
Script script = EcoreUtil2.getContainerOfType(typeDefiningContainer != null ? typeDefiningContainer : context, Script.class);
Type contextType = null;
TModule contextModule = script.getModule();
if (typeDefiningContainer != null) {
contextType = typeDefiningContainer.getDefinedType();
}
Type declaredReceiverType = getActualDeclaredReceiverType(context, receiverType, contextResource.getResourceSet());
if (declaredReceiverType != null && typeVisibilityChecker.isVisible(contextResource, declaredReceiverType).visibility) {
// check for local usage of locally defined member
if (shortcutIsVisible(member, contextType, contextModule, declaredReceiverType)) {
return new MemberVisibility(true);
}
return isVisible(contextModule, contextType, declaredReceiverType, member, supercall);
}
return new MemberVisibility(false);
}
use of org.eclipse.n4js.ts.types.TModule in project n4js by eclipse.
the class N4JSPostProcessor method exposeReferencedInternalTypes.
/**
* Moves all types contained in 'internalTypes' to 'exposedInternalTypes' that are referenced from any top level
* type or a variable.
*/
private static void exposeReferencedInternalTypes(N4JSResource res) {
final TModule module = res.getModule();
if (module == null) {
return;
}
// reset, i.e. make all exposed types internal again
module.getInternalTypes().addAll(module.getExposedInternalTypes());
// move internal types to exposedInternalTypes if referenced from topLevelTypes or variables
final List<EObject> stuffToScan = new ArrayList<>();
stuffToScan.addAll(module.getTopLevelTypes());
stuffToScan.addAll(module.getVariables());
for (EObject currRoot : stuffToScan) {
exposeTypesReferencedBy(currRoot);
}
}
Aggregations