Search in sources :

Example 1 with XComputedTypeReference

use of org.eclipse.xtext.xtype.XComputedTypeReference in project xtext-xtend by eclipse.

the class ConstantExpressionsInterpreter method evaluate.

public Object evaluate(final XExpression expression, final JvmTypeReference expectedType) {
    final ClassLoader classLoader = this.classLoaderProvider.getClassLoader(expression);
    final Map<String, JvmIdentifiableElement> visibleFeatures = this.findVisibleFeatures(expression);
    JvmTypeReference _xifexpression = null;
    if ((expectedType instanceof XComputedTypeReference)) {
        _xifexpression = null;
    } else {
        _xifexpression = expectedType;
    }
    ClassFinder _classFinder = new ClassFinder(classLoader);
    LinkedHashSet<XExpression> _newLinkedHashSet = CollectionLiterals.<XExpression>newLinkedHashSet();
    Context _context = new Context(_xifexpression, _classFinder, visibleFeatures, _newLinkedHashSet);
    final Object result = this.evaluate(expression, _context);
    return result;
}
Also used : Context(org.eclipse.xtext.xbase.interpreter.Context) JvmIdentifiableElement(org.eclipse.xtext.common.types.JvmIdentifiableElement) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference) ClassFinder(org.eclipse.xtext.common.types.access.impl.ClassFinder) XExpression(org.eclipse.xtext.xbase.XExpression) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject)

Example 2 with XComputedTypeReference

use of org.eclipse.xtext.xtype.XComputedTypeReference in project xtext-xtend by eclipse.

the class XtendReentrantTypeResolver method _doPrepare.

@Override
protected void _doPrepare(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmOperation operation, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
    super._doPrepare(resolvedTypes, featureScopeSession, operation, resolvedTypesByContext);
    resolvedTypes = resolvedTypesByContext.get(operation);
    if (dispatchHelper.isDispatcherFunction(operation)) {
        List<JvmFormalParameter> parameters = operation.getParameters();
        for (int i = 0; i < parameters.size(); i++) {
            JvmFormalParameter parameter = parameters.get(i);
            JvmTypeReference parameterType = parameter.getParameterType();
            if (InferredTypeIndicator.isInferred(parameterType)) {
                XComputedTypeReference casted = (XComputedTypeReference) parameterType;
                XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference();
                computedParameterType.setTypeProvider(new DispatchParameterTypeReferenceProvider(operation, i, resolvedTypes, featureScopeSession, this));
                casted.setEquivalent(computedParameterType);
            } else if (parameterType == null) {
                XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference();
                computedParameterType.setTypeProvider(new DispatchParameterTypeReferenceProvider(operation, i, resolvedTypes, featureScopeSession, this));
                parameter.setParameterType(computedParameterType);
            }
        }
    } else if (operation.getParameters().size() >= 1) {
        EObject sourceElement = associations.getPrimarySourceElement(operation);
        if (sourceElement instanceof XtendFunction) {
            XtendFunction function = (XtendFunction) sourceElement;
            if (function.getCreateExtensionInfo() != null) {
                JvmFormalParameter firstParameter = operation.getParameters().get(0);
                JvmTypeReference parameterType = firstParameter.getParameterType();
                if (InferredTypeIndicator.isInferred(parameterType)) {
                    XComputedTypeReference casted = (XComputedTypeReference) parameterType;
                    XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference();
                    computedParameterType.setTypeProvider(new InitializerParameterTypeReferenceProvider(firstParameter, function, resolvedTypesByContext, resolvedTypes, featureScopeSession, this));
                    casted.setEquivalent(computedParameterType);
                }
            }
        }
    }
    doPrepareLocalTypes(resolvedTypes, featureScopeSession, operation, resolvedTypesByContext);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference)

Example 3 with XComputedTypeReference

use of org.eclipse.xtext.xtype.XComputedTypeReference in project xtext-xtend by eclipse.

the class XtendReentrantTypeResolver method doPrepareLocalTypes.

protected void doPrepareLocalTypes(final ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmFeature container, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
    List<JvmGenericType> localClasses = container.getLocalClasses();
    for (final JvmGenericType localClass : localClasses) {
        JvmTypeReference superType = localClass.getSuperTypes().get(0);
        final IFeatureScopeSession nestedSession = featureScopeSession;
        if (InferredTypeIndicator.isInferred(superType)) {
            final XComputedTypeReference casted = (XComputedTypeReference) superType;
            InferredTypeIndicator typeProvider = (InferredTypeIndicator) casted.getTypeProvider();
            final AnonymousClass anonymousClass = (AnonymousClass) typeProvider.getExpression();
            XConstructorCall constructorCall = anonymousClass.getConstructorCall();
            IScope typeScope = featureScopeSession.getScope(constructorCall, TypesPackage.Literals.JVM_PARAMETERIZED_TYPE_REFERENCE__TYPE, resolvedTypes);
            final JvmDeclaredType type = anonymousClassUtil.getSuperTypeNonResolving(anonymousClass, typeScope);
            if (type == null) {
                JvmUnknownTypeReference superTypeReference = TypesFactory.eINSTANCE.createJvmUnknownTypeReference();
                requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {

                    @Override
                    public void accept(JvmTypeReference capturingTypeReference) {
                        casted.setEquivalent(capturingTypeReference);
                        inferAnonymousClassConstructor(anonymousClass, localClass);
                    }
                });
            } else {
                final JvmParameterizedTypeReference superTypeReference = createSuperTypeReference(type, constructorCall);
                requestCapturedLocalVariables(superTypeReference, localClass, resolvedTypes, resolvedTypesByContext, new IAcceptor<JvmTypeReference>() {

                    @Override
                    @SuppressWarnings("deprecation")
                    public void accept(JvmTypeReference capturingTypeReference) {
                        casted.setEquivalent(capturingTypeReference);
                        IFeatureScopeSession mySession = addThisAndSuper(nestedSession, resolvedTypes.getReferenceOwner(), localClass, superTypeReference, false);
                        if (type.eClass() == TypesPackage.Literals.JVM_GENERIC_TYPE && ((JvmGenericType) type).isInterface()) {
                            localClass.getSuperTypes().add(0, typesBuilder.newTypeRef(localClass, Object.class));
                            inferAnonymousClassConstructor(anonymousClass, localClass);
                        } else {
                            for (JvmMember superMember : type.getMembers()) {
                                if (superMember instanceof JvmConstructor) {
                                    JvmConstructor superTypeConstructor = (JvmConstructor) superMember;
                                    boolean visible = mySession.isVisible(superTypeConstructor);
                                    inferAnonymousClassConstructor(anonymousClass, localClass, superTypeConstructor, visible);
                                }
                            }
                        }
                    }
                });
            }
        }
    }
}
Also used : IFeatureScopeSession(org.eclipse.xtext.xbase.scoping.batch.IFeatureScopeSession) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference) XConstructorCall(org.eclipse.xtext.xbase.XConstructorCall) JvmDeclaredType(org.eclipse.xtext.common.types.JvmDeclaredType) JvmUnknownTypeReference(org.eclipse.xtext.common.types.JvmUnknownTypeReference) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) AnonymousClass(org.eclipse.xtend.core.xtend.AnonymousClass) InferredTypeIndicator(org.eclipse.xtext.xbase.typesystem.InferredTypeIndicator) JvmConstructor(org.eclipse.xtext.common.types.JvmConstructor) IScope(org.eclipse.xtext.scoping.IScope) JvmMember(org.eclipse.xtext.common.types.JvmMember) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference)

Example 4 with XComputedTypeReference

use of org.eclipse.xtext.xtype.XComputedTypeReference in project xtext-xtend by eclipse.

the class XtendReentrantTypeResolver method _doPrepare.

/**
 * Initializes the type inference strategy for the cache field for create extensions.
 */
@Override
protected void _doPrepare(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmField field, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) {
    JvmTypeReference knownType = field.getType();
    if (InferredTypeIndicator.isInferred(knownType)) {
        XComputedTypeReference castedKnownType = (XComputedTypeReference) knownType;
        EObject sourceElement = associations.getPrimarySourceElement(field);
        if (sourceElement instanceof XtendFunction) {
            XtendFunction function = (XtendFunction) sourceElement;
            if (function.getCreateExtensionInfo() != null) {
                JvmOperation operation = associations.getDirectlyInferredOperation(function);
                if (operation != null) {
                    declareTypeParameters(resolvedTypes, field, resolvedTypesByContext);
                    XComputedTypeReference fieldType = getServices().getXtypeFactory().createXComputedTypeReference();
                    fieldType.setTypeProvider(new CreateCacheFieldTypeReferenceProvider(operation, resolvedTypes, featureScopeSession));
                    castedKnownType.setEquivalent(fieldType);
                    return;
                }
            }
        }
    }
    super._doPrepare(resolvedTypes, featureScopeSession, field, resolvedTypesByContext);
    doPrepareLocalTypes(resolvedTypesByContext.get(field), featureScopeSession, field, resolvedTypesByContext);
}
Also used : XtendFunction(org.eclipse.xtend.core.xtend.XtendFunction) JvmOperation(org.eclipse.xtext.common.types.JvmOperation) JvmTypeReference(org.eclipse.xtext.common.types.JvmTypeReference) EObject(org.eclipse.emf.ecore.EObject) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference)

Example 5 with XComputedTypeReference

use of org.eclipse.xtext.xtype.XComputedTypeReference in project xtext-xtend by eclipse.

the class XtendValidator method validateInferredType.

protected void validateInferredType(JvmTypeReference inferredType, XtendMember member, String messagePrefix, EAttribute location) {
    if (inferredType != null) {
        TreeIterator<EObject> iterator = EcoreUtil2.eAll(inferredType);
        while (iterator.hasNext()) {
            EObject next = iterator.next();
            if (next instanceof JvmParameterizedTypeReference) {
                JvmParameterizedTypeReference candidate = (JvmParameterizedTypeReference) next;
                JvmType type = candidate.getType();
                if (type instanceof JvmGenericType && !((JvmGenericType) type).getTypeParameters().isEmpty()) {
                    if (candidate.getArguments().isEmpty()) {
                        StringBuilder message = new StringBuilder(messagePrefix);
                        message = proxyAwareUIStrings.visit(inferredType, message);
                        if (message != null) {
                            message.append(" uses the raw type ");
                            message.append(type.getSimpleName());
                            message.append(". References to generic type ");
                            message = proxyAwareUIStrings.appendTypeSignature(type, message);
                            message.append(" should be parameterized");
                            warning(message.toString(), member, location, org.eclipse.xtext.xbase.validation.IssueCodes.RAW_TYPE);
                        }
                        return;
                    }
                }
            } else if (next instanceof XComputedTypeReference) {
                validateInferredType(((XComputedTypeReference) next).getEquivalent(), member, messagePrefix, location);
                iterator.prune();
            }
        }
    }
}
Also used : ToStringBuilder(org.eclipse.xtext.xbase.lib.util.ToStringBuilder) EObject(org.eclipse.emf.ecore.EObject) JvmGenericType(org.eclipse.xtext.common.types.JvmGenericType) XComputedTypeReference(org.eclipse.xtext.xtype.XComputedTypeReference) JvmType(org.eclipse.xtext.common.types.JvmType) JvmParameterizedTypeReference(org.eclipse.xtext.common.types.JvmParameterizedTypeReference)

Aggregations

XComputedTypeReference (org.eclipse.xtext.xtype.XComputedTypeReference)6 EObject (org.eclipse.emf.ecore.EObject)5 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)5 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 XtendFunction (org.eclipse.xtend.core.xtend.XtendFunction)2 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)2 JvmIdentifiableElement (org.eclipse.xtext.common.types.JvmIdentifiableElement)2 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)2 JvmType (org.eclipse.xtext.common.types.JvmType)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)1 JvmArrayType (org.eclipse.xtext.common.types.JvmArrayType)1 JvmComponentType (org.eclipse.xtext.common.types.JvmComponentType)1 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)1 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)1 JvmEnumerationLiteral (org.eclipse.xtext.common.types.JvmEnumerationLiteral)1 JvmEnumerationType (org.eclipse.xtext.common.types.JvmEnumerationType)1 JvmField (org.eclipse.xtext.common.types.JvmField)1