Skip to content

Commit

Permalink
Fix ISE when caret is on parameter of function type
Browse files Browse the repository at this point in the history
EA-68570
  • Loading branch information
udalov committed May 28, 2015
1 parent 3de3c0f commit 9bcc9fb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions idea/src/org/jetbrains/kotlin/idea/intentions/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithVisibility
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.references.JetReference
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.idea.util.ShortenReferences
Expand Down Expand Up @@ -74,10 +73,11 @@ fun isAutoCreatedItUsage(expression: JetSimpleNameExpression): Boolean {
}

fun JetCallableDeclaration.canRemoveTypeSpecificationByVisibility(): Boolean {
val descriptor = resolveToDescriptor()
val isOverride = getModifierList()?.hasModifier(JetTokens.OVERRIDE_KEYWORD) ?: false
if (!isOverride && (descriptor as? DeclarationDescriptorWithVisibility)?.getVisibility()?.isPublicAPI() ?: false) return false
return true
if (isOverride) return true

val descriptor = analyze()[BindingContext.DECLARATION_TO_DESCRIPTOR, this]

This comment has been minimized.

Copy link
@pTalanov

pTalanov Jun 4, 2015

Contributor

Is it the nature of the fix that you don't use resolveToDescriptor()?

This comment has been minimized.

Copy link
@udalov

udalov Jun 4, 2015

Author Member

Yes.

return descriptor !is DeclarationDescriptorWithVisibility || !descriptor.getVisibility().isPublicAPI()
}

// returns assignment which replaces initializer
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// IS_APPLICABLE: false
fun foo(x: (<caret>String) -> Unit) {}
Original file line number Diff line number Diff line change
Expand Up @@ -5671,6 +5671,12 @@ public void testAllFilesPresentInRemoveExplicitType() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/removeExplicitType"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), true);
}

@TestMetadata("notOnParameterOfFunctionType.kt")
public void testNotOnParameterOfFunctionType() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/removeExplicitType/notOnParameterOfFunctionType.kt");
doTest(fileName);
}

@TestMetadata("notOnPublic.kt")
public void testNotOnPublic() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/intentions/removeExplicitType/notOnPublic.kt");
Expand Down

0 comments on commit 9bcc9fb

Please sign in to comment.