Add TypeBinding.
This commit is contained in:
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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.types
|
||||
|
||||
import org.jetbrains.jet.JetLiteFixture
|
||||
import org.jetbrains.jet.ConfigurationKind
|
||||
import org.jetbrains.jet.JetTestUtils
|
||||
import java.io.File
|
||||
import org.junit.Assert.*
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext
|
||||
import org.jetbrains.jet.lang.resolve.typeBinding.*
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.lazy.JvmResolveUtil
|
||||
import org.jetbrains.jet.lang.psi.JetCallableDeclaration
|
||||
import org.jetbrains.jet.utils.Printer
|
||||
import org.jetbrains.jet.test.util.trimIndent
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import org.jetbrains.jet.JetTestUtils.*
|
||||
import org.jetbrains.jet.lang.psi.JetVariableDeclaration
|
||||
|
||||
abstract class AbstractJetTypeBindingTest : JetLiteFixture() {
|
||||
override fun createEnvironment() = createEnvironmentWithMockJdk(ConfigurationKind.ALL)
|
||||
|
||||
protected fun doTest(path: String) {
|
||||
val testFile = File(path)
|
||||
val testKtFile = JetTestUtils.loadJetFile(getProject(), testFile)
|
||||
|
||||
val analyzeResult = JvmResolveUtil.analyzeFilesWithJavaIntegration(getProject(), listOf(testKtFile), { true })
|
||||
|
||||
val testDeclaration = testKtFile.getDeclarations().last!! as JetCallableDeclaration
|
||||
|
||||
val typeBinding = testDeclaration.createTypeBindingForReturnType(analyzeResult.bindingContext)
|
||||
|
||||
JetTestUtils.assertEqualsToFile(
|
||||
testFile,
|
||||
StringBuilder {
|
||||
append(removeLastComment(testKtFile))
|
||||
append("/*\n")
|
||||
|
||||
MyPrinter(this).print(typeBinding)
|
||||
|
||||
append("*/")
|
||||
}.toString()
|
||||
)
|
||||
}
|
||||
|
||||
private fun removeLastComment(file: JetFile): String {
|
||||
val fileText = file.getText()
|
||||
val lastIndex = fileText.indexOf("/*")
|
||||
return if (lastIndex > 0) {
|
||||
fileText.substring(0, lastIndex)
|
||||
}
|
||||
else fileText
|
||||
}
|
||||
|
||||
private class MyPrinter(out: StringBuilder) : Printer(out) {
|
||||
private fun JetType.render() = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(this)
|
||||
private fun TypeParameterDescriptor?.render() = if (this == null) "null" else DescriptorRenderer.SHORT_NAMES_IN_TYPES.render(this)
|
||||
|
||||
fun print(argument: TypeArgumentBinding<*>?): MyPrinter {
|
||||
if (argument == null) {
|
||||
println("null")
|
||||
return this
|
||||
}
|
||||
println("typeParameter: ${argument.typeParameterDescriptor.render()}")
|
||||
|
||||
val projection = argument.typeProjection.getProjectionKind().toString().let {
|
||||
if (it.isNotEmpty())
|
||||
"$it "
|
||||
else
|
||||
""
|
||||
}
|
||||
|
||||
println("typeProjection: ${projection}${argument.typeProjection.getType().render()}")
|
||||
print(argument.typeBinding)
|
||||
return this
|
||||
}
|
||||
|
||||
fun print(binding: TypeBinding<*>?): MyPrinter {
|
||||
if (binding == null) {
|
||||
println("null")
|
||||
return this
|
||||
}
|
||||
|
||||
println("psi: ${binding.psiElement.getText()}")
|
||||
println("type: ${binding.jetType.render()}")
|
||||
|
||||
printCollection(binding.getArgumentBindings()) {
|
||||
print(it)
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
private fun <T> printCollection(list: Iterable<T>, f: MyPrinter.(T) -> Unit) {
|
||||
pushIndent()
|
||||
var first = true
|
||||
for (element in list) {
|
||||
if (first) first = false
|
||||
else println()
|
||||
|
||||
f(element)
|
||||
}
|
||||
popIndent()
|
||||
}
|
||||
|
||||
override fun toString(): String = out.toString()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,273 @@
|
||||
/*
|
||||
* 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.types;
|
||||
|
||||
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("compiler/testData/type/binding")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@InnerTestClasses({JetTypeBindingTestGenerated.Explicit.class, JetTypeBindingTestGenerated.Implicit.class})
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class JetTypeBindingTestGenerated extends AbstractJetTypeBindingTest {
|
||||
public void testAllFilesPresentInBinding() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/type/binding"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/type/binding/explicit")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Explicit extends AbstractJetTypeBindingTest {
|
||||
public void testAllFilesPresentInExplicit() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/type/binding/explicit"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("conflictingProjection.kt")
|
||||
public void testConflictingProjection() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/conflictingProjection.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("conflictingProjection2.kt")
|
||||
public void testConflictingProjection2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/conflictingProjection2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("errorPair.kt")
|
||||
public void testErrorPair() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/errorPair.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("errorWithProjection.kt")
|
||||
public void testErrorWithProjection() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/errorWithProjection.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionType.kt")
|
||||
public void testFunctionType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/functionType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionType2.kt")
|
||||
public void testFunctionType2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/functionType2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionType3.kt")
|
||||
public void testFunctionType3() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/functionType3.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inProjection.kt")
|
||||
public void testInProjection() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/inProjection.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("int.kt")
|
||||
public void testInt() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/int.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("list0.kt")
|
||||
public void testList0() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/list0.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("list2.kt")
|
||||
public void testList2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/list2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nullableType.kt")
|
||||
public void testNullableType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/nullableType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("outProjection.kt")
|
||||
public void testOutProjection() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/outProjection.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("pair.kt")
|
||||
public void testPair() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/pair.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/simple.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("star.kt")
|
||||
public void testStar() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/star.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeWithBracket.kt")
|
||||
public void testTypeWithBracket() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/typeWithBracket.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unresolvedType.kt")
|
||||
public void testUnresolvedType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/explicit/unresolvedType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/type/binding/implicit")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Implicit extends AbstractJetTypeBindingTest {
|
||||
public void testAllFilesPresentInImplicit() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/type/binding/implicit"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("conflictingProjection.kt")
|
||||
public void testConflictingProjection() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/conflictingProjection.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("conflictingProjection2.kt")
|
||||
public void testConflictingProjection2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/conflictingProjection2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("errorPair.kt")
|
||||
public void testErrorPair() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/errorPair.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("errorWithProjection.kt")
|
||||
public void testErrorWithProjection() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/errorWithProjection.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionType.kt")
|
||||
public void testFunctionType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/functionType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionType2.kt")
|
||||
public void testFunctionType2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/functionType2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("functionType3.kt")
|
||||
public void testFunctionType3() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/functionType3.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inProjection.kt")
|
||||
public void testInProjection() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/inProjection.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("int.kt")
|
||||
public void testInt() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/int.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("list0.kt")
|
||||
public void testList0() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/list0.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("list2.kt")
|
||||
public void testList2() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/list2.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nullableType.kt")
|
||||
public void testNullableType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/nullableType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("outProjection.kt")
|
||||
public void testOutProjection() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/outProjection.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("pair.kt")
|
||||
public void testPair() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/pair.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/simple.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("star.kt")
|
||||
public void testStar() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/star.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeWithBracket.kt")
|
||||
public void testTypeWithBracket() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/typeWithBracket.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unresolvedType.kt")
|
||||
public void testUnresolvedType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/type/binding/implicit/unresolvedType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user