Search in sources :

Example 1 with MemberAccess

use of org.eclipse.n4js.n4JS.MemberAccess 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;
}
Also used : MemberAccess(org.eclipse.n4js.n4JS.MemberAccess) N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) N4JSResource(org.eclipse.n4js.resource.N4JSResource) ComposedMemberCache(org.eclipse.n4js.ts.types.ComposedMemberCache) TModule(org.eclipse.n4js.ts.types.TModule)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)1 MemberAccess (org.eclipse.n4js.n4JS.MemberAccess)1 N4JSResource (org.eclipse.n4js.resource.N4JSResource)1 ComposedMemberCache (org.eclipse.n4js.ts.types.ComposedMemberCache)1 TModule (org.eclipse.n4js.ts.types.TModule)1