isNothing() made static
This commit is contained in:
@@ -198,7 +198,7 @@ public class JetControlFlowProcessor {
|
||||
}
|
||||
|
||||
JetType type = trace.getBindingContext().get(BindingContext.EXPRESSION_TYPE, expression);
|
||||
if (type != null && KotlinBuiltIns.getInstance().isNothing(type)) {
|
||||
if (type != null && KotlinBuiltIns.isNothing(type)) {
|
||||
builder.jumpToError(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public final class WhenChecker {
|
||||
JetType type = trace.getBindingContext().get(
|
||||
EXPRESSION_TYPE, ((JetWhenConditionWithExpression) condition).getExpression()
|
||||
);
|
||||
if (type != null && KotlinBuiltIns.getInstance().isNothingOrNullableNothing(type)) {
|
||||
if (type != null && KotlinBuiltIns.isNothingOrNullableNothing(type)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -486,7 +486,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
||||
resolvedCall,
|
||||
receiverValues,
|
||||
arguments,
|
||||
returnType != null && KotlinBuiltIns.getInstance().isNothing(returnType) ? null : valueFactory
|
||||
returnType != null && KotlinBuiltIns.isNothing(returnType) ? null : valueFactory
|
||||
);
|
||||
add(instruction);
|
||||
return instruction;
|
||||
|
||||
@@ -736,12 +736,12 @@ public class DescriptorResolver {
|
||||
@NotNull TypeParameterDescriptor parameter,
|
||||
@NotNull JetTypeParameter typeParameter
|
||||
) {
|
||||
if (KotlinBuiltIns.getInstance().isNothing(parameter.getUpperBoundsAsType())) {
|
||||
if (KotlinBuiltIns.isNothing(parameter.getUpperBoundsAsType())) {
|
||||
trace.report(CONFLICTING_UPPER_BOUNDS.on(typeParameter, parameter));
|
||||
}
|
||||
|
||||
JetType classObjectType = parameter.getClassObjectType();
|
||||
if (classObjectType != null && KotlinBuiltIns.getInstance().isNothing(classObjectType)) {
|
||||
if (classObjectType != null && KotlinBuiltIns.isNothing(classObjectType)) {
|
||||
trace.report(CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS.on(typeParameter, parameter));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class ReifiedTypeParameterSubstitutionCheck implements CallResolverExtens
|
||||
Errors.TYPE_PARAMETER_AS_REIFIED.on(getCallElement(context), parameter)
|
||||
);
|
||||
}
|
||||
else if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(argument) || TypesPackage.isDynamic(argument)) {
|
||||
else if (KotlinBuiltIns.isNothingOrNullableNothing(argument) || TypesPackage.isDynamic(argument)) {
|
||||
context.trace.report(Errors.REIFIED_TYPE_FORBIDDEN_SUBSTITUTION.on(getCallElement(context), argument));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class CastDiagnosticsUtil {
|
||||
@NotNull JetType rhsType,
|
||||
@NotNull PlatformToKotlinClassMap platformToKotlinClassMap
|
||||
) {
|
||||
if (KotlinBuiltIns.getInstance().isNullableNothing(lhsType) && !TypeUtils.isNullableType(rhsType)) return false;
|
||||
if (KotlinBuiltIns.isNullableNothing(lhsType) && !TypeUtils.isNullableType(rhsType)) return false;
|
||||
if (isRelated(lhsType, rhsType, platformToKotlinClassMap)) return true;
|
||||
// This is an oversimplification (which does not render the method incomplete):
|
||||
// we consider any type parameter capable of taking any value, which may be made more precise if we considered bounds
|
||||
|
||||
@@ -91,7 +91,7 @@ public class SubstitutionUtils {
|
||||
fullSubstitution.put(parameter.getTypeConstructor(), substitute);
|
||||
}
|
||||
}
|
||||
if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(context)) return;
|
||||
if (KotlinBuiltIns.isNothingOrNullableNothing(context)) return;
|
||||
for (JetType supertype : context.getConstructor().getSupertypes()) {
|
||||
fillInDeepSubstitutor(supertype, substitutor, substitution, fullSubstitution);
|
||||
}
|
||||
|
||||
+1
-1
@@ -1079,7 +1079,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetType rightType = rightTypeInfo.getType();
|
||||
|
||||
DataFlowInfo dataFlowInfo = resolvedCall.getDataFlowInfoForArguments().getResultInfo();
|
||||
if (leftType != null && rightType != null && KotlinBuiltIns.getInstance().isNothingOrNullableNothing(rightType) && !rightType.isNullable()) {
|
||||
if (leftType != null && rightType != null && KotlinBuiltIns.isNothingOrNullableNothing(rightType) && !rightType.isNullable()) {
|
||||
DataFlowValue value = createDataFlowValue(left, leftType, context.trace.getBindingContext());
|
||||
dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL);
|
||||
}
|
||||
|
||||
+3
-3
@@ -130,8 +130,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
DataFlowInfo thenDataFlowInfo = thenTypeInfo.getDataFlowInfo();
|
||||
DataFlowInfo elseDataFlowInfo = elseTypeInfo.getDataFlowInfo();
|
||||
|
||||
boolean jumpInThen = thenType != null && KotlinBuiltIns.getInstance().isNothing(thenType);
|
||||
boolean jumpInElse = elseType != null && KotlinBuiltIns.getInstance().isNothing(elseType);
|
||||
boolean jumpInThen = thenType != null && KotlinBuiltIns.isNothing(thenType);
|
||||
boolean jumpInElse = elseType != null && KotlinBuiltIns.isNothing(elseType);
|
||||
|
||||
DataFlowInfo resultDataFlowInfo;
|
||||
if (thenType == null && elseType == null) {
|
||||
@@ -167,7 +167,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
presentScope, Collections.singletonList(presentBranch), CoercionStrategy.NO_COERCION, newContext, context.trace);
|
||||
JetType type = typeInfo.getType();
|
||||
DataFlowInfo dataFlowInfo;
|
||||
if (type != null && KotlinBuiltIns.getInstance().isNothing(type)) {
|
||||
if (type != null && KotlinBuiltIns.isNothing(type)) {
|
||||
dataFlowInfo = otherInfo;
|
||||
} else {
|
||||
dataFlowInfo = typeInfo.getDataFlowInfo().or(otherInfo);
|
||||
|
||||
+1
-1
@@ -325,7 +325,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
|
||||
// check if the pattern is essentially a 'null' expression
|
||||
if (KotlinBuiltIns.getInstance().isNullableNothing(type) && !TypeUtils.isNullableType(subjectType)) {
|
||||
if (KotlinBuiltIns.isNullableNothing(type) && !TypeUtils.isNullableType(subjectType)) {
|
||||
context.trace.report(SENSELESS_NULL_IN_WHEN.on(reportErrorOn));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class CommonSupertypes {
|
||||
JetType type = iterator.next();
|
||||
assert type != null;
|
||||
assert !TypesPackage.isFlexible(type) : "Flexible type " + type + " passed to commonSuperTypeForInflexible";
|
||||
if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(type)) {
|
||||
if (KotlinBuiltIns.isNothingOrNullableNothing(type)) {
|
||||
iterator.remove();
|
||||
}
|
||||
if (type.isError()) {
|
||||
|
||||
@@ -169,7 +169,7 @@ public class TypeSubstitutor {
|
||||
);
|
||||
}
|
||||
|
||||
if (KotlinBuiltIns.getInstance().isNothing(type) || type.isError()) return originalProjection;
|
||||
if (KotlinBuiltIns.isNothing(type) || type.isError()) return originalProjection;
|
||||
|
||||
TypeProjection replacement = substitution.get(type.getConstructor());
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ public class TypeUtils {
|
||||
boolean nothingTypePresent = false;
|
||||
List<JetType> nullabilityStripped = new ArrayList<JetType>(types.size());
|
||||
for (JetType type : types) {
|
||||
nothingTypePresent |= KotlinBuiltIns.getInstance().isNothingOrNullableNothing(type);
|
||||
nothingTypePresent |= KotlinBuiltIns.isNothingOrNullableNothing(type);
|
||||
allNullable &= type.isNullable();
|
||||
nullabilityStripped.add(makeNotNullable(type));
|
||||
}
|
||||
|
||||
+1
-1
@@ -194,7 +194,7 @@ public class TypeCheckingProcedure {
|
||||
}
|
||||
subtype = TypeUtils.makeNotNullable(subtype);
|
||||
supertype = TypeUtils.makeNotNullable(supertype);
|
||||
if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(subtype)) {
|
||||
if (KotlinBuiltIns.isNothingOrNullableNothing(subtype)) {
|
||||
return true;
|
||||
}
|
||||
@Nullable JetType closestSupertype = findCorrespondingSupertype(subtype, supertype, constraints);
|
||||
|
||||
@@ -835,18 +835,19 @@ public class KotlinBuiltIns {
|
||||
return FQ_NAMES.any.equals(DescriptorUtils.getFqName(descriptor));
|
||||
}
|
||||
|
||||
public boolean isNothing(@NotNull JetType type) {
|
||||
public static boolean isNothing(@NotNull JetType type) {
|
||||
return isNothingOrNullableNothing(type)
|
||||
&& !type.isNullable();
|
||||
}
|
||||
|
||||
public boolean isNullableNothing(@NotNull JetType type) {
|
||||
public static boolean isNullableNothing(@NotNull JetType type) {
|
||||
return isNothingOrNullableNothing(type)
|
||||
&& type.isNullable();
|
||||
}
|
||||
|
||||
public boolean isNothingOrNullableNothing(@NotNull JetType type) {
|
||||
return type.getConstructor() == getNothing().getTypeConstructor();
|
||||
public static boolean isNothingOrNullableNothing(@NotNull JetType type) {
|
||||
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
return descriptor != null && FQ_NAMES.nothing.equals(DescriptorUtils.getFqName(descriptor));
|
||||
}
|
||||
|
||||
public boolean isAnyOrNullableAny(@NotNull JetType type) {
|
||||
|
||||
@@ -78,7 +78,7 @@ public class FindImplicitNothingAction : AnAction() {
|
||||
try {
|
||||
val bindingContext = resolutionFacade.analyze(expression)
|
||||
val type = bindingContext[BindingContext.EXPRESSION_TYPE, expression] ?: return
|
||||
if (KotlinBuiltIns.getInstance().isNothing(type) && !expression.hasExplicitNothing(bindingContext)) { //TODO: what about nullable Nothing?
|
||||
if (KotlinBuiltIns.isNothing(type) && !expression.hasExplicitNothing(bindingContext)) { //TODO: what about nullable Nothing?
|
||||
found.add(expression)
|
||||
}
|
||||
}
|
||||
@@ -126,9 +126,8 @@ public class FindImplicitNothingAction : AnAction() {
|
||||
}
|
||||
|
||||
private fun JetType.isNothingOrNothingFunctionType(): Boolean {
|
||||
val builtIns = KotlinBuiltIns.getInstance()
|
||||
return when {
|
||||
builtIns.isNothing(this) -> true
|
||||
KotlinBuiltIns.isNothing(this) -> true
|
||||
|
||||
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(this) -> KotlinBuiltIns.getReturnTypeFromFunctionType(this).isNothingOrNothingFunctionType()
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class TypesWithSmartCasts(val bindingContext: BindingContext) {
|
||||
fun typesOf(descriptor: DeclarationDescriptor): Iterable<JetType> {
|
||||
if (descriptor is CallableDescriptor) {
|
||||
var returnType = descriptor.getReturnType()
|
||||
if (returnType != null && KotlinBuiltIns.getInstance().isNothing(returnType!!)) {
|
||||
if (returnType != null && KotlinBuiltIns.isNothing(returnType!!)) {
|
||||
//TODO: maybe we should include them on the second press?
|
||||
return listOf()
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ConvertToBlockBodyAction : PsiElementBaseIntentionAction() {
|
||||
fun generateBody(returnsValue: Boolean): JetExpression {
|
||||
val bodyType = expressionType(body)
|
||||
val needReturn = returnsValue &&
|
||||
(bodyType == null || (!KotlinBuiltIns.getInstance().isUnit(bodyType) && !KotlinBuiltIns.getInstance().isNothing(bodyType)))
|
||||
(bodyType == null || (!KotlinBuiltIns.getInstance().isUnit(bodyType) && !KotlinBuiltIns.isNothing(bodyType)))
|
||||
|
||||
val oldBodyText = body.getText()!!
|
||||
val newBodyText = if (needReturn) "return ${oldBodyText}" else oldBodyText
|
||||
@@ -57,7 +57,7 @@ public class ConvertToBlockBodyAction : PsiElementBaseIntentionAction() {
|
||||
specifyTypeExplicitly(declaration, returnType)
|
||||
}
|
||||
|
||||
val newBody = generateBody(!KotlinBuiltIns.getInstance().isUnit(returnType) && !KotlinBuiltIns.getInstance().isNothing(returnType))
|
||||
val newBody = generateBody(!KotlinBuiltIns.getInstance().isUnit(returnType) && !KotlinBuiltIns.isNothing(returnType))
|
||||
|
||||
declaration.getEqualsToken()!!.delete()
|
||||
body.replace(newBody)
|
||||
|
||||
@@ -93,7 +93,7 @@ public class ConvertToExpressionBodyAction : PsiElementBaseIntentionAction() {
|
||||
|
||||
val expressionType = expressionType(statement)
|
||||
if (expressionType != null &&
|
||||
(KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.getInstance().isNothing(expressionType)))
|
||||
(KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.isNothing(expressionType)))
|
||||
Data(declaration, statement)
|
||||
else
|
||||
null
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ private fun List<AbstractJumpInstruction>.checkEquivalence(checkPsi: Boolean): B
|
||||
}
|
||||
|
||||
private fun JetType.isMeaningful(): Boolean {
|
||||
return KotlinBuiltIns.getInstance().let { builtins -> !builtins.isUnit(this) && !builtins.isNothing(this) }
|
||||
return KotlinBuiltIns.getInstance().let { builtins -> !builtins.isUnit(this) && !KotlinBuiltIns.isNothing(this) }
|
||||
}
|
||||
|
||||
private fun ExtractionData.getLocalDeclarationsWithNonLocalUsages(
|
||||
|
||||
Reference in New Issue
Block a user