Fixed occasional insertions of fq-names by completion and similar effects
#KT-6182 Fixed #KT-6111 Fixed
This commit is contained in:
@@ -137,6 +137,7 @@ import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentCompletion
|
||||
import org.jetbrains.jet.plugin.coverage.AbstractKotlinCoverageOutputFilesTest
|
||||
import org.jetbrains.k2js.test.semantics.AbstractDynamicTest
|
||||
import org.jetbrains.k2js.test.semantics.AbstractMultiModuleTest
|
||||
import org.jetbrains.jet.completion.handlers.AbstractBasicCompletionHandlerTest
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
System.setProperty("java.awt.headless", "true")
|
||||
@@ -367,6 +368,10 @@ fun main(args: Array<String>) {
|
||||
model("completion/basic/custom", recursive = false)
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractBasicCompletionHandlerTest>()) {
|
||||
model("completion/handlers/basic")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractSmartCompletionHandlerTest>()) {
|
||||
model("completion/handlers/smart")
|
||||
}
|
||||
|
||||
@@ -37,21 +37,27 @@ public object KotlinClassInsertHandler : BaseDeclarationInsertHandler() {
|
||||
val document = context.getDocument()
|
||||
if (!isAfterDot(document, startOffset)) {
|
||||
val qualifiedName = qualifiedNameToInsert(item)
|
||||
// insert dot after because otherwise parser can sometimes produce no suitable reference here
|
||||
|
||||
// we need to insert prefix&suffix otherwise parser can sometimes produce no suitable reference here
|
||||
val tempPrefix = "$;val v:"
|
||||
val tempSuffix = ".xxx" // we add "xxx" after dot because of some bugs in resolve (see KT-5145)
|
||||
document.replaceString(startOffset, context.getTailOffset(), qualifiedName + tempSuffix)
|
||||
val classNameEnd = startOffset + qualifiedName.length()
|
||||
document.replaceString(startOffset, context.getTailOffset(), tempPrefix + qualifiedName + tempSuffix)
|
||||
|
||||
val psiDocumentManager = PsiDocumentManager.getInstance(context.getProject())
|
||||
psiDocumentManager.commitAllDocuments()
|
||||
val rangeMarker = document.createRangeMarker(classNameEnd, classNameEnd + tempSuffix.length())
|
||||
|
||||
ShortenReferences.process(file, startOffset, classNameEnd)
|
||||
val classNameStart = startOffset + tempPrefix.length()
|
||||
val classNameEnd = classNameStart + qualifiedName.length()
|
||||
val rangeMarker = document.createRangeMarker(classNameStart, classNameEnd)
|
||||
val wholeRangeMarker = document.createRangeMarker(startOffset, classNameEnd + tempSuffix.length())
|
||||
|
||||
ShortenReferences.process(file, classNameStart, classNameEnd)
|
||||
psiDocumentManager.commitAllDocuments()
|
||||
psiDocumentManager.doPostponedOperationsAndUnblockDocument(document)
|
||||
|
||||
if (rangeMarker.isValid()) {
|
||||
document.deleteString(rangeMarker.getStartOffset(), rangeMarker.getEndOffset())
|
||||
if (rangeMarker.isValid() && wholeRangeMarker.isValid()) {
|
||||
document.deleteString(wholeRangeMarker.getStartOffset(), rangeMarker.getStartOffset())
|
||||
document.deleteString(rangeMarker.getEndOffset(), wholeRangeMarker.getEndOffset())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
fun List<S<caret>>foo() {}
|
||||
|
||||
// ELEMENT: String
|
||||
// TAIL_TEXT: "(kotlin)"
|
||||
@@ -0,0 +1,4 @@
|
||||
fun List<String<caret>>foo() {}
|
||||
|
||||
// ELEMENT: String
|
||||
// TAIL_TEXT: "(kotlin)"
|
||||
@@ -0,0 +1,8 @@
|
||||
import java.util.HashMap
|
||||
|
||||
fun foo() {
|
||||
val v = HashMap<String, <caret>
|
||||
}
|
||||
|
||||
// INVOCATION_COUNT: 2
|
||||
// ELEMENT: HashSet
|
||||
@@ -0,0 +1,9 @@
|
||||
import java.util.HashMap
|
||||
import java.util.HashSet
|
||||
|
||||
fun foo() {
|
||||
val v = HashMap<String, HashSet<caret>
|
||||
}
|
||||
|
||||
// INVOCATION_COUNT: 2
|
||||
// ELEMENT: HashSet
|
||||
@@ -0,0 +1,8 @@
|
||||
class C : java.io.BufferedReader() {
|
||||
override fun hashCode(): Int {
|
||||
super<Buf<caret>
|
||||
}
|
||||
}
|
||||
|
||||
// INVOCATION_COUNT: 2
|
||||
// ELEMENT: BufferedReader
|
||||
@@ -0,0 +1,10 @@
|
||||
import java.io.BufferedReader
|
||||
|
||||
class C : java.io.BufferedReader() {
|
||||
override fun hashCode(): Int {
|
||||
super<BufferedReader<caret>
|
||||
}
|
||||
}
|
||||
|
||||
// INVOCATION_COUNT: 2
|
||||
// ELEMENT: BufferedReader
|
||||
+5
@@ -63,6 +63,11 @@ public abstract class AbstractCompletionHandlerTest() : CompletionHandlerTestBas
|
||||
protected abstract val defaultCompletionType: CompletionType
|
||||
}
|
||||
|
||||
public abstract class AbstractBasicCompletionHandlerTest() : AbstractCompletionHandlerTest() {
|
||||
override val defaultCompletionType: CompletionType = CompletionType.BASIC
|
||||
override val testDataRelativePath: String = "/completion/handlers/basic"
|
||||
}
|
||||
|
||||
public abstract class AbstractSmartCompletionHandlerTest() : AbstractCompletionHandlerTest() {
|
||||
override val defaultCompletionType: CompletionType = CompletionType.SMART
|
||||
override val testDataRelativePath: String = "/completion/handlers/smart"
|
||||
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.completion.CompletionType
|
||||
import org.jetbrains.jet.plugin.formatter.JetCodeStyleSettings
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
|
||||
deprecated("All tests from here to be moved to the generated test")
|
||||
public class BasicCompletionHandlerTest : CompletionHandlerTestBase(){
|
||||
override val testDataRelativePath: String = "/completion/handlers"
|
||||
|
||||
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.jet.completion.handlers;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/completion/handlers/basic")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class BasicCompletionHandlerTestGenerated extends AbstractBasicCompletionHandlerTest {
|
||||
public void testAllFilesPresentInBasic() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/completion/handlers/basic"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("ExtensionReceiverTypeArg.kt")
|
||||
public void testExtensionReceiverTypeArg() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/basic/ExtensionReceiverTypeArg.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SecondTypeArg.kt")
|
||||
public void testSecondTypeArg() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/basic/SecondTypeArg.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("SuperTypeArg.kt")
|
||||
public void testSuperTypeArg() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/basic/SuperTypeArg.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user