@Override public LightweightTypeReference getActualExpressionType() { return resolution.getActualType(expression); }
@Override protected JvmTypeReference handleReentrantInvocation(XComputedTypeReferenceImplCustom context) { resolvedTypes.addDiagnostic(new EObjectDiagnosticImpl( Severity.WARNING, IssueCodes.TOO_LITTLE_TYPE_INFORMATION, "Cannot infer type from recursive usage. Type 'Object' is used.", typeResolver.getSourceElement(operation), null, -1, null)); AnyTypeReference result = resolvedTypes.getReferenceOwner().newAnyTypeReference(); return typeResolver.toJavaCompliantTypeReference(result, session); } }
protected JvmTypeReference doGetTypeReferenceWithCurrentTypeResolver() { LightweightTypeReference actualType = returnType ? resolvedTypes.getReturnType(expression) : resolvedTypes.getActualType(expression); if (actualType == null) { computeTypes(resolvedTypesByContext, resolvedTypes, session, member); actualType = returnType ? resolvedTypes.getExpectedReturnType(expression) : resolvedTypes.getExpectedType(expression); if (actualType == null) actualType = returnType ? resolvedTypes.getReturnType(expression) : resolvedTypes.getActualType(expression); } if (actualType == null) return null; return toJavaCompliantTypeReference(convertLocalType(actualType), session); }
protected void mergeQueuedDiagnostics(ResolvedTypes parent) { Collection<AbstractDiagnostic> diagnostics = super.getQueuedDiagnostics(); for(AbstractDiagnostic diagnostic: diagnostics) { parent.addDiagnostic(diagnostic); } }
protected UnboundTypeReference createUnboundTypeReference(XExpression expression, JvmTypeParameter type) { UnboundTypeReference result = new UnboundTypeReference(getReferenceOwner(), expression, type) { // the constructor is protected since this guides developers better // therefore we use an anonymous class, here }; acceptUnboundTypeReference(result.getHandle(), result); return result; }
@Override public void applyToComputationState() { ResolvedTypes resolvedTypes = getState().getResolvedTypes(); TypeExpectation expectation = new TypeExpectation(null, getState(), false); LightweightTypeReference actualType = resolvedTypes.getActualType(getFeature()); if (actualType == null) throw new IllegalStateException("Cannot determine actual type of already resolved implicit first argument"); resolvedTypes.acceptType(getFeatureCall(), expectation, actualType.copyInto(resolvedTypes.getReferenceOwner()), false, ConformanceFlags.UNCHECKED); super.applyToComputationState(); }
@Override /* @Nullable */ protected JvmTypeReference doGetTypeReference(XComputedTypeReferenceImplCustom context) { try { CreateExtensionInfo createExtensionInfo = createFunction.getCreateExtensionInfo(); XExpression expression = createExtensionInfo.getCreateExpression(); LightweightTypeReference actualType = resolvedTypes.getReturnType(expression); if (actualType == null) { JvmOperation operation = typeResolver.associations.getDirectlyInferredOperation(createFunction); if (operation != null) { IFeatureScopeSession session = operation.isStatic() ? featureScopeSession : featureScopeSession.toInstanceContext(); typeResolver.computeTypes(resolvedTypesByContext, resolvedTypes, session, operation); actualType = resolvedTypes.getReturnType(expression); } } if (actualType == null) return null; // actualType may not be java compliant but still carry more information than the // java compliant reference JvmTypeReference result = typeResolver.toJavaCompliantTypeReference(actualType, featureScopeSession); if (actualType.isMultiType() || result.getType() != actualType.getType()) { resolvedTypes.setType(param, resolvedTypes.getReferenceOwner().toLightweightTypeReference(result)); resolvedTypes.reassignType(param, actualType); } return result; } finally { context.unsetTypeProviderWithoutNotification(); } } }
@Override public ITypeReferenceOwner getReferenceOwner() { return resolvedTypes.getReferenceOwner(); }
if (inheritedDispatcher != null) { JvmFormalParameter inheritedParameter = inheritedDispatcher.getParameters().get(idx); inheritedParameterType = resolvedTypes.getActualType(inheritedParameter); break; LightweightTypeReference parameterType = resolvedTypes.getActualType(parameter); if (parameterType != null && !parameterType.isType(Void.class)) { if (inheritedParameterType != null) { if (!inheritedParameterType.isAssignableFrom(parameterType)) { XtendParameter xtendParameter = (XtendParameter) typeResolver.getSourceElement(parameter); resolvedTypes.addDiagnostic(new EObjectDiagnosticImpl( Severity.ERROR, org.eclipse.xtend.core.validation.IssueCodes.DISPATCH_FUNCTIONS_INVALID_PARAMETER_TYPE, LightweightTypeReference parameterType = conformanceComputer.getCommonSuperType(parameterTypes, resolvedTypes.getReferenceOwner()); if (parameterType == null) { return resolvedTypes.getReferenceOwner().newUnknownTypeReference().toJavaCompliantTypeReference();
protected void mergeExpressionTypesIntoParent(ResolvedTypes parent) { Map<XExpression, List<TypeData>> expressionTypes = basicGetExpressionTypes(); if (!expressionTypes.isEmpty()) { for(Map.Entry<XExpression, List<TypeData>> entry: expressionTypes.entrySet()) { List<TypeData> list = entry.getValue(); for (int i = 0, size = list.size(); i < size; i++) { parent.acceptType(entry.getKey(), prepareMerge(list.get(i), parent.getReferenceOwner())); } } } }
public void reassignType(JvmIdentifiableElement identifiable, /* @Nullable */ LightweightTypeReference reference) { if (reference != null) { LightweightTypeReference actualType = getActualType(identifiable); if (actualType != null) { if (actualType.getKind() == LightweightTypeReference.KIND_UNBOUND_TYPE_REFERENCE && !((UnboundTypeReference) actualType).internalIsResolved()) { UnboundTypeReference casted = (UnboundTypeReference) actualType; List<LightweightBoundTypeArgument> hints = getHints(casted.getHandle()); boolean canAddHint = true; for(int i = 0; i < hints.size() && canAddHint; i++) { casted.acceptHint(reference, BoundTypeArgumentSource.EXPECTATION, identifiable, VarianceInfo.OUT, VarianceInfo.OUT); ensureReassignedTypesMapExists().put(identifiable, reference); } else if (!reference.isAssignableFrom(actualType)) { if (actualType.isAssignableFrom(reference)) { ensureReassignedTypesMapExists().put(identifiable, reference); } else { CompoundTypeReference multiType = toMultiType(actualType, reference); ensureReassignedTypesMapExists().put(identifiable, multiType); ensureReassignedTypesMapExists().put(identifiable, reference);
protected void mergeTypesIntoParent(ResolvedTypes parent) { Map<JvmIdentifiableElement, LightweightTypeReference> types = basicGetTypes(); if (!types.isEmpty()) { for(Map.Entry<JvmIdentifiableElement, LightweightTypeReference> entry: types.entrySet()) { LightweightTypeReference value = entry.getValue(); if (value instanceof UnboundTypeReference && super.isResolved(((UnboundTypeReference) value).getHandle())) { parent.setType(entry.getKey(), value.getUpperBoundSubstitute().copyInto(parent.getReferenceOwner())); } else { parent.setType(entry.getKey(), value.copyInto(parent.getReferenceOwner())); } } } }
List<LightweightTypeReference> types = Lists.newArrayListWithCapacity(cases.size()); for (JvmOperation operation : cases) { LightweightTypeReference caseType = resolvedTypes.getActualType(operation); types.add(caseType); if (types.isEmpty()) return null; LightweightTypeReference result = conformanceComputer.getCommonSuperType(types, resolvedTypes.getReferenceOwner()); if (result == null) { Iterator<LightweightTypeReference> iterator = types.iterator(); result = conformanceComputer.getCommonSuperType(types, resolvedTypes.getReferenceOwner()); if (result == null) { throw new UnsupportedOperationException("Cannot determine common super type of: " + types);
LightweightTypeReference reference = unbound.copyInto(parent.getReferenceOwner()); if (reference instanceof UnboundTypeReference) { parent.acceptUnboundTypeReference(unbound.getHandle(), (UnboundTypeReference) reference); if (!parent.isResolved(hint.getKey())) { List<LightweightBoundTypeArgument> boundTypeArguments = hint.getValue(); for(LightweightBoundTypeArgument boundTypeArgument: boundTypeArguments) { if (boundTypeArgument.getOrigin() instanceof VarianceInfo) { parent.acceptHint(hint.getKey(), boundTypeArgument); } else { LightweightBoundTypeArgument copy = new LightweightBoundTypeArgument( boundTypeArgument.getTypeReference().copyInto(parent.getReferenceOwner()), boundTypeArgument.getSource(), boundTypeArgument.getOrigin(), boundTypeArgument.getDeclaredVariance(), boundTypeArgument.getActualVariance()); parent.acceptHint(hint.getKey(), copy);
protected void resolveDependentTypeArguments(final Object handle, LightweightBoundTypeArgument boundTypeArgument) { List<LightweightBoundTypeArgument> existingTypeArguments = ensureTypeParameterHintsMapExists().get(handle); if (existingTypeArguments != null) { for(int i = 0; i < existingTypeArguments.size(); i++) { acceptHint(existingReference.getHandle(), boundTypeArgument); ExpectationTypeParameterHintCollector collector = new ExpectationTypeParameterHintCollector(getReferenceOwner()); collector.processPairedReferences(boundTypeReference, existingTypeReference); if (existingTypeReference instanceof UnboundTypeReference) { UnboundTypeReference existingReference = (UnboundTypeReference) existingTypeReference; if (!isResolved(existingReference.getHandle())) { if (!boundTypeReference.isWildcard()) { existingReference.acceptHint(boundTypeReference, if (existingTypeReference instanceof UnboundTypeReference) { UnboundTypeReference existingReference = (UnboundTypeReference) existingTypeReference; if (!isResolved(existingReference.getHandle())) {
@Override public void addExpressionScope(ResolvedTypes current, EObject context, IFeatureScopeSession session, Anchor anchor) { EnumMap<Anchor, ExpressionScope> recordedScopes = featureScopeSessions.get(context); if (recordedScopes == null) { recordedScopes = Maps.newEnumMap(Anchor.class); featureScopeSessions.put(context, recordedScopes); } ExpressionScope scope = recordedScopes.get(anchor); if (scope == null) { scope = new ExpressionScope(current.getResolver().getFeatureScopes(), context, anchor, current.getReferenceOwner()); recordedScopes.put(anchor, scope); } scope.addData(session, current.withFlattenedReassignedTypes()); }
@Override public void addDiagnostic(AbstractDiagnostic diagnostic) { resolvedTypes.addDiagnostic(diagnostic); }
@Override public List<LightweightTypeReference> getThrownExceptions(XExpression obj) { return getServices().getEarlyExitComputer().getThrownExceptions(obj, this, this.getReferenceOwner()); }
@Override public void discardReassignedTypes(JvmIdentifiableElement refinable) { resolvedTypes.reassignType(refinable, (LightweightTypeReference) null); }
protected LightweightTypeReference doGetDeclaredType(JvmIdentifiableElement identifiable) { if (identifiable instanceof JvmType) { ITypeReferenceOwner owner = getReferenceOwner(); LightweightTypeReference result = owner.toLightweightTypeReference((JvmType) identifiable); return result; } JvmTypeReference type = getDeclaredType(identifiable); if (type != null) { ITypeReferenceOwner owner = getReferenceOwner(); LightweightTypeReference result = owner.toLightweightTypeReference(type); return result; } return null; }