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
@@ -216,7 +216,7 @@ public abstract class AnnotationCodegen {
private static boolean isBareTypeParameterWithNullableUpperBound(@NotNull JetType type) {
ClassifierDescriptor classifier = type.getConstructor().getDeclarationDescriptor();
return !type.isNullable() && classifier instanceof TypeParameterDescriptor && TypeUtils.hasNullableSuperType(type);
return !type.isMarkedNullable() && classifier instanceof TypeParameterDescriptor && TypeUtils.hasNullableSuperType(type);
}
public void generateAnnotationDefaultValue(@NotNull CompileTimeConstant value, @NotNull JetType expectedType) {
@@ -3863,7 +3863,7 @@ The "returned" value of try expression with no finally is either the last expres
if (leaveExpressionOnStack) {
v.dup();
}
if (jetType.isNullable()) {
if (jetType.isMarkedNullable()) {
Label nope = new Label();
Label end = new Label();
@@ -25,7 +25,6 @@ import com.intellij.util.containers.ContainerUtil;
import kotlin.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.backend.common.CodegenUtil;
import org.jetbrains.jet.codegen.binding.CodegenBinding;
import org.jetbrains.jet.codegen.bridges.Bridge;
import org.jetbrains.jet.codegen.bridges.BridgesPackage;
@@ -71,7 +70,6 @@ import static org.jetbrains.jet.codegen.JvmSerializationBindings.*;
import static org.jetbrains.jet.codegen.binding.CodegenBinding.isLocalNamedFun;
import static org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor.Kind.DECLARATION;
import static org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils.callableDescriptorToDeclaration;
import static org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils.classDescriptorToDeclaration;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isFunctionLiteral;
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isTrait;
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
@@ -228,7 +226,7 @@ public class FunctionCodegen extends ParentCodegenAware {
if (kind == JvmMethodParameterKind.VALUE) {
ValueParameterDescriptor descriptor = descriptors.next();
name = descriptor.getName().asString();
nullableType = descriptor.getType().isNullable();
nullableType = descriptor.getType().isMarkedNullable();
}
else {
String lowercaseKind = kind.name().toLowerCase();
@@ -241,7 +239,7 @@ public class FunctionCodegen extends ParentCodegenAware {
if (kind == JvmMethodParameterKind.RECEIVER) {
ReceiverParameterDescriptor receiver = functionDescriptor.getExtensionReceiverParameter();
nullableType = receiver == null || receiver.getType().isNullable();
nullableType = receiver == null || receiver.getType().isMarkedNullable();
}
else {
nullableType = true;
@@ -285,7 +285,7 @@ public abstract class MemberCodegen<T extends JetElement/* TODO: & JetDeclaratio
private static boolean skipDefaultValue(@NotNull PropertyDescriptor propertyDescriptor, Object value, @NotNull Type type) {
if (isPrimitive(type)) {
if (!propertyDescriptor.getType().isNullable() && value instanceof Number) {
if (!propertyDescriptor.getType().isMarkedNullable() && value instanceof Number) {
if (type == Type.INT_TYPE && ((Number) value).intValue() == 0) {
return true;
}
@@ -54,11 +54,11 @@ public class RangeCodegenUtil {
private RangeCodegenUtil() {}
public static boolean isRange(JetType rangeType) {
return !rangeType.isNullable() && getPrimitiveRangeElementType(rangeType) != null;
return !rangeType.isMarkedNullable() && getPrimitiveRangeElementType(rangeType) != null;
}
public static boolean isProgression(JetType rangeType) {
return !rangeType.isNullable() && getPrimitiveProgressionElementType(rangeType) != null;
return !rangeType.isMarkedNullable() && getPrimitiveProgressionElementType(rangeType) != null;
}
@Nullable
@@ -64,7 +64,7 @@ class PropagationHeuristics {
JetTypeImpl betterTypeInSuper = new JetTypeImpl(
arrayTypeFromSuper.getAnnotations(),
arrayTypeFromSuper.getConstructor(),
arrayTypeFromSuper.isNullable(),
arrayTypeFromSuper.isMarkedNullable(),
Arrays.asList(new TypeProjectionImpl(Variance.OUT_VARIANCE, elementTypeInSuper)),
JetScope.Empty.INSTANCE$);
@@ -78,7 +78,7 @@ public class SingleAbstractMethodUtils {
return new JetTypeImpl(
functionType.getAnnotations(),
functionType.getConstructor(),
functionType.isNullable(),
functionType.isMarkedNullable(),
arguments,
((ClassDescriptor) classifier).getMemberScope(arguments)
);
@@ -106,7 +106,7 @@ public class SingleAbstractMethodUtils {
return LazyJavaTypeResolver.FlexibleJavaClassifierTypeCapabilities.create(fixedProjections, TypeUtils.makeNullable(fixedProjections));
}
return TypeUtils.makeNullableAsSpecified(fixedProjections, !isSamConstructor && samType.isNullable());
return TypeUtils.makeNullableAsSpecified(fixedProjections, !isSamConstructor && samType.isMarkedNullable());
}
}
return null;
@@ -74,7 +74,7 @@ public fun or(predicates: Collection<TypePredicate>): TypePredicate? =
fun JetType.getSubtypesPredicate(): TypePredicate {
return when {
KotlinBuiltIns.isAnyOrNullableAny(this) && isNullable() -> AllTypes
KotlinBuiltIns.isAnyOrNullableAny(this) && isMarkedNullable() -> AllTypes
TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, this) -> AllSubtypes(this)
else -> SingleType(this)
}
@@ -52,7 +52,7 @@ public class CompileTimeConstantUtils {
JetType parameterType = parameterDescriptor.getType();
JetTypeReference typeReference = parameter.getTypeReference();
if (typeReference != null) {
if (parameterType.isNullable()) {
if (parameterType.isMarkedNullable()) {
trace.report(NULLABLE_TYPE_OF_ANNOTATION_MEMBER.on(typeReference));
}
else if (!isAcceptableTypeForAnnotationParameter(parameterType)) {
@@ -82,7 +82,7 @@ public class CompileTimeConstantUtils {
List<TypeProjection> arguments = parameterType.getArguments();
if (arguments.size() == 1) {
JetType arrayType = arguments.get(0).getType();
if (arrayType.isNullable()) {
if (arrayType.isMarkedNullable()) {
return false;
}
ClassDescriptor arrayTypeDescriptor = TypeUtils.getClassDescriptor(arrayType);
@@ -84,7 +84,7 @@ public class PossiblyBareType {
public boolean isNullable() {
if (isBare()) return isBareTypeNullable();
return getActualType().isNullable();
return getActualType().isMarkedNullable();
}
public PossiblyBareType makeNullable() {
@@ -67,7 +67,7 @@ public class CallResolverUtil {
List<TypeProjection> newArguments = Lists.newArrayList();
newArguments.addAll(arguments.subList(0, arguments.size() - 1));
newArguments.add(new TypeProjectionImpl(Variance.INVARIANT, DONT_CARE));
return new JetTypeImpl(type.getAnnotations(), type.getConstructor(), type.isNullable(), newArguments, type.getMemberScope());
return new JetTypeImpl(type.getAnnotations(), type.getConstructor(), type.isMarkedNullable(), newArguments, type.getMemberScope());
}
private static boolean hasReturnTypeDependentOnUninferredParams(
@@ -115,7 +115,7 @@ public class CallResolverUtil {
fakeTypeArguments.add(new TypeProjectionImpl(typeProjection.getProjectionKind(), DONT_CARE));
}
return new JetTypeImpl(
receiverType.getAnnotations(), receiverType.getConstructor(), receiverType.isNullable(),
receiverType.getAnnotations(), receiverType.getConstructor(), receiverType.isMarkedNullable(),
fakeTypeArguments, ErrorUtils.createErrorScope("Error scope for erased receiver type", /*throwExceptions=*/true));
}
@@ -596,7 +596,7 @@ public class CandidateResolver {
JetType receiverArgumentType = receiverArgument.getType();
BindingContext bindingContext = trace.getBindingContext();
if (!safeAccess && !receiverParameter.getType().isNullable() && receiverArgumentType.isNullable()) {
if (!safeAccess && !receiverParameter.getType().isMarkedNullable() && receiverArgumentType.isMarkedNullable()) {
if (!SmartCastUtils.canBeSmartCast(receiverParameter, receiverArgument, bindingContext, context.dataFlowInfo)) {
context.tracing.unsafeCall(trace, receiverArgumentType, implicitInvokeCheck);
return UNSAFE_CALL_ERROR;
@@ -222,7 +222,7 @@ public class InlineCallResolverExtension implements CallResolverExtension {
JetType type = descriptor.getReturnType();
return type != null &&
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type) &&
!type.isNullable() &&
!type.isMarkedNullable() &&
!InlineUtil.hasNoinlineAnnotation(descriptor);
}
@@ -28,7 +28,6 @@ import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.scopes.receivers.*;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.lang.types.TypesPackage;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
@@ -62,7 +61,7 @@ public class DataFlowValueFactory {
if (receiverValue instanceof TransientReceiver || receiverValue instanceof ScriptReceiver) {
// SCRIPT: smartcasts data flow
JetType type = receiverValue.getType();
boolean nullable = type.isNullable() || TypeUtils.hasNullableSuperType(type);
boolean nullable = type.isMarkedNullable() || TypeUtils.hasNullableSuperType(type);
return new DataFlowValue(receiverValue, type, nullable, Nullability.NOT_NULL);
}
else if (receiverValue instanceof ClassReceiver || receiverValue instanceof ExtensionReceiver) {
@@ -110,7 +110,7 @@ import static org.jetbrains.jet.lang.resolve.calls.smartcasts.Nullability.NOT_NU
Set<JetType> enrichedTypes = Sets.newHashSetWithExpectedSize(types.size() + 1);
JetType originalType = key.getType();
if (originalType.isNullable()) {
if (originalType.isMarkedNullable()) {
enrichedTypes.add(TypeUtils.makeNotNullable(originalType));
}
for (JetType type : types) {
@@ -152,7 +152,7 @@ import static org.jetbrains.jet.lang.resolve.calls.smartcasts.Nullability.NOT_NU
if (value.getType().equals(type)) return this;
if (getPossibleTypes(value).contains(type)) return this;
ImmutableMap<DataFlowValue, Nullability> newNullabilityInfo =
type.isNullable() ? EMPTY_NULLABILITY_INFO : ImmutableMap.of(value, NOT_NULL);
type.isMarkedNullable() ? EMPTY_NULLABILITY_INFO : ImmutableMap.of(value, NOT_NULL);
SetMultimap<DataFlowValue, JetType> newTypeInfo = ImmutableSetMultimap.of(value, type);
return new DelegatingDataFlowInfo(this, newNullabilityInfo, newTypeInfo);
}
@@ -190,7 +190,7 @@ public class SmartCastUtils {
@NotNull BindingContext bindingContext,
@NotNull DataFlowInfo dataFlowInfo
) {
if (!receiver.getType().isNullable()) return true;
if (!receiver.getType().isMarkedNullable()) return true;
List<JetType> smartCastVariants = getSmartCastVariants(receiver, bindingContext, dataFlowInfo);
for (JetType smartCastVariant : smartCastVariants) {
@@ -152,7 +152,7 @@ public class InlineAnalyzerExtension implements FunctionAnalyzerExtension.Analyz
JetType type = parameter.getReturnType();
if (type != null && KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(type)) {
if (!InlineUtil.hasNoinlineAnnotation(parameter)) {
if (type.isNullable()) {
if (type.isMarkedNullable()) {
if (trace != null) {
trace.report(Errors.NULLABLE_INLINE_PARAMETER.on(expression, expression, functionDescriptor));
}
@@ -112,7 +112,7 @@ public class CastDiagnosticsUtil {
*/
public static boolean isCastErased(@NotNull JetType supertype, @NotNull JetType subtype, @NotNull JetTypeChecker typeChecker) {
// cast between T and T? is always OK
if (supertype.isNullable() || subtype.isNullable()) {
if (supertype.isMarkedNullable() || subtype.isMarkedNullable()) {
return isCastErased(TypeUtils.makeNotNullable(supertype), TypeUtils.makeNotNullable(subtype), typeChecker);
}
@@ -154,7 +154,7 @@ public class CastDiagnosticsUtil {
* result = List<*>, some arguments were not inferred, replaced with '*'
*/
public static TypeReconstructionResult findStaticallyKnownSubtype(@NotNull JetType supertype, @NotNull TypeConstructor subtypeConstructor) {
assert !supertype.isNullable() : "This method only makes sense for non-nullable types";
assert !supertype.isMarkedNullable() : "This method only makes sense for non-nullable types";
// Assume we are casting an expression of type Collection<Foo> to List<Bar>
// First, let's make List<T>, where T is a type variable
@@ -75,7 +75,7 @@ public class TypeUnifier {
}
// Foo? ~ X? => Foo ~ X
if (known.isNullable() && withVariables.isNullable()) {
if (known.isMarkedNullable() && withVariables.isMarkedNullable()) {
doUnify(
new TypeProjectionImpl(knownProjectionKind, TypeUtils.makeNotNullable(known)),
new TypeProjectionImpl(withVariablesProjectionKind, TypeUtils.makeNotNullable(withVariables)),
@@ -93,7 +93,7 @@ public class TypeUnifier {
}
// Foo ~ X? => fail
if (!known.isNullable() && withVariables.isNullable()) {
if (!known.isMarkedNullable() && withVariables.isMarkedNullable()) {
result.fail();
return;
}
@@ -106,7 +106,7 @@ public class TypeUnifier {
}
// Foo? ~ Foo || in Foo ~ Foo || Foo ~ Bar
boolean structuralMismatch = known.isNullable() != withVariables.isNullable()
boolean structuralMismatch = known.isMarkedNullable() != withVariables.isMarkedNullable()
|| knownProjectionKind != withVariablesProjectionKind
|| !known.getConstructor().equals(withVariables.getConstructor());
if (structuralMismatch) {
@@ -1079,7 +1079,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetType rightType = rightTypeInfo.getType();
DataFlowInfo dataFlowInfo = resolvedCall.getDataFlowInfoForArguments().getResultInfo();
if (leftType != null && rightType != null && KotlinBuiltIns.isNothingOrNullableNothing(rightType) && !rightType.isNullable()) {
if (leftType != null && rightType != null && KotlinBuiltIns.isNothingOrNullableNothing(rightType) && !rightType.isMarkedNullable()) {
DataFlowValue value = createDataFlowValue(left, leftType, context.trace.getBindingContext());
dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL);
}
@@ -289,7 +289,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
context.trace.report(DYNAMIC_NOT_ALLOWED.on(typeReferenceAfterIs));
}
if (!subjectType.isNullable() && targetType.isNullable()) {
if (!subjectType.isMarkedNullable() && targetType.isMarkedNullable()) {
JetTypeElement element = typeReferenceAfterIs.getTypeElement();
assert element instanceof JetNullableType : "element must be instance of " + JetNullableType.class.getName();
JetNullableType nullableType = (JetNullableType) element;
@@ -175,7 +175,7 @@ public abstract class LazyJavaMemberScope(
}
else {
val jetType = c.typeResolver.transformJavaType(javaParameter.getType(), typeUsage)
if (!PLATFORM_TYPES && jetType.isNullable() && c.hasNotNullAnnotation(javaParameter))
if (!PLATFORM_TYPES && jetType.isMarkedNullable() && c.hasNotNullAnnotation(javaParameter))
TypeUtils.makeNotNullable(jetType) to null
else
jetType to null
@@ -259,7 +259,7 @@ class LazyJavaTypeResolver(
when (classifier()) {
is JavaTypeParameter -> {
if (isConstructorTypeParameter())
getConstructorTypeParameterSubstitute().isNullable()
getConstructorTypeParameterSubstitute().isMarkedNullable()
else
attr.howThisTypeIsUsed !in setOf(TYPE_ARGUMENT, UPPER_BOUND, SUPERTYPE_ARGUMENT, SUPERTYPE)
}
@@ -269,7 +269,7 @@ class LazyJavaTypeResolver(
}
}
override fun isNullable(): Boolean = nullable()
override fun isMarkedNullable(): Boolean = nullable()
override fun getAnnotations() = attr.annotations
}
@@ -314,7 +314,7 @@ class LazyJavaTypeResolver(
// Int! >< Int?
if (otherType.isFlexible()) return Specificity.Relation.DONT_KNOW
// Int? >< Int!
if (otherType.isNullable()) return Specificity.Relation.DONT_KNOW
if (otherType.isMarkedNullable()) return Specificity.Relation.DONT_KNOW
// Int! lessSpecific Int
return Specificity.Relation.LESS_SPECIFIC
}
@@ -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();
@@ -351,7 +351,7 @@ public class DescriptorSerializer {
}
// to avoid storing a default
if (type.isNullable()) {
if (type.isMarkedNullable()) {
builder.setNullable(true);
}
@@ -43,7 +43,7 @@ class DeserializedType(
override fun getArguments(): List<TypeProjection> = arguments
override fun isNullable(): Boolean = typeProto.getNullable()
override fun isMarkedNullable(): Boolean = typeProto.getNullable()
private fun computeMemberScope(): JetScope =
if (isError()) {
@@ -41,7 +41,7 @@ fun CallableDescriptor.fuzzyExtensionReceiverType(): FuzzyType? {
fun FuzzyType.makeNotNullable() = FuzzyType(type.makeNotNullable(), freeParameters)
fun FuzzyType.makeNullable() = FuzzyType(type.makeNullable(), freeParameters)
fun FuzzyType.isNullable() = type.isNullable()
fun FuzzyType.isNullable() = type.isMarkedNullable()
class FuzzyType(
val type: JetType,
@@ -59,7 +59,7 @@ public fun approximateFlexibleTypes(jetType: JetType, outermost: Boolean = true)
return JetTypeImpl(
jetType.getAnnotations(),
jetType.getConstructor(),
jetType.isNullable(),
jetType.isMarkedNullable(),
jetType.getArguments().map { TypeProjectionImpl(it.getProjectionKind(), approximateFlexibleTypes(it.getType(), false)) },
ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true)
)
@@ -134,8 +134,8 @@ public class OperatorToFunctionIntention : JetSelfTargetingIntention<JetExpressi
JetTokens.MULTEQ -> if (functionName == "multAssign") "$leftText.multAssign($rightText)" else "$leftText = $leftText.mult($rightText)"
JetTokens.DIVEQ -> if (functionName == "divAssign") "$leftText.divAssign($rightText)" else "$leftText = $leftText.div($rightText)"
JetTokens.PERCEQ -> if (functionName == "modAssign") "$leftText.modAssign($rightText)" else "$leftText = $leftText.mod($rightText)"
JetTokens.EQEQ -> if (elemType?.isNullable() ?: true) "$leftText?.equals($rightText) ?: $rightText.identityEquals(null)" else "$leftText.equals($rightText)"
JetTokens.EXCLEQ -> if (elemType?.isNullable() ?: true) "!($leftText?.equals($rightText) ?: $rightText.identityEquals(null))" else "!$leftText.equals($rightText)"
JetTokens.EQEQ -> if (elemType?.isMarkedNullable() ?: true) "$leftText?.equals($rightText) ?: $rightText.identityEquals(null)" else "$leftText.equals($rightText)"
JetTokens.EXCLEQ -> if (elemType?.isMarkedNullable() ?: true) "!($leftText?.equals($rightText) ?: $rightText.identityEquals(null))" else "!$leftText.equals($rightText)"
JetTokens.GT -> "$leftText.compareTo($rightText) > 0"
JetTokens.LT -> "$leftText.compareTo($rightText) < 0"
JetTokens.GTEQ -> "$leftText.compareTo($rightText) >= 0"
@@ -30,8 +30,6 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import java.util.ArrayList;
import java.util.List;
@@ -186,7 +184,7 @@ public class CodeInsightUtils {
public static String defaultInitializer(JetType type) {
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
if (type.isNullable()) {
if (type.isMarkedNullable()) {
return "null";
}
else if (type.equals(builtIns.getIntType()) || type.equals(builtIns.getLongType()) ||
@@ -207,12 +207,12 @@ public class LookupElementFactory(
private fun callableWeight(descriptor: DeclarationDescriptor): CallableWeight? {
if (descriptor !is CallableDescriptor) return null
val isReceiverNullable = receiverTypes.isNotEmpty() && receiverTypes.all { it.isNullable() }
val isReceiverNullable = receiverTypes.isNotEmpty() && receiverTypes.all { it.isMarkedNullable() }
val receiverParameter = descriptor.getExtensionReceiverParameter()
if (receiverParameter != null) {
val receiverParamType = receiverParameter.getType()
return if (isReceiverNullable && !receiverParamType.isNullable())
return if (isReceiverNullable && !receiverParamType.isMarkedNullable())
CallableWeight.notApplicableReceiverNullable
else if (receiverTypes.any { TypeUtils.equalTypes(it, receiverParamType) })
CallableWeight.thisTypeExtension
@@ -57,7 +57,7 @@ object KeywordValues {
collection.addLookupElements(null,
expectedInfos,
{ info -> if (info.type.isNullable()) ExpectedInfoClassification.matches(TypeSubstitutor.EMPTY) else ExpectedInfoClassification.notMatches },
{ info -> if (info.type.isMarkedNullable()) ExpectedInfoClassification.matches(TypeSubstitutor.EMPTY) else ExpectedInfoClassification.notMatches },
{ LookupElementBuilder.create("null").bold().assignSmartCompletionPriority(SmartCompletionItemPriority.NULL) })
}
}
@@ -41,6 +41,6 @@ public class JetSuggestVariableNameMacro extends BaseJetVariableMacro {
@NotNull Project project,
@NotNull ExpressionTypingComponents components
) {
return variableDescriptor.getType().isNullable();
return variableDescriptor.getType().isMarkedNullable();
}
}
@@ -54,7 +54,7 @@ private fun JetType.render(typeParameterNameMap: Map<TypeParameterDescriptor, St
val arguments = getArguments().map { it.getType().render(typeParameterNameMap, fq) }
val typeString = getConstructor().getDeclarationDescriptor()!!.render(typeParameterNameMap, fq)
val typeArgumentString = if (arguments.notEmpty) arguments.joinToString(", ", "<", ">") else ""
val nullifier = if (isNullable()) "?" else ""
val nullifier = if (isMarkedNullable()) "?" else ""
return "$typeString$typeArgumentString$nullifier"
}
@@ -203,7 +203,7 @@ private fun JetNamedDeclaration.guessType(context: BindingContext): Array<JetTyp
private class JetTypeSubstitution(public val forType: JetType, public val byType: JetType)
private fun JetType.substitute(substitution: JetTypeSubstitution, variance: Variance): JetType {
val nullable = isNullable()
val nullable = isMarkedNullable()
val currentType = makeNotNullable()
if (when (variance) {
@@ -218,7 +218,7 @@ private fun JetType.substitute(substitution: JetTypeSubstitution, variance: Vari
val (projection, typeParameter) = pair
TypeProjectionImpl(Variance.INVARIANT, projection.getType().substitute(substitution, typeParameter.getVariance()))
}
return JetTypeImpl(getAnnotations(), getConstructor(), isNullable(), newArguments, getMemberScope())
return JetTypeImpl(getAnnotations(), getConstructor(), isMarkedNullable(), newArguments, getMemberScope())
}
}
@@ -30,7 +30,7 @@ object CreateIteratorFunctionActionFactory : JetSingleIntentionActionFactory() {
val returnJetTypeParameterType = TypeProjectionImpl(returnJetTypeParameterTypes[0])
val returnJetTypeArguments = Collections.singletonList(returnJetTypeParameterType)
val newReturnJetType = JetTypeImpl(returnJetType.getAnnotations(), returnJetType.getConstructor(), returnJetType.isNullable(), returnJetTypeArguments, returnJetType.getMemberScope())
val newReturnJetType = JetTypeImpl(returnJetType.getAnnotations(), returnJetType.getConstructor(), returnJetType.isMarkedNullable(), returnJetTypeArguments, returnJetType.getMemberScope())
val returnType = TypeInfo(newReturnJetType, Variance.OUT_VARIANCE)
return CreateCallableFromUsageFix(forExpr, FunctionInfo("iterator", iterableType, returnType))
}
@@ -339,7 +339,7 @@ public class JetPsiUnifier(
if (type1 != null && type2 != null) {
if (TypeUtils.equalTypes(type1, type2)) return MATCHED
if (type1.isNullable() != type2.isNullable()) return UNMATCHED
if (type1.isMarkedNullable() != type2.isMarkedNullable()) return UNMATCHED
if (!matchDescriptors(
type1.getConstructor().getDeclarationDescriptor(),
type2.getConstructor().getDeclarationDescriptor())) return UNMATCHED
@@ -117,7 +117,7 @@ public final class PatternTranslator extends AbstractTranslator {
}
private boolean isNullable(JetTypeReference typeReference) {
return getTypeByReference(bindingContext(), typeReference).isNullable();
return getTypeByReference(bindingContext(), typeReference).isMarkedNullable();
}
@NotNull
@@ -90,7 +90,7 @@ public final class StringTemplateTranslator extends AbstractTranslator {
}
JetType type = context().bindingContext().get(BindingContext.EXPRESSION_TYPE, entryExpression);
if (type == null || type.isNullable()) {
if (type == null || type.isMarkedNullable()) {
append(TopLevelFIF.TO_STRING.apply((JsExpression) null, Collections.singletonList(translatedExpression), context()));
}
else if (mustCallToString(type)) {
@@ -57,7 +57,7 @@ public final class UnaryOperationTranslator {
JetExpression baseExpression = getBaseExpression(expression);
JetType type = BindingContextUtils.getNotNull(context.bindingContext(), BindingContext.EXPRESSION_TYPE, baseExpression);
JsExpression translatedExpression = translateAsExpression(baseExpression, context);
return type.isNullable() ? sure(translatedExpression, context) : translatedExpression;
return type.isMarkedNullable() ? sure(translatedExpression, context) : translatedExpression;
}
if (operationToken == JetTokens.MINUS) {