Search in sources :

Example 16 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.

the class AbstractAssignabilityTest method isAssignableFrom.

public void isAssignableFrom(final Pair<String, String> lhsAndParams, final String rhs, final boolean expectation) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def ");
        {
            boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(lhsAndParams.getValue());
            boolean _not = (!_isNullOrEmpty);
            if (_not) {
                _builder.append("<");
                String _value = lhsAndParams.getValue();
                _builder.append(_value);
                _builder.append("> ");
            }
        }
        _builder.append("void method(");
        String _fixup = this.fixup(lhsAndParams.getKey());
        _builder.append(_fixup);
        _builder.append(" lhs, ");
        String _fixup_1 = this.fixup(rhs);
        _builder.append(_fixup_1);
        _builder.append(" rhs) {}");
        final String signature = _builder.toString();
        final XtendFunction function = this.function(signature.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        LightweightTypeReference _xifexpression = null;
        String _key = lhsAndParams.getKey();
        boolean _tripleNotEquals = (_key != null);
        if (_tripleNotEquals) {
            _xifexpression = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType());
        } else {
            _xifexpression = this.getOwner().newAnyTypeReference();
        }
        final LightweightTypeReference lhsType = _xifexpression;
        LightweightTypeReference _xifexpression_1 = null;
        if ((rhs != null)) {
            _xifexpression_1 = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>last(operation.getParameters()).getParameterType());
        } else {
            _xifexpression_1 = this.getOwner().newAnyTypeReference();
        }
        final LightweightTypeReference rhsType = _xifexpression_1;
        String _simpleName = lhsType.getSimpleName();
        String _plus = (_simpleName + " := ");
        String _simpleName_1 = rhsType.getSimpleName();
        String _plus_1 = (_plus + _simpleName_1);
        Assert.assertEquals(_plus_1, Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(lhsType, rhsType)));
        if (expectation) {
            List<LightweightTypeReference> _allSuperTypes = lhsType.getAllSuperTypes();
            for (final LightweightTypeReference superType : _allSuperTypes) {
                if (((superType.isArray() == lhsType.isArray()) || (lhsType.isArray() == rhsType.isArray()))) {
                    Assert.assertEquals(superType.toString(), Boolean.valueOf(expectation), Boolean.valueOf(this.testIsAssignable(superType, rhsType)));
                }
            }
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 17 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.

the class AbstractTestingTypeReferenceOwner method function.

@Override
protected XtendFunction function(final String string) throws Exception {
    final XtendFunction result = super.function(string);
    this.contextResourceSet = result.eResource().getResourceSet();
    this.owner = this.createOwner();
    return result;
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction)

Example 18 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction 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 19 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.

the class DispatchHelper method getDispatcherOperation.

/* @Nullable */
public JvmOperation getDispatcherOperation(JvmOperation dispatchCase) {
    EObject sourceElement = associations.getPrimarySourceElement(dispatchCase);
    if (sourceElement instanceof XtendFunction) {
        XtendFunction function = (XtendFunction) sourceElement;
        if (function.isDispatch()) {
            Iterable<JvmOperation> operations = filter(associations.getJvmElements(sourceElement), JvmOperation.class);
            for (JvmOperation operation : operations) {
                if (Strings.equal(operation.getSimpleName(), function.getName())) {
                    return operation;
                }
            }
        }
    } else {
        DispatchSignature signature = new DispatchSignature(dispatchCase.getSimpleName().substring(1), dispatchCase.getParameters().size());
        JvmOperation result = getDispatcherOperation(dispatchCase.getDeclaringType(), signature);
        return result;
    }
    return null;
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) EObject(org.eclipse.emf.ecore.EObject)

Example 20 with XtendFunction

use of org.eclipse.xtend.core.xtend.XtendFunction in project xtext-xtend by eclipse.

the class XtendJvmModelInferrer method initialize.

protected void initialize(XtendInterface source, JvmGenericType inferredJvmType) {
    inferredJvmType.setVisibility(source.getVisibility());
    inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
    inferredJvmType.setAbstract(true);
    inferredJvmType.setStrictFloatingPoint(source.isStrictFloatingPoint());
    translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
    for (JvmTypeReference intf : source.getExtends()) {
        inferredJvmType.getSuperTypes().add(jvmTypesBuilder.cloneWithProxies(intf));
    }
    fixTypeParameters(inferredJvmType);
    for (XtendMember member : source.getMembers()) {
        if (member instanceof XtendField || (member instanceof XtendFunction && ((XtendFunction) member).getName() != null)) {
            transform(member, inferredJvmType, false);
        }
    }
    jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
    nameClashResolver.resolveNameClashes(inferredJvmType);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Aggregations

XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)441 Test (org.junit.Test)374 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)248 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)198 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)182 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)116 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)101 XExpression (org.eclipse.xtext.xbase.XExpression)95 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)91 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)78 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)72 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)60 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)46 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)39 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)30 EObject (org.eclipse.emf.ecore.EObject)28 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)23 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)23 RichString (org.eclipse.xtend.core.xtend.RichString)17 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)16