Search in sources :

Example 61 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class ReplacingAppendableTest method insertListField.

protected XtextDocument insertListField(final String model, final String fieldName) throws Exception {
    final int cursorPosition = model.indexOf('|');
    String actualModel = model.replace("|", " ");
    final XtendFile file = testHelper.xtendFile("Foo", actualModel);
    final XtextDocument document = documentProvider.get();
    document.set(actualModel);
    XtextResource xtextResource = (XtextResource) file.eResource();
    document.setInput(xtextResource);
    final EObject context = eObjectAtOffsetHelper.resolveElementAt(xtextResource, cursorPosition);
    document.modify(new IUnitOfWork.Void<XtextResource>() {

        @Override
        public void process(XtextResource state) throws Exception {
            ReplacingAppendable a = appendableFactory.create(document, state, cursorPosition, 1);
            ITypeReferenceOwner owner = new StandardTypeReferenceOwner(services, context);
            LightweightTypeReference typeRef = owner.toLightweightTypeReference(services.getTypeReferences().getTypeForName(List.class, context, typesFactory.createJvmWildcardTypeReference()));
            a.append(typeRef);
            a.append(" ").append(fieldName);
            a.commitChanges();
        }
    });
    return document;
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) XtextResource(org.eclipse.xtext.resource.XtextResource) ReplacingAppendable(org.eclipse.xtext.xbase.ui.contentassist.ReplacingAppendable) ITypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner) IUnitOfWork(org.eclipse.xtext.util.concurrent.IUnitOfWork) EObject(org.eclipse.emf.ecore.EObject) StandardTypeReferenceOwner(org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)

Example 62 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class ConstructorBuilderTest method testXtendExceptions.

@Test
public void testXtendExceptions() {
    AbstractConstructorBuilder _createConstructorBuilder = this._codeBuilderFactory.createConstructorBuilder(this.getXtendClass());
    final Procedure1<AbstractConstructorBuilder> _function = (AbstractConstructorBuilder it) -> {
        it.setContext(this.getXtendClass());
        LightweightTypeReference _createTypeRef = this.createTypeRef(Exception.class, this.getXtendClass());
        LightweightTypeReference _createTypeRef_1 = this.createTypeRef(RuntimeException.class, this.getXtendClass());
        it.setExceptions(Collections.<LightweightTypeReference>unmodifiableList(CollectionLiterals.<LightweightTypeReference>newArrayList(_createTypeRef, _createTypeRef_1)));
    };
    AbstractConstructorBuilder _doubleArrow = ObjectExtensions.<AbstractConstructorBuilder>operator_doubleArrow(_createConstructorBuilder, _function);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("new() throws Exception, RuntimeException {");
    _builder.newLine();
    _builder.append("  ");
    _builder.append(AbstractBuilderTest.DEFAULT_BODY, "  ");
    _builder.newLineIfNotEmpty();
    _builder.append("}");
    this.assertBuilds(_doubleArrow, _builder.toString());
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) AbstractConstructorBuilder(org.eclipse.xtend.ide.codebuilder.AbstractConstructorBuilder) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Test(org.junit.Test) AbstractBuilderTest(org.eclipse.xtend.ide.tests.codebuilder.AbstractBuilderTest)

Example 63 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class AbstractSuperTypesTest method assertSuperTypes.

public void assertSuperTypes(final Pair<String, String> type, final String... superTypes) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def ");
        {
            boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(type.getValue());
            boolean _not = (!_isNullOrEmpty);
            if (_not) {
                _builder.append("<");
                String _value = type.getValue();
                _builder.append(_value);
                _builder.append("> ");
            }
        }
        _builder.append("void method(");
        String _key = type.getKey();
        _builder.append(_key);
        _builder.append(" type) {}");
        final String signature = _builder.toString();
        final XtendFunction function = this.function(signature.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        final LightweightTypeReference subtype = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType());
        final Function1<LightweightTypeReference, String> _function = (LightweightTypeReference it) -> {
            return it.getSimpleName();
        };
        Assert.assertEquals(IterableExtensions.<String>toList(((Iterable<String>) Conversions.doWrapArray(superTypes))), IterableExtensions.<String>toList(IterableExtensions.<LightweightTypeReference, String>map(this.collectSuperTypes(subtype), _function)));
    } 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) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 64 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class AssignmentFeatureCallArgumentsTest method toArguments.

protected AssignmentFeatureCallArguments toArguments(final String type, final String expression) {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def void m(");
        _builder.append(type);
        _builder.append(") {");
        _builder.newLineIfNotEmpty();
        _builder.append("\t");
        _builder.append(expression, "\t");
        _builder.newLineIfNotEmpty();
        _builder.append("}");
        _builder.newLine();
        final String functionString = _builder.toString();
        final XtendFunction function = this.function(functionString);
        XExpression _expression = function.getExpression();
        final XBlockExpression body = ((XBlockExpression) _expression);
        final XExpression value = IterableExtensions.<XExpression>head(body.getExpressions());
        JvmFormalParameter _head = IterableExtensions.<JvmFormalParameter>head(this._iXtendJvmAssociations.getDirectlyInferredOperation(function).getParameters());
        JvmTypeReference _parameterType = null;
        if (_head != null) {
            _parameterType = _head.getParameterType();
        }
        final JvmTypeReference declaredType = _parameterType;
        if ((declaredType != null)) {
            LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(declaredType);
            return new AssignmentFeatureCallArguments(value, _lightweightTypeReference);
        } else {
            return new AssignmentFeatureCallArguments(value, null);
        }
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) AssignmentFeatureCallArguments(org.eclipse.xtext.xbase.typesystem.arguments.AssignmentFeatureCallArguments) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 65 with LightweightTypeReference

use of org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference in project xtext-xtend by eclipse.

the class BoundTypeArgumentMergerTest method mergeSuccessive.

public LightweightMergedBoundTypeArgument mergeSuccessive(final Triple<String, VarianceInfo, VarianceInfo>... mergeUs) {
    try {
        int _length = mergeUs.length;
        boolean _greaterThan = (_length > 2);
        Assert.assertTrue(_greaterThan);
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def void method(");
        final Function1<Triple<String, VarianceInfo, VarianceInfo>, CharSequence> _function = (Triple<String, VarianceInfo, VarianceInfo> it) -> {
            return it.getFirst();
        };
        String _join = IterableExtensions.<Triple<String, VarianceInfo, VarianceInfo>>join(((Iterable<Triple<String, VarianceInfo, VarianceInfo>>) Conversions.doWrapArray(mergeUs)), 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);
        final ArrayList<LightweightBoundTypeArgument> mergable = CollectionLiterals.<LightweightBoundTypeArgument>newArrayList();
        final Procedure2<JvmFormalParameter, Integer> _function_1 = (JvmFormalParameter p, Integer i) -> {
            final Triple<String, VarianceInfo, VarianceInfo> input = mergeUs[(i).intValue()];
            LightweightTypeReference _lightweightTypeReference = this.toLightweightTypeReference(p.getParameterType());
            Object _object = new Object();
            VarianceInfo _second = input.getSecond();
            VarianceInfo _third = input.getThird();
            LightweightBoundTypeArgument _lightweightBoundTypeArgument = new LightweightBoundTypeArgument(_lightweightTypeReference, null, _object, _second, _third);
            mergable.add(_lightweightBoundTypeArgument);
        };
        IterableExtensions.<JvmFormalParameter>forEach(operation.getParameters(), _function_1);
        final Iterator<LightweightBoundTypeArgument> iterator = mergable.iterator();
        LightweightBoundTypeArgument first = iterator.next();
        LightweightBoundTypeArgument second = iterator.next();
        LightweightMergedBoundTypeArgument merged = this.merger.merge(Collections.<LightweightBoundTypeArgument>unmodifiableList(CollectionLiterals.<LightweightBoundTypeArgument>newArrayList(first, second)), this.getOwner());
        while (iterator.hasNext()) {
            {
                LightweightTypeReference _typeReference = merged.getTypeReference();
                Object _object = new Object();
                VarianceInfo _variance = merged.getVariance();
                VarianceInfo _variance_1 = merged.getVariance();
                LightweightBoundTypeArgument _lightweightBoundTypeArgument = new LightweightBoundTypeArgument(_typeReference, null, _object, _variance, _variance_1);
                first = _lightweightBoundTypeArgument;
                second = iterator.next();
                merged = this.merger.merge(Collections.<LightweightBoundTypeArgument>unmodifiableList(CollectionLiterals.<LightweightBoundTypeArgument>newArrayList(first, second)), this.getOwner());
            }
        }
        return merged;
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) VarianceInfo(org.eclipse.xtext.xbase.typesystem.util.VarianceInfo) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) Triple(org.eclipse.xtext.util.Triple) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) LightweightMergedBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightMergedBoundTypeArgument) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) LightweightBoundTypeArgument(org.eclipse.xtext.xbase.typesystem.references.LightweightBoundTypeArgument)

Aggregations

LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)83 Test (org.junit.Test)28 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)23 XExpression (org.eclipse.xtext.xbase.XExpression)22 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)20 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)19 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)16 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)13 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)10 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)10 IFeatureCallArguments (org.eclipse.xtext.xbase.typesystem.arguments.IFeatureCallArguments)10 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)9 XNumberLiteral (org.eclipse.xtext.xbase.XNumberLiteral)9 JvmType (org.eclipse.xtext.common.types.JvmType)8 ITypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.ITypeReferenceOwner)8 EObject (org.eclipse.emf.ecore.EObject)7 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)7 StandardTypeReferenceOwner (org.eclipse.xtext.xbase.typesystem.references.StandardTypeReferenceOwner)7 RichString (org.eclipse.xtend.core.xtend.RichString)6 JvmTypeParameter (org.eclipse.xtext.common.types.JvmTypeParameter)6