Search in sources :

Example 16 with TClassifier

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

the class TClassifierImpl method getSuperClassifiers.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public Iterable<? extends TClassifier> getSuperClassifiers() {
    final List<TClassifier> result = CollectionLiterals.<TClassifier>newArrayList();
    final Object _superClassifierRefs = this.getSuperClassifierRefs();
    for (final Object superClassifierRef : ((Iterable<?>) _superClassifierRefs)) {
        if ((superClassifierRef != null)) {
            final Type declType = ((TypeRef) superClassifierRef).getDeclaredType();
            if ((declType instanceof TClassifier)) {
                result.add(((TClassifier) declType));
            }
        }
    }
    return result;
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) Type(org.eclipse.n4js.ts.types.Type) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 17 with TClassifier

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

the class ConsumptionUtils method findInterfaceDefiningConsumedMember.

/**
 * Returns the directly consumed (or otherwise inherited) classifier which indirectly provides the consumed member
 * (or null, if interface is found). Usually the returned classifier is a TInterface.
 *
 * @param consumingClassifier
 *            the consuming classifier
 * @param consumedMember
 *            the member consumed by the classifier
 */
public static TClassifier findInterfaceDefiningConsumedMember(TClassifier consumingClassifier, TMember consumedMember) {
    if (consumedMember == null || !(consumedMember.eContainer() instanceof TInterface)) {
        return null;
    }
    TInterface tinterface = (TInterface) consumedMember.eContainer();
    List<TClassifier> path = findPathToInterface(consumingClassifier, tinterface);
    if (path.isEmpty()) {
        return null;
    }
    return path.get(0);
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) TInterface(org.eclipse.n4js.ts.types.TInterface)

Example 18 with TClassifier

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

the class TypeUtils method createConstructorTypeRef.

/**
 * Creates new type reference for constructor. if the declared type is TFunction a FunctionTypeRef is created. If
 * declared type is TClassifier than TypeTypeRef is created (i.e. <code>constructor{A}</code> in N4JS code)
 */
public static TypeRef createConstructorTypeRef(Type declaredType, TypeArgument... typeArgs) {
    TypeRef typeRef = null;
    if (declaredType instanceof TFunction) {
        // TODO is this correct?
        FunctionTypeRef ref = TypeRefsFactory.eINSTANCE.createFunctionTypeRef();
        ref.setDeclaredType(declaredType);
        for (TypeArgument typeArg : typeArgs) {
            ref.getTypeArgs().add(TypeUtils.copyIfContained(typeArg));
        }
        typeRef = ref;
    } else if (declaredType instanceof TClassifier) {
        TClassifier tClassifier = (TClassifier) declaredType;
        typeRef = createTypeTypeRef(createTypeRef(tClassifier, typeArgs), true);
    } else if (declaredType instanceof TypeVariable) {
        TypeVariable tTypeVar = (TypeVariable) declaredType;
        typeRef = createTypeTypeRef(createTypeRef(tTypeVar), true);
    }
    return typeRef;
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) TFunction(org.eclipse.n4js.ts.types.TFunction) TypeVariable(org.eclipse.n4js.ts.types.TypeVariable) ExistentialTypeRef(org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef) ThisTypeRef(org.eclipse.n4js.ts.typeRefs.ThisTypeRef) BoundThisTypeRef(org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) StructuralTypeRef(org.eclipse.n4js.ts.typeRefs.StructuralTypeRef) TypeRef(org.eclipse.n4js.ts.typeRefs.TypeRef) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) DeferredTypeRef(org.eclipse.n4js.ts.typeRefs.DeferredTypeRef) BaseTypeRef(org.eclipse.n4js.ts.typeRefs.BaseTypeRef) ComposedTypeRef(org.eclipse.n4js.ts.typeRefs.ComposedTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) FunctionTypeRef(org.eclipse.n4js.ts.typeRefs.FunctionTypeRef) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument)

Example 19 with TClassifier

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

the class MemberVisibilityChecker method isInternalCheckProtectedVisibile.

/**
 * Unified internal check for visibility focusing on protected-stage only. Used in
 * {@link #isProtectedVisible(Type, TModule, Type, TMember, boolean)} and
 * {@link #isProtectedInternalVisible(Type, TModule, Type, TMember, boolean)}
 *
 * <p>
 * Preconditions:
 * <ol>
 * <li>contextType != declaredReceiverType
 * </ol>
 *
 * @param contextModule
 *            module where the access is issued.
 * @param contextType
 *            containing type where the access is issued, eg. the container-type of the method, can be null if
 *            access happens on top-level
 * @param member
 *            member to access.
 * @param declaredReceiverType
 *            type on which the member will be accessed on. Not necessarily the definition type of the member but
 *            one of it's sub-types.
 * @param supercall
 *            true if super-keyword was used.
 */
private boolean isInternalCheckProtectedVisibile(Type contextType, TModule contextModule, Type declaredReceiverType, TMember member, boolean supercall) {
    // Protected means, that the context-type is a sub-type of the receiver-type
    if (contextType == null) {
        // not type information available, maybe just parsing the script: context is relevant here.
        return false;
    }
    // contextType must be a super-type of declaredRecieverType:
    List<TClassifier> receiverSuperTypes = AllSuperTypesCollector.collect((TClassifier) declaredReceiverType);
    if (!receiverSuperTypes.contains(contextType)) {
        // Problem: if super-keyword was usesed, the call is still valid.
        if (!supercall) {
            return false;
        }
    }
    // and the member is part of a super-type (including default-method of implemented interfaces) of the
    // receiver-type
    TClassifier memberClsfContainer = EcoreUtil2.getContainerOfType(member, TClassifier.class);
    if (declaredReceiverType instanceof TClassifier && receiverSuperTypes.contains(memberClsfContainer)) {
        // definition of member is done in the super-type-tree of the receiver.
        return true;
    }
    return false;
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier)

Example 20 with TClassifier

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

the class VisibilityAwareCtorScope method isAccepted.

@Override
protected boolean isAccepted(IEObjectDescription description) {
    EObject proxyOrInstance = description.getEObjectOrProxy();
    if (proxyOrInstance != null && !proxyOrInstance.eIsProxy()) {
        if (proxyOrInstance instanceof TClassifier) {
            TClassifier ctorClassifier = (TClassifier) proxyOrInstance;
            if (ctorClassifier.isAbstract()) {
                // avoid duplicate error messages
                return true;
            }
            // If the class is found, check if the visibility of the constructor is valid
            TMethod usedCtor = containerTypesHelper.fromContext(context).findConstructor(ctorClassifier);
            if (usedCtor != null && usedCtor.isConstructor()) {
                return checker.isConstructorVisible(context, TypeUtils.createTypeRef(ctorClassifier), usedCtor);
            }
        }
    }
    return true;
}
Also used : TClassifier(org.eclipse.n4js.ts.types.TClassifier) TMethod(org.eclipse.n4js.ts.types.TMethod) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

TClassifier (org.eclipse.n4js.ts.types.TClassifier)29 TMember (org.eclipse.n4js.ts.types.TMember)12 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)11 EObject (org.eclipse.emf.ecore.EObject)10 Type (org.eclipse.n4js.ts.types.Type)10 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)9 TClass (org.eclipse.n4js.ts.types.TClass)8 ContainerType (org.eclipse.n4js.ts.types.ContainerType)7 TMethod (org.eclipse.n4js.ts.types.TMethod)7 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)6 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)6 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)6 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)6 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)6 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)6 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)6 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)6 TInterface (org.eclipse.n4js.ts.types.TInterface)6 RuleEnvironment (org.eclipse.xsemantics.runtime.RuleEnvironment)6 ArrayList (java.util.ArrayList)5