fix more compilation errors and some tests

This commit is contained in:
Dmitry Jemerov
2015-10-08 16:53:43 +02:00
parent f5aaf65ca9
commit a63d3f5a0f
13 changed files with 29 additions and 56 deletions
@@ -33,7 +33,7 @@ public fun PsiElement.getKotlinFqName(): FqName? {
return when (element) {
is PsiPackage -> FqName(element.getQualifiedName())
is PsiClass -> element.getQualifiedName()?.let { FqName(it) }
is PsiMember -> (element : PsiMember).getName()?.let { name ->
is PsiMember -> (element as PsiMember).getName()?.let { name ->
val prefix = element.getContainingClass()?.getQualifiedName()
FqName(if (prefix != null) "$prefix.$name" else name)
}
@@ -57,7 +57,7 @@ public class JetElementDescriptionProvider : ElementDescriptionProvider {
if (targetElement !is PsiNamedElement || targetElement !is JetElement) return null
val name = (targetElement : PsiNamedElement).getName()
val name = (targetElement as PsiNamedElement).getName()
return when(location) {
is UsageViewLongNameLocation ->
@@ -52,7 +52,7 @@ internal fun getTargetParentByQualifier(
isQualified: Boolean,
qualifierDescriptor: DeclarationDescriptor?): PsiElement? {
val project = file.getProject()
val targetParent = when {
val targetParent: PsiElement = when {
!isQualified ->
file
qualifierDescriptor is ClassDescriptor ->
@@ -61,7 +61,7 @@ internal fun getTargetParentByQualifier(
if (qualifierDescriptor.fqName != file.getPackageFqName()) {
JavaPsiFacade.getInstance(project).findPackage(qualifierDescriptor.fqName.asString())
}
else file : PsiElement
else file as PsiElement
else ->
null
} ?: return null
@@ -112,11 +112,12 @@ internal fun JetSimpleNameExpression.getCreatePackageFixIfApplicable(targetParen
val name = getReferencedName()
if (!name.checkPackageName()) return null
val basePackage: PsiPackage = when (targetParent) {
val basePackage: PsiPackage? = when (targetParent) {
is JetFile -> JavaPsiFacade.getInstance(targetParent.getProject()).findPackage(targetParent.getPackageFqName().asString())
is PsiPackage -> targetParent : PsiPackage
is PsiPackage -> targetParent
else -> null
} ?: return null
}
if (basePackage == null) return null
val baseName = basePackage.getQualifiedName()
val fullName = if (baseName.isNotEmpty()) "$baseName.$name" else name
@@ -29,6 +29,7 @@ import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer
import com.intellij.refactoring.listeners.RefactoringEventListener
import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
@@ -222,12 +223,7 @@ public open class KotlinIntroduceParameterHandler(
}
val descriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, targetParent]
val functionDescriptor: FunctionDescriptor =
when (descriptor) {
is FunctionDescriptor -> descriptor : FunctionDescriptor
is ClassDescriptor -> descriptor.getUnsubstitutedPrimaryConstructor()
else -> null
} ?: throw AssertionError("Unexpected element type: ${targetParent.getElementTextWithContext()}")
val functionDescriptor = descriptor.toFunctionDescriptor(targetParent)
val replacementType = expressionType.approximateWithResolvableType(targetParent.getResolutionScope(context, targetParent.getResolutionFacade()), false)
val body = when (targetParent) {
@@ -354,6 +350,19 @@ public open class KotlinIntroduceParameterHandler(
}
}
private fun DeclarationDescriptor?.toFunctionDescriptor(targetParent: JetNamedDeclaration): FunctionDescriptor {
val functionDescriptor: FunctionDescriptor? =
when (this) {
is FunctionDescriptor -> this
is ClassDescriptor -> this.getUnsubstitutedPrimaryConstructor()
else -> null
}
if (functionDescriptor == null) {
throw AssertionError("Unexpected element type: ${targetParent.getElementTextWithContext()}")
}
return functionDescriptor
}
private fun findInternalUsagesOfParametersAndReceiver(
targetParent: JetNamedDeclaration,
targetDescriptor: FunctionDescriptor
@@ -413,12 +422,7 @@ public open class KotlinIntroduceLambdaParameterHandler(
): KotlinIntroduceParameterDialog {
val callable = lambdaExtractionDescriptor.extractionData.targetSibling as JetNamedDeclaration
val descriptor = callable.resolveToDescriptor()
val callableDescriptor: FunctionDescriptor =
when (descriptor) {
is FunctionDescriptor -> descriptor : FunctionDescriptor
is ClassDescriptor -> descriptor.getUnsubstitutedPrimaryConstructor()
else -> null
} ?: throw AssertionError("Unexpected element type: ${callable.getElementTextWithContext()}")
val callableDescriptor = descriptor.toFunctionDescriptor(callable)
val originalRange = lambdaExtractionDescriptor.extractionData.originalRange
val introduceParameterDescriptor = IntroduceParameterDescriptor(
originalRange = originalRange,
@@ -462,7 +462,7 @@ private fun copyTypeParameters<T>(
to: T,
inserter: (T, PsiTypeParameterList) -> Unit
) where T : PsiTypeParameterListOwner, T : PsiNameIdentifierOwner {
val factory = PsiElementFactory.SERVICE.getInstance((from : PsiElement).getProject())
val factory = PsiElementFactory.SERVICE.getInstance((from as PsiElement).getProject())
val templateTypeParams = from.getTypeParameterList()?.getTypeParameters() ?: PsiTypeParameter.EMPTY_ARRAY
if (templateTypeParams.isNotEmpty()) {
inserter(to, factory.createTypeParameterList())
+1 -1
View File
@@ -2,7 +2,7 @@
fun foo() {
@Suppress("REDUNDANT_NULLABLE")
call("": String?<caret>?)
call("" as String??)
}
fun call(s: String?) {}
@@ -1,5 +0,0 @@
// "class org.jetbrains.kotlin.idea.quickfix.ChangeParameterTypeFix" "false"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>kotlin.Int</td></tr><tr><td>Found:</td><td>kotlin.String</td></tr></table></html>
fun foo(y: Int = 0, z: (Int) -> String = {""}) {
foo(""<caret>: Int)
}
@@ -1,3 +0,0 @@
// "class org.jetbrains.kotlin.idea.quickfix.ChangeFunctionReturnTypeFix" "false"
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>kotlin.Int</td></tr><tr><td>Found:</td><td>kotlin.String</td></tr></table></html>
fun foo(): Int = if (true) ""<caret>: Int else 4
@@ -1,4 +0,0 @@
fun f() {
val v = 2..3
println(<caret>v: IntRange)
}
@@ -1,3 +0,0 @@
fun f() {
println((2..3): IntRange)
}
@@ -6413,12 +6413,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("changeFunctionParameterType5.kt")
public void testChangeFunctionParameterType5() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/changeFunctionParameterType5.kt");
doTest(fileName);
}
@TestMetadata("changeParameterTypeLongNameRuntime.kt")
public void testChangeParameterTypeLongNameRuntime() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/changeParameterTypeLongNameRuntime.kt");
@@ -6500,12 +6494,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
doTest(fileName);
}
@TestMetadata("returnedExpresionCantEvaluateToExpresionThatTypeMismatch.kt")
public void testReturnedExpresionCantEvaluateToExpresionThatTypeMismatch() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/returnedExpresionCantEvaluateToExpresionThatTypeMismatch.kt");
doTest(fileName);
}
@TestMetadata("returnedExpressionTypeMismatchFunctionParameterType.kt")
public void testReturnedExpressionTypeMismatchFunctionParameterType() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/returnedExpressionTypeMismatchFunctionParameterType.kt");
@@ -169,12 +169,6 @@ public class InlineTestGenerated extends AbstractInlineTest {
doTest(fileName);
}
@TestMetadata("Colon.kt")
public void testColon() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/inline/addParenthesis/Colon.kt");
doTest(fileName);
}
@TestMetadata("ColonDontAdd.kt")
public void testColonDontAdd() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/inline/addParenthesis/ColonDontAdd.kt");
@@ -116,13 +116,14 @@ public class DelegationTranslator(
val delegateRefName = context().getScopeForDescriptor(getterDescriptor).declareName(delegateName)
val delegateRef = JsNameRef(delegateRefName, JsLiteral.THIS)
val returnExpression: JsExpression = if (DescriptorUtils.isExtension(descriptor)) { // TODO remove explicit type specification after resolving KT-5569
val returnExpression: JsExpression = if (DescriptorUtils.isExtension(descriptor)) {
val getterName = context().getNameForDescriptor(getterDescriptor)
val receiver = Namer.getReceiverParameterName()
JsInvocation(JsNameRef(getterName, delegateRef), JsNameRef(receiver))
}
else {
JsNameRef(propertyName, delegateRef)
@Suppress("USELESS_CAST")
(JsNameRef(propertyName, delegateRef) as JsExpression) // TODO remove explicit type specification after resolving KT-5569
}
val jsFunction = simpleReturnFunction(context().getScopeForDescriptor(getterDescriptor.getContainingDeclaration()), returnExpression)