Search in sources :

Example 1 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 2 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 3 with XtendFunction

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

the class ModelExtensionsTest method testXtendFunction.

@Test
public void testXtendFunction() throws Exception {
    XtendFile file = file("package foo class Bar { def int foo() {1}}");
    XtendFunction xtendFunction = (XtendFunction) ((XtendClass) file.getXtendTypes().get(0)).getMembers().get(0);
    assertEquals("foo", xtendFunction.getName());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) Test(org.junit.Test)

Example 4 with XtendFunction

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

the class XtendFormatter method formatBody.

protected ISemanticRegion formatBody(final XtendTypeDeclaration type, @Extension final IFormattableDocument format) {
    ISemanticRegion _xblockexpression = null;
    {
        final ISemanticRegion open = this.textRegionExtensions.regionFor(type).keyword("{");
        final ISemanticRegion close = this.textRegionExtensions.regionFor(type).keyword("}");
        final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
            it.indent();
        };
        format.<ISemanticRegion, ISemanticRegion>interior(open, close, _function);
        format.prepend(open, XbaseFormatterPreferenceKeys.bracesInNewLine);
        ISemanticRegion _xifexpression = null;
        boolean _isEmpty = type.getMembers().isEmpty();
        boolean _not = (!_isEmpty);
        if (_not) {
            format.append(open, XtendFormatterPreferenceKeys.blankLinesBeforeFirstMember);
            int _size = type.getMembers().size();
            int _minus = (_size - 1);
            IntegerRange _upTo = new IntegerRange(0, _minus);
            for (final Integer i : _upTo) {
                {
                    final XtendMember current = type.getMembers().get((i).intValue());
                    format.<XtendMember>format(current);
                    int _size_1 = type.getMembers().size();
                    int _minus_1 = (_size_1 - 1);
                    boolean _lessThan = ((i).intValue() < _minus_1);
                    if (_lessThan) {
                        final XtendMember next = type.getMembers().get(((i).intValue() + 1));
                        if (((current instanceof XtendField) && (next instanceof XtendField))) {
                            format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenFields);
                        } else {
                            if (((current instanceof XtendFunction) && (next instanceof XtendFunction))) {
                                format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenMethods);
                            } else {
                                format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenFieldsAndMethods);
                            }
                        }
                    } else {
                        final XtendMember member = type.getMembers().get((i).intValue());
                        format.<XtendMember>append(member, XtendFormatterPreferenceKeys.blankLinesAfterLastMember);
                    }
                }
            }
        } else {
            final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
                it.newLine();
            };
            _xifexpression = format.append(open, _function_1);
        }
        _xblockexpression = _xifexpression;
    }
    return _xblockexpression;
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) IntegerRange(org.eclipse.xtext.xbase.lib.IntegerRange) IHiddenRegionFormatter(org.eclipse.xtext.formatting2.IHiddenRegionFormatter) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) ISemanticRegion(org.eclipse.xtext.formatting2.regionaccess.ISemanticRegion) JvmTypeConstraint(org.eclipse.xtext.common.types.JvmTypeConstraint) XtendField(org.eclipse.xtend.core.xtend.XtendField)

Example 5 with XtendFunction

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

the class XAnnotationExtensions method getAnnotatedTarget.

public XtendAnnotationTarget getAnnotatedTarget(final XAnnotation annotation) {
    XtendAnnotationTarget _switchResult = null;
    EObject _eContainer = annotation.eContainer();
    final EObject container = _eContainer;
    boolean _matched = false;
    if (container instanceof XtendAnnotationType) {
        _matched = true;
    }
    if (!_matched) {
        if (container instanceof XtendClass) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendInterface) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendEnum) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendField) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendFunction) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendConstructor) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendEnumLiteral) {
            _matched = true;
        }
    }
    if (!_matched) {
        if (container instanceof XtendParameter) {
            _matched = true;
        }
    }
    if (_matched) {
        _switchResult = ((XtendAnnotationTarget) container);
    }
    if (!_matched) {
        if (container instanceof XtendAnnotationTarget) {
            _matched = true;
            XtendAnnotationTarget _xblockexpression = null;
            {
                final EObject containerContainer = ((XtendAnnotationTarget) container).eContainer();
                XtendAnnotationTarget _xifexpression = null;
                if ((containerContainer instanceof XtendAnnotationTarget)) {
                    _xifexpression = ((XtendAnnotationTarget) containerContainer);
                } else {
                    _xifexpression = ((XtendAnnotationTarget) container);
                }
                _xblockexpression = _xifexpression;
            }
            _switchResult = _xblockexpression;
        }
    }
    if (!_matched) {
        if (container instanceof XAnnotation) {
            _matched = true;
            _switchResult = this.getAnnotatedTarget(((XAnnotation) container));
        }
    }
    if (!_matched) {
        _switchResult = null;
    }
    return _switchResult;
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XtendConstructor(org.eclipse.xtend.core.xtend.XtendConstructor) XtendField(org.eclipse.xtend.core.xtend.XtendField) XtendParameter(org.eclipse.xtend.core.xtend.XtendParameter) XtendAnnotationTarget(org.eclipse.xtend.core.xtend.XtendAnnotationTarget) XtendAnnotationType(org.eclipse.xtend.core.xtend.XtendAnnotationType) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XtendInterface(org.eclipse.xtend.core.xtend.XtendInterface) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) XtendEnum(org.eclipse.xtend.core.xtend.XtendEnum) XtendEnumLiteral(org.eclipse.xtend.core.xtend.XtendEnumLiteral)

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