Renamed JetType.isNullable() to isMarkedNullable()

This commit is contained in:
Valentin Kipyatkov
2014-12-03 21:36:10 +03:00
parent c76e69af62
commit b8d1f115bf
53 changed files with 91 additions and 96 deletions
@@ -407,7 +407,7 @@ public class DescriptorUtils {
public static boolean shouldRecordInitializerForProperty(@NotNull VariableDescriptor variable, @NotNull JetType type) {
if (variable.isVar() || type.isError()) return false;
if (type instanceof LazyType || type.isNullable()) return true;
if (type instanceof LazyType || type.isMarkedNullable()) return true;
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
return KotlinBuiltIns.isPrimitiveType(type) ||
@@ -433,7 +433,7 @@ public class ConstraintSystemImpl implements ConstraintSystem {
TypeBoundsImpl typeBounds = getTypeBounds(parameterType);
assert typeBounds != null : "constraint should be generated only for type variables";
if (!parameterType.isNullable() || !constrainingType.isNullable()) {
if (!parameterType.isMarkedNullable() || !constrainingType.isMarkedNullable()) {
typeBounds.addBound(boundKind, constrainingType, constraintPosition);
return;
}
@@ -38,7 +38,7 @@ public abstract class AbstractJetType implements JetType {
public final int hashCode() {
int result = getConstructor().hashCode();
result = 31 * result + getArguments().hashCode();
result = 31 * result + (isNullable() ? 1 : 0);
result = 31 * result + (isMarkedNullable() ? 1 : 0);
return result;
}
@@ -49,13 +49,13 @@ public abstract class AbstractJetType implements JetType {
JetType type = (JetType) obj;
return isNullable() == type.isNullable() && JetTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(this, type);
return isMarkedNullable() == type.isMarkedNullable() && JetTypeChecker.FLEXIBLE_UNEQUAL_TO_INFLEXIBLE.equalTypes(this, type);
}
@Override
public String toString() {
List<TypeProjection> arguments = getArguments();
return getConstructor() + (arguments.isEmpty() ? "" : "<" + argumentsToString(arguments) + ">") + (isNullable() ? "?" : "");
return getConstructor() + (arguments.isEmpty() ? "" : "<" + argumentsToString(arguments) + ">") + (isMarkedNullable() ? "?" : "");
}
private static StringBuilder argumentsToString(List<TypeProjection> arguments) {
@@ -37,7 +37,7 @@ public abstract class AbstractLazyType(storageManager: StorageManager) : Abstrac
protected abstract fun computeMemberScope(): JetScope
override fun isNullable() = false
override fun isMarkedNullable() = false
override fun isError() = getConstructor().getDeclarationDescriptor()?.let { d -> ErrorUtils.isError(d) } ?: false
@@ -124,7 +124,7 @@ public class CommonSupertypes {
if (type.isError()) {
return ErrorUtils.createErrorType("Supertype of error type " + type);
}
nullable |= type.isNullable();
nullable |= type.isMarkedNullable();
}
// Everything deleted => it's Nothing or Nothing?
@@ -220,7 +220,7 @@ public class CommonSupertypes {
boolean nullable = false;
for (JetType type : types) {
nullable |= type.isNullable();
nullable |= type.isMarkedNullable();
}
// TODO : attributes?
@@ -40,8 +40,8 @@ public abstract class DelegatingType implements JetType {
}
@Override
public boolean isNullable() {
return getDelegate().isNullable();
public boolean isMarkedNullable() {
return getDelegate().isMarkedNullable();
}
@NotNull
@@ -417,7 +417,7 @@ public class ErrorUtils {
}
@Override
public boolean isNullable() {
public boolean isMarkedNullable() {
return false;
}
@@ -36,7 +36,7 @@ public interface JetType extends Annotated {
@ReadOnly
List<TypeProjection> getArguments();
boolean isNullable();
boolean isMarkedNullable();
@NotNull
JetScope getMemberScope();
@@ -69,7 +69,7 @@ public final class JetTypeImpl extends AbstractJetType {
}
@Override
public boolean isNullable() {
public boolean isMarkedNullable() {
return nullable;
}
@@ -191,7 +191,7 @@ public class TypeSubstitutor {
}
else {
// this is a simple type T or T?: if it's T, we should just take replacement, if T? - we make replacement nullable
substitutedType = type.isNullable() ? TypeUtils.makeNullable(replacement.getType()) : replacement.getType();
substitutedType = type.isMarkedNullable() ? TypeUtils.makeNullable(replacement.getType()) : replacement.getType();
}
Variance resultingProjectionKind = combine(originalProjectionKind, replacement.getProjectionKind());
@@ -231,7 +231,7 @@ public class TypeSubstitutor {
};
JetType substitutedType = new JetTypeImpl(type.getAnnotations(), // Old annotations. This is questionable
type.getConstructor(), // The same constructor
type.isNullable(), // Same nullability
type.isMarkedNullable(), // Same nullability
substitutedArguments,
new SubstitutingScope(type.getMemberScope(), create(substitutionFilteringTypeParameters)));
return new TypeProjectionImpl(projectionKind, substitutedType);
@@ -64,7 +64,7 @@ public class TypeUtils {
}
@Override
public boolean isNullable() {
public boolean isMarkedNullable() {
throw new IllegalStateException(name);
}
@@ -136,7 +136,7 @@ public class TypeUtils {
}
// checking to preserve laziness
if (!(type instanceof LazyType) && type.isNullable() == nullable) {
if (!(type instanceof LazyType) && type.isMarkedNullable() == nullable) {
return type;
}
@@ -172,7 +172,7 @@ public class TypeUtils {
List<JetType> nullabilityStripped = new ArrayList<JetType>(types.size());
for (JetType type : types) {
nothingTypePresent |= KotlinBuiltIns.isNothingOrNullableNothing(type);
allNullable &= type.isNullable();
allNullable &= type.isMarkedNullable();
nullabilityStripped.add(makeNotNullable(type));
}
@@ -299,7 +299,7 @@ public class TypeUtils {
}
public static boolean canHaveSubtypes(JetTypeChecker typeChecker, JetType type) {
if (type.isNullable()) {
if (type.isMarkedNullable()) {
return true;
}
if (!type.getConstructor().isFinal()) {
@@ -401,7 +401,7 @@ public class TypeUtils {
@NotNull
public static List<JetType> getImmediateSupertypes(@NotNull JetType type) {
boolean isNullable = type.isNullable();
boolean isNullable = type.isMarkedNullable();
TypeSubstitutor substitutor = TypeSubstitutor.create(type);
Collection<JetType> originalSupertypes = type.getConstructor().getSupertypes();
List<JetType> result = new ArrayList<JetType>(originalSupertypes.size());
@@ -434,7 +434,7 @@ public class TypeUtils {
public static boolean hasNullableLowerBound(@NotNull TypeParameterDescriptor typeParameterDescriptor) {
for (JetType bound : typeParameterDescriptor.getLowerBounds()) {
if (bound.isNullable()) {
if (bound.isMarkedNullable()) {
return true;
}
}
@@ -446,7 +446,7 @@ public class TypeUtils {
* @return true if a value of this type can be null
*/
public static boolean isNullableType(@NotNull JetType type) {
if (type.isNullable()) {
if (type.isMarkedNullable()) {
return true;
}
if (TypesPackage.isFlexible(type) && isNullableType(TypesPackage.flexibility(type).getUpperBound())) {
@@ -465,7 +465,7 @@ public class TypeUtils {
}
for (JetType supertype : getImmediateSupertypes(type)) {
if (supertype.isNullable()) return true;
if (supertype.isMarkedNullable()) return true;
if (hasNullableSuperType(supertype)) return true;
}
@@ -775,7 +775,7 @@ public class TypeUtils {
}
@Override
public abstract boolean isNullable();
public abstract boolean isMarkedNullable();
@Override
@NotNull
@@ -802,7 +802,7 @@ public class TypeUtils {
}
@Override
public boolean isNullable() {
public boolean isMarkedNullable() {
return true;
}
}
@@ -814,7 +814,7 @@ public class TypeUtils {
}
@Override
public boolean isNullable() {
public boolean isMarkedNullable() {
return false;
}
}
@@ -79,11 +79,11 @@ public class TypeCheckingProcedure {
return heterogeneousEquivalence(type1, type2);
}
if (type1.isNullable() != type2.isNullable()) {
if (type1.isMarkedNullable() != type2.isMarkedNullable()) {
return false;
}
if (type1.isNullable()) {
if (type1.isMarkedNullable()) {
// Then type2 is nullable, too (see the previous condition
return constraints.assertEqualTypes(TypeUtils.makeNotNullable(type1), TypeUtils.makeNotNullable(type2), this);
}
@@ -189,7 +189,7 @@ public class TypeCheckingProcedure {
if (subtype.isError() || supertype.isError()) {
return true;
}
if (!supertype.isNullable() && subtype.isNullable()) {
if (!supertype.isMarkedNullable() && subtype.isMarkedNullable()) {
return false;
}
subtype = TypeUtils.makeNotNullable(subtype);
@@ -117,7 +117,7 @@ public trait Approximation : TypeCapability {
}
fun Approximation.Info.assertNotNull(): Boolean {
return from.upperIfFlexible().isNullable() && !TypeUtils.isNullableType(to)
return from.upperIfFlexible().isMarkedNullable() && !TypeUtils.isNullableType(to)
}
public fun JetType.getApproximationTo(
@@ -161,9 +161,9 @@ public open class DelegatingFlexibleType protected (
extraCapabilities)
}
override fun computeIsNullable() = delegateType.isNullable()
override fun computeIsNullable() = delegateType.isMarkedNullable()
override fun isNullable(): Boolean = getCapability(javaClass<NullAwareness>())!!.computeIsNullable()
override fun isMarkedNullable(): Boolean = getCapability(javaClass<NullAwareness>())!!.computeIsNullable()
override fun approximateToExpectedType(expectedType: JetType, dataFlowExtras: Approximation.DataFlowExtras): Approximation.Info? {
// val foo: Any? = foo() : Foo!
@@ -750,7 +750,7 @@ public class KotlinBuiltIns {
public static boolean isPrimitiveType(@NotNull JetType type) {
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
return !type.isNullable() && descriptor != null && FQ_NAMES.primitiveTypes.contains(DescriptorUtils.getFqName(descriptor));
return !type.isMarkedNullable() && descriptor != null && FQ_NAMES.primitiveTypes.contains(DescriptorUtils.getFqName(descriptor));
}
// Functions
@@ -853,7 +853,7 @@ public class KotlinBuiltIns {
}
private static boolean isNotNullConstructedFromGivenClass(@NotNull JetType type, @NotNull FqNameUnsafe fqName) {
return !type.isNullable() && isConstructedFromGivenClass(type, fqName);
return !type.isMarkedNullable() && isConstructedFromGivenClass(type, fqName);
}
public static boolean isSpecialClassWithNoSupertypes(@NotNull ClassDescriptor descriptor) {
@@ -867,12 +867,12 @@ public class KotlinBuiltIns {
public static boolean isNothing(@NotNull JetType type) {
return isNothingOrNullableNothing(type)
&& !type.isNullable();
&& !type.isMarkedNullable();
}
public static boolean isNullableNothing(@NotNull JetType type) {
return isNothingOrNullableNothing(type)
&& type.isNullable();
&& type.isMarkedNullable();
}
public static boolean isNothingOrNullableNothing(@NotNull JetType type) {
@@ -445,7 +445,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
sb.append(renderTypeName(type.getConstructor()));
}
sb.append(renderTypeArguments(type.getArguments()));
if (type.isNullable()) {
if (type.isMarkedNullable()) {
sb.append("?");
}
return sb.toString();
@@ -494,7 +494,7 @@ public class DescriptorRendererImpl implements DescriptorRenderer {
sb.append(") ").append(arrow()).append(" ");
sb.append(renderNormalizedType(KotlinBuiltIns.getReturnTypeFromFunctionType(type)));
if (type.isNullable()) {
if (type.isMarkedNullable()) {
return "(" + sb + ")?";
}
return sb.toString();