/** * Computes the common super type for the given list of types. The list may not be empty. */ protected LightweightTypeReference getCommonSuperType(List<LightweightTypeReference> types, ITypeReferenceOwner owner) { return services.getTypeConformanceComputer().getCommonSuperType(types, owner); }
protected boolean isJavaConformant(LightweightTypeReference left, LightweightTypeReference right) { boolean result = (services.getTypeConformanceComputer().isConformant( left, right, RawTypeConformanceComputer.ALLOW_PRIMITIVE_WIDENING | RawTypeConformanceComputer.ALLOW_RAW_TYPE_CONVERSION | RawTypeConformanceComputer.ALLOW_BOXING | RawTypeConformanceComputer.ALLOW_UNBOXING) & RawTypeConformanceComputer.SUCCESS) != 0; return result; }
public boolean isHandled(final LightweightTypeReference actualTypeReference, final LightweightTypeReference previousTypeReference) { boolean _xblockexpression = false; { @Extension final TypeConformanceComputer typeConformanceComputer = this.services.getTypeConformanceComputer(); final int conformant = typeConformanceComputer.isConformant(previousTypeReference, actualTypeReference, ((RawTypeConformanceComputer.ALLOW_BOXING_UNBOXING | RawTypeConformanceComputer.ALLOW_PRIMITIVE_WIDENING) | RawTypeConformanceComputer.ALLOW_RAW_TYPE_CONVERSION)); _xblockexpression = ((conformant & RawTypeConformanceComputer.SUCCESS) != 0); } return _xblockexpression; } }
private LightweightTypeReference getCommonSuperTypes(List<LightweightTypeReference> types, ITypeReferenceOwner owner) { // use the given type list as-is TypeConformanceComputer conformanceComputer = owner.getServices().getTypeConformanceComputer(); LightweightTypeReference type = conformanceComputer.getCommonSuperType(types, owner); if (type == null) { // failed - remove void if any List<LightweightTypeReference> filteredOutTypes = Lists.newArrayListWithCapacity(types.size()); for(LightweightTypeReference outType: types) { if (!outType.isPrimitiveVoid()) { filteredOutTypes.add(outType); } } // and try again to compute the common super types if (!filteredOutTypes.isEmpty() && filteredOutTypes.size() != types.size()) { type = conformanceComputer.getCommonSuperType(filteredOutTypes, owner); } // still no success - use the first non-void type in the list or void if all are void if (type == null) { type = filteredOutTypes.isEmpty() ? types.get(0) : filteredOutTypes.get(0); } } return type; }
protected LightweightTypeReference getMergedType(List<LightweightTypeReference> types) { if (types.isEmpty()) { return null; } if (types.size() == 1) { LightweightTypeReference result = types.get(0); return result; } LightweightTypeReference result = getServices().getTypeConformanceComputer().getCommonSuperType(types, getReferenceOwner()); if (result != null || types.isEmpty()) { return result; } // common type of JvmAnyType and JvmVoid may be null ... use JvmAnyType in that case for (LightweightTypeReference type: types) { if (!type.isType(Void.TYPE)) { return type; } } return types.get(0); }
result = getServices().getTypeConformanceComputer().getCommonSuperType(computedTypes, resolvedTypes.getReferenceOwner());
public int internalIsAssignableFrom(LightweightTypeReference reference, TypeConformanceComputationArgument argument) { TypeConformanceComputer conformanceCompouter = getOwner().getServices().getTypeConformanceComputer(); int result = conformanceCompouter.isConformant(this, reference, argument); return result; }
types.add(caseType); TypeConformanceComputer conformanceComputer = typeResolver.getServices().getTypeConformanceComputer(); if (types.isEmpty()) return null;
protected LightweightTypeReference normalizedMultiType(ITypeReferenceOwner referenceOwner, JvmTypeReference ref) { LightweightTypeReference result = referenceOwner.toLightweightTypeReference(ref); if (result.isSynonym()) { List<LightweightTypeReference> components = result.getMultiTypeComponents(); result = referenceOwner.getServices().getTypeConformanceComputer().getCommonSuperType(components, referenceOwner); } return result; }
protected JvmTypeReference resolveSynonymType(JvmSynonymTypeReference reference, EObject context) { LightweightTypeReference lightweight = toLightweight(reference, context); LightweightTypeReference superType = lightweight.getOwner().getServices().getTypeConformanceComputer().getCommonSuperType(lightweight.getMultiTypeComponents(), lightweight.getOwner()); return superType.toJavaCompliantTypeReference(); }
@Override public LightweightTypeReference toJavaType() { if (isMultiType()) { LightweightTypeReference result = null; for(LightweightTypeReference component: getMultiTypeComponents()) { if (!component.isInterfaceType()) { if (result != null) { result = null; break; } result = component; } } if (result != null) { return result; } } LightweightTypeReference result = getServices().getTypeConformanceComputer().getCommonSuperType(getMultiTypeComponents(), getOwner()); if (result == null) { throw new IllegalStateException("Cannot expression " + this + " as Java type reference"); } return result.toJavaType(); }
TypeConformanceComputer conformanceComputer = typeResolver.getServices().getTypeConformanceComputer(); List<LightweightTypeReference> parameterTypes = Lists.newArrayListWithCapacity(cases.size()); JvmOperation inheritedDispatcher = null;
LightweightTypeReference argument = typeArguments.get(i); JvmTypeParameter declaration = typeParameters.get(i); TypeConformanceComputer conformanceComputer = argument.getOwner().getServices().getTypeConformanceComputer(); if (argument.getType() != declaration) { LightweightTypeReference reference = argument.getOwner().newParameterizedTypeReference(declaration);
protected JvmTypeReference toJavaCompliantTypeReference(List<LightweightTypeReference> types, IVisibilityHelper visibilityHelper) { LightweightTypeReference type = getServices().getTypeConformanceComputer().getCommonSuperType(types, getOwner()); if (type == null) { return getOwner().getServices().getTypeReferences().getTypeForName(Object.class, getOwner().getContextResourceSet()); } return type.toJavaCompliantTypeReference(visibilityHelper); }
private void convertMultiType(LightweightTypeReference expectation, CompoundTypeReference multiType, XExpression context, ITreeAppendable b, Later expression) { LightweightTypeReference castTo = null; List<LightweightTypeReference> components = multiType.getMultiTypeComponents(); ITypeReferenceOwner owner = multiType.getOwner(); LightweightTypeReference commonType = owner.getServices().getTypeConformanceComputer().getCommonSuperType(components, owner); if (!isJavaConformant(expectation, commonType)) { for(LightweightTypeReference candidate: multiType.getMultiTypeComponents()) { if (isJavaConformant(expectation, candidate)) { castTo = candidate; break; } } } if (castTo != null && mustInsertTypeCast(context, castTo)) { b.append("(("); b.append(castTo); b.append(")"); expression.exec(b); b.append(")"); } else { expression.exec(b); } }