diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index a4479386895..8c30f1bd991 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -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) { System.setProperty("java.awt.headless", "true") @@ -367,6 +368,10 @@ fun main(args: Array) { model("completion/basic/custom", recursive = false) } + testClass(javaClass()) { + model("completion/handlers/basic") + } + testClass(javaClass()) { model("completion/handlers/smart") } diff --git a/idea/src/org/jetbrains/jet/plugin/completion/handlers/KotlinClassInsertHandler.kt b/idea/src/org/jetbrains/jet/plugin/completion/handlers/KotlinClassInsertHandler.kt index 197ed9d6a56..cd96560af49 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/handlers/KotlinClassInsertHandler.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/handlers/KotlinClassInsertHandler.kt @@ -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()) } } } diff --git a/idea/testData/completion/handlers/basic/ExtensionReceiverTypeArg.kt b/idea/testData/completion/handlers/basic/ExtensionReceiverTypeArg.kt new file mode 100644 index 00000000000..c6f11b638ae --- /dev/null +++ b/idea/testData/completion/handlers/basic/ExtensionReceiverTypeArg.kt @@ -0,0 +1,4 @@ +fun List>foo() {} + +// ELEMENT: String +// TAIL_TEXT: "(kotlin)" diff --git a/idea/testData/completion/handlers/basic/ExtensionReceiverTypeArg.kt.after b/idea/testData/completion/handlers/basic/ExtensionReceiverTypeArg.kt.after new file mode 100644 index 00000000000..a91bb293cb4 --- /dev/null +++ b/idea/testData/completion/handlers/basic/ExtensionReceiverTypeArg.kt.after @@ -0,0 +1,4 @@ +fun List>foo() {} + +// ELEMENT: String +// TAIL_TEXT: "(kotlin)" diff --git a/idea/testData/completion/handlers/basic/SecondTypeArg.kt b/idea/testData/completion/handlers/basic/SecondTypeArg.kt new file mode 100644 index 00000000000..40a02b884a7 --- /dev/null +++ b/idea/testData/completion/handlers/basic/SecondTypeArg.kt @@ -0,0 +1,8 @@ +import java.util.HashMap + +fun foo() { + val v = HashMap +} + +// INVOCATION_COUNT: 2 +// ELEMENT: HashSet \ No newline at end of file diff --git a/idea/testData/completion/handlers/basic/SecondTypeArg.kt.after b/idea/testData/completion/handlers/basic/SecondTypeArg.kt.after new file mode 100644 index 00000000000..b1a375b1f3f --- /dev/null +++ b/idea/testData/completion/handlers/basic/SecondTypeArg.kt.after @@ -0,0 +1,9 @@ +import java.util.HashMap +import java.util.HashSet + +fun foo() { + val v = HashMap +} + +// INVOCATION_COUNT: 2 +// ELEMENT: HashSet \ No newline at end of file diff --git a/idea/testData/completion/handlers/basic/SuperTypeArg.kt b/idea/testData/completion/handlers/basic/SuperTypeArg.kt new file mode 100644 index 00000000000..1a1cddd10a0 --- /dev/null +++ b/idea/testData/completion/handlers/basic/SuperTypeArg.kt @@ -0,0 +1,8 @@ +class C : java.io.BufferedReader() { + override fun hashCode(): Int { + super + } +} + +// INVOCATION_COUNT: 2 +// ELEMENT: BufferedReader diff --git a/idea/testData/completion/handlers/basic/SuperTypeArg.kt.after b/idea/testData/completion/handlers/basic/SuperTypeArg.kt.after new file mode 100644 index 00000000000..693420cec5f --- /dev/null +++ b/idea/testData/completion/handlers/basic/SuperTypeArg.kt.after @@ -0,0 +1,10 @@ +import java.io.BufferedReader + +class C : java.io.BufferedReader() { + override fun hashCode(): Int { + super + } +} + +// INVOCATION_COUNT: 2 +// ELEMENT: BufferedReader diff --git a/idea/tests/org/jetbrains/jet/completion/handlers/AbstractSmartCompletionHandlerTest.kt b/idea/tests/org/jetbrains/jet/completion/handlers/AbstractCompletionHandlerTests.kt similarity index 92% rename from idea/tests/org/jetbrains/jet/completion/handlers/AbstractSmartCompletionHandlerTest.kt rename to idea/tests/org/jetbrains/jet/completion/handlers/AbstractCompletionHandlerTests.kt index 48915e3cb90..f0908991269 100644 --- a/idea/tests/org/jetbrains/jet/completion/handlers/AbstractSmartCompletionHandlerTest.kt +++ b/idea/tests/org/jetbrains/jet/completion/handlers/AbstractCompletionHandlerTests.kt @@ -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" diff --git a/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTest.kt b/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTest.kt index c95d37c6458..f2dfaeb3ec7 100644 --- a/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTest.kt +++ b/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTest.kt @@ -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" diff --git a/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTestGenerated.java new file mode 100644 index 00000000000..03970129730 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/completion/handlers/BasicCompletionHandlerTestGenerated.java @@ -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); + } +}