Rename: auto cast -> smart cast

This commit is contained in:
Svetlana Isakova
2014-09-29 23:09:05 +04:00
parent 20f3403c80
commit ce01c61811
294 changed files with 840 additions and 842 deletions
@@ -31,7 +31,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyClassDescriptor;
import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyPackageDescriptor;
import org.jetbrains.jet.lang.resolve.name.FqName;
@@ -167,7 +167,7 @@ options.kotlin.attribute.descriptor.extension.fun.call=Extension function call
options.kotlin.attribute.descriptor.constructor.call=Constructor call
options.kotlin.attribute.descriptor.variable.as.function.call=Variable as function call
options.kotlin.attribute.descriptor.variable.as.function.like.call=Variable as function-like call
options.kotlin.attribute.descriptor.auto.casted=Smart-cast value
options.kotlin.attribute.descriptor.smart.cast=Smart-cast value
options.kotlin.attribute.descriptor.label=Label
change.to.function.invocation=Change to function invocation
migrate.sure=Replace sure() calls by !! in project
@@ -33,7 +33,6 @@ import org.jetbrains.jet.lang.resolve.TopDownAnalysisParameters
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.psi.util.CachedValueProvider
import org.jetbrains.jet.asJava.LightClassUtil
import com.intellij.openapi.roots.libraries.LibraryUtil
import org.jetbrains.jet.lang.resolve.LibrarySourceHacks
import org.jetbrains.jet.plugin.project.TargetPlatform
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies
@@ -57,13 +56,11 @@ import org.jetbrains.jet.lang.psi.JetClassOrObject
import org.jetbrains.jet.lang.psi.JetCallableDeclaration
import org.jetbrains.jet.lang.psi.JetCodeFragment
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo
import org.jetbrains.jet.analyzer.analyzeInContext
import org.jetbrains.jet.lang.resolve.BindingTraceContext
import org.jetbrains.jet.lang.types.TypeUtils
import org.jetbrains.jet.lang.resolve.scopes.ChainedScope
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
import org.jetbrains.jet.plugin.util.application.warnTimeConsuming
public trait CacheExtension<T> {
@@ -79,7 +79,7 @@ public class JetHighlightingColors {
// other
public static final TextAttributesKey BAD_CHARACTER = createTextAttributesKey("KOTLIN_BAD_CHARACTER", HighlighterColors.BAD_CHARACTER);
public static final TextAttributesKey AUTO_CASTED_VALUE = createTextAttributesKey("KOTLIN_AUTO_CASTED_VALUE");
public static final TextAttributesKey SMART_CAST_VALUE = createTextAttributesKey("KOTLIN_SMART_CAST_VALUE");
public static final TextAttributesKey LABEL = createTextAttributesKey("KOTLIN_LABEL");
public static final TextAttributesKey DEBUG_INFO = createTextAttributesKey("KOTLIN_DEBUG_INFO");
public static final TextAttributesKey RESOLVED_TO_ERROR = createTextAttributesKey("KOTLIN_RESOLVED_TO_ERROR");
@@ -68,10 +68,10 @@ class VariablesHighlightingVisitor extends AfterAnalysisHighlightingVisitor {
@Override
public void visitExpression(@NotNull JetExpression expression) {
JetType autoCast = bindingContext.get(AUTOCAST, expression);
if (autoCast != null) {
holder.createInfoAnnotation(expression, "Automatically cast to " + DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(autoCast)).setTextAttributes(
JetHighlightingColors.AUTO_CASTED_VALUE);
JetType smartCast = bindingContext.get(SMARTCAST, expression);
if (smartCast != null) {
holder.createInfoAnnotation(expression, "Smart cast to " + DescriptorRenderer.FQ_NAMES_IN_TYPES.renderType(smartCast)).setTextAttributes(
JetHighlightingColors.SMART_CAST_VALUE);
}
super.visitExpression(expression);
}
@@ -21,12 +21,10 @@ import org.jetbrains.jet.lang.psi.JetCallExpression
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.resolve.calls.util.DelegatingCall
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo
import org.jetbrains.jet.lang.types.TypeUtils
import org.jetbrains.jet.lang.resolve.scopes.JetScope
import org.jetbrains.jet.lang.psi.JetTypeProjection
import org.jetbrains.jet.lang.psi.Call
import java.util.ArrayList
import org.jetbrains.jet.di.InjectorForMacros
import org.jetbrains.jet.lang.resolve.BindingTraceContext
import org.jetbrains.jet.plugin.caches.resolve.getLazyResolveSession
@@ -20,7 +20,7 @@
<option name="FONT_TYPE" value="1" />
</value>
</option>
<option name="KOTLIN_AUTO_CASTED_VALUE">
<option name="KOTLIN_SMART_CAST_VALUE">
<value>
<option name="BACKGROUND" value="223c23" />
</value>
@@ -20,7 +20,7 @@
<option name="FONT_TYPE" value="1" />
</value>
</option>
<option name="KOTLIN_AUTO_CASTED_VALUE">
<option name="KOTLIN_SMART_CAST_VALUE">
<value>
<option name="BACKGROUND" value="dbffdb" />
</value>
@@ -20,8 +20,8 @@ import org.jetbrains.jet.lang.descriptors.*
import org.jetbrains.jet.lang.psi.*
import org.jetbrains.jet.lang.psi.psiUtil.*
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastUtils
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo
import org.jetbrains.jet.lang.resolve.calls.smartcasts.SmartCastUtils
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.jet.lang.resolve.scopes.JetScope
import org.jetbrains.jet.lang.resolve.scopes.JetScopeUtils
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver
@@ -61,7 +61,7 @@ public object TipsManager{
val receiverValue = ExpressionReceiver(receiverExpression, expressionType)
val dataFlowInfo = context.getDataFlowInfo(expression)
for (variant in AutoCastUtils.getAutoCastVariants(receiverValue, context, dataFlowInfo)) {
for (variant in SmartCastUtils.getSmartCastVariants(receiverValue, context, dataFlowInfo)) {
variant.getMemberScope().getAllDescriptors().filterTo(descriptors) { filterIfInfix(it) && !it.isExtension }
}
@@ -16,7 +16,7 @@
package org.jetbrains.jet.plugin.completion
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowValue
import org.jetbrains.jet.lang.resolve.scopes.receivers.ThisReceiver
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.descriptors.VariableDescriptor
@@ -97,7 +97,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
else
filteredExpectedInfos
val typesWithAutoCasts: (DeclarationDescriptor) -> Iterable<JetType> = TypesWithAutoCasts(bindingContext).calculate(expressionWithType, receiver)
val typesWithSmartCasts: (DeclarationDescriptor) -> Iterable<JetType> = TypesWithSmartCasts(bindingContext).calculate(expressionWithType, receiver)
val itemsToSkip = calcItemsToSkip(expressionWithType)
@@ -106,7 +106,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
fun filterDeclaration(descriptor: DeclarationDescriptor): Collection<LookupElement> {
val result = ArrayList<LookupElement>()
if (!itemsToSkip.contains(descriptor)) {
val types = typesWithAutoCasts(descriptor)
val types = typesWithSmartCasts(descriptor)
val nonNullTypes = types.map { it.makeNotNullable() }
val classifier = { (expectedInfo: ExpectedInfo) ->
when {
@@ -136,7 +136,7 @@ class SmartCompletion(val expression: JetSimpleNameExpression,
KeywordValues.addToCollection(additionalItems, filteredExpectedInfos/* use filteredExpectedInfos to not include null after == */, expressionWithType)
MultipleArgumentsItemProvider(bindingContext, typesWithAutoCasts).addToCollection(additionalItems, expectedInfos, expression)
MultipleArgumentsItemProvider(bindingContext, typesWithSmartCasts).addToCollection(additionalItems, expectedInfos, expression)
}
return Result(::filterDeclaration, additionalItems)
@@ -25,19 +25,19 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.descriptors.ClassKind
import java.util.Collections
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowValue
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowValueFactory
import java.util.HashMap
import com.google.common.collect.SetMultimap
import org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability
import org.jetbrains.jet.lang.resolve.calls.smartcasts.Nullability
import java.util.HashSet
import org.jetbrains.jet.lang.resolve.BindingContext
import org.jetbrains.jet.lang.resolve.scopes.receivers.ThisReceiver
import org.jetbrains.jet.plugin.util.makeNotNullable
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getDataFlowInfo
class TypesWithAutoCasts(val bindingContext: BindingContext) {
class TypesWithSmartCasts(val bindingContext: BindingContext) {
public fun calculate(expression: JetExpression, receiver: JetExpression?): (DeclarationDescriptor) -> Iterable<JetType> {
val dataFlowInfo = bindingContext.getDataFlowInfo(expression)
val (variableToTypes: Map<VariableDescriptor, Collection<JetType>>, notNullVariables: Set<VariableDescriptor>)
@@ -55,9 +55,9 @@ class TypesWithAutoCasts(val bindingContext: BindingContext) {
returnType = returnType?.makeNotNullable()
}
val autoCastTypes = variableToTypes[descriptor]
if (autoCastTypes != null && !autoCastTypes.isEmpty()) {
return autoCastTypes + returnType.toList()
val smartCastTypes = variableToTypes[descriptor]
if (smartCastTypes != null && !smartCastTypes.isEmpty()) {
return smartCastTypes + returnType.toList()
}
}
return returnType.toList()
@@ -67,7 +67,7 @@ public class JetColorSettingsPage implements ColorSettingsPage {
" if (!<LOCAL_VARIABLE>ints</LOCAL_VARIABLE>.<EXTENSION_PROPERTY><PACKAGE_PROPERTY>empty</PACKAGE_PROPERTY></EXTENSION_PROPERTY>) {\n" +
" <LOCAL_VARIABLE>ints</LOCAL_VARIABLE>.<EXTENSION_FUNCTION_CALL><PACKAGE_FUNCTION_CALL><FUNCTION_CALL>forEach</FUNCTION_CALL></PACKAGE_FUNCTION_CALL></EXTENSION_FUNCTION_CALL> @lit <FUNCTION_LITERAL_BRACES_AND_ARROW>{</FUNCTION_LITERAL_BRACES_AND_ARROW>\n" +
" if (<FUNCTION_LITERAL_DEFAULT_PARAMETER>it</FUNCTION_LITERAL_DEFAULT_PARAMETER> == null) return @lit\n" +
" <FUNCTION_CALL><PACKAGE_FUNCTION_CALL>println</PACKAGE_FUNCTION_CALL></FUNCTION_CALL>(<FUNCTION_LITERAL_DEFAULT_PARAMETER><AUTO_CASTED_VALUE>it</AUTO_CASTED_VALUE></FUNCTION_LITERAL_DEFAULT_PARAMETER> + <LOCAL_VARIABLE><MUTABLE_VARIABLE><WRAPPED_INTO_REF>ref</WRAPPED_INTO_REF></MUTABLE_VARIABLE></LOCAL_VARIABLE>)\n" +
" <FUNCTION_CALL><PACKAGE_FUNCTION_CALL>println</PACKAGE_FUNCTION_CALL></FUNCTION_CALL>(<FUNCTION_LITERAL_DEFAULT_PARAMETER><SMART_CAST_VALUE>it</SMART_CAST_VALUE></FUNCTION_LITERAL_DEFAULT_PARAMETER> + <LOCAL_VARIABLE><MUTABLE_VARIABLE><WRAPPED_INTO_REF>ref</WRAPPED_INTO_REF></MUTABLE_VARIABLE></LOCAL_VARIABLE>)\n" +
" <FUNCTION_LITERAL_BRACES_AND_ARROW>}</FUNCTION_LITERAL_BRACES_AND_ARROW>\n" +
" }\n" +
" }\n" +
@@ -159,7 +159,7 @@ public class JetColorSettingsPage implements ColorSettingsPage {
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.bad.character"), JetHighlightingColors.BAD_CHARACTER),
new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.auto.casted"), JetHighlightingColors.AUTO_CASTED_VALUE),
new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.smart.cast"), JetHighlightingColors.SMART_CAST_VALUE),
new AttributesDescriptor(JetBundle.message("options.kotlin.attribute.descriptor.label"), JetHighlightingColors.LABEL),
};
@@ -31,7 +31,7 @@ import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
import com.intellij.psi.PsiElement
import org.jetbrains.jet.plugin.refactoring.inline.KotlinInlineValHandler
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowValueFactory
import org.jetbrains.jet.lang.resolve.BindingContextUtils
import org.jetbrains.jet.lang.descriptors.VariableDescriptor
import com.intellij.psi.search.searches.ReferencesSearch
@@ -35,7 +35,7 @@ import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingComponents;
import org.jetbrains.jet.plugin.caches.resolve.ResolvePackage;
@@ -84,13 +84,13 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
}
@NotNull
public static JetSingleIntentionActionFactory createFactoryForAutoCastImpossible() {
public static JetSingleIntentionActionFactory createFactoryForSmartCastImpossible() {
return new JetSingleIntentionActionFactory() {
@Nullable
@Override
public IntentionAction createAction(Diagnostic diagnostic) {
DiagnosticWithParameters2<JetExpression, JetType, String> diagnosticWithParameters =
Errors.AUTOCAST_IMPOSSIBLE.cast(diagnostic);
Errors.SMARTCAST_IMPOSSIBLE.cast(diagnostic);
return new CastExpressionFix(diagnosticWithParameters.getPsiElement(), diagnosticWithParameters.getA());
}
};
@@ -244,7 +244,7 @@ public class QuickFixRegistrar {
QuickFixes.factories.put(TYPE_MISMATCH, new QuickFixFactoryForTypeMismatchError());
QuickFixes.factories.put(AUTOCAST_IMPOSSIBLE, CastExpressionFix.createFactoryForAutoCastImpossible());
QuickFixes.factories.put(SMARTCAST_IMPOSSIBLE, CastExpressionFix.createFactoryForSmartCastImpossible());
QuickFixes.factories.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, MapPlatformClassToKotlinFix.createFactory());
@@ -552,7 +552,7 @@ private fun ExtractionData.inferParametersInfo(
if (extractParameter) {
val parameterType = when {
receiver.exists() -> receiver.getType()
else -> bindingContext[BindingContext.AUTOCAST, originalRef]
else -> bindingContext[BindingContext.SMARTCAST, originalRef]
?: bindingContext[BindingContext.EXPRESSION_TYPE, originalRef]
?: DEFAULT_PARAMETER_TYPE
}
@@ -41,7 +41,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
import org.jetbrains.jet.lang.resolve.ObservableBindingTrace;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
@@ -60,7 +60,6 @@ import org.jetbrains.jet.plugin.refactoring.introduce.KotlinIntroduceHandlerBase
import org.jetbrains.jet.plugin.util.psi.patternMatching.JetPsiRange;
import org.jetbrains.jet.plugin.util.psi.patternMatching.JetPsiUnifier;
import org.jetbrains.jet.plugin.util.psi.patternMatching.PatternMatchingPackage;
import org.jetbrains.jet.plugin.util.psi.patternMatching.UnifierParameter;
import org.jetbrains.jet.plugin.util.psiModificationUtil.PsiModificationUtilPackage;
import org.jetbrains.jet.renderer.DescriptorRenderer;
@@ -10,8 +10,8 @@ fun f9(a : A?) {
a<info>?.</info>foo()
a<info>?.</info><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
if (a is B) {
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Automatically cast to B">a</info>.foo()
<info descr="Smart cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.foo()
}
a<info>?.</info>foo()
a<info>?.</info><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
@@ -19,14 +19,14 @@ fun f9(a : A?) {
a<info>?.</info><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
a<info>?.</info>foo()
}
if (!(a is B) || <info descr="Automatically cast to B">a</info>.bar() == Unit) {
if (!(a is B) || <info descr="Smart cast to B">a</info>.bar() == Unit) {
a<info>?.</info><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
}
if (!(a is B)) {
return;
}
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Automatically cast to B">a</info>.foo()
<info descr="Smart cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.foo()
}
fun f10(a : A?) {
@@ -46,15 +46,15 @@ class C() : A() {
fun f101(a : A?) {
if (a is C) {
<info descr="Automatically cast to C">a</info>.bar();
<info descr="Smart cast to C">a</info>.bar();
}
}
fun f11(a : A?) {
when (a) {
is B -> <info descr="Automatically cast to B">a</info>.bar()
is A -> <info descr="Automatically cast to A">a</info>.foo()
is Any -> <info descr="Automatically cast to A">a</info>.foo()
is B -> <info descr="Smart cast to B">a</info>.bar()
is A -> <info descr="Smart cast to A">a</info>.foo()
is Any -> <info descr="Smart cast to A">a</info>.foo()
is Any? -> a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
else -> a<info>?.</info>foo()
}
@@ -62,11 +62,11 @@ fun f11(a : A?) {
fun f12(a : A?) {
when (a) {
is B -> <info descr="Automatically cast to B">a</info>.bar()
is A -> <info descr="Automatically cast to A">a</info>.foo()
is Any -> <info descr="Automatically cast to A">a</info>.foo();
is B -> <info descr="Smart cast to B">a</info>.bar()
is A -> <info descr="Smart cast to A">a</info>.foo()
is Any -> <info descr="Smart cast to A">a</info>.foo();
is Any? -> a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
is C -> <info descr="Automatically cast to C">a</info>.bar()
is C -> <info descr="Smart cast to C">a</info>.bar()
else -> a<info>?.</info>foo()
}
@@ -74,14 +74,14 @@ fun f12(a : A?) {
a<info>?.</info><error descr="[UNRESOLVED_REFERENCE] Unresolved reference: bar">bar</error>()
}
if (a is B) {
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.bar()
}
}
fun f13(a : A?) {
if (a is B) {
<info descr="Automatically cast to B">a</info>.foo()
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.foo()
<info descr="Smart cast to B">a</info>.bar()
}
else {
a<info>?.</info>foo()
@@ -93,13 +93,13 @@ fun f13(a : A?) {
a<info>?.</info>foo()
}
else {
<info descr="Automatically cast to B">a</info>.foo()
<info descr="Smart cast to B">a</info>.foo()
}
a<info>?.</info>foo()
if (a is B && <info descr="Automatically cast to B">a</info>.foo() == Unit) {
<info descr="Automatically cast to B">a</info>.foo()
<info descr="Automatically cast to B">a</info>.bar()
if (a is B && <info descr="Smart cast to B">a</info>.foo() == Unit) {
<info descr="Smart cast to B">a</info>.foo()
<info descr="Smart cast to B">a</info>.bar()
}
else {
a<info>?.</info>foo()
@@ -114,72 +114,72 @@ fun f13(a : A?) {
}
if (!(a is B)) return
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.bar()
}
fun f14(a : A?) {
while (!(a is B)) {
}
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.bar()
}
fun f15(a : A?) {
do {
} while (!(a is B))
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.bar()
}
fun getStringLength(obj : Any) : Char? {
if (obj !is String)
return null
return <info descr="Automatically cast to kotlin.String">obj</info>.get(0) // no cast to kotlin.String is needed
return <info descr="Smart cast to kotlin.String">obj</info>.get(0) // no cast to kotlin.String is needed
}
fun toInt(i: Int?): Int = if (i != null) <info descr="Automatically cast to kotlin.Int">i</info> else 0
fun toInt(i: Int?): Int = if (i != null) <info descr="Smart cast to kotlin.Int">i</info> else 0
fun illegalWhenBody(a: Any): Int = when(a) {
is Int -> <info descr="Automatically cast to kotlin.Int">a</info>
is Int -> <info descr="Smart cast to kotlin.Int">a</info>
is String -> <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is kotlin.Any but kotlin.Int was expected">a</error>
else -> 1
}
fun illegalWhenBlock(a: Any): Int {
when(a) {
is Int -> return <info descr="Automatically cast to kotlin.Int">a</info>
is Int -> return <info descr="Smart cast to kotlin.Int">a</info>
is String -> return <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is kotlin.Any but kotlin.Int was expected">a</error>
else -> return 1
}
}
fun declarations(a: Any?) {
if (a is String) {
val <warning>p4</warning>: String = <info descr="Automatically cast to kotlin.String">a</info>
val <warning>p4</warning>: String = <info descr="Smart cast to kotlin.String">a</info>
}
if (a is String?) {
if (a != null) {
val <warning>s</warning>: String = <info descr="Automatically cast to kotlin.String">a</info>
val <warning>s</warning>: String = <info descr="Smart cast to kotlin.String">a</info>
}
}
if (a != null) {
if (a is String?) {
val <warning>s</warning>: String = <info descr="Automatically cast to kotlin.String">a</info>
val <warning>s</warning>: String = <info descr="Smart cast to kotlin.String">a</info>
}
}
}
fun vars(a: Any?) {
var <warning>b</warning>: Int = 0
if (a is Int) {
b = <warning><info descr="Automatically cast to kotlin.Int">a</info></warning>
b = <warning><info descr="Smart cast to kotlin.Int">a</info></warning>
}
}
fun returnFunctionLiteralBlock(<info>a</info>: Any?): Function0<Int> {
if (<info>a</info> is Int) return { <info descr="Automatically cast to kotlin.Int"><info>a</info></info> }
if (<info>a</info> is Int) return { <info descr="Smart cast to kotlin.Int"><info>a</info></info> }
else return { 1 }
}
fun returnFunctionLiteral(<info>a</info>: Any?): Function0<Int> =
if (<info>a</info> is Int) { (): Int -> <info descr="Automatically cast to kotlin.Int"><info>a</info></info> }
if (<info>a</info> is Int) { (): Int -> <info descr="Smart cast to kotlin.Int"><info>a</info></info> }
else { () -> 1 }
fun merge<TYPO descr="Typo: In word 'Autocasts'">Autocasts</TYPO>(a: Any?) {
fun mergeSmartCasts(a: Any?) {
if (a is String || a is Int) {
a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: compareTo">compareTo</error>("")
<info descr="Automatically cast to kotlin.Any"><info>a</info></info>.toString()
<info descr="Smart cast to kotlin.Any"><info>a</info></info>.toString()
}
if (a is Int || a is String) {
a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: compareTo">compareTo</error>("")
@@ -188,9 +188,9 @@ fun merge<TYPO descr="Typo: In word 'Autocasts'">Autocasts</TYPO>(a: Any?) {
is String, is Any -> a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: compareTo">compareTo</error>("")
}
if (a is String && a is Any) {
val <warning>i</warning>: Int = <info descr="Automatically cast to kotlin.String">a</info>.compareTo("")
val <warning>i</warning>: Int = <info descr="Smart cast to kotlin.String">a</info>.compareTo("")
}
if (a is String && <info descr="Automatically cast to kotlin.String">a</info>.compareTo("") == 0) {}
if (a is String && <info descr="Smart cast to kotlin.String">a</info>.compareTo("") == 0) {}
if (a is String || a.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: compareTo">compareTo</error>("") <error>==</error> 0) {}
}
@@ -198,10 +198,10 @@ fun merge<TYPO descr="Typo: In word 'Autocasts'">Autocasts</TYPO>(a: Any?) {
fun f(): String {
var <info>a</info>: Any = 11
if (<info>a</info> is String) {
val <warning>i</warning>: String = <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error>
<error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error>.compareTo("f")
val <warning>f</warning>: Function0<String> = { <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error> }
return <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error>
val <warning>i</warning>: String = <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error>
<error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error>.compareTo("f")
val <warning>f</warning>: Function0<String> = { <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error> }
return <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.String' is impossible, because 'a' could have changed since the is-check">a</error>
}
return ""
}
@@ -209,14 +209,14 @@ fun f(): String {
fun foo(aa: Any): Int {
var a = aa
if (a is Int) {
return <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to 'kotlin.Int' is impossible, because 'a' could have changed since the is-check">a</error>
return <error descr="[SMARTCAST_IMPOSSIBLE] Smart cast to 'kotlin.Int' is impossible, because 'a' could have changed since the is-check">a</error>
}
return 1
}
fun inForLoop(x: Any?) {
if (x is Array<String>) {
for (i in <info descr="Automatically cast to kotlin.Array<kotlin.String>">x</info>) {}
for (i in <info descr="Smart cast to kotlin.Array<kotlin.String>">x</info>) {}
}
for (i in <error descr="[ITERATOR_MISSING] For-loop range must have an iterator() method">x</error>) {}
}
@@ -12,15 +12,15 @@ trait D : A
fun test(a: A?) {
if (a != null && a is B?) {
<info descr="Automatically cast to B">a</info>.bar()
<info descr="Smart cast to B">a</info>.bar()
}
if (a is B && a is C) {
<info descr="Automatically cast to B">a</info>.foo()
<info descr="Smart cast to B">a</info>.foo()
}
if (a is B? && a is C?) {
<info descr="Automatically cast to B?">a</info><info>?.</info>bar()
<info descr="Smart cast to B?">a</info><info>?.</info>bar()
}
a<info>?.</info>foo()
@@ -29,7 +29,7 @@ fun test(a: A?) {
}
if (a is B && a is D) {
//when it's resolved, the message should be 'Automatically cast to A'
//when it's resolved, the message should be 'Smart cast to A'
a.<error>foo</error>
}
}
@@ -656,12 +656,6 @@ public class JetPsiCheckerTestGenerated extends AbstractJetPsiCheckerTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/checker/infos"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("Autocasts.kt")
public void testAutocasts() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/infos/Autocasts.kt");
doTestWithInfos(fileName);
}
@TestMetadata("CapturedInInlinedClosure.kt")
public void testCapturedInInlinedClosure() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/infos/CapturedInInlinedClosure.kt");
@@ -674,6 +668,12 @@ public class JetPsiCheckerTestGenerated extends AbstractJetPsiCheckerTest {
doTestWithInfos(fileName);
}
@TestMetadata("SmartCasts.kt")
public void testSmartCasts() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/infos/SmartCasts.kt");
doTestWithInfos(fileName);
}
@TestMetadata("SmartCastsWithSafeAccess.kt")
public void testSmartCastsWithSafeAccess() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/checker/infos/SmartCastsWithSafeAccess.kt");
@@ -54,30 +54,6 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/completion/basic/common"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("AutoCastAfterIf.kt")
public void testAutoCastAfterIf() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/AutoCastAfterIf.kt");
doTest(fileName);
}
@TestMetadata("AutoCastAfterIfMethod.kt")
public void testAutoCastAfterIfMethod() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/AutoCastAfterIfMethod.kt");
doTest(fileName);
}
@TestMetadata("AutoCastForThis.kt")
public void testAutoCastForThis() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/AutoCastForThis.kt");
doTest(fileName);
}
@TestMetadata("AutoCastInWhen.kt")
public void testAutoCastInWhen() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/AutoCastInWhen.kt");
doTest(fileName);
}
@TestMetadata("BasicAny.kt")
public void testBasicAny() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/BasicAny.kt");
@@ -588,6 +564,30 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes
doTest(fileName);
}
@TestMetadata("SmartCastAfterIf.kt")
public void testSmartCastAfterIf() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/SmartCastAfterIf.kt");
doTest(fileName);
}
@TestMetadata("SmartCastAfterIfMethod.kt")
public void testSmartCastAfterIfMethod() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/SmartCastAfterIfMethod.kt");
doTest(fileName);
}
@TestMetadata("SmartCastForThis.kt")
public void testSmartCastForThis() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/SmartCastForThis.kt");
doTest(fileName);
}
@TestMetadata("SmartCastInWhen.kt")
public void testSmartCastInWhen() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/SmartCastInWhen.kt");
doTest(fileName);
}
@TestMetadata("StandardJetArrayFirst.kt")
public void testStandardJetArrayFirst() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/StandardJetArrayFirst.kt");
@@ -54,30 +54,6 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/completion/basic/common"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("AutoCastAfterIf.kt")
public void testAutoCastAfterIf() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/AutoCastAfterIf.kt");
doTest(fileName);
}
@TestMetadata("AutoCastAfterIfMethod.kt")
public void testAutoCastAfterIfMethod() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/AutoCastAfterIfMethod.kt");
doTest(fileName);
}
@TestMetadata("AutoCastForThis.kt")
public void testAutoCastForThis() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/AutoCastForThis.kt");
doTest(fileName);
}
@TestMetadata("AutoCastInWhen.kt")
public void testAutoCastInWhen() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/AutoCastInWhen.kt");
doTest(fileName);
}
@TestMetadata("BasicAny.kt")
public void testBasicAny() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/BasicAny.kt");
@@ -588,6 +564,30 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT
doTest(fileName);
}
@TestMetadata("SmartCastAfterIf.kt")
public void testSmartCastAfterIf() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/SmartCastAfterIf.kt");
doTest(fileName);
}
@TestMetadata("SmartCastAfterIfMethod.kt")
public void testSmartCastAfterIfMethod() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/SmartCastAfterIfMethod.kt");
doTest(fileName);
}
@TestMetadata("SmartCastForThis.kt")
public void testSmartCastForThis() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/SmartCastForThis.kt");
doTest(fileName);
}
@TestMetadata("SmartCastInWhen.kt")
public void testSmartCastInWhen() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/SmartCastInWhen.kt");
doTest(fileName);
}
@TestMetadata("StandardJetArrayFirst.kt")
public void testStandardJetArrayFirst() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/StandardJetArrayFirst.kt");
@@ -86,18 +86,6 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
doTest(fileName);
}
@TestMetadata("AutoCastedType.kt")
public void testAutoCastedType() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/AutoCastedType.kt");
doTest(fileName);
}
@TestMetadata("AutoCastedTypeWithQualifier.kt")
public void testAutoCastedTypeWithQualifier() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/AutoCastedTypeWithQualifier.kt");
doTest(fileName);
}
@TestMetadata("AutoNotNullType.kt")
public void testAutoNotNullType() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/AutoNotNullType.kt");
@@ -686,6 +674,18 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT
doTest(fileName);
}
@TestMetadata("SmartCastType.kt")
public void testSmartCastType() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/SmartCastType.kt");
doTest(fileName);
}
@TestMetadata("SmartCastTypeWithQualifier.kt")
public void testSmartCastTypeWithQualifier() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/SmartCastTypeWithQualifier.kt");
doTest(fileName);
}
@TestMetadata("This.kt")
public void testThis() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/smart/This.kt");
@@ -86,9 +86,9 @@ public class MultiFileJvmBasicCompletionTestGenerated extends AbstractMultiFileJ
doTest(fileName);
}
@TestMetadata("ExtensionsForAutoCasted")
public void testExtensionsForAutoCasted() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/multifile/ExtensionsForAutoCasted/");
@TestMetadata("ExtensionsForSmartCast")
public void testExtensionsForSmartCast() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/multifile/ExtensionsForSmartCast/");
doTest(fileName);
}
@@ -208,9 +208,9 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
doTestWithExtraFile(fileName);
}
@TestMetadata("withAutoCastedQualifier.before.Main.kt")
public void testWithAutoCastedQualifier() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/withAutoCastedQualifier.before.Main.kt");
@TestMetadata("withSmartCastQualifier.before.Main.kt")
public void testWithSmartCastQualifier() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/autoImports/withSmartCastQualifier.before.Main.kt");
doTestWithExtraFile(fileName);
}
@@ -2886,30 +2886,30 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/typeMismatch/casts"), Pattern.compile("^before(\\w+)\\.kt$"), true);
}
@TestMetadata("beforeAutocastImpossible1.kt")
public void testAutocastImpossible1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/casts/beforeAutocastImpossible1.kt");
doTest(fileName);
}
@TestMetadata("beforeAutocastImpossible2.kt")
public void testAutocastImpossible2() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/casts/beforeAutocastImpossible2.kt");
doTest(fileName);
}
@TestMetadata("beforeAutocastImpossible3.kt")
public void testAutocastImpossible3() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/casts/beforeAutocastImpossible3.kt");
doTest(fileName);
}
@TestMetadata("beforeCastToFunctionType.kt")
public void testCastToFunctionType() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/casts/beforeCastToFunctionType.kt");
doTest(fileName);
}
@TestMetadata("beforeSmartcastImpossible1.kt")
public void testSmartcastImpossible1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/casts/beforeSmartcastImpossible1.kt");
doTest(fileName);
}
@TestMetadata("beforeSmartcastImpossible2.kt")
public void testSmartcastImpossible2() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/casts/beforeSmartcastImpossible2.kt");
doTest(fileName);
}
@TestMetadata("beforeSmartcastImpossible3.kt")
public void testSmartcastImpossible3() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/casts/beforeSmartcastImpossible3.kt");
doTest(fileName);
}
@TestMetadata("beforeTypeMismatch1.kt")
public void testTypeMismatch1() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/casts/beforeTypeMismatch1.kt");