2/2 Extract code which is required for :kotlin-scripting-ide-services from ide-common into seprate module
Extract the code and keep it in Kotlin repo. See previous preparation commit as well
This commit is contained in:
@@ -301,6 +301,7 @@ extra["compilerArtifactsForIde"] = listOf(
|
|||||||
":prepare:ide-plugin-dependencies:high-level-api-for-ide",
|
":prepare:ide-plugin-dependencies:high-level-api-for-ide",
|
||||||
":prepare:ide-plugin-dependencies:high-level-api-fir-for-ide",
|
":prepare:ide-plugin-dependencies:high-level-api-fir-for-ide",
|
||||||
":prepare:ide-plugin-dependencies:high-level-api-fir-tests-for-ide",
|
":prepare:ide-plugin-dependencies:high-level-api-fir-tests-for-ide",
|
||||||
|
":prepare:ide-plugin-dependencies:kotlin-scripting-ide-common-for-ide",
|
||||||
":kotlin-script-runtime",
|
":kotlin-script-runtime",
|
||||||
":kotlin-script-util",
|
":kotlin-script-util",
|
||||||
":kotlin-scripting-common",
|
":kotlin-scripting-common",
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("jvm")
|
||||||
|
id("jps-compatible")
|
||||||
|
}
|
||||||
|
|
||||||
|
jvmTarget = "1.8"
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly(project(":compiler:util"))
|
||||||
|
compileOnly(project(":compiler:frontend"))
|
||||||
|
compileOnly(project(":compiler:frontend.java"))
|
||||||
|
compileOnly(project(":js:js.frontend"))
|
||||||
|
compileOnly(project(":js:js.serializer"))
|
||||||
|
compileOnly(intellijCoreDep()) { includeJars("intellij-core", "guava", rootProject = rootProject) }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
"main" { projectDefault() }
|
||||||
|
"test" { }
|
||||||
|
}
|
||||||
-11
@@ -10,26 +10,17 @@ import com.intellij.psi.PsiElement
|
|||||||
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
import org.jetbrains.kotlin.analyzer.AnalysisResult
|
||||||
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
import org.jetbrains.kotlin.analyzer.ModuleInfo
|
||||||
import org.jetbrains.kotlin.analyzer.ResolverForProject
|
import org.jetbrains.kotlin.analyzer.ResolverForProject
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||||
import org.jetbrains.kotlin.idea.FrontendInternals
|
import org.jetbrains.kotlin.idea.FrontendInternals
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|
||||||
|
|
||||||
interface ResolutionFacade {
|
interface ResolutionFacade {
|
||||||
val project: Project
|
val project: Project
|
||||||
|
|
||||||
fun analyze(element: KtElement, bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL): BindingContext
|
|
||||||
fun analyze(elements: Collection<KtElement>, bodyResolveMode: BodyResolveMode): BindingContext
|
|
||||||
|
|
||||||
fun analyzeWithAllCompilerChecks(elements: Collection<KtElement>, callback: DiagnosticSink.DiagnosticsCallback? = null): AnalysisResult
|
fun analyzeWithAllCompilerChecks(elements: Collection<KtElement>, callback: DiagnosticSink.DiagnosticsCallback? = null): AnalysisResult
|
||||||
|
|
||||||
fun resolveToDescriptor(declaration: KtDeclaration, bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL): DeclarationDescriptor
|
|
||||||
|
|
||||||
val moduleDescriptor: ModuleDescriptor
|
val moduleDescriptor: ModuleDescriptor
|
||||||
|
|
||||||
// get service for the module this resolution was created for
|
// get service for the module this resolution was created for
|
||||||
@@ -53,5 +44,3 @@ interface ResolutionFacade {
|
|||||||
|
|
||||||
@FrontendInternals
|
@FrontendInternals
|
||||||
inline fun <reified T : Any> ResolutionFacade.frontendService(): T = this.getFrontendService(T::class.java)
|
inline fun <reified T : Any> ResolutionFacade.frontendService(): T = this.getFrontendService(T::class.java)
|
||||||
|
|
||||||
inline fun <reified T : Any> ResolutionFacade.ideService(): T = this.getIdeService(T::class.java)
|
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -229,8 +229,10 @@ data class ReceiverType(
|
|||||||
val receiverIndex: Int,
|
val receiverIndex: Int,
|
||||||
val implicitValue: ReceiverValue? = null
|
val implicitValue: ReceiverValue? = null
|
||||||
) {
|
) {
|
||||||
|
@Suppress("unused") // Used in intellij-community
|
||||||
val implicit: Boolean get() = implicitValue != null
|
val implicit: Boolean get() = implicitValue != null
|
||||||
|
|
||||||
|
@Suppress("unused") // Used in intellij-community
|
||||||
fun extractDslMarkers() =
|
fun extractDslMarkers() =
|
||||||
implicitValue?.let(DslMarkerUtils::extractDslMarkerFqNames)?.all()
|
implicitValue?.let(DslMarkerUtils::extractDslMarkerFqNames)?.all()
|
||||||
?: DslMarkerUtils.extractDslMarkerFqNames(type)
|
?: DslMarkerUtils.extractDslMarkerFqNames(type)
|
||||||
|
|||||||
+4
-49
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -18,40 +18,10 @@ import org.jetbrains.kotlin.types.checker.StrictEqualityTypeChecker
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.*
|
import org.jetbrains.kotlin.types.typeUtil.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
fun CallableDescriptor.fuzzyReturnType() = returnType?.toFuzzyType(typeParameters)
|
|
||||||
fun CallableDescriptor.fuzzyExtensionReceiverType() = extensionReceiverParameter?.type?.toFuzzyType(typeParameters)
|
fun CallableDescriptor.fuzzyExtensionReceiverType() = extensionReceiverParameter?.type?.toFuzzyType(typeParameters)
|
||||||
|
|
||||||
fun FuzzyType.makeNotNullable() = type.makeNotNullable().toFuzzyType(freeParameters)
|
|
||||||
fun FuzzyType.makeNullable() = type.makeNullable().toFuzzyType(freeParameters)
|
|
||||||
fun FuzzyType.nullability() = type.nullability()
|
fun FuzzyType.nullability() = type.nullability()
|
||||||
|
|
||||||
fun FuzzyType.isAlmostEverything(): Boolean {
|
|
||||||
if (freeParameters.isEmpty()) return false
|
|
||||||
val typeParameter = type.constructor.declarationDescriptor as? TypeParameterDescriptor ?: return false
|
|
||||||
if (typeParameter !in freeParameters) return false
|
|
||||||
return typeParameter.upperBounds.singleOrNull()?.isAnyOrNullableAny() ?: false
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces free parameters inside the type with corresponding type parameters of the class (when possible)
|
|
||||||
*/
|
|
||||||
fun FuzzyType.presentationType(): KotlinType {
|
|
||||||
if (freeParameters.isEmpty()) return type
|
|
||||||
|
|
||||||
val map = HashMap<TypeConstructor, TypeProjection>()
|
|
||||||
for ((argument, typeParameter) in type.arguments.zip(type.constructor.parameters)) {
|
|
||||||
if (argument.projectionKind == Variance.INVARIANT) {
|
|
||||||
val equalToFreeParameter = freeParameters.firstOrNull {
|
|
||||||
StrictEqualityTypeChecker.strictEqualTypes(it.defaultType, argument.type.unwrap())
|
|
||||||
} ?: continue
|
|
||||||
|
|
||||||
map[equalToFreeParameter.typeConstructor] = createProjection(typeParameter.defaultType, Variance.INVARIANT, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val substitutor = TypeSubstitutor.create(map)
|
|
||||||
return substitutor.substitute(type, Variance.INVARIANT)!!
|
|
||||||
}
|
|
||||||
|
|
||||||
fun KotlinType.toFuzzyType(freeParameters: Collection<TypeParameterDescriptor>) = FuzzyType(this, freeParameters)
|
fun KotlinType.toFuzzyType(freeParameters: Collection<TypeParameterDescriptor>) = FuzzyType(this, freeParameters)
|
||||||
|
|
||||||
class FuzzyType(
|
class FuzzyType(
|
||||||
@@ -101,10 +71,13 @@ class FuzzyType(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("MemberVisibilityCanBePrivate") // Used in intellij-community
|
||||||
fun checkIsSubtypeOf(otherType: FuzzyType): TypeSubstitutor? = matchedSubstitutor(otherType, MatchKind.IS_SUBTYPE)
|
fun checkIsSubtypeOf(otherType: FuzzyType): TypeSubstitutor? = matchedSubstitutor(otherType, MatchKind.IS_SUBTYPE)
|
||||||
|
|
||||||
|
@Suppress("MemberVisibilityCanBePrivate") // Used in intellij-community
|
||||||
fun checkIsSuperTypeOf(otherType: FuzzyType): TypeSubstitutor? = matchedSubstitutor(otherType, MatchKind.IS_SUPERTYPE)
|
fun checkIsSuperTypeOf(otherType: FuzzyType): TypeSubstitutor? = matchedSubstitutor(otherType, MatchKind.IS_SUPERTYPE)
|
||||||
|
|
||||||
|
@Suppress("unused") // Used in intellij-community
|
||||||
fun checkIsSubtypeOf(otherType: KotlinType): TypeSubstitutor? = checkIsSubtypeOf(otherType.toFuzzyType(emptyList()))
|
fun checkIsSubtypeOf(otherType: KotlinType): TypeSubstitutor? = checkIsSubtypeOf(otherType.toFuzzyType(emptyList()))
|
||||||
|
|
||||||
fun checkIsSuperTypeOf(otherType: KotlinType): TypeSubstitutor? = checkIsSuperTypeOf(otherType.toFuzzyType(emptyList()))
|
fun checkIsSuperTypeOf(otherType: KotlinType): TypeSubstitutor? = checkIsSuperTypeOf(otherType.toFuzzyType(emptyList()))
|
||||||
@@ -174,21 +147,3 @@ class FuzzyType(
|
|||||||
return TypeConstructorSubstitution.createByConstructorsMap(substitutionMap, approximateCapturedTypes = true).buildSubstitutor()
|
return TypeConstructorSubstitution.createByConstructorsMap(substitutionMap, approximateCapturedTypes = true).buildSubstitutor()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun TypeSubstitution.hasConflictWith(other: TypeSubstitution, freeParameters: Collection<TypeParameterDescriptor>): Boolean {
|
|
||||||
return freeParameters.any { parameter ->
|
|
||||||
val type = parameter.defaultType
|
|
||||||
val substituted1 = this[type] ?: return@any false
|
|
||||||
val substituted2 = other[type] ?: return@any false
|
|
||||||
!StrictEqualityTypeChecker.strictEqualTypes(
|
|
||||||
substituted1.type.unwrap(),
|
|
||||||
substituted2.type.unwrap()
|
|
||||||
) || substituted1.projectionKind != substituted2.projectionKind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun TypeSubstitutor.combineIfNoConflicts(other: TypeSubstitutor, freeParameters: Collection<TypeParameterDescriptor>): TypeSubstitutor? {
|
|
||||||
if (this.substitution.hasConflictWith(other.substitution, freeParameters)) return null
|
|
||||||
return TypeSubstitutor.createChainedSubstitutor(this.substitution, other.substitution)
|
|
||||||
}
|
|
||||||
|
|||||||
+52
@@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.scripting.ide_common.idea.util
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.renderer.*
|
||||||
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor
|
||||||
|
import org.jetbrains.kotlin.types.isDynamic
|
||||||
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
|
|
||||||
|
// Copy-pasted from IdeDescriptorRenderers in intellij-community
|
||||||
|
object IdeDescriptorRenderersScripting {
|
||||||
|
@JvmField
|
||||||
|
val APPROXIMATE_FLEXIBLE_TYPES: (KotlinType) -> KotlinType = { it.approximateFlexibleTypes(preferNotNull = false) }
|
||||||
|
|
||||||
|
private fun unwrapAnonymousType(type: KotlinType): KotlinType {
|
||||||
|
if (type.isDynamic()) return type
|
||||||
|
if (type.constructor is NewCapturedTypeConstructor) return type
|
||||||
|
|
||||||
|
val classifier = type.constructor.declarationDescriptor
|
||||||
|
if (classifier != null && !classifier.name.isSpecial) return type
|
||||||
|
|
||||||
|
type.constructor.supertypes.singleOrNull()?.let { return it }
|
||||||
|
|
||||||
|
val builtIns = type.builtIns
|
||||||
|
return if (type.isMarkedNullable)
|
||||||
|
builtIns.nullableAnyType
|
||||||
|
else
|
||||||
|
builtIns.anyType
|
||||||
|
}
|
||||||
|
|
||||||
|
private val BASE: DescriptorRenderer = DescriptorRenderer.withOptions {
|
||||||
|
normalizedVisibilities = true
|
||||||
|
withDefinedIn = false
|
||||||
|
renderDefaultVisibility = false
|
||||||
|
overrideRenderingPolicy = OverrideRenderingPolicy.RENDER_OVERRIDE
|
||||||
|
unitReturnType = false
|
||||||
|
enhancedTypes = true
|
||||||
|
modifiers = DescriptorRendererModifier.ALL
|
||||||
|
renderUnabbreviatedType = false
|
||||||
|
annotationArgumentsRenderingPolicy = AnnotationArgumentsRenderingPolicy.UNLESS_EMPTY
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmField
|
||||||
|
val SOURCE_CODE: DescriptorRenderer = BASE.withOptions {
|
||||||
|
classifierNamePolicy = ClassifierNamePolicy.SOURCE_CODE_QUALIFIED
|
||||||
|
typeNormalizer = { APPROXIMATE_FLEXIBLE_TYPES(unwrapAnonymousType(it)) }
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-24
@@ -1,17 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2016 JetBrains s.r.o.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
*
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
* 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@file:JvmName("ImportsUtils")
|
@file:JvmName("ImportsUtils")
|
||||||
@@ -19,18 +8,13 @@
|
|||||||
package org.jetbrains.kotlin.idea.imports
|
package org.jetbrains.kotlin.idea.imports
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.KtImportDirective
|
|
||||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||||
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
import org.jetbrains.kotlin.resolve.bindingContextUtil.getReferenceTargets
|
import org.jetbrains.kotlin.resolve.bindingContextUtil.getReferenceTargets
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getImportableDescriptor
|
import org.jetbrains.kotlin.resolve.descriptorUtil.getImportableDescriptor
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|
||||||
val DeclarationDescriptor.importableFqName: FqName?
|
val DeclarationDescriptor.importableFqName: FqName?
|
||||||
@@ -71,9 +55,3 @@ fun KtReferenceExpression.getImportableTargets(bindingContext: BindingContext):
|
|||||||
?: getReferenceTargets(bindingContext)
|
?: getReferenceTargets(bindingContext)
|
||||||
return targets.map { it.getImportableDescriptor() }.toSet()
|
return targets.map { it.getImportableDescriptor() }.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtImportDirective.canResolve(facade: ResolutionFacade): Boolean {
|
|
||||||
return (importedReference?.getQualifiedElementSelector() as? KtSimpleNameExpression)?.let { nameExpression ->
|
|
||||||
nameExpression.getImportableTargets(facade.analyze(nameExpression, BodyResolveMode.PARTIAL)).isNotEmpty()
|
|
||||||
} ?: false
|
|
||||||
}
|
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
+3
-28
@@ -66,39 +66,14 @@ class ShadowedDeclarationsFilter(
|
|||||||
fun <TDescriptor : DeclarationDescriptor> filter(declarations: Collection<TDescriptor>): Collection<TDescriptor> =
|
fun <TDescriptor : DeclarationDescriptor> filter(declarations: Collection<TDescriptor>): Collection<TDescriptor> =
|
||||||
declarations.groupBy { signature(it) }.values.flatMap { group -> filterEqualSignatureGroup(group) }
|
declarations.groupBy { signature(it) }.values.flatMap { group -> filterEqualSignatureGroup(group) }
|
||||||
|
|
||||||
fun <TDescriptor : DeclarationDescriptor> createNonImportedDeclarationsFilter(
|
fun signature(descriptor: DeclarationDescriptor): Any = when (descriptor) {
|
||||||
importedDeclarations: Collection<DeclarationDescriptor>
|
|
||||||
): (Collection<TDescriptor>) -> Collection<TDescriptor> {
|
|
||||||
val importedDeclarationsSet = importedDeclarations.toSet()
|
|
||||||
val importedDeclarationsBySignature = importedDeclarationsSet.groupBy { signature(it) }
|
|
||||||
|
|
||||||
return filter@{ declarations ->
|
|
||||||
// optimization
|
|
||||||
if (declarations.size == 1 && importedDeclarationsBySignature[signature(declarations.single())] == null) return@filter declarations
|
|
||||||
|
|
||||||
val nonImportedDeclarations = declarations.filter { it !in importedDeclarationsSet }
|
|
||||||
|
|
||||||
val notShadowed = HashSet<DeclarationDescriptor>()
|
|
||||||
// same signature non-imported declarations from different packages do not shadow each other
|
|
||||||
for ((pair, group) in nonImportedDeclarations.groupBy { signature(it) to packageName(it) }) {
|
|
||||||
val imported = importedDeclarationsBySignature[pair.first]
|
|
||||||
val all = if (imported != null) group + imported else group
|
|
||||||
notShadowed.addAll(filterEqualSignatureGroup(all, descriptorsToImport = group))
|
|
||||||
}
|
|
||||||
declarations.filter { it in notShadowed }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun signature(descriptor: DeclarationDescriptor): Any = when (descriptor) {
|
|
||||||
is SimpleFunctionDescriptor -> FunctionSignature(descriptor)
|
is SimpleFunctionDescriptor -> FunctionSignature(descriptor)
|
||||||
is VariableDescriptor -> descriptor.name
|
is VariableDescriptor -> descriptor.name
|
||||||
is ClassDescriptor -> descriptor.importableFqName ?: descriptor
|
is ClassDescriptor -> descriptor.importableFqName ?: descriptor
|
||||||
else -> descriptor
|
else -> descriptor
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun packageName(descriptor: DeclarationDescriptor) = descriptor.importableFqName?.parent()
|
fun <TDescriptor : DeclarationDescriptor> filterEqualSignatureGroup(
|
||||||
|
|
||||||
private fun <TDescriptor : DeclarationDescriptor> filterEqualSignatureGroup(
|
|
||||||
descriptors: Collection<TDescriptor>,
|
descriptors: Collection<TDescriptor>,
|
||||||
descriptorsToImport: Collection<TDescriptor> = emptyList()
|
descriptorsToImport: Collection<TDescriptor> = emptyList()
|
||||||
): Collection<TDescriptor> {
|
): Collection<TDescriptor> {
|
||||||
@@ -253,4 +228,4 @@ class ShadowedDeclarationsFilter(
|
|||||||
|
|
||||||
override fun hashCode() = function.name.hashCode() * 17 + function.valueParameters.size
|
override fun hashCode() = function.name.hashCode() * 17 + function.valueParameters.size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-196
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -7,40 +7,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.idea.util
|
package org.jetbrains.kotlin.idea.util
|
||||||
|
|
||||||
import com.intellij.psi.*
|
|
||||||
import org.jetbrains.kotlin.builtins.getReturnTypeFromFunctionType
|
|
||||||
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType
|
|
||||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMapper
|
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMapper
|
||||||
import org.jetbrains.kotlin.builtins.replaceReturnType
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
|
||||||
import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl
|
|
||||||
import org.jetbrains.kotlin.descriptors.impl.MutablePackageFragmentDescriptor
|
|
||||||
import org.jetbrains.kotlin.idea.FrontendInternals
|
|
||||||
import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
|
|
||||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
|
||||||
import org.jetbrains.kotlin.load.java.components.TypeUsage
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.JavaResolverComponents
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.TypeParameterResolver
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.child
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaTypeParameterDescriptor
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.types.JavaTypeAttributes
|
|
||||||
import org.jetbrains.kotlin.load.java.lazy.types.JavaTypeResolver
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.JavaTypeParameter
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaTypeImpl
|
|
||||||
import org.jetbrains.kotlin.load.java.structure.impl.JavaTypeParameterImpl
|
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
|
||||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
|
||||||
import org.jetbrains.kotlin.types.*
|
import org.jetbrains.kotlin.types.*
|
||||||
import org.jetbrains.kotlin.types.typeUtil.*
|
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||||
import org.jetbrains.kotlin.utils.SmartSet
|
import org.jetbrains.kotlin.types.typeUtil.nullability
|
||||||
|
import org.jetbrains.kotlin.types.typeUtil.substitute
|
||||||
|
|
||||||
|
// Copy-pasted from Kotlin plugin in intellij-community
|
||||||
fun KotlinType.approximateFlexibleTypes(
|
fun KotlinType.approximateFlexibleTypes(
|
||||||
preferNotNull: Boolean = false,
|
preferNotNull: Boolean = false,
|
||||||
preferStarForRaw: Boolean = false
|
preferStarForRaw: Boolean = false
|
||||||
@@ -49,6 +23,7 @@ fun KotlinType.approximateFlexibleTypes(
|
|||||||
return unwrapEnhancement().approximateNonDynamicFlexibleTypes(preferNotNull, preferStarForRaw)
|
return unwrapEnhancement().approximateNonDynamicFlexibleTypes(preferNotNull, preferStarForRaw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy-pasted from Kotlin plugin in intellij-community
|
||||||
private fun KotlinType.approximateNonDynamicFlexibleTypes(
|
private fun KotlinType.approximateNonDynamicFlexibleTypes(
|
||||||
preferNotNull: Boolean = false,
|
preferNotNull: Boolean = false,
|
||||||
preferStarForRaw: Boolean = false
|
preferStarForRaw: Boolean = false
|
||||||
@@ -95,167 +70,3 @@ private fun KotlinType.approximateNonDynamicFlexibleTypes(
|
|||||||
ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true)
|
ErrorUtils.createErrorScope("This type is not supposed to be used in member resolution", true)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KotlinType.isResolvableInScope(scope: LexicalScope?, checkTypeParameters: Boolean, allowIntersections: Boolean = false): Boolean {
|
|
||||||
if (constructor is IntersectionTypeConstructor) {
|
|
||||||
if (!allowIntersections) return false
|
|
||||||
return constructor.supertypes.all { it.isResolvableInScope(scope, checkTypeParameters, allowIntersections) }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (canBeReferencedViaImport()) return true
|
|
||||||
|
|
||||||
val descriptor = constructor.declarationDescriptor
|
|
||||||
if (descriptor == null || descriptor.name.isSpecial) return false
|
|
||||||
if (!checkTypeParameters && descriptor is TypeParameterDescriptor) return true
|
|
||||||
|
|
||||||
return scope != null && scope.findClassifier(descriptor.name, NoLookupLocation.FROM_IDE) == descriptor
|
|
||||||
}
|
|
||||||
|
|
||||||
fun KotlinType.approximateWithResolvableType(scope: LexicalScope?, checkTypeParameters: Boolean): KotlinType {
|
|
||||||
if (isError || isResolvableInScope(scope, checkTypeParameters)) return this
|
|
||||||
return supertypes().firstOrNull { it.isResolvableInScope(scope, checkTypeParameters) }
|
|
||||||
?: builtIns.anyType
|
|
||||||
}
|
|
||||||
|
|
||||||
fun KotlinType.anonymousObjectSuperTypeOrNull(): KotlinType? {
|
|
||||||
val classDescriptor = constructor.declarationDescriptor
|
|
||||||
if (classDescriptor != null && DescriptorUtils.isAnonymousObject(classDescriptor)) {
|
|
||||||
return immediateSupertypes().firstOrNull() ?: classDescriptor.builtIns.anyType
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
fun KotlinType.getResolvableApproximations(
|
|
||||||
scope: LexicalScope?,
|
|
||||||
checkTypeParameters: Boolean,
|
|
||||||
allowIntersections: Boolean = false
|
|
||||||
): Sequence<KotlinType> {
|
|
||||||
return (listOf(this) + TypeUtils.getAllSupertypes(this))
|
|
||||||
.asSequence()
|
|
||||||
.mapNotNull {
|
|
||||||
it.asTypeProjection()
|
|
||||||
.fixTypeProjection(scope, checkTypeParameters, allowIntersections, isOutVariance = true)
|
|
||||||
?.type
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun TypeProjection.fixTypeProjection(
|
|
||||||
scope: LexicalScope?,
|
|
||||||
checkTypeParameters: Boolean,
|
|
||||||
allowIntersections: Boolean,
|
|
||||||
isOutVariance: Boolean
|
|
||||||
): TypeProjection? {
|
|
||||||
if (!type.isResolvableInScope(scope, checkTypeParameters, allowIntersections)) return null
|
|
||||||
if (type.arguments.isEmpty()) return this
|
|
||||||
|
|
||||||
val resolvableArgs = type.arguments.filterTo(SmartSet.create()) { typeProjection ->
|
|
||||||
typeProjection.type.isResolvableInScope(scope, checkTypeParameters, allowIntersections)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (resolvableArgs.containsAll(type.arguments)) {
|
|
||||||
fun fixArguments(type: KotlinType): KotlinType? = type.replace(
|
|
||||||
(type.arguments zip type.constructor.parameters).map { (arg, param) ->
|
|
||||||
if (arg.isStarProjection) arg
|
|
||||||
else arg.fixTypeProjection(
|
|
||||||
scope,
|
|
||||||
checkTypeParameters,
|
|
||||||
allowIntersections,
|
|
||||||
isOutVariance = isOutVariance && param.variance == Variance.OUT_VARIANCE
|
|
||||||
) ?: when {
|
|
||||||
!isOutVariance -> return null
|
|
||||||
param.variance == Variance.OUT_VARIANCE -> arg.type.approximateWithResolvableType(
|
|
||||||
scope,
|
|
||||||
checkTypeParameters
|
|
||||||
).asTypeProjection()
|
|
||||||
else -> type.replaceArgumentsWithStarProjections().arguments.first()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return if (type.isBuiltinFunctionalType) {
|
|
||||||
val returnType = type.getReturnTypeFromFunctionType()
|
|
||||||
type.replaceReturnType(fixArguments(returnType) ?: return null).asTypeProjection()
|
|
||||||
} else fixArguments(type)?.asTypeProjection()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isOutVariance) return null
|
|
||||||
|
|
||||||
val newArguments = (type.arguments zip type.constructor.parameters).map { (arg, param) ->
|
|
||||||
when {
|
|
||||||
arg in resolvableArgs -> arg
|
|
||||||
|
|
||||||
arg.projectionKind == Variance.OUT_VARIANCE ||
|
|
||||||
param.variance == Variance.OUT_VARIANCE -> TypeProjectionImpl(
|
|
||||||
arg.projectionKind,
|
|
||||||
arg.type.approximateWithResolvableType(scope, checkTypeParameters)
|
|
||||||
)
|
|
||||||
|
|
||||||
else -> return if (isOutVariance) type.replaceArgumentsWithStarProjections().asTypeProjection() else null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return type.replace(newArguments).asTypeProjection()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun KotlinType.isAbstract(): Boolean {
|
|
||||||
val modality = (constructor.declarationDescriptor as? ClassDescriptor)?.modality
|
|
||||||
return modality == Modality.ABSTRACT || modality == Modality.SEALED
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NOTE: this is a very shaky implementation of [PsiType] to [KotlinType] conversion,
|
|
||||||
* produced types are fakes and are usable only for code generation. Please be careful using this method.
|
|
||||||
*/
|
|
||||||
@OptIn(FrontendInternals::class)
|
|
||||||
fun PsiType.resolveToKotlinType(resolutionFacade: ResolutionFacade): KotlinType {
|
|
||||||
if (this == PsiType.NULL) {
|
|
||||||
return resolutionFacade.moduleDescriptor.builtIns.nullableAnyType
|
|
||||||
}
|
|
||||||
|
|
||||||
val typeParameters = collectTypeParameters()
|
|
||||||
val components = resolutionFacade.getFrontendService(JavaResolverComponents::class.java)
|
|
||||||
val rootContext = LazyJavaResolverContext(components, TypeParameterResolver.EMPTY) { null }
|
|
||||||
val dummyPackageDescriptor = MutablePackageFragmentDescriptor(resolutionFacade.moduleDescriptor, FqName("dummy"))
|
|
||||||
val dummyClassDescriptor = ClassDescriptorImpl(
|
|
||||||
dummyPackageDescriptor,
|
|
||||||
Name.identifier("Dummy"),
|
|
||||||
Modality.FINAL,
|
|
||||||
ClassKind.CLASS,
|
|
||||||
emptyList(),
|
|
||||||
SourceElement.NO_SOURCE,
|
|
||||||
false,
|
|
||||||
LockBasedStorageManager.NO_LOCKS
|
|
||||||
)
|
|
||||||
val typeParameterResolver = object : TypeParameterResolver {
|
|
||||||
override fun resolveTypeParameter(javaTypeParameter: JavaTypeParameter): TypeParameterDescriptor? {
|
|
||||||
val psiTypeParameter = (javaTypeParameter as JavaTypeParameterImpl).psi
|
|
||||||
val index = typeParameters.indexOf(psiTypeParameter)
|
|
||||||
if (index < 0) return null
|
|
||||||
return LazyJavaTypeParameterDescriptor(rootContext.child(this), javaTypeParameter, index, dummyClassDescriptor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val typeResolver = JavaTypeResolver(rootContext, typeParameterResolver)
|
|
||||||
val attributes = JavaTypeAttributes(TypeUsage.COMMON)
|
|
||||||
return typeResolver.transformJavaType(JavaTypeImpl.create(this), attributes).approximateFlexibleTypes(preferNotNull = true)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun PsiType.collectTypeParameters(): List<PsiTypeParameter> {
|
|
||||||
val results = ArrayList<PsiTypeParameter>()
|
|
||||||
accept(
|
|
||||||
object : PsiTypeVisitor<Unit>() {
|
|
||||||
override fun visitArrayType(arrayType: PsiArrayType) {
|
|
||||||
arrayType.componentType.accept(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitClassType(classType: PsiClassType) {
|
|
||||||
(classType.resolve() as? PsiTypeParameter)?.let { results += it }
|
|
||||||
classType.parameters.forEach { it.accept(this) }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitWildcardType(wildcardType: PsiWildcardType) {
|
|
||||||
wildcardType.bound?.accept(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
return results
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -18,7 +18,6 @@ import org.jetbrains.kotlin.types.FlexibleType
|
|||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||||
|
|
||||||
|
|
||||||
fun SmartCastManager.getSmartCastVariantsWithLessSpecificExcluded(
|
fun SmartCastManager.getSmartCastVariantsWithLessSpecificExcluded(
|
||||||
receiverToCast: ReceiverValue,
|
receiverToCast: ReceiverValue,
|
||||||
bindingContext: BindingContext,
|
bindingContext: BindingContext,
|
||||||
|
|||||||
+1
-36
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -8,14 +8,6 @@
|
|||||||
package org.jetbrains.kotlin.idea.util
|
package org.jetbrains.kotlin.idea.util
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
|
||||||
import org.jetbrains.kotlin.psi.KtPsiUtil
|
|
||||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
|
||||||
import org.jetbrains.kotlin.psi.KtThisExpression
|
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
import org.jetbrains.kotlin.types.typeUtil.TypeNullability
|
||||||
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||||
@@ -49,30 +41,3 @@ fun <TCallable : CallableDescriptor> TCallable.substituteExtensionIfCallable(
|
|||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ReceiverValue?.getThisReceiverOwner(bindingContext: BindingContext): DeclarationDescriptor? {
|
|
||||||
return when (this) {
|
|
||||||
is ExpressionReceiver -> {
|
|
||||||
val thisRef = (KtPsiUtil.deparenthesize(this.expression) as? KtThisExpression)?.instanceReference ?: return null
|
|
||||||
bindingContext[BindingContext.REFERENCE_TARGET, thisRef]
|
|
||||||
}
|
|
||||||
|
|
||||||
is ImplicitReceiver -> this.declarationDescriptor
|
|
||||||
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ReceiverValue?.getReceiverTargetDescriptor(bindingContext: BindingContext): DeclarationDescriptor? = when (this) {
|
|
||||||
is ExpressionReceiver -> when (val expression = KtPsiUtil.deparenthesize(this.expression)) {
|
|
||||||
is KtThisExpression -> expression.instanceReference
|
|
||||||
is KtReferenceExpression -> expression
|
|
||||||
else -> null
|
|
||||||
}?.let { referenceExpression ->
|
|
||||||
bindingContext[BindingContext.REFERENCE_TARGET, referenceExpression]
|
|
||||||
}
|
|
||||||
|
|
||||||
is ImplicitReceiver -> this.declarationDescriptor
|
|
||||||
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ fun LexicalScope.getImplicitReceiversWithInstanceToExpression(
|
|||||||
else
|
else
|
||||||
thisWithLabel to false
|
thisWithLabel to false
|
||||||
} else if (owner is ClassDescriptor && owner.kind.isSingleton) {
|
} else if (owner is ClassDescriptor && owner.kind.isSingleton) {
|
||||||
IdeDescriptorRenderers.SOURCE_CODE.renderClassifierName(owner) to false
|
IdeDescriptorRenderersScripting.SOURCE_CODE.renderClassifierName(owner) to false
|
||||||
} else {
|
} else {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-38
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -9,47 +9,16 @@ package org.jetbrains.kotlin.idea.util
|
|||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes
|
import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
|
||||||
import org.jetbrains.kotlin.idea.FrontendInternals
|
import org.jetbrains.kotlin.idea.FrontendInternals
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
|
||||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
import org.jetbrains.kotlin.psi.KtClassBody
|
import org.jetbrains.kotlin.psi.KtClassBody
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|
||||||
import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
|
import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.collectFunctions
|
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.collectVariables
|
|
||||||
|
|
||||||
|
|
||||||
fun LexicalScope.getAllAccessibleVariables(name: Name): Collection<VariableDescriptor> {
|
|
||||||
return getVariablesFromImplicitReceivers(name) + collectVariables(name, NoLookupLocation.FROM_IDE)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun LexicalScope.getAllAccessibleFunctions(name: Name): Collection<FunctionDescriptor> {
|
|
||||||
return getImplicitReceiversWithInstance().flatMap {
|
|
||||||
it.type.memberScope.getContributedFunctions(name, NoLookupLocation.FROM_IDE)
|
|
||||||
} + collectFunctions(name, NoLookupLocation.FROM_IDE)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun LexicalScope.getVariablesFromImplicitReceivers(name: Name): Collection<VariableDescriptor> =
|
|
||||||
getImplicitReceiversWithInstance().flatMap {
|
|
||||||
it.type.memberScope.getContributedVariables(name, NoLookupLocation.FROM_IDE)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun LexicalScope.getVariableFromImplicitReceivers(name: Name): VariableDescriptor? {
|
|
||||||
getImplicitReceiversWithInstance().forEach {
|
|
||||||
it.type.memberScope.getContributedVariables(name, NoLookupLocation.FROM_IDE).singleOrNull()?.let { return it }
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
fun PsiElement.getResolutionScope(bindingContext: BindingContext): LexicalScope? {
|
fun PsiElement.getResolutionScope(bindingContext: BindingContext): LexicalScope? {
|
||||||
for (parent in parentsWithSelf) {
|
for (parent in parentsWithSelf) {
|
||||||
@@ -80,12 +49,6 @@ fun PsiElement.getResolutionScope(
|
|||||||
else -> error("Not in KtFile")
|
else -> error("Not in KtFile")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun KtElement.getResolutionScope(): LexicalScope {
|
|
||||||
val resolutionFacade = getResolutionFacade()
|
|
||||||
val context = resolutionFacade.analyze(this, BodyResolveMode.FULL)
|
|
||||||
return getResolutionScope(context, resolutionFacade)
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(FrontendInternals::class)
|
@OptIn(FrontendInternals::class)
|
||||||
fun ResolutionFacade.getFileResolutionScope(file: KtFile): LexicalScope {
|
fun ResolutionFacade.getFileResolutionScope(file: KtFile): LexicalScope {
|
||||||
return frontendService<FileScopeProvider>().getFileResolutionScope(file)
|
return frontendService<FileScopeProvider>().getFileResolutionScope(file)
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
+1
-16
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -57,21 +57,6 @@ fun descriptorsEqualWithSubstitution(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
fun ClassDescriptor.findCallableMemberBySignature(
|
|
||||||
signature: CallableMemberDescriptor,
|
|
||||||
allowOverridabilityConflicts: Boolean = false
|
|
||||||
): CallableMemberDescriptor? {
|
|
||||||
val descriptorKind = if (signature is FunctionDescriptor) DescriptorKindFilter.FUNCTIONS else DescriptorKindFilter.VARIABLES
|
|
||||||
return defaultType.memberScope
|
|
||||||
.getContributedDescriptors(descriptorKind)
|
|
||||||
.filterIsInstance<CallableMemberDescriptor>()
|
|
||||||
.firstOrNull {
|
|
||||||
if (it.containingDeclaration != this) return@firstOrNull false
|
|
||||||
val overridability = OverridingUtil.DEFAULT.isOverridableBy(it as CallableDescriptor, signature, null).result
|
|
||||||
overridability == OVERRIDABLE || (allowOverridabilityConflicts && overridability == CONFLICT)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun TypeConstructor.supertypesWithAny(): Collection<KotlinType> {
|
fun TypeConstructor.supertypesWithAny(): Collection<KotlinType> {
|
||||||
val supertypes = supertypes
|
val supertypes = supertypes
|
||||||
val noSuperClass = supertypes.map { it.constructor.declarationDescriptor as? ClassDescriptor }.all {
|
val noSuperClass = supertypes.map { it.constructor.declarationDescriptor as? ClassDescriptor }.all {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ plugins { java }
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
embedded(project(":kotlin-scripting-ide-services-unshaded")) { isTransitive = false }
|
embedded(project(":kotlin-scripting-ide-services-unshaded")) { isTransitive = false }
|
||||||
embedded(project(":idea:ide-common")) { isTransitive = false }
|
embedded(project(":kotlin-scripting-ide-common")) { isTransitive = false }
|
||||||
runtimeOnly(project(":kotlin-script-runtime"))
|
runtimeOnly(project(":kotlin-script-runtime"))
|
||||||
runtimeOnly(kotlinStdlib())
|
runtimeOnly(kotlinStdlib())
|
||||||
runtimeOnly(project(":kotlin-scripting-common"))
|
runtimeOnly(project(":kotlin-scripting-common"))
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ dependencies {
|
|||||||
|
|
||||||
testRuntimeOnly(project(":kotlin-compiler"))
|
testRuntimeOnly(project(":kotlin-compiler"))
|
||||||
testRuntimeOnly(commonDep("org.jetbrains.intellij.deps", "trove4j"))
|
testRuntimeOnly(commonDep("org.jetbrains.intellij.deps", "trove4j"))
|
||||||
testRuntimeOnly(project(":idea:ide-common")) { isTransitive = false }
|
testRuntimeOnly(project(":kotlin-scripting-ide-common")) { isTransitive = false }
|
||||||
|
|
||||||
embeddableTestRuntime(project(":kotlin-scripting-ide-services", configuration="runtimeElements"))
|
embeddableTestRuntime(project(":kotlin-scripting-ide-services", configuration="runtimeElements"))
|
||||||
embeddableTestRuntime(project(":kotlin-scripting-compiler-impl-embeddable", configuration="runtimeElements"))
|
embeddableTestRuntime(project(":kotlin-scripting-compiler-impl-embeddable", configuration="runtimeElements"))
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ publish()
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile(project(":kotlin-script-runtime"))
|
compile(project(":kotlin-script-runtime"))
|
||||||
compile(kotlinStdlib())
|
compile(kotlinStdlib())
|
||||||
compileOnly(project(":idea:ide-common"))
|
compileOnly(project(":kotlin-scripting-ide-common"))
|
||||||
compile(project(":kotlin-scripting-common"))
|
compile(project(":kotlin-scripting-common"))
|
||||||
compile(project(":kotlin-scripting-jvm"))
|
compile(project(":kotlin-scripting-jvm"))
|
||||||
compileOnly(project(":kotlin-scripting-compiler"))
|
compileOnly(project(":kotlin-scripting-compiler"))
|
||||||
|
|||||||
+3
-3
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.ReferenceVariantsHelper
|
import org.jetbrains.kotlin.idea.codeInsight.ReferenceVariantsHelper
|
||||||
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderersScripting
|
||||||
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
||||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
@@ -414,11 +414,11 @@ private class KJvmReplCompleter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val RENDERER =
|
private val RENDERER =
|
||||||
IdeDescriptorRenderers.SOURCE_CODE.withOptions {
|
IdeDescriptorRenderersScripting.SOURCE_CODE.withOptions {
|
||||||
this.classifierNamePolicy =
|
this.classifierNamePolicy =
|
||||||
ClassifierNamePolicy.SHORT
|
ClassifierNamePolicy.SHORT
|
||||||
this.typeNormalizer =
|
this.typeNormalizer =
|
||||||
IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES
|
IdeDescriptorRenderersScripting.APPROXIMATE_FLEXIBLE_TYPES
|
||||||
this.parameterNameRenderingPolicy =
|
this.parameterNameRenderingPolicy =
|
||||||
ParameterNameRenderingPolicy.NONE
|
ParameterNameRenderingPolicy.NONE
|
||||||
this.renderDefaultAnnotationArguments = false
|
this.renderDefaultAnnotationArguments = false
|
||||||
|
|||||||
-16
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
|||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
|
||||||
|
|
||||||
class KotlinResolutionFacadeForRepl(
|
class KotlinResolutionFacadeForRepl(
|
||||||
private val environment: KotlinCoreEnvironment,
|
private val environment: KotlinCoreEnvironment,
|
||||||
@@ -31,13 +30,6 @@ class KotlinResolutionFacadeForRepl(
|
|||||||
override val project: Project
|
override val project: Project
|
||||||
get() = environment.project
|
get() = environment.project
|
||||||
|
|
||||||
override fun analyze(
|
|
||||||
element: KtElement,
|
|
||||||
bodyResolveMode: BodyResolveMode
|
|
||||||
): BindingContext {
|
|
||||||
throw UnsupportedOperationException()
|
|
||||||
}
|
|
||||||
|
|
||||||
override val moduleDescriptor: ModuleDescriptor = provider.getService(ModuleDescriptor::class.java)
|
override val moduleDescriptor: ModuleDescriptor = provider.getService(ModuleDescriptor::class.java)
|
||||||
|
|
||||||
@FrontendInternals
|
@FrontendInternals
|
||||||
@@ -69,10 +61,6 @@ class KotlinResolutionFacadeForRepl(
|
|||||||
throw UnsupportedOperationException()
|
throw UnsupportedOperationException()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun analyze(elements: Collection<KtElement>, bodyResolveMode: BodyResolveMode): BindingContext {
|
|
||||||
throw UnsupportedOperationException()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun analyzeWithAllCompilerChecks(
|
override fun analyzeWithAllCompilerChecks(
|
||||||
elements: Collection<KtElement>,
|
elements: Collection<KtElement>,
|
||||||
callback: DiagnosticSink.DiagnosticsCallback?
|
callback: DiagnosticSink.DiagnosticsCallback?
|
||||||
@@ -80,8 +68,4 @@ class KotlinResolutionFacadeForRepl(
|
|||||||
throw UnsupportedOperationException()
|
throw UnsupportedOperationException()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun resolveToDescriptor(declaration: KtDeclaration, bodyResolveMode: BodyResolveMode): DeclarationDescriptor {
|
|
||||||
throw UnsupportedOperationException()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
plugins {
|
||||||
|
kotlin("jvm")
|
||||||
|
}
|
||||||
|
|
||||||
|
publishJarsForIde(listOf(":kotlin-scripting-ide-common"))
|
||||||
+11
-7
@@ -284,6 +284,11 @@ include ":compiler:fir:cones",
|
|||||||
":compiler:fir:analysis-tests",
|
":compiler:fir:analysis-tests",
|
||||||
":compiler:fir:analysis-tests:legacy-fir-tests"
|
":compiler:fir:analysis-tests:legacy-fir-tests"
|
||||||
|
|
||||||
|
include ":kotlin-scripting-ide-services-unshaded",
|
||||||
|
":kotlin-scripting-ide-services-test",
|
||||||
|
":kotlin-scripting-ide-services",
|
||||||
|
":kotlin-scripting-ide-common"
|
||||||
|
|
||||||
include ":compiler:test-infrastructure",
|
include ":compiler:test-infrastructure",
|
||||||
":compiler:test-infrastructure-utils",
|
":compiler:test-infrastructure-utils",
|
||||||
":compiler:tests-common-new"
|
":compiler:tests-common-new"
|
||||||
@@ -319,7 +324,8 @@ if (!buildProperties.inJpsBuildIdeaSync) {
|
|||||||
":prepare:ide-plugin-dependencies:low-level-api-fir-for-ide",
|
":prepare:ide-plugin-dependencies:low-level-api-fir-for-ide",
|
||||||
":prepare:ide-plugin-dependencies:high-level-api-for-ide",
|
":prepare:ide-plugin-dependencies:high-level-api-for-ide",
|
||||||
":prepare:ide-plugin-dependencies:high-level-api-fir-for-ide",
|
":prepare:ide-plugin-dependencies:high-level-api-fir-for-ide",
|
||||||
":prepare:ide-plugin-dependencies:high-level-api-fir-tests-for-ide"
|
":prepare:ide-plugin-dependencies:high-level-api-fir-tests-for-ide",
|
||||||
|
":prepare:ide-plugin-dependencies:kotlin-scripting-ide-common-for-ide"
|
||||||
}
|
}
|
||||||
|
|
||||||
void kotlinIde(String imlPath) {
|
void kotlinIde(String imlPath) {
|
||||||
@@ -461,9 +467,6 @@ if (!buildProperties.getBoolean("disableKotlinPluginModules", false) && attached
|
|||||||
":noarg-ide-plugin",
|
":noarg-ide-plugin",
|
||||||
":allopen-ide-plugin",
|
":allopen-ide-plugin",
|
||||||
":jps-plugin",
|
":jps-plugin",
|
||||||
":kotlin-scripting-ide-services-unshaded",
|
|
||||||
":kotlin-scripting-ide-services-test",
|
|
||||||
":kotlin-scripting-ide-services",
|
|
||||||
":kotlinx-serialization-ide-plugin",
|
":kotlinx-serialization-ide-plugin",
|
||||||
":kotlin-jps-plugin",
|
":kotlin-jps-plugin",
|
||||||
":generators:idea-generator",
|
":generators:idea-generator",
|
||||||
@@ -492,9 +495,6 @@ if (!buildProperties.getBoolean("disableKotlinPluginModules", false) && attached
|
|||||||
project(':plugins:kapt3-idea').projectDir = "$rootDir/plugins/kapt3/kapt3-idea" as File
|
project(':plugins:kapt3-idea').projectDir = "$rootDir/plugins/kapt3/kapt3-idea" as File
|
||||||
project(':allopen-ide-plugin').projectDir = "$rootDir/plugins/allopen/allopen-ide" as File
|
project(':allopen-ide-plugin').projectDir = "$rootDir/plugins/allopen/allopen-ide" as File
|
||||||
project(':noarg-ide-plugin').projectDir = "$rootDir/plugins/noarg/noarg-ide" as File
|
project(':noarg-ide-plugin').projectDir = "$rootDir/plugins/noarg/noarg-ide" as File
|
||||||
project(':kotlin-scripting-ide-services-unshaded').projectDir = "$rootDir/plugins/scripting/scripting-ide-services" as File
|
|
||||||
project(':kotlin-scripting-ide-services-test').projectDir = "$rootDir/plugins/scripting/scripting-ide-services-test" as File
|
|
||||||
project(':kotlin-scripting-ide-services').projectDir = "$rootDir/plugins/scripting/scripting-ide-services-embeddable" as File
|
|
||||||
project(':kotlinx-serialization-ide-plugin').projectDir = file("$rootDir/plugins/kotlin-serialization/kotlin-serialization-ide")
|
project(':kotlinx-serialization-ide-plugin').projectDir = file("$rootDir/plugins/kotlin-serialization/kotlin-serialization-ide")
|
||||||
project(':kotlin-jps-plugin').projectDir = "$rootDir/prepare/jps-plugin" as File
|
project(':kotlin-jps-plugin').projectDir = "$rootDir/prepare/jps-plugin" as File
|
||||||
project(':sam-with-receiver-ide-plugin').projectDir = "$rootDir/plugins/sam-with-receiver/sam-with-receiver-ide" as File
|
project(':sam-with-receiver-ide-plugin').projectDir = "$rootDir/plugins/sam-with-receiver/sam-with-receiver-ide" as File
|
||||||
@@ -690,6 +690,10 @@ project(":idea-frontend-fir:idea-frontend-fir-generator").projectDir = "$rootDir
|
|||||||
project(":idea-frontend-fir").projectDir = "$rootDir/idea/idea-frontend-fir" as File
|
project(":idea-frontend-fir").projectDir = "$rootDir/idea/idea-frontend-fir" as File
|
||||||
project(":idea-frontend-api").projectDir = "$rootDir/idea/idea-frontend-api" as File
|
project(":idea-frontend-api").projectDir = "$rootDir/idea/idea-frontend-api" as File
|
||||||
|
|
||||||
|
project(':kotlin-scripting-ide-services-unshaded').projectDir = "$rootDir/plugins/scripting/scripting-ide-services" as File
|
||||||
|
project(':kotlin-scripting-ide-services-test').projectDir = "$rootDir/plugins/scripting/scripting-ide-services-test" as File
|
||||||
|
project(':kotlin-scripting-ide-services').projectDir = "$rootDir/plugins/scripting/scripting-ide-services-embeddable" as File
|
||||||
|
project(':kotlin-scripting-ide-common').projectDir = "$rootDir/plugins/scripting/scripting-ide-common" as File
|
||||||
|
|
||||||
// Uncomment to use locally built protobuf-relocated
|
// Uncomment to use locally built protobuf-relocated
|
||||||
// includeBuild("dependencies/protobuf")
|
// includeBuild("dependencies/protobuf")
|
||||||
|
|||||||
Reference in New Issue
Block a user