#KT-5728 Fixed

This commit is contained in:
Anton Sukhonosenko
2016-02-25 10:00:04 +03:00
parent 029b918ec9
commit 31fea1d2b7
9 changed files with 137 additions and 11 deletions
+1
View File
@@ -458,6 +458,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,40 @@
/*
* 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.openapi.util.io.FileUtil;
import com.intellij.testFramework.EditorTestUtil;
import com.intellij.testFramework.LightCodeInsightTestCase;
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase;
import java.io.File;
public abstract class AbstractEditorTest extends LightCodeInsightTestCase {
protected abstract String getBasePath();
protected String loadFile(String name) throws Exception {
return FileUtil.loadFile(new File(getBasePath(), name), true);
}
protected void configure() throws Exception {
configureFromFileText("a.kt", loadFile(getTestName(true) + ".kt"));
}
protected void check() throws Exception {
checkResultByText(loadFile(getTestName(true) + "_after.kt"));
}
}
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.idea.test.PluginTestCaseBase;
import java.io.File;
public class KotlinCommenterTest extends LightCodeInsightTestCase {
public class KotlinCommenterTest extends AbstractEditorTest {
private static final String BASE_PATH =
new File(PluginTestCaseBase.getTestDataPathBase(), "/editor/commenter/").getAbsolutePath();
@@ -45,15 +45,8 @@ public class KotlinCommenterTest extends LightCodeInsightTestCase {
check();
}
private void configure() throws Exception {
configureFromFileText("a.kt", loadFile(getTestName(true) + ".kt"));
}
private void check() throws Exception {
checkResultByText(loadFile(getTestName(true) + "_after.kt"));
}
protected static String loadFile(String name) throws Exception {
return FileUtil.loadFile(new File(BASE_PATH, name), true);
@Override
protected String getBasePath() {
return BASE_PATH;
}
}
@@ -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.openapi.actionSystem.IdeActions
import com.intellij.testFramework.EditorTestUtil
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import java.io.File
class StringTemplateBackspaceHandlerTest : AbstractEditorTest() {
val path = File(PluginTestCaseBase.getTestDataPathBase(), "/editor/stringTemplateBackspaceHandler/").getAbsolutePath()
override fun getBasePath(): String? {
return path
}
fun testStringTemplateBrackets() {
doTest()
}
fun testEscapedStringTemplate() {
doTest()
}
fun doTest() {
configure()
EditorTestUtil.executeAction(getEditor(), IdeActions.ACTION_EDITOR_BACKSPACE)
check()
}
}