Search in sources :

Example 71 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.

the class ConstantExpressionsInterpreter method _internalEvaluate.

protected Object _internalEvaluate(final XFeatureCall it, final Context ctx) {
    Object _eGet = it.eGet(XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE, this.isResolveProxies(it));
    final EObject feature = ((EObject) _eGet);
    boolean _eIsProxy = feature.eIsProxy();
    boolean _not = (!_eIsProxy);
    if (_not) {
        Object _switchResult = null;
        boolean _matched = false;
        if (feature instanceof JvmEnumerationLiteral) {
            _matched = true;
            _switchResult = feature;
        }
        if (!_matched) {
            if (feature instanceof JvmField) {
                _matched = true;
                _switchResult = this.evaluateField(it, ((JvmField) feature), ctx);
            }
        }
        if (!_matched) {
            if (feature instanceof JvmType) {
                _matched = true;
                _switchResult = this.toTypeReference(((JvmType) feature), 0);
            }
        }
        return _switchResult;
    }
    final String featureName = it.getConcreteSyntaxFeatureName();
    JvmType _switchResult_1 = null;
    JvmTypeReference _expectedType = ctx.getExpectedType();
    final JvmTypeReference it_1 = _expectedType;
    boolean _matched_1 = false;
    if (it_1 instanceof XComputedTypeReferenceImplCustom) {
        boolean _isEquivalentComputed = ((XComputedTypeReferenceImplCustom) it_1).isEquivalentComputed();
        if (_isEquivalentComputed) {
            _matched_1 = true;
            _switchResult_1 = ((XComputedTypeReferenceImplCustom) it_1).getType();
        }
    }
    if (!_matched_1) {
        if (it_1 instanceof XComputedTypeReference) {
            _matched_1 = true;
        }
        if (!_matched_1) {
            if ((it_1 == null)) {
                _matched_1 = true;
            }
        }
        if (_matched_1) {
            _switchResult_1 = null;
        }
    }
    if (!_matched_1) {
        _switchResult_1 = it_1.getType();
    }
    final JvmType expectedRawType = _switchResult_1;
    Map<String, JvmIdentifiableElement> _xifexpression = null;
    boolean _isEnumExpectationInAnnotationValue = this.isEnumExpectationInAnnotationValue(it, expectedRawType);
    if (_isEnumExpectationInAnnotationValue) {
        HashMap<String, JvmIdentifiableElement> _xblockexpression = null;
        {
            JvmEnumerationType _switchResult_2 = null;
            boolean _matched_2 = false;
            if (expectedRawType instanceof JvmEnumerationType) {
                _matched_2 = true;
                _switchResult_2 = ((JvmEnumerationType) expectedRawType);
            }
            if (!_matched_2) {
                if (expectedRawType instanceof JvmArrayType) {
                    _matched_2 = true;
                    JvmComponentType _componentType = ((JvmArrayType) expectedRawType).getComponentType();
                    _switchResult_2 = ((JvmEnumerationType) _componentType);
                }
            }
            final JvmEnumerationType enumType = _switchResult_2;
            Map<String, JvmIdentifiableElement> _visibleFeatures = ctx.getVisibleFeatures();
            final HashMap<String, JvmIdentifiableElement> copy = new HashMap<String, JvmIdentifiableElement>(_visibleFeatures);
            final Consumer<JvmEnumerationLiteral> _function = (JvmEnumerationLiteral it_2) -> {
                copy.put(it_2.getSimpleName(), it_2);
            };
            enumType.getLiterals().forEach(_function);
            _xblockexpression = copy;
        }
        _xifexpression = _xblockexpression;
    } else {
        _xifexpression = ctx.getVisibleFeatures();
    }
    final Map<String, JvmIdentifiableElement> visibleFeatures = _xifexpression;
    boolean _containsKey = visibleFeatures.containsKey(featureName);
    if (_containsKey) {
        Object _switchResult_2 = null;
        JvmIdentifiableElement _get = visibleFeatures.get(featureName);
        final JvmIdentifiableElement visibleFeature = _get;
        boolean _matched_2 = false;
        if (visibleFeature instanceof JvmEnumerationLiteral) {
            _matched_2 = true;
            JvmEnumerationLiteral _xblockexpression_1 = null;
            {
                this.resolveFeature(it, visibleFeature);
                _xblockexpression_1 = ((JvmEnumerationLiteral) visibleFeature);
            }
            _switchResult_2 = _xblockexpression_1;
        }
        if (!_matched_2) {
            if (visibleFeature instanceof JvmField) {
                _matched_2 = true;
                Object _xblockexpression_1 = null;
                {
                    this.resolveFeature(it, visibleFeature);
                    _xblockexpression_1 = this.evaluateField(it, ((JvmField) visibleFeature), ctx);
                }
                _switchResult_2 = _xblockexpression_1;
            }
        }
        return _switchResult_2;
    }
    final JvmType type = this.findTypeByName(it, featureName);
    if ((type != null)) {
        this.resolveType(it, type);
        return this.toTypeReference(type, 0);
    }
    throw new UnresolvableFeatureException(("Couldn\'t resolve feature " + featureName), it);
}
Also used : JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) HashMap(java.util.HashMap) JvmComponentType(org.eclipse.xtext.common.types.JvmComponentType) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference) UnresolvableFeatureException(org.eclipse.xtext.xbase.interpreter.UnresolvableFeatureException) JvmType(org.eclipse.xtext.common.types.JvmType) Consumer(java.util.function.Consumer) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) XComputedTypeReferenceImplCustom(org.eclipse.xtext.xtype.impl.XComputedTypeReferenceImplCustom) JvmEnumerationLiteral(org.eclipse.xtext.common.types.JvmEnumerationLiteral) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) JvmField(org.eclipse.xtext.common.types.JvmField) JvmEnumerationType(org.eclipse.xtext.common.types.JvmEnumerationType) Map(java.util.Map) HashMap(java.util.HashMap) JvmArrayType(org.eclipse.xtext.common.types.JvmArrayType)

Example 72 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.

the class ConstantExpressionsInterpreter method evaluateField.

protected Object evaluateField(final XAbstractFeatureCall call, final JvmField field, final Context context) {
    if ((field.isSetConstant() || (field.eResource() instanceof TypeResource))) {
        boolean _isConstant = field.isConstant();
        if (_isConstant) {
            return field.getConstantValue();
        } else {
            String _simpleName = field.getDeclaringType().getSimpleName();
            String _plus = ("Field " + _simpleName);
            String _plus_1 = (_plus + ".");
            String _simpleName_1 = field.getSimpleName();
            String _plus_2 = (_plus_1 + _simpleName_1);
            String _plus_3 = (_plus_2 + " is not a constant");
            throw new ConstantExpressionEvaluationException(_plus_3);
        }
    }
    final XExpression expression = this.containerProvider.getAssociatedExpression(field);
    boolean _contains = context.getAlreadyEvaluating().contains(expression);
    if (_contains) {
        throw new ConstantExpressionEvaluationException("Endless recursive evaluation detected.");
    }
    try {
        final Map<String, JvmIdentifiableElement> visibleFeatures = this.findVisibleFeatures(expression);
        JvmTypeReference _type = field.getType();
        ClassFinder _classFinder = context.getClassFinder();
        Set<XExpression> _alreadyEvaluating = context.getAlreadyEvaluating();
        final Context ctx = new Context(_type, _classFinder, visibleFeatures, _alreadyEvaluating);
        return this.evaluate(expression, ctx);
    } catch (final Throwable _t) {
        if (_t instanceof ConstantExpressionEvaluationException) {
            final ConstantExpressionEvaluationException e = (ConstantExpressionEvaluationException) _t;
            throw new StackedConstantExpressionEvaluationException(call, field, e);
        } else {
            throw Exceptions.sneakyThrow(_t);
        }
    }
}
Also used : Context(org.eclipse.xtext.xbase.interpreter.Context) TypeResource(org.eclipse.xtext.common.types.access.TypeResource) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) ConstantExpressionEvaluationException(org.eclipse.xtext.xbase.interpreter.ConstantExpressionEvaluationException) StackedConstantExpressionEvaluationException(org.eclipse.xtext.xbase.interpreter.StackedConstantExpressionEvaluationException) StackedConstantExpressionEvaluationException(org.eclipse.xtext.xbase.interpreter.StackedConstantExpressionEvaluationException) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) ClassFinder(org.eclipse.xtext.common.types.access.impl.ClassFinder) XExpression(org.eclipse.xtext.xbase.XExpression)

Example 73 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement 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)

Example 74 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.

the class LinkingTest method testExplicitStaticInvocation_01.

@Test
public void testExplicitStaticInvocation_01() throws Exception {
    XtendFile file = file("class C {\n" + "   static def void getFields() {\n" + "       C::fields" + "   }" + "}\n");
    XtendClass c = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction m = (XtendFunction) c.getMembers().get(0);
    XBlockExpression body = (XBlockExpression) m.getExpression();
    XMemberFeatureCall featureCall = (XMemberFeatureCall) body.getExpressions().get(0);
    JvmIdentifiableElement method = featureCall.getFeature();
    assertEquals("C.getFields()", method.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Example 75 with JvmIdentifiableElement

use of org.eclipse.xtext.common.types.JvmIdentifiableElement in project xtext-xtend by eclipse.

the class LinkingTest method testOverloadedMethods_15.

@Test
public void testOverloadedMethods_15() throws Exception {
    XtendFile file = file("import java.util.Collection\n" + "class X {\n" + "  def <T> foo(Collection<T> collection, Iterable<? extends T> elements) {\n" + "    collection.addAll(elements)\n" + "  }\n" + "}");
    XtendClass clazz = (XtendClass) file.getXtendTypes().get(0);
    XtendFunction func = (XtendFunction) clazz.getMembers().get(0);
    XMemberFeatureCall featureCall = (XMemberFeatureCall) ((XBlockExpression) func.getExpression()).getExpressions().get(0);
    JvmIdentifiableElement addAll = featureCall.getFeature();
    assertNotNull(addAll);
    assertFalse(addAll.eIsProxy());
    assertEquals("org.eclipse.xtext.xbase.lib.CollectionExtensions.addAll(java.util.Collection,java.lang.Iterable)", addAll.getIdentifier());
}
Also used : XtendFile(org.eclipse.xtend.core.xtend.XtendFile) XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) XBlockExpression(org.eclipse.xtext.xbase.XBlockExpression) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) XtendClass(org.eclipse.xtend.core.xtend.XtendClass) XMemberFeatureCall(org.eclipse.xtext.xbase.XMemberFeatureCall) Test(org.junit.Test)

Aggregations

JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)112 Test (org.junit.Test)65 XtendClass (org.eclipse.xtend.core.xtend.XtendClass)63 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)62 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)60 XBlockExpression (org.eclipse.xtext.xbase.XBlockExpression)58 XMemberFeatureCall (org.eclipse.xtext.xbase.XMemberFeatureCall)39 XFeatureCall (org.eclipse.xtext.xbase.XFeatureCall)27 EObject (org.eclipse.emf.ecore.EObject)26 XAbstractFeatureCall (org.eclipse.xtext.xbase.XAbstractFeatureCall)13 XExpression (org.eclipse.xtext.xbase.XExpression)12 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)11 IJavaElement (org.eclipse.jdt.core.IJavaElement)10 JvmOperation (org.eclipse.xtext.common.types.JvmOperation)8 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)6 JvmType (org.eclipse.xtext.common.types.JvmType)6 XtextResource (org.eclipse.xtext.resource.XtextResource)6 XtendField (org.eclipse.xtend.core.xtend.XtendField)5 JvmExecutable (org.eclipse.xtext.common.types.JvmExecutable)5 JvmMember (org.eclipse.xtext.common.types.JvmMember)5