Search in sources :

Example 1 with N4TypeDefinition

use of org.eclipse.n4js.n4JS.N4TypeDefinition 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);
}
Also used : Script(org.eclipse.n4js.n4JS.Script) Type(org.eclipse.n4js.ts.types.Type) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) N4TypeDefinition(org.eclipse.n4js.n4JS.N4TypeDefinition) UnionTypeExpression(org.eclipse.n4js.ts.typeRefs.UnionTypeExpression) Resource(org.eclipse.emf.ecore.resource.Resource) TModule(org.eclipse.n4js.ts.types.TModule)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)1 N4TypeDefinition (org.eclipse.n4js.n4JS.N4TypeDefinition)1 Script (org.eclipse.n4js.n4JS.Script)1 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)1 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)1 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)1 UnionTypeExpression (org.eclipse.n4js.ts.typeRefs.UnionTypeExpression)1 TModule (org.eclipse.n4js.ts.types.TModule)1 TStructuralType (org.eclipse.n4js.ts.types.TStructuralType)1 Type (org.eclipse.n4js.ts.types.Type)1