Search in sources :

Example 16 with TMethod

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

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

the class TypeUtils method setMemberTypeRef.

/**
 * Convenience method setting the type of the given member. Sets the return type in case of getters and methods and
 * the type of the single fpar in case of setters. If the setter does not have an fpar yet, it will be created.
 */
public static void setMemberTypeRef(TMember m, TypeRef typeRef) {
    typeRef = TypeUtils.copyIfContained(typeRef);
    if (m instanceof TField)
        ((TField) m).setTypeRef(typeRef);
    else if (m instanceof TGetter)
        ((TGetter) m).setDeclaredTypeRef(typeRef);
    else if (m instanceof TSetter) {
        final TSetter s = (TSetter) m;
        if (s.getFpar() == null)
            s.setFpar(TypesFactory.eINSTANCE.createTFormalParameter());
        s.getFpar().setTypeRef(typeRef);
    } else if (m instanceof TMethod)
        ((TMethod) m).setReturnTypeRef(typeRef);
    else if (m != null)
        throw new IllegalArgumentException("unknown sub-class of TMember: " + m.getClass().getName());
}
Also used : TSetter(org.eclipse.n4js.ts.types.TSetter) TMethod(org.eclipse.n4js.ts.types.TMethod) TField(org.eclipse.n4js.ts.types.TField) TGetter(org.eclipse.n4js.ts.types.TGetter)

Example 18 with TMethod

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

the class TypesSemanticSequencer method sequence.

@Override
public void sequence(ISerializationContext context, EObject semanticObject) {
    EPackage epackage = semanticObject.eClass().getEPackage();
    ParserRule rule = context.getParserRule();
    Action action = context.getAssignedAction();
    Set<Parameter> parameters = context.getEnabledBooleanParameters();
    if (epackage == TypeRefsPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case TypeRefsPackage.FUNCTION_TYPE_EXPRESSION:
                if (rule == grammarAccess.getIntersectionTypeExpressionRule() || action == grammarAccess.getIntersectionTypeExpressionAccess().getIntersectionTypeExpressionTypeRefsAction_1_0() || rule == grammarAccess.getPrimaryTypeExpressionRule()) {
                    sequence_ArrowFunctionTypeExpression_ColonSepReturnTypeRef_FunctionTypeExpressionOLD_TAnonymousFormalParameterList_TypeRef_TypeRefWithModifiers(context, (FunctionTypeExpression) semanticObject);
                    return;
                } else if (rule == grammarAccess.getArrowFunctionTypeExpressionRule()) {
                    sequence_ArrowFunctionTypeExpression_TAnonymousFormalParameterList(context, (FunctionTypeExpression) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithoutModifiersRule() || rule == grammarAccess.getFunctionTypeExpressionOLDRule()) {
                    sequence_ColonSepReturnTypeRef_FunctionTypeExpressionOLD_TAnonymousFormalParameterList(context, (FunctionTypeExpression) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithModifiersRule()) {
                    sequence_ColonSepReturnTypeRef_FunctionTypeExpressionOLD_TAnonymousFormalParameterList_TypeRefWithModifiers(context, (FunctionTypeExpression) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefRule() || rule == grammarAccess.getTypeArgumentRule()) {
                    sequence_ColonSepReturnTypeRef_FunctionTypeExpressionOLD_TAnonymousFormalParameterList_TypeRef(context, (FunctionTypeExpression) semanticObject);
                    return;
                } else
                    break;
            case TypeRefsPackage.INTERSECTION_TYPE_EXPRESSION:
                if (rule == grammarAccess.getTypeRefWithoutModifiersRule() || rule == grammarAccess.getTypeRefFunctionTypeExpressionRule() || rule == grammarAccess.getIntersectionTypeExpressionOLDRule()) {
                    sequence_IntersectionTypeExpressionOLD(context, (IntersectionTypeExpression) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithModifiersRule()) {
                    sequence_IntersectionTypeExpressionOLD_TypeRefWithModifiers(context, (IntersectionTypeExpression) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefRule() || rule == grammarAccess.getTypeArgumentRule()) {
                    sequence_IntersectionTypeExpressionOLD_TypeRef(context, (IntersectionTypeExpression) semanticObject);
                    return;
                } else if (action == grammarAccess.getIntersectionTypeExpressionAccess().getIntersectionTypeExpressionTypeRefsAction_1_0() || rule == grammarAccess.getPrimaryTypeExpressionRule()) {
                    sequence_IntersectionTypeExpressionOLD_TypeRef_TypeRefWithModifiers(context, (IntersectionTypeExpression) semanticObject);
                    return;
                } else if (rule == grammarAccess.getIntersectionTypeExpressionRule()) {
                    sequence_IntersectionTypeExpression_IntersectionTypeExpressionOLD_TypeRef_TypeRefWithModifiers(context, (IntersectionTypeExpression) semanticObject);
                    return;
                } else
                    break;
            case TypeRefsPackage.PARAMETERIZED_TYPE_REF:
                if (rule == grammarAccess.getArrayTypeRefRule()) {
                    sequence_ArrayTypeRef(context, (ParameterizedTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefFunctionTypeExpressionRule()) {
                    sequence_ArrayTypeRef_TypeAndTypeArguments_TypeArguments(context, (ParameterizedTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getIntersectionTypeExpressionRule() || action == grammarAccess.getIntersectionTypeExpressionAccess().getIntersectionTypeExpressionTypeRefsAction_1_0() || rule == grammarAccess.getPrimaryTypeExpressionRule()) {
                    sequence_ArrayTypeRef_TypeAndTypeArguments_TypeArguments_TypeRef_TypeRefWithModifiers_TypeRefWithoutModifiers(context, (ParameterizedTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeArgInTypeTypeRefRule() || rule == grammarAccess.getParameterizedTypeRefRule() || rule == grammarAccess.getParameterizedTypeRefNominalRule() || rule == grammarAccess.getTypeAndTypeArgumentsRule()) {
                    sequence_TypeAndTypeArguments_TypeArguments(context, (ParameterizedTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithModifiersRule()) {
                    sequence_TypeAndTypeArguments_TypeArguments_TypeRefWithModifiers_TypeRefWithoutModifiers(context, (ParameterizedTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithoutModifiersRule()) {
                    sequence_TypeAndTypeArguments_TypeArguments_TypeRefWithoutModifiers(context, (ParameterizedTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefRule() || rule == grammarAccess.getTypeArgumentRule()) {
                    sequence_TypeAndTypeArguments_TypeArguments_TypeRef_TypeRefWithoutModifiers(context, (ParameterizedTypeRef) semanticObject);
                    return;
                } else
                    break;
            case TypeRefsPackage.PARAMETERIZED_TYPE_REF_STRUCTURAL:
                if (rule == grammarAccess.getTypeRefFunctionTypeExpressionRule() || rule == grammarAccess.getParameterizedTypeRefRule() || rule == grammarAccess.getParameterizedTypeRefStructuralRule()) {
                    sequence_ParameterizedTypeRefStructural_TStructMemberList_TypeArguments(context, (ParameterizedTypeRefStructural) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithModifiersRule()) {
                    sequence_ParameterizedTypeRefStructural_TStructMemberList_TypeArguments_TypeRefWithModifiers_TypeRefWithoutModifiers(context, (ParameterizedTypeRefStructural) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithoutModifiersRule()) {
                    sequence_ParameterizedTypeRefStructural_TStructMemberList_TypeArguments_TypeRefWithoutModifiers(context, (ParameterizedTypeRefStructural) semanticObject);
                    return;
                } else if (rule == grammarAccess.getIntersectionTypeExpressionRule() || action == grammarAccess.getIntersectionTypeExpressionAccess().getIntersectionTypeExpressionTypeRefsAction_1_0() || rule == grammarAccess.getPrimaryTypeExpressionRule()) {
                    sequence_ParameterizedTypeRefStructural_TStructMemberList_TypeArguments_TypeRef_TypeRefWithModifiers_TypeRefWithoutModifiers(context, (ParameterizedTypeRefStructural) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefRule() || rule == grammarAccess.getTypeArgumentRule()) {
                    sequence_ParameterizedTypeRefStructural_TStructMemberList_TypeArguments_TypeRef_TypeRefWithoutModifiers(context, (ParameterizedTypeRefStructural) semanticObject);
                    return;
                } else
                    break;
            case TypeRefsPackage.THIS_TYPE_REF_NOMINAL:
                if (rule == grammarAccess.getTypeArgInTypeTypeRefRule() || rule == grammarAccess.getThisTypeRefRule() || rule == grammarAccess.getThisTypeRefNominalRule()) {
                    sequence_ThisTypeRefNominal(context, (ThisTypeRefNominal) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithModifiersRule()) {
                    sequence_ThisTypeRefNominal_TypeRefWithModifiers_TypeRefWithoutModifiers(context, (ThisTypeRefNominal) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithoutModifiersRule()) {
                    sequence_ThisTypeRefNominal_TypeRefWithoutModifiers(context, (ThisTypeRefNominal) semanticObject);
                    return;
                } else if (rule == grammarAccess.getIntersectionTypeExpressionRule() || action == grammarAccess.getIntersectionTypeExpressionAccess().getIntersectionTypeExpressionTypeRefsAction_1_0() || rule == grammarAccess.getPrimaryTypeExpressionRule()) {
                    sequence_ThisTypeRefNominal_TypeRef_TypeRefWithModifiers_TypeRefWithoutModifiers(context, (ThisTypeRefNominal) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefRule() || rule == grammarAccess.getTypeArgumentRule()) {
                    sequence_ThisTypeRefNominal_TypeRef_TypeRefWithoutModifiers(context, (ThisTypeRefNominal) semanticObject);
                    return;
                } else
                    break;
            case TypeRefsPackage.THIS_TYPE_REF_STRUCTURAL:
                if (rule == grammarAccess.getThisTypeRefRule() || rule == grammarAccess.getThisTypeRefStructuralRule()) {
                    sequence_TStructMemberList_ThisTypeRefStructural(context, (ThisTypeRefStructural) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithModifiersRule()) {
                    sequence_TStructMemberList_ThisTypeRefStructural_TypeRefWithModifiers_TypeRefWithoutModifiers(context, (ThisTypeRefStructural) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithoutModifiersRule()) {
                    sequence_TStructMemberList_ThisTypeRefStructural_TypeRefWithoutModifiers(context, (ThisTypeRefStructural) semanticObject);
                    return;
                } else if (rule == grammarAccess.getIntersectionTypeExpressionRule() || action == grammarAccess.getIntersectionTypeExpressionAccess().getIntersectionTypeExpressionTypeRefsAction_1_0() || rule == grammarAccess.getPrimaryTypeExpressionRule()) {
                    sequence_TStructMemberList_ThisTypeRefStructural_TypeRef_TypeRefWithModifiers_TypeRefWithoutModifiers(context, (ThisTypeRefStructural) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefRule() || rule == grammarAccess.getTypeArgumentRule()) {
                    sequence_TStructMemberList_ThisTypeRefStructural_TypeRef_TypeRefWithoutModifiers(context, (ThisTypeRefStructural) semanticObject);
                    return;
                } else
                    break;
            case TypeRefsPackage.TYPE_TYPE_REF:
                if (rule == grammarAccess.getTypeRefWithModifiersRule()) {
                    sequence_TypeRefWithModifiers_TypeTypeRef(context, (TypeTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getIntersectionTypeExpressionRule() || action == grammarAccess.getIntersectionTypeExpressionAccess().getIntersectionTypeExpressionTypeRefsAction_1_0() || rule == grammarAccess.getPrimaryTypeExpressionRule()) {
                    sequence_TypeRef_TypeRefWithModifiers_TypeTypeRef(context, (TypeTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefRule() || rule == grammarAccess.getTypeArgumentRule()) {
                    sequence_TypeRef_TypeTypeRef(context, (TypeTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithoutModifiersRule() || rule == grammarAccess.getTypeRefFunctionTypeExpressionRule() || rule == grammarAccess.getTypeTypeRefRule()) {
                    sequence_TypeTypeRef(context, (TypeTypeRef) semanticObject);
                    return;
                } else
                    break;
            case TypeRefsPackage.UNION_TYPE_EXPRESSION:
                if (rule == grammarAccess.getTypeRefWithModifiersRule()) {
                    sequence_TypeRefWithModifiers_UnionTypeExpressionOLD(context, (UnionTypeExpression) semanticObject);
                    return;
                } else if (rule == grammarAccess.getIntersectionTypeExpressionRule() || action == grammarAccess.getIntersectionTypeExpressionAccess().getIntersectionTypeExpressionTypeRefsAction_1_0() || rule == grammarAccess.getPrimaryTypeExpressionRule()) {
                    sequence_TypeRef_TypeRefWithModifiers_UnionTypeExpressionOLD(context, (UnionTypeExpression) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefRule() || rule == grammarAccess.getTypeArgumentRule()) {
                    sequence_TypeRef_UnionTypeExpressionOLD(context, (UnionTypeExpression) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithoutModifiersRule() || rule == grammarAccess.getTypeRefFunctionTypeExpressionRule() || rule == grammarAccess.getUnionTypeExpressionOLDRule()) {
                    sequence_UnionTypeExpressionOLD(context, (UnionTypeExpression) semanticObject);
                    return;
                } else
                    break;
            case TypeRefsPackage.VERSIONED_PARAMETERIZED_TYPE_REF:
                if (rule == grammarAccess.getTypeRefWithModifiersRule()) {
                    sequence_TypeAndTypeArguments_TypeArguments_TypeRefWithModifiers_TypeRefWithoutModifiers_VersionRequest(context, (VersionedParameterizedTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithoutModifiersRule()) {
                    sequence_TypeAndTypeArguments_TypeArguments_TypeRefWithoutModifiers_VersionRequest(context, (VersionedParameterizedTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getIntersectionTypeExpressionRule() || action == grammarAccess.getIntersectionTypeExpressionAccess().getIntersectionTypeExpressionTypeRefsAction_1_0() || rule == grammarAccess.getPrimaryTypeExpressionRule()) {
                    sequence_TypeAndTypeArguments_TypeArguments_TypeRef_TypeRefWithModifiers_TypeRefWithoutModifiers_VersionRequest(context, (VersionedParameterizedTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefRule() || rule == grammarAccess.getTypeArgumentRule()) {
                    sequence_TypeAndTypeArguments_TypeArguments_TypeRef_TypeRefWithoutModifiers_VersionRequest(context, (VersionedParameterizedTypeRef) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefFunctionTypeExpressionRule() || rule == grammarAccess.getTypeArgInTypeTypeRefRule() || rule == grammarAccess.getParameterizedTypeRefRule() || rule == grammarAccess.getParameterizedTypeRefNominalRule() || rule == grammarAccess.getTypeAndTypeArgumentsRule()) {
                    sequence_TypeAndTypeArguments_TypeArguments_VersionRequest(context, (VersionedParameterizedTypeRef) semanticObject);
                    return;
                } else
                    break;
            case TypeRefsPackage.VERSIONED_PARAMETERIZED_TYPE_REF_STRUCTURAL:
                if (rule == grammarAccess.getTypeRefWithModifiersRule()) {
                    sequence_ParameterizedTypeRefStructural_TStructMemberList_TypeArguments_TypeRefWithModifiers_TypeRefWithoutModifiers_VersionRequest(context, (VersionedParameterizedTypeRefStructural) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefWithoutModifiersRule()) {
                    sequence_ParameterizedTypeRefStructural_TStructMemberList_TypeArguments_TypeRefWithoutModifiers_VersionRequest(context, (VersionedParameterizedTypeRefStructural) semanticObject);
                    return;
                } else if (rule == grammarAccess.getIntersectionTypeExpressionRule() || action == grammarAccess.getIntersectionTypeExpressionAccess().getIntersectionTypeExpressionTypeRefsAction_1_0() || rule == grammarAccess.getPrimaryTypeExpressionRule()) {
                    sequence_ParameterizedTypeRefStructural_TStructMemberList_TypeArguments_TypeRef_TypeRefWithModifiers_TypeRefWithoutModifiers_VersionRequest(context, (VersionedParameterizedTypeRefStructural) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefRule() || rule == grammarAccess.getTypeArgumentRule()) {
                    sequence_ParameterizedTypeRefStructural_TStructMemberList_TypeArguments_TypeRef_TypeRefWithoutModifiers_VersionRequest(context, (VersionedParameterizedTypeRefStructural) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeRefFunctionTypeExpressionRule() || rule == grammarAccess.getParameterizedTypeRefRule() || rule == grammarAccess.getParameterizedTypeRefStructuralRule()) {
                    sequence_ParameterizedTypeRefStructural_TStructMemberList_TypeArguments_VersionRequest(context, (VersionedParameterizedTypeRefStructural) semanticObject);
                    return;
                } else
                    break;
            case TypeRefsPackage.WILDCARD:
                if (rule == grammarAccess.getWildcardNewNotationRule()) {
                    sequence_WildcardNewNotation(context, (Wildcard) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeArgInTypeTypeRefRule() || rule == grammarAccess.getWildcardRule()) {
                    sequence_Wildcard(context, (Wildcard) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeArgumentRule()) {
                    sequence_Wildcard_WildcardNewNotation(context, (Wildcard) semanticObject);
                    return;
                } else
                    break;
        }
    else if (epackage == TypesPackage.eINSTANCE)
        switch(semanticObject.eClass().getClassifierID()) {
            case TypesPackage.ANY_TYPE:
                sequence_AnyType(context, (AnyType) semanticObject);
                return;
            case TypesPackage.NULL_TYPE:
                sequence_NullType(context, (NullType) semanticObject);
                return;
            case TypesPackage.PRIMITIVE_TYPE:
                sequence_PrimitiveType(context, (PrimitiveType) semanticObject);
                return;
            case TypesPackage.TANNOTATION:
                sequence_TAnnotation(context, (TAnnotation) semanticObject);
                return;
            case TypesPackage.TANNOTATION_STRING_ARGUMENT:
                sequence_TAnnotationStringArgument(context, (TAnnotationStringArgument) semanticObject);
                return;
            case TypesPackage.TANNOTATION_TYPE_REF_ARGUMENT:
                sequence_TAnnotationTypeRefArgument(context, (TAnnotationTypeRefArgument) semanticObject);
                return;
            case TypesPackage.TANONYMOUS_FORMAL_PARAMETER:
                sequence_ColonSepTypeRef_DefaultFormalParameter_TAnonymousFormalParameter(context, (TAnonymousFormalParameter) semanticObject);
                return;
            case TypesPackage.TCLASS:
                sequence_TClass_TClassOrInterfaceHeader(context, (TClass) semanticObject);
                return;
            case TypesPackage.TENUM:
                sequence_TEnum(context, (TEnum) semanticObject);
                return;
            case TypesPackage.TENUM_LITERAL:
                sequence_TEnumLiteral(context, (TEnumLiteral) semanticObject);
                return;
            case TypesPackage.TFIELD:
                sequence_ColonSepTypeRef_TField(context, (TField) semanticObject);
                return;
            case TypesPackage.TFORMAL_PARAMETER:
                sequence_ColonSepTypeRef_DefaultFormalParameter_TFormalParameter(context, (TFormalParameter) semanticObject);
                return;
            case TypesPackage.TFUNCTION:
                sequence_ColonSepReturnTypeRef_TFormalParameters_TFunction_TypeVariables(context, (TFunction) semanticObject);
                return;
            case TypesPackage.TGETTER:
                sequence_ColonSepDeclaredTypeRef_TGetter(context, (TGetter) semanticObject);
                return;
            case TypesPackage.TINTERFACE:
                sequence_TClassOrInterfaceHeader_TInterface(context, (TInterface) semanticObject);
                return;
            case TypesPackage.TMETHOD:
                if (rule == grammarAccess.getCallableCtorRule()) {
                    sequence_CallableCtor_ColonSepReturnTypeRef_TFormalParameters(context, (TMethod) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTMemberRule() || rule == grammarAccess.getTMethodRule()) {
                    sequence_ColonSepReturnTypeRef_TFormalParameters_TMethod_TypeVariables(context, (TMethod) semanticObject);
                    return;
                } else
                    break;
            case TypesPackage.TOBJECT_PROTOTYPE:
                sequence_TObjectPrototype_TypeVariables(context, (TObjectPrototype) semanticObject);
                return;
            case TypesPackage.TSETTER:
                sequence_TSetter(context, (TSetter) semanticObject);
                return;
            case TypesPackage.TSTRUCT_FIELD:
                sequence_ColonSepTypeRef_TStructField(context, (TStructField) semanticObject);
                return;
            case TypesPackage.TSTRUCT_GETTER:
                sequence_ColonSepDeclaredTypeRef_TStructGetter(context, (TStructGetter) semanticObject);
                return;
            case TypesPackage.TSTRUCT_METHOD:
                sequence_ColonSepReturnTypeRef_TAnonymousFormalParameterList_TStructMethod_TypeVariables(context, (TStructMethod) semanticObject);
                return;
            case TypesPackage.TSTRUCT_SETTER:
                sequence_TStructSetter(context, (TStructSetter) semanticObject);
                return;
            case TypesPackage.TYPE_DEFS:
                sequence_TypeDefs(context, (TypeDefs) semanticObject);
                return;
            case TypesPackage.TYPE_VARIABLE:
                if (rule == grammarAccess.getTypeRule() || rule == grammarAccess.getTypeVariableRule()) {
                    sequence_TypeVariable(context, (TypeVariable) semanticObject);
                    return;
                } else if (rule == grammarAccess.getTypeExpressionsTypeVariableRule()) {
                    sequence_TypeVariable(context, (TypeVariable) semanticObject);
                    return;
                } else
                    break;
            case TypesPackage.UNDEFINED_TYPE:
                sequence_UndefinedType(context, (UndefinedType) semanticObject);
                return;
            case TypesPackage.VIRTUAL_BASE_TYPE:
                sequence_VirtualBaseType(context, (VirtualBaseType) semanticObject);
                return;
            case TypesPackage.VOID_TYPE:
                sequence_VoidType(context, (VoidType) semanticObject);
                return;
        }
    if (errorAcceptor != null)
        errorAcceptor.accept(diagnosticProvider.createInvalidContextOrTypeDiagnostic(semanticObject, context));
}
Also used : ParserRule(org.eclipse.xtext.ParserRule) Action(org.eclipse.xtext.Action) FunctionTypeExpression(org.eclipse.n4js.ts.typeRefs.FunctionTypeExpression) TMethod(org.eclipse.n4js.ts.types.TMethod) VersionedParameterizedTypeRefStructural(org.eclipse.n4js.ts.typeRefs.VersionedParameterizedTypeRefStructural) ParameterizedTypeRefStructural(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRefStructural) UnionTypeExpression(org.eclipse.n4js.ts.typeRefs.UnionTypeExpression) VersionedParameterizedTypeRefStructural(org.eclipse.n4js.ts.typeRefs.VersionedParameterizedTypeRefStructural) ThisTypeRefNominal(org.eclipse.n4js.ts.typeRefs.ThisTypeRefNominal) EPackage(org.eclipse.emf.ecore.EPackage) ParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef) VersionedParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.VersionedParameterizedTypeRef) Wildcard(org.eclipse.n4js.ts.typeRefs.Wildcard) TypeVariable(org.eclipse.n4js.ts.types.TypeVariable) ThisTypeRefStructural(org.eclipse.n4js.ts.typeRefs.ThisTypeRefStructural) TypeTypeRef(org.eclipse.n4js.ts.typeRefs.TypeTypeRef) TAnonymousFormalParameter(org.eclipse.n4js.ts.types.TAnonymousFormalParameter) TFormalParameter(org.eclipse.n4js.ts.types.TFormalParameter) Parameter(org.eclipse.xtext.Parameter) IntersectionTypeExpression(org.eclipse.n4js.ts.typeRefs.IntersectionTypeExpression) VersionedParameterizedTypeRef(org.eclipse.n4js.ts.typeRefs.VersionedParameterizedTypeRef)

Example 19 with TMethod

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

Example 20 with TMethod

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

the class N4JSMemberRedefinitionValidator method constraints_60_InheritedConsumedCovariantSpecConstructor.

/**
 * Checks a certain special case of Constraints 60 related to &#64;Spec constructors: if the classifier being
 * validated does *not* have an owned constructor, normally nothing would be checked; in case of &#64;Spec
 * constructors, however, we have to check that the inherited/consumed constructor (if any) is compatible to itself
 * within the classifier being validated:
 *
 * <pre>
 * class C {
 *     &#64;CovariantConstructor constructor(&#64;Spec spec: ~i~this) {}
 * }
 * class D { // &lt;-- must show error here, because inherited &#64;Spec constructor not compatible to itself
 *     public badField;
 * }
 * </pre>
 */
private boolean constraints_60_InheritedConsumedCovariantSpecConstructor(TClassifier tClassifier, MemberMatrix mm) {
    boolean isValid = true;
    if (!mm.hasOwned()) {
        final TMember firstInherited = mm.hasInherited() ? mm.inherited().iterator().next() : null;
        if (firstInherited instanceof TMethod && firstInherited.isConstructor() && isCovarianceForConstructorsRequired(tClassifier, firstInherited)) {
            isValid &= checkSpecConstructorOverrideCompatibility(tClassifier, (TMethod) firstInherited);
        }
        final TMember firstImplemented = mm.hasImplemented() ? mm.implemented().iterator().next() : null;
        if (firstImplemented instanceof TMethod && firstImplemented.isConstructor() && isCovarianceForConstructorsRequired(tClassifier, firstImplemented)) {
            isValid &= checkSpecConstructorOverrideCompatibility(tClassifier, (TMethod) firstImplemented);
        }
    }
    return isValid;
}
Also used : TMethod(org.eclipse.n4js.ts.types.TMethod) TMember(org.eclipse.n4js.ts.types.TMember)

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