Search in sources :

Example 31 with JvmTypeParameter

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

the class MemberFromSuperImplementor method appendOverrideFunction.

public void appendOverrideFunction(final XtendTypeDeclaration overrider, final IResolvedOperation overriddenOperation, final ISourceAppender appendable) {
    final JvmDeclaredType inferredType = this.associations.getInferredType(overrider);
    final AbstractMethodBuilder methodBuilder = this.codeBuilderFactory.createMethodBuilder(inferredType);
    this.initializeExecutableBuilder(methodBuilder, inferredType, overriddenOperation);
    methodBuilder.setOverrideFlag(true);
    methodBuilder.setMethodName(overriddenOperation.getDeclaration().getSimpleName());
    methodBuilder.setReturnType(overriddenOperation.getResolvedReturnType());
    boolean _isSynchronized = overriddenOperation.getDeclaration().isSynchronized();
    if (_isSynchronized) {
        methodBuilder.setSynchronizedFlag(true);
    }
    boolean _isEmpty = overriddenOperation.getResolvedTypeParameters().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        final ArrayList<JvmTypeParameter> typeParameters = CollectionLiterals.<JvmTypeParameter>newArrayList();
        final Procedure2<JvmTypeParameter, Integer> _function = (JvmTypeParameter typeParam, Integer idx) -> {
            final JvmTypeParameter newTypeParam = this.typesFactory.createJvmTypeParameter();
            newTypeParam.setName(typeParam.getName());
            final Consumer<LightweightTypeReference> _function_1 = (LightweightTypeReference it) -> {
                final JvmUpperBound upperBound = this.typesFactory.createJvmUpperBound();
                upperBound.setTypeReference(it.toJavaCompliantTypeReference());
                EList<JvmTypeConstraint> _constraints = newTypeParam.getConstraints();
                _constraints.add(upperBound);
            };
            overriddenOperation.getResolvedTypeParameterConstraints((idx).intValue()).forEach(_function_1);
            typeParameters.add(newTypeParam);
        };
        IterableExtensions.<JvmTypeParameter>forEach(overriddenOperation.getResolvedTypeParameters(), _function);
        methodBuilder.setTypeParameters(typeParameters);
    }
    boolean _isAbstract = overriddenOperation.getDeclaration().isAbstract();
    boolean _not_1 = (!_isAbstract);
    if (_not_1) {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("super.");
        {
            List<JvmTypeParameter> _resolvedTypeParameters = overriddenOperation.getResolvedTypeParameters();
            boolean _hasElements = false;
            for (final JvmTypeParameter typeParam : _resolvedTypeParameters) {
                if (!_hasElements) {
                    _hasElements = true;
                    _builder.append("<");
                } else {
                    _builder.appendImmediate(", ", "");
                }
                String _simpleName = typeParam.getSimpleName();
                _builder.append(_simpleName);
            }
            if (_hasElements) {
                _builder.append(">");
            }
        }
        String _simpleName_1 = overriddenOperation.getDeclaration().getSimpleName();
        _builder.append(_simpleName_1);
        _builder.append("(");
        final Function1<JvmFormalParameter, String> _function_1 = (JvmFormalParameter it) -> {
            return it.getSimpleName();
        };
        String _join = IterableExtensions.join(ListExtensions.<JvmFormalParameter, String>map(overriddenOperation.getDeclaration().getParameters(), _function_1), ", ");
        _builder.append(_join);
        _builder.append(")");
        final String body = _builder.toString();
        final Procedure1<? super ISourceAppender> superTypeRef = this.getImplementedInterface(inferredType, overriddenOperation.getDeclaration().getDeclaringType());
        final Procedure1<ISourceAppender> _function_2 = (ISourceAppender it) -> {
            if (superTypeRef != null) {
                superTypeRef.apply(it);
            }
            it.append(body);
        };
        methodBuilder.setBodyGenerator(_function_2);
    }
    boolean _isValid = methodBuilder.isValid();
    if (_isValid) {
        methodBuilder.build(appendable);
    }
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender) JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) Consumer(java.util.function.Consumer) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) AbstractMethodBuilder(org.eclipse.xtend.ide.codebuilder.AbstractMethodBuilder)

Example 32 with JvmTypeParameter

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

the class XtendFormatter method _format.

protected void _format(final XtendConstructor func, @Extension final IFormattableDocument format) {
    this.formatAnnotations(func, format, XbaseFormatterPreferenceKeys.newLineAfterConstructorAnnotations);
    this.formatModifiers(func, format);
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.noSpace();
    };
    format.append(this.textRegionExtensions.regionFor(func).keyword("new"), _function);
    boolean _isEmpty = func.getTypeParameters().isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        format.append(this.textRegionExtensions.regionFor(func).keyword("<"), _function_1);
        EList<JvmTypeParameter> _typeParameters = func.getTypeParameters();
        for (final JvmTypeParameter arg : _typeParameters) {
            {
                format.<JvmTypeParameter>format(arg);
                final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                    it.noSpace();
                };
                final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
                    it.oneSpace();
                };
                format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(arg).keyword(","), _function_2), _function_3);
            }
        }
        final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
            it.noSpace();
        };
        format.surround(this.textRegionExtensions.regionFor(func).keyword(">"), _function_2);
    }
    final ISemanticRegion open = this.textRegionExtensions.regionFor(func).keyword("(");
    final ISemanticRegion close = this.textRegionExtensions.regionFor(func).keyword(")");
    format.append(close, XbaseFormatterPreferenceKeys.bracesInNewLine);
    this.formatCommaSeparatedList(func.getParameters(), open, close, format);
    format.<XExpression>format(func.getExpression());
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XExpression(org.eclipse.xtext.xbase.XExpression) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 33 with JvmTypeParameter

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

the class XtendFormatter method formatTypeParameters.

protected ISemanticRegion formatTypeParameters(final XtendMember member, final List<? extends JvmTypeParameter> typeParameters, @Extension final IFormattableDocument format) {
    ISemanticRegion _xifexpression = null;
    boolean _isEmpty = typeParameters.isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
        ISemanticRegion _xblockexpression = null;
        {
            final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            format.surround(this.textRegionExtensions.regionFor(member).keyword("<"), _function);
            for (final JvmTypeParameter arg : typeParameters) {
                {
                    format.<JvmTypeParameter>format(arg);
                    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                        it.noSpace();
                    };
                    final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
                        it.oneSpace();
                    };
                    format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(arg).keyword(","), _function_1), _function_2);
                }
            }
            final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                it.noSpace();
            };
            _xblockexpression = format.prepend(this.textRegionExtensions.regionFor(member).keyword(">"), _function_1);
        }
        _xifexpression = _xblockexpression;
    }
    return _xifexpression;
}
Also used : IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion)

Example 34 with JvmTypeParameter

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

the class XtendJvmModelInferrer method fixTypeParameters.

protected void fixTypeParameters(JvmTypeParameterDeclarator target) {
    for (JvmTypeParameter typeParameter : target.getTypeParameters()) {
        boolean upperBoundSeen = false;
        for (JvmTypeConstraint constraint : typeParameter.getConstraints()) {
            if (constraint instanceof JvmUpperBound) {
                upperBoundSeen = true;
                break;
            }
        }
        if (!upperBoundSeen) {
            JvmUpperBound upperBound = typesFactory.createJvmUpperBound();
            upperBound.setTypeReference(typeReferences.getTypeForName(Object.class, target));
            typeParameter.getConstraints().add(upperBound);
        }
    }
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) EObject(org.eclipse.emf.ecore.EObject)

Example 35 with JvmTypeParameter

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

the class AbstractCodeBuilder method appendTypeParameters.

protected ISourceAppender appendTypeParameters(final ISourceAppender appendable, final List<JvmTypeParameter> typeParameters) {
    ISourceAppender _xblockexpression = null;
    {
        final Iterator<JvmTypeParameter> iterator = typeParameters.iterator();
        boolean _hasNext = iterator.hasNext();
        if (_hasNext) {
            appendable.append("<");
            do {
                {
                    final JvmTypeParameter typeParameter = iterator.next();
                    appendable.append(typeParameter.getName());
                    final Function1<JvmUpperBound, Boolean> _function = (JvmUpperBound it) -> {
                        String _identifier = it.getTypeReference().getIdentifier();
                        return Boolean.valueOf((!Objects.equal(_identifier, "java.lang.Object")));
                    };
                    final Iterable<JvmUpperBound> upperBounds = IterableExtensions.<JvmUpperBound>filter(Iterables.<JvmUpperBound>filter(typeParameter.getConstraints(), JvmUpperBound.class), _function);
                    boolean _isEmpty = IterableExtensions.isEmpty(upperBounds);
                    boolean _not = (!_isEmpty);
                    if (_not) {
                        appendable.append(" extends ");
                        boolean isFirst = true;
                        final StandardTypeReferenceOwner owner = new StandardTypeReferenceOwner(this.services, this.context);
                        for (final JvmUpperBound upperBound : upperBounds) {
                            {
                                if ((!isFirst)) {
                                    appendable.append(" & ");
                                }
                                isFirst = false;
                                this.appendType(appendable, owner.toLightweightTypeReference(upperBound.getTypeReference()), "Object");
                            }
                        }
                    }
                    boolean _hasNext_1 = iterator.hasNext();
                    if (_hasNext_1) {
                        appendable.append(",");
                    }
                }
            } while (iterator.hasNext());
            appendable.append("> ");
        }
        _xblockexpression = appendable;
    }
    return _xblockexpression;
}
Also used : JvmUpperBound(org.eclipse.xtext.common.types.JvmUpperBound) JvmTypeParameter(org.eclipse.xtext.common.types.JvmTypeParameter) Iterator(java.util.Iterator) ISourceAppender(org.eclipse.xtext.xbase.compiler.ISourceAppender) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

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