Search in sources :

Example 16 with TClass

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

the class TestDiscoveryHelper method collectSuitsForModule.

private Collection<TestSuite> collectSuitsForModule(final TModule module) {
    final List<TestSuite> suites = newArrayList();
    // Collect all top level non-abstract exported classes, exclude everything else.
    for (final TClass clazz : from(module.getTopLevelTypes()).filter(TClass.class).filter(c -> !c.isAbstract() && c.isExported())) {
        final TestSuite testSuite = new TestSuite(getClassName(clazz));
        for (final TMethod method : getAllTestMethodsOfClass(clazz)) {
            final TestCase testCase = createTestCase(method, module, getClassName(clazz));
            testSuite.add(testCase);
        }
        if (!isEmpty(testSuite)) {
            suites.add(testSuite);
        }
    }
    return suites;
}
Also used : TMethod(org.eclipse.n4js.ts.types.TMethod) TestSuite(org.eclipse.n4js.tester.domain.TestSuite) TestCase(org.eclipse.n4js.tester.domain.TestCase) TClass(org.eclipse.n4js.ts.types.TClass)

Example 17 with TClass

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

the class MissingApiMembersForTranspiler method create.

/**
 * Returns a tuple of collections used by transpiler to generate interface or class members.
 */
public static MissingApiMembersForTranspiler create(ContainerTypesHelper containerTypesHelper, ScriptApiTracker apiTracker, TClassifier type, ConcreteMembersOrderedForTranspiler cmoft, Script context) {
    MemberCollector collector = containerTypesHelper.fromContext(context);
    // IDE-1510 create missing API-methods here.
    MemberList<TMethod> missingApiMethods = new MemberList<>();
    if (type instanceof TClass) {
        List<TMethod> c = apiTracker.computeMissingApiMethods((TClass) type, context);
        missingApiMethods.addAll(c);
        List<VirtualApiTMethod> missingAPIfromInheritance = apiTracker.computeMethodDiff((TClass) type, collector, cmoft.ownedAndMixedInConcreteMembers, missingApiMethods);
        missingApiMethods.addAll(missingAPIfromInheritance);
    }
    if (type instanceof TInterface) {
        List<TMethod> c = apiTracker.computeMissingApiMethods((TInterface) type, context);
        missingApiMethods.addAll(c);
    }
    // IDE-1510 create missing API-fields here.
    List<AccessorTuple> missingApiAccessorTuples = new ArrayList<>();
    {
        List<AccessorTuple> computedMissingApiGetterSetter = apiTracker.computeMissingApiGetterSetter((TN4Classifier) type, cmoft.concreteAccessorTuples);
        List<AccessorTuple> computedMissingApiFields = apiTracker.computeMissingApiFields((TN4Classifier) type);
        // In case of field vs. getter the implementation should be free to choose the form.
        // So filter out all missing set/get pairs which are backed by a field (either concrete or inherited)
        List<AccessorTuple> filteredMissingApiGetterSetter = filterOutTuplesImplementedByField(computedMissingApiGetterSetter, cmoft.ownedAndMixedInConcreteMembers, cmoft.concreteInheritedMembers);
        // Some logic applies to missing fields which are backed by a getter/setter. The situation here is a
        // little bit more complex as the set/get must be processed as a pair and one could be missing or they stem
        // from different (super-)types.
        // *Beware* not side-effect free since we have to mix in virtual getter/setter into an existing but
        // incomplete accessor-pairs
        List<AccessorTuple> filteredMissingApiFields0 = filterMissingApiFieldsAndEnrichExistingTuples(computedMissingApiFields, cmoft.concreteAccessorTuples);
        List<AccessorTuple> filteredMissingApiFields = filterMissingApiFieldsImplementedBySuperGetSet(filteredMissingApiFields0, cmoft.concreteInheritedMembers);
        missingApiAccessorTuples.addAll(filteredMissingApiGetterSetter);
        missingApiAccessorTuples.addAll(filteredMissingApiFields);
    }
    MemberList<TField> fieldsOverridingAccessors = getFieldsOverridingAccessor(cmoft.ownedAndMixedInConcreteMembers, cmoft.concreteInheritedMembers);
    // compute the list of mixed in fields, which do not override any Accessor (handled separately)
    MemberList<TField> fieldsPurelyMixedInNotOverridingAccessor = new MemberList<>();
    fieldsPurelyMixedInNotOverridingAccessor.addAll(cmoft.ownedAndMixedInConcreteMembers.stream().filter(it -> it instanceof TField && // must stem from different type
    it.getContainingType() != type).map(it -> (TField) it).filter(// remove the ones overriding get/set
    it -> !fieldsOverridingAccessors.contains(it)).collect(Collectors.toList()));
    return new MissingApiMembersForTranspiler(missingApiMethods, missingApiAccessorTuples);
}
Also used : VirtualApiTMethod(org.eclipse.n4js.transpiler.utils.ScriptApiTracker.VirtualApiTMethod) TField(org.eclipse.n4js.ts.types.TField) TMember(org.eclipse.n4js.ts.types.TMember) Script(org.eclipse.n4js.n4JS.Script) TClass(org.eclipse.n4js.ts.types.TClass) TMethod(org.eclipse.n4js.ts.types.TMethod) AccessorTuple(org.eclipse.n4js.ts.types.util.AccessorTuple) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TSetter(org.eclipse.n4js.ts.types.TSetter) TGetter(org.eclipse.n4js.ts.types.TGetter) List(java.util.List) TN4Classifier(org.eclipse.n4js.ts.types.TN4Classifier) ContainerTypesHelper(org.eclipse.n4js.utils.ContainerTypesHelper) Stream(java.util.stream.Stream) TClassifier(org.eclipse.n4js.ts.types.TClassifier) TInterface(org.eclipse.n4js.ts.types.TInterface) MemberList(org.eclipse.n4js.ts.types.util.MemberList) Optional(java.util.Optional) MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector) VirtualApiTMethod(org.eclipse.n4js.transpiler.utils.ScriptApiTracker.VirtualApiTMethod) TMethod(org.eclipse.n4js.ts.types.TMethod) TField(org.eclipse.n4js.ts.types.TField) MemberList(org.eclipse.n4js.ts.types.util.MemberList) TInterface(org.eclipse.n4js.ts.types.TInterface) TN4Classifier(org.eclipse.n4js.ts.types.TN4Classifier) VirtualApiTMethod(org.eclipse.n4js.transpiler.utils.ScriptApiTracker.VirtualApiTMethod) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) MemberList(org.eclipse.n4js.ts.types.util.MemberList) AccessorTuple(org.eclipse.n4js.ts.types.util.AccessorTuple) MemberCollector(org.eclipse.n4js.utils.ContainerTypesHelper.MemberCollector) TClass(org.eclipse.n4js.ts.types.TClass)

Example 18 with TClass

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

the class TClassImpl method getSuperClass.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public TClass getSuperClass() {
    ParameterizedTypeRef _superClassRef = this.getSuperClassRef();
    Type _declaredType = null;
    if (_superClassRef != null) {
        _declaredType = _superClassRef.getDeclaredType();
    }
    final Type superType = _declaredType;
    TClass _xifexpression = null;
    if ((superType instanceof TClass)) {
        _xifexpression = ((TClass) superType);
    } else {
        _xifexpression = null;
    }
    return _xifexpression;
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) Type(org.eclipse.n4js.ts.types.Type) TClass(org.eclipse.n4js.ts.types.TClass)

Example 19 with TClass

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

the class TypeUtils method isRawSuperType.

private static boolean isRawSuperType(Type type, Type superTypeCandidate, RecursionGuard<Type> guard) {
    if (type == superTypeCandidate) {
        return true;
    }
    if (type == null) {
        return false;
    }
    if (guard.tryNext(type)) {
        if (type instanceof TClass) {
            final TClass c = (TClass) type;
            if (isRawSuperType(c.getSuperClassRef(), superTypeCandidate, guard)) {
                return true;
            }
            if (isRawSuperType(c.getImplementedInterfaceRefs(), superTypeCandidate, guard)) {
                return true;
            }
            return false;
        }
        if (type instanceof TInterface) {
            final TInterface r = (TInterface) type;
            if (isRawSuperType(r.getSuperInterfaceRefs(), superTypeCandidate, guard)) {
                return true;
            }
            return false;
        }
        if (type instanceof TypeVariable) {
            TypeVariable v = (TypeVariable) type;
            TypeRef ub = v.getDeclaredUpperBound();
            if (ub != null && isRawSuperType(ub, superTypeCandidate, guard)) {
                return true;
            }
            return false;
        }
        if (type instanceof PrimitiveType) {
            PrimitiveType assignmentCompatible = ((PrimitiveType) type).getAssignmentCompatible();
            if (isRawSuperType(assignmentCompatible, superTypeCandidate, guard)) {
                return true;
            }
        }
    }
    return false;
}
Also used : TInterface(org.eclipse.n4js.ts.types.TInterface) 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) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) TClass(org.eclipse.n4js.ts.types.TClass)

Example 20 with TClass

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

the class TypeUtils method declaredSuperTypes.

/**
 * Convenience method, returns directly declared super types (class, role, interface) of a classifier. May return an
 * empty list but never null. Order is always super class, super roles, super interfaces. For all non-classifiers
 * this method returns an empty list.
 */
@SuppressWarnings("unchecked")
public static Iterable<? extends ParameterizedTypeRef> declaredSuperTypes(final Type type) {
    if (type instanceof TClass) {
        final TClass c = (TClass) type;
        if (c.getSuperClassRef() != null) {
            return Iterables.concat(concat(singletonList(c.getSuperClassRef()), c.getImplementedInterfaceRefs()));
        } else {
            return c.getImplementedInterfaceRefs();
        }
    }
    if (type instanceof TInterface) {
        final TInterface r = (TInterface) type;
        return r.getSuperInterfaceRefs();
    }
    if (type instanceof PrimitiveType) {
        PrimitiveType assignmentCompatible = ((PrimitiveType) type).getAssignmentCompatible();
        if (assignmentCompatible != null) {
            ParameterizedTypeRef typeRef = TypeRefsFactory.eINSTANCE.createParameterizedTypeRef();
            typeRef.setDeclaredType(assignmentCompatible);
            return Collections.singletonList(typeRef);
        }
    }
    if (type instanceof TObjectPrototype) {
        // IDE-1221 string based enums: traversing super types for object prototypes as well
        TObjectPrototype tObjectPrototype = (TObjectPrototype) type;
        if (tObjectPrototype.getSuperType() != null) {
            return singletonList(tObjectPrototype.getSuperType());
        }
    }
    return Collections.emptyList();
}
Also used : ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) TInterface(org.eclipse.n4js.ts.types.TInterface) TObjectPrototype(org.eclipse.n4js.ts.types.TObjectPrototype) PrimitiveType(org.eclipse.n4js.ts.types.PrimitiveType) TClass(org.eclipse.n4js.ts.types.TClass)

Aggregations

TClass (org.eclipse.n4js.ts.types.TClass)27 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)16 Type (org.eclipse.n4js.ts.types.Type)15 TMember (org.eclipse.n4js.ts.types.TMember)11 TClassifier (org.eclipse.n4js.ts.types.TClassifier)10 TInterface (org.eclipse.n4js.ts.types.TInterface)9 TMethod (org.eclipse.n4js.ts.types.TMethod)8 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 EObject (org.eclipse.emf.ecore.EObject)5 PrimitiveType (org.eclipse.n4js.ts.types.PrimitiveType)5 TField (org.eclipse.n4js.ts.types.TField)5 MemberList (org.eclipse.n4js.ts.types.util.MemberList)5 Collections.emptyList (java.util.Collections.emptyList)4 HashMap (java.util.HashMap)4 Stream (java.util.stream.Stream)4 N4InterfaceDeclaration (org.eclipse.n4js.n4JS.N4InterfaceDeclaration)4 Script (org.eclipse.n4js.n4JS.Script)4