Resolution: Resolve primary constructor references to primary constructor

itself if it's explicitly present in PSI
This commit is contained in:
Alexey Sedunov
2015-06-04 16:26:47 +03:00
parent b049455aa4
commit 608ce59f15
15 changed files with 36 additions and 23 deletions
@@ -21,11 +21,13 @@ import com.intellij.psi.FileViewProvider
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.idea.decompiler.textBuilder.DecompiledText
import org.jetbrains.kotlin.idea.decompiler.textBuilder.descriptorToKey
import org.jetbrains.kotlin.psi.JetCallableDeclaration
import org.jetbrains.kotlin.psi.JetClassOrObject
import org.jetbrains.kotlin.psi.JetDeclaration
import org.jetbrains.kotlin.psi.JetFile
import org.jetbrains.kotlin.utils.concurrent.block.LockedClearableLazyValue
@@ -42,6 +44,11 @@ public abstract class KotlinClsFileBase(provider: FileViewProvider) : JetFile(pr
return callableDeclaration.getValueParameters()[original.getIndex()]
}
if (original is ConstructorDescriptor && original.isPrimary()) {
val classOrObject = getDeclarationForDescriptor(original.getContainingDeclaration()) as? JetClassOrObject
return classOrObject?.getPrimaryConstructor() ?: classOrObject
}
val key = descriptorToKey(original)
val range = decompiledText.get().renderedDescriptorsToRange[key]
@@ -21,13 +21,19 @@ import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag
import org.jetbrains.kotlin.psi.JetDeclaration
import org.jetbrains.kotlin.psi.JetPrimaryConstructor
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
object KDocFinder {
fun findKDoc(declaration: DeclarationDescriptor): KDocTag? {
if (declaration is DeclarationDescriptorWithSource) {
val psiDeclaration = (declaration.getSource() as? PsiSourceElement)?.psi?.getNavigationElement()
var psiDeclaration = (declaration.getSource() as? PsiSourceElement)?.psi?.getNavigationElement()
// KDoc for primary constructor is located inside of its class KDoc
if (psiDeclaration is JetPrimaryConstructor) {
psiDeclaration = psiDeclaration.getClassOrObject()
}
if (psiDeclaration is JetDeclaration) {
val kdoc = psiDeclaration.getDocComment()
if (kdoc != null) {
@@ -1 +1 @@
Following declarations are used outside of selected code fragment: local final class A value-parameter val n: Int = ...
Following declarations are used outside of selected code fragment: public constructor A(n: Int = ...) value-parameter val n: Int = ...
+1 -1
View File
@@ -2,4 +2,4 @@
package foo
// REF: (kotlin).deprecated
// REF: (in kotlin.deprecated).deprecated(kotlin.String,kotlin.ReplaceWith)
@@ -4,4 +4,4 @@ package foo
import kotlin.deprecated as D
// REF: (kotlin).deprecated
// REF: (in kotlin.deprecated).deprecated(kotlin.String,kotlin.ReplaceWith)
+1 -1
View File
@@ -7,4 +7,4 @@ fun main(args : Array<String>) {
var a = <caret>IntArray(array(1, 2, 3))
}
// REF: (kotlin).IntArray
// REF: (in kotlin.IntArray).IntArray(Int)
+1 -1
View File
@@ -4,4 +4,4 @@ fun foo() {
<caret>Fake()
}
//REF: (java.lang).Fake
//REF: (in java.lang.Fake).Fake()
+1 -1
View File
@@ -5,4 +5,4 @@ fun foo() {
<caret>Fake()
}
//REF: (java.lang).Fake
//REF: (in java.lang.Fake).Fake()