Renamed object and its methods.

This commit is contained in:
Evgeny Gerashchenko
2015-03-03 19:14:13 +03:00
parent 6982757700
commit 6ee4d92f36
26 changed files with 63 additions and 65 deletions
@@ -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)
}
}
@@ -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))
}