Rename: analyzeWithDeclarations --> analyzeWithContent()

This commit is contained in:
Mikhail Glukhikh
2018-02-20 17:46:32 +03:00
parent f6513cd17e
commit bd0cbb716c
22 changed files with 44 additions and 46 deletions
@@ -162,7 +162,7 @@ class CliLightClassGenerationSupport(project: Project) : LightClassGenerationSup
override fun analyze(element: KtElement) = bindingContext override fun analyze(element: KtElement) = bindingContext
override fun analyzeWithDeclarations(element: KtClassOrObject) = bindingContext override fun analyzeWithContent(element: KtClassOrObject) = bindingContext
override fun getFacadeClasses(facadeFqName: FqName, scope: GlobalSearchScope): Collection<PsiClass> { override fun getFacadeClasses(facadeFqName: FqName, scope: GlobalSearchScope): Collection<PsiClass> {
val filesForFacade = findFilesForFacade(facadeFqName, scope) val filesForFacade = findFilesForFacade(facadeFqName, scope)
@@ -67,7 +67,7 @@ abstract class LightClassGenerationSupport {
abstract fun analyze(element: KtElement): BindingContext abstract fun analyze(element: KtElement): BindingContext
abstract fun analyzeWithDeclarations(element: KtClassOrObject): BindingContext abstract fun analyzeWithContent(element: KtClassOrObject): BindingContext
abstract fun getFacadeClasses(facadeFqName: FqName, scope: GlobalSearchScope): Collection<PsiClass> abstract fun getFacadeClasses(facadeFqName: FqName, scope: GlobalSearchScope): Collection<PsiClass>
@@ -43,7 +43,7 @@ class KtLightPsiReferenceList (
override val kotlinOrigin by lazyPub { override val kotlinOrigin by lazyPub {
val superTypeList = this@KtLightPsiReferenceList.kotlinOrigin ?: return@lazyPub null val superTypeList = this@KtLightPsiReferenceList.kotlinOrigin ?: return@lazyPub null
val fqNameToFind = clsDelegate.qualifiedName ?: return@lazyPub null val fqNameToFind = clsDelegate.qualifiedName ?: return@lazyPub null
val context = LightClassGenerationSupport.getInstance(project).analyzeWithDeclarations(superTypeList.parent as KtClassOrObject) val context = LightClassGenerationSupport.getInstance(project).analyzeWithContent(superTypeList.parent as KtClassOrObject)
superTypeList.entries.firstOrNull { superTypeList.entries.firstOrNull {
val referencedType = context[BindingContext.TYPE, it.typeReference] val referencedType = context[BindingContext.TYPE, it.typeReference]
referencedType?.constructor?.declarationDescriptor?.fqNameUnsafe?.asString() == fqNameToFind referencedType?.constructor?.declarationDescriptor?.fqNameUnsafe?.asString() == fqNameToFind
@@ -78,18 +78,18 @@ fun KtFile.resolveImportReference(fqName: FqName): Collection<DeclarationDescrip
} }
// This and next function are used for 'normal' element analysis // This and next functions are used for 'normal' element analysis
// This analysis *should* provide all information extractable from this KtElement except: // This analysis *should* provide all information extractable from this KtElement except:
// - it does not analyze bodies of functions // - for declarations, it does not analyze their bodies
// - it does not analyze content of classes // - for classes, it does not analyze their content
// - it does not analyze initializers / accessors for member / top-level properties // - for member / top-level properties, it does not analyze initializers / accessors
// This information includes related descriptors, resolved calls (but not inside body, see above!) // This information includes related descriptors, resolved calls (but not inside body, see above!)
// and many other binding context slices. // and many other binding context slices.
// Normally, the function is used on local declarations or statements / expressions // Normally, the function is used on local declarations or statements / expressions
// Any usage on non-local declaration is a bit suspicious, // Any usage on non-local declaration is a bit suspicious,
// consider replacing it with resolveToDescriptorIfAny and // consider replacing it with resolveToDescriptorIfAny and
// remember that body / content is not analyzed; // remember that body / content is not analyzed;
// if it's necessary, use analyzeWithContent() / analyzeWithDeclarations(). // if it's necessary, use analyzeWithContent()
// //
// If you need diagnostics in result context, use BodyResolveMode.PARTIAL_WITH_DIAGNOSTICS. // If you need diagnostics in result context, use BodyResolveMode.PARTIAL_WITH_DIAGNOSTICS.
// BodyResolveMode.FULL analyzes all statements on the level of KtElement and above. // BodyResolveMode.FULL analyzes all statements on the level of KtElement and above.
@@ -114,13 +114,13 @@ fun KtDeclaration.analyzeWithContent(): BindingContext =
// This function is used to make full analysis of declaration container. // This function is used to make full analysis of declaration container.
// All its declarations, including their content (see above), are analyzed. // All its declarations, including their content (see above), are analyzed.
inline fun <reified T> T.analyzeWithDeclarations(): BindingContext where T : KtDeclarationContainer, T : KtElement = inline fun <reified T> T.analyzeWithContent(): BindingContext where T : KtDeclarationContainer, T : KtElement =
getResolutionFacade().analyzeFullyAndGetResult(listOf(this)).bindingContext getResolutionFacade().analyzeFullyAndGetResult(listOf(this)).bindingContext
// NB: for statements / expressions, usually should be replaced with analyze(), // NB: for statements / expressions, usually should be replaced with analyze(),
// for declarations, analyzeWithContent() will do what you want. // for declarations, analyzeWithContent() will do what you want.
@Deprecated( @Deprecated(
"Use either analyzeWithContent() or analyzeWithDeclarations() instead, or use just analyze()", "Use analyzeWithContent() instead, or use just analyze()",
ReplaceWith("analyze()") ReplaceWith("analyze()")
) )
fun KtElement.analyzeFully(): BindingContext = getResolutionFacade().analyzeFullyAndGetResult(listOf(this)).bindingContext fun KtElement.analyzeFully(): BindingContext = getResolutionFacade().analyzeFullyAndGetResult(listOf(this)).bindingContext
@@ -237,7 +237,7 @@ class IDELightClassGenerationSupport(private val project: Project) : LightClassG
override fun analyze(element: KtElement) = element.analyze(BodyResolveMode.PARTIAL) override fun analyze(element: KtElement) = element.analyze(BodyResolveMode.PARTIAL)
override fun analyzeWithDeclarations(element: KtClassOrObject) = element.analyzeWithDeclarations() override fun analyzeWithContent(element: KtClassOrObject) = element.analyzeWithContent()
override fun getFacadeNames(packageFqName: FqName, scope: GlobalSearchScope): Collection<String> { override fun getFacadeNames(packageFqName: FqName, scope: GlobalSearchScope): Collection<String> {
val facadeFilesInPackage = runReadAction { val facadeFilesInPackage = runReadAction {
@@ -40,7 +40,7 @@ class DebugInfoAnnotator : Annotator {
if (element is KtFile && element !is KtCodeFragment) { if (element is KtFile && element !is KtCodeFragment) {
try { try {
val bindingContext = element.analyzeWithDeclarations() val bindingContext = element.analyzeWithContent()
DebugInfoUtil.markDebugAnnotations(element, bindingContext, object : DebugInfoUtil.DebugInfoReporter() { DebugInfoUtil.markDebugAnnotations(element, bindingContext, object : DebugInfoUtil.DebugInfoReporter() {
override fun reportElementWithErrorType(expression: KtReferenceExpression) { override fun reportElementWithErrorType(expression: KtReferenceExpression) {
holder.createErrorAnnotation(expression, "[DEBUG] Resolved to error element").textAttributes = holder.createErrorAnnotation(expression, "[DEBUG] Resolved to error element").textAttributes =
@@ -19,10 +19,8 @@ package org.jetbrains.kotlin.idea.highlighter
import com.intellij.lang.annotation.AnnotationHolder import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.lang.annotation.Annotator import com.intellij.lang.annotation.Annotator
import com.intellij.psi.PsiElement import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.asJava.getJvmSignatureDiagnostics import org.jetbrains.kotlin.asJava.*
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent import org.jetbrains.kotlin.idea.caches.resolve.*
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations
import org.jetbrains.kotlin.idea.caches.resolve.getModuleInfo
import org.jetbrains.kotlin.idea.project.TargetPlatformDetector import org.jetbrains.kotlin.idea.project.TargetPlatformDetector
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil import org.jetbrains.kotlin.idea.util.ProjectRootsUtil
import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtDeclaration
@@ -39,7 +37,7 @@ class DuplicateJvmSignatureAnnotator : Annotator {
val otherDiagnostics = when (element) { val otherDiagnostics = when (element) {
is KtDeclaration -> element.analyzeWithContent() is KtDeclaration -> element.analyzeWithContent()
is KtFile -> element.analyzeWithDeclarations() is KtFile -> element.analyzeWithContent()
else -> throw AssertionError("DuplicateJvmSignatureAnnotator: should not get here! Element: ${element.text}") else -> throw AssertionError("DuplicateJvmSignatureAnnotator: should not get here! Element: ${element.text}")
}.diagnostics }.diagnostics
@@ -24,7 +24,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile import com.intellij.psi.PsiFile
import com.intellij.util.ExceptionUtil import com.intellij.util.ExceptionUtil
import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode import org.jetbrains.kotlin.idea.actions.internal.KotlinInternalMode
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
import org.jetbrains.kotlin.idea.core.replaced import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.* import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.*
@@ -154,7 +154,7 @@ private fun KtFile.findContextElement(): KtElement? {
private var PsiElement.DEBUG_SMART_CAST: PsiElement? by CopyablePsiUserDataProperty(Key.create("DEBUG_SMART_CAST")) private var PsiElement.DEBUG_SMART_CAST: PsiElement? by CopyablePsiUserDataProperty(Key.create("DEBUG_SMART_CAST"))
private fun KtCodeFragment.markSmartCasts() { private fun KtCodeFragment.markSmartCasts() {
val bindingContext = runInReadActionWithWriteActionPriorityWithPCE { analyzeWithDeclarations() } val bindingContext = runInReadActionWithWriteActionPriorityWithPCE { analyzeWithContent() }
val factory = KtPsiFactory(project) val factory = KtPsiFactory(project)
getContentElement()?.forEachDescendantOfType<KtExpression> { expression -> getContentElement()?.forEachDescendantOfType<KtExpression> { expression ->
@@ -10,7 +10,7 @@ import com.intellij.psi.PsiFile
import com.intellij.testFramework.UsefulTestCase import com.intellij.testFramework.UsefulTestCase
import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.InTextDirectivesUtils
@@ -22,7 +22,7 @@ object DirectiveBasedActionUtils {
val expectedErrors = InTextDirectivesUtils.findLinesWithPrefixesRemoved(file.text, "// ERROR:").sorted() val expectedErrors = InTextDirectivesUtils.findLinesWithPrefixesRemoved(file.text, "// ERROR:").sorted()
val actualErrors = file.analyzeWithDeclarations().diagnostics val actualErrors = file.analyzeWithContent().diagnostics
.filter { it.getSeverity() == Severity.ERROR } .filter { it.getSeverity() == Severity.ERROR }
.map { DefaultErrorMessages.render(it).replace("\n", "<br>") } .map { DefaultErrorMessages.render(it).replace("\n", "<br>") }
.sorted() .sorted()
@@ -32,7 +32,7 @@ import com.intellij.util.Consumer
import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
import org.jetbrains.kotlin.idea.caches.resolve.LibraryModificationTracker import org.jetbrains.kotlin.idea.caches.resolve.LibraryModificationTracker
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.decompiler.KotlinDecompiledFileViewProvider import org.jetbrains.kotlin.idea.decompiler.KotlinDecompiledFileViewProvider
import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile
import org.jetbrains.kotlin.idea.util.application.runWriteAction import org.jetbrains.kotlin.idea.util.application.runWriteAction
@@ -73,7 +73,7 @@ fun Module.configureAs(kind: ModuleKind) {
} }
fun KtFile.dumpTextWithErrors(): String { fun KtFile.dumpTextWithErrors(): String {
val diagnostics = analyzeWithDeclarations().diagnostics val diagnostics = analyzeWithContent().diagnostics
val errors = diagnostics.filter { it.severity == Severity.ERROR } val errors = diagnostics.filter { it.severity == Severity.ERROR }
if (errors.isEmpty()) return text if (errors.isEmpty()) return text
val header = errors.map { "// ERROR: " + DefaultErrorMessages.render(it).replace('\n', ' ') }.joinToString("\n", postfix = "\n") val header = errors.map { "// ERROR: " + DefaultErrorMessages.render(it).replace('\n', ' ') }.joinToString("\n", postfix = "\n")
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.core.CollectingNameValidator import org.jetbrains.kotlin.idea.core.CollectingNameValidator
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
@@ -98,7 +98,7 @@ class KotlinGenerateEqualsAndHashcodeAction : KotlinGenerateMemberActionBase<Kot
override fun prepareMembersInfo(klass: KtClassOrObject, project: Project, editor: Editor?): Info? { override fun prepareMembersInfo(klass: KtClassOrObject, project: Project, editor: Editor?): Info? {
if (klass !is KtClass) throw AssertionError("Not a class: ${klass.getElementTextWithContext()}") if (klass !is KtClass) throw AssertionError("Not a class: ${klass.getElementTextWithContext()}")
val context = klass.analyzeWithDeclarations() val context = klass.analyzeWithContent()
val classDescriptor = context.get(BindingContext.CLASS, klass) ?: return null val classDescriptor = context.get(BindingContext.CLASS, klass) ?: return null
val equalsDescriptor = classDescriptor.findDeclaredEquals(false) val equalsDescriptor = classDescriptor.findDeclaredEquals(false)
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.core.CollectingNameValidator import org.jetbrains.kotlin.idea.core.CollectingNameValidator
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
@@ -104,7 +104,7 @@ class KotlinGenerateSecondaryConstructorAction : KotlinGenerateMemberActionBase<
} }
override fun prepareMembersInfo(klass: KtClassOrObject, project: Project, editor: Editor?): Info? { override fun prepareMembersInfo(klass: KtClassOrObject, project: Project, editor: Editor?): Info? {
val context = klass.analyzeWithDeclarations() val context = klass.analyzeWithContent()
val classDescriptor = context.get(BindingContext.CLASS, klass) ?: return null val classDescriptor = context.get(BindingContext.CLASS, klass) ?: return null
val superConstructors = chooseSuperConstructors(klass, classDescriptor).map { it.descriptor as ConstructorDescriptor } val superConstructors = chooseSuperConstructors(klass, classDescriptor).map { it.descriptor as ConstructorDescriptor }
val propertiesToInitialize = choosePropertiesToInitialize(klass, context).map { it.descriptor as PropertyDescriptor } val propertiesToInitialize = choosePropertiesToInitialize(klass, context).map { it.descriptor as PropertyDescriptor }
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor import org.jetbrains.kotlin.idea.caches.resolve.unsafeResolveToDescriptor
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.core.insertMembersAfter import org.jetbrains.kotlin.idea.core.insertMembersAfter
@@ -132,7 +132,7 @@ class KotlinGenerateToStringAction : KotlinGenerateMemberActionBase<KotlinGenera
override fun prepareMembersInfo(klass: KtClassOrObject, project: Project, editor: Editor?): Info? { override fun prepareMembersInfo(klass: KtClassOrObject, project: Project, editor: Editor?): Info? {
if (klass !is KtClass) throw AssertionError("Not a class: ${klass.getElementTextWithContext()}") if (klass !is KtClass) throw AssertionError("Not a class: ${klass.getElementTextWithContext()}")
val context = klass.analyzeWithDeclarations() val context = klass.analyzeWithContent()
val classDescriptor = context.get(BindingContext.CLASS, klass) ?: return null val classDescriptor = context.get(BindingContext.CLASS, klass) ?: return null
classDescriptor.findDeclaredToString(false)?.let { classDescriptor.findDeclaredToString(false)?.let {
@@ -32,7 +32,7 @@ class CopyAsDiagnosticTestAction : AnAction() {
val psiFile = e.getData(CommonDataKeys.PSI_FILE) val psiFile = e.getData(CommonDataKeys.PSI_FILE)
assert(editor != null && psiFile != null) assert(editor != null && psiFile != null)
val bindingContext = (psiFile as KtFile).analyzeWithDeclarations() val bindingContext = (psiFile as KtFile).analyzeWithContent()
val diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors( val diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(
bindingContext, psiFile, false, null, null, false bindingContext, psiFile, false, null, null, false
@@ -44,7 +44,7 @@ class PlainTextPasteImportResolver(val dataForConversion: DataForConversion, val
private val importList = file.importList!! private val importList = file.importList!!
private val psiElementFactory = PsiElementFactory.SERVICE.getInstance(project) private val psiElementFactory = PsiElementFactory.SERVICE.getInstance(project)
private val bindingContext by lazy { targetFile.analyzeWithDeclarations() } private val bindingContext by lazy { targetFile.analyzeWithContent() }
private val resolutionFacade = targetFile.getResolutionFacade() private val resolutionFacade = targetFile.getResolutionFacade()
private val shortNameCache = PsiShortNamesCache.getInstance(project) private val shortNameCache = PsiShortNamesCache.getInstance(project)
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.MemberDescriptor import org.jetbrains.kotlin.descriptors.MemberDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.diagnostics.DiagnosticSink import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.addRemoveModifier.addModifier import org.jetbrains.kotlin.psi.addRemoveModifier.addModifier
@@ -50,7 +50,7 @@ class AddVarianceModifierInspection : AbstractKotlinInspection() {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor { override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
return classOrObjectVisitor { klass -> return classOrObjectVisitor { klass ->
val context = klass.analyzeWithDeclarations() val context = klass.analyzeWithContent()
for (typeParameter in klass.typeParameters) { for (typeParameter in klass.typeParameters) {
if (typeParameter.variance != Variance.INVARIANT) continue if (typeParameter.variance != Variance.INVARIANT) continue
val parameterDescriptor = val parameterDescriptor =
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor import com.intellij.openapi.editor.Editor
import com.intellij.openapi.util.TextRange import com.intellij.openapi.util.TextRange
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection import org.jetbrains.kotlin.idea.inspections.IntentionBasedInspection
import org.jetbrains.kotlin.idea.util.CommentSaver import org.jetbrains.kotlin.idea.util.CommentSaver
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
@@ -59,7 +59,7 @@ class ConvertSecondaryConstructorToPrimaryIntention : SelfTargetingRangeIntentio
val klass = element.containingClassOrObject ?: return null val klass = element.containingClassOrObject ?: return null
if (klass.hasPrimaryConstructor()) return null if (klass.hasPrimaryConstructor()) return null
val context = klass.analyzeWithDeclarations() val context = klass.analyzeWithContent()
val classDescriptor = context[BindingContext.CLASS, klass] ?: return null val classDescriptor = context[BindingContext.CLASS, klass] ?: return null
val elementDescriptor = context[BindingContext.CONSTRUCTOR, element] ?: return null val elementDescriptor = context[BindingContext.CONSTRUCTOR, element] ?: return null
@@ -154,7 +154,7 @@ class ConvertSecondaryConstructorToPrimaryIntention : SelfTargetingRangeIntentio
override fun applyTo(element: KtSecondaryConstructor, editor: Editor?) { override fun applyTo(element: KtSecondaryConstructor, editor: Editor?) {
val klass = element.containingClassOrObject as? KtClass ?: return val klass = element.containingClassOrObject as? KtClass ?: return
val context = klass.analyzeWithDeclarations() val context = klass.analyzeWithContent()
val factory = KtPsiFactory(klass) val factory = KtPsiFactory(klass)
val constructorCommentSaver = CommentSaver(element) val constructorCommentSaver = CommentSaver(element)
val constructorInClass = klass.createPrimaryConstructorIfAbsent() val constructorInClass = klass.createPrimaryConstructorIfAbsent()
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType
@@ -61,7 +61,7 @@ class MapPlatformClassToKotlinFix(
override fun getFamilyName() = "Change to Kotlin class" override fun getFamilyName() = "Change to Kotlin class"
public override fun invoke(project: Project, editor: Editor?, file: KtFile) { public override fun invoke(project: Project, editor: Editor?, file: KtFile) {
val bindingContext = file.analyzeWithDeclarations() val bindingContext = file.analyzeWithContent()
val imports = ArrayList<KtImportDirective>() val imports = ArrayList<KtImportDirective>()
val usages = ArrayList<KtUserType>() val usages = ArrayList<KtUserType>()
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages import org.jetbrains.kotlin.diagnostics.rendering.DefaultErrorMessages
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
import org.jetbrains.kotlin.idea.util.approximateWithResolvableType import org.jetbrains.kotlin.idea.util.approximateWithResolvableType
@@ -51,7 +51,7 @@ class QuickFixFactoryForTypeMismatchError : KotlinIntentionActionsFactory() {
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction> { override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction> {
val actions = LinkedList<IntentionAction>() val actions = LinkedList<IntentionAction>()
val context = (diagnostic.psiFile as KtFile).analyzeWithDeclarations() val context = (diagnostic.psiFile as KtFile).analyzeWithContent()
val diagnosticElement = diagnostic.psiElement val diagnosticElement = diagnostic.psiElement
if (diagnosticElement !is KtExpression) { if (diagnosticElement !is KtExpression) {
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.core.ShortenReferences import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.overrideImplement.OverrideMemberChooserObject import org.jetbrains.kotlin.idea.core.overrideImplement.OverrideMemberChooserObject
import org.jetbrains.kotlin.idea.core.overrideImplement.generateMember import org.jetbrains.kotlin.idea.core.overrideImplement.generateMember
@@ -44,7 +44,7 @@ class SpecifyOverrideExplicitlyFix(
override fun invoke(project: Project, editor: Editor?, file: KtFile) { override fun invoke(project: Project, editor: Editor?, file: KtFile) {
val element = element ?: return val element = element ?: return
val context = element.analyzeWithDeclarations() val context = element.analyzeWithContent()
val delegatedDescriptor = context.diagnostics.forElement(element).mapNotNull { val delegatedDescriptor = context.diagnostics.forElement(element).mapNotNull {
if (it.factory == Errors.DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE) if (it.factory == Errors.DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE)
Errors.DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE.cast(it).a Errors.DELEGATED_MEMBER_HIDES_SUPERTYPE_OVERRIDE.cast(it).a
@@ -23,7 +23,7 @@ import com.intellij.psi.PsiElement
import com.intellij.psi.util.PsiTreeUtil import com.intellij.psi.util.PsiTreeUtil
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
import org.jetbrains.kotlin.checkers.AbstractPsiCheckerTest import org.jetbrains.kotlin.checkers.AbstractPsiCheckerTest
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
import org.jetbrains.kotlin.idea.completion.test.AbstractJvmBasicCompletionTest import org.jetbrains.kotlin.idea.completion.test.AbstractJvmBasicCompletionTest
import org.jetbrains.kotlin.idea.completion.test.ExpectedCompletionUtils import org.jetbrains.kotlin.idea.completion.test.ExpectedCompletionUtils
@@ -127,7 +127,7 @@ private fun JavaCodeInsightTestFixture.configureByCodeFragment(filePath: String)
if (typeStr != null) { if (typeStr != null) {
file.putCopyableUserData(KtCodeFragment.RUNTIME_TYPE_EVALUATOR, { file.putCopyableUserData(KtCodeFragment.RUNTIME_TYPE_EVALUATOR, {
val codeFragment = KtPsiFactory(project).createBlockCodeFragment("val xxx: $typeStr", PsiTreeUtil.getParentOfType(elementAt, KtElement::class.java)) val codeFragment = KtPsiFactory(project).createBlockCodeFragment("val xxx: $typeStr", PsiTreeUtil.getParentOfType(elementAt, KtElement::class.java))
val context = codeFragment.analyzeWithDeclarations() val context = codeFragment.analyzeWithContent()
val typeReference: KtTypeReference = PsiTreeUtil.getChildOfType(codeFragment.getContentElement().firstChild, KtTypeReference::class.java)!! val typeReference: KtTypeReference = PsiTreeUtil.getChildOfType(codeFragment.getContentElement().firstChild, KtTypeReference::class.java)!!
context[BindingContext.TYPE, typeReference] context[BindingContext.TYPE, typeReference]
}) })
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer import org.jetbrains.kotlin.cli.common.messages.MessageRenderer
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector
import org.jetbrains.kotlin.diagnostics.Severity import org.jetbrains.kotlin.diagnostics.Severity
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithDeclarations import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor import org.jetbrains.kotlin.idea.test.KotlinJdkAndLibraryProjectDescriptor
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
@@ -45,7 +45,7 @@ class NoErrorsInStdlibTest : KotlinLightCodeInsightFixtureTestCase() {
val psiFile = psiManager.findFile(file) val psiFile = psiManager.findFile(file)
if (psiFile is KtFile) { if (psiFile is KtFile) {
hasAtLeastOneFile = true hasAtLeastOneFile = true
val bindingContext = psiFile.analyzeWithDeclarations() val bindingContext = psiFile.analyzeWithContent()
val errors = bindingContext.diagnostics.all().filter { it.severity == Severity.ERROR } val errors = bindingContext.diagnostics.all().filter { it.severity == Severity.ERROR }
if (errors.isNotEmpty()) { if (errors.isNotEmpty()) {