Search in sources :

Example 21 with TypeArgument

use of org.eclipse.n4js.ts.typeRefs.TypeArgument in project n4js by eclipse.

the class VersionedParameterizedTypeRefStructural_IMImpl method getTypeRefAsString.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String getTypeRefAsString() {
    TypingStrategy _typingStrategy = this.getTypingStrategy();
    Type _declaredType = this.getDeclaredType();
    String _rawTypeAsString = null;
    if (_declaredType != null) {
        _rawTypeAsString = _declaredType.getRawTypeAsString();
    }
    String _plus = (_typingStrategy + _rawTypeAsString);
    String _xifexpression = null;
    boolean _isEmpty = this.getTypeArgs().isEmpty();
    if (_isEmpty) {
        _xifexpression = "";
    } else {
        final Function1<TypeArgument, String> _function = new Function1<TypeArgument, String>() {

            public String apply(final TypeArgument it) {
                return it.getTypeRefAsString();
            }
        };
        String _join = IterableExtensions.join(XcoreEListExtensions.<TypeArgument, String>map(this.getTypeArgs(), _function), ",");
        String _plus_1 = ("<" + _join);
        _xifexpression = (_plus_1 + ">");
    }
    String _plus_2 = (_plus + _xifexpression);
    String _xifexpression_1 = null;
    boolean _isEmpty_1 = this.getStructuralMembers().isEmpty();
    if (_isEmpty_1) {
        _xifexpression_1 = "";
    } else {
        final Function1<TStructMember, String> _function_1 = new Function1<TStructMember, String>() {

            public String apply(final TStructMember it) {
                return it.getMemberAsString();
            }
        };
        String _join_1 = IterableExtensions.join(XcoreEListExtensions.<TStructMember, String>map(this.getStructuralMembers(), _function_1), "; ");
        String _plus_3 = (" with { " + _join_1);
        String _plus_4 = (_plus_3 + " }");
        String _xifexpression_2 = null;
        boolean _isEmpty_2 = this.getPostponedSubstitutions().isEmpty();
        if (_isEmpty_2) {
            _xifexpression_2 = "";
        } else {
            final Function1<TypeVariableMapping, String> _function_2 = new Function1<TypeVariableMapping, String>() {

                public String apply(final TypeVariableMapping it) {
                    String _typeAsString = it.getTypeVar().getTypeAsString();
                    String _plus = (_typeAsString + "->");
                    String _typeRefAsString = it.getTypeArg().getTypeRefAsString();
                    return (_plus + _typeRefAsString);
                }
            };
            String _join_2 = IterableExtensions.join(XcoreEListExtensions.<TypeVariableMapping, String>map(this.getPostponedSubstitutions(), _function_2), ", ");
            String _plus_5 = (" [[" + _join_2);
            _xifexpression_2 = (_plus_5 + "]]");
        }
        _xifexpression_1 = (_plus_4 + _xifexpression_2);
    }
    return (_plus_2 + _xifexpression_1);
}
Also used : TypingStrategy(org.eclipse.n4js.ts.types.TypingStrategy) Type(org.eclipse.n4js.ts.types.Type) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) TStructMember(org.eclipse.n4js.ts.types.TStructMember) TypeVariableMapping(org.eclipse.n4js.ts.typeRefs.TypeVariableMapping) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument)

Example 22 with TypeArgument

use of org.eclipse.n4js.ts.typeRefs.TypeArgument in project n4js by eclipse.

the class ParameterizedTypeRefImpl method getTypeRefAsString.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String getTypeRefAsString() {
    Type _declaredType = this.getDeclaredType();
    String _rawTypeAsString = null;
    if (_declaredType != null) {
        _rawTypeAsString = _declaredType.getRawTypeAsString();
    }
    String _xifexpression = null;
    int _version = this.getVersion();
    boolean _greaterThan = (_version > 0);
    if (_greaterThan) {
        int _version_1 = this.getVersion();
        _xifexpression = ("#" + Integer.valueOf(_version_1));
    } else {
        String _xifexpression_1 = null;
        boolean _isEmpty = this.getTypeArgs().isEmpty();
        if (_isEmpty) {
            _xifexpression_1 = "";
        } else {
            final Function1<TypeArgument, String> _function = new Function1<TypeArgument, String>() {

                public String apply(final TypeArgument it) {
                    return it.getTypeRefAsString();
                }
            };
            String _join = IterableExtensions.join(XcoreEListExtensions.<TypeArgument, String>map(this.getTypeArgs(), _function), ",");
            String _plus = ("<" + _join);
            _xifexpression_1 = (_plus + ">");
        }
        String _plus_1 = ("" + _xifexpression_1);
        String _modifiersAsString = this.getModifiersAsString();
        _xifexpression = (_plus_1 + _modifiersAsString);
    }
    return (_rawTypeAsString + _xifexpression);
}
Also used : Type(org.eclipse.n4js.ts.types.Type) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument)

Example 23 with TypeArgument

use of org.eclipse.n4js.ts.typeRefs.TypeArgument in project n4js by eclipse.

the class VersionedParameterizedTypeRefStructuralImpl method getTypeRefAsString.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String getTypeRefAsString() {
    TypingStrategy _typingStrategy = this.getTypingStrategy();
    Type _declaredType = this.getDeclaredType();
    String _rawTypeAsString = null;
    if (_declaredType != null) {
        _rawTypeAsString = _declaredType.getRawTypeAsString();
    }
    String _plus = (_typingStrategy + _rawTypeAsString);
    String _xifexpression = null;
    boolean _isEmpty = this.getTypeArgs().isEmpty();
    if (_isEmpty) {
        _xifexpression = "";
    } else {
        final Function1<TypeArgument, String> _function = new Function1<TypeArgument, String>() {

            public String apply(final TypeArgument it) {
                return it.getTypeRefAsString();
            }
        };
        String _join = IterableExtensions.join(XcoreEListExtensions.<TypeArgument, String>map(this.getTypeArgs(), _function), ",");
        String _plus_1 = ("<" + _join);
        _xifexpression = (_plus_1 + ">");
    }
    String _plus_2 = (_plus + _xifexpression);
    String _xifexpression_1 = null;
    boolean _isEmpty_1 = this.getStructuralMembers().isEmpty();
    if (_isEmpty_1) {
        _xifexpression_1 = "";
    } else {
        final Function1<TStructMember, String> _function_1 = new Function1<TStructMember, String>() {

            public String apply(final TStructMember it) {
                return it.getMemberAsString();
            }
        };
        String _join_1 = IterableExtensions.join(XcoreEListExtensions.<TStructMember, String>map(this.getStructuralMembers(), _function_1), "; ");
        String _plus_3 = (" with { " + _join_1);
        String _plus_4 = (_plus_3 + " }");
        String _xifexpression_2 = null;
        boolean _isEmpty_2 = this.getPostponedSubstitutions().isEmpty();
        if (_isEmpty_2) {
            _xifexpression_2 = "";
        } else {
            final Function1<TypeVariableMapping, String> _function_2 = new Function1<TypeVariableMapping, String>() {

                public String apply(final TypeVariableMapping it) {
                    String _typeAsString = it.getTypeVar().getTypeAsString();
                    String _plus = (_typeAsString + "->");
                    String _typeRefAsString = it.getTypeArg().getTypeRefAsString();
                    return (_plus + _typeRefAsString);
                }
            };
            String _join_2 = IterableExtensions.join(XcoreEListExtensions.<TypeVariableMapping, String>map(this.getPostponedSubstitutions(), _function_2), ", ");
            String _plus_5 = (" [[" + _join_2);
            _xifexpression_2 = (_plus_5 + "]]");
        }
        _xifexpression_1 = (_plus_4 + _xifexpression_2);
    }
    return (_plus_2 + _xifexpression_1);
}
Also used : TypingStrategy(org.eclipse.n4js.ts.types.TypingStrategy) Type(org.eclipse.n4js.ts.types.Type) TStructuralType(org.eclipse.n4js.ts.types.TStructuralType) TStructMember(org.eclipse.n4js.ts.types.TStructMember) TypeVariableMapping(org.eclipse.n4js.ts.typeRefs.TypeVariableMapping) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument)

Example 24 with TypeArgument

use of org.eclipse.n4js.ts.typeRefs.TypeArgument in project n4js by eclipse.

the class TypeUtils method createPromiseTypeRef.

/**
 * For the given success and failure value types, this method returns a Promise<R,?> type reference. The failure
 * type is optional (i.e. may be <code>null</code>). A success value type of <code>void</code> will be changed to
 * type <code>undefined</code>, because <code>void</code> is not a valid type argument.
 * <p>
 * WARNING: this method will resolve proxies in 'successType' (in order to check if it points to type 'void')
 */
public static ParameterizedTypeRef createPromiseTypeRef(BuiltInTypeScope scope, TypeArgument successType, TypeArgument failureTypeOrNull) {
    Objects.requireNonNull(successType);
    TypeArgument successTypeArg = isVoid(successType) ? scope.getUndefinedTypeRef() : TypeUtils.copyWithProxies(successType);
    TypeArgument failureTypeArg = failureTypeOrNull != null ? TypeUtils.copyWithProxies(failureTypeOrNull) : TypeRefsFactory.eINSTANCE.createWildcard();
    return createTypeRef(scope.getPromiseType(), successTypeArg, failureTypeArg);
}
Also used : TypeArgument(org.eclipse.n4js.ts.typeRefs.TypeArgument)

Example 25 with TypeArgument

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

Aggregations

TypeArgument (org.eclipse.n4js.ts.typeRefs.TypeArgument)44 ParameterizedTypeRef (org.eclipse.n4js.ts.typeRefs.ParameterizedTypeRef)22 TypeTypeRef (org.eclipse.n4js.ts.typeRefs.TypeTypeRef)21 ComposedTypeRef (org.eclipse.n4js.ts.typeRefs.ComposedTypeRef)19 ExistentialTypeRef (org.eclipse.n4js.ts.typeRefs.ExistentialTypeRef)19 TypeRef (org.eclipse.n4js.ts.typeRefs.TypeRef)19 BoundThisTypeRef (org.eclipse.n4js.ts.typeRefs.BoundThisTypeRef)18 BaseTypeRef (org.eclipse.n4js.ts.typeRefs.BaseTypeRef)17 FunctionTypeRef (org.eclipse.n4js.ts.typeRefs.FunctionTypeRef)17 StructuralTypeRef (org.eclipse.n4js.ts.typeRefs.StructuralTypeRef)17 ThisTypeRef (org.eclipse.n4js.ts.typeRefs.ThisTypeRef)17 StructuralTypingResult (org.eclipse.n4js.typesystem.StructuralTypingResult)16 Result (org.eclipse.xsemantics.runtime.Result)16 StaticBaseTypeRef (org.eclipse.n4js.ts.typeRefs.StaticBaseTypeRef)15 UnknownTypeRef (org.eclipse.n4js.ts.typeRefs.UnknownTypeRef)15 RuleFailedException (org.eclipse.xsemantics.runtime.RuleFailedException)15 EObject (org.eclipse.emf.ecore.EObject)14 Type (org.eclipse.n4js.ts.types.Type)14 TStructuralType (org.eclipse.n4js.ts.types.TStructuralType)13 RuleEnvironment (org.eclipse.xsemantics.runtime.RuleEnvironment)12