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 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; }
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)); } } }
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);
@Override protected ITypeComputationResult createNoTypeResult() { JvmOperation operation = (JvmOperation) getMember(); LightweightTypeReference expectedType = ((LogicalContainerAwareReentrantTypeResolver)getResolver()).getReturnTypeOfOverriddenOperation(operation, resolvedTypes, getFeatureScopeSession()); if (expectedType != null) { InferredTypeIndicator.resolveTo(operation.getReturnType(), expectedType.toJavaCompliantTypeReference()); } return new NoTypeResult(getMember(), resolvedTypes.getReferenceOwner()); } }
/** * 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; }
@Override /* @Nullable */ protected LightweightTypeReference getExpectedType() { JvmOperation operation = (JvmOperation) getMember(); LightweightTypeReference expectedType = ((LogicalContainerAwareReentrantTypeResolver)getResolver()).getReturnTypeOfOverriddenOperation(operation, resolvedTypes, getFeatureScopeSession()); if (expectedType != null) { InferredTypeIndicator.resolveTo(operation.getReturnType(), expectedType.toJavaCompliantTypeReference()); return expectedType; } return getResolvedTypes().getExpectedTypeForAssociatedExpression(getMember(), getNonNullRootExpression()); }
/** * 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 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; }
@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 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()); }
/** * 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) {