Add test for completion with runtime type cast
This commit is contained in:
@@ -134,6 +134,7 @@ import org.jetbrains.jet.completion.handlers.AbstractCompletionCharFilterTest
|
||||
import org.jetbrains.jet.resolve.AbstractPartialBodyResolveTest
|
||||
import org.jetbrains.jet.checkers.AbstractJetDiagnosticsTestWithJsStdLib
|
||||
import org.jetbrains.jet.types.AbstractJetTypeBindingTest
|
||||
import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentCompletionHandlerTest
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
System.setProperty("java.awt.headless", "true")
|
||||
@@ -377,6 +378,10 @@ fun main(args: Array<String>) {
|
||||
model("completion/handlers/charFilter")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractCodeFragmentCompletionHandlerTest>()) {
|
||||
model("completion/handlers/runtimeCast")
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractCodeFragmentCompletionTest>()) {
|
||||
model("completion/basic/codeFragments", extension = "kt")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
fun main(args: Array<String>) {
|
||||
val b: Base<String> = Derived()
|
||||
<caret>val a = 1
|
||||
}
|
||||
|
||||
open class Base<T> {
|
||||
fun funInBase(t: T): T { return t }
|
||||
|
||||
open fun funWithOverride(t: T): T { return t }
|
||||
open fun funWithoutOverride(t: T): T { return t }
|
||||
}
|
||||
|
||||
class Derived: Base<String>() {
|
||||
override fun funWithOverride(t: String): String { return "a" }
|
||||
}
|
||||
|
||||
// INVOCATION_COUNT: 1
|
||||
// EXIST: funInBase, funWithOverride, funWithoutOverride
|
||||
// NUMBER: 3
|
||||
|
||||
// RUNTIME_TYPE: Derived
|
||||
@@ -0,0 +1 @@
|
||||
b.fun<caret>
|
||||
@@ -0,0 +1,25 @@
|
||||
fun main(args: Array<String>) {
|
||||
val b: A = C()
|
||||
<caret>val a = 1
|
||||
}
|
||||
|
||||
open class A {
|
||||
fun funA() {}
|
||||
private fun funAp() {}
|
||||
}
|
||||
|
||||
open class B: A() {
|
||||
fun funB() {}
|
||||
private fun funBp() {}
|
||||
}
|
||||
|
||||
class C: B() {
|
||||
fun funC() {}
|
||||
private fun funCp() {}
|
||||
}
|
||||
|
||||
// INVOCATION_COUNT: 2
|
||||
// EXIST: funA, funAp, funB, funBp, funC, funCp
|
||||
// NUMBER: 6
|
||||
|
||||
// RUNTIME_TYPE: C
|
||||
@@ -0,0 +1 @@
|
||||
b.fun<caret>
|
||||
@@ -0,0 +1,20 @@
|
||||
fun main(args: Array<String>) {
|
||||
val b: Base = Derived()
|
||||
<caret>val a = 1
|
||||
}
|
||||
|
||||
open class Base {
|
||||
}
|
||||
|
||||
class Derived: Base() {
|
||||
}
|
||||
|
||||
fun Derived.funExtDerived() { }
|
||||
fun Base.funExtBase() { }
|
||||
|
||||
// INVOCATION_COUNT: 1
|
||||
// EXIST: funExtBase, funExtDerived
|
||||
// NUMBER: 2
|
||||
|
||||
|
||||
// RUNTIME_TYPE: Derived
|
||||
@@ -0,0 +1 @@
|
||||
b.fun<caret>
|
||||
@@ -0,0 +1,24 @@
|
||||
fun main(args: Array<String>) {
|
||||
val b: Base = Derived()
|
||||
<caret>val a = 1
|
||||
}
|
||||
|
||||
open class Base {
|
||||
fun funInBase() {}
|
||||
|
||||
open fun funWithOverride() { }
|
||||
open fun funWithoutOverride() { }
|
||||
}
|
||||
|
||||
class Derived: Base() {
|
||||
fun funInDerived() { }
|
||||
|
||||
override fun funWithOverride() { }
|
||||
}
|
||||
|
||||
// INVOCATION_COUNT: 1
|
||||
// EXIST: funInBase, funWithOverride, funWithoutOverride, funInDerived
|
||||
// NUMBER: 4
|
||||
|
||||
|
||||
// RUNTIME_TYPE: Derived
|
||||
@@ -0,0 +1 @@
|
||||
b.fun<caret>
|
||||
@@ -0,0 +1,14 @@
|
||||
fun main(args: Array<String>) {
|
||||
val b: A = C()
|
||||
<caret>val a = 1
|
||||
}
|
||||
|
||||
open class A
|
||||
open class B {
|
||||
private fun funInB() {}
|
||||
}
|
||||
|
||||
class C: B()
|
||||
|
||||
// INVOCATION_COUNT: 2
|
||||
// RUNTIME_TYPE: C
|
||||
@@ -0,0 +1 @@
|
||||
(b as B).funInB()
|
||||
@@ -0,0 +1 @@
|
||||
b.funIn<caret>
|
||||
@@ -0,0 +1,12 @@
|
||||
fun main(args: Array<String>) {
|
||||
val b: Base = Derived()
|
||||
<caret>val a = 1
|
||||
}
|
||||
|
||||
open class Base
|
||||
|
||||
class Derived: Base()
|
||||
|
||||
fun Derived.funInDerived() { }
|
||||
|
||||
// RUNTIME_TYPE: Derived
|
||||
@@ -0,0 +1 @@
|
||||
(b as Derived).funInDerived()
|
||||
@@ -0,0 +1 @@
|
||||
b.funIn<caret>
|
||||
@@ -0,0 +1,12 @@
|
||||
fun main(args: Array<String>) {
|
||||
val b: Base = Derived()
|
||||
<caret>val a = 1
|
||||
}
|
||||
|
||||
open class Base
|
||||
|
||||
class Derived: Base() {
|
||||
fun funInDerived() { }
|
||||
}
|
||||
|
||||
// RUNTIME_TYPE: Derived
|
||||
@@ -0,0 +1 @@
|
||||
(b as Derived).funInDerived()
|
||||
@@ -0,0 +1 @@
|
||||
b.funIn<caret>
|
||||
@@ -123,6 +123,8 @@ public class ExpectedCompletionUtils {
|
||||
private static final String WITH_ORDER_PREFIX = "WITH_ORDER:";
|
||||
private static final String AUTOCOMPLETE_SETTING_PREFIX = "AUTOCOMPLETE_SETTING:";
|
||||
|
||||
public static final String RUNTIME_TYPE = "RUNTIME_TYPE:";
|
||||
|
||||
public static final List<String> KNOWN_PREFIXES = ImmutableList.of(
|
||||
EXIST_LINE_PREFIX,
|
||||
ABSENT_LINE_PREFIX,
|
||||
@@ -136,6 +138,7 @@ public class ExpectedCompletionUtils {
|
||||
INVOCATION_COUNT_PREFIX,
|
||||
WITH_ORDER_PREFIX,
|
||||
AUTOCOMPLETE_SETTING_PREFIX,
|
||||
RUNTIME_TYPE,
|
||||
AstAccessControl.INSTANCE$.getALLOW_AST_ACCESS_DIRECTIVE());
|
||||
|
||||
@NotNull
|
||||
|
||||
+8
-2
@@ -18,6 +18,8 @@ package org.jetbrains.jet.completion.handlers
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import org.jetbrains.jet.InTextDirectivesUtils
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import java.io.File
|
||||
|
||||
public abstract class AbstractCompletionHandlerTest() : CompletionHandlerTestBase() {
|
||||
private val INVOCATION_COUNT_PREFIX = "INVOCATION_COUNT:"
|
||||
@@ -28,9 +30,9 @@ public abstract class AbstractCompletionHandlerTest() : CompletionHandlerTestBas
|
||||
private val COMPLETION_TYPE_PREFIX = "COMPLETION_TYPE:"
|
||||
|
||||
protected fun doTest(testPath: String) {
|
||||
fixture.configureByFile(testPath)
|
||||
setUpFixture(testPath)
|
||||
|
||||
val fileText = fixture.getFile()!!.getText()
|
||||
val fileText = FileUtil.loadFile(File(testPath))
|
||||
val invocationCount = InTextDirectivesUtils.getPrefixedInt(fileText, INVOCATION_COUNT_PREFIX) ?: 1
|
||||
val lookupString = InTextDirectivesUtils.findStringWithPrefixes(fileText, LOOKUP_STRING_PREFIX)
|
||||
val itemText = InTextDirectivesUtils.findStringWithPrefixes(fileText, ELEMENT_TEXT_PREFIX)
|
||||
@@ -54,6 +56,10 @@ public abstract class AbstractCompletionHandlerTest() : CompletionHandlerTestBas
|
||||
doTestWithTextLoaded(completionType, invocationCount, lookupString, itemText, tailText, completionChar)
|
||||
}
|
||||
|
||||
protected open fun setUpFixture(testPath: String) {
|
||||
fixture.configureByFile(testPath)
|
||||
}
|
||||
|
||||
protected abstract val defaultCompletionType: CompletionType
|
||||
}
|
||||
|
||||
|
||||
+28
@@ -29,6 +29,15 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import org.jetbrains.jet.InTextDirectivesUtils
|
||||
import org.jetbrains.jet.lang.psi.JetCodeFragment
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyzeFully
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.completion.ExpectedCompletionUtils
|
||||
import org.jetbrains.jet.lang.psi.JetElement
|
||||
import org.jetbrains.jet.completion.handlers.AbstractCompletionHandlerTest
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import org.jetbrains.jet.JetTestUtils
|
||||
|
||||
public abstract class AbstractCodeFragmentHighlightingTest : AbstractJetPsiCheckerTest() {
|
||||
override fun doTest(filePath: String) {
|
||||
@@ -56,12 +65,31 @@ public abstract class AbstractCodeFragmentCompletionTest : AbstractJvmBasicCompl
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class AbstractCodeFragmentCompletionHandlerTest : AbstractCompletionHandlerTest() {
|
||||
override fun setUpFixture(testPath: String) {
|
||||
myFixture.configureByCodeFragment(testPath)
|
||||
}
|
||||
|
||||
override val testDataRelativePath: String = "/completion/handlers/runtimeCast/"
|
||||
override val defaultCompletionType: CompletionType = CompletionType.BASIC
|
||||
}
|
||||
|
||||
private fun JavaCodeInsightTestFixture.configureByCodeFragment(filePath: String) {
|
||||
configureByFile(filePath)
|
||||
|
||||
val elementAt = getFile()?.findElementAt(getCaretOffset())
|
||||
val file = createCodeFragment(filePath, elementAt!!)
|
||||
|
||||
val typeStr = InTextDirectivesUtils.findStringWithPrefixes(getFile().getText(), "// ${ExpectedCompletionUtils.RUNTIME_TYPE} ")
|
||||
if (typeStr != null) {
|
||||
file.putCopyableUserData(JetCodeFragment.RUNTIME_TYPE_EVALUATOR, {
|
||||
val codeFragment = JetPsiFactory(getProject()).createBlockCodeFragment("val xxx: $typeStr" , PsiTreeUtil.getParentOfType(elementAt, javaClass<JetElement>()))
|
||||
val context = codeFragment.analyzeFully()
|
||||
val typeReference: JetTypeReference = PsiTreeUtil.getChildOfType(codeFragment.getContentElement().getFirstChild(), javaClass())
|
||||
context[BindingContext.TYPE, typeReference]
|
||||
})
|
||||
}
|
||||
|
||||
configureFromExistingVirtualFile(file.getVirtualFile()!!)
|
||||
}
|
||||
|
||||
|
||||
+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.plugin.debugger.evaluate;
|
||||
|
||||
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/runtimeCast")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class CodeFragmentCompletionHandlerTestGenerated extends AbstractCodeFragmentCompletionHandlerTest {
|
||||
public void testAllFilesPresentInRuntimeCast() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/completion/handlers/runtimeCast"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("CastPrivateFun.kt")
|
||||
public void testCastPrivateFun() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/runtimeCast/CastPrivateFun.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("InsertExtFunction.kt")
|
||||
public void testInsertExtFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/runtimeCast/InsertExtFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("InsertFunction.kt")
|
||||
public void testInsertFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/handlers/runtimeCast/InsertFunction.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
+34
@@ -30,6 +30,7 @@ import java.util.regex.Pattern;
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/completion/basic/codeFragments")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@InnerTestClasses({CodeFragmentCompletionTestGenerated.RuntimeType.class})
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class CodeFragmentCompletionTestGenerated extends AbstractCodeFragmentCompletionTest {
|
||||
public void testAllFilesPresentInCodeFragments() throws Exception {
|
||||
@@ -59,4 +60,37 @@ public class CodeFragmentCompletionTestGenerated extends AbstractCodeFragmentCom
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/codeFragments/topLevel.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/completion/basic/codeFragments/runtimeType")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class RuntimeType extends AbstractCodeFragmentCompletionTest {
|
||||
public void testAllFilesPresentInRuntimeType() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/completion/basic/codeFragments/runtimeType"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("castWithGenerics.kt")
|
||||
public void testCastWithGenerics() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/codeFragments/runtimeType/castWithGenerics.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("complexHierarchy.kt")
|
||||
public void testComplexHierarchy() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/codeFragments/runtimeType/complexHierarchy.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("extensionMethod.kt")
|
||||
public void testExtensionMethod() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/codeFragments/runtimeType/extensionMethod.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("runtimeCast.kt")
|
||||
public void testRuntimeCast() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/codeFragments/runtimeType/runtimeCast.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user