Fixed EA-69042

This commit is contained in:
Valentin Kipyatkov
2015-06-03 15:47:06 +03:00
parent e597532c7a
commit f05789e224
4 changed files with 31 additions and 8 deletions
@@ -42,7 +42,7 @@ enum class CaretPosition {
data class GenerateLambdaInfo(val lambdaType: JetType, val explicitParameters: Boolean)
class KotlinFunctionInsertHandler(val caretPosition : CaretPosition, val lambdaInfo: GenerateLambdaInfo?) : KotlinCallableInsertHandler() {
class KotlinFunctionInsertHandler(val caretPosition: CaretPosition, val lambdaInfo: GenerateLambdaInfo?) : KotlinCallableInsertHandler() {
init {
if (caretPosition == CaretPosition.AFTER_BRACKETS && lambdaInfo != null) {
throw IllegalArgumentException("CaretPosition.AFTER_BRACKETS with lambdaInfo != null combination is not supported")
@@ -92,11 +92,10 @@ class KotlinFunctionInsertHandler(val caretPosition : CaretPosition, val lambdaI
val document = context.getDocument()
val chars = document.getCharsSequence()
val forceParenthesis = lambdaInfo != null && completionChar == '\t' && chars.charAt(offset) == '('
val braces = lambdaInfo != null && completionChar != '(' && !forceParenthesis
val insertLambda = lambdaInfo != null && completionChar != '(' && !(completionChar == '\t' && chars.charAt(offset) == '(')
val openingBracket = if (braces) '{' else '('
val closingBracket = if (braces) '}' else ')'
val openingBracket = if (insertLambda) '{' else '('
val closingBracket = if (insertLambda) '}' else ')'
if (completionChar == Lookup.REPLACE_SELECT_CHAR) {
val offset1 = chars.skipSpaces(offset)
@@ -117,7 +116,7 @@ class KotlinFunctionInsertHandler(val caretPosition : CaretPosition, val lambdaI
var openingBracketOffset = chars.indexOfSkippingSpace(openingBracket, offset)
var inBracketsShift = 0
if (openingBracketOffset == null) {
if (braces) {
if (insertLambda) {
if (completionChar == ' ' || completionChar == '{') {
context.setAddCompletionChar(false)
}
@@ -151,8 +150,8 @@ class KotlinFunctionInsertHandler(val caretPosition : CaretPosition, val lambdaI
PsiDocumentManager.getInstance(context.getProject()).commitDocument(document)
if (lambdaInfo != null && lambdaInfo.explicitParameters) {
insertLambdaTemplate(context, TextRange(openingBracketOffset, closeBracketOffset!! + 1), lambdaInfo.lambdaType)
if (insertLambda && lambdaInfo!!.explicitParameters) {
insertLambdaTemplate(context, TextRange(openingBracketOffset, closeBracketOffset!! + 1), lambdaInfo!!.lambdaType)
}
}
@@ -0,0 +1,9 @@
fun foo(p : (String, Char) -> Boolean){}
fun main(args: Array<String>) {
fo<caret>(1, 2
}
// ELEMENT: "foo"
// TAIL_TEXT: " { String, Char -> ... } (<root>)"
// CHAR: '\t'
@@ -0,0 +1,9 @@
fun foo(p : (String, Char) -> Boolean){}
fun main(args: Array<String>) {
foo(<caret>1, 2
}
// ELEMENT: "foo"
// TAIL_TEXT: " { String, Char -> ... } (<root>)"
// CHAR: '\t'
@@ -119,6 +119,12 @@ public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletion
doTest(fileName);
}
@TestMetadata("ReplaceByLambdaTemplateNoClosingParenth.kt")
public void testReplaceByLambdaTemplateNoClosingParenth() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/ReplaceByLambdaTemplateNoClosingParenth.kt");
doTest(fileName);
}
@TestMetadata("ReplaceFunctionCallByProperty.kt")
public void testReplaceFunctionCallByProperty() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/idea-completion/testData/handlers/basic/ReplaceFunctionCallByProperty.kt");