Search in sources :

Example 11 with JvmTypeParameter

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

the class MutableJvmTypeParameterDeclarationImpl method setSimpleName.

@Override
public void setSimpleName(final String name) {
    this.checkMutable();
    ConditionUtils.checkJavaIdentifier(name, "name");
    JvmTypeParameter _delegate = this.getDelegate();
    _delegate.setName(name);
}
Also used : JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter)

Example 12 with JvmTypeParameter

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

the class MutableJvmTypeParameterDeclarationImpl method remove.

@Override
public void remove() {
    this.checkMutable();
    Resource _eResource = this.getDelegate().eResource();
    boolean _tripleNotEquals = (_eResource != null);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("This element has already been removed: ");
    JvmTypeParameter _delegate = this.getDelegate();
    _builder.append(_delegate);
    Preconditions.checkState(_tripleNotEquals, _builder);
    this.getCompilationUnit().getJvmModelAssociator().removeAllAssociation(this.getDelegate());
    EcoreUtil.remove(this.getDelegate());
    Resource _eResource_1 = this.getDelegate().eResource();
    boolean _tripleEquals = (_eResource_1 == null);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("Couldn\'t remove: ");
    JvmTypeParameter _delegate_1 = this.getDelegate();
    _builder_1.append(_delegate_1);
    Preconditions.checkState(_tripleEquals, _builder_1);
}
Also used : JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Resource(org.eclipse.emf.ecore.resource.Resource) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 13 with JvmTypeParameter

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

the class TypeReferenceProviderImpl method createTypeRef.

public JvmParameterizedTypeReference createTypeRef(final JvmType type, final JvmTypeReference... typeArgs) {
    if ((type == null)) {
        throw new NullPointerException("type");
    }
    final JvmParameterizedTypeReference reference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
    reference.setType(type);
    for (final JvmTypeReference typeArg : typeArgs) {
        reference.getArguments().add(EcoreUtil2.<JvmTypeReference>cloneIfContained(typeArg));
    }
    if ((type instanceof JvmGenericType)) {
        final EList<JvmTypeParameter> list = ((JvmGenericType) type).getTypeParameters();
        if (((!reference.getArguments().isEmpty()) && (list.size() != reference.getArguments().size()))) {
            String _identifier = ((JvmGenericType) type).getIdentifier();
            String _plus = ("The type " + _identifier);
            String _plus_1 = (_plus + " expects ");
            int _size = list.size();
            String _plus_2 = (_plus_1 + Integer.valueOf(_size));
            String _plus_3 = (_plus_2 + " type arguments, but was ");
            int _size_1 = reference.getArguments().size();
            String _plus_4 = (_plus_3 + Integer.valueOf(_size_1));
            String _plus_5 = (_plus_4 + ". Either pass zero arguments (raw type) or the correct number.");
            throw new IllegalArgumentException(_plus_5);
        }
    }
    return reference;
}
Also used : JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference)

Example 14 with JvmTypeParameter

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

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

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