Merge pull request #825 from mcgee/KT-5728

#KT-5728 Fixed
This commit is contained in:
Dmitry Jemerov
2016-03-09 12:27:36 +01:00
9 changed files with 145 additions and 0 deletions
@@ -73,6 +73,7 @@ import org.jetbrains.kotlin.idea.decompiler.textBuilder.AbstractCommonDecompiled
import org.jetbrains.kotlin.idea.decompiler.textBuilder.AbstractCommonDecompiledTextTest
import org.jetbrains.kotlin.idea.decompiler.textBuilder.AbstractJsDecompiledTextFromJsMetadataTest
import org.jetbrains.kotlin.idea.decompiler.textBuilder.AbstractJvmDecompiledTextTest
import org.jetbrains.kotlin.idea.editor.backspaceHandler.AbstractBackspaceHandlerTest
import org.jetbrains.kotlin.idea.editor.quickDoc.AbstractQuickDocProviderTest
import org.jetbrains.kotlin.idea.filters.AbstractKotlinExceptionFilterTest
import org.jetbrains.kotlin.idea.folding.AbstractKotlinFoldingTest
@@ -500,6 +501,10 @@ fun main(args: Array<String>) {
model("codeInsight/unwrapAndRemove/unwrapLambda", testMethod = "doTestLambdaUnwrapper")
}
testClass<AbstractBackspaceHandlerTest>() {
model("editor/backspaceHandler")
}
testClass<AbstractQuickDocProviderTest>() {
model("editor/quickDoc", pattern = """^([^_]+)\.[^\.]*$""")
}
+1
View File
@@ -455,6 +455,7 @@
id="KotlinEnterHandler" order="before EnterBetweenBracesHandler"/>
<lang.smartEnterProcessor language="kotlin" implementationClass="org.jetbrains.kotlin.idea.editor.KotlinSmartEnterHandler"/>
<backspaceHandlerDelegate implementation="org.jetbrains.kotlin.idea.editor.KotlinBackspaceHandler"/>
<backspaceHandlerDelegate implementation="org.jetbrains.kotlin.idea.editor.KotlinStringTemplateBackspaceHandler"/>
<copyPastePostProcessor implementation="org.jetbrains.kotlin.idea.conversion.copy.ConvertJavaCopyPastePostProcessor"/>
<copyPastePostProcessor implementation="org.jetbrains.kotlin.idea.codeInsight.KotlinCopyPasteReferenceProcessor"/>
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.editor
import com.intellij.codeInsight.CodeInsightSettings
import com.intellij.codeInsight.editorActions.BackspaceHandlerDelegate
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.editor.ex.EditorEx
import com.intellij.psi.PsiFile
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtFile
class KotlinStringTemplateBackspaceHandler : BackspaceHandlerDelegate() {
override fun beforeCharDeleted(c: Char, file: PsiFile?, editor: Editor?) {
if (c != '{' || file !is KtFile || !CodeInsightSettings.getInstance().AUTOINSERT_PAIR_BRACKET) return
val offset = editor?.caretModel?.offset ?: return
val highlighter = (editor as EditorEx).highlighter
val iterator = highlighter.createIterator(offset)
if (iterator.tokenType != KtTokens.LONG_TEMPLATE_ENTRY_END) return
iterator.retreat()
if (iterator.tokenType != KtTokens.LONG_TEMPLATE_ENTRY_START) return
editor.document.deleteString(offset, offset + 1)
}
override fun charDeleted(c: Char, file: PsiFile?, editor: Editor?): Boolean {
return false
}
}
@@ -0,0 +1 @@
"\${<caret>}"
@@ -0,0 +1 @@
"\$<caret>}"
@@ -0,0 +1 @@
"${<caret>}"
@@ -0,0 +1 @@
"$<caret>"
@@ -0,0 +1,33 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.editor.backspaceHandler
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.openapi.util.io.FileUtil
import com.intellij.testFramework.EditorTestUtil
import com.intellij.testFramework.LightCodeInsightTestCase
import java.io.File
open class AbstractBackspaceHandlerTest : LightCodeInsightTestCase() {
fun doTest(path: String) {
configureFromFileText("a.kt", loadFile(path))
EditorTestUtil.executeAction(getEditor(), IdeActions.ACTION_EDITOR_BACKSPACE)
checkResultByText(loadFile(path + ".after"))
}
private fun loadFile(path: String) = FileUtil.loadFile(File(path), true)
}
@@ -0,0 +1,58 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.idea.editor.backspaceHandler;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/editor/backspaceHandler")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class BackspaceHandlerTestGenerated extends AbstractBackspaceHandlerTest {
public void testAllFilesPresentInBackspaceHandler() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/editor/backspaceHandler"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("idea/testData/editor/backspaceHandler/stringTemplate")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class StringTemplate extends AbstractBackspaceHandlerTest {
public void testAllFilesPresentInStringTemplate() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/editor/backspaceHandler/stringTemplate"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("escapedStringTemplate.kt")
public void testEscapedStringTemplate() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/backspaceHandler/stringTemplate/escapedStringTemplate.kt");
doTest(fileName);
}
@TestMetadata("stringTemplateBrackets.kt")
public void testStringTemplateBrackets() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/editor/backspaceHandler/stringTemplate/stringTemplateBrackets.kt");
doTest(fileName);
}
}
}