Search in sources :

Example 1 with IFeatureScopeSession

use of org.eclipse.xtext.xbase.scoping.batch.IFeatureScopeSession in project xtext-xtend by eclipse.

the class XtendReentrantTypeResolver method computeDanglingExpressionType.

/**
 * Computes the type of the given expression if it was not yet processed.
 * Used to compute types for expressions that are contained in heavily broken
 * models thus the model inferrer could not put them into proper contexts, or
 * for expressions that are dangling after an active annotation did its job in
 * an unexpected way.
 */
protected void computeDanglingExpressionType(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, XtendMember member, XExpression expression) {
    if (!allRootedExpressions.contains(expression)) {
        rootedInstances.add(expression);
        IFeatureScopeSession session = member == null || member.isStatic() ? featureScopeSession : featureScopeSession.toInstanceContext();
        super.computeTypes(resolvedTypes, session, expression);
    }
}
Also used : IFeatureScopeSession(org.eclipse.xtext.xbase.scoping.batch.IFeatureScopeSession)

Example 2 with IFeatureScopeSession

use of org.eclipse.xtext.xbase.scoping.batch.IFeatureScopeSession 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)

Aggregations

IFeatureScopeSession (org.eclipse.xtext.xbase.scoping.batch.IFeatureScopeSession)2 AnonymousClass (org.eclipse.xtend.core.xtend.AnonymousClass)1 JvmConstructor (org.eclipse.xtext.common.types.JvmConstructor)1 JvmDeclaredType (org.eclipse.xtext.common.types.JvmDeclaredType)1 JvmGenericType (org.eclipse.xtext.common.types.JvmGenericType)1 JvmMember (org.eclipse.xtext.common.types.JvmMember)1 JvmParameterizedTypeReference (org.eclipse.xtext.common.types.JvmParameterizedTypeReference)1 JvmTypeReference (org.eclipse.xtext.common.types.JvmTypeReference)1 JvmUnknownTypeReference (org.eclipse.xtext.common.types.JvmUnknownTypeReference)1 IScope (org.eclipse.xtext.scoping.IScope)1 XConstructorCall (org.eclipse.xtext.xbase.XConstructorCall)1 InferredTypeIndicator (org.eclipse.xtext.xbase.typesystem.InferredTypeIndicator)1 XComputedTypeReference (org.eclipse.xtext.xtype.XComputedTypeReference)1