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"); } }
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; }
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; }
/** * Detects whether the type reference refers to primitive boolean. * * @since 2.9 */ protected boolean isPrimitiveBoolean(JvmTypeReference typeRef) { if (InferredTypeIndicator.isInferred(typeRef)) { return false; } return typeRef != null && typeRef.getType() != null && !typeRef.getType().eIsProxy() && "boolean".equals(typeRef.getType().getIdentifier()); }
protected void resolveDispatchCaseTypes(JvmOperation dispatcher, List<JvmOperation> dispatchCases, LightweightTypeReference type, IFeatureScopeSession featureScopeSession) { if (InferredTypeIndicator.isInferred(dispatcher.getReturnType())) { InferredTypeIndicator.resolveTo(dispatcher.getReturnType(), toJavaCompliantTypeReference(type, featureScopeSession)); } for (JvmOperation dispatchCase : dispatchCases) { if (InferredTypeIndicator.isInferred(dispatchCase.getReturnType())) { InferredTypeIndicator.resolveTo(dispatchCase.getReturnType(), toJavaCompliantTypeReference(type, featureScopeSession)); } } }
/** * 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; }
private JvmTypeReference ensureValidType(Resource targetResource, JvmTypeReference returnType) { // No return type could be inferred => assume "void" if (returnType == null) { return this._typeReferenceBuilder.typeRef(Void.TYPE); } // The given type is not associated to the target resource => force relocation. final Resource returnTypeResource = returnType.eResource(); if (returnTypeResource != null && !Objects.equal(returnType.eResource(), targetResource)) { return this.typeBuilder.cloneWithProxies(returnType); } // A return type was inferred => use it as-is because it is not yet resolved to the concrete type. if (InferredTypeIndicator.isInferred(returnType)) { return returnType; } // A return was inferred and resolved => use it. return this.typeBuilder.cloneWithProxies(returnType); }
/** * Returns <code>null</code> if the given operation declares it's own return type or if it does not override * another operation. */ /* @Nullable */ @SuppressWarnings("unused") protected LightweightTypeReference getReturnTypeOfOverriddenOperation(JvmOperation operation, ResolvedTypes resolvedTypes, IFeatureScopeSession session) { if (operation.getVisibility() == JvmVisibility.PRIVATE) return null; if (InferredTypeIndicator.isInferred(operation.getReturnType())) { LightweightTypeReference declaringType = resolvedTypes.getActualType(operation.getDeclaringType()); if (declaringType == null) { throw new IllegalStateException("Cannot determine declaring type of operation: " + operation); } LightweightTypeReference result = overrideHelper.getReturnTypeOfOverriddenOperation(operation, declaringType); return result; } return null; }
protected IEObjectDescription doGetSingleElement(JvmDeclaredType declarator, QualifiedName name, String firstSegment, int dollarIndex) { if (declarator.isLocal()) { JvmTypeReference superTypeReference = Iterables.getLast(declarator.getSuperTypes()); if (InferredTypeIndicator.isInferred(superTypeReference)) return findNestedTypeInLocalTypeNonResolving(declarator, name, firstSegment, dollarIndex); } Iterable<JvmDeclaredType> nestedTypes = declarator.findAllNestedTypesByName(firstSegment); for(JvmDeclaredType nested: nestedTypes) { JvmType nestedType = findNestedType(nested, 0, name); if (nestedType != null) { return toDescription(name, nestedType, dollarIndex, 0); } } return null; }
if (operation.getVisibility() == JvmVisibility.PRIVATE || !InferredTypeIndicator.isInferred(operation.getReturnType())) { return null;
if (InferredTypeIndicator.isInferred(type)) { return type;
&& InferredTypeIndicator.isInferred(operation.getReturnType())) { JvmOperation dispatcher = dispatchHelper.getDispatcherOperation(operation); if (dispatcher == null) { if (InferredTypeIndicator.isInferred(dispatchCase.getReturnType())) { dispatchCasesWithInferredReturnType.add(dispatchCase); } else { if (dispatchCaseResolvedTypes == null) { if (preparedResolvedTypes.containsKey(dispatchCase)) { if (InferredTypeIndicator.isInferred(dispatchCase.getReturnType())) { if (declaredDispatcherType == null) { dispatchCaseResults.add(childResolvedTypes.getActualType(dispatchCase)); unmarkComputing(dispatchCase.getReturnType()); if (InferredTypeIndicator.isInferred(dispatchCase.getReturnType())) { if (declaredDispatcherType == null) { LightweightTypeReference returnType = dispatchCaseResult.getReturnType();
if (operation.getVisibility() == JvmVisibility.PRIVATE) return null; if (InferredTypeIndicator.isInferred(operation.getReturnType())) { LightweightTypeReference declaringType = resolvedTypes.getActualType(operation.getDeclaringType()); if (declaringType == null) {
@Override /* @Nullable */ protected LightweightTypeReference getExpectedType() { LightweightTypeReference expectedType = super.getExpectedType(); if (expectedType != null) { return expectedType; } if (dispatcher != null) { JvmOperation operation = (JvmOperation) getMember(); if (!InferredTypeIndicator.isInferred(dispatcher.getReturnType())) { LightweightTypeReference result = getResolvedTypes().getActualType(dispatcher); if (result != null) InferredTypeIndicator.resolveTo(operation.getReturnType(), result.toJavaCompliantTypeReference()); return result; } } return inheritedExpectedType; }
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); } }
JvmFormalParameter parameter = parameters.get(i); JvmTypeReference parameterType = parameter.getParameterType(); if (InferredTypeIndicator.isInferred(parameterType)) { XComputedTypeReference casted = (XComputedTypeReference) parameterType; XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference(); JvmFormalParameter firstParameter = operation.getParameters().get(0); JvmTypeReference parameterType = firstParameter.getParameterType(); if (InferredTypeIndicator.isInferred(parameterType)) { XComputedTypeReference casted = (XComputedTypeReference) parameterType; XComputedTypeReference computedParameterType = getServices().getXtypeFactory().createXComputedTypeReference();
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); } }
/** * 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); }
JvmTypeReference superType = localClass.getSuperTypes().get(0); final IFeatureScopeSession nestedSession = featureScopeSession; if (InferredTypeIndicator.isInferred(superType)) { final XComputedTypeReference casted = (XComputedTypeReference) superType; InferredTypeIndicator typeProvider = (InferredTypeIndicator) casted.getTypeProvider();
if (operation.getVisibility() == JvmVisibility.PRIVATE || !InferredTypeIndicator.isInferred(operation.getReturnType())) { return null;