Search in sources :

Example 1 with VarianceInfo

use of org.eclipse.xtext.xbase.typesystem.util.VarianceInfo in project xtext-xtend by eclipse.

the class ActualTypeArgumentCollectorTest method assertMapping.

public Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> assertMapping(final Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> mapping, final String typeParamName, final Triple<String, VarianceInfo, VarianceInfo>... mappedTypes) {
    final Set<JvmTypeParameter> allKeys = mapping.keySet();
    for (final JvmTypeParameter key : allKeys) {
        String _simpleName = key.getSimpleName();
        boolean _equals = Objects.equal(_simpleName, typeParamName);
        if (_equals) {
            Assert.assertNotNull(mappedTypes);
            final List<LightweightBoundTypeArgument> mappingData = mapping.get(key);
            final Function1<LightweightBoundTypeArgument, String> _function = (LightweightBoundTypeArgument it) -> {
                StringConcatenation _builder = new StringConcatenation();
                LightweightTypeReference _typeReference = it.getTypeReference();
                _builder.append(_typeReference);
                _builder.append("(");
                VarianceInfo _declaredVariance = it.getDeclaredVariance();
                _builder.append(_declaredVariance);
                _builder.append("/");
                VarianceInfo _actualVariance = it.getActualVariance();
                _builder.append(_actualVariance);
                _builder.append(")");
                return _builder.toString();
            };
            Assert.assertEquals(ListExtensions.<LightweightBoundTypeArgument, String>map(mappingData, _function).toString(), ((List<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mappedTypes)).size(), mappingData.size());
            final Function1<LightweightBoundTypeArgument, Triple<String, VarianceInfo, VarianceInfo>> _function_1 = (LightweightBoundTypeArgument it) -> {
                return Tuples.<String, VarianceInfo, VarianceInfo>create(it.getTypeReference().toString(), it.getDeclaredVariance(), it.getActualVariance());
            };
            Assert.assertEquals(IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>toList(((Iterable<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mappedTypes))), IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>toList(ListExtensions.<LightweightBoundTypeArgument, Triple<String, VarianceInfo, VarianceInfo>>map(mappingData, _function_1)));
            return mapping;
        }
    }
    if ((mappedTypes != null)) {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("No mapping for ");
        _builder.append(typeParamName);
        _builder.append(" in ");
        final Function1<JvmTypeParameter, String> _function_2 = (JvmTypeParameter it) -> {
            return it.getSimpleName();
        };
        Iterable<String> _map = IterableExtensions.<JvmTypeParameter, String>map(mapping.keySet(), _function_2);
        _builder.append(_map);
        Assert.fail(_builder.toString());
    }
    return mapping;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) VarianceInfo(org.eclipse.xtext.xbase.typesystem.util.VarianceInfo) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Triple(org.eclipse.xtext.util.Triple) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) LightweightBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)

Example 2 with VarianceInfo

use of org.eclipse.xtext.xbase.typesystem.util.VarianceInfo in project xtext-xtend by eclipse.

the class DeferredTypeParameterHintCollectorTest method like.

public List<LightweightBoundTypeArgument> like(final List<LightweightBoundTypeArgument> mappingData, final Triple<String, VarianceInfo, VarianceInfo>... mappedTypes) {
    final Function1<LightweightBoundTypeArgument, String> _function = (LightweightBoundTypeArgument it) -> {
        StringConcatenation _builder = new StringConcatenation();
        String _string = it.getTypeReference().toString();
        _builder.append(_string);
        _builder.append("(");
        VarianceInfo _declaredVariance = it.getDeclaredVariance();
        _builder.append(_declaredVariance);
        _builder.append("/");
        VarianceInfo _actualVariance = it.getActualVariance();
        _builder.append(_actualVariance);
        _builder.append(")");
        return _builder.toString();
    };
    Assert.assertEquals(ListExtensions.<LightweightBoundTypeArgument, String>map(mappingData, _function).toString(), ((List<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mappedTypes)).size(), mappingData.size());
    List<Triple<String, VarianceInfo, VarianceInfo>> _list = IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>toList(((Iterable<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mappedTypes)));
    final Function1<LightweightBoundTypeArgument, Triple<String, VarianceInfo, VarianceInfo>> _function_1 = (LightweightBoundTypeArgument it) -> {
        return Tuples.<String, VarianceInfo, VarianceInfo>create(it.getTypeReference().toString(), it.getDeclaredVariance(), it.getActualVariance());
    };
    Assert.assertEquals(((Object) _list), IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>toList(ListExtensions.<LightweightBoundTypeArgument, Triple<String, VarianceInfo, VarianceInfo>>map(mappingData, _function_1)));
    return mappingData;
}
Also used : Triple(org.eclipse.xtext.util.Triple) VarianceInfo(org.eclipse.xtext.xbase.typesystem.util.VarianceInfo) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) LightweightBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)

Example 3 with VarianceInfo

use of org.eclipse.xtext.xbase.typesystem.util.VarianceInfo in project xtext-xtend by eclipse.

the class BoundTypeArgumentMergerTest method mergeSuccessive.

public LightweightMergedBoundTypeArgument mergeSuccessive(final Triple<String, VarianceInfo, VarianceInfo>... mergeUs) {
    try {
        int _length = mergeUs.length;
        boolean _greaterThan = (_length > 2);
        Assert.assertTrue(_greaterThan);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def void method(");
        final Function1<Triple<String, VarianceInfo, VarianceInfo>, CharSequence> _function = (Triple<String, VarianceInfo, VarianceInfo> it) -> {
            return it.getFirst();
        };
        String _join = IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>join(((Iterable<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mergeUs)), null, " p, ", " p", _function);
        _builder.append(_join);
        _builder.append(") {}");
        final String signature = _builder.toString();
        final XtendFunction function = this.function(signature.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        final ArrayList<LightweightBoundTypeArgument> mergable = CollectionLiterals.<LightweightBoundTypeArgument>newArrayList();
        final Procedure2<JvmFormalParameter, Integer> _function_1 = (JvmFormalParameter p, Integer i) -> {
            final Triple<String, VarianceInfo, VarianceInfo> input = mergeUs[(i).intValue()];
            LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(p.getParameterType());
            Object _object = new Object();
            VarianceInfo _second = input.getSecond();
            VarianceInfo _third = input.getThird();
            LightweightBoundTypeArgument _lightweightBoundTypeArgument = new LightweightBoundTypeArgument(_lightweightTypeReference, null, _object, _second, _third);
            mergable.add(_lightweightBoundTypeArgument);
        };
        IterableExtensions.<JvmFormalParameter>forEach(operation.getParameters(), _function_1);
        final Iterator<LightweightBoundTypeArgument> iterator = mergable.iterator();
        LightweightBoundTypeArgument first = iterator.next();
        LightweightBoundTypeArgument second = iterator.next();
        LightweightMergedBoundTypeArgument merged = this.merger.merge(Collections.<LightweightBoundTypeArgument>unmodifiableList(CollectionLiterals.<LightweightBoundTypeArgument>newArrayList(first, second)), this.getOwner());
        while (iterator.hasNext()) {
            {
                LightweightTypeReference _typeReference = merged.getTypeReference();
                Object _object = new Object();
                VarianceInfo _variance = merged.getVariance();
                VarianceInfo _variance_1 = merged.getVariance();
                LightweightBoundTypeArgument _lightweightBoundTypeArgument = new LightweightBoundTypeArgument(_typeReference, null, _object, _variance, _variance_1);
                first = _lightweightBoundTypeArgument;
                second = iterator.next();
                merged = this.merger.merge(Collections.<LightweightBoundTypeArgument>unmodifiableList(CollectionLiterals.<LightweightBoundTypeArgument>newArrayList(first, second)), this.getOwner());
            }
        }
        return merged;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) VarianceInfo(org.eclipse.xtext.xbase.typesystem.util.VarianceInfo) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) Triple(org.eclipse.xtext.util.Triple) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) LightweightMergedBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightMergedBoundTypeArgument) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) LightweightBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)

Example 4 with VarianceInfo

use of org.eclipse.xtext.xbase.typesystem.util.VarianceInfo in project xtext-xtend by eclipse.

the class BoundTypeArgumentMergerTest method mergeWithSource.

public LightweightMergedBoundTypeArgument mergeWithSource(final Object source, final Triple<String, VarianceInfo, VarianceInfo>... mergeUs) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def void method(");
        final Function1<Triple<String, VarianceInfo, VarianceInfo>, CharSequence> _function = (Triple<String, VarianceInfo, VarianceInfo> it) -> {
            return it.getFirst();
        };
        String _join = IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>join(((Iterable<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mergeUs)), null, " p, ", " p", _function);
        _builder.append(_join);
        _builder.append(") {}");
        final String signature = _builder.toString();
        final XtendFunction function = this.function(signature.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        final ArrayList<LightweightBoundTypeArgument> mergable = CollectionLiterals.<LightweightBoundTypeArgument>newArrayList();
        final Procedure2<JvmFormalParameter, Integer> _function_1 = (JvmFormalParameter p, Integer i) -> {
            final Triple<String, VarianceInfo, VarianceInfo> input = mergeUs[(i).intValue()];
            LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(p.getParameterType());
            Object _elvis = null;
            if (source != null) {
                _elvis = source;
            } else {
                Object _object = new Object();
                _elvis = _object;
            }
            VarianceInfo _second = input.getSecond();
            VarianceInfo _third = input.getThird();
            LightweightBoundTypeArgument _lightweightBoundTypeArgument = new LightweightBoundTypeArgument(_lightweightTypeReference, null, _elvis, _second, _third);
            mergable.add(_lightweightBoundTypeArgument);
        };
        IterableExtensions.<JvmFormalParameter>forEach(operation.getParameters(), _function_1);
        return this.merger.merge(mergable, this.getOwner());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) VarianceInfo(org.eclipse.xtext.xbase.typesystem.util.VarianceInfo) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) Triple(org.eclipse.xtext.util.Triple) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) LightweightBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)

Aggregations

StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)4 Triple (org.eclipse.xtext.util.Triple)4 LightweightBoundTypeArgument (org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)4 VarianceInfo (org.eclipse.xtext.xbase.typesystem.util.VarianceInfo)4 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)3 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)2 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)2 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)2 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)1 LightweightMergedBoundTypeArgument (org.eclipse.xtext.xbase.typesystem.references.LightweightMergedBoundTypeArgument)1