Search in sources :

Example 1 with ActualTypeArgumentCollector

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

the class ActualTypeArgumentCollectorTest method mappedBy.

public Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> mappedBy(final String typeParameters, final String... alternatingTypeReferences) {
    final JvmOperation operation = this.operation(typeParameters, alternatingTypeReferences);
    EList<JvmTypeParameter> _typeParameters = operation.getTypeParameters();
    ITypeReferenceOwner _owner = this.getOwner();
    final ActualTypeArgumentCollector collector = new ActualTypeArgumentCollector(_typeParameters, BoundTypeArgumentSource.INFERRED, _owner);
    int _size = ((List<String>) Conversions.doWrapArray(alternatingTypeReferences)).size();
    int _minus = (_size - 1);
    IntegerRange _withStep = new IntegerRange(0, _minus).withStep(2);
    for (final Integer i : _withStep) {
        collector.populateTypeParameterMapping(this.toLightweightTypeReference(operation.getParameters().get((i).intValue()).getParameterType()), this.toLightweightTypeReference(operation.getParameters().get(((i).intValue() + 1)).getParameterType()));
    }
    return collector.getTypeParameterMapping();
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) EList(org.eclipse.emf.common.util.EList) List(java.util.List) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) ActualTypeArgumentCollector(org.eclipse.xtext.xbase.typesystem.util.ActualTypeArgumentCollector)

Example 2 with ActualTypeArgumentCollector

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

the class ActualTypeArgumentMergeTest method mappedBy.

public Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> mappedBy(final String typeParameters, final String... alternatingTypeReferences) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def ");
        {
            boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(typeParameters);
            boolean _not = (!_isNullOrEmpty);
            if (_not) {
                _builder.append("<");
                _builder.append(typeParameters);
                _builder.append(">");
            }
        }
        _builder.append(" void method(");
        final Function1<String, CharSequence> _function = (String it) -> {
            return it;
        };
        String _join = IterableExtensions.<String>join(((Iterable<String>) Conversions.doWrapArray(alternatingTypeReferences)), 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);
        EList<JvmTypeParameter> _typeParameters = operation.getTypeParameters();
        ITypeReferenceOwner _owner = this.getOwner();
        final ActualTypeArgumentCollector collector = new ActualTypeArgumentCollector(_typeParameters, BoundTypeArgumentSource.INFERRED, _owner);
        int _size = ((List<String>) Conversions.doWrapArray(alternatingTypeReferences)).size();
        int _minus = (_size - 1);
        IntegerRange _withStep = new IntegerRange(0, _minus).withStep(2);
        for (final Integer i : _withStep) {
            collector.populateTypeParameterMapping(this.toLightweightTypeReference(operation.getParameters().get((i).intValue()).getParameterType()), this.toLightweightTypeReference(operation.getParameters().get(((i).intValue() + 1)).getParameterType()));
        }
        return collector.getTypeParameterMapping();
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) EList(org.eclipse.emf.common.util.EList) List(java.util.List) ActualTypeArgumentCollector(org.eclipse.xtext.xbase.typesystem.util.ActualTypeArgumentCollector)

Aggregations

List (java.util.List)2 EList (org.eclipse.emf.common.util.EList)2 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)2 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)2 IntegerRange (org.eclipse.xtext.xbase.lib.IntegerRange)2 ITypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner)2 ActualTypeArgumentCollector (org.eclipse.xtext.xbase.typesystem.util.ActualTypeArgumentCollector)2 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1