protected AbstractDemandTypeReferenceProvider getComputedTypeReference(JvmTypeReference knownType) { if (InferredTypeIndicator.isInferred(knownType)) { XComputedTypeReference casted = (XComputedTypeReference) knownType; JvmTypeReference equivalent = casted.getEquivalent(); if (equivalent instanceof XComputedTypeReference) { IJvmTypeReferenceProvider typeProvider = ((XComputedTypeReference) equivalent).getTypeProvider(); if (typeProvider instanceof AbstractDemandTypeReferenceProvider) { return (AbstractDemandTypeReferenceProvider) typeProvider; } } } return null; }
public static void resolveTo(JvmTypeReference inferred, JvmTypeReference resolved) { if (isInferred(inferred)) { XComputedTypeReference casted = (XComputedTypeReference) inferred; casted.setEquivalent(resolved); ((InferredTypeIndicator)casted.getTypeProvider()).resolved = true; } else { throw new IllegalStateException("Cannot resolve a reference that is not inferred"); } }
/** * Produces an inferred type which will be resolved on demand. It should not be attempted to resolve * this type during the model inference. * * @param expression the expression that will be used resolve the type. May not be <code>null</code>. * @return an inferred type. */ public JvmTypeReference inferredType(XExpression expression) { Preconditions.checkNotNull(expression); XComputedTypeReference result = xtypesFactory.createXComputedTypeReference(); result.setTypeProvider(new InferredTypeIndicator(expression)); return result; }
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); XComputedTypeReference casted = (XComputedTypeReference) parameterType; XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference(); computedParameterType.setTypeProvider(new InitializerParameterTypeReferenceProvider( firstParameter, function, featureScopeSession, this)); casted.setEquivalent(computedParameterType);
public static boolean isInferred(JvmTypeReference typeReference) { if (typeReference instanceof XComputedTypeReference) { IJvmTypeReferenceProvider typeProvider = ((XComputedTypeReference) typeReference).getTypeProvider(); if (typeProvider instanceof InferredTypeIndicator && !((InferredTypeIndicator)typeProvider).resolved) { return true; } } return false; }
@Override public void accept(JvmTypeReference capturingTypeReference) { casted.setEquivalent(capturingTypeReference); inferAnonymousClassConstructor(anonymousClass, localClass); } });
validateInferredType(((XComputedTypeReference) next).getEquivalent(), member, messagePrefix, location); iterator.prune();
@Override protected Object beforeSaveEObject(final InternalEObject object, final BinaryResourceImpl.EObjectOutputStream writable) throws IOException { JvmType _xblockexpression = null; { super.beforeSaveEObject(object, writable); JvmType _xifexpression = null; if ((object instanceof XComputedTypeReference)) { _xifexpression = ((XComputedTypeReference)object).getType(); } _xblockexpression = _xifexpression; } return _xblockexpression; }
/** * 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); }
if (InferredTypeIndicator.isInferred(superType)) { final XComputedTypeReference casted = (XComputedTypeReference) superType; InferredTypeIndicator typeProvider = (InferredTypeIndicator) casted.getTypeProvider(); final AnonymousClass anonymousClass = (AnonymousClass) typeProvider.getExpression(); XConstructorCall constructorCall = anonymousClass.getConstructorCall();
@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() || type.eClass() == TypesPackage.Literals.JVM_ANNOTATION_TYPE) { 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); } } } } });
/** * Returns the expression that will be used to infer the given type from. If the type is * already resolved, the result will be null. If no expression can be determined, null is * also returned. */ protected XExpression getInferredFrom(JvmTypeReference typeReference) { if (InferredTypeIndicator.isInferred(typeReference)) { XComputedTypeReference computed = (XComputedTypeReference) typeReference; if (computed.getEquivalent() instanceof XComputedTypeReference) { XComputedTypeReference inferred = (XComputedTypeReference) computed.getEquivalent(); IJvmTypeReferenceProvider typeProvider = inferred.getTypeProvider(); if (typeProvider instanceof DemandTypeReferenceProvider) { return ((DemandTypeReferenceProvider) typeProvider).expression; } } } return null; }
protected void _doPrepare(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmOperation operation, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) { StackedResolvedTypes childResolvedTypes = declareTypeParameters(resolvedTypes, operation, resolvedTypesByContext); JvmTypeReference knownType = operation.getReturnType(); if (InferredTypeIndicator.isInferred(knownType)) { XComputedTypeReference casted = (XComputedTypeReference) knownType; JvmTypeReference reference = createComputedTypeReference( resolvedTypesByContext, childResolvedTypes, featureScopeSession, operation, (InferredTypeIndicator) casted.getTypeProvider(), true); casted.setEquivalent(reference); } else if (knownType != null) { LightweightTypeReference lightweightReference = childResolvedTypes.getReferenceOwner().toLightweightTypeReference(knownType); childResolvedTypes.setType(operation, lightweightReference); } else { JvmTypeReference reference = createComputedTypeReference(resolvedTypesByContext, childResolvedTypes, featureScopeSession, operation, null, true); operation.setReturnType(reference); } }
/** * Produces an inferred type which will be resolved on demand. It should not be attempted to resolve * this type during the model inference. * * @return an inferred type. */ public JvmTypeReference inferredType() { XComputedTypeReference result = xtypesFactory.createXComputedTypeReference(); result.setTypeProvider(new InferredTypeIndicator(null)); return result; }
protected static <R extends LocalVariableCapturer> R findLocalClassSupertype(JvmTypeReference typeReference) { if (InferredTypeIndicator.isInferred(typeReference)) { JvmTypeReference equivalent = ((XComputedTypeReference) typeReference).getEquivalent(); return findLocalClassSupertype(equivalent); } if (typeReference instanceof XComputedTypeReference) { IJvmTypeReferenceProvider typeProvider = ((XComputedTypeReference) typeReference).getTypeProvider(); if (typeProvider instanceof LocalVariableCapturer) { @SuppressWarnings("unchecked") R result = (R) typeProvider; return result; } } return null; }
protected void _doPrepare(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmField field, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext) { StackedResolvedTypes childResolvedTypes = declareTypeParameters(resolvedTypes, field, resolvedTypesByContext); JvmTypeReference knownType = field.getType(); if (InferredTypeIndicator.isInferred(knownType)) { XComputedTypeReference casted = (XComputedTypeReference) knownType; JvmTypeReference reference = createComputedTypeReference(resolvedTypesByContext, childResolvedTypes, featureScopeSession, field, (InferredTypeIndicator) casted.getTypeProvider(), false); casted.setEquivalent(reference); } else if (knownType != null) { LightweightTypeReference lightweightReference = childResolvedTypes.getReferenceOwner().toLightweightTypeReference(knownType); childResolvedTypes.setType(field, lightweightReference); } else { JvmTypeReference reference = createComputedTypeReference(resolvedTypesByContext, childResolvedTypes, featureScopeSession, field, null, false); field.setType(reference); } }
protected JvmTypeReference createComputedTypeReference( Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext, ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession, JvmMember member, /* @Nullable */ InferredTypeIndicator indicator, boolean returnType) { XComputedTypeReference result = getServices().getXtypeFactory().createXComputedTypeReference(); if (indicator == null || indicator.getExpression() == null) result.setTypeProvider(createTypeProvider(resolvedTypesByContext, resolvedTypes, featureScopeSession, member, returnType)); else result.setTypeProvider(createTypeProvider(resolvedTypesByContext, resolvedTypes, featureScopeSession, member, indicator.getExpression(), returnType)); // TODO do we need a lightweight computed type reference? // resolvedTypes.setType(member, result); return result; }
@Override public LightweightTypeReference doVisitComputedTypeReference(XComputedTypeReference reference) { IJvmTypeReferenceProvider typeProvider = reference.getTypeProvider(); if (typeProvider instanceof UnboundTypeReferenceResolver) { UnboundTypeReference typeReference = ((UnboundTypeReferenceResolver) typeProvider).getUnboundTypeReference(); return typeReference.copyInto(owner); } JvmTypeReference equivalent = reference.getEquivalent(); if (equivalent == null) return owner.newUnknownTypeReference(); return super.doVisitComputedTypeReference(reference); }
protected void requestCapturedLocalVariables(JvmTypeReference toBeWrapped, JvmDeclaredType type, ResolvedTypes resolvedTypes, Map<JvmIdentifiableElement, ResolvedTypes> resolvedTypesByContext, IAcceptor<JvmTypeReference> result) { LocalVariableCapturerImpl capturer = new LocalVariableCapturerImpl(toBeWrapped, type, this, resolvedTypes, resolvedTypesByContext); XComputedTypeReference ref = getServices().getXtypeFactory().createXComputedTypeReference(); ref.setTypeProvider(capturer); result.accept(ref); capturer.awaitCapturing(); } }
@Override public JvmTypeReference toTypeReference() { if (internalGetResolvedTo() != null) { return resolvedTo.toTypeReference(); } XComputedTypeReference result = getServices().getXtypeFactory().createXComputedTypeReference(); result.setTypeProvider(new UnboundTypeReferenceResolver(this)); return result; }