Search in sources :

Example 16 with JvmTypeParameter

use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.

the class ActualTypeArgumentMergeTest method merge.

public Pair<Map<JvmTypeParameter, List<LightweightBoundTypeArgument>>, LightweightMergedBoundTypeArgument> merge(final Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> mapping, final String typeParamName) {
    final Set<JvmTypeParameter> allKeys = mapping.keySet();
    for (final JvmTypeParameter key : allKeys) {
        String _simpleName = key.getSimpleName();
        boolean _equals = Objects.equal(_simpleName, typeParamName);
        if (_equals) {
            final List<LightweightBoundTypeArgument> mappingData = mapping.get(key);
            LightweightMergedBoundTypeArgument _merge = this.merger.merge(mappingData, this.getOwner());
            return Pair.<Map<JvmTypeParameter, List<LightweightBoundTypeArgument>>, LightweightMergedBoundTypeArgument>of(mapping, _merge);
        }
    }
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("No mapping for ");
    _builder.append(typeParamName);
    _builder.append(" in ");
    final Function1<JvmTypeParameter, String> _function = (JvmTypeParameter it) -> {
        return it.getSimpleName();
    };
    Iterable<String> _map = IterableExtensions.<JvmTypeParameter, String>map(mapping.keySet(), _function);
    _builder.append(_map);
    Assert.fail(_builder.toString());
    return null;
}
Also used : LightweightMergedBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightMergedBoundTypeArgument) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) LightweightBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument) Map(java.util.Map)

Example 17 with JvmTypeParameter

use of org.eclipse.xtext.common.types.JvmTypeParameter 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)

Example 18 with JvmTypeParameter

use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.

the class XtendJvmModelInferrer method copyTypeParameters.

protected void copyTypeParameters(List<JvmTypeParameter> typeParameters, JvmTypeParameterDeclarator target) {
    for (JvmTypeParameter typeParameter : typeParameters) {
        if (!Strings.isEmpty(typeParameter.getName())) {
            final JvmTypeParameter clonedTypeParameter = jvmTypesBuilder.cloneWithProxies(typeParameter);
            if (clonedTypeParameter != null) {
                target.getTypeParameters().add(clonedTypeParameter);
                associator.associate(typeParameter, clonedTypeParameter);
            }
        }
    }
}
Also used : JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter)

Example 19 with JvmTypeParameter

use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.

the class SimpleUnboundTypeReference method createCopy.

@Override
protected UnboundTypeReference createCopy(final ITypeReferenceOwner owner) {
    JvmTypeParameter _typeParameter = this.getTypeParameter();
    Object _handle = this.getHandle();
    return new SimpleUnboundTypeReference(owner, _typeParameter, _handle);
}
Also used : JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter)

Example 20 with JvmTypeParameter

use of org.eclipse.xtext.common.types.JvmTypeParameter in project xtext-xtend by eclipse.

the class DeferredTypeParameterHintCollectorTest method hasHintsFor.

public List<LightweightBoundTypeArgument> hasHintsFor(final Map<JvmTypeParameter, LightweightMergedBoundTypeArgument> mapping, final String typeParamName) {
    final Set<JvmTypeParameter> allKeys = mapping.keySet();
    for (final JvmTypeParameter key : allKeys) {
        String _simpleName = key.getSimpleName();
        boolean _equals = Objects.equal(_simpleName, typeParamName);
        if (_equals) {
            LightweightTypeReference _typeReference = mapping.get(key).getTypeReference();
            final UnboundTypeReference unbound = ((UnboundTypeReference) _typeReference);
            final Consumer<LightweightBoundTypeArgument> _function = (LightweightBoundTypeArgument it) -> {
                Assert.assertEquals(BoundTypeArgumentSource.INFERRED_LATER, it.getSource());
            };
            unbound.getAllHints().forEach(_function);
            return unbound.getAllHints();
        }
    }
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("No mapping for ");
    _builder.append(typeParamName);
    _builder.append(" in ");
    final Function1<JvmTypeParameter, String> _function_1 = (JvmTypeParameter it) -> {
        return it.getSimpleName();
    };
    Iterable<String> _map = IterableExtensions.<JvmTypeParameter, String>map(mapping.keySet(), _function_1);
    _builder.append(_map);
    Assert.fail(_builder.toString());
    return null;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) UnboundTypeReference(org.eclipse.xtext.xbase.typesystem.references.UnboundTypeReference) LightweightBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)

Aggregations

JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)57 Test (org.junit.Test)20 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)16 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)14 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)13 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)12 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)12 JvmUpperBound (org.eclipse.xtext.common.types.JvmUpperBound)10 Procedure1 (org.eclipse.xtext.xbase.lib.Procedures.Procedure1)8 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)7 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)7 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)6 List (java.util.List)5 EList (org.eclipse.emf.common.util.EList)5 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)5 EObject (org.eclipse.emf.ecore.EObject)4 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)4 ArrayList (java.util.ArrayList)3 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)3 AbstractMethodBuilder (org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder)3