Search in sources :

Example 1 with AnyTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.AnyTypeReference in project xtext-xtend by eclipse.

the class CommonSuperTypeTest method testCommonSuperType_23.

@Test
public void testCommonSuperType_23() {
    try {
        this.function("def void m() {}");
        ITypeReferenceOwner _owner = this.getOwner();
        AnyTypeReference _anyTypeReference = new AnyTypeReference(_owner);
        ITypeReferenceOwner _owner_1 = this.getOwner();
        AnyTypeReference _anyTypeReference_1 = new AnyTypeReference(_owner_1);
        final List<LightweightTypeReference> types = CollectionLiterals.<LightweightTypeReference>newImmutableList(_anyTypeReference, _anyTypeReference_1);
        final LightweightTypeReference superType = this.getServices().getTypeConformanceComputer().getCommonSuperType(types, this.getOwner());
        Assert.assertEquals("null", superType.getSimpleName());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) AnyTypeReference(org.eclipse.xtext.xbase.typesystem.references.AnyTypeReference) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) Test(org.junit.Test)

Example 2 with AnyTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.AnyTypeReference in project xtext-xtend by eclipse.

the class CommonSuperTypeTest method isSuperTypeOf.

public Object isSuperTypeOf(final Pair<String, String> superTypeAndParam, final String... types) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def ");
        {
            boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(superTypeAndParam.getValue());
            boolean _not = (!_isNullOrEmpty);
            if (_not) {
                _builder.append("<");
                String _value = superTypeAndParam.getValue();
                _builder.append(_value);
                _builder.append("> ");
            }
        }
        _builder.append("void method(");
        {
            boolean _hasElements = false;
            for (final String type : types) {
                if (!_hasElements) {
                    _hasElements = true;
                } else {
                    _builder.appendImmediate(", ", "");
                }
                String _fixup = this.fixup(type);
                _builder.append(_fixup);
                _builder.append(" t");
            }
        }
        _builder.append(") {}");
        final String signature = _builder.toString();
        final XtendFunction function = this.function(signature.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        final Function1<JvmFormalParameter, LightweightTypeReference> _function = (JvmFormalParameter it) -> {
            return this.toLightweightTypeReference(it.getParameterType());
        };
        List<LightweightTypeReference> _map = ListExtensions.<JvmFormalParameter, LightweightTypeReference>map(operation.getParameters(), _function);
        final ArrayList<LightweightTypeReference> typeReferences = new ArrayList<LightweightTypeReference>(_map);
        final TypeConformanceComputer conformanceComputer = this.getServices().getTypeConformanceComputer();
        LightweightTypeReference computedSuperType = conformanceComputer.getCommonSuperType(typeReferences, this.getOwner());
        String _simpleName = null;
        if (computedSuperType != null) {
            _simpleName = computedSuperType.getSimpleName();
        }
        Assert.assertEquals(superTypeAndParam.getKey(), _simpleName);
        computedSuperType = this.getServices().getTypeConformanceComputer().getCommonSuperType(IterableExtensions.<LightweightTypeReference>toList(Iterables.<LightweightTypeReference>concat(typeReferences, typeReferences)), this.getOwner());
        String _simpleName_1 = null;
        if (computedSuperType != null) {
            _simpleName_1 = computedSuperType.getSimpleName();
        }
        Assert.assertEquals(superTypeAndParam.getKey(), _simpleName_1);
        computedSuperType = this.getServices().getTypeConformanceComputer().getCommonSuperType(ListExtensions.<LightweightTypeReference>reverseView(typeReferences), this.getOwner());
        String _simpleName_2 = null;
        if (computedSuperType != null) {
            _simpleName_2 = computedSuperType.getSimpleName();
        }
        Assert.assertEquals(superTypeAndParam.getKey(), _simpleName_2);
        boolean _isPrimitiveOrVoid = this.isPrimitiveOrVoid(computedSuperType);
        boolean _not_1 = (!_isPrimitiveOrVoid);
        if (_not_1) {
            List<AnyTypeReference> _newImmutableList = CollectionLiterals.<AnyTypeReference>newImmutableList(this.getOwner().newAnyTypeReference(), this.getOwner().newAnyTypeReference());
            computedSuperType = this.getServices().getTypeConformanceComputer().getCommonSuperType(IterableExtensions.<LightweightTypeReference>toList(Iterables.<LightweightTypeReference>concat(typeReferences, _newImmutableList)), this.getOwner());
            String _simpleName_3 = null;
            if (computedSuperType != null) {
                _simpleName_3 = computedSuperType.getSimpleName();
            }
            Assert.assertEquals(superTypeAndParam.getKey(), _simpleName_3);
        }
        if ((computedSuperType != null)) {
            final Procedure1<LightweightTypeReference> _function_1 = (LightweightTypeReference superType) -> {
                final Consumer<LightweightTypeReference> _function_2 = (LightweightTypeReference it) -> {
                    LightweightTypeReference _commonSuperType = conformanceComputer.getCommonSuperType(Collections.<LightweightTypeReference>unmodifiableList(CollectionLiterals.<LightweightTypeReference>newArrayList(it, superType)), superType.getOwner());
                    String _simpleName_4 = null;
                    if (_commonSuperType != null) {
                        _simpleName_4 = _commonSuperType.getSimpleName();
                    }
                    Assert.assertEquals(superTypeAndParam.getKey(), _simpleName_4);
                };
                typeReferences.forEach(_function_2);
            };
            ObjectExtensions.<LightweightTypeReference>operator_doubleArrow(computedSuperType, _function_1);
        }
        if ((computedSuperType != null)) {
            for (final LightweightTypeReference subType : typeReferences) {
                Assert.assertTrue(computedSuperType.isAssignableFrom(subType));
            }
        }
        return computedSuperType;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) ArrayList(java.util.ArrayList) AnyTypeReference(org.eclipse.xtext.xbase.typesystem.references.AnyTypeReference) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) TypeConformanceComputer(org.eclipse.xtext.xbase.typesystem.conformance.TypeConformanceComputer) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) Consumer(java.util.function.Consumer) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Aggregations

AnyTypeReference (org.eclipse.xtext.xbase.typesystem.references.AnyTypeReference)2 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)2 ArrayList (java.util.ArrayList)1 Consumer (java.util.function.Consumer)1 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)1 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)1 TypeConformanceComputer (org.eclipse.xtext.xbase.typesystem.conformance.TypeConformanceComputer)1 ITypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner)1 Test (org.junit.Test)1