Search in sources :

Example 1 with ComposedMemberCache

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

the class IndexedAccessExpressionImpl method setComposedMemberCache.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setComposedMemberCache(ComposedMemberCache newComposedMemberCache) {
    ComposedMemberCache oldComposedMemberCache = composedMemberCache;
    composedMemberCache = newComposedMemberCache;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.INDEXED_ACCESS_EXPRESSION__COMPOSED_MEMBER_CACHE, oldComposedMemberCache, composedMemberCache));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ComposedMemberCache(org.eclipse.n4js.ts.types.ComposedMemberCache)

Example 2 with ComposedMemberCache

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

the class ParameterizedPropertyAccessExpressionImpl method setComposedMemberCache.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setComposedMemberCache(ComposedMemberCache newComposedMemberCache) {
    ComposedMemberCache oldComposedMemberCache = composedMemberCache;
    composedMemberCache = newComposedMemberCache;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.PARAMETERIZED_PROPERTY_ACCESS_EXPRESSION__COMPOSED_MEMBER_CACHE, oldComposedMemberCache, composedMemberCache));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ComposedMemberCache(org.eclipse.n4js.ts.types.ComposedMemberCache)

Example 3 with ComposedMemberCache

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

the class MemberAccessImpl method setComposedMemberCache.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setComposedMemberCache(ComposedMemberCache newComposedMemberCache) {
    ComposedMemberCache oldComposedMemberCache = composedMemberCache;
    composedMemberCache = newComposedMemberCache;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.MEMBER_ACCESS__COMPOSED_MEMBER_CACHE, oldComposedMemberCache, composedMemberCache));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ComposedMemberCache(org.eclipse.n4js.ts.types.ComposedMemberCache)

Example 4 with ComposedMemberCache

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

the class JSXPropertyAttributeImpl method setComposedMemberCache.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setComposedMemberCache(ComposedMemberCache newComposedMemberCache) {
    ComposedMemberCache oldComposedMemberCache = composedMemberCache;
    composedMemberCache = newComposedMemberCache;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, N4JSPackage.JSX_PROPERTY_ATTRIBUTE__COMPOSED_MEMBER_CACHE, oldComposedMemberCache, composedMemberCache));
}
Also used : ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl) ComposedMemberCache(org.eclipse.n4js.ts.types.ComposedMemberCache)

Example 5 with ComposedMemberCache

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

the class ComposedMemberScope method createComposedMember.

/**
 * Key method of entire scoping for composed types e.g. union/intersection types. This creates a new TMember as a
 * combination of all members of the given name in the type's contained types. If those members cannot be combined
 * into a single valid member, this method creates a dummy placeholder.
 */
private TMember createComposedMember(String memberName) {
    // check all subScopes for a member of the given name and
    // merge the properties of the existing members into 'composedMember'
    final Resource resource = EcoreUtilN4.getResource(request.context, composedTypeRef);
    ComposedMemberInfoBuilder cmiBuilder = new ComposedMemberInfoBuilder();
    cmiBuilder.init(writeAccess, resource, ts);
    for (int idx = 0; idx < subScopes.length; idx++) {
        final IScope subScope = subScopes[idx];
        final TypeRef typeRef = composedTypeRef.getTypeRefs().get(idx);
        final Resource res = EcoreUtilN4.getResource(request.context, composedTypeRef);
        final RuleEnvironment GwithSubstitutions = ts.createRuleEnvironmentForContext(typeRef, res);
        final TMember member = findMemberInSubScope(subScope, memberName);
        cmiBuilder.addMember(member, GwithSubstitutions);
    }
    // produce result
    ComposedMemberInfo cmi = cmiBuilder.get();
    ComposedMemberFactory cmf = getComposedMemberFactory(cmi);
    if (!cmf.isEmpty()) {
        // at least one of the subScopes had an element of that name
        final TMember result;
        if (cmf.isValid()) {
            // success case: The element for that name can be merged into a valid composed member
            result = cmf.create(memberName);
        } else {
            // some of the subScopes do not have an element for that name OR
            // they do not form a valid composed member (e.g. they are of different kind)
            // -> produce a specific error message explaining the incompatibility
            // (this error placeholder will be wrapped with a UncommonMemberDescription
            // in #getSingleLocalElementByName(QualifiedName) above)
            result = createErrorPlaceholder(memberName);
        }
        // add composed member to ComposedTypeRef's cache (without notifications to avoid cache-clear)
        final ComposedMemberCache cache = getOrCreateComposedMemberCache();
        if (cache != null) {
            EcoreUtilN4.doWithDeliver(false, () -> {
                cache.getCachedComposedMembers().add(result);
            }, cache);
        }
        // if cache==null: simply do not cache the composed member (i.e. member won't be contained in a resource!)
        return result;
    } else {
        // -> produce the ordinary "Cannot resolve reference ..." error by returning 'null'
        return null;
    }
}
Also used : TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) UnknownTypeRef(org.eclipse.n4js.ts.typeRefs.UnknownTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) N4JSResource(org.eclipse.n4js.resource.N4JSResource) Resource(org.eclipse.emf.ecore.resource.Resource) IScope(org.eclipse.xtext.scoping.IScope) RuleEnvironment(org.eclipse.xsemantics.runtime.RuleEnvironment) ComposedMemberCache(org.eclipse.n4js.ts.types.ComposedMemberCache) TMember(org.eclipse.n4js.ts.types.TMember)

Aggregations

ComposedMemberCache (org.eclipse.n4js.ts.types.ComposedMemberCache)6 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)4 Resource (org.eclipse.emf.ecore.resource.Resource)2 N4JSResource (org.eclipse.n4js.resource.N4JSResource)2 MemberAccess (org.eclipse.n4js.n4JS.MemberAccess)1 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)1 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)1 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)1 TMember (org.eclipse.n4js.ts.types.TMember)1 TModule (org.eclipse.n4js.ts.types.TModule)1 RuleEnvironment (org.eclipse.xsemantics.runtime.RuleEnvironment)1 IScope (org.eclipse.xtext.scoping.IScope)1