-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get rif of IDE plugin dependencies (#3073)
* Get rif of IDE plugin dependencies Everything in this commit has been copy-pasted from IDE plugin and marked as internal
- Loading branch information
Showing
24 changed files
with
1,239 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
.../org/jetbrains/dokka/analysis/kotlin/descriptors/ide/IdeCompilerExtensionPointProvider.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...descriptors/ide/src/main/kotlin/org/jetbrains/kotlin/caches/resolve/KotlinCacheService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. | ||
|
||
package org.jetbrains.kotlin.caches.resolve | ||
|
||
import com.intellij.openapi.components.ComponentManager | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.psi.PsiFile | ||
import org.jetbrains.kotlin.analyzer.ModuleInfo | ||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade | ||
import org.jetbrains.kotlin.psi.KtElement | ||
import org.jetbrains.kotlin.platform.TargetPlatform | ||
import org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache | ||
|
||
internal interface KotlinCacheService { | ||
companion object { | ||
inline fun <reified T : Any> ComponentManager.service(): T { | ||
val serviceClass = T::class.java | ||
return getService(serviceClass) | ||
?: error("Cannot find service ${serviceClass.name} in $this (classloader=${serviceClass.classLoader}") | ||
} | ||
|
||
fun getInstance(project: Project): KotlinCacheService = project.service() | ||
} | ||
|
||
/** | ||
* Provides resolution facade for [elements], guaranteeing that the resolution will be seen from the [platform]-perspective. | ||
* | ||
* This allows to get resolution for common sources in MPP from the perspective of given platform (with expects substituted to actuals, | ||
* declarations resolved from platform-specific artifacts, ModuleDescriptors will contain only platform dependencies, etc.) | ||
* | ||
* It is equivalent to usual [getResolutionFacade]-overloads if platform(s) of module(s) containing [elements] are equal to [platform] | ||
* | ||
* Doesn't support scripts or any other 'special' files. | ||
*/ | ||
fun getResolutionFacadeWithForcedPlatform(elements: List<KtElement>, platform: TargetPlatform): ResolutionFacade | ||
|
||
fun getResolutionFacade(element: KtElement): ResolutionFacade | ||
fun getResolutionFacade(elements: List<KtElement>): ResolutionFacade | ||
fun getResolutionFacadeByFile(file: PsiFile, platform: TargetPlatform): ResolutionFacade? | ||
|
||
fun getSuppressionCache(): KotlinSuppressCache | ||
fun getResolutionFacadeByModuleInfo(moduleInfo: ModuleInfo, platform: TargetPlatform): ResolutionFacade? | ||
|
||
fun getResolutionFacadeByModuleInfo(moduleInfo: ModuleInfo, settings: PlatformAnalysisSettings): ResolutionFacade? | ||
} |
22 changes: 22 additions & 0 deletions
22
...ptors/ide/src/main/kotlin/org/jetbrains/kotlin/caches/resolve/PlatformAnalysisSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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.caches.resolve | ||
|
||
/** | ||
* Regulates which sources should be analyzed together. | ||
* | ||
* There are exactly two descendants, which are in strong one-to-one correspondence with [ResolutionModeComponent.Mode] (meaning | ||
* that after checking value of ResolutionMode, it's safe to downcast settings instance to the respective type): | ||
* - [PlatformAnalysisSettingsImpl] should be used iff we're working under [Mode.SEPARATE], and will create separate | ||
* facade for each platforms, sdk, builtIns settings and other stuff. | ||
* This is the old and stable mode, which should be used by default. | ||
* | ||
* - [CompositeAnalysisSettings] should be used iff we're working under [Mode.COMPOSITE], and will analyze all sources | ||
* together, in one facade. | ||
* This mode is new and experimental, and works only together with TypeRefinement facilities in the compiler's frontend. | ||
* This mode is currently enabled only for HMPP projects | ||
*/ | ||
internal interface PlatformAnalysisSettings |
78 changes: 78 additions & 0 deletions
78
...ors/ide/src/main/kotlin/org/jetbrains/kotlin/idea/caches/resolve/ExtendedResolutionApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
|
||
package org.jetbrains.kotlin.idea.caches.resolve | ||
|
||
import org.jetbrains.kotlin.caches.resolve.KotlinCacheService | ||
import org.jetbrains.kotlin.descriptors.* | ||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade | ||
import org.jetbrains.kotlin.psi.* | ||
import org.jetbrains.kotlin.resolve.BindingContext | ||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode | ||
import org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException | ||
|
||
|
||
internal fun KtElement.getResolutionFacade(): ResolutionFacade = KotlinCacheService.getInstance(project).getResolutionFacade(this) | ||
|
||
/** | ||
* This function first uses declaration resolvers to resolve this declaration and/or additional declarations (e.g. its parent), | ||
* and then takes the relevant descriptor from binding context. | ||
* The exact set of declarations to resolve depends on bodyResolveMode | ||
*/ | ||
internal fun KtDeclaration.resolveToDescriptorIfAny( | ||
resolutionFacade: ResolutionFacade, | ||
bodyResolveMode: BodyResolveMode = BodyResolveMode.PARTIAL | ||
): DeclarationDescriptor? { | ||
//TODO: BodyResolveMode.PARTIAL is not quite safe! | ||
val context = safeAnalyze(resolutionFacade, bodyResolveMode) | ||
return if (this is KtParameter && hasValOrVar()) { | ||
context.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, this) | ||
// It is incorrect to have `val/var` parameters outside the primary constructor (e.g., `fun foo(val x: Int)`) | ||
// but we still want to try to resolve in such cases. | ||
?: context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, this) | ||
} else { | ||
context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, this) | ||
} | ||
} | ||
|
||
internal fun KtParameter.resolveToParameterDescriptorIfAny(bodyResolveMode: BodyResolveMode = BodyResolveMode.PARTIAL) = | ||
resolveToParameterDescriptorIfAny(getResolutionFacade(), bodyResolveMode) | ||
|
||
internal fun KtParameter.resolveToParameterDescriptorIfAny( | ||
resolutionFacade: ResolutionFacade, | ||
bodyResolveMode: BodyResolveMode = BodyResolveMode.PARTIAL | ||
): ValueParameterDescriptor? { | ||
val context = safeAnalyze(resolutionFacade, bodyResolveMode) | ||
return context.get(BindingContext.VALUE_PARAMETER, this) as? ValueParameterDescriptor | ||
} | ||
|
||
internal fun KtDeclaration.resolveToDescriptorIfAny( | ||
bodyResolveMode: BodyResolveMode = BodyResolveMode.PARTIAL | ||
): DeclarationDescriptor? = | ||
resolveToDescriptorIfAny(getResolutionFacade(), bodyResolveMode) | ||
|
||
internal fun KtElement.analyze( | ||
resolutionFacade: ResolutionFacade, | ||
bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL | ||
): BindingContext = resolutionFacade.analyze(this, bodyResolveMode) | ||
|
||
internal fun KtElement.safeAnalyze( | ||
resolutionFacade: ResolutionFacade, | ||
bodyResolveMode: BodyResolveMode = BodyResolveMode.FULL | ||
): BindingContext = try { | ||
analyze(resolutionFacade, bodyResolveMode) | ||
} catch (e: Exception) { | ||
e.returnIfNoDescriptorForDeclarationException { BindingContext.EMPTY } | ||
} | ||
|
||
internal inline fun <T> Exception.returnIfNoDescriptorForDeclarationException( | ||
crossinline condition: (Boolean) -> Boolean = { v -> v }, | ||
crossinline computable: () -> T | ||
): T = | ||
if (condition(this.isItNoDescriptorForDeclarationException)) { | ||
computable() | ||
} else { | ||
throw this | ||
} | ||
|
||
internal val Exception.isItNoDescriptorForDeclarationException: Boolean | ||
get() = this is NoDescriptorForDeclarationException || (cause as? Exception)?.isItNoDescriptorForDeclarationException == true |
Oops, something went wrong.