Renamed object and its methods.
This commit is contained in:
+11
-12
@@ -29,13 +29,19 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.*
|
||||
import java.util.*
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
|
||||
// TODO rename it it DescriptorToSourceIde
|
||||
public object DescriptorToDeclarationUtil {
|
||||
public fun getDeclaration(project: Project, descriptor: DeclarationDescriptor): PsiElement? {
|
||||
return getPsiElementsStream(project, descriptor).firstOrNull()
|
||||
public object DescriptorToSourceUtilsIde {
|
||||
public fun getAnyDeclaration(project: Project, descriptor: DeclarationDescriptor): PsiElement? {
|
||||
return getDeclarationsStream(project, descriptor).firstOrNull()
|
||||
}
|
||||
|
||||
private fun getPsiElementsStream(project: Project, targetDescriptor: DeclarationDescriptor): Stream<PsiElement> {
|
||||
public fun getAllDeclarations(project: Project, targetDescriptor: DeclarationDescriptor): Collection<PsiElement> {
|
||||
val result = getDeclarationsStream(project, targetDescriptor).toHashSet()
|
||||
// filter out elements which are navigate to some other element of the result
|
||||
// this is needed to avoid duplicated results for references to declaration in same library source file
|
||||
return result.filter { element -> result.none { element != it && it.getNavigationElement() == element } }
|
||||
}
|
||||
|
||||
private fun getDeclarationsStream(project: Project, targetDescriptor: DeclarationDescriptor): Stream<PsiElement> {
|
||||
val effectiveReferencedDescriptors = DescriptorToSourceUtils.getEffectiveReferencedDescriptors(targetDescriptor).stream()
|
||||
return effectiveReferencedDescriptors.flatMap {
|
||||
streamOf(
|
||||
@@ -46,13 +52,6 @@ public object DescriptorToDeclarationUtil {
|
||||
}.filterNotNull()
|
||||
}
|
||||
|
||||
public fun resolveToPsiElements(project: Project, targetDescriptor: DeclarationDescriptor): Collection<PsiElement> {
|
||||
val result = getPsiElementsStream(project, targetDescriptor).toHashSet()
|
||||
// filter out elements which are navigate to some other element of the result
|
||||
// this is needed to avoid duplicated results for references to declaration in same library source file
|
||||
return result.filter { element -> result.none { element != it && it.getNavigationElement() == element } }
|
||||
}
|
||||
|
||||
private fun findBuiltinDeclaration(project: Project, descriptor: DeclarationDescriptor): PsiElement? {
|
||||
val libraryReferenceResolver = project.getComponent(javaClass<BuiltInsReferenceResolver>())
|
||||
return libraryReferenceResolver!!.resolveBuiltInSymbol(descriptor)
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import java.util.Collections
|
||||
import org.jetbrains.kotlin.psi.JetReferenceExpression
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.psi.JetElement
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
@@ -101,7 +101,7 @@ public abstract class AbstractJetReference<T : JetElement>(element: T)
|
||||
return psiFacade.findPackage(fqName).singletonOrEmptyList()
|
||||
}
|
||||
else {
|
||||
return DescriptorToDeclarationUtil.resolveToPsiElements(expression.getProject(), targetDescriptor)
|
||||
return DescriptorToSourceUtilsIde.getAllDeclarations(expression.getProject(), targetDescriptor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.idea.structureView
|
||||
import com.intellij.ide.util.InheritedMembersNodeProvider
|
||||
import com.intellij.ide.util.treeView.smartTree.TreeElement
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
@@ -51,7 +51,7 @@ public class KotlinInheritedMembersNodeProvider: InheritedMembersNodeProvider<Tr
|
||||
when (memberDescriptor.getKind()) {
|
||||
CallableMemberDescriptor.Kind.FAKE_OVERRIDE,
|
||||
CallableMemberDescriptor.Kind.DELEGATION -> {
|
||||
val superTypeMember = DescriptorToDeclarationUtil.getDeclaration(project, memberDescriptor)
|
||||
val superTypeMember = DescriptorToSourceUtilsIde.getAnyDeclaration(project, memberDescriptor)
|
||||
if (superTypeMember is NavigatablePsiElement) {
|
||||
children.add(JetStructureViewElement(superTypeMember, memberDescriptor, true))
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.descriptors.ClassKind;
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.Modality;
|
||||
import org.jetbrains.kotlin.idea.JetBundle;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde;
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||
import org.jetbrains.kotlin.idea.util.ShortenReferences;
|
||||
import org.jetbrains.kotlin.psi.JetClass;
|
||||
@@ -78,7 +78,7 @@ public class JetAddFunctionToClassifierAction implements QuestionAction {
|
||||
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
final JetClass classifierDeclaration = (JetClass) DescriptorToDeclarationUtil.INSTANCE$.getDeclaration(project, typeDescriptor);
|
||||
final JetClass classifierDeclaration = (JetClass) DescriptorToSourceUtilsIde.INSTANCE$.getAnyDeclaration(project, typeDescriptor);
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqNameSafe
|
||||
import org.jetbrains.kotlin.idea.references.JetSimpleNameReference
|
||||
import org.jetbrains.kotlin.idea.JetDescriptorIconProvider
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
|
||||
/**
|
||||
* Automatically adds import directive to the file for resolving reference.
|
||||
@@ -64,7 +64,7 @@ public class JetAddImportAction(
|
||||
}
|
||||
|
||||
private fun detectPriority(descriptor: DeclarationDescriptor): Priority {
|
||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor)
|
||||
val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor)
|
||||
return when {
|
||||
declaration == null -> Priority.OTHER
|
||||
ModuleUtilCore.findModuleForPsiElement(declaration) == module -> Priority.MODULE
|
||||
@@ -90,7 +90,7 @@ public class JetAddImportAction(
|
||||
}
|
||||
}.first()
|
||||
}
|
||||
val declarationToImport = DescriptorToDeclarationUtil.getDeclaration(project, descriptorToImport)
|
||||
val declarationToImport = DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptorToImport)
|
||||
}
|
||||
|
||||
private val variants = candidates
|
||||
|
||||
@@ -69,7 +69,7 @@ public abstract class OverrideImplementMethodsHandler implements LanguageCodeIns
|
||||
) {
|
||||
List<DescriptorClassMember> members = new ArrayList<DescriptorClassMember>();
|
||||
for (CallableMemberDescriptor memberDescriptor : missingImplementations) {
|
||||
PsiElement declaration = DescriptorToDeclarationUtil.INSTANCE$.getDeclaration(file.getProject(), memberDescriptor);
|
||||
PsiElement declaration = DescriptorToSourceUtilsIde.INSTANCE$.getAnyDeclaration(file.getProject(), memberDescriptor);
|
||||
if (declaration == null) {
|
||||
LOG.error("Can not find declaration for descriptor " + memberDescriptor);
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
|
||||
if (getterDescriptor != null && !getterDescriptor.isDefault()) {
|
||||
val delegatedResolvedCall = bindingContext[BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, getterDescriptor]
|
||||
if (delegatedResolvedCall == null) {
|
||||
val getter = DescriptorToDeclarationUtil.getDeclaration(file.getProject(), getterDescriptor)
|
||||
val getter = DescriptorToSourceUtilsIde.getAnyDeclaration(file.getProject(), getterDescriptor)
|
||||
if (getter is JetPropertyAccessor && (getter.getBodyExpression() != null || getter.getEqualsToken() != null)) {
|
||||
val psiMethod = LightClassUtil.getLightClassAccessorMethod(getter)
|
||||
if (psiMethod != null) {
|
||||
@@ -143,7 +143,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
|
||||
else {
|
||||
val delegatedPropertyGetterDescriptor = delegatedResolvedCall.getResultingDescriptor()
|
||||
if (delegatedPropertyGetterDescriptor is CallableMemberDescriptor) {
|
||||
val function = DescriptorToDeclarationUtil.getDeclaration(file.getProject(), delegatedPropertyGetterDescriptor)
|
||||
val function = DescriptorToSourceUtilsIde.getAnyDeclaration(file.getProject(), delegatedPropertyGetterDescriptor)
|
||||
if (function is JetNamedFunction) {
|
||||
val psiMethod = LightClassUtil.getLightClassMethod(function)
|
||||
if (psiMethod != null) {
|
||||
@@ -165,7 +165,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
|
||||
val descriptor = resolvedCall.getResultingDescriptor()
|
||||
if (descriptor is CallableMemberDescriptor) {
|
||||
// TODO doesn't work for libraries
|
||||
val function = DescriptorToDeclarationUtil.getDeclaration(file.getProject(), descriptor)
|
||||
val function = DescriptorToSourceUtilsIde.getAnyDeclaration(file.getProject(), descriptor)
|
||||
if (function is JetNamedFunction) {
|
||||
val psiMethod = LightClassUtil.getLightClassMethod(function)
|
||||
if (psiMethod != null) {
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||
import com.intellij.psi.NavigatablePsiElement
|
||||
import java.awt.event.MouseEvent
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.codeInsight.daemon.impl.PsiElementListNavigator
|
||||
import org.jetbrains.kotlin.idea.JetBundle
|
||||
@@ -82,7 +82,7 @@ public class SuperDeclarationMarkerNavigationHandler : GutterIconNavigationHandl
|
||||
|
||||
val superDeclarations = ArrayList<NavigatablePsiElement>()
|
||||
for (overriddenMember in overriddenDescriptors) {
|
||||
val declarations = DescriptorToDeclarationUtil.resolveToPsiElements(element.getProject(), overriddenMember)
|
||||
val declarations = DescriptorToSourceUtilsIde.getAllDeclarations(element.getProject(), overriddenMember)
|
||||
for (declaration in declarations) {
|
||||
if (declaration is NavigatablePsiElement) {
|
||||
superDeclarations.add(declaration as NavigatablePsiElement)
|
||||
|
||||
@@ -58,7 +58,7 @@ import org.jetbrains.kotlin.psi.JetProperty
|
||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
||||
import org.jetbrains.kotlin.idea.refactoring.reportDeclarationConflict
|
||||
import org.jetbrains.kotlin.idea.refactoring.getContainingScope
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.idea.util.ShortenReferences
|
||||
|
||||
public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention<JetNamedFunction>(
|
||||
@@ -128,7 +128,7 @@ public class ConvertFunctionToPropertyIntention : JetSelfTargetingIntention<JetN
|
||||
callableDescriptor.getContainingScope(bindingContext)
|
||||
?.getProperties(callableDescriptor.getName())
|
||||
?.firstOrNull()
|
||||
?.let { DescriptorToDeclarationUtil.getDeclaration(project, it) }
|
||||
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
|
||||
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ import org.jetbrains.kotlin.codegen.PropertyCodegen
|
||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
||||
import org.jetbrains.kotlin.idea.refactoring.reportDeclarationConflict
|
||||
import org.jetbrains.kotlin.idea.refactoring.getContainingScope
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
|
||||
public class ConvertPropertyToFunctionIntention : JetSelfTargetingIntention<JetProperty>(
|
||||
"convert.property.to.function.intention", javaClass()
|
||||
@@ -110,7 +110,7 @@ public class ConvertPropertyToFunctionIntention : JetSelfTargetingIntention<JetP
|
||||
callableDescriptor.getContainingScope(bindingContext)
|
||||
?.getFunctions(callableDescriptor.getName())
|
||||
?.firstOrNull { it.getValueParameters().isEmpty() }
|
||||
?.let { DescriptorToDeclarationUtil.getDeclaration(project, it) }
|
||||
?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }
|
||||
?.let { reportDeclarationConflict(conflicts, it) { "$it already exists" } }
|
||||
}
|
||||
else if (callable is PsiMethod) {
|
||||
|
||||
@@ -50,7 +50,7 @@ import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink;
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.KotlinCacheService;
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde;
|
||||
import org.jetbrains.kotlin.idea.util.InfinitePeriodicalTask;
|
||||
import org.jetbrains.kotlin.idea.util.LongRunningReadTask;
|
||||
import org.jetbrains.kotlin.idea.util.ProjectRootsUtil;
|
||||
@@ -206,7 +206,7 @@ public class KotlinBytecodeToolWindow extends JPanel implements Disposable {
|
||||
if (descriptor instanceof SimpleFunctionDescriptor &&
|
||||
((SimpleFunctionDescriptor) descriptor).getInlineStrategy().isInline()) {
|
||||
PsiElement declaration =
|
||||
DescriptorToDeclarationUtil.INSTANCE$.getDeclaration(project, descriptor);
|
||||
DescriptorToSourceUtilsIde.INSTANCE$.getAnyDeclaration(project, descriptor);
|
||||
if (declaration != null && declaration instanceof JetElement) {
|
||||
collectedElements.add((JetElement) declaration);
|
||||
}
|
||||
|
||||
@@ -34,14 +34,13 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticWithParameters2;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.idea.JetBundle;
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde;
|
||||
import org.jetbrains.kotlin.idea.refactoring.JetNameSuggester;
|
||||
import org.jetbrains.kotlin.idea.refactoring.JetNameValidator;
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetParameterInfo;
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
|
||||
|
||||
@@ -82,7 +81,7 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
||||
return false;
|
||||
}
|
||||
|
||||
Collection<PsiElement> declarations = DescriptorToDeclarationUtil.INSTANCE$.resolveToPsiElements(project, functionDescriptor);
|
||||
Collection<PsiElement> declarations = DescriptorToSourceUtilsIde.INSTANCE$.getAllDeclarations(project, functionDescriptor);
|
||||
if (declarations.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.kotlin.idea.JetBundle
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.command.CommandProcessor
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.psi.JetClassOrObject
|
||||
import org.jetbrains.kotlin.idea.refactoring.chooseContainerElementIfNecessary
|
||||
import org.jetbrains.kotlin.psi.JetClassBody
|
||||
@@ -54,7 +54,7 @@ public class CreateCallableFromUsageFix(
|
||||
|
||||
private fun getDeclarationIfApplicable(project: Project, candidate: TypeCandidate): PsiElement? {
|
||||
val descriptor = candidate.theType.getConstructor().getDeclarationDescriptor()
|
||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor) ?: return null
|
||||
val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor) ?: return null
|
||||
if (declaration !is JetClassOrObject && declaration !is PsiClass) return null
|
||||
return if (isExtension || declaration.canRefactor()) declaration else null
|
||||
}
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.quickfix.JetIntentionActionsFactory
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.idea.refactoring.*
|
||||
@@ -124,7 +124,7 @@ object CreateFunctionOrPropertyFromCallActionFactory : JetIntentionActionsFactor
|
||||
if (qualifierType != null) return TypeInfo(qualifierType, Variance.IN_VARIANCE)
|
||||
|
||||
val classifier = receiver.classifier as? JavaClassDescriptor ?: return null
|
||||
val javaClass = DescriptorToDeclarationUtil.getDeclaration(project, classifier) as? PsiClass
|
||||
val javaClass = DescriptorToSourceUtilsIde.getAnyDeclaration(project, classifier) as? PsiClass
|
||||
if (javaClass == null || !javaClass.canRefactor()) return null
|
||||
TypeInfo.StaticContextRequired(TypeInfo(classifier.getDefaultType(), Variance.IN_VARIANCE))
|
||||
}
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import com.intellij.psi.JavaPsiFacade
|
||||
import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.guessTypes
|
||||
@@ -61,7 +61,7 @@ private fun getTargetParentByQualifier(
|
||||
!isQualified ->
|
||||
file
|
||||
qualifierDescriptor is ClassDescriptor ->
|
||||
DescriptorToDeclarationUtil.getDeclaration(project, qualifierDescriptor)
|
||||
DescriptorToSourceUtilsIde.getAnyDeclaration(project, qualifierDescriptor)
|
||||
qualifierDescriptor is PackageViewDescriptor ->
|
||||
if (qualifierDescriptor.getFqName() != file.getPackageFqName()) {
|
||||
JavaPsiFacade.getInstance(project).findPackage(qualifierDescriptor.getFqName().asString())
|
||||
|
||||
+2
-2
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.psi.JetValueArgument
|
||||
import org.jetbrains.kotlin.psi.JetCallElement
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.idea.refactoring.canRefactor
|
||||
import org.jetbrains.kotlin.psi.JetFunction
|
||||
import org.jetbrains.kotlin.psi.JetClass
|
||||
@@ -46,7 +46,7 @@ public object CreateParameterByNamedArgumentActionFactory: JetSingleIntentionAct
|
||||
|
||||
val callElement = argument.getStrictParentOfType<JetCallElement>() ?: return null
|
||||
val functionDescriptor = callElement.getResolvedCall(context)?.getResultingDescriptor() as? FunctionDescriptor ?: return null
|
||||
val callable = DescriptorToDeclarationUtil.getDeclaration(callElement.getProject(), functionDescriptor) ?: return null
|
||||
val callable = DescriptorToSourceUtilsIde.getAnyDeclaration(callElement.getProject(), functionDescriptor) ?: return null
|
||||
if (!((callable is JetFunction || callable is JetClass) && callable.canRefactor())) return null
|
||||
|
||||
val anyType = KotlinBuiltIns.getInstance().getAnyType()
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
|
||||
import java.util.HashSet
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.asJava.toLightMethods
|
||||
import org.jetbrains.kotlin.asJava.namedUnwrappedElement
|
||||
import org.jetbrains.kotlin.psi.JetCallableDeclaration
|
||||
@@ -171,7 +171,7 @@ public abstract class CallableRefactoring<T: CallableDescriptor>(
|
||||
}
|
||||
|
||||
fun getAffectedCallables(project: Project, descriptorsForChange: Collection<CallableDescriptor>): List<PsiElement> {
|
||||
val baseCallables = descriptorsForChange.map { DescriptorToDeclarationUtil.getDeclaration(project, it) }.filterNotNull()
|
||||
val baseCallables = descriptorsForChange.map { DescriptorToSourceUtilsIde.getAnyDeclaration(project, it) }.filterNotNull()
|
||||
return baseCallables + baseCallables.flatMap { it.toLightMethods() }.flatMapTo(HashSet<PsiElement>()) { psiMethod ->
|
||||
val overrides = OverridingMethodsSearch.search(psiMethod).findAll()
|
||||
overrides.map { method -> method.namedUnwrappedElement ?: method}
|
||||
|
||||
@@ -45,7 +45,7 @@ import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor;
|
||||
import org.jetbrains.kotlin.idea.JetBundle;
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde;
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers;
|
||||
import org.jetbrains.kotlin.idea.util.string.StringPackage;
|
||||
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken;
|
||||
@@ -139,7 +139,7 @@ public class JetRefactoringUtil {
|
||||
Project project = declaration.getProject();
|
||||
Map<PsiElement, CallableDescriptor> overriddenElementsToDescriptor = new HashMap<PsiElement, CallableDescriptor>();
|
||||
for (CallableDescriptor overriddenDescriptor : DescriptorUtils.getAllOverriddenDescriptors(declarationDescriptor)) {
|
||||
PsiElement overriddenDeclaration = DescriptorToDeclarationUtil.INSTANCE$.getDeclaration(project, overriddenDescriptor);
|
||||
PsiElement overriddenDeclaration = DescriptorToSourceUtilsIde.INSTANCE$.getAnyDeclaration(project, overriddenDescriptor);
|
||||
if (PsiTreeUtil.instanceOf(overriddenDeclaration, JetNamedFunction.class, JetProperty.class, PsiMethod.class)) {
|
||||
overriddenElementsToDescriptor.put(overriddenDeclaration, overriddenDescriptor);
|
||||
}
|
||||
|
||||
+2
-2
@@ -30,7 +30,7 @@ import org.jetbrains.kotlin.renderer.DescriptorRenderer
|
||||
import java.util.*
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.*
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.idea.quickfix.QuickFixUtil
|
||||
import com.intellij.CommonBundle
|
||||
import com.intellij.refactoring.RefactoringBundle
|
||||
@@ -93,7 +93,7 @@ public class JetChangeSignature(project: Project,
|
||||
|
||||
fun createChangeSignatureDialog(descriptorsForSignatureChange: Collection<FunctionDescriptor>): JetChangeSignatureDialog? {
|
||||
val baseDescriptor = preferContainedInClass(descriptorsForSignatureChange)
|
||||
val functionDeclaration = DescriptorToDeclarationUtil.getDeclaration(project, baseDescriptor)
|
||||
val functionDeclaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, baseDescriptor)
|
||||
if (functionDeclaration == null) {
|
||||
LOG.error("Could not find declaration for $baseDescriptor")
|
||||
return null
|
||||
|
||||
+2
-2
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.*
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.JetFunctionDefinitionUsage
|
||||
|
||||
import java.util.*
|
||||
@@ -84,7 +84,7 @@ public class JetChangeSignatureData(
|
||||
|
||||
override val primaryFunctions: Collection<JetFunctionDefinitionUsage<PsiElement>> by Delegates.lazy {
|
||||
descriptorsForSignatureChange.map {
|
||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(baseDeclaration.getProject(), it)
|
||||
val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(baseDeclaration.getProject(), it)
|
||||
assert(declaration != null) { "No declaration found for " + baseDescriptor }
|
||||
JetFunctionDefinitionUsage<PsiElement>(declaration, it, null, null)
|
||||
}
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde;
|
||||
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle;
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaCallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
@@ -109,7 +109,7 @@ public class JetChangeSignatureHandler implements ChangeSignatureHandler {
|
||||
}
|
||||
|
||||
if (functionDescriptor instanceof JavaCallableMemberDescriptor) {
|
||||
PsiElement declaration = DescriptorToDeclarationUtil.INSTANCE$.getDeclaration(project, functionDescriptor);
|
||||
PsiElement declaration = DescriptorToSourceUtilsIde.INSTANCE$.getAnyDeclaration(project, functionDescriptor);
|
||||
assert declaration instanceof PsiMethod : "PsiMethod expected: " + functionDescriptor;
|
||||
ChangeSignatureUtil.invokeChangeSignatureOn((PsiMethod) declaration, project);
|
||||
return;
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde;
|
||||
import org.jetbrains.kotlin.idea.codeInsight.JetFileReferencesResolver;
|
||||
import org.jetbrains.kotlin.idea.refactoring.RefactoringPackage;
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.*;
|
||||
@@ -444,7 +444,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
|
||||
//noinspection ConstantConditions
|
||||
CallableDescriptor descriptor =
|
||||
CallUtilPackage.getResolvedCall(originalRef, originalContext).getCandidateDescriptor();
|
||||
PsiElement declaration = DescriptorToDeclarationUtil.INSTANCE$.getDeclaration(callable.getProject(), descriptor);
|
||||
PsiElement declaration = DescriptorToSourceUtilsIde.INSTANCE$.getAnyDeclaration(callable.getProject(), descriptor);
|
||||
String prefix = declaration != null ? RefactoringUIUtil.getDescription(declaration, true) : originalRef.getText();
|
||||
result.putValue(
|
||||
originalRef,
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ import java.util.HashMap
|
||||
import org.jetbrains.kotlin.idea.codeInsight.JetFileReferencesResolver
|
||||
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import java.util.Collections
|
||||
import org.jetbrains.kotlin.psi.JetBlockExpression
|
||||
import org.jetbrains.kotlin.psi.JetQualifiedExpression
|
||||
@@ -135,7 +135,7 @@ data class ExtractionData(
|
||||
val descriptor = context[BindingContext.REFERENCE_TARGET, ref]
|
||||
if (descriptor == null) continue
|
||||
|
||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor) as? PsiNamedElement
|
||||
val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor) as? PsiNamedElement
|
||||
?: if (isExtractableIt(descriptor, context)) itFakeDeclaration else continue
|
||||
|
||||
val offset = ref.getTextRange()!!.getStartOffset() - originalStartOffset
|
||||
|
||||
+3
-3
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.cfg.pseudocode.*
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.idea.refactoring.JetNameValidatorImpl
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.idea.imports.canBeReferencedViaImport
|
||||
import com.intellij.psi.PsiNamedElement
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
@@ -199,7 +199,7 @@ private fun ExtractionData.getLocalDeclarationsWithNonLocalUsages(
|
||||
pseudocode.traverse(TraversalOrder.FORWARD) { instruction ->
|
||||
if (instruction !in localInstructions) {
|
||||
instruction.getPrimaryDeclarationDescriptorIfAny(bindingContext)?.let { descriptor ->
|
||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(project, descriptor)
|
||||
val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(project, descriptor)
|
||||
if (declaration is JetNamedDeclaration && declaration.isInsideOf(originalElements)) {
|
||||
declarations.add(declaration)
|
||||
}
|
||||
@@ -872,7 +872,7 @@ fun ExtractableCodeDescriptor.validate(): ExtractableCodeDescriptorWithConflicts
|
||||
|
||||
val currentDescriptor = bindingContext[BindingContext.REFERENCE_TARGET, currentRefExpr]
|
||||
val currentTarget =
|
||||
currentDescriptor?.let { DescriptorToDeclarationUtil.getDeclaration(extractionData.project, it) } as? PsiNamedElement
|
||||
currentDescriptor?.let { DescriptorToSourceUtilsIde.getAnyDeclaration(extractionData.project, it) } as? PsiNamedElement
|
||||
if (currentTarget is JetParameter && currentTarget.getParent() == valueParameterList) continue
|
||||
if (currentDescriptor is LocalVariableDescriptor
|
||||
&& parameters.any { it.mirrorVarName == currentDescriptor.getName().asString() }) continue
|
||||
|
||||
+2
-2
@@ -57,7 +57,7 @@ import org.jetbrains.kotlin.idea.refactoring.getUsageContext
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isInsideOf
|
||||
import org.jetbrains.kotlin.idea.codeInsight.JetFileReferencesResolver
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.psi.JetModifierListOwner
|
||||
import com.intellij.psi.PsiModifierListOwner
|
||||
import com.intellij.psi.PsiModifier
|
||||
@@ -192,7 +192,7 @@ public class MoveKotlinTopLevelDeclarationsProcessor(
|
||||
val referenceToContext = JetFileReferencesResolver.resolve(element = declaration, resolveQualifiers = false)
|
||||
for ((refExpr, bindingContext) in referenceToContext) {
|
||||
val refTarget = bindingContext[BindingContext.REFERENCE_TARGET, refExpr]?.let { descriptor ->
|
||||
DescriptorToDeclarationUtil.getDeclaration(declaration.getProject(), descriptor)
|
||||
DescriptorToSourceUtilsIde.getAnyDeclaration(declaration.getProject(), descriptor)
|
||||
}
|
||||
if (refTarget == null || refTarget.isInsideOf(elementsToMove)) continue
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.kotlin.idea.references.JetSimpleNameReference
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.idea.JetFileType
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isAncestor
|
||||
import java.util.Collections
|
||||
import org.jetbrains.kotlin.idea.refactoring.fqName.isImported
|
||||
@@ -80,7 +80,7 @@ public fun JetElement.getInternalReferencesToUpdateOnPackageNameChange(packageNa
|
||||
fun processReference(refExpr: JetSimpleNameExpression, bindingContext: BindingContext): UsageInfo? {
|
||||
val descriptor = bindingContext[BindingContext.REFERENCE_TARGET, refExpr]?.getImportableDescriptor() ?: return null
|
||||
|
||||
val declaration = DescriptorToDeclarationUtil.getDeclaration(getProject(), descriptor) ?: return null
|
||||
val declaration = DescriptorToSourceUtilsIde.getAnyDeclaration(getProject(), descriptor) ?: return null
|
||||
if (isAncestor(declaration, false)) return null
|
||||
|
||||
val isCallable = descriptor is CallableDescriptor
|
||||
|
||||
Reference in New Issue
Block a user