Search in sources :

Example 31 with IResolvedTypes

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

the class Oven method fireproof.

public void fireproof(final String input) throws Exception {
    try {
        final EObject file = this._parseHelper.parse(input);
        final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(file);
        Assert.assertNotNull(resolvedTypes);
        if ((file != null)) {
            Iterable<EObject> _iterable = IteratorExtensions.<EObject>toIterable(file.eAllContents());
            for (final EObject content : _iterable) {
                boolean _matched = false;
                if (content instanceof XAbstractFeatureCall) {
                    _matched = true;
                    this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                    XExpression _implicitReceiver = ((XAbstractFeatureCall) content).getImplicitReceiver();
                    boolean _tripleNotEquals = (_implicitReceiver != null);
                    if (_tripleNotEquals) {
                        this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitReceiver(), resolvedTypes);
                    }
                    XExpression _implicitFirstArgument = ((XAbstractFeatureCall) content).getImplicitFirstArgument();
                    boolean _tripleNotEquals_1 = (_implicitFirstArgument != null);
                    if (_tripleNotEquals_1) {
                        this.assertExpressionTypeIsResolved(((XAbstractFeatureCall) content).getImplicitFirstArgument(), resolvedTypes);
                    }
                }
                if (!_matched) {
                    if (content instanceof XClosure) {
                        _matched = true;
                        this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                        final Consumer<JvmFormalParameter> _function = (JvmFormalParameter it) -> {
                            this.assertIdentifiableTypeIsResolved(it, resolvedTypes);
                        };
                        ((XClosure) content).getImplicitFormalParameters().forEach(_function);
                    }
                }
                if (!_matched) {
                    if (content instanceof XExpression) {
                        _matched = true;
                        this.assertExpressionTypeIsResolved(((XExpression) content), resolvedTypes);
                    }
                }
                if (!_matched) {
                    if (content instanceof JvmIdentifiableElement) {
                        _matched = true;
                        this.assertIdentifiableTypeIsResolved(((JvmIdentifiableElement) content), resolvedTypes);
                    }
                }
            }
        }
    } catch (final Throwable _t) {
        if (_t instanceof Throwable) {
            final Throwable e = (Throwable) _t;
            String _message = e.getMessage();
            final ComparisonFailure error = new ComparisonFailure(_message, input, "");
            error.setStackTrace(e.getStackTrace());
            throw error;
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) XClosure(org.eclipse.xtext.xbase.XClosure) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) ComparisonFailure(org.junit.ComparisonFailure) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 32 with IResolvedTypes

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

the class XtendResourceDescription method getImportedNames.

@Override
public Iterable<QualifiedName> getImportedNames() {
    if ((this.importedNames != null)) {
        return this.importedNames;
    }
    final HashSet<QualifiedName> result = CollectionLiterals.<QualifiedName>newHashSet();
    final EObject astRoot = IterableExtensions.<EObject>head(this.getResource().getContents());
    if ((astRoot != null)) {
        final IResolvedTypes types = this.typeResolver.resolveTypes(astRoot);
        Iterable<XExpression> _filter = Iterables.<XExpression>filter(IteratorExtensions.<Object>toIterable(EcoreUtil.<Object>getAllContents(astRoot, true)), XExpression.class);
        for (final XExpression expression : _filter) {
            {
                boolean _matched = false;
                if (expression instanceof XMemberFeatureCall) {
                    if ((((((XMemberFeatureCall) expression).getFeature() != null) && ((XMemberFeatureCall) expression).getFeature().eIsProxy()) && (!((XMemberFeatureCall) expression).isExplicitOperationCallOrBuilderSyntax()))) {
                        _matched = true;
                        final XExpression receiver = ((XMemberFeatureCall) expression).getActualReceiver();
                        boolean _matched_1 = false;
                        if (receiver instanceof XAbstractFeatureCall) {
                            boolean _isTypeLiteral = ((XAbstractFeatureCall) receiver).isTypeLiteral();
                            if (_isTypeLiteral) {
                                _matched_1 = true;
                                final JvmIdentifiableElement type = ((XAbstractFeatureCall) receiver).getFeature();
                                String _identifier = type.getIdentifier();
                                String _plus = (_identifier + "$");
                                String _concreteSyntaxFeatureName = ((XMemberFeatureCall) expression).getConcreteSyntaxFeatureName();
                                String _plus_1 = (_plus + _concreteSyntaxFeatureName);
                                QualifiedName _lowerCase = this.nameConverter.toQualifiedName(_plus_1).toLowerCase();
                                result.add(_lowerCase);
                            }
                        }
                    }
                }
                if (!_matched) {
                    if (expression instanceof XAbstractFeatureCall) {
                        boolean _isTypeLiteral = ((XAbstractFeatureCall) expression).isTypeLiteral();
                        if (_isTypeLiteral) {
                            _matched = true;
                            final JvmIdentifiableElement type = ((XAbstractFeatureCall) expression).getFeature();
                            if ((type instanceof JvmDeclaredType)) {
                                final Function1<String, Boolean> _function = (String it) -> {
                                    QualifiedName _lowerCase = this.nameConverter.toQualifiedName(it).toLowerCase();
                                    return Boolean.valueOf(result.add(_lowerCase));
                                };
                                this.registerAllTypes(((JvmType) type), _function);
                            }
                        }
                    }
                }
                final LightweightTypeReference typeRef = types.getActualType(expression);
                if ((typeRef != null)) {
                    final Function1<String, Boolean> _function = (String it) -> {
                        QualifiedName _lowerCase = this.nameConverter.toQualifiedName(it).toLowerCase();
                        return Boolean.valueOf(result.add(_lowerCase));
                    };
                    this.registerAllTypes(typeRef.getType(), _function);
                }
            }
        }
        EList<EObject> _contents = this.getResource().getContents();
        for (final EObject eobject : _contents) {
            {
                final Function1<JvmIdentifiableElement, LightweightTypeReference> _function = (JvmIdentifiableElement it) -> {
                    LightweightTypeReference _xifexpression = null;
                    if (((!(it instanceof JvmType)) || (it instanceof JvmDeclaredType))) {
                        _xifexpression = types.getActualType(it);
                    }
                    return _xifexpression;
                };
                final Iterable<LightweightTypeReference> typesOfIdentifiables = IteratorExtensions.<LightweightTypeReference>toIterable(IteratorExtensions.<JvmIdentifiableElement, LightweightTypeReference>map(Iterators.<JvmIdentifiableElement>filter(EcoreUtil.<Object>getAllContents(eobject, true), JvmIdentifiableElement.class), _function));
                for (final LightweightTypeReference typeRef : typesOfIdentifiables) {
                    if ((typeRef != null)) {
                        final Function1<String, Boolean> _function_1 = (String it) -> {
                            QualifiedName _lowerCase = this.nameConverter.toQualifiedName(it).toLowerCase();
                            return Boolean.valueOf(result.add(_lowerCase));
                        };
                        this.registerAllTypes(typeRef.getType(), _function_1);
                    }
                }
            }
        }
    }
    Iterables.<QualifiedName>addAll(result, super.getImportedNames());
    final Function1<QualifiedName, Boolean> _function = (QualifiedName it) -> {
        boolean _contains = XtendResourceDescription.primitivesFilter.contains(it.getLastSegment());
        return Boolean.valueOf((!_contains));
    };
    this.importedNames = IterableExtensions.<QualifiedName>toSet(IterableExtensions.<QualifiedName>filter(result, _function));
    return this.importedNames;
}
Also used : LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) IResolvedTypes(org.eclipse.xtext.xbase.typesystem.IResolvedTypes) QualifiedName(org.eclipse.xtext.naming.QualifiedName) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmType(org.eclipse.xtext.common.types.JvmType) XAbstractFeatureCall(org.eclipse.xtext.xbase.XAbstractFeatureCall) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) EObject(org.eclipse.emf.ecore.EObject) XExpression(org.eclipse.xtext.xbase.XExpression) EObject(org.eclipse.emf.ecore.EObject)

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