compiler: cleanup 'public', property access syntax
This commit is contained in:
@@ -30,16 +30,16 @@ import org.jetbrains.kotlin.psi.*
|
||||
|
||||
class MutableDiagnosticsTest : KotlinTestWithEnvironment() {
|
||||
override fun createEnvironment(): KotlinCoreEnvironment? {
|
||||
return KotlinCoreEnvironment.createForTests(getTestRootDisposable()!!, CompilerConfiguration(), EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
return KotlinCoreEnvironment.createForTests(testRootDisposable!!, CompilerConfiguration(), EnvironmentConfigFiles.JVM_CONFIG_FILES)
|
||||
}
|
||||
|
||||
private val BindingTrace.diagnostics: Diagnostics
|
||||
get() = getBindingContext().getDiagnostics()
|
||||
get() = bindingContext.diagnostics
|
||||
|
||||
fun testPropagatingModification() {
|
||||
val base = BindingTraceContext()
|
||||
val middle = DelegatingBindingTrace(base.getBindingContext(), "middle")
|
||||
val derived = DelegatingBindingTrace(middle.getBindingContext(), "derived")
|
||||
val middle = DelegatingBindingTrace(base.bindingContext, "middle")
|
||||
val derived = DelegatingBindingTrace(middle.bindingContext, "derived")
|
||||
|
||||
Assert.assertTrue(base.diagnostics.isEmpty())
|
||||
Assert.assertTrue(middle.diagnostics.isEmpty())
|
||||
@@ -81,8 +81,8 @@ class MutableDiagnosticsTest : KotlinTestWithEnvironment() {
|
||||
|
||||
fun testCaching() {
|
||||
val base = BindingTraceContext()
|
||||
val middle = DelegatingBindingTrace(base.getBindingContext(), "middle")
|
||||
val derived = DelegatingBindingTrace(middle.getBindingContext(), "derived")
|
||||
val middle = DelegatingBindingTrace(base.bindingContext, "middle")
|
||||
val derived = DelegatingBindingTrace(middle.bindingContext, "derived")
|
||||
|
||||
base.reportDiagnostic()
|
||||
middle.reportDiagnostic()
|
||||
@@ -128,14 +128,14 @@ class MutableDiagnosticsTest : KotlinTestWithEnvironment() {
|
||||
|
||||
//NOTE: cannot simply call all() since it applies filter on every query and produces new collection
|
||||
private fun Diagnostics.contents(): MutableCollection<Diagnostic> {
|
||||
return (this as MutableDiagnosticsWithSuppression).getReadonlyView().getDiagnostics()
|
||||
return (this as MutableDiagnosticsWithSuppression).getReadonlyView().diagnostics
|
||||
}
|
||||
|
||||
private class DummyDiagnosticFactory : DiagnosticFactory<DummyDiagnostic>("DUMMY", Severity.ERROR)
|
||||
|
||||
private inner class DummyDiagnostic : Diagnostic {
|
||||
private val factory = DummyDiagnosticFactory()
|
||||
private val dummyElement = KtPsiFactory(getEnvironment().project).createType("Int")
|
||||
private val dummyElement = KtPsiFactory(environment.project).createType("Int")
|
||||
|
||||
init {
|
||||
dummyElement.getContainingKtFile().doNotAnalyze = null
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import java.io.File
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
|
||||
public abstract class AbstractAnnotationParameterTest : AbstractAnnotationDescriptorResolveTest() {
|
||||
abstract class AbstractAnnotationParameterTest : AbstractAnnotationDescriptorResolveTest() {
|
||||
fun doTest(path: String) {
|
||||
val fileText = FileUtil.loadFile(File(path), true)
|
||||
val packageView = getPackage(fileText)
|
||||
|
||||
@@ -41,19 +41,19 @@ import org.jetbrains.kotlin.psi.KtFile
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.*
|
||||
|
||||
public abstract class AbstractResolvedCallsTest : KotlinLiteFixture() {
|
||||
abstract class AbstractResolvedCallsTest : KotlinLiteFixture() {
|
||||
override fun createEnvironment(): KotlinCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.ALL)
|
||||
|
||||
public fun doTest(filePath: String) {
|
||||
fun doTest(filePath: String) {
|
||||
val text = KotlinTestUtils.doLoadFile(File(filePath))!!
|
||||
|
||||
val jetFile = KtPsiFactory(getProject()).createFile(text.replace("<caret>", ""))
|
||||
val jetFile = KtPsiFactory(project).createFile(text.replace("<caret>", ""))
|
||||
val bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegration(jetFile, environment).bindingContext
|
||||
|
||||
val (element, cachedCall) = buildCachedCall(bindingContext, jetFile, text)
|
||||
|
||||
val resolvedCall = if (cachedCall !is VariableAsFunctionResolvedCall) cachedCall
|
||||
else if ("(" == element?.getText()) cachedCall.functionCall
|
||||
else if ("(" == element?.text) cachedCall.functionCall
|
||||
else cachedCall.variableCall
|
||||
|
||||
val resolvedCallInfoFileName = FileUtil.getNameWithoutExtension(filePath) + ".txt"
|
||||
@@ -73,25 +73,25 @@ public abstract class AbstractResolvedCallsTest : KotlinLiteFixture() {
|
||||
}
|
||||
|
||||
private fun Receiver?.getText() = when (this) {
|
||||
is ExpressionReceiver -> "${expression.getText()} {${getType()}}"
|
||||
is ImplicitClassReceiver -> "Class{${getType()}}"
|
||||
is ExtensionReceiver -> "${getType()}Ext{${declarationDescriptor.getText()}}"
|
||||
is ExpressionReceiver -> "${expression.text} {${type}}"
|
||||
is ImplicitClassReceiver -> "Class{${type}}"
|
||||
is ExtensionReceiver -> "${type}Ext{${declarationDescriptor.getText()}}"
|
||||
null -> "NO_RECEIVER"
|
||||
else -> toString()
|
||||
}
|
||||
|
||||
private fun ValueArgument.getText() = this.getArgumentExpression()?.getText()?.replace("\n", " ") ?: ""
|
||||
private fun ValueArgument.getText() = this.getArgumentExpression()?.text?.replace("\n", " ") ?: ""
|
||||
|
||||
private fun ArgumentMapping.getText() = when (this) {
|
||||
is ArgumentMatch -> {
|
||||
val parameterType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(valueParameter.getType())
|
||||
"${status.name} ${valueParameter.getName()} : ${parameterType} ="
|
||||
val parameterType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(valueParameter.type)
|
||||
"${status.name} ${valueParameter.name} : ${parameterType} ="
|
||||
}
|
||||
else -> "ARGUMENT UNMAPPED: "
|
||||
}
|
||||
|
||||
private fun DeclarationDescriptor.getText(): String = when (this) {
|
||||
is ReceiverParameterDescriptor -> "${getValue().getText()}::this"
|
||||
is ReceiverParameterDescriptor -> "${value.getText()}::this"
|
||||
else -> DescriptorRenderer.COMPACT_WITH_SHORT_TYPES.render(this)
|
||||
}
|
||||
|
||||
@@ -100,17 +100,17 @@ private fun ResolvedCall<*>.renderToText(): String {
|
||||
appendln("Resolved call:")
|
||||
appendln()
|
||||
|
||||
if (getCandidateDescriptor() != getResultingDescriptor()) {
|
||||
appendln("Candidate descriptor: ${getCandidateDescriptor()!!.getText()}")
|
||||
if (candidateDescriptor != resultingDescriptor) {
|
||||
appendln("Candidate descriptor: ${candidateDescriptor!!.getText()}")
|
||||
}
|
||||
appendln("Resulting descriptor: ${getResultingDescriptor()!!.getText()}")
|
||||
appendln("Resulting descriptor: ${resultingDescriptor!!.getText()}")
|
||||
appendln()
|
||||
|
||||
appendln("Explicit receiver kind = ${getExplicitReceiverKind()}")
|
||||
appendln("Dispatch receiver = ${getDispatchReceiver().getText()}")
|
||||
appendln("Extension receiver = ${getExtensionReceiver().getText()}")
|
||||
appendln("Explicit receiver kind = ${explicitReceiverKind}")
|
||||
appendln("Dispatch receiver = ${dispatchReceiver.getText()}")
|
||||
appendln("Extension receiver = ${extensionReceiver.getText()}")
|
||||
|
||||
val valueArguments = getCall().getValueArguments()
|
||||
val valueArguments = call.valueArguments
|
||||
if (!valueArguments.isEmpty()) {
|
||||
appendln()
|
||||
appendln("Value arguments mapping:")
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.debugText.getDebugText
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getParentResolvedCall
|
||||
|
||||
|
||||
abstract public class AbstractResolvedConstructorDelegationCallsTests : AbstractResolvedCallsTest() {
|
||||
abstract class AbstractResolvedConstructorDelegationCallsTests : AbstractResolvedCallsTest() {
|
||||
override fun buildCachedCall(
|
||||
bindingContext: BindingContext, jetFile: KtFile, text: String
|
||||
): Pair<PsiElement?, ResolvedCall<out CallableDescriptor>?> {
|
||||
|
||||
+4
-4
@@ -31,13 +31,13 @@ import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
|
||||
public abstract class AbstractCompileTimeConstantEvaluatorTest : AbstractAnnotationDescriptorResolveTest() {
|
||||
abstract class AbstractCompileTimeConstantEvaluatorTest : AbstractAnnotationDescriptorResolveTest() {
|
||||
|
||||
// Test directives should look like [// val testedPropertyName: expectedValue]
|
||||
fun doConstantTest(path: String) {
|
||||
doTest(path) {
|
||||
property, context ->
|
||||
val compileTimeConstant = property.getCompileTimeInitializer()
|
||||
val compileTimeConstant = property.compileTimeInitializer
|
||||
if (compileTimeConstant is StringValue) {
|
||||
"\\\"${compileTimeConstant.value}\\\""
|
||||
} else {
|
||||
@@ -65,9 +65,9 @@ public abstract class AbstractCompileTimeConstantEvaluatorTest : AbstractAnnotat
|
||||
private fun evaluateInitializer(context: BindingContext, property: VariableDescriptor): CompileTimeConstant<*>? {
|
||||
val propertyDeclaration = DescriptorToSourceUtils.descriptorToDeclaration(property) as KtProperty
|
||||
val compileTimeConstant = ConstantExpressionEvaluator(property.builtIns).evaluateExpression(
|
||||
propertyDeclaration.getInitializer()!!,
|
||||
propertyDeclaration.initializer!!,
|
||||
DelegatingBindingTrace(context, "trace for evaluating compile time constant"),
|
||||
property.getType()
|
||||
property.type
|
||||
)
|
||||
return compileTimeConstant
|
||||
}
|
||||
|
||||
+6
-6
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import java.io.File
|
||||
|
||||
abstract public class AbstractConstraintSystemTest() : KotlinLiteFixture() {
|
||||
abstract class AbstractConstraintSystemTest() : KotlinLiteFixture() {
|
||||
|
||||
private var _typeResolver: TypeResolver? = null
|
||||
private val typeResolver: TypeResolver
|
||||
@@ -51,7 +51,7 @@ abstract public class AbstractConstraintSystemTest() : KotlinLiteFixture() {
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
|
||||
_typeResolver = createContainerForTests(getProject(), KotlinTestUtils.createEmptyModule()).typeResolver
|
||||
_typeResolver = createContainerForTests(project, KotlinTestUtils.createEmptyModule()).typeResolver
|
||||
_testDeclarations = analyzeDeclarations()
|
||||
}
|
||||
|
||||
@@ -70,10 +70,10 @@ abstract public class AbstractConstraintSystemTest() : KotlinLiteFixture() {
|
||||
|
||||
val psiFile = createPsiFile(null, fileName, loadFile(fileName))!!
|
||||
val bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegrationAndCheckForErrors(psiFile).bindingContext
|
||||
return ConstraintSystemTestData(bindingContext, getProject(), typeResolver)
|
||||
return ConstraintSystemTestData(bindingContext, project, typeResolver)
|
||||
}
|
||||
|
||||
public fun doTest(filePath: String) {
|
||||
fun doTest(filePath: String) {
|
||||
val constraintsFile = File(filePath)
|
||||
val constraintsFileText = constraintsFile.readLines()
|
||||
|
||||
@@ -114,9 +114,9 @@ abstract public class AbstractConstraintSystemTest() : KotlinLiteFixture() {
|
||||
|
||||
val resultingSubstitutor = system.resultingSubstitutor
|
||||
val result = typeParameterDescriptors.map {
|
||||
val parameterType = testDeclarations.getType(it.getName().asString())
|
||||
val parameterType = testDeclarations.getType(it.name.asString())
|
||||
val resultType = resultingSubstitutor.substitute(parameterType, Variance.INVARIANT)
|
||||
"${it.getName()}=${resultType?.let { DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(it) }}"
|
||||
"${it.name}=${resultType?.let { DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(it) }}"
|
||||
}.joinToString("\n", prefix = "result:\n")
|
||||
|
||||
val boundsFile = File(filePath.replace("constraints", "bounds"))
|
||||
|
||||
+4
-4
@@ -34,7 +34,7 @@ import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.KotlinTypeImpl
|
||||
import java.util.regex.Pattern
|
||||
|
||||
public class ConstraintSystemTestData(
|
||||
class ConstraintSystemTestData(
|
||||
context: BindingContext,
|
||||
private val project: Project,
|
||||
private val typeResolver: TypeResolver
|
||||
@@ -46,17 +46,17 @@ public class ConstraintSystemTestData(
|
||||
val functions = context.getSliceContents(BindingContext.FUNCTION)
|
||||
functionFoo = findFunctionByName(functions.values, "foo")
|
||||
val function = DescriptorToSourceUtils.descriptorToDeclaration(functionFoo) as KtFunction
|
||||
val fooBody = function.getBodyExpression()
|
||||
val fooBody = function.bodyExpression
|
||||
scopeToResolveTypeParameters = context.get(BindingContext.LEXICAL_SCOPE, fooBody)!!
|
||||
}
|
||||
|
||||
private fun findFunctionByName(functions: Collection<FunctionDescriptor>, name: String): FunctionDescriptor {
|
||||
return functions.firstOrNull { it.getName().asString() == name } ?:
|
||||
return functions.firstOrNull { it.name.asString() == name } ?:
|
||||
throw AssertionError("Function ${name} is not declared")
|
||||
}
|
||||
|
||||
fun getParameterDescriptor(name: String): TypeParameterDescriptor {
|
||||
return functionFoo.getTypeParameters().firstOrNull { it.getName().asString() == name } ?:
|
||||
return functionFoo.typeParameters.firstOrNull { it.name.asString() == name } ?:
|
||||
throw AssertionError("Unsupported type parameter name: $name. You may add it to constraintSystem/declarations.kt")
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.CompilerEnvironment
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmAnalyzerFacade
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmPlatformParameters
|
||||
|
||||
public fun createResolveSessionForFiles(
|
||||
fun createResolveSessionForFiles(
|
||||
project: Project,
|
||||
syntheticFiles: Collection<KtFile>,
|
||||
addBuiltIns: Boolean
|
||||
|
||||
+18
-18
@@ -36,24 +36,24 @@ import org.jetbrains.kotlin.types.typesApproximation.approximateCapturedTypesIfN
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
|
||||
class CapturedTypeApproximationTest() : KotlinLiteFixture() {
|
||||
|
||||
override fun getTestDataPath() = "compiler/testData/capturedTypeApproximation/"
|
||||
|
||||
override fun createEnvironment(): KotlinCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY)
|
||||
|
||||
public fun doTest(filePath: String, vararg substitutions: String) {
|
||||
fun doTest(filePath: String, vararg substitutions: String) {
|
||||
assert(substitutions.size in 1..2) { "Captured type approximation test requires substitutions for (T) or (T, R)" }
|
||||
val oneTypeVariable = substitutions.size == 1
|
||||
|
||||
val declarationsText = KotlinTestUtils.doLoadFile(File(getTestDataPath() + "/declarations.kt"))
|
||||
val declarationsText = KotlinTestUtils.doLoadFile(File(testDataPath + "/declarations.kt"))
|
||||
|
||||
fun analyzeTestFile(testType: String) = run {
|
||||
val test = declarationsText.replace("#TestType#", testType)
|
||||
val testFile = KtPsiFactory(getProject()).createFile(test)
|
||||
val testFile = KtPsiFactory(project).createFile(test)
|
||||
val bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegration(testFile).bindingContext
|
||||
val functions = bindingContext.getSliceContents(BindingContext.FUNCTION)
|
||||
val functionFoo = functions.values.firstOrNull { it.getName().asString() == "foo" } ?:
|
||||
val functionFoo = functions.values.firstOrNull { it.name.asString() == "foo" } ?:
|
||||
throw AssertionError("Function 'foo' is not declared")
|
||||
Pair(bindingContext, functionFoo)
|
||||
}
|
||||
@@ -94,12 +94,12 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
|
||||
for ((index, testTypeWithUnsubstitutedTypeVars) in testTypes.withIndex()) {
|
||||
val testType = createTestType(testTypeWithUnsubstitutedTypeVars)
|
||||
val (bindingContext, functionFoo) = analyzeTestFile(testType)
|
||||
val typeParameters = functionFoo.getTypeParameters()
|
||||
val type = functionFoo.getReturnType()
|
||||
val typeParameters = functionFoo.typeParameters
|
||||
val type = functionFoo.returnType
|
||||
|
||||
appendln(testType)
|
||||
|
||||
if (bindingContext.getDiagnostics().noSuppression().any { it.getSeverity() == Severity.ERROR }) {
|
||||
if (bindingContext.diagnostics.noSuppression().any { it.severity == Severity.ERROR }) {
|
||||
appendln(" compiler error\n")
|
||||
continue
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
|
||||
val testSubstitutions = createTestSubstitutions(typeParameters)
|
||||
for (testSubstitution in testSubstitutions) {
|
||||
val typeSubstitutor = createTestSubstitutor(testSubstitution)
|
||||
val typeWithCapturedType = typeSubstitutor.substituteWithoutApproximation(TypeProjectionImpl(INVARIANT, type!!))!!.getType()
|
||||
val typeWithCapturedType = typeSubstitutor.substituteWithoutApproximation(TypeProjectionImpl(INVARIANT, type!!))!!.type
|
||||
|
||||
val (lower, upper) = approximateCapturedTypes(typeWithCapturedType)
|
||||
val substitution =
|
||||
@@ -116,7 +116,7 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
|
||||
|
||||
append(" ")
|
||||
for (typeParameter in testSubstitution.keys) {
|
||||
if (testSubstitution.size > 1) append("${typeParameter.getName()} = ")
|
||||
if (testSubstitution.size > 1) append("${typeParameter.name} = ")
|
||||
append("${testSubstitution[typeParameter]}. ")
|
||||
}
|
||||
appendln("lower: $lower; upper: $upper; substitution: $substitution")
|
||||
@@ -125,7 +125,7 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
|
||||
}
|
||||
}
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(File(getTestDataPath() + "/" + filePath), result)
|
||||
KotlinTestUtils.assertEqualsToFile(File(testDataPath + "/" + filePath), result)
|
||||
}
|
||||
|
||||
private fun getTypePatternsForOneTypeVariable() = listOf("In<#T#>", "Out<#T#>", "Inv<#T#>", "Inv<in #T#>", "Inv<out #T#>")
|
||||
@@ -170,31 +170,31 @@ public class CapturedTypeApproximationTest() : KotlinLiteFixture() {
|
||||
return result
|
||||
}
|
||||
|
||||
public fun testSimpleT() {
|
||||
fun testSimpleT() {
|
||||
doTest("simpleT.txt", "T");
|
||||
}
|
||||
|
||||
public fun testNullableT() {
|
||||
fun testNullableT() {
|
||||
doTest("nullableT.txt", "T?")
|
||||
}
|
||||
|
||||
public fun testUseSiteInT() {
|
||||
fun testUseSiteInT() {
|
||||
doTest("useSiteInT.txt", "in T");
|
||||
}
|
||||
|
||||
public fun testUseSiteInNullableT() {
|
||||
fun testUseSiteInNullableT() {
|
||||
doTest("useSiteInNullableT.txt", "in T?");
|
||||
}
|
||||
|
||||
public fun testUseSiteOutT() {
|
||||
fun testUseSiteOutT() {
|
||||
doTest("useSiteOutT.txt", "out T");
|
||||
}
|
||||
|
||||
public fun testUseSiteOutNullableT() {
|
||||
fun testUseSiteOutNullableT() {
|
||||
doTest("useSiteOutNullableT.txt", "out T?");
|
||||
}
|
||||
|
||||
public fun testTwoVariables() {
|
||||
fun testTwoVariables() {
|
||||
doTest("twoVariables.txt", "T", "R")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user