Search in sources :

Example 1 with IResolvedTypes

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

the class XtendGenerator method generateMembersInBody.

@Override
public ITreeAppendable generateMembersInBody(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
    ITreeAppendable _xifexpression = null;
    boolean _isLocal = it.isLocal();
    if (_isLocal) {
        ITreeAppendable _xblockexpression = null;
        {
            appendable.append("{").increaseIndentation();
            EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it));
            final AnonymousClass anonymousClass = ((AnonymousClass) _head);
            if (((!appendable.hasName(Pair.<String, JvmDeclaredType>of("this", it))) && this.needSyntheticThisVariable(anonymousClass, it))) {
                final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(anonymousClass);
                final LightweightTypeReference actualType = resolvedTypes.getActualType(anonymousClass);
                Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("this", it);
                final String thisName = appendable.declareSyntheticVariable(_mappedTo, "_this");
                appendable.newLine().append("final ").append(actualType).append(" ").append(thisName).append(" = this;");
            }
            final Function1<JvmField, Boolean> _function = (JvmField it_1) -> {
                boolean _xblockexpression_1 = false;
                {
                    Procedure1<? super ITreeAppendable> _compilationStrategy = this._jvmTypeExtensions.getCompilationStrategy(it_1);
                    boolean _tripleNotEquals = (_compilationStrategy != null);
                    if (_tripleNotEquals) {
                        return Boolean.valueOf(true);
                    } else {
                        StringConcatenationClient _compilationTemplate = this._jvmTypeExtensions.getCompilationTemplate(it_1);
                        boolean _tripleNotEquals_1 = (_compilationTemplate != null);
                        if (_tripleNotEquals_1) {
                            return Boolean.valueOf(true);
                        } else {
                            boolean _not = (!(it_1.isFinal() && it_1.isStatic()));
                            if (_not) {
                                final XExpression expression = this._iLogicalContainerProvider.getAssociatedExpression(it_1);
                                if (((expression != null) && config.isGenerateExpressions())) {
                                    return Boolean.valueOf(true);
                                }
                            }
                        }
                    }
                    _xblockexpression_1 = false;
                }
                return Boolean.valueOf(_xblockexpression_1);
            };
            final Iterable<JvmField> fieldsWithInitializer = IterableExtensions.<JvmField>filter(it.getDeclaredFields(), _function);
            boolean _isEmpty = IterableExtensions.isEmpty(fieldsWithInitializer);
            boolean _not = (!_isEmpty);
            if (_not) {
                appendable.newLine().append("{").increaseIndentation();
                final Procedure1<LoopParams> _function_1 = (LoopParams it_1) -> {
                    final Function1<ITreeAppendable, ITreeAppendable> _function_2 = (ITreeAppendable it_2) -> {
                        return it_2.newLine();
                    };
                    it_1.setSeparator(_function_2);
                };
                final Procedure1<JvmField> _function_2 = (JvmField it_1) -> {
                    final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
                    memberAppendable.openScope();
                    appendable.newLine();
                    final ITreeAppendable tracedAppendable = appendable.trace(it_1);
                    this._treeAppendableUtil.traceSignificant(tracedAppendable, it_1).append(it_1.getSimpleName());
                    this.generateInitialization(it_1, tracedAppendable, config);
                    tracedAppendable.append(";");
                    memberAppendable.closeScope();
                };
                this._loopExtensions.<JvmField>forEach(appendable, fieldsWithInitializer, _function_1, _function_2);
                appendable.decreaseIndentation().newLine().append("}");
            }
            final Procedure1<LoopParams> _function_3 = (LoopParams it_1) -> {
                final Function1<ITreeAppendable, ITreeAppendable> _function_4 = (ITreeAppendable it_2) -> {
                    return it_2.newLine();
                };
                it_1.setSeparator(_function_4);
            };
            final Procedure1<JvmMember> _function_4 = (JvmMember it_1) -> {
                final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
                memberAppendable.openScope();
                this.generateMember(it_1, memberAppendable, config);
                memberAppendable.closeScope();
            };
            this._loopExtensions.<JvmMember>forEach(appendable, this.getMembersToBeCompiled(it), _function_3, _function_4);
            _xblockexpression = appendable.decreaseIndentation().newLine().append("}");
        }
        _xifexpression = _xblockexpression;
    } else {
        _xifexpression = super.generateMembersInBody(it, appendable, config);
    }
    return _xifexpression;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenationClient(org.eclipse.xtend2.lib.StringConcatenationClient) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) ITreeAppendable(org.eclipse.xtext.xbase.compiler.output.ITreeAppendable) LoopParams(org.eclipse.xtext.xbase.compiler.LoopParams) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) EObject(org.eclipse.emf.ecore.EObject) Procedure1(org.eclipse.xtext.xbase.lib.Procedures.Procedure1) XExpression(org.eclipse.xtext.xbase.XExpression) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmField(org.eclipse.xtext.common.types.JvmField) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 2 with IResolvedTypes

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

the class XtendValidator method checkImplicitReturn.

@Check
protected void checkImplicitReturn(final XtendFunction method) {
    if (isIgnored(IMPLICIT_RETURN))
        return;
    JvmOperation jvmOperation = associations.getDirectlyInferredOperation(method);
    IResolvedTypes types = batchTypeResolver.resolveTypes(method);
    if (jvmOperation != null && types.getActualType(jvmOperation).isPrimitiveVoid())
        return;
    implicitReturnFinder.findImplicitReturns(method.getExpression(), new Acceptor() {

        @Override
        public void accept(XExpression implicitReturn) {
            if (method.getExpression() == implicitReturn)
                return;
            addIssue("Implicit return", implicitReturn, IMPLICIT_RETURN);
        }
    });
}
Also used : JvmOperation(org.eclipse.xtext.common.types.JvmOperation) ValidationMessageAcceptor(org.eclipse.xtext.validation.ValidationMessageAcceptor) Acceptor(org.eclipse.xtext.xbase.validation.ImplicitReturnFinder.Acceptor) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XExpression(org.eclipse.xtext.xbase.XExpression) Check(org.eclipse.xtext.validation.Check)

Example 3 with IResolvedTypes

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

the class AnonymousClassTypeTest method testOverriddenMethodTypeArgumentInference.

@Test
public void testOverriddenMethodTypeArgumentInference() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new Iterable<String>() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("override iterator() {}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFunction function = this.function(_builder.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(operation.eResource());
        Assert.assertEquals("Iterable<String>", resolvedTypes.getActualType(operation).toString());
        XExpression _expression = function.getExpression();
        XExpression _head = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
        final AnonymousClass anonymousClass = ((AnonymousClass) _head);
        XtendMember _last = IterableExtensions.<XtendMember>last(anonymousClass.getMembers());
        final JvmOperation overriding = this._iXtendJvmAssociations.getDirectlyInferredOperation(((XtendFunction) _last));
        Assert.assertEquals("Iterator<String>", resolvedTypes.getActualType(overriding).toString());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 4 with IResolvedTypes

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

the class AnonymousClassTypeTest method testOverriddenMethodTypeArgumentInference_2.

@Test
public void testOverriddenMethodTypeArgumentInference_2() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("def <T> foo() {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("new Iterable<T>() {");
        _builder.newLine();
        _builder.append("\t\t");
        _builder.append("override iterator() {}");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("}");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtendFunction function = this.function(_builder.toString());
        final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
        final IResolvedTypes resolvedTypes = this._iBatchTypeResolver.resolveTypes(operation.eResource());
        Assert.assertEquals("Iterable<T>", resolvedTypes.getActualType(operation).toString());
        XExpression _expression = function.getExpression();
        XExpression _head = IterableExtensions.<XExpression>head(((XBlockExpression) _expression).getExpressions());
        final AnonymousClass anonymousClass = ((AnonymousClass) _head);
        XtendMember _last = IterableExtensions.<XtendMember>last(anonymousClass.getMembers());
        final JvmOperation overriding = this._iXtendJvmAssociations.getDirectlyInferredOperation(((XtendFunction) _last));
        Assert.assertEquals("Iterator<T>", resolvedTypes.getActualType(overriding).toString());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XtendMember(org.eclipse.xtend.core.xtend.XtendMember) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) Test(org.junit.Test)

Example 5 with IResolvedTypes

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

the class ErrorTest method testErrorModel_015.

@Test
public void testErrorModel_015() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("@ class Node {");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final XtendFile file = this.processWithoutException(_builder);
    final XtendTypeDeclaration node = IterableExtensions.<XtendTypeDeclaration>head(file.getXtendTypes());
    final XAnnotation annotation = IterableExtensions.<XAnnotation>head(node.getAnnotations());
    final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(annotation);
    Assert.assertNotNull(resolvedTypes.getActualType(annotation));
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XtendTypeDeclaration(org.eclipse.xtend.core.xtend.XtendTypeDeclaration) XAnnotation(org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation) Test(org.junit.Test)

Aggregations

IResolvedTypes (org.eclipse.xtext.xbase.typesystem.IResolvedTypes)32 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)25 Test (org.junit.Test)25 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)21 XtendTypeDeclaration (org.eclipse.xtend.core.xtend.XtendTypeDeclaration)19 XtendMember (org.eclipse.xtend.core.xtend.XtendMember)14 XExpression (org.eclipse.xtext.xbase.XExpression)14 XAnnotation (org.eclipse.xtext.xbase.annotations.xAnnotations.XAnnotation)11 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)9 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)7 EObject (org.eclipse.emf.ecore.EObject)6 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)6 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)5 XtendField (org.eclipse.xtend.core.xtend.XtendField)4 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)3 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)3 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)3 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)3 XClosure (org.eclipse.xtext.xbase.XClosure)3 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)3