use of org.eclipse.n4js.ts.types.ComposedMemberCache in project n4js by eclipse.
the class ComposedMemberScope method getOrCreateComposedMemberCache.
/**
* Returns the composed member cache for the given ComposedTypeRef, creating it if it does not exist yet. Returns
* <code>null</code> if a cache could not be created, because the given type reference is not contained in an
* N4JSResource or this resource does not have a TModule.
*/
private ComposedMemberCache getOrCreateComposedMemberCache() {
if (request.provideContainedMembers) {
final //
MemberAccess contextCasted = // cast is valid, see MemberScopeRequest#provideContainedMembers
(MemberAccess) request.context;
final ComposedMemberCache cache = contextCasted.getComposedMemberCache();
if (cache != null && TypeCompareUtils.isEqual(cache.getComposedTypeRef(), this.composedTypeRef)) {
return cache;
}
// does not exist yet -> create new composed member cache in TModule:
final Resource res = contextCasted.eResource();
final TModule module = res instanceof N4JSResource ? ((N4JSResource) res).getModule() : null;
if (module != null) {
// Search in the module for composed member cache containing equivalent composed type ref
for (ComposedMemberCache existingCache : module.getComposedMemberCaches()) {
if (TypeCompareUtils.isEqual(existingCache.getComposedTypeRef(), composedTypeRef)) {
return existingCache;
}
}
final ComposedMemberCache cacheNew = TypesFactory.eINSTANCE.createComposedMemberCache();
EcoreUtilN4.doWithDeliver(false, () -> {
// Order important due to notification!
cacheNew.setComposedTypeRef(TypeUtils.copyIfContained(composedTypeRef));
module.getComposedMemberCaches().add(cacheNew);
contextCasted.setComposedMemberCache(cacheNew);
}, module, contextCasted);
return cacheNew;
}
}
return null;
}
Aggregations