is<TYPE>() made static in KotlinBuiltIns

This commit is contained in:
Andrey Breslav
2014-12-02 16:00:15 +03:00
parent 7a41e37655
commit db635c0e44
30 changed files with 60 additions and 53 deletions
@@ -319,7 +319,7 @@ public class ReplInterpreter {
earlierLines.add(new EarlierLine(line, scriptDescriptor, scriptClass, scriptInstance, scriptClassType));
JetType returnType = scriptDescriptor.getScriptCodeDescriptor().getReturnType();
return LineResult.successful(rv, returnType != null && KotlinBuiltIns.getInstance().isUnit(returnType));
return LineResult.successful(rv, returnType != null && KotlinBuiltIns.isUnit(returnType));
}
catch (Throwable e) {
@SuppressWarnings("UseOfSystemOutOrSystemErr")
@@ -91,7 +91,7 @@ public abstract class ElementAlternativeSignatureData {
@Nullable JetTypeReference altReturnTypeReference,
@NotNull Map<TypeParameterDescriptor, TypeParameterDescriptorImpl> originalToAltTypeParameters) {
if (altReturnTypeReference == null) {
if (KotlinBuiltIns.getInstance().isUnit(originalType)) {
if (KotlinBuiltIns.isUnit(originalType)) {
return originalType;
}
else {
@@ -105,7 +105,7 @@ public class JetControlFlowProcessor {
JetType returnType = subroutineDescriptor.getReturnType();
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
if (returnType != null && builtIns.isUnit(returnType) && subroutineDescriptor instanceof AnonymousFunctionDescriptor) return;
if (returnType != null && KotlinBuiltIns.isUnit(returnType) && subroutineDescriptor instanceof AnonymousFunctionDescriptor) return;
PseudoValue returnValue = builder.getBoundValue(bodyExpression);
if (returnValue == null) return;
@@ -245,7 +245,7 @@ public class JetFlowInformationProvider {
if (!(element instanceof JetExpression || element instanceof JetWhenCondition)) return;
if (blockBody && !noExpectedType(expectedReturnType)
&& !KotlinBuiltIns.getInstance().isUnit(expectedReturnType)
&& !KotlinBuiltIns.isUnit(expectedReturnType)
&& !unreachableCode.getElements().contains(element)) {
noReturnError[0] = true;
}
@@ -435,7 +435,7 @@ public class JetFlowInformationProvider {
if (operationReference != null) {
DeclarationDescriptor descriptor = trace.get(BindingContext.REFERENCE_TARGET, operationReference);
if (descriptor instanceof FunctionDescriptor) {
if (KotlinBuiltIns.getInstance().isUnit(((FunctionDescriptor) descriptor).getReturnType())) {
if (KotlinBuiltIns.isUnit(((FunctionDescriptor) descriptor).getReturnType())) {
hasReassignMethodReturningUnit = true;
}
}
@@ -444,7 +444,7 @@ public class JetFlowInformationProvider {
trace.get(BindingContext.AMBIGUOUS_REFERENCE_TARGET, operationReference);
if (descriptors != null) {
for (DeclarationDescriptor referenceDescriptor : descriptors) {
if (KotlinBuiltIns.getInstance().isUnit(((FunctionDescriptor) referenceDescriptor).getReturnType())) {
if (KotlinBuiltIns.isUnit(((FunctionDescriptor) referenceDescriptor).getReturnType())) {
hasReassignMethodReturningUnit = true;
}
}
@@ -38,7 +38,7 @@ public final class WhenChecker {
public static boolean mustHaveElse(@NotNull JetWhenExpression expression, @NotNull BindingTrace trace) {
JetType expectedType = trace.get(BindingContext.EXPECTED_EXPRESSION_TYPE, expression);
boolean isUnit = expectedType != null && KotlinBuiltIns.getInstance().isUnit(expectedType);
boolean isUnit = expectedType != null && KotlinBuiltIns.isUnit(expectedType);
// Some "statements" are actually expressions returned from lambdas, their expected types are non-null
boolean isStatement = BindingContextUtilPackage.isUsedAsStatement(expression, trace.getBindingContext()) && expectedType == null;
@@ -74,7 +74,7 @@ public fun or(predicates: Collection<TypePredicate>): TypePredicate? =
fun JetType.getSubtypesPredicate(): TypePredicate {
return when {
KotlinBuiltIns.getInstance().isAnyOrNullableAny(this) && isNullable() -> AllTypes
KotlinBuiltIns.isAnyOrNullableAny(this) && isNullable() -> AllTypes
TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, this) -> AllSubtypes(this)
else -> SingleType(this)
}
@@ -72,7 +72,7 @@ public class ArgumentTypeResolver {
@NotNull JetType expectedType
) {
if (actualType == PLACEHOLDER_FUNCTION_TYPE) {
return isFunctionOrErrorType(expectedType) || KotlinBuiltIns.getInstance().isAnyOrNullableAny(expectedType); //todo function type extends
return isFunctionOrErrorType(expectedType) || KotlinBuiltIns.isAnyOrNullableAny(expectedType); //todo function type extends
}
return JetTypeChecker.DEFAULT.isSubtypeOf(actualType, expectedType);
}
@@ -302,7 +302,7 @@ public class CallExpressionResolver {
//TODO move further
if (expression.getOperationSign() == JetTokens.SAFE_ACCESS) {
if (selectorReturnType != null && !KotlinBuiltIns.getInstance().isUnit(selectorReturnType)) {
if (selectorReturnType != null && !KotlinBuiltIns.isUnit(selectorReturnType)) {
if (TypeUtils.isNullableType(receiverType)) {
selectorReturnType = TypeUtils.makeNullable(selectorReturnType);
}
@@ -744,7 +744,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetType result;
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
assert returnType != null : "returnType is null for " + resolutionResults.getResultingDescriptor();
if (KotlinBuiltIns.getInstance().isUnit(returnType)) {
if (KotlinBuiltIns.isUnit(returnType)) {
result = ErrorUtils.createErrorType(KotlinBuiltIns.getInstance().getUnit().getName().asString());
context.trace.report(INC_DEC_SHOULD_NOT_RETURN_UNIT.on(operationSign));
}
@@ -265,7 +265,7 @@ public class ClosureExpressionsTypingVisitor extends ExpressionTypingVisitor {
JetType returnType = computeUnsafeReturnType(expression, context, functionDescriptor, expectedReturnType);
if (!expression.getFunctionLiteral().hasDeclaredReturnType() && functionTypeExpected) {
if (KotlinBuiltIns.getInstance().isUnit(expectedReturnType)) {
if (KotlinBuiltIns.isUnit(expectedReturnType)) {
return KotlinBuiltIns.getInstance().getUnitType();
}
}
@@ -495,7 +495,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
.replaceContextDependency(INDEPENDENT));
}
else {
if (expectedType != null && !noExpectedType(expectedType) && !KotlinBuiltIns.getInstance().isUnit(expectedType)) {
if (expectedType != null && !noExpectedType(expectedType) && !KotlinBuiltIns.isUnit(expectedType)) {
context.trace.report(RETURN_TYPE_MISMATCH.on(expression, expectedType));
}
}
@@ -254,7 +254,7 @@ public class DataFlowUtils {
@Nullable
public static JetType checkStatementType(@NotNull JetExpression expression, @NotNull ResolutionContext context) {
if (!noExpectedType(context.expectedType) && !KotlinBuiltIns.getInstance().isUnit(context.expectedType) && !context.expectedType.isError()) {
if (!noExpectedType(context.expectedType) && !KotlinBuiltIns.isUnit(context.expectedType) && !context.expectedType.isError()) {
context.trace.report(EXPECTED_TYPE_MISMATCH.on(expression, context.expectedType));
return null;
}
@@ -269,7 +269,7 @@ public class DataFlowUtils {
@Nullable
public static JetType checkImplicitCast(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ExpressionTypingContext context, boolean isStatement) {
if (expressionType != null && context.expectedType == NO_EXPECTED_TYPE && context.contextDependency == INDEPENDENT && !isStatement
&& (KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.getInstance().isAnyOrNullableAny(expressionType))
&& (KotlinBuiltIns.isUnit(expressionType) || KotlinBuiltIns.isAnyOrNullableAny(expressionType))
&& !TypesPackage.isDynamic(expressionType)) {
context.trace.report(IMPLICIT_CAST_TO_UNIT_OR_ANY.on(expression, expressionType));
}
@@ -328,7 +328,7 @@ public class ExpressionTypingServices {
if (!noExpectedType(context.expectedType) || context.expectedType == UNIT_EXPECTED_TYPE) {
JetType expectedType;
if (context.expectedType == UNIT_EXPECTED_TYPE ||//the first check is necessary to avoid invocation 'isUnit(UNIT_EXPECTED_TYPE)'
(coercionStrategyForLastExpression == COERCION_TO_UNIT && KotlinBuiltIns.getInstance().isUnit(context.expectedType))) {
(coercionStrategyForLastExpression == COERCION_TO_UNIT && KotlinBuiltIns.isUnit(context.expectedType))) {
expectedType = UNIT_EXPECTED_TYPE;
}
else {
@@ -353,7 +353,7 @@ public class ExpressionTypingServices {
}
if (mightBeUnit) {
// ExpressionTypingVisitorForStatements should return only null or Unit for declarations and assignments
assert result.getType() == null || KotlinBuiltIns.getInstance().isUnit(result.getType());
assert result.getType() == null || KotlinBuiltIns.isUnit(result.getType());
result = JetTypeInfo.create(KotlinBuiltIns.getInstance().getUnitType(), context.dataFlowInfo);
}
}
@@ -75,7 +75,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
@NotNull JetBinaryExpression expression,
@NotNull ExpressionTypingContext context
) {
if (assignmentType != null && !KotlinBuiltIns.getInstance().isUnit(assignmentType) && !noExpectedType(context.expectedType) &&
if (assignmentType != null && !KotlinBuiltIns.isUnit(assignmentType) && !noExpectedType(context.expectedType) &&
TypeUtils.equalTypes(context.expectedType, assignmentType)) {
context.trace.report(Errors.ASSIGNMENT_TYPE_MISMATCH.on(expression, context.expectedType));
return null;
@@ -130,7 +130,7 @@ public class MultiModuleJavaAnalysisCustomTest : UsefulTestCase() {
if (name in setOf("equals", "hashCode", "toString")) return
val returnType = callable.getReturnType()!!
if (!KotlinBuiltIns.getInstance().isUnit(returnType)) {
if (!KotlinBuiltIns.isUnit(returnType)) {
checkDescriptor(returnType.getConstructor().getDeclarationDescriptor()!!, callable)
}
@@ -145,7 +145,7 @@ public class MultiModuleJavaAnalysisCustomTest : UsefulTestCase() {
private fun checkSupertypes(classDescriptor: ClassDescriptor) {
classDescriptor.getDefaultType().getConstructor().getSupertypes().filter {
!KotlinBuiltIns.getInstance().isAnyOrNullableAny(it)
!KotlinBuiltIns.isAnyOrNullableAny(it)
}.map {
it.getConstructor().getDeclarationDescriptor()!!
}.forEach {