ReplaceWith annotation resolver: use module from resolution facade to build imports scope
#KT-15873 Fixed Using module from original element may lead to exceptions as it could be <built-ins module> (after deprecation of `mod` operator)
This commit is contained in:
+5
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2016 JetBrains s.r.o.
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,10 +19,10 @@ package org.jetbrains.kotlin.idea.quickfix.replaceWith
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.analysis.analyzeInContext
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveImportReference
|
||||
import org.jetbrains.kotlin.idea.codeInliner.CodeToInline
|
||||
import org.jetbrains.kotlin.idea.codeInliner.CodeToInlineBuilder
|
||||
import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.idea.codeInliner.CodeToInlineBuilder
|
||||
import org.jetbrains.kotlin.idea.codeInliner.CodeToInline
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -32,9 +32,7 @@ import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtUserType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.lazy.DefaultImportProvider
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSupport
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
@@ -42,7 +40,6 @@ import org.jetbrains.kotlin.resolve.scopes.utils.chainImportingScopes
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.types.expressions.PreliminaryDeclarationVisitor
|
||||
import java.util.*
|
||||
|
||||
data class ReplaceWith(val pattern: String, val imports: List<String>)
|
||||
@@ -73,7 +70,7 @@ object ReplaceWithAnnotationAnalyzer {
|
||||
return null
|
||||
}
|
||||
|
||||
val module = symbolDescriptor.module
|
||||
val module = resolutionFacade.moduleDescriptor
|
||||
val explicitImportsScope = buildExplicitImportsScope(annotation, resolutionFacade, module)
|
||||
val defaultImportsScopes = buildDefaultImportsScopes(resolutionFacade, module)
|
||||
val scope = getResolutionScope(symbolDescriptor, symbolDescriptor,
|
||||
@@ -103,7 +100,7 @@ object ReplaceWithAnnotationAnalyzer {
|
||||
}
|
||||
if (typeReference.typeElement !is KtUserType) return null
|
||||
|
||||
val module = symbolDescriptor.module
|
||||
val module = resolutionFacade.moduleDescriptor
|
||||
|
||||
val explicitImportsScope = buildExplicitImportsScope(annotation, resolutionFacade, module)
|
||||
val defaultImportScopes = buildDefaultImportsScopes(resolutionFacade, module)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with 'rem(other)'" "true"
|
||||
|
||||
fun test() {
|
||||
1.<caret>mod(3)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Replace with 'rem(other)'" "true"
|
||||
|
||||
fun test() {
|
||||
1.rem(3)
|
||||
}
|
||||
@@ -4495,6 +4495,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("replaceModToRem.kt")
|
||||
public void testReplaceModToRem() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/replaceModToRem.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("shortenReferences.kt")
|
||||
public void testShortenReferences() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/shortenReferences.kt");
|
||||
|
||||
Reference in New Issue
Block a user