Fix in SpecifyTypeExplicitlyIntention
This commit is contained in:
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.util.ShortenReferences
|
||||
import org.jetbrains.kotlin.j2k.isConstructor
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -45,6 +46,8 @@ import java.util.ArrayList
|
||||
public class SpecifyTypeExplicitlyIntention : JetSelfTargetingIntention<JetCallableDeclaration>(javaClass(), "Specify type explicitly") {
|
||||
override fun isApplicableTo(element: JetCallableDeclaration, caretOffset: Int): Boolean {
|
||||
if (element.getContainingFile() is JetCodeFragment) return false
|
||||
if (element is JetFunctionLiteral) return false // TODO: should JetFunctionLiteral be JetCallableDeclaration at all?
|
||||
if (element is JetPrimaryConstructor || element is JetSecondaryConstructor) return false // TODO: base class?
|
||||
if (element.getTypeReference() != null) return false
|
||||
|
||||
if (getTypeForDeclaration(element).isError() || hasPublicMemberDiagnostic(element)) return false
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// IS_APPLICABLE: false
|
||||
// ERROR: Primary constructor call expected
|
||||
class A(val x: Int) {
|
||||
constructor(x: String)<caret>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// IS_APPLICABLE: false
|
||||
fun foo(): Any {
|
||||
return { (x: String<caret>) -> 42 }
|
||||
}
|
||||
@@ -5820,6 +5820,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("constructor.kt")
|
||||
public void testConstructor() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/specifyTypeExplicitly/constructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("enumType.kt")
|
||||
public void testEnumType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/specifyTypeExplicitly/enumType.kt");
|
||||
@@ -5832,6 +5838,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("lambdaParam.kt")
|
||||
public void testLambdaParam() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/specifyTypeExplicitly/lambdaParam.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("loopParameter.kt")
|
||||
public void testLoopParameter() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/specifyTypeExplicitly/loopParameter.kt");
|
||||
|
||||
Reference in New Issue
Block a user