Search in sources :

Example 11 with TMethod

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

the class TypingStrategyFilter method apply.

@Override
public boolean apply(IEObjectDescription description) {
    if (typingStrategy == TypingStrategy.DEFAULT || typingStrategy == TypingStrategy.NOMINAL) {
        return true;
    }
    EObject proxyOrInstance = description.getEObjectOrProxy();
    if (proxyOrInstance == null || proxyOrInstance.eIsProxy()) {
        return true;
    }
    if (!(proxyOrInstance instanceof TMember)) {
        return true;
    }
    TMember member = (TMember) proxyOrInstance;
    if (member.isStatic() || member.getMemberAccessModifier() != MemberAccessModifier.PUBLIC) {
        return false;
    }
    if (member instanceof TMethod) {
        switch(typingStrategy) {
            case NOMINAL:
            case DEFAULT:
                return true;
            case STRUCTURAL_FIELDS:
            case STRUCTURAL_READ_ONLY_FIELDS:
            case STRUCTURAL_WRITE_ONLY_FIELDS:
            case STRUCTURAL_FIELD_INITIALIZER:
                return false;
            case STRUCTURAL:
                // including constructors
                return true;
        }
    }
    if (member instanceof TGetter) {
        switch(typingStrategy) {
            case NOMINAL:
            case DEFAULT:
            case STRUCTURAL:
            case STRUCTURAL_FIELDS:
            case STRUCTURAL_READ_ONLY_FIELDS:
                return true;
            case STRUCTURAL_WRITE_ONLY_FIELDS:
                return false;
            case STRUCTURAL_FIELD_INITIALIZER:
                ContainerType<?> type = member.getContainingType();
                NameAndAccess naa = new NameAndAccess(member.getName(), true, false);
                Map<NameAndAccess, ? extends TMember> members = type.getOwnedMembersByNameAndAccess();
                boolean hasSetter = members.containsKey(naa);
                return hasSetter;
        }
    }
    if (member instanceof TSetter) {
        switch(typingStrategy) {
            case NOMINAL:
            case DEFAULT:
            case STRUCTURAL:
            case STRUCTURAL_FIELDS:
            case STRUCTURAL_WRITE_ONLY_FIELDS:
                return true;
            case STRUCTURAL_READ_ONLY_FIELDS:
            case STRUCTURAL_FIELD_INITIALIZER:
                return false;
        }
    }
    if (member instanceof TField) {
        TField field = (TField) member;
        switch(typingStrategy) {
            case NOMINAL:
            case DEFAULT:
            case STRUCTURAL:
            case STRUCTURAL_FIELDS:
                return true;
            case STRUCTURAL_READ_ONLY_FIELDS:
                return !isWriteAccess;
            case STRUCTURAL_WRITE_ONLY_FIELDS:
                return isWriteAccess;
            case STRUCTURAL_FIELD_INITIALIZER:
                boolean isAccessable = !isWriteAccess && (!field.isFinal() || !field.isHasExpression());
                return isAccessable;
        }
    }
    return true;
}
Also used : TSetter(org.eclipse.n4js.ts.types.TSetter) NameAndAccess(org.eclipse.n4js.ts.types.NameAndAccess) TMethod(org.eclipse.n4js.ts.types.TMethod) TField(org.eclipse.n4js.ts.types.TField) TGetter(org.eclipse.n4js.ts.types.TGetter) EObject(org.eclipse.emf.ecore.EObject) TMember(org.eclipse.n4js.ts.types.TMember)

Example 12 with TMethod

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

the class TestDiscoveryHelper method collectSuitsForMethod.

private Collection<TestSuite> collectSuitsForMethod(final URI uri, final TModule module) {
    final EObject object = module.eResource().getResourceSet().getEObject(uri, true);
    if (object instanceof N4MethodDeclaration) {
        final Type type = ((N4MethodDeclaration) object).getDefinedType();
        if (type instanceof TMethod) {
            final TMethod method = (TMethod) type;
            final TestSuite testSuite = new TestSuite(getClassName(method));
            testSuite.add(createTestCase(method, module));
            return singletonList(testSuite);
        }
    }
    return emptyList();
}
Also used : Type(org.eclipse.n4js.ts.types.Type) EcoreUtil2.getContainerOfType(org.eclipse.xtext.EcoreUtil2.getContainerOfType) FileExtensionType(org.eclipse.n4js.fileextensions.FileExtensionType) TMethod(org.eclipse.n4js.ts.types.TMethod) TestSuite(org.eclipse.n4js.tester.domain.TestSuite) EObject(org.eclipse.emf.ecore.EObject) N4MethodDeclaration(org.eclipse.n4js.n4JS.N4MethodDeclaration)

Example 13 with TMethod

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

the class ContainerTypeImpl method basicSetCallableCtor.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public NotificationChain basicSetCallableCtor(TMethod newCallableCtor, NotificationChain msgs) {
    TMethod oldCallableCtor = callableCtor;
    callableCtor = newCallableCtor;
    if (eNotificationRequired()) {
        ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, TypesPackage.CONTAINER_TYPE__CALLABLE_CTOR, oldCallableCtor, newCallableCtor);
        if (msgs == null)
            msgs = notification;
        else
            msgs.add(notification);
    }
    return msgs;
}
Also used : TMethod(org.eclipse.n4js.ts.types.TMethod) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 14 with TMethod

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

the class TFunctionImpl method isCallableConstructor.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public boolean isCallableConstructor() {
    final EObject parent = this.eContainer();
    boolean _xifexpression = false;
    if ((parent instanceof ContainerType<?>)) {
        TMethod _callableCtor = ((ContainerType<?>) parent).getCallableCtor();
        _xifexpression = (_callableCtor == this);
    } else {
        _xifexpression = false;
    }
    return _xifexpression;
}
Also used : TMethod(org.eclipse.n4js.ts.types.TMethod) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) ContainerType(org.eclipse.n4js.ts.types.ContainerType)

Example 15 with TMethod

use of org.eclipse.n4js.ts.types.TMethod 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)

Aggregations

TMethod (org.eclipse.n4js.ts.types.TMethod)24 EObject (org.eclipse.emf.ecore.EObject)10 TMember (org.eclipse.n4js.ts.types.TMember)10 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)9 TClassifier (org.eclipse.n4js.ts.types.TClassifier)9 TClass (org.eclipse.n4js.ts.types.TClass)8 Type (org.eclipse.n4js.ts.types.Type)6 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)5 TSetter (org.eclipse.n4js.ts.types.TSetter)5 Inject (com.google.inject.Inject)4 TField (org.eclipse.n4js.ts.types.TField)4 TGetter (org.eclipse.n4js.ts.types.TGetter)4 MemberList (org.eclipse.n4js.ts.types.util.MemberList)4 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)4 Pair (org.eclipse.xtext.xbase.lib.Pair)4 LinkedHashMultimap (com.google.common.collect.LinkedHashMultimap)3 Singleton (com.google.inject.Singleton)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Collections.emptyList (java.util.Collections.emptyList)3